1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556
|
/* -*- Mode: c++; c-basic-offset: 2; tab-width: 4; indent-tabs-mode: nil; -*-
* vim: set sw=2 ts=4 expandtab:
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <algorithm>
#include <atomic>
#include <android/log.h>
#include <android/native_window.h>
#include <android/native_window_jni.h>
#include <math.h>
#include <queue>
#include <type_traits>
#include <unistd.h>
#include "AndroidBridge.h"
#include "AndroidBridgeUtilities.h"
#include "AndroidCompositorWidget.h"
#include "AndroidContentController.h"
#include "AndroidDragEvent.h"
#include "AndroidUiThread.h"
#include "AndroidView.h"
#include "AndroidWidgetUtils.h"
#include "gfxContext.h"
#include "GeckoEditableSupport.h"
#include "GeckoViewOutputStream.h"
#include "GeckoViewSupport.h"
#include "GLContext.h"
#include "GLContextProvider.h"
#include "JavaBuiltins.h"
#include "JavaExceptions.h"
#include "KeyEvent.h"
#include "MotionEvent.h"
#include "ScopedGLHelpers.h"
#include "ScreenHelperAndroid.h"
#include "TouchResampler.h"
#include "WidgetUtils.h"
#include "WindowRenderer.h"
#include "mozilla/EventForwards.h"
#include "nsAppShell.h"
#include "nsContentUtils.h"
#include "nsDragService.h"
#include "nsFocusManager.h"
#include "nsGkAtoms.h"
#include "nsGfxCIID.h"
#include "nsIDocShellTreeOwner.h"
#include "nsLayoutUtils.h"
#include "nsNetUtil.h"
#include "nsPrintfCString.h"
#include "nsString.h"
#include "nsTArray.h"
#include "nsThreadUtils.h"
#include "nsUserIdleService.h"
#include "nsWidgetsCID.h"
#include "nsWindow.h"
#include "nsIWidgetListener.h"
#include "nsIWindowWatcher.h"
#include "nsIAppWindow.h"
#include "nsIPrintSettings.h"
#include "nsIPrintSettingsService.h"
#include "mozilla/Logging.h"
#include "mozilla/MiscEvents.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/Preferences.h"
#include "mozilla/StaticPrefs_android.h"
#include "mozilla/StaticPrefs_ui.h"
#include "mozilla/StaticPrefs_widget.h"
#include "mozilla/TouchEvents.h"
#include "mozilla/WheelHandlingHelper.h" // for WheelDeltaAdjustmentStrategy
#include "mozilla/a11y/SessionAccessibility.h"
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/BrowserHost.h"
#include "mozilla/dom/CanonicalBrowsingContext.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/MouseEventBinding.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/DataSurfaceHelpers.h"
#include "mozilla/gfx/Logging.h"
#include "mozilla/gfx/Swizzle.h"
#include "mozilla/gfx/Types.h"
#include "mozilla/ipc/Shmem.h"
#include "mozilla/java/EventDispatcherWrappers.h"
#include "mozilla/java/GeckoAppShellWrappers.h"
#include "mozilla/java/GeckoEditableChildWrappers.h"
#include "mozilla/java/GeckoResultWrappers.h"
#include "mozilla/java/GeckoSessionNatives.h"
#include "mozilla/java/GeckoSystemStateListenerWrappers.h"
#include "mozilla/java/PanZoomControllerNatives.h"
#include "mozilla/java/SessionAccessibilityWrappers.h"
#include "mozilla/java/SurfaceControlManagerWrappers.h"
#include "mozilla/jni/NativesInlines.h"
#include "mozilla/layers/APZEventState.h"
#include "mozilla/layers/APZInputBridge.h"
#include "mozilla/layers/APZThreadUtils.h"
#include "mozilla/layers/CompositorBridgeChild.h"
#include "mozilla/layers/CompositorOGL.h"
#include "mozilla/layers/CompositorSession.h"
#include "mozilla/layers/LayersTypes.h"
#include "mozilla/layers/UiCompositorControllerChild.h"
#include "mozilla/layers/IAPZCTreeManager.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/widget/AndroidVsync.h"
#include "mozilla/widget/Screen.h"
#define GVS_LOG(...) MOZ_LOG(sGVSupportLog, LogLevel::Warning, (__VA_ARGS__))
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::layers;
using namespace mozilla::widget;
using namespace mozilla::ipc;
using mozilla::dom::ContentChild;
using mozilla::dom::ContentParent;
using mozilla::gfx::DataSourceSurface;
using mozilla::gfx::IntSize;
using mozilla::gfx::Matrix;
using mozilla::gfx::SurfaceFormat;
using mozilla::java::GeckoSession;
using mozilla::java::sdk::IllegalStateException;
using GeckoPrintException = GeckoSession::GeckoPrintException;
static mozilla::LazyLogModule sGVSupportLog("GeckoViewSupport");
// All the toplevel windows that have been created; these are in
// stacking order, so the window at gTopLevelWindows[0] is the topmost
// one.
MOZ_CONSTINIT static nsTArray<nsWindow*> gTopLevelWindows;
static const double kTouchResampleVsyncAdjustMs = 5.0;
static const int32_t INPUT_RESULT_UNHANDLED =
java::PanZoomController::INPUT_RESULT_UNHANDLED;
static const int32_t INPUT_RESULT_HANDLED =
java::PanZoomController::INPUT_RESULT_HANDLED;
static const int32_t INPUT_RESULT_HANDLED_CONTENT =
java::PanZoomController::INPUT_RESULT_HANDLED_CONTENT;
static const int32_t INPUT_RESULT_IGNORED =
java::PanZoomController::INPUT_RESULT_IGNORED;
static const nsCString::size_type MAX_TOPLEVEL_DATA_URI_LEN = 2 * 1024 * 1024;
// Unique ID given to each widget, to identify it for the
// CompositorSurfaceManager.
static std::atomic<int32_t> sWidgetId{0};
namespace {
template <class Instance, class Impl>
std::enable_if_t<jni::detail::NativePtrPicker<Impl>::value ==
jni::detail::NativePtrType::REFPTR,
void>
CallAttachNative(Instance aInstance, Impl* aImpl) {
Impl::AttachNative(aInstance, RefPtr<Impl>(aImpl).get());
}
template <class Instance, class Impl>
std::enable_if_t<jni::detail::NativePtrPicker<Impl>::value ==
jni::detail::NativePtrType::OWNING,
void>
CallAttachNative(Instance aInstance, Impl* aImpl) {
Impl::AttachNative(aInstance, UniquePtr<Impl>(aImpl));
}
template <class Lambda>
bool DispatchToUiThread(const char* aName, Lambda&& aLambda) {
if (RefPtr<nsThread> uiThread = GetAndroidUiThread()) {
uiThread->Dispatch(NS_NewRunnableFunction(aName, std::move(aLambda)));
return true;
}
return false;
}
} // namespace
namespace mozilla {
namespace widget {
// For double click detection
static int64_t sLastMouseDownTime = 0;
static int32_t sLastMouseButtons = 0;
static int32_t sLastClickCount = 0;
static float sLastMouseDownX = 0;
static float sLastMouseDownY = 0;
using WindowPtr = jni::NativeWeakPtr<GeckoViewSupport>;
/**
* PanZoomController handles its native calls on the UI thread, so make
* it separate from GeckoViewSupport.
*/
class NPZCSupport final
: public java::PanZoomController::NativeProvider::Natives<NPZCSupport> {
WindowPtr mWindow;
java::PanZoomController::NativeProvider::WeakRef mNPZC;
// Stores the returnResult of each pending motion event between
// HandleMotionEvent and FinishHandlingMotionEvent.
std::queue<std::pair<uint64_t, java::GeckoResult::GlobalRef>>
mPendingMotionEventReturnResults;
RefPtr<AndroidVsync> mAndroidVsync;
TouchResampler mTouchResampler;
int mPreviousButtons = 0;
bool mListeningToVsync = false;
// Only true if mAndroidVsync is non-null and the resampling pref is set.
bool mTouchResamplingEnabled = false;
template <typename Lambda>
class InputEvent final : public nsAppShell::Event {
java::PanZoomController::NativeProvider::GlobalRef mNPZC;
Lambda mLambda;
public:
InputEvent(const NPZCSupport* aNPZCSupport, Lambda&& aLambda)
: mNPZC(aNPZCSupport->mNPZC), mLambda(std::move(aLambda)) {}
void Run() override {
MOZ_ASSERT(NS_IsMainThread());
JNIEnv* const env = jni::GetGeckoThreadEnv();
const auto npzcSupportWeak = GetNative(
java::PanZoomController::NativeProvider::LocalRef(env, mNPZC));
if (!npzcSupportWeak) {
// We already shut down.
env->ExceptionClear();
return;
}
auto acc = npzcSupportWeak->Access();
if (!acc) {
// We already shut down.
env->ExceptionClear();
return;
}
auto win = acc->mWindow.Access();
if (!win) {
// We already shut down.
env->ExceptionClear();
return;
}
nsWindow* const window = win->GetNsWindow();
if (!window) {
// We already shut down.
env->ExceptionClear();
return;
}
window->UserActivity();
return mLambda(window);
}
bool IsUIEvent() const override { return true; }
};
class MOZ_HEAP_CLASS Observer final : public AndroidVsync::Observer {
public:
static Observer* Create(jni::NativeWeakPtr<NPZCSupport>&& aNPZCSupport) {
return new Observer(std::move(aNPZCSupport));
}
private:
// Private constructor, part of a strategy to make sure
// we're only able to create these on the heap.
explicit Observer(jni::NativeWeakPtr<NPZCSupport>&& aNPZCSupport)
: mNPZCSupport(std::move(aNPZCSupport)) {}
void OnVsync(const TimeStamp& aTimeStamp) override {
auto accessor = mNPZCSupport.Access();
if (!accessor) {
return;
}
accessor->mTouchResampler.NotifyFrame(
aTimeStamp -
TimeDuration::FromMilliseconds(kTouchResampleVsyncAdjustMs));
accessor->ConsumeMotionEventsFromResampler();
}
void Dispose() override { delete this; }
jni::NativeWeakPtr<NPZCSupport> mNPZCSupport;
};
Observer* mObserver = nullptr;
template <typename Lambda>
void PostInputEvent(Lambda&& aLambda) {
// Use priority queue for input events.
nsAppShell::PostEvent(
MakeUnique<InputEvent<Lambda>>(this, std::move(aLambda)));
}
public:
typedef java::PanZoomController::NativeProvider::Natives<NPZCSupport> Base;
NPZCSupport(WindowPtr aWindow,
const java::PanZoomController::NativeProvider::LocalRef& aNPZC)
: mWindow(aWindow), mNPZC(aNPZC) {
#if defined(DEBUG)
auto win(mWindow.Access());
MOZ_ASSERT(!!win);
#endif // defined(DEBUG)
mAndroidVsync = AndroidVsync::GetInstance();
}
~NPZCSupport() {
if (mListeningToVsync) {
MOZ_RELEASE_ASSERT(mAndroidVsync);
mAndroidVsync->UnregisterObserver(mObserver, AndroidVsync::INPUT);
mListeningToVsync = false;
}
}
using Base::AttachNative;
using Base::DisposeNative;
void OnWeakNonIntrusiveDetach(already_AddRefed<Runnable> aDisposer) {
RefPtr<Runnable> disposer = aDisposer;
// There are several considerations when shutting down NPZC. 1) The
// Gecko thread may destroy NPZC at any time when nsWindow closes. 2)
// There may be pending events on the Gecko thread when NPZC is
// destroyed. 3) mWindow may not be available when the pending event
// runs. 4) The UI thread may destroy NPZC at any time when GeckoView
// is destroyed. 5) The UI thread may destroy NPZC at the same time as
// Gecko thread trying to destroy NPZC. 6) There may be pending calls
// on the UI thread when NPZC is destroyed. 7) mWindow may have been
// cleared on the Gecko thread when the pending call happens on the UI
// thread.
//
// 1) happens through OnWeakNonIntrusiveDetach, which first notifies the UI
// thread through Destroy; Destroy then calls DisposeNative, which
// finally disposes the native instance back on the Gecko thread. Using
// Destroy to indirectly call DisposeNative here also solves 5), by
// making everything go through the UI thread, avoiding contention.
//
// 2) and 3) are solved by clearing mWindow, which signals to the
// pending event that we had shut down. In that case the event bails
// and does not touch mWindow.
//
// 4) happens through DisposeNative directly.
//
// 6) is solved by keeping a destroyed flag in the Java NPZC instance,
// and only make a pending call if the destroyed flag is not set.
//
// 7) is solved by taking a lock whenever mWindow is modified on the
// Gecko thread or accessed on the UI thread. That way, we don't
// release mWindow until the UI thread is done using it, thus avoiding
// the race condition.
if (RefPtr<nsThread> uiThread = GetAndroidUiThread()) {
auto npzc = java::PanZoomController::NativeProvider::GlobalRef(mNPZC);
if (!npzc) {
return;
}
uiThread->Dispatch(
NS_NewRunnableFunction("NPZCSupport::OnWeakNonIntrusiveDetach",
[npzc, disposer = std::move(disposer)] {
npzc->SetAttached(false);
disposer->Run();
}));
}
}
const java::PanZoomController::NativeProvider::Ref& GetJavaNPZC() const {
return mNPZC;
}
public:
void SetIsLongpressEnabled(bool aIsLongpressEnabled) {
RefPtr<IAPZCTreeManager> controller;
if (auto window = mWindow.Access()) {
nsWindow* gkWindow = window->GetNsWindow();
if (gkWindow) {
controller = gkWindow->mAPZC;
}
}
if (controller) {
controller->SetLongTapEnabled(aIsLongpressEnabled);
}
}
int32_t HandleScrollEvent(int64_t aTime, int32_t aMetaState, float aX,
float aY, float aHScroll, float aVScroll) {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
RefPtr<IAPZCTreeManager> controller;
if (auto window = mWindow.Access()) {
nsWindow* gkWindow = window->GetNsWindow();
if (gkWindow) {
controller = gkWindow->mAPZC;
}
}
if (!controller) {
return INPUT_RESULT_UNHANDLED;
}
ScreenPoint origin = ScreenPoint(aX, aY);
if (StaticPrefs::ui_scrolling_negate_wheel_scroll()) {
aHScroll = -aHScroll;
aVScroll = -aVScroll;
}
ScrollWheelInput input(
nsWindow::GetEventTimeStamp(aTime), nsWindow::GetModifiers(aMetaState),
ScrollWheelInput::SCROLLMODE_SMOOTH,
ScrollWheelInput::SCROLLDELTA_PIXEL, origin, aHScroll, aVScroll, false,
// XXX Do we need to support auto-dir scrolling
// for Android widgets with a wheel device?
// Currently, I just leave it unimplemented. If
// we need to implement it, what's the extra work
// to do?
WheelDeltaAdjustmentStrategy::eNone);
APZEventResult result = controller->InputBridge()->ReceiveInputEvent(input);
if (result.GetStatus() == nsEventStatus_eConsumeNoDefault) {
return INPUT_RESULT_IGNORED;
}
PostInputEvent([input = std::move(input), result](nsWindow* window) {
WidgetWheelEvent wheelEvent = input.ToWidgetEvent(window);
window->ProcessUntransformedAPZEvent(&wheelEvent, result);
});
switch (result.GetStatus()) {
case nsEventStatus_eIgnore:
return INPUT_RESULT_UNHANDLED;
case nsEventStatus_eConsumeDoDefault:
return result.GetHandledResult()->IsHandledByRoot()
? INPUT_RESULT_HANDLED
: INPUT_RESULT_HANDLED_CONTENT;
default:
MOZ_ASSERT_UNREACHABLE("Unexpected nsEventStatus");
return INPUT_RESULT_UNHANDLED;
}
}
private:
static MouseInput::ButtonType GetButtonType(int button) {
MouseInput::ButtonType result = MouseInput::NONE;
switch (button) {
case java::sdk::MotionEvent::BUTTON_PRIMARY:
result = MouseInput::PRIMARY_BUTTON;
break;
case java::sdk::MotionEvent::BUTTON_SECONDARY:
result = MouseInput::SECONDARY_BUTTON;
break;
case java::sdk::MotionEvent::BUTTON_TERTIARY:
result = MouseInput::MIDDLE_BUTTON;
break;
default:
break;
}
return result;
}
static int16_t ConvertButtons(int buttons) {
int16_t result = 0;
if (buttons & java::sdk::MotionEvent::BUTTON_PRIMARY) {
result |= MouseButtonsFlag::ePrimaryFlag;
}
if (buttons & java::sdk::MotionEvent::BUTTON_SECONDARY) {
result |= MouseButtonsFlag::eSecondaryFlag;
}
if (buttons & java::sdk::MotionEvent::BUTTON_TERTIARY) {
result |= MouseButtonsFlag::eMiddleFlag;
}
if (buttons & java::sdk::MotionEvent::BUTTON_BACK) {
result |= MouseButtonsFlag::e4thFlag;
}
if (buttons & java::sdk::MotionEvent::BUTTON_FORWARD) {
result |= MouseButtonsFlag::e5thFlag;
}
return result;
}
static int32_t ConvertAPZHandledPlace(APZHandledPlace aHandledPlace) {
switch (aHandledPlace) {
case APZHandledPlace::Unhandled:
return INPUT_RESULT_UNHANDLED;
case APZHandledPlace::HandledByRoot:
return INPUT_RESULT_HANDLED;
case APZHandledPlace::HandledByContent:
return INPUT_RESULT_HANDLED_CONTENT;
case APZHandledPlace::Invalid:
MOZ_ASSERT_UNREACHABLE("The handled result should NOT be Invalid");
return INPUT_RESULT_UNHANDLED;
}
MOZ_ASSERT_UNREACHABLE("Unknown handled result");
return INPUT_RESULT_UNHANDLED;
}
static int32_t ConvertSideBits(SideBits aSideBits) {
int32_t ret = java::PanZoomController::SCROLLABLE_FLAG_NONE;
if (aSideBits & SideBits::eTop) {
ret |= java::PanZoomController::SCROLLABLE_FLAG_TOP;
}
if (aSideBits & SideBits::eRight) {
ret |= java::PanZoomController::SCROLLABLE_FLAG_RIGHT;
}
if (aSideBits & SideBits::eBottom) {
ret |= java::PanZoomController::SCROLLABLE_FLAG_BOTTOM;
}
if (aSideBits & SideBits::eLeft) {
ret |= java::PanZoomController::SCROLLABLE_FLAG_LEFT;
}
return ret;
}
static int32_t ConvertScrollDirections(
layers::ScrollDirections aScrollDirections) {
int32_t ret = java::PanZoomController::OVERSCROLL_FLAG_NONE;
if (aScrollDirections.contains(layers::HorizontalScrollDirection)) {
ret |= java::PanZoomController::OVERSCROLL_FLAG_HORIZONTAL;
}
if (aScrollDirections.contains(layers::VerticalScrollDirection)) {
ret |= java::PanZoomController::OVERSCROLL_FLAG_VERTICAL;
}
return ret;
}
static java::PanZoomController::InputResultDetail::LocalRef
ConvertAPZHandledResult(const APZHandledResult& aHandledResult) {
return java::PanZoomController::InputResultDetail::New(
ConvertAPZHandledPlace(aHandledResult.mPlace),
ConvertSideBits(aHandledResult.mScrollableDirections),
ConvertScrollDirections(aHandledResult.mOverscrollDirections));
}
static bool IsIntoDoubleClickThreshold(float aX, float aY) {
int32_t deltaX = abs((int32_t)floorf(sLastMouseDownX - aX));
int32_t deltaY = abs((int32_t)floorf(sLastMouseDownY - aY));
int32_t threshold = StaticPrefs::widget_double_click_threshold();
return (deltaX * deltaX + deltaY * deltaY < threshold * threshold);
}
static bool IsDoubleClick(int64_t aTime, float aX, float aY, int buttons) {
if (sLastMouseButtons != buttons) {
return false;
}
int64_t deltaTime = aTime - sLastMouseDownTime;
if (deltaTime < (int64_t)StaticPrefs::widget_double_click_min() ||
deltaTime > (int64_t)StaticPrefs::widget_double_click_timeout()) {
return false;
}
return IsIntoDoubleClickThreshold(aX, aY);
}
public:
int32_t HandleMouseEvent(int32_t aAction, int64_t aTime, int32_t aMetaState,
float aX, float aY, int buttons) {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
RefPtr<IAPZCTreeManager> controller;
if (auto window = mWindow.Access()) {
nsWindow* gkWindow = window->GetNsWindow();
if (gkWindow) {
controller = gkWindow->mAPZC;
}
}
if (!controller) {
return INPUT_RESULT_UNHANDLED;
}
MouseInput::MouseType mouseType = MouseInput::MOUSE_NONE;
MouseInput::ButtonType buttonType = MouseInput::NONE;
switch (aAction) {
case java::sdk::MotionEvent::ACTION_DOWN:
mouseType = MouseInput::MOUSE_DOWN;
buttonType = GetButtonType(buttons ^ mPreviousButtons);
mPreviousButtons = buttons;
if (IsDoubleClick(aTime, aX, aY, buttons)) {
sLastClickCount++;
} else {
sLastClickCount = 1;
}
sLastMouseDownTime = aTime;
sLastMouseDownX = aX;
sLastMouseDownY = aY;
sLastMouseButtons = buttons;
break;
case java::sdk::MotionEvent::ACTION_UP:
mouseType = MouseInput::MOUSE_UP;
buttonType = GetButtonType(buttons ^ mPreviousButtons);
mPreviousButtons = buttons;
break;
case java::sdk::MotionEvent::ACTION_MOVE:
mouseType = MouseInput::MOUSE_MOVE;
if (!IsIntoDoubleClickThreshold(aX, aY)) {
sLastClickCount = 0;
}
break;
case java::sdk::MotionEvent::ACTION_HOVER_MOVE:
mouseType = MouseInput::MOUSE_MOVE;
break;
case java::sdk::MotionEvent::ACTION_HOVER_ENTER:
mouseType = MouseInput::MOUSE_WIDGET_ENTER;
break;
case java::sdk::MotionEvent::ACTION_HOVER_EXIT:
mouseType = MouseInput::MOUSE_WIDGET_EXIT;
break;
default:
break;
}
if (mouseType == MouseInput::MOUSE_NONE) {
return INPUT_RESULT_UNHANDLED;
}
ScreenPoint origin = ScreenPoint(aX, aY);
MouseInput input(
mouseType, buttonType, MouseEvent_Binding::MOZ_SOURCE_MOUSE,
ConvertButtons(buttons), origin, nsWindow::GetEventTimeStamp(aTime),
nsWindow::GetModifiers(aMetaState));
APZEventResult result = controller->InputBridge()->ReceiveInputEvent(input);
if (result.GetStatus() == nsEventStatus_eConsumeNoDefault) {
return INPUT_RESULT_IGNORED;
}
PostInputEvent([input = std::move(input), result,
clickCount = sLastClickCount](nsWindow* window) {
WidgetMouseEvent mouseEvent =
input.ToWidgetEvent<WidgetMouseEvent>(window);
mouseEvent.mClickCount = clickCount;
window->ProcessUntransformedAPZEvent(&mouseEvent, result);
if (MouseInput::SECONDARY_BUTTON == input.mButtonType) {
if ((StaticPrefs::ui_context_menus_after_mouseup() &&
MouseInput::MOUSE_UP == input.mType) ||
(!StaticPrefs::ui_context_menus_after_mouseup() &&
MouseInput::MOUSE_DOWN == input.mType)) {
MouseInput contextMenu = input;
// Actually we don't dispatch context menu event to APZ since we don't
// handle it on APZ yet. If handling it, we need to consider how to
// dispatch it on APZ thread. It may cause a race condition.
contextMenu.mType = MouseInput::MOUSE_CONTEXTMENU;
if (contextMenu.IsPointerEventType()) {
WidgetPointerEvent contextMenuEvent =
contextMenu.ToWidgetEvent<WidgetPointerEvent>(window);
window->ProcessUntransformedAPZEvent(&contextMenuEvent, result);
} else {
WidgetMouseEvent contextMenuEvent =
contextMenu.ToWidgetEvent<WidgetMouseEvent>(window);
window->ProcessUntransformedAPZEvent(&contextMenuEvent, result);
}
}
}
});
switch (result.GetStatus()) {
case nsEventStatus_eIgnore:
return INPUT_RESULT_UNHANDLED;
case nsEventStatus_eConsumeDoDefault:
return result.GetHandledResult()->IsHandledByRoot()
? INPUT_RESULT_HANDLED
: INPUT_RESULT_HANDLED_CONTENT;
default:
MOZ_ASSERT_UNREACHABLE("Unexpected nsEventStatus");
return INPUT_RESULT_UNHANDLED;
}
}
// Convert MotionEvent touch radius and orientation into the format required
// by w3c touchevents.
// toolMajor and toolMinor span a rectangle that's oriented as per
// aOrientation, centered around the touch point.
static std::pair<float, ScreenSize> ConvertOrientationAndRadius(
float aOrientation, float aToolMajor, float aToolMinor) {
float angle = aOrientation * 180.0f / M_PI;
// w3c touchevents spec does not allow orientations == 90
// this shifts it to -90, which will be shifted to zero below
if (angle >= 90.0) {
angle -= 180.0f;
}
// w3c touchevent radii are given with an orientation between 0 and
// 90. The radii are found by removing the orientation and
// measuring the x and y radii of the resulting ellipse. For
// Android orientations >= 0 and < 90, use the y radius as the
// major radius, and x as the minor radius. However, for an
// orientation < 0, we have to shift the orientation by adding 90,
// and reverse which radius is major and minor.
ScreenSize radius;
if (angle < 0.0f) {
angle += 90.0f;
radius =
ScreenSize(int32_t(aToolMajor / 2.0f), int32_t(aToolMinor / 2.0f));
} else {
radius =
ScreenSize(int32_t(aToolMinor / 2.0f), int32_t(aToolMajor / 2.0f));
}
return std::make_pair(angle, radius);
}
static void SetTiltXY(float aOrientation, float aTilt,
SingleTouchData& aSingleTouchData) {
float r = sinf(aTilt);
float z = cosf(aTilt);
float x = atan2f(sinf(-aOrientation) * r, z);
float y = atan2f(cosf(-aOrientation) * r, z);
aSingleTouchData.mTiltX = int32_t(floorf(x * 180.0 / M_PI));
aSingleTouchData.mTiltY = int32_t(floorf(y * 180.0 / M_PI));
}
void HandleMotionEvent(
const java::PanZoomController::NativeProvider::LocalRef& aInstance,
jni::Object::Param aEventData, float aScreenX, float aScreenY,
jni::Object::Param aResult) {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
auto returnResult = java::GeckoResult::Ref::From(aResult);
auto eventData =
java::PanZoomController::MotionEventData::Ref::From(aEventData);
nsTArray<int32_t> pointerId(eventData->PointerId()->GetElements());
size_t pointerCount = pointerId.Length();
MultiTouchInput::MultiTouchType type;
size_t startIndex = 0;
size_t endIndex = pointerCount;
switch (eventData->Action()) {
case java::sdk::MotionEvent::ACTION_DOWN:
case java::sdk::MotionEvent::ACTION_POINTER_DOWN:
type = MultiTouchInput::MULTITOUCH_START;
break;
case java::sdk::MotionEvent::ACTION_MOVE:
type = MultiTouchInput::MULTITOUCH_MOVE;
break;
case java::sdk::MotionEvent::ACTION_UP:
case java::sdk::MotionEvent::ACTION_POINTER_UP:
// for pointer-up events we only want the data from
// the one pointer that went up
type = MultiTouchInput::MULTITOUCH_END;
startIndex = eventData->ActionIndex();
endIndex = startIndex + 1;
break;
case java::sdk::MotionEvent::ACTION_OUTSIDE:
case java::sdk::MotionEvent::ACTION_CANCEL:
type = MultiTouchInput::MULTITOUCH_CANCEL;
break;
default:
if (returnResult) {
returnResult->Complete(
java::sdk::Integer::ValueOf(INPUT_RESULT_UNHANDLED));
}
return;
}
MultiTouchInput input(type, eventData->Time(),
nsWindow::GetEventTimeStamp(eventData->Time()), 0);
input.modifiers = nsWindow::GetModifiers(eventData->MetaState());
input.mTouches.SetCapacity(endIndex - startIndex);
input.mScreenOffset =
ExternalIntPoint(int32_t(floorf(aScreenX)), int32_t(floorf(aScreenY)));
switch (eventData->ToolType()) {
case java::sdk::MotionEvent::TOOL_TYPE_STYLUS:
input.mInputSource = MouseEvent_Binding::MOZ_SOURCE_PEN;
break;
default:
input.mInputSource = MouseEvent_Binding::MOZ_SOURCE_TOUCH;
break;
}
size_t historySize = eventData->HistorySize();
nsTArray<int64_t> historicalTime(
eventData->HistoricalTime()->GetElements());
MOZ_RELEASE_ASSERT(historicalTime.Length() == historySize);
// Each of these is |historySize| sets of |pointerCount| values.
size_t historicalDataCount = historySize * pointerCount;
nsTArray<float> historicalX(eventData->HistoricalX()->GetElements());
nsTArray<float> historicalY(eventData->HistoricalY()->GetElements());
nsTArray<float> historicalOrientation(
eventData->HistoricalOrientation()->GetElements());
nsTArray<float> historicalPressure(
eventData->HistoricalPressure()->GetElements());
nsTArray<float> historicalToolMajor(
eventData->HistoricalToolMajor()->GetElements());
nsTArray<float> historicalToolMinor(
eventData->HistoricalToolMinor()->GetElements());
MOZ_RELEASE_ASSERT(historicalX.Length() == historicalDataCount);
MOZ_RELEASE_ASSERT(historicalY.Length() == historicalDataCount);
MOZ_RELEASE_ASSERT(historicalOrientation.Length() == historicalDataCount);
MOZ_RELEASE_ASSERT(historicalPressure.Length() == historicalDataCount);
MOZ_RELEASE_ASSERT(historicalToolMajor.Length() == historicalDataCount);
MOZ_RELEASE_ASSERT(historicalToolMinor.Length() == historicalDataCount);
// Each of these is |pointerCount| values.
nsTArray<float> x(eventData->X()->GetElements());
nsTArray<float> y(eventData->Y()->GetElements());
nsTArray<float> orientation(eventData->Orientation()->GetElements());
nsTArray<float> pressure(eventData->Pressure()->GetElements());
nsTArray<float> tilt(eventData->Tilt()->GetElements());
nsTArray<float> toolMajor(eventData->ToolMajor()->GetElements());
nsTArray<float> toolMinor(eventData->ToolMinor()->GetElements());
MOZ_ASSERT(x.Length() == pointerCount);
MOZ_ASSERT(y.Length() == pointerCount);
MOZ_ASSERT(orientation.Length() == pointerCount);
MOZ_ASSERT(pressure.Length() == pointerCount);
MOZ_ASSERT(tilt.Length() == pointerCount);
MOZ_ASSERT(toolMajor.Length() == pointerCount);
MOZ_ASSERT(toolMinor.Length() == pointerCount);
for (size_t i = startIndex; i < endIndex; i++) {
auto [orien, radius] = ConvertOrientationAndRadius(
orientation[i], toolMajor[i], toolMinor[i]);
ScreenIntPoint point(int32_t(floorf(x[i])), int32_t(floorf(y[i])));
SingleTouchData singleTouchData(pointerId[i], point, radius, orien,
pressure[i]);
SetTiltXY(orientation[i], tilt[i], singleTouchData);
for (size_t historyIndex = 0; historyIndex < historySize;
historyIndex++) {
size_t historicalI = historyIndex * pointerCount + i;
auto [historicalAngle, historicalRadius] = ConvertOrientationAndRadius(
historicalOrientation[historicalI],
historicalToolMajor[historicalI], historicalToolMinor[historicalI]);
ScreenIntPoint historicalPoint(
int32_t(floorf(historicalX[historicalI])),
int32_t(floorf(historicalY[historicalI])));
singleTouchData.mHistoricalData.AppendElement(
SingleTouchData::HistoricalTouchData{
nsWindow::GetEventTimeStamp(historicalTime[historyIndex]),
historicalPoint,
{}, // mLocalScreenPoint will be computed later by APZ
historicalRadius,
historicalAngle,
historicalPressure[historicalI]});
}
input.mTouches.AppendElement(singleTouchData);
}
if (mAndroidVsync &&
eventData->Action() == java::sdk::MotionEvent::ACTION_DOWN) {
// Query pref value at the beginning of a touch gesture so that we don't
// leave events stuck in the resampler after a pref flip.
mTouchResamplingEnabled = StaticPrefs::android_touch_resampling_enabled();
}
if (!mTouchResamplingEnabled) {
FinishHandlingMotionEvent(std::move(input),
java::GeckoResult::LocalRef(returnResult));
return;
}
uint64_t eventId = mTouchResampler.ProcessEvent(std::move(input));
mPendingMotionEventReturnResults.push(
{eventId, java::GeckoResult::GlobalRef(returnResult)});
RegisterOrUnregisterForVsync(mTouchResampler.InTouchingState());
ConsumeMotionEventsFromResampler();
}
void RegisterOrUnregisterForVsync(bool aNeedVsync) {
MOZ_RELEASE_ASSERT(mAndroidVsync);
if (aNeedVsync && !mListeningToVsync) {
MOZ_ASSERT(!mObserver);
auto win = mWindow.Access();
if (!win) {
return;
}
RefPtr<nsWindow> gkWindow = win->GetNsWindow();
if (!gkWindow) {
return;
}
MutexAutoLock lock(gkWindow->GetDestroyMutex());
if (gkWindow->Destroyed()) {
return;
}
jni::NativeWeakPtr<NPZCSupport> weakPtrToThis =
gkWindow->GetNPZCSupportWeakPtr();
mObserver = Observer::Create(std::move(weakPtrToThis));
mAndroidVsync->RegisterObserver(mObserver, AndroidVsync::INPUT);
} else if (!aNeedVsync && mListeningToVsync) {
mAndroidVsync->UnregisterObserver(mObserver, AndroidVsync::INPUT);
mObserver = nullptr;
}
mListeningToVsync = aNeedVsync;
}
void HandleDragEvent(int32_t aAction, int64_t aTime, float aX, float aY,
jni::Object::Param aDropData) {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
RefPtr<IAPZCTreeManager> controller;
if (auto window = mWindow.Access()) {
if (nsWindow* gkWindow = window->GetNsWindow()) {
controller = gkWindow->mAPZC;
}
}
if (!controller) {
return;
}
MouseInput::MouseType mouseType = MouseInput::MouseType::MOUSE_NONE;
switch (aAction) {
case java::sdk::DragEvent::ACTION_DRAG_STARTED:
mouseType = MouseInput::MouseType::MOUSE_DRAG_START;
break;
case java::sdk::DragEvent::ACTION_DRAG_ENDED:
mouseType = MouseInput::MouseType::MOUSE_DRAG_END;
break;
case java::sdk::DragEvent::ACTION_DRAG_ENTERED:
mouseType = MouseInput::MouseType::MOUSE_DRAG_ENTER;
break;
case java::sdk::DragEvent::ACTION_DRAG_LOCATION:
mouseType = MouseInput::MouseType::MOUSE_DRAG_OVER;
break;
case java::sdk::DragEvent::ACTION_DRAG_EXITED:
mouseType = MouseInput::MouseType::MOUSE_DRAG_EXIT;
break;
case java::sdk::DragEvent::ACTION_DROP:
mouseType = MouseInput::MouseType::MOUSE_DROP;
break;
default:
break;
}
ScreenPoint origin = ScreenPoint(aX, aY);
MouseInput input(
mouseType, MouseInput::NONE, MouseEvent_Binding::MOZ_SOURCE_MOUSE, 0,
origin, nsWindow::GetEventTimeStamp(aTime), nsWindow::GetModifiers(0));
APZEventResult result = controller->InputBridge()->ReceiveInputEvent(input);
if (result.GetStatus() == nsEventStatus_eConsumeNoDefault) {
return;
}
PostInputEvent(
[input = std::move(input), result, aAction, aX, aY,
dropData = jni::Object::GlobalRef(aDropData)](nsWindow* window) {
window->OnDragEvent(aAction, aX, aY, dropData, result, input);
});
}
void ConsumeMotionEventsFromResampler() {
auto outgoing = mTouchResampler.ConsumeOutgoingEvents();
while (!outgoing.empty()) {
auto outgoingEvent = std::move(outgoing.front());
outgoing.pop();
java::GeckoResult::GlobalRef returnResult;
if (outgoingEvent.mEventId) {
// Look up the GeckoResult for this event.
// The outgoing events from the resampler are in the same order as the
// original events, and no event IDs are skipped.
MOZ_RELEASE_ASSERT(!mPendingMotionEventReturnResults.empty());
auto pair = mPendingMotionEventReturnResults.front();
mPendingMotionEventReturnResults.pop();
MOZ_RELEASE_ASSERT(pair.first == *outgoingEvent.mEventId);
returnResult = pair.second;
}
FinishHandlingMotionEvent(std::move(outgoingEvent.mEvent),
java::GeckoResult::LocalRef(returnResult));
}
}
void FinishHandlingMotionEvent(MultiTouchInput&& aInput,
java::GeckoResult::LocalRef&& aReturnResult) {
RefPtr<IAPZCTreeManager> controller;
if (auto window = mWindow.Access()) {
nsWindow* gkWindow = window->GetNsWindow();
if (gkWindow) {
controller = gkWindow->mAPZC;
}
}
if (!controller) {
if (aReturnResult) {
aReturnResult->Complete(java::PanZoomController::InputResultDetail::New(
INPUT_RESULT_UNHANDLED,
java::PanZoomController::SCROLLABLE_FLAG_NONE,
java::PanZoomController::OVERSCROLL_FLAG_NONE));
}
return;
}
APZInputBridge::InputBlockCallback callback;
if (aReturnResult) {
callback = [aReturnResult = java::GeckoResult::GlobalRef(aReturnResult)](
uint64_t aInputBlockId,
const APZHandledResult& aHandledResult) {
aReturnResult->Complete(ConvertAPZHandledResult(aHandledResult));
};
}
APZEventResult result = controller->InputBridge()->ReceiveInputEvent(
aInput, std::move(callback));
if (result.GetStatus() == nsEventStatus_eConsumeNoDefault) {
if (aReturnResult) {
if (result.GetHandledResult() != Nothing()) {
aReturnResult->Complete(
ConvertAPZHandledResult(result.GetHandledResult().value()));
} else {
MOZ_ASSERT_UNREACHABLE(
"nsEventStatus_eConsumeNoDefault should involve a valid "
"APZHandledResult");
aReturnResult->Complete(
java::PanZoomController::InputResultDetail::New(
INPUT_RESULT_IGNORED,
java::PanZoomController::SCROLLABLE_FLAG_NONE,
java::PanZoomController::OVERSCROLL_FLAG_NONE));
}
}
return;
}
// Dispatch APZ input event on Gecko thread.
PostInputEvent([input = std::move(aInput), result](nsWindow* window) {
WidgetTouchEvent touchEvent = input.ToWidgetEvent(window);
window->ProcessUntransformedAPZEvent(&touchEvent, result);
window->DispatchHitTest(touchEvent);
});
if (aReturnResult && result.GetHandledResult() != Nothing()) {
MOZ_ASSERT(result.GetStatus() == nsEventStatus_eConsumeDoDefault ||
result.GetStatus() == nsEventStatus_eIgnore);
aReturnResult->Complete(
ConvertAPZHandledResult(result.GetHandledResult().value()));
}
}
};
NS_IMPL_ISUPPORTS(AndroidView, nsIGeckoViewEventDispatcher, nsIGeckoViewView)
nsresult AndroidView::GetInitData(JSContext* aCx,
JS::MutableHandle<JS::Value> aOut) {
if (!mInitData) {
aOut.setNull();
return NS_OK;
}
return widget::EventDispatcher::UnboxBundle(aCx, mInitData, aOut);
}
/**
* Compositor has some unique requirements for its native calls, so make it
* separate from GeckoViewSupport.
*/
class LayerViewSupport final
: public GeckoSession::Compositor::Natives<LayerViewSupport> {
WindowPtr mWindow;
GeckoSession::Compositor::WeakRef mCompositor;
Atomic<bool, ReleaseAcquire> mCompositorPaused;
java::sdk::Surface::GlobalRef mSurface;
java::sdk::SurfaceControl::GlobalRef mSurfaceControl;
int32_t mX;
int32_t mY;
int32_t mWidth;
int32_t mHeight;
// Used to communicate with the gecko compositor from the UI thread.
// Set in NotifyCompositorCreated and cleared in
// NotifyCompositorSessionLost.
RefPtr<UiCompositorControllerChild> mUiCompositorControllerChild;
// Whether we have requested a new Surface from the GeckoSession.
bool mRequestedNewSurface = false;
Maybe<uint32_t> mDefaultClearColor;
struct CaptureRequest {
explicit CaptureRequest() : mResult(nullptr) {}
explicit CaptureRequest(java::GeckoResult::GlobalRef aResult,
java::sdk::Bitmap::GlobalRef aBitmap,
const ScreenRect& aSource,
const IntSize& aOutputSize)
: mResult(aResult),
mBitmap(aBitmap),
mSource(aSource),
mOutputSize(aOutputSize) {}
// where to send the pixels
java::GeckoResult::GlobalRef mResult;
// where to store the pixels
java::sdk::Bitmap::GlobalRef mBitmap;
ScreenRect mSource;
IntSize mOutputSize;
};
std::queue<CaptureRequest> mCapturePixelsResults;
// In order to use Event::HasSameTypeAs in PostTo(), we cannot make
// LayerViewEvent a template because each template instantiation is
// a different type. So implement LayerViewEvent as a ProxyEvent.
class LayerViewEvent final : public nsAppShell::ProxyEvent {
using Event = nsAppShell::Event;
public:
static UniquePtr<Event> MakeEvent(UniquePtr<Event>&& event) {
return MakeUnique<LayerViewEvent>(std::move(event));
}
explicit LayerViewEvent(UniquePtr<Event>&& event)
: nsAppShell::ProxyEvent(std::move(event)) {}
void PostTo(LinkedList<Event>& queue) override {
// Give priority to compositor events, but keep in order with
// existing compositor events.
nsAppShell::Event* event = queue.getFirst();
while (event && event->HasSameTypeAs(this)) {
event = event->getNext();
}
if (event) {
event->setPrevious(this);
} else {
queue.insertBack(this);
}
}
};
public:
typedef GeckoSession::Compositor::Natives<LayerViewSupport> Base;
LayerViewSupport(WindowPtr aWindow,
const GeckoSession::Compositor::LocalRef& aInstance)
: mWindow(aWindow), mCompositor(aInstance), mCompositorPaused(true) {
#if defined(DEBUG)
auto win(mWindow.Access());
MOZ_ASSERT(!!win);
#endif // defined(DEBUG)
}
~LayerViewSupport() {}
using Base::AttachNative;
using Base::DisposeNative;
void OnWeakNonIntrusiveDetach(already_AddRefed<Runnable> aDisposer) {
RefPtr<Runnable> disposer = aDisposer;
if (RefPtr<nsThread> uiThread = GetAndroidUiThread()) {
GeckoSession::Compositor::GlobalRef compositor(mCompositor);
if (!compositor) {
return;
}
uiThread->Dispatch(NS_NewRunnableFunction(
"LayerViewSupport::OnWeakNonIntrusiveDetach",
[compositor, disposer = std::move(disposer),
results = &mCapturePixelsResults, window = mWindow]() mutable {
if (auto accWindow = window.Access()) {
while (!results->empty()) {
auto aResult =
java::GeckoResult::LocalRef(results->front().mResult);
if (aResult) {
aResult->CompleteExceptionally(
java::sdk::IllegalStateException::New(
"The compositor has detached from the session")
.Cast<jni::Throwable>());
}
results->pop();
}
}
compositor->OnCompositorDetached();
disposer->Run();
}));
}
}
const GeckoSession::Compositor::Ref& GetJavaCompositor() const {
return mCompositor;
}
bool CompositorPaused() const { return mCompositorPaused; }
/// Called from the main thread whenever the compositor has been
/// (re)initialized.
void NotifyCompositorCreated(
RefPtr<UiCompositorControllerChild> aUiCompositorControllerChild) {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
mUiCompositorControllerChild = aUiCompositorControllerChild;
if (mDefaultClearColor) {
mUiCompositorControllerChild->SetDefaultClearColor(*mDefaultClearColor);
}
if (!mCompositorPaused) {
// If we are using SurfaceControl but mSurface is null, that means the
// previous surface was destroyed along with the the previous
// compositor, and we need to create a new one.
if (mSurfaceControl && !mSurface) {
mSurface = java::SurfaceControlManager::GetInstance()->GetChildSurface(
mSurfaceControl, mWidth, mHeight);
}
if (auto window{mWindow.Access()}) {
nsWindow* gkWindow = window->GetNsWindow();
if (gkWindow) {
mUiCompositorControllerChild->OnCompositorSurfaceChanged(
gkWindow->mWidgetId, mSurface);
}
}
bool resumed = mUiCompositorControllerChild->ResumeAndResize(
mX, mY, mWidth, mHeight);
if (!resumed) {
gfxCriticalNote
<< "Failed to resume compositor from NotifyCompositorCreated";
RequestNewSurface();
}
}
}
/// Called from the main thread whenever the compositor has been destroyed.
void NotifyCompositorSessionLost() {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
mUiCompositorControllerChild = nullptr;
if (mSurfaceControl) {
// If we are using SurfaceControl then we must set the Surface to null
// here to ensure we create a new one when the new compositor is
// created.
mSurface = nullptr;
}
if (auto window = mWindow.Access()) {
while (!mCapturePixelsResults.empty()) {
auto result =
java::GeckoResult::LocalRef(mCapturePixelsResults.front().mResult);
if (result) {
result->CompleteExceptionally(
java::sdk::IllegalStateException::New(
"Compositor session lost during screen pixels request")
.Cast<jni::Throwable>());
}
mCapturePixelsResults.pop();
}
}
}
java::sdk::Surface::Param GetSurface() { return mSurface; }
private:
already_AddRefed<DataSourceSurface> FlipScreenPixels(
Shmem& aMem, const ScreenIntSize& aInSize, const ScreenRect& aInRegion,
const IntSize& aOutSize) {
RefPtr<gfx::DataSourceSurface> image =
gfx::Factory::CreateWrappingDataSourceSurface(
aMem.get<uint8_t>(),
StrideForFormatAndWidth(SurfaceFormat::B8G8R8A8, aInSize.width),
IntSize(aInSize.width, aInSize.height), SurfaceFormat::B8G8R8A8);
RefPtr<gfx::DrawTarget> drawTarget =
gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
aOutSize, SurfaceFormat::B8G8R8A8);
if (!drawTarget) {
return nullptr;
}
drawTarget->SetTransform(Matrix::Scaling(1.0, -1.0) *
Matrix::Translation(0, aOutSize.height));
gfx::Rect srcRect(aInRegion.x,
(aInSize.height - aInRegion.height) - aInRegion.y,
aInRegion.width, aInRegion.height);
gfx::Rect destRect(0, 0, aOutSize.width, aOutSize.height);
drawTarget->DrawSurface(image, destRect, srcRect);
RefPtr<gfx::SourceSurface> snapshot = drawTarget->Snapshot();
RefPtr<gfx::DataSourceSurface> data = snapshot->GetDataSurface();
return data.forget();
}
/**
* Compositor methods
*/
public:
void AttachNPZC(jni::Object::Param aNPZC) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aNPZC);
auto locked(mWindow.Access());
if (!locked) {
return; // Already shut down.
}
nsWindow* gkWindow = locked->GetNsWindow();
// We can have this situation if we get two GeckoViewSupport::Transfer()
// called before the first AttachNPZC() gets here. Just detach the current
// instance since that's what happens in GeckoViewSupport::Transfer() as
// well.
gkWindow->mNPZCSupport.Detach();
auto npzc = java::PanZoomController::NativeProvider::LocalRef(
jni::GetGeckoThreadEnv(),
java::PanZoomController::NativeProvider::Ref::From(aNPZC));
gkWindow->mNPZCSupport =
jni::NativeWeakPtrHolder<NPZCSupport>::Attach(npzc, mWindow, npzc);
DispatchToUiThread(
"LayerViewSupport::AttachNPZC",
[npzc = java::PanZoomController::NativeProvider::GlobalRef(npzc)] {
npzc->SetAttached(true);
});
}
void OnBoundsChanged(int32_t aLeft, int32_t aTop, int32_t aWidth,
int32_t aHeight) {
MOZ_ASSERT(NS_IsMainThread());
auto acc = mWindow.Access();
if (!acc) {
return; // Already shut down.
}
nsWindow* gkWindow = acc->GetNsWindow();
if (!gkWindow) {
return;
}
gkWindow->DoResize(aLeft, aTop, aWidth, aHeight, /* repaint */ false);
}
void NotifyMemoryPressure() {
MOZ_ASSERT(NS_IsMainThread());
auto acc = mWindow.Access();
if (!acc) {
return; // Already shut down.
}
nsWindow* gkWindow = acc->GetNsWindow();
if (!gkWindow || !gkWindow->mCompositorBridgeChild) {
return;
}
gkWindow->mCompositorBridgeChild->SendNotifyMemoryPressure();
}
void SetDynamicToolbarMaxHeight(int32_t aHeight) {
MOZ_ASSERT(NS_IsMainThread());
auto acc = mWindow.Access();
if (!acc) {
return; // Already shut down.
}
nsWindow* gkWindow = acc->GetNsWindow();
if (!gkWindow) {
return;
}
gkWindow->UpdateDynamicToolbarMaxHeight(ScreenIntCoord(aHeight));
}
void OnPipModeChanged(bool aPipMode) {
MOZ_ASSERT(NS_IsMainThread());
auto win(mWindow.Access());
if (!win) {
return; // Already shut down.
}
nsWindow* gkWindow = win->GetNsWindow();
if (!gkWindow) {
return;
}
gkWindow->PipModeChanged(aPipMode);
}
void OnKeyboardHeightChanged(int32_t aHeight) {
MOZ_ASSERT(NS_IsMainThread());
auto win(mWindow.Access());
if (!win) {
return; // Already shut down.
}
nsWindow* gkWindow = win->GetNsWindow();
if (!gkWindow) {
return;
}
gkWindow->KeyboardHeightChanged(ScreenIntCoord(aHeight));
}
void SyncPauseCompositor() {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
// Set this true prior to attempting to pause the compositor, so that if
// pausing fails the subsequent recovery knows to initialize the compositor
// in a paused state.
mCompositorPaused = true;
if (mUiCompositorControllerChild) {
mUiCompositorControllerChild->Pause();
mSurface = nullptr;
mSurfaceControl = nullptr;
if (auto window = mWindow.Access()) {
nsWindow* gkWindow = window->GetNsWindow();
if (gkWindow) {
mUiCompositorControllerChild->OnCompositorSurfaceChanged(
gkWindow->mWidgetId, nullptr);
}
}
}
if (auto lock{mWindow.Access()}) {
while (!mCapturePixelsResults.empty()) {
auto result =
java::GeckoResult::LocalRef(mCapturePixelsResults.front().mResult);
if (result) {
result->CompleteExceptionally(
java::sdk::IllegalStateException::New(
"The compositor has detached from the session")
.Cast<jni::Throwable>());
}
mCapturePixelsResults.pop();
}
}
}
void SyncResumeCompositor() {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
// Set this false prior to attempting to resume the compositor, so that if
// resumption fails the subsequent recovery knows to initialize the
// compositor in a resumed state.
mCompositorPaused = false;
if (mUiCompositorControllerChild) {
bool resumed = mUiCompositorControllerChild->Resume();
if (!resumed) {
gfxCriticalNote
<< "Failed to resume compositor from SyncResumeCompositor";
RequestNewSurface();
}
}
}
void SyncResumeResizeCompositor(
const GeckoSession::Compositor::LocalRef& aObj, int32_t aX, int32_t aY,
int32_t aWidth, int32_t aHeight, jni::Object::Param aSurface,
jni::Object::Param aSurfaceControl) {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
// Set this false prior to attempting to resume the compositor, so that if
// resumption fails the subsequent recovery knows to initialize the
// compositor in a resumed state.
mCompositorPaused = false;
mX = aX;
mY = aY;
mWidth = aWidth;
mHeight = aHeight;
if (StaticPrefs::widget_android_use_surfacecontrol_AtStartup()) {
mSurfaceControl =
java::sdk::SurfaceControl::GlobalRef::From(aSurfaceControl);
}
if (mSurfaceControl) {
// When using SurfaceControl, we create a child Surface to render in to
// rather than rendering directly in to the Surface provided by the
// application. This allows us to work around a bug on some versions of
// Android when recovering from a GPU process crash.
mSurface = java::SurfaceControlManager::GetInstance()->GetChildSurface(
mSurfaceControl, mWidth, mHeight);
} else {
mSurface = java::sdk::Surface::GlobalRef::From(aSurface);
}
if (mUiCompositorControllerChild) {
if (auto window = mWindow.Access()) {
nsWindow* gkWindow = window->GetNsWindow();
if (gkWindow) {
// Send new Surface to GPU process, if one exists.
mUiCompositorControllerChild->OnCompositorSurfaceChanged(
gkWindow->mWidgetId, mSurface);
}
}
bool resumed = mUiCompositorControllerChild->ResumeAndResize(
aX, aY, aWidth, aHeight);
if (!resumed) {
gfxCriticalNote
<< "Failed to resume compositor from SyncResumeResizeCompositor";
// Only request a new Surface if this SyncResumeAndResize call is not
// response to a previous request, otherwise we will get stuck in an
// infinite loop.
if (!mRequestedNewSurface) {
RequestNewSurface();
}
return;
}
}
mRequestedNewSurface = false;
class OnResumedEvent : public nsAppShell::Event {
GeckoSession::Compositor::GlobalRef mCompositor;
public:
explicit OnResumedEvent(GeckoSession::Compositor::GlobalRef&& aCompositor)
: mCompositor(std::move(aCompositor)) {}
void Run() override {
MOZ_ASSERT(NS_IsMainThread());
JNIEnv* const env = jni::GetGeckoThreadEnv();
const auto lvsHolder =
GetNative(GeckoSession::Compositor::LocalRef(env, mCompositor));
if (!lvsHolder) {
env->ExceptionClear();
return; // Already shut down.
}
auto lvs(lvsHolder->Access());
if (!lvs) {
env->ExceptionClear();
return; // Already shut down.
}
auto win = lvs->mWindow.Access();
if (!win) {
env->ExceptionClear();
return; // Already shut down.
}
// When we get here, the compositor has already been told to
// resume. This means it's now safe for layer updates to occur.
// Since we might have prevented one or more draw events from
// occurring while the compositor was paused, we need to
// schedule a draw event now.
if (!lvs->mCompositorPaused) {
nsWindow* const gkWindow = win->GetNsWindow();
if (gkWindow) {
gkWindow->RedrawAll();
}
}
}
};
// Use priority queue for timing-sensitive event.
nsAppShell::PostEvent(
MakeUnique<LayerViewEvent>(MakeUnique<OnResumedEvent>(aObj)));
}
void RequestNewSurface() {
if (const auto& compositor = GetJavaCompositor()) {
mRequestedNewSurface = true;
if (mSurfaceControl) {
java::SurfaceControlManager::GetInstance()->RemoveSurface(
mSurfaceControl);
}
compositor->RequestNewSurface();
}
}
mozilla::jni::Object::LocalRef GetMagnifiableSurface() {
return mozilla::jni::Object::LocalRef::From(GetSurface());
}
void SyncInvalidateAndScheduleComposite() {
if (!mUiCompositorControllerChild) {
return;
}
if (AndroidBridge::IsJavaUiThread()) {
mUiCompositorControllerChild->InvalidateAndRender();
return;
}
if (RefPtr<nsThread> uiThread = GetAndroidUiThread()) {
uiThread->Dispatch(NewRunnableMethod<>(
"LayerViewSupport::InvalidateAndRender",
mUiCompositorControllerChild,
&UiCompositorControllerChild::InvalidateAndRender),
nsIThread::DISPATCH_NORMAL);
}
}
void SetMaxToolbarHeight(int32_t aHeight) {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
if (mUiCompositorControllerChild) {
mUiCompositorControllerChild->SetMaxToolbarHeight(aHeight);
}
}
void SetFixedBottomOffset(int32_t aOffset) {
if (auto acc{mWindow.Access()}) {
nsWindow* gkWindow = acc->GetNsWindow();
if (gkWindow) {
gkWindow->UpdateDynamicToolbarOffset(ScreenIntCoord(aOffset));
}
}
if (RefPtr<nsThread> uiThread = GetAndroidUiThread()) {
uiThread->Dispatch(NS_NewRunnableFunction(
"LayerViewSupport::SetFixedBottomOffset", [this, offset = aOffset] {
if (mUiCompositorControllerChild) {
mUiCompositorControllerChild->SetFixedBottomOffset(offset);
}
}));
}
}
void SendToolbarAnimatorMessage(int32_t aMessage) {
if (!mUiCompositorControllerChild) {
return;
}
if (AndroidBridge::IsJavaUiThread()) {
mUiCompositorControllerChild->ToolbarAnimatorMessageFromUI(aMessage);
return;
}
if (RefPtr<nsThread> uiThread = GetAndroidUiThread()) {
uiThread->Dispatch(
NewRunnableMethod<int32_t>(
"LayerViewSupport::ToolbarAnimatorMessageFromUI",
mUiCompositorControllerChild,
&UiCompositorControllerChild::ToolbarAnimatorMessageFromUI,
aMessage),
nsIThread::DISPATCH_NORMAL);
}
}
void RecvToolbarAnimatorMessage(int32_t aMessage) {
auto compositor = GeckoSession::Compositor::LocalRef(mCompositor);
if (compositor) {
compositor->RecvToolbarAnimatorMessage(aMessage);
}
}
void SetDefaultClearColor(int32_t aColor) {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
mDefaultClearColor = Some((uint32_t)aColor);
if (mUiCompositorControllerChild) {
mUiCompositorControllerChild->SetDefaultClearColor((uint32_t)aColor);
}
}
void RequestScreenPixels(jni::Object::Param aResult,
jni::Object::Param aTarget, int32_t aXOffset,
int32_t aYOffset, int32_t aSrcWidth,
int32_t aSrcHeight, int32_t aOutWidth,
int32_t aOutHeight) {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
auto result = java::GeckoResult::LocalRef(aResult);
if (!mUiCompositorControllerChild) {
if (result) {
if (auto window = mWindow.Access()) {
result->CompleteExceptionally(
java::sdk::IllegalStateException::New(
"Compositor session lost prior to screen pixels request")
.Cast<jni::Throwable>());
}
}
return;
}
int size = 0;
if (auto window = mWindow.Access()) {
mCapturePixelsResults.push(CaptureRequest(
java::GeckoResult::GlobalRef(result),
java::sdk::Bitmap::GlobalRef(java::sdk::Bitmap::LocalRef(aTarget)),
ScreenRect(aXOffset, aYOffset, aSrcWidth, aSrcHeight),
IntSize(aOutWidth, aOutHeight)));
size = mCapturePixelsResults.size();
}
if (size == 1) {
mUiCompositorControllerChild->RequestScreenPixels();
}
}
void RecvScreenPixels(Shmem&& aMem, const ScreenIntSize& aSize,
bool aNeedsYFlip) {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
CaptureRequest request;
java::GeckoResult::LocalRef result = nullptr;
java::sdk::Bitmap::LocalRef bitmap = nullptr;
if (auto window = mWindow.Access()) {
// The result might have been already rejected if the compositor was
// detached from the session
if (!mCapturePixelsResults.empty()) {
request = mCapturePixelsResults.front();
result = java::GeckoResult::LocalRef(request.mResult);
bitmap = java::sdk::Bitmap::LocalRef(request.mBitmap);
mCapturePixelsResults.pop();
}
}
if (result) {
if (bitmap) {
RefPtr<DataSourceSurface> surf;
if (aNeedsYFlip) {
surf = FlipScreenPixels(aMem, aSize, request.mSource,
request.mOutputSize);
} else {
surf = gfx::Factory::CreateWrappingDataSourceSurface(
aMem.get<uint8_t>(),
StrideForFormatAndWidth(SurfaceFormat::B8G8R8A8, aSize.width),
IntSize(aSize.width, aSize.height), SurfaceFormat::B8G8R8A8);
}
if (surf) {
DataSourceSurface::ScopedMap smap(surf, DataSourceSurface::READ);
auto pixels = mozilla::jni::ByteBuffer::New(
reinterpret_cast<int8_t*>(smap.GetData()),
smap.GetStride() * request.mOutputSize.height);
bitmap->CopyPixelsFromBuffer(pixels);
result->Complete(bitmap);
} else {
result->CompleteExceptionally(
java::sdk::IllegalStateException::New(
"Failed to create flipped snapshot surface (probably out "
"of memory)")
.Cast<jni::Throwable>());
}
} else {
result->CompleteExceptionally(java::sdk::IllegalArgumentException::New(
"No target bitmap argument provided")
.Cast<jni::Throwable>());
}
}
// Pixels have been copied, so Dealloc Shmem
if (mUiCompositorControllerChild) {
mUiCompositorControllerChild->DeallocPixelBuffer(aMem);
if (auto window = mWindow.Access()) {
if (!mCapturePixelsResults.empty()) {
mUiCompositorControllerChild->RequestScreenPixels();
}
}
}
}
void EnableLayerUpdateNotifications(bool aEnable) {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
if (mUiCompositorControllerChild) {
mUiCompositorControllerChild->EnableLayerUpdateNotifications(aEnable);
}
}
void OnSafeAreaInsetsChanged(int32_t aTop, int32_t aRight, int32_t aBottom,
int32_t aLeft) {
MOZ_ASSERT(NS_IsMainThread());
auto win(mWindow.Access());
if (!win) {
return; // Already shut down.
}
nsWindow* gkWindow = win->GetNsWindow();
if (!gkWindow) {
return;
}
LayoutDeviceIntMargin safeAreaInsets(aTop, aRight, aBottom, aLeft);
gkWindow->UpdateSafeAreaInsets(safeAreaInsets);
}
};
GeckoViewSupport::~GeckoViewSupport() {
if (mWindow) {
mWindow->DetachNatives();
}
}
/* static */
void GeckoViewSupport::Open(
const jni::Class::LocalRef& aCls, GeckoSession::Window::Param aWindow,
jni::Object::Param aQueue, jni::Object::Param aCompositor,
jni::Object::Param aDispatcher, jni::Object::Param aSessionAccessibility,
jni::Object::Param aInitData, jni::String::Param aId,
jni::String::Param aChromeURI, bool aPrivateMode) {
MOZ_ASSERT(NS_IsMainThread());
PROFILER_MARKER_TEXT("Applink Startup", OTHER, {},
"GeckoViewSupport::Open"_ns);
AUTO_PROFILER_LABEL("mozilla::widget::GeckoViewSupport::Open", OTHER);
// We'll need gfxPlatform to be initialized to create a compositor later.
// Might as well do that now so that the GPU process launch can get a head
// start.
gfxPlatform::GetPlatform();
nsCOMPtr<nsIWindowWatcher> ww = do_GetService(NS_WINDOWWATCHER_CONTRACTID);
MOZ_RELEASE_ASSERT(ww);
nsAutoCString url;
if (aChromeURI) {
url = aChromeURI->ToCString();
} else {
nsresult rv = Preferences::GetCString("toolkit.defaultChromeURI", url);
if (NS_FAILED(rv)) {
url = "chrome://geckoview/content/geckoview.xhtml"_ns;
}
}
// Prepare an nsIGeckoViewView to pass as argument to the window.
RefPtr<AndroidView> androidView = new AndroidView();
androidView->mEventDispatcher->Attach(
java::EventDispatcher::Ref::From(aDispatcher));
androidView->mInitData = java::GeckoBundle::Ref::From(aInitData);
nsAutoCString chromeFlags("chrome,dialog=0,remote,resizable,scrollbars");
if (aPrivateMode) {
chromeFlags += ",private";
}
nsCOMPtr<mozIDOMWindowProxy> domWindow;
ww->OpenWindow(nullptr, url, nsDependentCString(aId->ToCString().get()),
chromeFlags, androidView, getter_AddRefs(domWindow));
MOZ_RELEASE_ASSERT(domWindow);
nsCOMPtr<nsPIDOMWindowOuter> pdomWindow = nsPIDOMWindowOuter::From(domWindow);
const RefPtr<nsWindow> window = nsWindow::From(pdomWindow);
MOZ_ASSERT(window);
// Attach a new GeckoView support object to the new window.
GeckoSession::Window::LocalRef sessionWindow(aCls.Env(), aWindow);
auto weakGeckoViewSupport =
jni::NativeWeakPtrHolder<GeckoViewSupport>::Attach(
sessionWindow, window, sessionWindow, pdomWindow);
window->mGeckoViewSupport = weakGeckoViewSupport;
window->mAndroidView = androidView;
// Attach other session support objects.
{ // Scope for gvsAccess
auto gvsAccess = weakGeckoViewSupport.Access();
MOZ_ASSERT(gvsAccess);
gvsAccess->Transfer(sessionWindow, aQueue, aCompositor, aDispatcher,
aSessionAccessibility, aInitData);
}
if (window->mWidgetListener) {
nsCOMPtr<nsIAppWindow> appWindow(window->mWidgetListener->GetAppWindow());
if (appWindow) {
// Our window is not intrinsically sized, so tell AppWindow to
// not set a size for us.
appWindow->SetIntrinsicallySized(false);
}
}
}
void GeckoViewSupport::Close() {
if (mWindow) {
if (mWindow->mAndroidView) {
mWindow->mAndroidView->mEventDispatcher->Detach();
}
mWindow = nullptr;
}
if (!mDOMWindow) {
return;
}
mDOMWindow->ForceClose();
mDOMWindow = nullptr;
mGeckoViewWindow = nullptr;
}
void GeckoViewSupport::Transfer(const GeckoSession::Window::LocalRef& inst,
jni::Object::Param aQueue,
jni::Object::Param aCompositor,
jni::Object::Param aDispatcher,
jni::Object::Param aSessionAccessibility,
jni::Object::Param aInitData) {
AssertIsOnMainThread();
mWindow->mNPZCSupport.Detach();
auto compositor = GeckoSession::Compositor::LocalRef(
inst.Env(), GeckoSession::Compositor::Ref::From(aCompositor));
bool attachLvs;
{ // Scope for lvsAccess
auto lvsAccess{mWindow->mLayerViewSupport.Access()};
// If we do not yet have mLayerViewSupport, or if the compositor has
// changed, then we must attach a new one.
attachLvs = !lvsAccess || lvsAccess->GetJavaCompositor() != compositor;
}
if (attachLvs) {
mWindow->mLayerViewSupport =
jni::NativeWeakPtrHolder<LayerViewSupport>::Attach(
compositor, mWindow->mGeckoViewSupport, compositor);
if (RefPtr<UiCompositorControllerChild> uiCompositorController =
mWindow->GetUiCompositorControllerChild()) {
DispatchToUiThread(
"LayerViewSupport::NotifyCompositorCreated",
[lvs = mWindow->mLayerViewSupport, uiCompositorController] {
if (auto lvsAccess{lvs.Access()}) {
lvsAccess->NotifyCompositorCreated(uiCompositorController);
}
});
}
}
MOZ_ASSERT(mWindow->mAndroidView);
mWindow->mAndroidView->mEventDispatcher->Attach(
java::EventDispatcher::Ref::From(aDispatcher));
RefPtr<jni::DetachPromise> promise = mWindow->mSessionAccessibility.Detach();
if (aSessionAccessibility) {
// SessionAccessibility's JNI object isn't released immediately, it uses
// recycled object, we have to wait for released object completely.
auto sa = java::SessionAccessibility::NativeProvider::LocalRef(
aSessionAccessibility);
promise->Then(
GetMainThreadSerialEventTarget(),
"GeckoViewSupprt::Transfer::SessionAccessibility",
[inst = GeckoSession::Window::GlobalRef(inst),
sa = java::SessionAccessibility::NativeProvider::GlobalRef(sa),
window = mWindow, gvs = mWindow->mGeckoViewSupport](
const mozilla::jni::DetachPromise::ResolveOrRejectValue& aValue) {
MOZ_ASSERT(aValue.IsResolve());
if (window->Destroyed()) {
return;
}
MOZ_ASSERT(!window->mSessionAccessibility.IsAttached());
if (auto gvsAccess{gvs.Access()}) {
gvsAccess->AttachAccessibility(inst, sa);
}
});
}
if (mIsReady) {
// We're in a transfer; update init-data and notify JS code.
mWindow->mAndroidView->mInitData = java::GeckoBundle::Ref::From(aInitData);
OnReady(aQueue);
mWindow->mAndroidView->mEventDispatcher->Dispatch(
u"GeckoView:UpdateInitData"_ns, JS::NullHandleValue);
}
DispatchToUiThread("GeckoViewSupport::Transfer",
[compositor = GeckoSession::Compositor::GlobalRef(
compositor)] { compositor->OnCompositorAttached(); });
}
void GeckoViewSupport::AttachEditable(
const GeckoSession::Window::LocalRef& inst,
jni::Object::Param aEditableParent) {
if (auto win{mWindow->mEditableSupport.Access()}) {
win->TransferParent(aEditableParent);
} else {
auto editableChild = java::GeckoEditableChild::New(aEditableParent,
/* default */ true);
mWindow->mEditableSupport =
jni::NativeWeakPtrHolder<GeckoEditableSupport>::Attach(
editableChild, mWindow->mGeckoViewSupport, editableChild);
}
mWindow->mEditableParent = aEditableParent;
}
void GeckoViewSupport::AttachAccessibility(
const GeckoSession::Window::LocalRef& inst,
jni::Object::Param aSessionAccessibility) {
java::SessionAccessibility::NativeProvider::LocalRef sessionAccessibility(
inst.Env());
sessionAccessibility = java::SessionAccessibility::NativeProvider::Ref::From(
aSessionAccessibility);
mWindow->mSessionAccessibility =
jni::NativeWeakPtrHolder<a11y::SessionAccessibility>::Attach(
sessionAccessibility, mWindow->mGeckoViewSupport,
sessionAccessibility);
DispatchToUiThread(
"GeckoViewSupport::AttachAccessibility",
[sa = java::SessionAccessibility::NativeProvider::GlobalRef(
sessionAccessibility)] { sa->SetAttached(true); });
}
auto GeckoViewSupport::OnLoadRequest(mozilla::jni::String::Param aUri,
int32_t aWindowType, int32_t aFlags,
mozilla::jni::String::Param aTriggeringUri,
bool aHasUserGesture,
bool aIsTopLevel) const
-> java::GeckoResult::LocalRef {
GeckoSession::Window::LocalRef window(mGeckoViewWindow);
if (!window) {
return nullptr;
}
return window->OnLoadRequest(aUri, aWindowType, aFlags, aTriggeringUri,
aHasUserGesture, aIsTopLevel);
}
void GeckoViewSupport::OnShowDynamicToolbar() const {
GeckoSession::Window::LocalRef window(mGeckoViewWindow);
if (!window) {
return;
}
window->OnShowDynamicToolbar();
}
void GeckoViewSupport::OnHideDynamicToolbar() const {
GeckoSession::Window::LocalRef window(mGeckoViewWindow);
if (!window) {
return;
}
window->OnHideDynamicToolbar();
}
void GeckoViewSupport::OnReady(jni::Object::Param aQueue) {
GeckoSession::Window::LocalRef window(mGeckoViewWindow);
if (!window) {
return;
}
window->OnReady(aQueue);
mIsReady = true;
}
void GeckoViewSupport::PassExternalResponse(
java::WebResponse::Param aResponse) {
GeckoSession::Window::LocalRef window(mGeckoViewWindow);
if (!window) {
return;
}
auto response = java::WebResponse::GlobalRef(aResponse);
DispatchToUiThread("GeckoViewSupport::PassExternalResponse",
[window = java::GeckoSession::Window::GlobalRef(window),
response] { window->PassExternalWebResponse(response); });
}
RefPtr<CanonicalBrowsingContext>
GeckoViewSupport::GetContentCanonicalBrowsingContext() {
nsCOMPtr<nsIDocShellTreeOwner> treeOwner = mDOMWindow->GetTreeOwner();
if (!treeOwner) {
return nullptr;
}
RefPtr<BrowsingContext> bc;
nsresult rv = treeOwner->GetPrimaryContentBrowsingContext(getter_AddRefs(bc));
if (NS_WARN_IF(NS_FAILED(rv)) || !bc) {
return nullptr;
}
return bc->Canonical();
}
void GeckoViewSupport::CreatePdf(
jni::LocalRef<mozilla::java::GeckoResult> aGeckoResult,
RefPtr<dom::CanonicalBrowsingContext> aCbc) {
MOZ_ASSERT(NS_IsMainThread());
const auto pdfErrorMsg = "Could not save this page as PDF.";
auto stream = java::GeckoInputStream::New(nullptr);
RefPtr<GeckoViewOutputStream> streamListener =
new GeckoViewOutputStream(stream);
nsCOMPtr<nsIPrintSettingsService> printSettingsService =
do_GetService("@mozilla.org/gfx/printsettings-service;1");
if (!printSettingsService) {
aGeckoResult->CompleteExceptionally(
GeckoPrintException::New(
GeckoPrintException::ERROR_PRINT_SETTINGS_SERVICE_NOT_AVAILABLE)
.Cast<jni::Throwable>());
GVS_LOG("Could not create print settings service.");
return;
}
nsCOMPtr<nsIPrintSettings> printSettings;
nsresult rv = printSettingsService->CreateNewPrintSettings(
getter_AddRefs(printSettings));
if (NS_WARN_IF(NS_FAILED(rv))) {
aGeckoResult->CompleteExceptionally(
GeckoPrintException::New(
GeckoPrintException::ERROR_UNABLE_TO_CREATE_PRINT_SETTINGS)
.Cast<jni::Throwable>());
GVS_LOG("Could not create print settings.");
return;
}
printSettings->SetPrinterName(u"Mozilla Save to PDF"_ns);
printSettings->SetOutputDestination(
nsIPrintSettings::kOutputDestinationStream);
printSettings->SetOutputFormat(nsIPrintSettings::kOutputFormatPDF);
printSettings->SetOutputStream(streamListener);
printSettings->SetPrintSilent(true);
RefPtr<CanonicalBrowsingContext::PrintPromise> print =
aCbc->Print(printSettings);
aGeckoResult->Complete(stream);
print->Then(
mozilla::GetCurrentSerialEventTarget(), __func__,
[result = java::GeckoResult::GlobalRef(aGeckoResult), stream,
pdfErrorMsg](
const CanonicalBrowsingContext::PrintPromise::ResolveOrRejectValue&
aValue) {
if (aValue.IsReject()) {
GVS_LOG("Could not print. %s", pdfErrorMsg);
stream->WriteError();
}
});
}
void GeckoViewSupport::PrintToPdf(
const java::GeckoSession::Window::LocalRef& inst,
jni::Object::Param aResult) {
auto geckoResult = java::GeckoResult::Ref::From(aResult);
RefPtr<CanonicalBrowsingContext> cbc = GetContentCanonicalBrowsingContext();
if (!cbc) {
geckoResult->CompleteExceptionally(
GeckoPrintException::New(
GeckoPrintException::
ERROR_UNABLE_TO_RETRIEVE_CANONICAL_BROWSING_CONTEXT)
.Cast<jni::Throwable>());
GVS_LOG("Could not retrieve content canonical browsing context.");
return;
}
CreatePdf(geckoResult, cbc);
}
void GeckoViewSupport::PrintToPdf(
const java::GeckoSession::Window::LocalRef& inst,
jni::Object::Param aResult, int64_t aBcId) {
auto geckoResult = java::GeckoResult::Ref::From(aResult);
RefPtr<CanonicalBrowsingContext> cbc = CanonicalBrowsingContext::Get(aBcId);
if (!cbc) {
geckoResult->CompleteExceptionally(
GeckoPrintException::New(
GeckoPrintException::
ERROR_UNABLE_TO_RETRIEVE_CANONICAL_BROWSING_CONTEXT)
.Cast<jni::Throwable>());
GVS_LOG("Could not retrieve content canonical browsing context by ID.");
return;
}
CreatePdf(geckoResult, cbc);
}
} // namespace widget
} // namespace mozilla
void nsWindow::InitNatives() {
jni::InitConversionStatics();
mozilla::widget::GeckoViewSupport::Base::Init();
mozilla::widget::LayerViewSupport::Init();
mozilla::widget::NPZCSupport::Init();
mozilla::widget::GeckoEditableSupport::Init();
a11y::SessionAccessibility::Init();
}
void nsWindow::DetachNatives() {
MOZ_ASSERT(NS_IsMainThread());
mEditableSupport.Detach();
mNPZCSupport.Detach();
mLayerViewSupport.Detach();
mSessionAccessibility.Detach();
}
/* static */
already_AddRefed<nsWindow> nsWindow::From(nsPIDOMWindowOuter* aDOMWindow) {
nsCOMPtr<nsIWidget> widget = WidgetUtils::DOMWindowToWidget(aDOMWindow);
return From(widget);
}
/* static */
already_AddRefed<nsWindow> nsWindow::From(nsIWidget* aWidget) {
// `widget` may be one of several different types in the parent
// process, including the Android nsWindow, PuppetWidget, etc. To
// ensure that the cast to the Android nsWindow is valid, we check that the
// widget is a top-level window and that its NS_NATIVE_WIDGET value is
// non-null, which is not the case for non-native widgets like
// PuppetWidget.
if (aWidget && aWidget->GetWindowType() == WindowType::TopLevel &&
aWidget->GetNativeData(NS_NATIVE_WIDGET) == aWidget) {
RefPtr<nsWindow> window = static_cast<nsWindow*>(aWidget);
return window.forget();
}
return nullptr;
}
nsWindow* nsWindow::TopWindow() {
if (!gTopLevelWindows.IsEmpty()) return gTopLevelWindows[0];
return nullptr;
}
void nsWindow::LogWindow(nsWindow* win, int index, int indent) {
#if defined(DEBUG) || defined(FORCE_ALOG)
char spaces[] = " ";
spaces[indent < 20 ? indent : 20] = 0;
ALOG("%s [% 2d] 0x%p [parent 0x%p] [% 3d,% 3dx% 3d,% 3d] vis %d type %d",
spaces, index, win, win->mParent, win->mBounds.x, win->mBounds.y,
win->mBounds.width, win->mBounds.height, win->mIsVisible,
int(win->mWindowType));
int i = 0;
for (nsIWidget* kid = win->mFirstChild; kid; kid = kid->GetNextSibling()) {
LogWindow(static_cast<nsWindow*>(kid), i++, indent + 1);
}
#endif
}
void nsWindow::DumpWindows() { DumpWindows(gTopLevelWindows); }
void nsWindow::DumpWindows(const nsTArray<nsWindow*>& wins, int indent) {
for (uint32_t i = 0; i < wins.Length(); ++i) {
nsWindow* w = wins[i];
LogWindow(w, i, indent);
}
}
nsWindow::nsWindow() : mWidgetId(++sWidgetId) {}
nsWindow::~nsWindow() {
gTopLevelWindows.RemoveElement(this);
ALOG("nsWindow %p destructor", (void*)this);
// The mCompositorSession should have been cleaned up in nsWindow::Destroy()
// DestroyLayerManager() will call DestroyCompositor() which will crash if
// called from nsIWidget destructor. See Bug 1392705
MOZ_ASSERT(!mCompositorSession);
}
bool nsWindow::IsTopLevel() {
return mWindowType == WindowType::TopLevel ||
mWindowType == WindowType::Dialog;
}
nsresult nsWindow::Create(nsIWidget* aParent, const LayoutDeviceIntRect& aRect,
const InitData& aInitData) {
ALOG("nsWindow[%p]::Create %p [%d %d %d %d]", (void*)this, (void*)aParent,
aRect.x, aRect.y, aRect.width, aRect.height);
// A default size of 1x1 confuses MobileViewportManager, so
// use 0x0 instead. This is also a little more fitting since
// we don't yet have a surface yet (and therefore a valid size)
// and 0x0 is usually recognized as invalid.
LayoutDeviceIntRect rect = aRect;
if (aRect.width == 1 && aRect.height == 1) {
rect.width = 0;
rect.height = 0;
}
mBounds = rect;
SetSizeConstraints(SizeConstraints());
MOZ_DIAGNOSTIC_ASSERT(aInitData.mWindowType != WindowType::Invisible);
BaseCreate(aParent, aInitData);
MOZ_ASSERT_IF(!IsTopLevel(), aParent);
if (IsTopLevel()) {
gTopLevelWindows.AppendElement(this);
}
#ifdef DEBUG_ANDROID_WIDGET
DumpWindows();
#endif
return NS_OK;
}
void nsWindow::Destroy() {
MutexAutoLock lock(mDestroyMutex);
nsIWidget::mOnDestroyCalled = true;
// Disassociate our native object from GeckoView.
mGeckoViewSupport.Detach();
// Stuff below may release the last ref to this
nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
// Ensure the compositor has been shutdown before this nsWindow is potentially
// deleted
nsIWidget::DestroyCompositor();
nsIWidget::Destroy();
if (IsTopLevel()) {
gTopLevelWindows.RemoveElement(this);
}
nsIWidget::OnDestroy();
#ifdef DEBUG_ANDROID_WIDGET
DumpWindows();
#endif
}
mozilla::widget::EventDispatcher* nsWindow::GetEventDispatcher() const {
if (mAndroidView) {
return mAndroidView->mEventDispatcher;
}
return nullptr;
}
void nsWindow::RedrawAll() {
if (mAttachedWidgetListener) {
mAttachedWidgetListener->RequestRepaint();
} else if (mWidgetListener) {
mWidgetListener->RequestRepaint();
}
}
RefPtr<UiCompositorControllerChild> nsWindow::GetUiCompositorControllerChild() {
return mCompositorSession
? mCompositorSession->GetUiCompositorControllerChild()
: nullptr;
}
mozilla::layers::LayersId nsWindow::GetRootLayerId() const {
return mCompositorSession ? mCompositorSession->RootLayerTreeId()
: mozilla::layers::LayersId{0};
}
void nsWindow::OnGeckoViewReady() {
auto acc(mGeckoViewSupport.Access());
if (!acc) {
return;
}
acc->OnReady();
}
void nsWindow::DidClearParent(nsIWidget*) {
// if we are now in the toplevel window's hierarchy, schedule a redraw
if (FindTopLevel() == nsWindow::TopWindow()) {
RedrawAll();
}
}
RefPtr<MozPromise<bool, bool, false>> nsWindow::OnLoadRequest(
nsIURI* aUri, int32_t aWindowType, int32_t aFlags,
nsIPrincipal* aTriggeringPrincipal, bool aHasUserGesture,
bool aIsTopLevel) {
auto geckoViewSupport(mGeckoViewSupport.Access());
if (!geckoViewSupport) {
return MozPromise<bool, bool, false>::CreateAndResolve(false, __func__);
}
nsAutoCString spec, triggeringSpec;
if (aUri) {
aUri->GetDisplaySpec(spec);
if (aIsTopLevel && aUri->SchemeIs("data") &&
spec.Length() > MAX_TOPLEVEL_DATA_URI_LEN) {
return MozPromise<bool, bool, false>::CreateAndResolve(false, __func__);
}
}
bool isNullPrincipal = false;
if (aTriggeringPrincipal) {
aTriggeringPrincipal->GetIsNullPrincipal(&isNullPrincipal);
if (!isNullPrincipal) {
nsCOMPtr<nsIURI> triggeringUri;
BasePrincipal::Cast(aTriggeringPrincipal)
->GetURI(getter_AddRefs(triggeringUri));
if (triggeringUri) {
triggeringUri->GetDisplaySpec(triggeringSpec);
}
}
}
auto geckoResult = geckoViewSupport->OnLoadRequest(
spec.get(), aWindowType, aFlags,
isNullPrincipal ? nullptr : triggeringSpec.get(), aHasUserGesture,
aIsTopLevel);
return geckoResult
? MozPromise<bool, bool, false>::FromGeckoResult(geckoResult)
: nullptr;
}
float nsWindow::GetDPI() {
float dpi = 160.0f;
nsCOMPtr<nsIScreen> screen = GetWidgetScreen();
if (screen) {
screen->GetDpi(&dpi);
}
return dpi;
}
double nsWindow::GetDefaultScaleInternal() {
double scale = 1.0f;
nsCOMPtr<nsIScreen> screen = GetWidgetScreen();
if (screen) {
screen->GetContentsScaleFactor(&scale);
}
return scale;
}
void nsWindow::Show(bool aState) {
ALOG("nsWindow[%p]::Show %d", (void*)this, aState);
if (mWindowType == WindowType::Invisible) {
ALOG("trying to show invisible window! ignoring..");
return;
}
if (aState == mIsVisible) return;
mIsVisible = aState;
if (IsTopLevel()) {
// XXX should we bring this to the front when it's shown,
// if it's a toplevel widget?
// XXX we should synthesize a eMouseExitFromWidget (for old top
// window)/eMouseEnterIntoWidget (for new top window) since we need
// to pretend that the top window always has focus. Not sure
// if Show() is the right place to do this, though.
if (aState) {
// It just became visible, so bring it to the front.
BringToFront();
} else if (nsWindow::TopWindow() == this) {
// find the next visible window to show
unsigned int i;
for (i = 1; i < gTopLevelWindows.Length(); i++) {
nsWindow* win = gTopLevelWindows[i];
if (!win->mIsVisible) {
continue;
}
win->BringToFront();
break;
}
}
} else if (FindTopLevel() == nsWindow::TopWindow()) {
RedrawAll();
}
#ifdef DEBUG_ANDROID_WIDGET
DumpWindows();
#endif
}
bool nsWindow::IsVisible() const { return mIsVisible; }
void nsWindow::ConstrainPosition(DesktopIntPoint& aPoint) {
ALOG("nsWindow[%p]::ConstrainPosition [%d %d]", this, aPoint.x.value,
aPoint.y.value);
// Constrain toplevel windows; children we don't care about
if (IsTopLevel()) {
aPoint = DesktopIntPoint();
}
}
void nsWindow::Move(const DesktopPoint& aPoint) {
if (IsTopLevel()) {
return;
}
DoResize(aPoint.x, aPoint.y, mBounds.width, mBounds.height, true);
}
void nsWindow::Resize(const DesktopSize& aSize, bool aRepaint) {
DoResize(mBounds.x, mBounds.y, aSize.width, aSize.height, aRepaint);
}
void nsWindow::Resize(const DesktopRect& aRect, bool aRepaint) {
DoResize(aRect.x, aRect.y, aRect.width, aRect.height, aRepaint);
}
void nsWindow::DoResize(double aX, double aY, double aWidth, double aHeight,
bool aRepaint) {
ALOG("nsWindow[%p]::DoResize [%f %f %f %f] (repaint %d)", this, aX, aY,
aWidth, aHeight, aRepaint);
LayoutDeviceIntRect oldBounds = mBounds;
mBounds.x = NSToIntRound(aX);
mBounds.y = NSToIntRound(aY);
mBounds.width = NSToIntRound(aWidth);
mBounds.height = NSToIntRound(aHeight);
ConstrainSize(&mBounds.width, &mBounds.height);
bool needPositionDispatch = mBounds.TopLeft() != oldBounds.TopLeft();
bool needSizeDispatch = mBounds.Size() != oldBounds.Size();
if (needSizeDispatch) {
OnSizeChanged(mBounds.Size().ToUnknownSize());
}
if (needPositionDispatch) {
NotifyWindowMoved(mBounds.x, mBounds.y);
}
// Should we skip honoring aRepaint here?
if (aRepaint && FindTopLevel() == nsWindow::TopWindow()) RedrawAll();
}
void nsWindow::SetSizeMode(nsSizeMode aMode) {
if (aMode == mSizeMode) {
return;
}
mSizeMode = aMode;
switch (aMode) {
case nsSizeMode_Minimized:
java::GeckoAppShell::MoveTaskToBack();
break;
case nsSizeMode_Fullscreen:
MakeFullScreen(true);
break;
default:
break;
}
}
void nsWindow::Enable(bool aState) {
ALOG("nsWindow[%p]::Enable %d ignored", (void*)this, aState);
}
bool nsWindow::IsEnabled() const { return true; }
void nsWindow::Invalidate(const LayoutDeviceIntRect& aRect) {}
nsWindow* nsWindow::FindTopLevel() {
nsWindow* toplevel = this;
while (toplevel) {
if (toplevel->IsTopLevel()) {
return toplevel;
}
toplevel = static_cast<nsWindow*>(toplevel->mParent);
}
ALOG(
"nsWindow::FindTopLevel(): couldn't find a toplevel or dialog window in "
"this [%p] widget's hierarchy!",
(void*)this);
return this;
}
void nsWindow::SetFocus(Raise, mozilla::dom::CallerType aCallerType) {
FindTopLevel()->BringToFront();
}
void nsWindow::BringToFront() {
MOZ_ASSERT(XRE_IsParentProcess());
// If the window to be raised is the same as the currently raised one,
// do nothing. We need to check the focus manager as well, as the first
// window that is created will be first in the window list but won't yet
// be focused.
nsFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm && fm->GetActiveWindow() && FindTopLevel() == nsWindow::TopWindow()) {
return;
}
if (!IsTopLevel()) {
FindTopLevel()->BringToFront();
return;
}
RefPtr<nsWindow> kungFuDeathGrip(this);
nsWindow* oldTop = nullptr;
if (!gTopLevelWindows.IsEmpty()) {
oldTop = gTopLevelWindows[0];
}
gTopLevelWindows.RemoveElement(this);
gTopLevelWindows.InsertElementAt(0, this);
if (oldTop) {
nsIWidgetListener* listener = oldTop->GetWidgetListener();
if (listener) {
listener->WindowDeactivated();
}
}
if (mWidgetListener) {
mWidgetListener->WindowActivated();
}
RedrawAll();
}
LayoutDeviceIntRect nsWindow::GetScreenBounds() {
return LayoutDeviceIntRect(WidgetToScreenOffset(), mBounds.Size());
}
LayoutDeviceIntPoint nsWindow::WidgetToScreenOffset() {
LayoutDeviceIntPoint p(0, 0);
for (nsWindow* w = this; !!w; w = static_cast<nsWindow*>(w->mParent)) {
p += w->mBounds.TopLeft();
if (w->IsTopLevel()) {
break;
}
}
return p;
}
nsresult nsWindow::DispatchEvent(WidgetGUIEvent* aEvent,
nsEventStatus& aStatus) {
aStatus = DispatchEvent(aEvent);
return NS_OK;
}
nsEventStatus nsWindow::DispatchEvent(WidgetGUIEvent* aEvent) {
if (mAttachedWidgetListener) {
return mAttachedWidgetListener->HandleEvent(aEvent, mUseAttachedEvents);
} else if (mWidgetListener) {
return mWidgetListener->HandleEvent(aEvent, mUseAttachedEvents);
}
return nsEventStatus_eIgnore;
}
nsresult nsWindow::MakeFullScreen(bool aFullScreen) {
AssertIsOnMainThread();
if (!mAndroidView) {
return NS_ERROR_NOT_AVAILABLE;
}
mIsFullScreen = aFullScreen;
mAndroidView->mEventDispatcher->Dispatch(aFullScreen
? u"GeckoView:FullScreenEnter"_ns
: u"GeckoView:FullScreenExit"_ns,
JS::NullHandleValue);
nsIWidgetListener* listener = GetWidgetListener();
if (listener) {
mSizeMode = mIsFullScreen ? nsSizeMode_Fullscreen : nsSizeMode_Normal;
listener->SizeModeChanged(mSizeMode);
}
return NS_OK;
}
mozilla::WindowRenderer* nsWindow::GetWindowRenderer() {
if (!mWindowRenderer) {
CreateLayerManager();
}
return mWindowRenderer;
}
void nsWindow::CreateLayerManager() {
if (mWindowRenderer) {
return;
}
nsWindow* topLevelWindow = FindTopLevel();
if (!topLevelWindow || topLevelWindow->mWindowType == WindowType::Invisible) {
// don't create a layer manager for an invisible top-level window
return;
}
// Ensure that gfxPlatform is initialized first.
gfxPlatform::GetPlatform();
if (ShouldUseOffMainThreadCompositing()) {
LayoutDeviceIntRect rect = GetBounds();
CreateCompositor(rect.Width(), rect.Height());
if (mWindowRenderer) {
if (mLayerViewSupport.IsAttached()) {
DispatchToUiThread(
"LayerViewSupport::NotifyCompositorCreated",
[lvs = mLayerViewSupport,
uiCompositorController = GetUiCompositorControllerChild()] {
if (auto lvsAccess{lvs.Access()}) {
lvsAccess->NotifyCompositorCreated(uiCompositorController);
}
});
}
return;
}
}
if (ComputeShouldAccelerate()) {
mWindowRenderer = CreateBackgroundedFallbackRenderer();
} else {
printf_stderr(" -- creating basic, not accelerated\n");
mWindowRenderer = CreateFallbackRenderer();
}
}
void nsWindow::NotifyCompositorSessionLost(
mozilla::layers::CompositorSession* aSession) {
nsIWidget::NotifyCompositorSessionLost(aSession);
DispatchToUiThread("nsWindow::NotifyCompositorSessionLost",
[lvs = mLayerViewSupport] {
if (auto lvsAccess{lvs.Access()}) {
lvsAccess->NotifyCompositorSessionLost();
}
});
RedrawAll();
}
void nsWindow::ShowDynamicToolbar() {
auto acc(mGeckoViewSupport.Access());
if (!acc) {
return;
}
acc->OnShowDynamicToolbar();
}
void nsWindow::OnDragEvent(int32_t aAction, float aX, float aY,
jni::Object::Param aDropData,
const mozilla::layers::APZEventResult& aApzResult,
const MouseInput& aInput) {
MOZ_ASSERT(NS_IsMainThread());
LayoutDeviceIntPoint point =
LayoutDeviceIntPoint(int32_t(floorf(aX)), int32_t(floorf(aY)));
RefPtr<nsDragService> dragService = nsDragService::GetInstance();
if (!dragService) {
return;
}
RefPtr<nsDragSession> dragSession =
static_cast<nsDragSession*>(dragService->GetCurrentSession(this));
if (aAction == java::sdk::DragEvent::ACTION_DRAG_STARTED) {
if (dragSession) {
dragSession->SetDragEndPoint(point.x, point.y);
}
return;
}
if (aAction == java::sdk::DragEvent::ACTION_DRAG_ENDED) {
if (dragSession) {
dragSession->EndDragSession(false, 0);
}
return;
}
if (aAction == java::sdk::DragEvent::ACTION_DRAG_ENTERED) {
nsIWidget* widget = this;
dragSession =
static_cast<nsDragSession*>(dragService->StartDragSession(widget));
// For compatibility, we have to set temporary data.
auto dropData =
mozilla::java::GeckoDragAndDrop::DropData::Ref::From(aDropData);
dragSession->SetDropData(dropData);
}
if (dragSession) {
switch (aAction) {
case java::sdk::DragEvent::ACTION_DRAG_LOCATION:
dragSession->SetDragEndPoint(point.x, point.y);
dragSession->FireDragEventAtSource(eDrag, 0);
break;
case java::sdk::DragEvent::ACTION_DROP: {
bool canDrop = false;
dragSession->GetCanDrop(&canDrop);
if (!canDrop) {
nsCOMPtr<nsINode> sourceNode;
dragSession->GetSourceNode(getter_AddRefs(sourceNode));
if (!sourceNode) {
dragSession->EndDragSession(false, 0);
}
return;
}
auto dropData =
mozilla::java::GeckoDragAndDrop::DropData::Ref::From(aDropData);
dragSession->SetDropData(dropData);
dragSession->SetDragEndPoint(point.x, point.y);
break;
}
default:
break;
}
dragSession->SetDragAction(nsIDragService::DRAGDROP_ACTION_MOVE);
}
WidgetDragEvent geckoEvent = aInput.ToWidgetEvent<WidgetDragEvent>(this);
ProcessUntransformedAPZEvent(&geckoEvent, aApzResult);
if (!dragSession) {
return;
}
switch (aAction) {
case java::sdk::DragEvent::ACTION_DRAG_EXITED: {
nsCOMPtr<nsINode> sourceNode;
dragSession->GetSourceNode(getter_AddRefs(sourceNode));
if (!sourceNode) {
// We're leaving a window while doing a drag that was
// initiated in a different app. End the drag session,
// since we're done with it for now (until the user
// drags back into mozilla).
dragSession->EndDragSession(false, 0);
}
break;
}
case java::sdk::DragEvent::ACTION_DROP:
dragSession->EndDragSession(true, 0);
break;
default:
break;
}
}
void nsWindow::StartDragAndDrop(java::sdk::Bitmap::LocalRef aBitmap) {
if (mozilla::jni::NativeWeakPtr<LayerViewSupport>::Accessor lvs{
mLayerViewSupport.Access()}) {
const auto& compositor = lvs->GetJavaCompositor();
DispatchToUiThread(
"nsWindow::StartDragAndDrop",
[compositor = GeckoSession::Compositor::GlobalRef(compositor),
bitmap = java::sdk::Bitmap::GlobalRef(aBitmap)] {
compositor->StartDragAndDrop(bitmap);
});
}
}
void nsWindow::UpdateDragImage(java::sdk::Bitmap::LocalRef aBitmap) {
if (mozilla::jni::NativeWeakPtr<LayerViewSupport>::Accessor lvs{
mLayerViewSupport.Access()}) {
const auto& compositor = lvs->GetJavaCompositor();
DispatchToUiThread(
"nsWindow::UpdateDragImage",
[compositor = GeckoSession::Compositor::GlobalRef(compositor),
bitmap = java::sdk::Bitmap::GlobalRef(aBitmap)] {
compositor->UpdateDragImage(bitmap);
});
}
}
void nsWindow::OnSizeChanged(const gfx::IntSize& aSize) {
ALOG("nsWindow: %p OnSizeChanged [%d %d]", (void*)this, aSize.width,
aSize.height);
if (mWidgetListener) {
mWidgetListener->WindowResized(this, aSize.width, aSize.height);
}
if (mAttachedWidgetListener) {
mAttachedWidgetListener->WindowResized(this, aSize.width, aSize.height);
}
if (mCompositorWidgetDelegate) {
mCompositorWidgetDelegate->NotifyClientSizeChanged(
LayoutDeviceIntSize::FromUnknownSize(aSize));
}
}
void nsWindow::InitEvent(WidgetGUIEvent& event, LayoutDeviceIntPoint* aPoint) {
if (aPoint) {
event.mRefPoint = *aPoint;
} else {
event.mRefPoint = LayoutDeviceIntPoint(0, 0);
}
}
void nsWindow::UpdateOverscrollVelocity(const float aX, const float aY) {
if (::mozilla::jni::NativeWeakPtr<LayerViewSupport>::Accessor lvs{
mLayerViewSupport.Access()}) {
const auto& compositor = lvs->GetJavaCompositor();
if (AndroidBridge::IsJavaUiThread()) {
compositor->UpdateOverscrollVelocity(aX, aY);
return;
}
DispatchToUiThread(
"nsWindow::UpdateOverscrollVelocity",
[compositor = GeckoSession::Compositor::GlobalRef(compositor), aX, aY] {
compositor->UpdateOverscrollVelocity(aX, aY);
});
}
}
void nsWindow::UpdateOverscrollOffset(const float aX, const float aY) {
if (::mozilla::jni::NativeWeakPtr<LayerViewSupport>::Accessor lvs{
mLayerViewSupport.Access()}) {
const auto& compositor = lvs->GetJavaCompositor();
if (AndroidBridge::IsJavaUiThread()) {
compositor->UpdateOverscrollOffset(aX, aY);
return;
}
DispatchToUiThread(
"nsWindow::UpdateOverscrollOffset",
[compositor = GeckoSession::Compositor::GlobalRef(compositor), aX, aY] {
compositor->UpdateOverscrollOffset(aX, aY);
});
}
}
void nsWindow::HideDynamicToolbar() {
auto acc(mGeckoViewSupport.Access());
if (!acc) {
return;
}
acc->OnHideDynamicToolbar();
}
void* nsWindow::GetNativeData(uint32_t aDataType) {
switch (aDataType) {
// used by GLContextProviderEGL, nullptr is EGL_DEFAULT_DISPLAY
case NS_NATIVE_WIDGET:
return (void*)this;
case NS_RAW_NATIVE_IME_CONTEXT: {
void* pseudoIMEContext = GetPseudoIMEContext();
if (pseudoIMEContext) {
return pseudoIMEContext;
}
// We assume that there is only one context per process on Android
return NS_ONLY_ONE_NATIVE_IME_CONTEXT;
}
case NS_JAVA_SURFACE:
if (::mozilla::jni::NativeWeakPtr<LayerViewSupport>::Accessor lvs{
mLayerViewSupport.Access()}) {
return lvs->GetSurface().Get();
}
return nullptr;
}
return nullptr;
}
void nsWindow::DispatchHitTest(const WidgetTouchEvent& aEvent) {
if (aEvent.mMessage == eTouchStart && aEvent.mTouches.Length() == 1) {
// Since touch events don't get retargeted by PositionedEventTargeting.cpp
// code, we dispatch a dummy mouse event that *does* get retargeted.
// Front-end code can use this to activate the highlight element in case
// this touchstart is the start of a tap.
WidgetMouseEvent hittest(true, eMouseHitTest, this,
WidgetMouseEvent::eReal);
hittest.mRefPoint = aEvent.mTouches[0]->mRefPoint;
nsEventStatus status;
DispatchEvent(&hittest, status);
}
}
void nsWindow::PassExternalResponse(java::WebResponse::Param aResponse) {
if (Destroyed()) {
return;
}
auto acc(mGeckoViewSupport.Access());
if (!acc) {
return;
}
acc->PassExternalResponse(aResponse);
}
mozilla::Modifiers nsWindow::GetModifiers(int32_t metaState) {
using mozilla::java::sdk::KeyEvent;
return (metaState & KeyEvent::META_ALT_MASK ? MODIFIER_ALT : 0) |
(metaState & KeyEvent::META_SHIFT_MASK ? MODIFIER_SHIFT : 0) |
(metaState & KeyEvent::META_CTRL_MASK ? MODIFIER_CONTROL : 0) |
(metaState & KeyEvent::META_META_MASK ? MODIFIER_META : 0) |
(metaState & KeyEvent::META_FUNCTION_ON ? MODIFIER_FN : 0) |
(metaState & KeyEvent::META_CAPS_LOCK_ON ? MODIFIER_CAPSLOCK : 0) |
(metaState & KeyEvent::META_NUM_LOCK_ON ? MODIFIER_NUMLOCK : 0) |
(metaState & KeyEvent::META_SCROLL_LOCK_ON ? MODIFIER_SCROLLLOCK : 0);
}
TimeStamp nsWindow::GetEventTimeStamp(int64_t aEventTime) {
// Android's event time is SystemClock.uptimeMillis that is counted in ms
// since OS was booted.
// (https://developer.android.com/reference/android/os/SystemClock.html)
// and this SystemClock.uptimeMillis uses SYSTEM_TIME_MONOTONIC.
// Our posix implemententaion of TimeStamp::Now uses SYSTEM_TIME_MONOTONIC
// too. Due to same implementation, we can use this via FromSystemTime.
int64_t tick =
BaseTimeDurationPlatformUtils::TicksFromMilliseconds(aEventTime);
return TimeStamp::FromSystemTime(tick);
}
void nsWindow::UserActivity() {
if (!mIdleService) {
mIdleService = do_GetService("@mozilla.org/widget/useridleservice;1");
}
if (mIdleService) {
mIdleService->ResetIdleTimeOut(0);
}
if (FindTopLevel() != nsWindow::TopWindow()) {
BringToFront();
}
}
RefPtr<mozilla::a11y::SessionAccessibility>
nsWindow::GetSessionAccessibility() {
auto acc(mSessionAccessibility.Access());
if (!acc) {
return nullptr;
}
return acc.AsRefPtr();
}
TextEventDispatcherListener* nsWindow::GetNativeTextEventDispatcherListener() {
nsWindow* top = FindTopLevel();
MOZ_ASSERT(top);
auto acc(top->mEditableSupport.Access());
if (!acc) {
// Non-GeckoView windows don't support IME operations.
return nullptr;
}
nsCOMPtr<TextEventDispatcherListener> ptr;
if (NS_FAILED(acc->QueryInterface(NS_GET_IID(TextEventDispatcherListener),
getter_AddRefs(ptr)))) {
return nullptr;
}
return ptr.get();
}
void nsWindow::SetInputContext(const InputContext& aContext,
const InputContextAction& aAction) {
nsWindow* top = FindTopLevel();
MOZ_ASSERT(top);
auto acc(top->mEditableSupport.Access());
if (!acc) {
// Non-GeckoView windows don't support IME operations.
return;
}
// We are using an IME event later to notify Java, and the IME event
// will be processed by the top window. Therefore, to ensure the
// IME event uses the correct mInputContext, we need to let the top
// window process SetInputContext
acc->SetInputContext(aContext, aAction);
}
InputContext nsWindow::GetInputContext() {
nsWindow* top = FindTopLevel();
MOZ_ASSERT(top);
auto acc(top->mEditableSupport.Access());
if (!acc) {
// Non-GeckoView windows don't support IME operations.
return InputContext();
}
// We let the top window process SetInputContext,
// so we should let it process GetInputContext as well.
return acc->GetInputContext();
}
void nsWindow::PostHandleKeyEvent(mozilla::WidgetKeyboardEvent* aEvent) {
nsWindow* top = FindTopLevel();
MOZ_ASSERT(top);
auto acc(top->mEditableSupport.Access());
if (!acc) {
return;
}
return acc->PostHandleKeyEvent(aEvent);
}
nsresult nsWindow::SynthesizeNativeTouchPoint(
uint32_t aPointerId, TouchPointerState aPointerState,
LayoutDeviceIntPoint aPoint, double aPointerPressure,
uint32_t aPointerOrientation, nsISynthesizedEventCallback* aCallback) {
mozilla::widget::AutoSynthesizedEventCallbackNotifier notifier(aCallback);
int eventType;
switch (aPointerState) {
case TOUCH_CONTACT:
// This could be a ACTION_DOWN or ACTION_MOVE depending on the
// existing state; it is mapped to the right thing in Java.
eventType = java::sdk::MotionEvent::ACTION_POINTER_DOWN;
break;
case TOUCH_REMOVE:
// This could be turned into a ACTION_UP in Java
eventType = java::sdk::MotionEvent::ACTION_POINTER_UP;
break;
case TOUCH_CANCEL:
eventType = java::sdk::MotionEvent::ACTION_CANCEL;
break;
case TOUCH_HOVER: // not supported for now
default:
return NS_ERROR_UNEXPECTED;
}
MOZ_ASSERT(mNPZCSupport.IsAttached());
auto npzcSup(mNPZCSupport.Access());
MOZ_ASSERT(!!npzcSup);
const auto& npzc = npzcSup->GetJavaNPZC();
const auto& bounds = FindTopLevel()->mBounds;
aPoint -= bounds.TopLeft();
DispatchToUiThread(
"nsWindow::SynthesizeNativeTouchPoint",
[npzc = java::PanZoomController::NativeProvider::GlobalRef(npzc),
aPointerId, eventType, aPoint, aPointerPressure, aPointerOrientation] {
npzc->SynthesizeNativeTouchPoint(aPointerId, eventType, aPoint.x,
aPoint.y, aPointerPressure,
aPointerOrientation);
});
return NS_OK;
}
nsresult nsWindow::SynthesizeNativeMouseEvent(
LayoutDeviceIntPoint aPoint, NativeMouseMessage aNativeMessage,
MouseButton aButton, nsIWidget::Modifiers aModifierFlags,
nsISynthesizedEventCallback* aCallback) {
mozilla::widget::AutoSynthesizedEventCallbackNotifier notifier(aCallback);
MOZ_ASSERT(mNPZCSupport.IsAttached());
auto npzcSup(mNPZCSupport.Access());
MOZ_ASSERT(!!npzcSup);
const auto& npzc = npzcSup->GetJavaNPZC();
const auto& bounds = FindTopLevel()->mBounds;
aPoint -= bounds.TopLeft();
int32_t nativeMessage;
switch (aNativeMessage) {
case NativeMouseMessage::ButtonDown:
nativeMessage = java::sdk::MotionEvent::ACTION_POINTER_DOWN;
break;
case NativeMouseMessage::ButtonUp:
nativeMessage = java::sdk::MotionEvent::ACTION_POINTER_UP;
break;
case NativeMouseMessage::Move:
nativeMessage = java::sdk::MotionEvent::ACTION_HOVER_MOVE;
break;
default:
MOZ_ASSERT_UNREACHABLE("Non supported mouse event on Android");
return NS_ERROR_INVALID_ARG;
}
int32_t button = 0;
if (aNativeMessage != NativeMouseMessage::ButtonUp) {
switch (aButton) {
case MouseButton::ePrimary:
button = java::sdk::MotionEvent::BUTTON_PRIMARY;
break;
case MouseButton::eMiddle:
button = java::sdk::MotionEvent::BUTTON_TERTIARY;
break;
case MouseButton::eSecondary:
button = java::sdk::MotionEvent::BUTTON_SECONDARY;
break;
case MouseButton::eX1:
button = java::sdk::MotionEvent::BUTTON_BACK;
break;
case MouseButton::eX2:
button = java::sdk::MotionEvent::BUTTON_FORWARD;
break;
default:
if (aNativeMessage == NativeMouseMessage::ButtonDown) {
MOZ_ASSERT_UNREACHABLE("Non supported mouse button type on Android");
return NS_ERROR_INVALID_ARG;
}
break;
}
}
// TODO (bug 1693237): Handle aModifierFlags.
DispatchToUiThread(
"nsWindow::SynthesizeNativeMouseEvent",
[npzc = java::PanZoomController::NativeProvider::GlobalRef(npzc),
nativeMessage, aPoint, button] {
npzc->SynthesizeNativeMouseEvent(nativeMessage, aPoint.x, aPoint.y,
button);
});
return NS_OK;
}
nsresult nsWindow::SynthesizeNativeMouseMove(
LayoutDeviceIntPoint aPoint, nsISynthesizedEventCallback* aCallback) {
return SynthesizeNativeMouseEvent(
aPoint, NativeMouseMessage::Move, MouseButton::eNotPressed,
nsIWidget::Modifiers::NO_MODIFIERS, aCallback);
}
void nsWindow::SetCompositorWidgetDelegate(CompositorWidgetDelegate* delegate) {
if (delegate) {
mCompositorWidgetDelegate = delegate->AsPlatformSpecificDelegate();
MOZ_ASSERT(mCompositorWidgetDelegate,
"nsWindow::SetCompositorWidgetDelegate called with a "
"non-PlatformCompositorWidgetDelegate");
} else {
mCompositorWidgetDelegate = nullptr;
}
}
void nsWindow::GetCompositorWidgetInitData(
mozilla::widget::CompositorWidgetInitData* aInitData) {
*aInitData = mozilla::widget::AndroidCompositorWidgetInitData(
mWidgetId, GetClientSize());
}
bool nsWindow::WidgetPaintsBackground() {
return StaticPrefs::android_widget_paints_background();
}
bool nsWindow::NeedsPaint() {
auto lvs(mLayerViewSupport.Access());
if (!lvs || lvs->CompositorPaused() || !GetWindowRenderer()) {
return false;
}
return nsIWidget::NeedsPaint();
}
void nsWindow::ConfigureAPZControllerThread() {
nsCOMPtr<nsISerialEventTarget> thread = mozilla::GetAndroidUiThread();
APZThreadUtils::SetControllerThread(thread);
}
already_AddRefed<GeckoContentController>
nsWindow::CreateRootContentController() {
RefPtr<GeckoContentController> controller =
new AndroidContentController(this, mAPZEventState, mAPZC);
return controller.forget();
}
uint32_t nsWindow::GetMaxTouchPoints() const {
return java::GeckoAppShell::GetMaxTouchPoints();
}
void nsWindow::UpdateZoomConstraints(
const uint32_t& aPresShellId, const ScrollableLayerGuid::ViewID& aViewId,
const mozilla::Maybe<ZoomConstraints>& aConstraints) {
nsIWidget::UpdateZoomConstraints(aPresShellId, aViewId, aConstraints);
}
CompositorBridgeChild* nsWindow::GetCompositorBridgeChild() const {
return mCompositorSession ? mCompositorSession->GetCompositorBridgeChild()
: nullptr;
}
void nsWindow::SetContentDocumentDisplayed(bool aDisplayed) {
mContentDocumentDisplayed = aDisplayed;
}
bool nsWindow::IsContentDocumentDisplayed() {
return mContentDocumentDisplayed;
}
void nsWindow::RecvToolbarAnimatorMessageFromCompositor(int32_t aMessage) {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
if (::mozilla::jni::NativeWeakPtr<LayerViewSupport>::Accessor lvs{
mLayerViewSupport.Access()}) {
lvs->RecvToolbarAnimatorMessage(aMessage);
}
}
static int32_t ConvertScrollUpdateSource(
CompositorScrollUpdate::Source aSource) {
switch (aSource) {
case CompositorScrollUpdate::Source::UserInteraction:
return java::GeckoSession::ScrollPositionUpdate::SOURCE_USER_INTERACTION;
case CompositorScrollUpdate::Source::Other:
return java::GeckoSession::ScrollPositionUpdate::SOURCE_OTHER;
}
MOZ_ASSERT_UNREACHABLE("Unknown CompositorScrollUpdate::Source");
return java::GeckoSession::ScrollPositionUpdate::SOURCE_USER_INTERACTION;
}
void nsWindow::NotifyCompositorScrollUpdate(
const CompositorScrollUpdate& aUpdate) {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
if (::mozilla::jni::NativeWeakPtr<LayerViewSupport>::Accessor lvs{
mLayerViewSupport.Access()}) {
const auto& compositor = lvs->GetJavaCompositor();
mContentDocumentDisplayed = true;
compositor->NotifyCompositorScrollUpdate(
aUpdate.mMetrics.mVisualScrollOffset.x,
aUpdate.mMetrics.mVisualScrollOffset.y, aUpdate.mMetrics.mZoom.scale,
ConvertScrollUpdateSource(aUpdate.mSource));
}
}
void nsWindow::RecvScreenPixels(Shmem&& aMem, const ScreenIntSize& aSize,
bool aNeedsYFlip) {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
if (::mozilla::jni::NativeWeakPtr<LayerViewSupport>::Accessor lvs{
mLayerViewSupport.Access()}) {
lvs->RecvScreenPixels(std::move(aMem), aSize, aNeedsYFlip);
}
}
void nsWindow::UpdateDynamicToolbarMaxHeight(ScreenIntCoord aHeight) {
if (mDynamicToolbarMaxHeight == aHeight) {
return;
}
mDynamicToolbarMaxHeight = aHeight;
if (mWidgetListener) {
mWidgetListener->DynamicToolbarMaxHeightChanged(aHeight);
}
if (mAttachedWidgetListener) {
mAttachedWidgetListener->DynamicToolbarMaxHeightChanged(aHeight);
}
}
void nsWindow::UpdateDynamicToolbarOffset(ScreenIntCoord aOffset) {
if (mWidgetListener) {
mWidgetListener->DynamicToolbarOffsetChanged(aOffset);
}
if (mAttachedWidgetListener) {
mAttachedWidgetListener->DynamicToolbarOffsetChanged(aOffset);
}
}
void nsWindow::PipModeChanged(bool aPipMode) {
if (mWidgetListener) {
mWidgetListener->AndroidPipModeChanged(aPipMode);
}
if (mAttachedWidgetListener) {
mAttachedWidgetListener->AndroidPipModeChanged(aPipMode);
}
}
void nsWindow::KeyboardHeightChanged(ScreenIntCoord aHeight) {
if (mWidgetListener) {
mWidgetListener->KeyboardHeightChanged(aHeight);
}
if (mAttachedWidgetListener) {
mAttachedWidgetListener->KeyboardHeightChanged(aHeight);
}
}
LayoutDeviceIntMargin nsWindow::GetSafeAreaInsets() const {
return mSafeAreaInsets;
}
void nsWindow::UpdateSafeAreaInsets(
const LayoutDeviceIntMargin& aSafeAreaInsets) {
mSafeAreaInsets = aSafeAreaInsets;
if (mWidgetListener) {
mWidgetListener->SafeAreaInsetsChanged(aSafeAreaInsets);
}
if (mAttachedWidgetListener) {
mAttachedWidgetListener->SafeAreaInsetsChanged(aSafeAreaInsets);
}
}
jni::NativeWeakPtr<NPZCSupport> nsWindow::GetNPZCSupportWeakPtr() {
return mNPZCSupport;
}
already_AddRefed<nsIWidget> nsIWidget::CreateTopLevelWindow() {
nsCOMPtr<nsIWidget> window = new nsWindow();
return window.forget();
}
already_AddRefed<nsIWidget> nsIWidget::CreateChildWindow() {
nsCOMPtr<nsIWidget> window = new nsWindow();
return window.forget();
}
static already_AddRefed<DataSourceSurface> GetCursorImage(
const nsIWidget::Cursor& aCursor, mozilla::CSSToLayoutDeviceScale aScale) {
if (!aCursor.IsCustom()) {
return nullptr;
}
RefPtr<DataSourceSurface> destDataSurface;
nsIntSize size = nsIWidget::CustomCursorSize(aCursor);
// prevent DoS attacks
if (size.width > 128 || size.height > 128) {
return nullptr;
}
RefPtr<gfx::SourceSurface> surface = aCursor.mContainer->GetFrameAtSize(
size * aScale.scale, imgIContainer::FRAME_CURRENT,
imgIContainer::FLAG_SYNC_DECODE | imgIContainer::FLAG_ASYNC_NOTIFY);
if (NS_WARN_IF(!surface)) {
return nullptr;
}
return AndroidWidgetUtils::GetDataSourceSurfaceForAndroidBitmap(surface);
}
static int32_t GetCursorType(nsCursor aCursor) {
// When our minimal requirement of SDK version is 25+,
// we should replace with JNI auto-generator.
switch (aCursor) {
case eCursor_standard:
// android.view.PointerIcon.TYPE_ARROW
return 0x3e8;
case eCursor_wait:
// android.view.PointerIcon.TYPE_WAIT
return 0x3ec;
case eCursor_select:
// android.view.PointerIcon.TYPE_TEXT;
return 0x3f0;
case eCursor_hyperlink:
// android.view.PointerIcon.TYPE_HAND
return 0x3ea;
case eCursor_n_resize:
case eCursor_s_resize:
case eCursor_ns_resize:
case eCursor_row_resize:
// android.view.PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW
return 0x3f7;
case eCursor_w_resize:
case eCursor_e_resize:
case eCursor_ew_resize:
case eCursor_col_resize:
// android.view.PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW
return 0x3f6;
case eCursor_nw_resize:
case eCursor_se_resize:
case eCursor_nwse_resize:
// android.view.PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW
return 0x3f9;
case eCursor_ne_resize:
case eCursor_sw_resize:
case eCursor_nesw_resize:
// android.view.PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW
return 0x3f8;
case eCursor_crosshair:
// android.view.PointerIcon.TYPE_CROSSHAIR
return 0x3ef;
case eCursor_move:
// android.view.PointerIcon.TYPE_ARROW
return 0x3e8;
case eCursor_help:
// android.view.PointerIcon.TYPE_HELP
return 0x3eb;
case eCursor_copy:
// android.view.PointerIcon.TYPE_COPY
return 0x3f3;
case eCursor_alias:
// android.view.PointerIcon.TYPE_ALIAS
return 0x3f2;
case eCursor_context_menu:
// android.view.PointerIcon.TYPE_CONTEXT_MENU
return 0x3e9;
case eCursor_cell:
// android.view.PointerIcon.TYPE_CELL
return 0x3ee;
case eCursor_grab:
// android.view.PointerIcon.TYPE_GRAB
return 0x3fc;
case eCursor_grabbing:
// android.view.PointerIcon.TYPE_GRABBING
return 0x3fd;
case eCursor_spinning:
// android.view.PointerIcon.TYPE_WAIT
return 0x3ec;
case eCursor_zoom_in:
// android.view.PointerIcon.TYPE_ZOOM_IN
return 0x3fa;
case eCursor_zoom_out:
// android.view.PointerIcon.TYPE_ZOOM_OUT
return 0x3fb;
case eCursor_not_allowed:
// android.view.PointerIcon.TYPE_NO_DROP:
return 0x3f4;
case eCursor_no_drop:
// android.view.PointerIcon.TYPE_NO_DROP:
return 0x3f4;
case eCursor_vertical_text:
// android.view.PointerIcon.TYPE_VERTICAL_TEXT
return 0x3f1;
case eCursor_all_scroll:
// android.view.PointerIcon.TYPE_ALL_SCROLL
return 0x3f5;
case eCursor_none:
// android.view.PointerIcon.TYPE_NULL
return 0;
default:
NS_WARNING_ASSERTION(aCursor, "Invalid cursor type");
// android.view.PointerIcon.TYPE_ARROW
return 0x3e8;
}
}
void nsWindow::SetCursor(const Cursor& aCursor) {
// Only change cursor if it's actually been changed
if (!mUpdateCursor && mCursor == aCursor) {
return;
}
mUpdateCursor = false;
mCursor = aCursor;
int32_t type = 0;
RefPtr<DataSourceSurface> destDataSurface =
GetCursorImage(aCursor, GetDefaultScale());
if (!destDataSurface) {
type = GetCursorType(aCursor.mDefaultCursor);
}
if (mozilla::jni::NativeWeakPtr<LayerViewSupport>::Accessor lvs{
mLayerViewSupport.Access()}) {
const auto& compositor = lvs->GetJavaCompositor();
DispatchToUiThread(
"nsWindow::SetCursor",
[compositor = GeckoSession::Compositor::GlobalRef(compositor), type,
destDataSurface = std::move(destDataSurface),
hotspotX = aCursor.mHotspotX, hotspotY = aCursor.mHotspotY] {
java::sdk::Bitmap::LocalRef bitmap;
if (destDataSurface) {
DataSourceSurface::ScopedMap destMap(destDataSurface,
DataSourceSurface::READ);
auto pixels = mozilla::jni::ByteBuffer::New(
reinterpret_cast<int8_t*>(destMap.GetData()),
destMap.GetStride() * destDataSurface->GetSize().height);
bitmap = java::sdk::Bitmap::CreateBitmap(
destDataSurface->GetSize().width,
destDataSurface->GetSize().height,
java::sdk::Bitmap::Config::ARGB_8888());
bitmap->CopyPixelsFromBuffer(pixels);
}
compositor->SetPointerIcon(type, bitmap, hotspotX, hotspotY);
});
}
}
|