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 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822
|
/*
* Copyright (C) 2007-2023 Apple Inc. All rights reserved.
* Copyright (C) 2012, 2013 Adobe Systems Incorporated. All rights reserved.
* Copyright (C) 2025 Sam Weinig. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "CSSPropertyAnimation.h"
#include "AnimationMalloc.h"
#include "AnimationUtilities.h"
#include "BlockEllipsis.h"
#include "CSSCustomPropertyValue.h"
#include "CSSPrimitiveValue.h"
#include "CSSPropertyBlendingClient.h"
#include "CSSPropertyNames.h"
#include "CSSRegisteredCustomProperty.h"
#include "CachedImage.h"
#include "CalculationValue.h"
#include "ColorBlending.h"
#include "ComputedStyleExtractor.h"
#include "ContentData.h"
#include "CustomPropertyRegistry.h"
#include "Document.h"
#include "FloatConversion.h"
#include "FontCascade.h"
#include "FontSelectionAlgorithm.h"
#include "FontSelectionValueInlines.h"
#include "FontTaggedSettings.h"
#include "GridPositionsResolver.h"
#include "IdentityTransformOperation.h"
#include "LengthPoint.h"
#include "Logging.h"
#include "Matrix3DTransformOperation.h"
#include "MatrixTransformOperation.h"
#include "QuotesData.h"
#include "RenderBox.h"
#include "RenderStyleSetters.h"
#include "SVGRenderStyle.h"
#include "ScopedName.h"
#include "ScrollbarGutter.h"
#include "Settings.h"
#include "StyleBoxShadow.h"
#include "StyleCachedImage.h"
#include "StyleCrossfadeImage.h"
#include "StyleDynamicRangeLimit.h"
#include "StyleFilterImage.h"
#include "StylePropertyShorthand.h"
#include "StyleResolver.h"
#include "StyleTextEdge.h"
#include <algorithm>
#include <memory>
#include <wtf/MathExtras.h>
#include <wtf/NeverDestroyed.h>
#include <wtf/PointerComparison.h>
#include <wtf/text/TextStream.h>
namespace WebCore {
#if !LOG_DISABLED
static TextStream& operator<<(TextStream& stream, CSSPropertyID property)
{
return stream << nameLiteral(property);
}
#endif
struct CSSPropertyBlendingContext : BlendingContext {
const CSSPropertyBlendingClient& client;
AnimatableCSSProperty property;
CSSPropertyBlendingContext(double progress, bool isDiscrete, CompositeOperation compositeOperation, const CSSPropertyBlendingClient& client, const AnimatableCSSProperty& property, IterationCompositeOperation iterationCompositeOperation = IterationCompositeOperation::Replace, double currentIteration = 0)
: BlendingContext(progress, isDiscrete, compositeOperation, iterationCompositeOperation, currentIteration)
, client(client)
, property(property)
{
}
};
static inline int blendFunc(int from, int to, const CSSPropertyBlendingContext& context)
{
return blend(from, to, context);
}
static inline double blendFunc(double from, double to, const CSSPropertyBlendingContext& context)
{
return blend(from, to, context);
}
static inline float blendFunc(float from, float to, const CSSPropertyBlendingContext& context)
{
if (context.iterationCompositeOperation == IterationCompositeOperation::Accumulate && context.currentIteration) {
auto iterationIncrement = context.currentIteration * to;
from += iterationIncrement;
to += iterationIncrement;
}
if (context.compositeOperation == CompositeOperation::Replace)
return narrowPrecisionToFloat(from + (to - from) * context.progress);
return narrowPrecisionToFloat(from + from + (to - from) * context.progress);
}
static inline Color blendFunc(const Color& from, const Color& to, const CSSPropertyBlendingContext& context)
{
return blend(from, to, context);
}
static inline Length blendFunc(const Length& from, const Length& to, const CSSPropertyBlendingContext& context, ValueRange valueRange = ValueRange::All)
{
return blend(from, to, context, valueRange);
}
static inline GapLength blendFunc(const GapLength& from, const GapLength& to, const CSSPropertyBlendingContext& context)
{
if (from.isNormal() || to.isNormal())
return context.progress < 0.5 ? from : to;
return blend(from.length(), to.length(), context, ValueRange::NonNegative);
}
static inline TabSize blendFunc(const TabSize& from, const TabSize& to, const CSSPropertyBlendingContext& context)
{
auto blendedValue = blend(from.value(), to.value(), context);
return { blendedValue < 0 ? 0 : blendedValue, from.isSpaces() ? SpaceValueType : LengthValueType };
}
static inline LengthSize blendFunc(const LengthSize& from, const LengthSize& to, const CSSPropertyBlendingContext& context)
{
return blend(from, to, context, ValueRange::NonNegative);
}
static inline LengthPoint blendFunc(const LengthPoint& from, const LengthPoint& to, const CSSPropertyBlendingContext& context)
{
return blend(from, to, context);
}
static inline std::unique_ptr<ShadowData> blendFunc(const ShadowData* from, const ShadowData* to, const RenderStyle& fromStyle, const RenderStyle& toStyle, const CSSPropertyBlendingContext& context)
{
ASSERT(from && to);
ASSERT(from->style() == to->style());
return makeUnique<ShadowData>(
Style::blend(from->asBoxShadow(), to->asBoxShadow(), fromStyle, toStyle, context)
);
}
static inline TransformOperations blendFunc(const TransformOperations& from, const TransformOperations& to, const CSSPropertyBlendingContext& context)
{
if (context.compositeOperation == CompositeOperation::Add) {
ASSERT(context.progress == 1.0);
Vector<Ref<TransformOperation>> operations;
operations.reserveInitialCapacity(from.size() + to.size());
operations.appendRange(from.begin(), from.end());
operations.appendRange(to.begin(), to.end());
return TransformOperations { WTFMove(operations) };
}
auto prefix = [&]() -> std::optional<unsigned> {
// We cannot use the pre-computed prefix when dealing with accumulation
// since the values used to accumulate may be different than those held
// in the initial keyframe list. We must do the same with any property
// other than "transform" since we only pre-compute the prefix for that
// property.
if (context.compositeOperation == CompositeOperation::Accumulate || std::holds_alternative<AtomString>(context.property) || std::get<CSSPropertyID>(context.property) != CSSPropertyTransform)
return std::nullopt;
return context.client.transformFunctionListPrefix();
};
auto* renderBox = dynamicDowncast<RenderBox>(context.client.renderer());
auto boxSize = renderBox ? renderBox->borderBoxRect().size() : LayoutSize();
return to.blend(from, context, boxSize, prefix());
}
static RefPtr<ScaleTransformOperation> blendFunc(ScaleTransformOperation* from, ScaleTransformOperation* to, const CSSPropertyBlendingContext& context)
{
if (!from && !to)
return nullptr;
RefPtr<ScaleTransformOperation> identity;
if (!from) {
identity = ScaleTransformOperation::create(1, 1, 1, to->type());
from = identity.get();
} else if (!to) {
identity = ScaleTransformOperation::create(1, 1, 1, from->type());
to = identity.get();
}
// Ensure the two transforms have the same type.
if (!from->isSameType(*to)) {
RefPtr<ScaleTransformOperation> normalizedFrom;
RefPtr<ScaleTransformOperation> normalizedTo;
if (from->is3DOperation() || to->is3DOperation()) {
normalizedFrom = ScaleTransformOperation::create(from->x(), from->y(), from->z(), TransformOperation::Type::Scale3D);
normalizedTo = ScaleTransformOperation::create(to->x(), to->y(), to->z(), TransformOperation::Type::Scale3D);
} else {
normalizedFrom = ScaleTransformOperation::create(from->x(), from->y(), TransformOperation::Type::Scale);
normalizedTo = ScaleTransformOperation::create(to->x(), to->y(), TransformOperation::Type::Scale);
}
return blendFunc(normalizedFrom.get(), normalizedTo.get(), context);
}
auto blendedOperation = to->blend(from, context);
if (auto* scale = dynamicDowncast<ScaleTransformOperation>(blendedOperation.get()))
return ScaleTransformOperation::create(scale->x(), scale->y(), scale->z(), scale->type());
return nullptr;
}
static RefPtr<RotateTransformOperation> blendFunc(RotateTransformOperation* from, RotateTransformOperation* to, const CSSPropertyBlendingContext& context)
{
if (!from && !to)
return nullptr;
RefPtr<RotateTransformOperation> identity;
if (!from) {
identity = RotateTransformOperation::create(0, to->type());
from = identity.get();
} else if (!to) {
identity = RotateTransformOperation::create(0, from->type());
to = identity.get();
}
// Ensure the two transforms have the same type.
if (!from->isSameType(*to)) {
RefPtr<RotateTransformOperation> normalizedFrom;
RefPtr<RotateTransformOperation> normalizedTo;
if (from->is3DOperation() || to->is3DOperation()) {
normalizedFrom = RotateTransformOperation::create(from->x(), from->y(), from->z(), from->angle(), TransformOperation::Type::Rotate3D);
normalizedTo = RotateTransformOperation::create(to->x(), to->y(), to->z(), to->angle(), TransformOperation::Type::Rotate3D);
} else {
normalizedFrom = RotateTransformOperation::create(from->angle(), TransformOperation::Type::Rotate);
normalizedTo = RotateTransformOperation::create(to->angle(), TransformOperation::Type::Rotate);
}
return blendFunc(normalizedFrom.get(), normalizedTo.get(), context);
}
auto blendedOperation = to->blend(from, context);
if (auto* rotate = dynamicDowncast<RotateTransformOperation>(blendedOperation.get()))
return RotateTransformOperation::create(rotate->x(), rotate->y(), rotate->z(), rotate->angle(), rotate->type());
return nullptr;
}
static RefPtr<TranslateTransformOperation> blendFunc(TranslateTransformOperation* from, TranslateTransformOperation* to, const CSSPropertyBlendingContext& context)
{
if (!from && !to)
return nullptr;
RefPtr<TranslateTransformOperation> identity;
if (!from) {
identity = TranslateTransformOperation::create(Length(0, LengthType::Fixed), Length(0, LengthType::Fixed), Length(0, LengthType::Fixed), to->type());
from = identity.get();
} else if (!to) {
identity = TranslateTransformOperation::create(Length(0, LengthType::Fixed), Length(0, LengthType::Fixed), Length(0, LengthType::Fixed), from->type());
to = identity.get();
}
// Ensure the two transforms have the same type.
if (!from->isSameType(*to)) {
RefPtr<TranslateTransformOperation> normalizedFrom;
RefPtr<TranslateTransformOperation> normalizedTo;
if (from->is3DOperation() || to->is3DOperation()) {
normalizedFrom = TranslateTransformOperation::create(from->x(), from->y(), from->z(), TransformOperation::Type::Translate3D);
normalizedTo = TranslateTransformOperation::create(to->x(), to->y(), to->z(), TransformOperation::Type::Translate3D);
} else {
normalizedFrom = TranslateTransformOperation::create(from->x(), from->y(), TransformOperation::Type::Translate);
normalizedTo = TranslateTransformOperation::create(to->x(), to->y(), TransformOperation::Type::Translate);
}
return blendFunc(normalizedFrom.get(), normalizedTo.get(), context);
}
Ref<TransformOperation> blendedOperation = to->blend(from, context);
if (auto* translate = dynamicDowncast<TranslateTransformOperation>(blendedOperation.get()))
return TranslateTransformOperation::create(translate->x(), translate->y(), translate->z(), translate->type());
return nullptr;
}
static Ref<TransformOperation> blendFunc(TransformOperation& from, TransformOperation& to, const CSSPropertyBlendingContext& context)
{
return to.blend(&from, context);
}
static inline RefPtr<PathOperation> blendFunc(PathOperation* from, PathOperation* to, const CSSPropertyBlendingContext& context)
{
if (context.isDiscrete) {
ASSERT(!context.progress || context.progress == 1);
return context.progress ? to : from;
}
ASSERT(from && to);
return from->blend(to, context);
}
static inline RefPtr<ShapeValue> blendFunc(ShapeValue* from, ShapeValue* to, const CSSPropertyBlendingContext& context)
{
if (context.isDiscrete) {
ASSERT(!context.progress || context.progress == 1);
return context.progress ? to : from;
}
ASSERT(from && to);
return from->blend(*to, context);
}
static inline FilterOperations blendFunc(const FilterOperations& from, const FilterOperations& to, const CSSPropertyBlendingContext& context)
{
return from.blend(to, context);
}
static inline RefPtr<StyleImage> blendFilter(RefPtr<StyleImage> inputImage, const FilterOperations& from, const FilterOperations& to, const CSSPropertyBlendingContext& context)
{
auto filterResult = from.blend(to, context);
return StyleFilterImage::create(WTFMove(inputImage), WTFMove(filterResult));
}
static inline ContentVisibility blendFunc(ContentVisibility from, ContentVisibility to, const CSSPropertyBlendingContext& context)
{
// https://drafts.csswg.org/css-contain-3/#content-visibility-animation
// In general, the content-visibility property's animation type is discrete. However, similar to interpolation of
// visibility, during interpolation between hidden and any other content-visibility value, p values between 0 and 1
// map to the non-hidden value.
if (from != ContentVisibility::Hidden && to != ContentVisibility::Hidden)
return context.progress < 0.5 ? from : to;
if (context.progress <= 0)
return from;
if (context.progress >= 1)
return to;
return from == ContentVisibility::Hidden ? to : from;
}
static inline Visibility blendFunc(Visibility from, Visibility to, const CSSPropertyBlendingContext& context)
{
if (context.isDiscrete) {
ASSERT(!context.progress || context.progress == 1.0);
return context.progress ? to : from;
}
// Any non-zero result means we consider the object to be visible. Only at 0 do we consider the object to be
// invisible. The invisible value we use (Visibility::Hidden vs. Visibility::Collapse) depends on the specified from/to values.
double fromVal = from == Visibility::Visible ? 1. : 0.;
double toVal = to == Visibility::Visible ? 1. : 0.;
if (fromVal == toVal)
return to;
// The composite operation here is irrelevant.
double result = blendFunc(fromVal, toVal, { context.progress, false, CompositeOperation::Replace, context.client, context.property });
return result > 0. ? Visibility::Visible : (to != Visibility::Visible ? to : from);
}
static inline DisplayType blendFunc(DisplayType from, DisplayType to, const CSSPropertyBlendingContext& context)
{
// https://drafts.csswg.org/css-display-4/#display-animation
// In general, the display property's animation type is discrete. However, similar to interpolation of
// visibility, during interpolation between none and any other display value, p values between 0 and 1
// map to the non-none value. Additionally, the element is inert as long as its display value would
// compute to none when ignoring the Transitions and Animations cascade origins.
if (from != DisplayType::None && to != DisplayType::None)
return context.progress < 0.5 ? from : to;
if (context.progress <= 0)
return from;
if (context.progress >= 1)
return to;
return from == DisplayType::None ? to : from;
}
static inline LengthBox blendFunc(const LengthBox& from, const LengthBox& to, const CSSPropertyBlendingContext& context, ValueRange valueRange = ValueRange::NonNegative)
{
LengthBox result(blendFunc(from.top(), to.top(), context, valueRange),
blendFunc(from.right(), to.right(), context, valueRange),
blendFunc(from.bottom(), to.bottom(), context, valueRange),
blendFunc(from.left(), to.left(), context, valueRange));
return result;
}
static inline SVGLengthValue blendFunc(const SVGLengthValue& from, const SVGLengthValue& to, const CSSPropertyBlendingContext& context)
{
return SVGLengthValue::blend(from, to, narrowPrecisionToFloat(context.progress));
}
static inline Vector<SVGLengthValue> blendFunc(const Vector<SVGLengthValue>& from, const Vector<SVGLengthValue>& to, const CSSPropertyBlendingContext& context)
{
size_t fromLength = from.size();
size_t toLength = to.size();
if (!fromLength || !toLength)
return context.progress < 0.5 ? from : to;
size_t resultLength = fromLength;
if (fromLength != toLength) {
if (!remainder(std::max(fromLength, toLength), std::min(fromLength, toLength)))
resultLength = std::max(fromLength, toLength);
else
resultLength = fromLength * toLength;
}
Vector<SVGLengthValue> result(resultLength);
for (size_t i = 0; i < resultLength; ++i)
result[i] = SVGLengthValue::blend(from[i % fromLength], to[i % toLength], narrowPrecisionToFloat(context.progress));
return result;
}
static inline RefPtr<StyleImage> crossfadeBlend(StyleCachedImage& fromStyleImage, StyleCachedImage& toStyleImage, const CSSPropertyBlendingContext& context)
{
// If progress is at one of the extremes, we want getComputedStyle to show the image,
// not a completed cross-fade, so we hand back one of the existing images.
if (!context.progress)
return &fromStyleImage;
if (context.progress == 1)
return &toStyleImage;
if (!fromStyleImage.cachedImage() || !toStyleImage.cachedImage())
return &toStyleImage;
return StyleCrossfadeImage::create(&fromStyleImage, &toStyleImage, context.progress, false);
}
static inline RefPtr<StyleImage> blendFunc(StyleImage* from, StyleImage* to, const CSSPropertyBlendingContext& context)
{
if (!context.progress)
return from;
if (context.progress == 1.0)
return to;
ASSERT(from && to);
from = from->selectedImage();
to = to->selectedImage();
if (!from || !to)
return to;
// Animation between two generated images. Cross fade for all other cases.
if (auto [fromFilter, toFilter] = std::tuple { dynamicDowncast<StyleFilterImage>(*from), dynamicDowncast<StyleFilterImage>(*to) }; fromFilter && toFilter) {
// Animation of generated images just possible if input images are equal.
// Otherwise fall back to cross fade animation.
if (fromFilter->equalInputImages(*toFilter) && is<StyleCachedImage>(fromFilter->inputImage()))
return blendFilter(fromFilter->inputImage(), fromFilter->filterOperations(), toFilter->filterOperations(), context);
} else if (auto [fromCrossfade, toCrossfade] = std::tuple { dynamicDowncast<StyleCrossfadeImage>(*from), dynamicDowncast<StyleCrossfadeImage>(*to) }; fromCrossfade && toCrossfade) {
if (fromCrossfade->equalInputImages(*toCrossfade)) {
if (auto crossfadeBlend = toCrossfade->blend(*fromCrossfade, context))
return crossfadeBlend;
}
} else if (auto [fromFilter, toCachedImage] = std::tuple { dynamicDowncast<StyleFilterImage>(*from), dynamicDowncast<StyleCachedImage>(*to) }; fromFilter && toCachedImage) {
RefPtr fromFilterInputImage = dynamicDowncast<StyleCachedImage>(fromFilter->inputImage());
if (fromFilterInputImage && toCachedImage->equals(*fromFilterInputImage))
return blendFilter(WTFMove(fromFilterInputImage), fromFilter->filterOperations(), FilterOperations(), context);
} else if (auto [fromCachedImage, toFilter] = std::tuple { dynamicDowncast<StyleCachedImage>(*from), dynamicDowncast<StyleFilterImage>(*to) }; fromCachedImage && toFilter) {
RefPtr toFilterInputImage = dynamicDowncast<StyleCachedImage>(toFilter->inputImage());
if (toFilterInputImage && fromCachedImage->equals(*toFilterInputImage))
return blendFilter(WTFMove(toFilterInputImage), FilterOperations(), toFilter->filterOperations(), context);
}
auto* fromCachedImage = dynamicDowncast<StyleCachedImage>(*from);
auto* toCachedImage = dynamicDowncast<StyleCachedImage>(*to);
if (fromCachedImage && toCachedImage)
return crossfadeBlend(*fromCachedImage, *toCachedImage, context);
// FIXME: Add support for animation between two *gradient() functions.
// https://bugs.webkit.org/show_bug.cgi?id=119956
// FIXME: Add support cross fade between cached and generated images.
// https://bugs.webkit.org/show_bug.cgi?id=78293
return to;
}
static inline NinePieceImage blendFunc(const NinePieceImage& from, const NinePieceImage& to, const CSSPropertyBlendingContext& context)
{
if (!from.hasImage() || !to.hasImage())
return to;
// FIXME (74112): Support transitioning between NinePieceImages that differ by more than image content.
if (from.imageSlices() != to.imageSlices() || from.borderSlices() != to.borderSlices() || from.outset() != to.outset() || from.fill() != to.fill() || from.overridesBorderWidths() != to.overridesBorderWidths() || from.horizontalRule() != to.horizontalRule() || from.verticalRule() != to.verticalRule())
return to;
if (auto* renderer = context.client.renderer()) {
if (from.image()->imageSize(renderer, 1.0) != to.image()->imageSize(renderer, 1.0))
return to;
}
return NinePieceImage(blendFunc(from.image(), to.image(), context),
from.imageSlices(), from.fill(), from.borderSlices(), from.overridesBorderWidths(), from.outset(), from.horizontalRule(), from.verticalRule());
}
#if ENABLE(VARIATION_FONTS)
static inline FontVariationSettings blendFunc(const FontVariationSettings& from, const FontVariationSettings& to, const CSSPropertyBlendingContext& context)
{
if (context.isDiscrete) {
ASSERT(!context.progress || context.progress == 1.0);
return context.progress ? to : from;
}
ASSERT(from.size() == to.size());
FontVariationSettings result;
unsigned size = from.size();
for (unsigned i = 0; i < size; ++i) {
auto& fromItem = from.at(i);
auto& toItem = to.at(i);
ASSERT(fromItem.tag() == toItem.tag());
float interpolated = blendFunc(fromItem.value(), toItem.value(), context);
result.insert({ fromItem.tag(), interpolated });
}
return result;
}
#endif
static inline FontSelectionValue blendFunc(FontSelectionValue from, FontSelectionValue to, const CSSPropertyBlendingContext& context)
{
return FontSelectionValue(std::max(0.0f, blendFunc(static_cast<float>(from), static_cast<float>(to), context)));
}
static inline std::optional<FontSelectionValue> blendFunc(std::optional<FontSelectionValue> from, std::optional<FontSelectionValue> to, const CSSPropertyBlendingContext& context)
{
if (!from && !to)
return std::nullopt;
auto valueOrDefault = [](std::optional<FontSelectionValue> fontSelectionValue) {
if (!fontSelectionValue)
return 0.0f;
return static_cast<float>(fontSelectionValue.value());
};
return normalizedFontItalicValue(blendFunc(valueOrDefault(from), valueOrDefault(to), context));
}
static inline bool canInterpolate(const GridTrackList& from, const GridTrackList& to)
{
if (from.list.size() != to.list.size())
return false;
size_t i = 0;
auto visitor = WTF::makeVisitor([&](const GridTrackSize&) {
return std::holds_alternative<GridTrackSize>(to.list[i]);
}, [&](const Vector<String>&) {
return std::holds_alternative<Vector<String>>(to.list[i]);
}, [&](const GridTrackEntryRepeat& repeat) {
if (!std::holds_alternative<GridTrackEntryRepeat>(to.list[i]))
return false;
const auto& toEntry = std::get<GridTrackEntryRepeat>(to.list[i]);
return repeat.repeats == toEntry.repeats && repeat.list.size() == toEntry.list.size();
}, [](const GridTrackEntryAutoRepeat&) {
return false;
}, [](const GridTrackEntrySubgrid&) {
return false;
}, [](const GridTrackEntryMasonry&) {
return false;
});
for (i = 0; i < from.list.size(); i++) {
if (!std::visit(visitor, from.list[i]))
return false;
}
return true;
}
static inline GridLength blendFunc(const GridLength& from, const GridLength& to, const CSSPropertyBlendingContext& context)
{
if (from.isFlex() != to.isFlex())
return context.progress < 0.5 ? from : to;
if (from.isFlex())
return GridLength(blend(from.flex(), to.flex(), context));
return GridLength(blendFunc(from.length(), to.length(), context));
}
static inline GridTrackSize blendFunc(const GridTrackSize& from, const GridTrackSize& to, const CSSPropertyBlendingContext& context)
{
if (from.type() != to.type())
return context.progress < 0.5 ? from : to;
if (from.type() == LengthTrackSizing) {
auto length = blendFunc(from.minTrackBreadth(), to.minTrackBreadth(), context);
return GridTrackSize(length, LengthTrackSizing);
}
if (from.type() == MinMaxTrackSizing) {
auto minTrackBreadth = blendFunc(from.minTrackBreadth(), to.minTrackBreadth(), context);
auto maxTrackBreadth = blendFunc(from.maxTrackBreadth(), to.maxTrackBreadth(), context);
return GridTrackSize(minTrackBreadth, maxTrackBreadth);
}
auto fitContentBreadth = blendFunc(from.fitContentTrackBreadth(), to.fitContentTrackBreadth(), context);
return GridTrackSize(fitContentBreadth, FitContentTrackSizing);
}
static inline RepeatTrackList blendFunc(const RepeatTrackList& from, const RepeatTrackList& to, const CSSPropertyBlendingContext& context)
{
RepeatTrackList result;
size_t i = 0;
auto visitor = WTF::makeVisitor([&](const GridTrackSize& size) {
result.append(blendFunc(size, std::get<GridTrackSize>(to[i]), context));
}, [&](const Vector<String>& names) {
if (context.progress < 0.5)
result.append(names);
else {
const Vector<String>& toNames = std::get<Vector<String>>(to[i]);
result.append(toNames);
}
});
for (i = 0; i < from.size(); i++)
std::visit(visitor, from[i]);
return result;
}
static inline GridTrackList blendFunc(const GridTrackList& from, const GridTrackList& to, const CSSPropertyBlendingContext& context)
{
if (!canInterpolate(from, to))
return context.progress < 0.5 ? from : to;
GridTrackList result;
size_t i = 0;
auto visitor = WTF::makeVisitor([&](const GridTrackSize& size) {
result.list.append(blendFunc(size, std::get<GridTrackSize>(to.list[i]), context));
}, [&](const Vector<String>& names) {
if (context.progress < 0.5)
result.list.append(names);
else {
const Vector<String>& toNames = std::get<Vector<String>>(to.list[i]);
result.list.append(toNames);
}
}, [&](const GridTrackEntryRepeat& repeatFrom) {
auto& repeatTo = std::get<GridTrackEntryRepeat>(to.list[i]);
GridTrackEntryRepeat repeatResult;
repeatResult.repeats = repeatFrom.repeats;
repeatResult.list = blendFunc(repeatFrom.list, repeatTo.list, context);
result.list.append(WTFMove(repeatResult));
}, [&](const GridTrackEntryAutoRepeat& repeatFrom) {
auto& repeatTo = std::get<GridTrackEntryAutoRepeat>(to.list[i]);
GridTrackEntryAutoRepeat repeatResult;
repeatResult.type = repeatFrom.type;
repeatResult.list = blendFunc(repeatFrom.list, repeatTo.list, context);
result.list.append(WTFMove(repeatResult));
}, [](const GridTrackEntrySubgrid&) {
}, [](const GridTrackEntryMasonry&) {
});
for (i = 0; i < from.list.size(); i++)
std::visit(visitor, from.list[i]);
return result;
}
static inline RefPtr<StylePathData> blendFunc(StylePathData* from, StylePathData* to, const CSSPropertyBlendingContext& context)
{
if (context.isDiscrete)
return context.progress < 0.5 ? from : to;
ASSERT(from && to);
return from->blend(*to, context);
}
class AnimationPropertyWrapperBase {
WTF_MAKE_NONCOPYABLE(AnimationPropertyWrapperBase);
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
explicit AnimationPropertyWrapperBase(CSSPropertyID property)
: m_property(property)
{
}
virtual ~AnimationPropertyWrapperBase() = default;
virtual bool isShorthandWrapper() const { return false; }
virtual bool isAdditiveOrCumulative() const { return true; }
virtual bool requiresBlendingForAccumulativeIteration(const RenderStyle&, const RenderStyle&) const { return false; }
virtual bool equals(const RenderStyle&, const RenderStyle&) const = 0;
virtual bool canInterpolate(const RenderStyle&, const RenderStyle&, CompositeOperation) const { return true; }
virtual bool normalizesProgressForDiscreteInterpolation() const { return true; }
virtual void blend(RenderStyle&, const RenderStyle&, const RenderStyle&, const CSSPropertyBlendingContext&) const = 0;
#if !LOG_DISABLED
virtual void logBlend(const RenderStyle&, const RenderStyle&, const RenderStyle&, double) const = 0;
#endif
CSSPropertyID property() const { return m_property; }
virtual bool animationIsAccelerated(const Settings&) const { return false; }
private:
CSSPropertyID m_property;
};
template <typename T>
class PropertyWrapperGetter : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperGetter(CSSPropertyID property, T (RenderStyle::*getter)() const)
: AnimationPropertyWrapperBase(property)
, m_getter(getter)
{
}
T value(const RenderStyle& style) const
{
return (style.*m_getter)();
}
bool equals(const RenderStyle& a, const RenderStyle& b) const override
{
if (&a == &b)
return true;
return value(a) == value(b);
}
#if !LOG_DISABLED
void logBlend(const RenderStyle& from, const RenderStyle& to, const RenderStyle& destination, double progress) const final
{
LOG_WITH_STREAM(Animations, stream << " blending " << property() << " from " << value(from) << " to " << value(to) << " at " << TextStream::FormatNumberRespectingIntegers(progress) << " -> " << value(destination));
}
#endif
private:
T (RenderStyle::*m_getter)() const;
};
template <typename T>
class PropertyWrapper : public PropertyWrapperGetter<T> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapper(CSSPropertyID property, T (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T))
: PropertyWrapperGetter<T>(property, getter)
, m_setter(setter)
{
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const override
{
(destination.*m_setter)(blendFunc(this->value(from), this->value(to), context));
}
protected:
void (RenderStyle::*m_setter)(T);
};
class OffsetRotateWrapper final : public PropertyWrapperGetter<OffsetRotation> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
OffsetRotateWrapper()
: PropertyWrapperGetter(CSSPropertyOffsetRotate, &RenderStyle::offsetRotate)
{
}
private:
bool animationIsAccelerated(const Settings& settings) const final
{
#if ENABLE(THREADED_ANIMATION_RESOLUTION)
return settings.threadedAnimationResolutionEnabled();
#else
UNUSED_PARAM(settings);
return false;
#endif
}
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
return value(from).canBlend(value(to));
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
destination.setOffsetRotate(value(from).blend(value(to), context));
}
};
template <typename T>
class PositivePropertyWrapper final : public PropertyWrapper<T> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PositivePropertyWrapper(CSSPropertyID property, T (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T))
: PropertyWrapper<T>(property, getter, setter)
{
}
private:
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
auto blendedValue = blendFunc(this->value(from), this->value(to), context);
(destination.*this->m_setter)(blendedValue > 1 ? blendedValue : 1);
}
};
template <typename T>
class DiscretePropertyWrapper : public PropertyWrapperGetter<T> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
DiscretePropertyWrapper(CSSPropertyID property, T (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T))
: PropertyWrapperGetter<T>(property, getter)
, m_setter(setter)
{
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const override
{
ASSERT(!context.progress || context.progress == 1.0);
(destination.*this->m_setter)(this->value(context.progress ? to : from));
}
private:
bool canInterpolate(const RenderStyle&, const RenderStyle&, CompositeOperation) const final { return false; }
void (RenderStyle::*m_setter)(T);
};
class GridTemplatePropertyWrapper final : public PropertyWrapper<const GridTrackList&> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
GridTemplatePropertyWrapper(CSSPropertyID property, const GridTrackList& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const GridTrackList&))
: PropertyWrapper(property, getter, setter)
{
}
private:
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
(destination.*m_setter)(blendFunc(this->value(from), this->value(to), context));
}
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
return WebCore::canInterpolate(this->value(from), this->value(to));
}
};
class NinePieceImageRepeatWrapper final : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
NinePieceImageRepeatWrapper(CSSPropertyID property, NinePieceImageRule (RenderStyle::*horizontalGetter)() const, void (RenderStyle::*horizontalSetter)(NinePieceImageRule), NinePieceImageRule (RenderStyle::*verticalGetter)() const, void (RenderStyle::*verticalSetter)(NinePieceImageRule))
: AnimationPropertyWrapperBase(property)
, m_horizontalWrapper(DiscretePropertyWrapper<NinePieceImageRule>(property, horizontalGetter, horizontalSetter))
, m_verticalWrapper(DiscretePropertyWrapper<NinePieceImageRule>(property, verticalGetter, verticalSetter))
{
}
private:
bool canInterpolate(const RenderStyle&, const RenderStyle&, CompositeOperation) const final { return false; }
bool equals(const RenderStyle& a, const RenderStyle& b) const override
{
return m_horizontalWrapper.equals(a, b) && m_verticalWrapper.equals(a, b);
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
m_horizontalWrapper.blend(destination, from, to, context);
m_verticalWrapper.blend(destination, from, to, context);
}
#if !LOG_DISABLED
void logBlend(const RenderStyle& from, const RenderStyle& to, const RenderStyle& destination, double progress) const final
{
m_horizontalWrapper.logBlend(from, to, destination, progress);
m_verticalWrapper.logBlend(from, to, destination, progress);
}
#endif
DiscretePropertyWrapper<NinePieceImageRule> m_horizontalWrapper;
DiscretePropertyWrapper<NinePieceImageRule> m_verticalWrapper;
};
template <typename T>
class RefCountedPropertyWrapper : public PropertyWrapperGetter<T*> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
RefCountedPropertyWrapper(CSSPropertyID property, T* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(RefPtr<T>&&))
: PropertyWrapperGetter<T*>(property, getter)
, m_setter(setter)
{
}
private:
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
(destination.*this->m_setter)(blendFunc(this->value(from), this->value(to), context));
}
void (RenderStyle::*m_setter)(RefPtr<T>&&);
};
static bool canInterpolateLengths(const Length& from, const Length& to, bool isLengthPercentage)
{
if (from.type() == to.type())
return true;
// Some properties allow for <length-percentage> and <number> values. We must allow animating
// between a <length> and a <percentage>, but exclude animating between a <number> and either
// a <length> or <percentage>. We can use Length::isRelative() to determine whether we are
// dealing with a <number> as opposed to a <length> or <percentage>.
if (isLengthPercentage) {
return (from.isFixed() || from.isPercentOrCalculated() || from.isRelative())
&& (to.isFixed() || to.isPercentOrCalculated() || to.isRelative())
&& from.isRelative() == to.isRelative();
}
if (from.isCalculated())
return to.isFixed() || to.isPercentOrCalculated();
if (to.isCalculated())
return from.isFixed() || from.isPercentOrCalculated();
return false;
}
static bool lengthsRequireBlendingForAccumulativeIteration(const Length& from, const Length& to)
{
// If blending the values can yield a calc() value, we must go through the blending code for iterationComposite.
return from.isCalculated() || to.isCalculated() || from.type() != to.type();
}
class LengthPropertyWrapper : public PropertyWrapperGetter<const Length&> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
enum class Flags {
IsLengthPercentage = 1 << 0,
NegativeLengthsAreInvalid = 1 << 1,
};
LengthPropertyWrapper(CSSPropertyID property, const Length& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(Length&&), OptionSet<Flags> flags = { })
: PropertyWrapperGetter(property, getter)
, m_setter(setter)
, m_flags(flags)
{
}
protected:
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const override
{
return canInterpolateLengths(value(from), value(to), m_flags.contains(Flags::IsLengthPercentage));
}
bool requiresBlendingForAccumulativeIteration(const RenderStyle& from, const RenderStyle& to) const final
{
return lengthsRequireBlendingForAccumulativeIteration(value(from), value(to));
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const override
{
auto valueRange = m_flags.contains(Flags::NegativeLengthsAreInvalid) ? ValueRange::NonNegative : ValueRange::All;
(destination.*m_setter)(blendFunc(value(from), value(to), context, valueRange));
}
private:
void (RenderStyle::*m_setter)(Length&&);
OptionSet<Flags> m_flags;
};
static bool canInterpolateLengthVariants(const LengthSize& from, const LengthSize& to)
{
bool isLengthPercentage = true;
return canInterpolateLengths(from.width, to.width, isLengthPercentage)
&& canInterpolateLengths(from.height, to.height, isLengthPercentage);
}
static bool canInterpolateLengthVariants(const GapLength& from, const GapLength& to)
{
if (from.isNormal() || to.isNormal())
return false;
bool isLengthPercentage = true;
return canInterpolateLengths(from.length(), to.length(), isLengthPercentage);
}
class LengthPointPropertyWrapper : public PropertyWrapperGetter<const LengthPoint&> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
LengthPointPropertyWrapper(CSSPropertyID property, const LengthPoint& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(LengthPoint))
: PropertyWrapperGetter(property, getter)
, m_setter(setter)
{
}
private:
bool requiresBlendingForAccumulativeIteration(const RenderStyle& from, const RenderStyle& to) const final
{
auto fromLengthPoint = value(from);
auto toLengthPoint = value(to);
return lengthsRequireBlendingForAccumulativeIteration(fromLengthPoint.x, toLengthPoint.x)
|| lengthsRequireBlendingForAccumulativeIteration(fromLengthPoint.y, toLengthPoint.y);
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
(destination.*m_setter)(blendFunc(value(from), value(to), context));
}
void (RenderStyle::*m_setter)(LengthPoint);
};
// This class extends LengthPointPropertyWrapper to accommodate `auto` or `normal` values expressed as
// LengthPoint(Length(LengthType::Auto/Normal), Length(LengthType::Auto/Normal)). This is used for
// offset-anchor and offset-position, which allows `auto` and `normal`, and is expressed like so.
class LengthPointOrAutoPropertyWrapper : public LengthPointPropertyWrapper {
public:
LengthPointOrAutoPropertyWrapper(CSSPropertyID property, const LengthPoint& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(LengthPoint))
: LengthPointPropertyWrapper(property, getter, setter)
{
}
private:
// Check if it's possible to interpolate between the from and to values. In particular,
// it's only possible if they're both not auto or normal.
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
auto valueFrom = value(from);
auto valueTo = value(to);
return !valueFrom.x.isAuto() && !valueTo.x.isAuto() && !valueFrom.x.isNormal() && !valueTo.x.isNormal();
}
};
class OffsetLengthPointWrapper final : public LengthPointOrAutoPropertyWrapper {
public:
OffsetLengthPointWrapper(CSSPropertyID property, const LengthPoint& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(LengthPoint))
: LengthPointOrAutoPropertyWrapper(property, getter, setter)
{
}
private:
bool animationIsAccelerated(const Settings& settings) const final
{
#if ENABLE(THREADED_ANIMATION_RESOLUTION)
return settings.threadedAnimationResolutionEnabled();
#else
UNUSED_PARAM(settings);
return false;
#endif
}
};
static bool lengthVariantRequiresBlendingForAccumulativeIteration(const LengthSize& from, const LengthSize& to)
{
return lengthsRequireBlendingForAccumulativeIteration(from.width, to.width)
|| lengthsRequireBlendingForAccumulativeIteration(from.height, to.height);
}
static bool lengthVariantRequiresBlendingForAccumulativeIteration(const GapLength& from, const GapLength& to)
{
return from.isNormal() || to.isNormal() || lengthsRequireBlendingForAccumulativeIteration(from.length(), to.length());
}
template <typename T>
class LengthVariantPropertyWrapper final : public PropertyWrapperGetter<const T&> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
LengthVariantPropertyWrapper(CSSPropertyID property, const T& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T&&))
: PropertyWrapperGetter<const T&>(property, getter)
, m_setter(setter)
{
}
private:
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
return canInterpolateLengthVariants(this->value(from), this->value(to));
}
bool requiresBlendingForAccumulativeIteration(const RenderStyle& from, const RenderStyle& to) const final
{
return lengthVariantRequiresBlendingForAccumulativeIteration(this->value(from), this->value(to));
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
(destination.*m_setter)(blendFunc(this->value(from), this->value(to), context));
}
void (RenderStyle::*m_setter)(T&&);
};
class OptionalLengthPropertyWrapper : public PropertyWrapperGetter<std::optional<Length>> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
enum class Flags {
IsLengthPercentage = 1 << 0,
NegativeLengthsAreInvalid = 1 << 1,
};
OptionalLengthPropertyWrapper(CSSPropertyID property, std::optional<Length> (RenderStyle::*getter)() const, void (RenderStyle::*setter)(std::optional<Length>), OptionSet<Flags> flags = { })
: PropertyWrapperGetter<std::optional<Length>>(property, getter)
, m_setter(setter)
, m_flags(flags)
{
}
protected:
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const override
{
if (!this->value(from) || !this->value(to))
return false;
bool isLengthPercentage = m_flags.contains(Flags::IsLengthPercentage);
return canInterpolateLengths(*this->value(from), *this->value(to), isLengthPercentage);
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const override
{
if (context.isDiscrete) {
ASSERT(!context.progress || context.progress == 1);
(destination.*m_setter)(context.progress ? this->value(to) : this->value(from));
return;
}
auto valueRange = m_flags.contains(Flags::NegativeLengthsAreInvalid) ? ValueRange::NonNegative : ValueRange::All;
(destination.*m_setter)(blendFunc(*this->value(from), *this->value(to), context, valueRange));
}
private:
void (RenderStyle::*m_setter)(std::optional<Length>);
OptionSet<Flags> m_flags;
};
class ContainIntrinsicLengthPropertyWrapper final : public OptionalLengthPropertyWrapper {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
ContainIntrinsicLengthPropertyWrapper(CSSPropertyID property, std::optional<Length> (RenderStyle::*getter)() const, void (RenderStyle::*setter)(std::optional<Length>), ContainIntrinsicSizeType (RenderStyle::*typeGetter)() const, void (RenderStyle::*typeSetter)(ContainIntrinsicSizeType))
: OptionalLengthPropertyWrapper(property, getter, setter, { Flags::NegativeLengthsAreInvalid })
, m_containIntrinsicSizeTypeGetter(typeGetter)
, m_containIntrinsicSizeTypeSetter(typeSetter)
{
}
private:
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation operation) const final
{
if ((from.*m_containIntrinsicSizeTypeGetter)() != (to.*m_containIntrinsicSizeTypeGetter)())
return false;
return OptionalLengthPropertyWrapper::canInterpolate(from, to, operation);
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
auto type = context.progress < 0.5 ? (from.*m_containIntrinsicSizeTypeGetter)() : (to.*m_containIntrinsicSizeTypeGetter)();
(destination.*m_containIntrinsicSizeTypeSetter)(type);
OptionalLengthPropertyWrapper::blend(destination, from, to, context);
}
ContainIntrinsicSizeType (RenderStyle::*m_containIntrinsicSizeTypeGetter)() const;
void (RenderStyle::*m_containIntrinsicSizeTypeSetter)(ContainIntrinsicSizeType);
};
class LengthBoxPropertyWrapper : public PropertyWrapperGetter<const LengthBox&> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
enum class Flags {
IsLengthPercentage = 1 << 0,
UsesFillKeyword = 1 << 1,
AllowsNegativeValues = 1 << 2,
MayOverrideBorderWidths = 1 << 3,
};
LengthBoxPropertyWrapper(CSSPropertyID property, const LengthBox& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(LengthBox&&), OptionSet<Flags> flags = { })
: PropertyWrapperGetter(property, getter)
, m_setter(setter)
, m_flags(flags)
{
}
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const override
{
if (m_flags.contains(Flags::UsesFillKeyword)) {
if (property() == CSSPropertyBorderImageSlice && from.borderImage().fill() != to.borderImage().fill())
return false;
if (property() == CSSPropertyMaskBorderSlice && from.maskBorder().fill() != to.maskBorder().fill())
return false;
}
bool isLengthPercentage = m_flags.contains(Flags::IsLengthPercentage);
if (m_flags.contains(Flags::MayOverrideBorderWidths)) {
bool overridesBorderWidths = from.borderImage().overridesBorderWidths();
if (overridesBorderWidths != to.borderImage().overridesBorderWidths())
return false;
// Even if this property accepts <length-percentage>, border widths can only be a <length>.
if (overridesBorderWidths)
isLengthPercentage = false;
}
auto& fromLengthBox = value(from);
auto& toLengthBox = value(to);
return canInterpolateLengths(fromLengthBox.top(), toLengthBox.top(), isLengthPercentage)
&& canInterpolateLengths(fromLengthBox.right(), toLengthBox.right(), isLengthPercentage)
&& canInterpolateLengths(fromLengthBox.bottom(), toLengthBox.bottom(), isLengthPercentage)
&& canInterpolateLengths(fromLengthBox.left(), toLengthBox.left(), isLengthPercentage);
}
bool requiresBlendingForAccumulativeIteration(const RenderStyle& from, const RenderStyle& to) const final
{
auto& fromLengthBox = value(from);
auto& toLengthBox = value(to);
return lengthsRequireBlendingForAccumulativeIteration(fromLengthBox.top(), toLengthBox.top())
&& lengthsRequireBlendingForAccumulativeIteration(fromLengthBox.right(), toLengthBox.right())
&& lengthsRequireBlendingForAccumulativeIteration(fromLengthBox.bottom(), toLengthBox.bottom())
&& lengthsRequireBlendingForAccumulativeIteration(fromLengthBox.left(), toLengthBox.left());
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const override
{
if (m_flags.contains(Flags::UsesFillKeyword)) {
if (property() == CSSPropertyBorderImageSlice)
destination.setBorderImageSliceFill((!context.progress || !context.isDiscrete ? from : to).borderImage().fill());
else if (property() == CSSPropertyMaskBorderSlice)
destination.setMaskBorderSliceFill((!context.progress || !context.isDiscrete ? from : to).maskBorder().fill());
}
if (m_flags.contains(Flags::MayOverrideBorderWidths))
destination.setBorderImageWidthOverridesBorderWidths((!context.progress || !context.isDiscrete ? from : to).borderImage().overridesBorderWidths());
if (context.isDiscrete) {
// It is important we have this non-interpolated shortcut because certain CSS properties
// represented as a LengthBox, such as border-image-slice, don't know how to deal with
// calculated Length values, see for instance valueForImageSliceSide(const Length&).
(destination.*m_setter)(context.progress ? LengthBox(value(to)) : LengthBox(value(from)));
return;
}
auto valueRange = m_flags.contains(Flags::AllowsNegativeValues) ? ValueRange::All : ValueRange::NonNegative;
(destination.*m_setter)(blendFunc(value(from), value(to), context, valueRange));
}
void (RenderStyle::*m_setter)(LengthBox&&);
OptionSet<Flags> m_flags;
};
class ClipWrapper final : public LengthBoxPropertyWrapper {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
ClipWrapper()
: LengthBoxPropertyWrapper(CSSPropertyClip, &RenderStyle::clip, &RenderStyle::setClip, { LengthBoxPropertyWrapper::Flags::AllowsNegativeValues })
{
}
private:
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation compositeOperation) const final
{
return from.hasClip() && to.hasClip() && LengthBoxPropertyWrapper::canInterpolate(from, to, compositeOperation);
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
LengthBoxPropertyWrapper::blend(destination, from, to, context);
destination.setHasClip(true);
}
};
class PathOperationPropertyWrapper : public RefCountedPropertyWrapper<PathOperation> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PathOperationPropertyWrapper(CSSPropertyID property, PathOperation* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(RefPtr<PathOperation>&&))
: RefCountedPropertyWrapper(property, getter, setter)
{
}
private:
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const override
{
auto* fromPath = value(from);
auto* toPath = value(to);
return fromPath && toPath && fromPath->canBlend(*toPath);
}
bool equals(const RenderStyle& a, const RenderStyle& b) const final
{
// If the style pointers are the same, don't bother doing the test.
if (&a == &b)
return true;
auto* clipPathA = value(a);
auto* clipPathB = value(b);
if (clipPathA == clipPathB)
return true;
if (!clipPathA || !clipPathB)
return false;
return *clipPathA == *clipPathB;
}
};
class OffsetPathWrapper final : public PathOperationPropertyWrapper {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
OffsetPathWrapper()
: PathOperationPropertyWrapper(CSSPropertyOffsetPath, &RenderStyle::offsetPath, &RenderStyle::setOffsetPath)
{
}
private:
bool animationIsAccelerated(const Settings& settings) const final
{
#if ENABLE(THREADED_ANIMATION_RESOLUTION)
return settings.threadedAnimationResolutionEnabled();
#else
UNUSED_PARAM(settings);
return false;
#endif
}
};
#if ENABLE(VARIATION_FONTS)
class PropertyWrapperFontVariationSettings final : public PropertyWrapper<FontVariationSettings> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperFontVariationSettings()
: PropertyWrapper(CSSPropertyFontVariationSettings, &RenderStyle::fontVariationSettings, &RenderStyle::setFontVariationSettings)
{
}
private:
bool equals(const RenderStyle& a, const RenderStyle& b) const final
{
// If the style pointers are the same, don't bother doing the test.
if (&a == &b)
return true;
return value(a) == value(b);
}
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
auto fromVariationSettings = value(from);
auto toVariationSettings = value(to);
if (fromVariationSettings.size() != toVariationSettings.size())
return false;
auto size = fromVariationSettings.size();
for (unsigned i = 0; i < size; ++i) {
if (fromVariationSettings.at(i).tag() != toVariationSettings.at(i).tag())
return false;
}
return true;
}
};
#endif
class PropertyWrapperShape final : public RefCountedPropertyWrapper<ShapeValue> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperShape(CSSPropertyID property, ShapeValue* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(RefPtr<ShapeValue>&&))
: RefCountedPropertyWrapper(property, getter, setter)
{
}
private:
bool equals(const RenderStyle& a, const RenderStyle& b) const final
{
// If the style pointers are the same, don't bother doing the test.
if (&a == &b)
return true;
auto* shapeA = value(a);
auto* shapeB = value(b);
if (shapeA == shapeB)
return true;
if (!shapeA || !shapeB)
return false;
return *shapeA == *shapeB;
}
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
auto* fromShape = value(from);
auto* toShape = value(to);
return fromShape && toShape && fromShape->canBlend(*toShape);
}
};
class StyleImagePropertyWrapper final : public RefCountedPropertyWrapper<StyleImage> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
StyleImagePropertyWrapper(CSSPropertyID property, StyleImage* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(RefPtr<StyleImage>&&))
: RefCountedPropertyWrapper(property, getter, setter)
{
}
private:
bool equals(const RenderStyle& a, const RenderStyle& b) const final
{
if (&a == &b)
return true;
auto* imageA = value(a);
auto* imageB = value(b);
return arePointingToEqualData(imageA, imageB);
}
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
return value(from) && value(to);
}
};
template <typename T>
class AcceleratedPropertyWrapper final : public PropertyWrapper<T> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
AcceleratedPropertyWrapper(CSSPropertyID property, T (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T))
: PropertyWrapper<T>(property, getter, setter)
{
}
private:
bool animationIsAccelerated(const Settings&) const final { return true; }
bool requiresBlendingForAccumulativeIteration(const RenderStyle&, const RenderStyle&) const final { return this->property() == CSSPropertyTransform; }
};
class AcceleratedTransformOperationsPropertyWrapper final : public PropertyWrapperGetter<const TransformOperations&> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
AcceleratedTransformOperationsPropertyWrapper()
: PropertyWrapperGetter<const TransformOperations&>(CSSPropertyTransform, &RenderStyle::transform)
{
}
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation compositeOperation) const override
{
if (compositeOperation == CompositeOperation::Replace)
return !this->value(to).shouldFallBackToDiscreteAnimation(this->value(from), { });
return true;
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const override
{
destination.setTransform(blendFunc(this->value(from), this->value(to), context));
}
private:
bool animationIsAccelerated(const Settings&) const final { return true; }
bool requiresBlendingForAccumulativeIteration(const RenderStyle&, const RenderStyle&) const final { return true; }
};
template <typename T>
class AcceleratedIndividualTransformPropertyWrapper final : public RefCountedPropertyWrapper<T> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
AcceleratedIndividualTransformPropertyWrapper(CSSPropertyID property, T* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(RefPtr<T>&&))
: RefCountedPropertyWrapper<T>(property, getter, setter)
{
}
private:
bool animationIsAccelerated(const Settings&) const final { return true; }
bool equals(const RenderStyle& a, const RenderStyle& b) const final
{
return arePointingToEqualData(this->value(a), this->value(b));
}
};
class PropertyWrapperFilter final : public PropertyWrapperGetter<const FilterOperations&> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperFilter(CSSPropertyID property, const FilterOperations& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(FilterOperations&&))
: PropertyWrapperGetter<const FilterOperations&>(property, getter)
, m_setter(setter)
{
}
private:
bool animationIsAccelerated(const Settings&) const final
{
return property() == CSSPropertyFilter
|| property() == CSSPropertyBackdropFilter
|| property() == CSSPropertyWebkitBackdropFilter;
}
bool requiresBlendingForAccumulativeIteration(const RenderStyle&, const RenderStyle&) const final { return true; }
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation compositeOperation) const final
{
return value(from).canInterpolate(value(to), compositeOperation);
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
(destination.*m_setter)(blendFunc(value(from), value(to), context));
}
void (RenderStyle::*m_setter)(FilterOperations&&);
};
static inline size_t shadowListLength(const ShadowData* shadow)
{
size_t count;
for (count = 0; shadow; shadow = shadow->next())
++count;
return count;
}
static inline const ShadowData* shadowForBlending(const ShadowData* srcShadow, const ShadowData* otherShadow)
{
static NeverDestroyed<ShadowData> defaultShadowData {
Style::BoxShadow {
.color = { Color::transparentBlack },
.location = { { 0 }, { 0 } },
.blur = { 0 },
.spread = { 0 },
.inset = std::nullopt,
.isWebkitBoxShadow = false
}
};
static NeverDestroyed<ShadowData> defaultInsetShadowData {
Style::BoxShadow {
.color = { Color::transparentBlack },
.location = { { 0 }, { 0 } },
.blur = { 0 },
.spread = { 0 },
.inset = CSS::Keyword::Inset { },
.isWebkitBoxShadow = false
}
};
static NeverDestroyed<ShadowData> defaultWebKitBoxShadowData {
Style::BoxShadow {
.color = { Color::transparentBlack },
.location = { { 0 }, { 0 } },
.blur = { 0 },
.spread = { 0 },
.inset = std::nullopt,
.isWebkitBoxShadow = true
}
};
static NeverDestroyed<ShadowData> defaultInsetWebKitBoxShadowData {
Style::BoxShadow {
.color = { Color::transparentBlack },
.location = { { 0 }, { 0 } },
.blur = { 0 },
.spread = { 0 },
.inset = CSS::Keyword::Inset { },
.isWebkitBoxShadow = true
}
};
if (srcShadow)
return srcShadow;
if (otherShadow->style() == ShadowStyle::Inset)
return otherShadow->isWebkitBoxShadow() ? &defaultInsetWebKitBoxShadowData.get() : &defaultInsetShadowData.get();
return otherShadow->isWebkitBoxShadow() ? &defaultWebKitBoxShadowData.get() : &defaultShadowData.get();
}
class PropertyWrapperShadow final : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperShadow(CSSPropertyID property, const ShadowData* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(std::unique_ptr<ShadowData>, bool))
: AnimationPropertyWrapperBase(property)
, m_getter(getter)
, m_setter(setter)
{
}
private:
bool requiresBlendingForAccumulativeIteration(const RenderStyle&, const RenderStyle&) const final { return true; }
bool equals(const RenderStyle& a, const RenderStyle& b) const final
{
if (&a == &b)
return true;
const ShadowData* shadowA = (a.*m_getter)();
const ShadowData* shadowB = (b.*m_getter)();
while (true) {
// end of both lists
if (!shadowA && !shadowB)
return true;
// end of just one of the lists
if (!shadowA || !shadowB)
return false;
if (*shadowA != *shadowB)
return false;
shadowA = shadowA->next();
shadowB = shadowB->next();
}
return true;
}
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation compositeOperation) const final
{
if (compositeOperation != CompositeOperation::Replace)
return true;
const ShadowData* fromShadow = (from.*m_getter)();
const ShadowData* toShadow = (to.*m_getter)();
// The only scenario where we can't interpolate is if specified items don't have the same shadow style.
while (fromShadow && toShadow) {
if (fromShadow->style() != toShadow->style())
return false;
fromShadow = fromShadow->next();
toShadow = toShadow->next();
}
return true;
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
const ShadowData* fromShadow = (from.*m_getter)();
const ShadowData* toShadow = (to.*m_getter)();
if (context.isDiscrete) {
ASSERT(!context.progress || context.progress == 1.0);
auto* shadow = context.progress ? toShadow : fromShadow;
(destination.*m_setter)(shadow ? makeUnique<ShadowData>(*shadow) : nullptr, false);
return;
}
int fromLength = shadowListLength(fromShadow);
int toLength = shadowListLength(toShadow);
if (fromLength == toLength || (fromLength <= 1 && toLength <= 1)) {
(destination.*m_setter)(blendSimpleOrMatchedShadowLists(fromShadow, toShadow, from, to, context), false);
return;
}
(destination.*m_setter)(blendMismatchedShadowLists(fromShadow, toShadow, fromLength, toLength, from, to, context), false);
}
#if !LOG_DISABLED
void logBlend(const RenderStyle&, const RenderStyle&, const RenderStyle&, double progress) const final
{
// FIXME: better logging.
LOG_WITH_STREAM(Animations, stream << " blending ShadowData at " << TextStream::FormatNumberRespectingIntegers(progress));
}
#endif
std::unique_ptr<ShadowData> addShadowLists(const ShadowData* shadowA, const ShadowData* shadowB) const
{
std::unique_ptr<ShadowData> newShadowData;
ShadowData* lastShadow = nullptr;
auto addShadows = [&](const ShadowData* shadow) {
while (shadow) {
auto blendedShadow = makeUnique<ShadowData>(*shadow);
auto* blendedShadowPtr = blendedShadow.get();
if (!lastShadow)
newShadowData = WTFMove(blendedShadow);
else
lastShadow->setNext(WTFMove(blendedShadow));
lastShadow = blendedShadowPtr;
shadow = shadow ? shadow->next() : nullptr;
}
};
addShadows(shadowB);
addShadows(shadowA);
return newShadowData;
}
std::unique_ptr<ShadowData> blendSimpleOrMatchedShadowLists(const ShadowData* shadowA, const ShadowData* shadowB, const RenderStyle& styleA, const RenderStyle& styleB, const CSSPropertyBlendingContext& context) const
{
// from or to might be null in which case we don't want to do additivity, but do replace instead.
if (shadowA && shadowB && context.compositeOperation == CompositeOperation::Add)
return addShadowLists(shadowA, shadowB);
std::unique_ptr<ShadowData> newShadowData;
ShadowData* lastShadow = nullptr;
while (shadowA || shadowB) {
const ShadowData* srcShadow = shadowForBlending(shadowA, shadowB);
const ShadowData* dstShadow = shadowForBlending(shadowB, shadowA);
std::unique_ptr<ShadowData> blendedShadow = blendFunc(srcShadow, dstShadow, styleA, styleB, context);
ShadowData* blendedShadowPtr = blendedShadow.get();
if (!lastShadow)
newShadowData = WTFMove(blendedShadow);
else
lastShadow->setNext(WTFMove(blendedShadow));
lastShadow = blendedShadowPtr;
shadowA = shadowA ? shadowA->next() : 0;
shadowB = shadowB ? shadowB->next() : 0;
}
return newShadowData;
}
std::unique_ptr<ShadowData> blendMismatchedShadowLists(const ShadowData* shadowA, const ShadowData* shadowB, int fromLength, int toLength, const RenderStyle& styleA, const RenderStyle& styleB, const CSSPropertyBlendingContext& context) const
{
if (shadowA && shadowB && context.compositeOperation != CompositeOperation::Replace)
return addShadowLists(shadowA, shadowB);
// The shadows in ShadowData are stored in reverse order, so when animating mismatched lists,
// reverse them and match from the end.
Vector<const ShadowData*, 4> fromShadows(fromLength);
for (int i = fromLength - 1; i >= 0; --i) {
fromShadows[i] = shadowA;
shadowA = shadowA->next();
}
Vector<const ShadowData*, 4> toShadows(toLength);
for (int i = toLength - 1; i >= 0; --i) {
toShadows[i] = shadowB;
shadowB = shadowB->next();
}
std::unique_ptr<ShadowData> newShadowData;
int maxLength = std::max(fromLength, toLength);
for (int i = 0; i < maxLength; ++i) {
const ShadowData* fromShadow = i < fromLength ? fromShadows[i] : 0;
const ShadowData* toShadow = i < toLength ? toShadows[i] : 0;
const ShadowData* srcShadow = shadowForBlending(fromShadow, toShadow);
const ShadowData* dstShadow = shadowForBlending(toShadow, fromShadow);
std::unique_ptr<ShadowData> blendedShadow = blendFunc(srcShadow, dstShadow, styleA, styleB, context);
// Insert at the start of the list to preserve the order.
blendedShadow->setNext(WTFMove(newShadowData));
newShadowData = WTFMove(blendedShadow);
}
return newShadowData;
}
const ShadowData* (RenderStyle::*m_getter)() const;
void (RenderStyle::*m_setter)(std::unique_ptr<ShadowData>, bool);
};
class PropertyWrapperStyleColor : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperStyleColor(CSSPropertyID property, const Style::Color& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Style::Color&))
: AnimationPropertyWrapperBase(property)
, m_getter(getter)
, m_setter(setter)
{
}
bool equals(const RenderStyle& a, const RenderStyle& b) const override
{
if (&a == &b)
return true;
auto& fromStyleColor = value(a);
auto& toStyleColor = value(b);
if (fromStyleColor.isCurrentColor() && toStyleColor.isCurrentColor())
return true;
if (fromStyleColor.isResolvedColor() && toStyleColor.isResolvedColor())
return fromStyleColor.resolvedColor() == toStyleColor.resolvedColor();
return a.colorResolvingCurrentColor(fromStyleColor) == b.colorResolvingCurrentColor(toStyleColor);
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const override
{
auto& fromStyleColor = value(from);
auto& toStyleColor = value(to);
// We don't animate on currentcolor-only transition.
// https://github.com/WebKit/WebKit/blob/main/LayoutTests/imported/w3c/web-platform-tests/css/css-transitions/currentcolor-animation-001.html#L27
if (fromStyleColor.isCurrentColor() && toStyleColor.isCurrentColor())
return;
auto fromColor = from.colorResolvingCurrentColor(fromStyleColor);
auto toColor = to.colorResolvingCurrentColor(toStyleColor);
auto result = blendFunc(fromColor, toColor, context);
(destination.*m_setter)(WTFMove(result));
}
#if !LOG_DISABLED
void logBlend(const RenderStyle& from, const RenderStyle& to, const RenderStyle& destination, double progress) const final
{
// FIXME: better logging.
LOG_WITH_STREAM(Animations, stream << " blending " << property() << " from " << value(from) << " to " << value(to) << " at " << TextStream::FormatNumberRespectingIntegers(progress) << " -> " << value(destination));
}
#endif
private:
const Style::Color& value(const RenderStyle& style) const
{
return (style.*m_getter)();
}
const Style::Color& (RenderStyle::*m_getter)() const;
void (RenderStyle::*m_setter)(const Style::Color&);
};
class PropertyWrapperColor : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperColor(CSSPropertyID property, const Color& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
: AnimationPropertyWrapperBase(property)
, m_getter(getter)
, m_setter(setter)
{
}
bool equals(const RenderStyle& a, const RenderStyle& b) const override
{
if (&a == &b)
return true;
return value(a) == value(b);
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const override
{
auto result = blendFunc(value(from), value(to), context);
(destination.*m_setter)(WTFMove(result));
}
#if !LOG_DISABLED
void logBlend(const RenderStyle& from, const RenderStyle& to, const RenderStyle& destination, double progress) const final
{
// FIXME: better logging.
LOG_WITH_STREAM(Animations, stream << " blending " << property() << " from " << value(from) << " to " << value(to) << " at " << TextStream::FormatNumberRespectingIntegers(progress) << " -> " << value(destination));
}
#endif
private:
const Color& value(const RenderStyle& style) const
{
return (style.*m_getter)();
}
const Color& (RenderStyle::*m_getter)() const;
void (RenderStyle::*m_setter)(const Color&);
};
class ScrollbarColorPropertyWrapper final : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
ScrollbarColorPropertyWrapper()
: AnimationPropertyWrapperBase(CSSPropertyScrollbarColor)
, m_thumbWrapper(makeUnique<PropertyWrapperStyleColor>(CSSPropertyScrollbarColor, &RenderStyle::scrollbarThumbColor, &RenderStyle::setScrollbarThumbColor))
, m_trackWrapper(makeUnique<PropertyWrapperStyleColor>(CSSPropertyScrollbarColor, &RenderStyle::scrollbarTrackColor, &RenderStyle::setScrollbarTrackColor))
{
}
private:
bool equals(const RenderStyle& a, const RenderStyle& b) const final
{
bool aAuto = !a.scrollbarColor().has_value();
bool bAuto = !b.scrollbarColor().has_value();
if (aAuto || bAuto)
return aAuto == bAuto;
return m_thumbWrapper->equals(a, b) && m_trackWrapper->equals(a, b);
}
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
return from.scrollbarColor().has_value() && to.scrollbarColor().has_value();
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
if (canInterpolate(from, to, context.compositeOperation)) {
destination.setScrollbarColor(from.scrollbarColor().value());
m_thumbWrapper->blend(destination, from, to, context);
m_trackWrapper->blend(destination, from, to, context);
return;
}
ASSERT(!context.progress || context.progress == 1.0);
auto& blendingRenderStyle = context.progress ? to : from;
destination.setScrollbarColor(blendingRenderStyle.scrollbarColor());
}
std::unique_ptr<PropertyWrapperStyleColor> m_thumbWrapper;
std::unique_ptr<PropertyWrapperStyleColor> m_trackWrapper;
#if !LOG_DISABLED
void logBlend(const RenderStyle& from, const RenderStyle& to, const RenderStyle& destination, double progress) const final
{
m_thumbWrapper->logBlend(from, to, destination, progress);
m_trackWrapper->logBlend(from, to, destination, progress);
}
#endif
};
class PropertyWrapperVisitedAffectedStyleColor : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperVisitedAffectedStyleColor(CSSPropertyID property, const Style::Color& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Style::Color&), const Style::Color& (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visitedSetter)(const Style::Color&))
: AnimationPropertyWrapperBase(property)
, m_wrapper(makeUnique<PropertyWrapperStyleColor>(property, getter, setter))
, m_visitedWrapper(makeUnique<PropertyWrapperStyleColor>(property, visitedGetter, visitedSetter))
{
}
protected:
bool requiresBlendingForAccumulativeIteration(const RenderStyle&, const RenderStyle&) const final { return true; }
bool equals(const RenderStyle& a, const RenderStyle& b) const override
{
return m_wrapper->equals(a, b) && m_visitedWrapper->equals(a, b);
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const override
{
m_wrapper->blend(destination, from, to, context);
m_visitedWrapper->blend(destination, from, to, context);
}
std::unique_ptr<PropertyWrapperStyleColor> m_wrapper;
std::unique_ptr<PropertyWrapperStyleColor> m_visitedWrapper;
private:
#if !LOG_DISABLED
void logBlend(const RenderStyle& from, const RenderStyle& to, const RenderStyle& destination, double progress) const final
{
m_wrapper->logBlend(from, to, destination, progress);
m_visitedWrapper->logBlend(from, to, destination, progress);
}
#endif
};
class PropertyWrapperVisitedAffectedColor : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperVisitedAffectedColor(CSSPropertyID property, const Color& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&), const Color& (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visitedSetter)(const Color&))
: AnimationPropertyWrapperBase(property)
, m_wrapper(makeUnique<PropertyWrapperColor>(property, getter, setter))
, m_visitedWrapper(makeUnique<PropertyWrapperColor>(property, visitedGetter, visitedSetter))
{
}
protected:
bool requiresBlendingForAccumulativeIteration(const RenderStyle&, const RenderStyle&) const final { return true; }
bool equals(const RenderStyle& a, const RenderStyle& b) const override
{
return m_wrapper->equals(a, b) && m_visitedWrapper->equals(a, b);
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const override
{
m_wrapper->blend(destination, from, to, context);
m_visitedWrapper->blend(destination, from, to, context);
}
std::unique_ptr<PropertyWrapperColor> m_wrapper;
std::unique_ptr<PropertyWrapperColor> m_visitedWrapper;
private:
#if !LOG_DISABLED
void logBlend(const RenderStyle& from, const RenderStyle& to, const RenderStyle& destination, double progress) const final
{
m_wrapper->logBlend(from, to, destination, progress);
m_visitedWrapper->logBlend(from, to, destination, progress);
}
#endif
};
class AccentColorPropertyWrapper final : public PropertyWrapperStyleColor {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
AccentColorPropertyWrapper()
: PropertyWrapperStyleColor(CSSPropertyAccentColor, &RenderStyle::accentColor, &RenderStyle::setAccentColor)
{
}
private:
bool equals(const RenderStyle& a, const RenderStyle& b) const final
{
return a.hasAutoAccentColor() == b.hasAutoAccentColor()
&& PropertyWrapperStyleColor::equals(a, b);
}
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
return !from.hasAutoAccentColor() && !to.hasAutoAccentColor();
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
if (canInterpolate(from, to, context.compositeOperation)) {
PropertyWrapperStyleColor::blend(destination, from, to, context);
return;
}
ASSERT(!context.progress || context.progress == 1.0);
auto& blendingRenderStyle = context.progress ? to : from;
if (blendingRenderStyle.hasAutoAccentColor())
destination.setHasAutoAccentColor();
else
destination.setAccentColor(blendingRenderStyle.accentColor());
}
};
static bool canInterpolateCaretColor(const RenderStyle& from, const RenderStyle& to, bool visited)
{
if (visited)
return !from.hasVisitedLinkAutoCaretColor() && !to.hasVisitedLinkAutoCaretColor();
return !from.hasAutoCaretColor() && !to.hasAutoCaretColor();
}
class CaretColorPropertyWrapper final : public PropertyWrapperVisitedAffectedStyleColor {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
CaretColorPropertyWrapper()
: PropertyWrapperVisitedAffectedStyleColor(CSSPropertyCaretColor, &RenderStyle::caretColor, &RenderStyle::setCaretColor, &RenderStyle::visitedLinkCaretColor, &RenderStyle::setVisitedLinkCaretColor)
{
}
private:
bool equals(const RenderStyle& a, const RenderStyle& b) const final
{
return a.hasAutoCaretColor() == b.hasAutoCaretColor()
&& a.hasVisitedLinkAutoCaretColor() == b.hasVisitedLinkAutoCaretColor()
&& PropertyWrapperVisitedAffectedStyleColor::equals(a, b);
}
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
return canInterpolateCaretColor(from, to, false) || canInterpolateCaretColor(from, to, true);
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
if (canInterpolateCaretColor(from, to, false))
m_wrapper->blend(destination, from, to, context);
else {
auto& blendingRenderStyle = context.progress < 0.5 ? from : to;
if (blendingRenderStyle.hasAutoCaretColor())
destination.setHasAutoCaretColor();
else
destination.setCaretColor(blendingRenderStyle.caretColor());
}
if (canInterpolateCaretColor(from, to, true))
m_visitedWrapper->blend(destination, from, to, context);
else {
auto& blendingRenderStyle = context.progress < 0.5 ? from : to;
if (blendingRenderStyle.hasVisitedLinkAutoCaretColor())
destination.setHasVisitedLinkAutoCaretColor();
else
destination.setVisitedLinkCaretColor(blendingRenderStyle.visitedLinkCaretColor());
}
}
};
// Wrapper base class for an animatable property in a FillLayer
class FillLayerAnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
FillLayerAnimationPropertyWrapperBase(CSSPropertyID property)
: m_property(property)
{
}
virtual ~FillLayerAnimationPropertyWrapperBase() = default;
CSSPropertyID property() const { return m_property; }
virtual bool equals(const FillLayer*, const FillLayer*) const = 0;
virtual void blend(FillLayer*, const FillLayer*, const FillLayer*, const CSSPropertyBlendingContext&) const = 0;
virtual bool canInterpolate(const FillLayer*, const FillLayer*) const { return true; }
#if !LOG_DISABLED
virtual void logBlend(const FillLayer* destination, const FillLayer*, const FillLayer*, double) const = 0;
#endif
private:
CSSPropertyID m_property;
};
template <typename T>
class FillLayerPropertyWrapperGetter : public FillLayerAnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
WTF_MAKE_NONCOPYABLE(FillLayerPropertyWrapperGetter);
public:
FillLayerPropertyWrapperGetter(CSSPropertyID property, T (FillLayer::*getter)() const)
: FillLayerAnimationPropertyWrapperBase(property)
, m_getter(getter)
{
}
protected:
bool equals(const FillLayer* a, const FillLayer* b) const override
{
if (a == b)
return true;
if (!a || !b)
return false;
return value(a) == value(b);
}
T value(const FillLayer* layer) const
{
return (layer->*m_getter)();
}
#if !LOG_DISABLED
void logBlend(const FillLayer* destination, const FillLayer* from, const FillLayer* to, double progress) const override
{
LOG_WITH_STREAM(Animations, stream << " blending " << property() << " from " << value(from) << " to " << value(to) << " at " << TextStream::FormatNumberRespectingIntegers(progress) << " -> " << value(destination));
}
#endif
private:
T (FillLayer::*m_getter)() const;
};
template <typename T>
class FillLayerPropertyWrapper final : public FillLayerPropertyWrapperGetter<const T&> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
FillLayerPropertyWrapper(CSSPropertyID property, const T& (FillLayer::*getter)() const, void (FillLayer::*setter)(T))
: FillLayerPropertyWrapperGetter<const T&>(property, getter)
, m_setter(setter)
{
}
private:
void blend(FillLayer* destination, const FillLayer* from, const FillLayer* to, const CSSPropertyBlendingContext& context) const final
{
(destination->*this->m_setter)(blendFunc(this->value(from), this->value(to), context));
}
bool canInterpolate(const FillLayer* from, const FillLayer* to) const final
{
return canInterpolateLengthVariants(this->value(from), this->value(to));
}
#if !LOG_DISABLED
void logBlend(const FillLayer* destination, const FillLayer* from, const FillLayer* to, double progress) const final
{
LOG_WITH_STREAM(Animations, stream << " blending " << FillLayerPropertyWrapperGetter<const T&>::property()
<< " from " << FillLayerPropertyWrapperGetter<const T&>::value(from)
<< " to " << FillLayerPropertyWrapperGetter<const T&>::value(to)
<< " at " << TextStream::FormatNumberRespectingIntegers(progress) << " -> " << FillLayerPropertyWrapperGetter<const T&>::value(destination));
}
#endif
void (FillLayer::*m_setter)(T);
};
class FillLayerPositionPropertyWrapper final : public FillLayerPropertyWrapperGetter<const Length&> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
FillLayerPositionPropertyWrapper(CSSPropertyID property, const Length& (FillLayer::*lengthGetter)() const, void (FillLayer::*lengthSetter)(Length), Edge (FillLayer::*originGetter)() const, void (FillLayer::*originSetter)(Edge), Edge farEdge)
: FillLayerPropertyWrapperGetter(property, lengthGetter)
, m_lengthSetter(lengthSetter)
, m_originGetter(originGetter)
, m_originSetter(originSetter)
, m_farEdge(farEdge)
{
}
private:
bool equals(const FillLayer* a, const FillLayer* b) const final
{
if (a == b)
return true;
if (!a || !b)
return false;
auto fromLength = value(a);
auto toLength = value(b);
Edge fromEdge = (a->*m_originGetter)();
Edge toEdge = (b->*m_originGetter)();
return fromLength == toLength && fromEdge == toEdge;
}
void blend(FillLayer* destination, const FillLayer* from, const FillLayer* to, const CSSPropertyBlendingContext& context) const final
{
auto fromLength = value(from);
auto toLength = value(to);
Edge fromEdge = (from->*m_originGetter)();
Edge toEdge = (to->*m_originGetter)();
Edge destinationEdge = toEdge;
if (fromEdge != toEdge) {
// Convert the right/bottom into a calc expression,
if (fromEdge == m_farEdge)
fromLength = convertTo100PercentMinusLength(fromLength);
else if (toEdge == m_farEdge) {
toLength = convertTo100PercentMinusLength(toLength);
destinationEdge = fromEdge; // Now we have a calc(100% - l), it's relative to the left/top edge.
}
}
(destination->*m_originSetter)(destinationEdge);
(destination->*m_lengthSetter)(blendFunc(fromLength, toLength, context));
}
#if !LOG_DISABLED
void logBlend(const FillLayer* destination, const FillLayer* from, const FillLayer* to, double progress) const final
{
LOG_WITH_STREAM(Animations, stream << " blending " << property() << " from " << value(from) << " to " << value(to) << " at " << TextStream::FormatNumberRespectingIntegers(progress) << " -> " << value(destination));
}
#endif
void (FillLayer::*m_lengthSetter)(Length);
Edge (FillLayer::*m_originGetter)() const;
void (FillLayer::*m_originSetter)(Edge);
Edge m_farEdge;
};
template <typename T>
class FillLayerRefCountedPropertyWrapper : public FillLayerPropertyWrapperGetter<T*> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
FillLayerRefCountedPropertyWrapper(CSSPropertyID property, T* (FillLayer::*getter)() const, void (FillLayer::*setter)(RefPtr<T>&&))
: FillLayerPropertyWrapperGetter<T*>(property, getter)
, m_setter(setter)
{
}
private:
void blend(FillLayer* destination, const FillLayer* from, const FillLayer* to, const CSSPropertyBlendingContext& context) const final
{
(destination->*this->m_setter)(blendFunc(this->value(from), this->value(to), context));
}
#if !LOG_DISABLED
void logBlend(const FillLayer* destination, const FillLayer* from, const FillLayer* to, double progress) const override
{
LOG_WITH_STREAM(Animations, stream << " blending " << FillLayerPropertyWrapperGetter<T*>::property()
<< " from " << FillLayerPropertyWrapperGetter<T*>::value(from)
<< " to " << FillLayerPropertyWrapperGetter<T*>::value(to)
<< " at " << TextStream::FormatNumberRespectingIntegers(progress) << " -> " << FillLayerPropertyWrapperGetter<T*>::value(destination));
}
#endif
void (FillLayer::*m_setter)(RefPtr<T>&&);
};
class FillLayerStyleImagePropertyWrapper final : public FillLayerRefCountedPropertyWrapper<StyleImage> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
FillLayerStyleImagePropertyWrapper(CSSPropertyID property, StyleImage* (FillLayer::*getter)() const, void (FillLayer::*setter)(RefPtr<StyleImage>&&))
: FillLayerRefCountedPropertyWrapper(property, getter, setter)
{
}
private:
bool equals(const FillLayer* a, const FillLayer* b) const final
{
if (a == b)
return true;
if (!a || !b)
return false;
return arePointingToEqualData(value(a), value(b));
}
bool canInterpolate(const FillLayer* from, const FillLayer* to) const final
{
if (property() == CSSPropertyMaskImage)
return false;
return value(from) && value(to);
}
#if !LOG_DISABLED
void logBlend(const FillLayer* destination, const FillLayer* from, const FillLayer* to, double progress) const final
{
LOG_WITH_STREAM(Animations, stream << " blending " << property() << " from " << this->value(from) << " to " << this->value(to) << " at " << TextStream::FormatNumberRespectingIntegers(progress) << " -> " << value(destination));
}
#endif
};
template <typename T>
class DiscreteFillLayerPropertyWrapper final : public FillLayerAnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
DiscreteFillLayerPropertyWrapper(CSSPropertyID property, T (FillLayer::*getter)() const, void (FillLayer::*setter)(T))
: FillLayerAnimationPropertyWrapperBase(property)
, m_getter(getter)
, m_setter(setter)
{
}
private:
bool equals(const FillLayer* a, const FillLayer* b) const final
{
return (a->*m_getter)() == (b->*m_getter)();
}
bool canInterpolate(const FillLayer*, const FillLayer*) const final { return false; }
#if !LOG_DISABLED
void logBlend(const FillLayer* destination, const FillLayer* from, const FillLayer* to, double progress) const final
{
LOG_WITH_STREAM(Animations, stream << " blending " << property() << " from " << (from->*m_getter)() << " to " << (to->*m_getter)() << " at " << TextStream::FormatNumberRespectingIntegers(progress) << " -> " << (destination->*m_getter)());
}
#endif
void blend(FillLayer* destination, const FillLayer* from, const FillLayer* to, const CSSPropertyBlendingContext& context) const final
{
ASSERT(!context.progress || context.progress == 1.0);
(destination->*m_setter)(((context.progress ? to : from)->*m_getter)());
}
T (FillLayer::*m_getter)() const;
void (FillLayer::*m_setter)(T);
};
class FillLayersPropertyWrapper final : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
typedef const FillLayer& (RenderStyle::*LayersGetter)() const;
typedef FillLayer& (RenderStyle::*LayersAccessor)();
FillLayersPropertyWrapper(CSSPropertyID property, LayersGetter getter, LayersAccessor accessor)
: AnimationPropertyWrapperBase(property)
, m_layersGetter(getter)
, m_layersAccessor(accessor)
{
switch (property) {
case CSSPropertyBackgroundPositionX:
case CSSPropertyWebkitMaskPositionX:
m_fillLayerPropertyWrapper = makeUnique<FillLayerPositionPropertyWrapper>(property, &FillLayer::xPosition, &FillLayer::setXPosition, &FillLayer::backgroundXOrigin, &FillLayer::setBackgroundXOrigin, Edge::Right);
break;
case CSSPropertyBackgroundPositionY:
case CSSPropertyWebkitMaskPositionY:
m_fillLayerPropertyWrapper = makeUnique<FillLayerPositionPropertyWrapper>(property, &FillLayer::yPosition, &FillLayer::setYPosition, &FillLayer::backgroundYOrigin, &FillLayer::setBackgroundYOrigin, Edge::Bottom);
break;
case CSSPropertyBackgroundSize:
case CSSPropertyWebkitBackgroundSize:
case CSSPropertyMaskSize:
m_fillLayerPropertyWrapper = makeUnique<FillLayerPropertyWrapper<LengthSize>>(property, &FillLayer::sizeLength, &FillLayer::setSizeLength);
break;
case CSSPropertyBackgroundImage:
case CSSPropertyMaskImage:
m_fillLayerPropertyWrapper = makeUnique<FillLayerStyleImagePropertyWrapper>(property, &FillLayer::image, &FillLayer::setImage);
break;
case CSSPropertyMaskClip:
m_fillLayerPropertyWrapper = makeUnique<DiscreteFillLayerPropertyWrapper<FillBox>>(property, &FillLayer::clip, &FillLayer::setClip);
break;
case CSSPropertyMaskOrigin:
m_fillLayerPropertyWrapper = makeUnique<DiscreteFillLayerPropertyWrapper<FillBox>>(property, &FillLayer::origin, &FillLayer::setOrigin);
break;
case CSSPropertyMaskComposite:
m_fillLayerPropertyWrapper = makeUnique<DiscreteFillLayerPropertyWrapper<CompositeOperator>>(property, &FillLayer::composite, &FillLayer::setComposite);
break;
case CSSPropertyMaskMode:
m_fillLayerPropertyWrapper = makeUnique<DiscreteFillLayerPropertyWrapper<MaskMode>>(property, &FillLayer::maskMode, &FillLayer::setMaskMode);
break;
default:
break;
}
}
private:
bool equals(const RenderStyle& a, const RenderStyle& b) const final
{
if (&a == &b)
return true;
auto* fromLayer = &(a.*m_layersGetter)();
auto* toLayer = &(b.*m_layersGetter)();
while (fromLayer && toLayer) {
if (!m_fillLayerPropertyWrapper->equals(fromLayer, toLayer))
return false;
fromLayer = fromLayer->next();
toLayer = toLayer->next();
}
return true;
}
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
auto* fromLayer = &(from.*m_layersGetter)();
auto* toLayer = &(to.*m_layersGetter)();
while (fromLayer && toLayer) {
if (fromLayer->sizeType() != toLayer->sizeType())
return false;
if (!m_fillLayerPropertyWrapper->canInterpolate(fromLayer, toLayer))
return false;
fromLayer = fromLayer->next();
toLayer = toLayer->next();
}
return true;
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
auto* fromLayer = &(from.*m_layersGetter)();
auto* toLayer = &(to.*m_layersGetter)();
auto* dstLayer = &(destination.*m_layersAccessor)();
if (context.isDiscrete) {
ASSERT(!context.progress || context.progress == 1.0);
auto* layer = context.progress ? toLayer : fromLayer;
fromLayer = layer;
toLayer = layer;
}
size_t layerCount = 0;
Vector<FillLayer*> previousDstLayers;
FillLayer* previousDstLayer = nullptr;
while (fromLayer && toLayer) {
if (dstLayer)
previousDstLayers.append(dstLayer);
else {
ASSERT(!previousDstLayers.isEmpty());
auto* layerToCopy = previousDstLayers[layerCount % previousDstLayers.size()];
previousDstLayer->setNext(layerToCopy->copy());
dstLayer = previousDstLayer->next();
}
dstLayer->setSizeType((context.progress ? toLayer : fromLayer)->sizeType());
m_fillLayerPropertyWrapper->blend(dstLayer, fromLayer, toLayer, context);
fromLayer = fromLayer->next();
toLayer = toLayer->next();
previousDstLayer = dstLayer;
dstLayer = dstLayer->next();
layerCount++;
}
}
#if !LOG_DISABLED
void logBlend(const RenderStyle& from, const RenderStyle& to, const RenderStyle& destination, double progress) const final
{
auto* fromLayer = &(from.*m_layersGetter)();
auto* toLayer = &(to.*m_layersGetter)();
auto* dstLayer = &(destination.*m_layersGetter)();
while (fromLayer && toLayer && dstLayer) {
m_fillLayerPropertyWrapper->logBlend(dstLayer, fromLayer, toLayer, progress);
fromLayer = fromLayer->next();
toLayer = toLayer->next();
dstLayer = dstLayer->next();
}
}
#endif
std::unique_ptr<FillLayerAnimationPropertyWrapperBase> m_fillLayerPropertyWrapper;
LayersGetter m_layersGetter;
LayersAccessor m_layersAccessor;
};
class ShorthandPropertyWrapper final : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
ShorthandPropertyWrapper(CSSPropertyID property, Vector<AnimationPropertyWrapperBase*> longhandWrappers)
: AnimationPropertyWrapperBase(property)
, m_propertyWrappers(WTFMove(longhandWrappers))
{
}
bool isShorthandWrapper() const final { return true; }
const Vector<AnimationPropertyWrapperBase*>& propertyWrappers() const { return m_propertyWrappers; }
private:
bool equals(const RenderStyle& a, const RenderStyle& b) const final
{
if (&a == &b)
return true;
for (auto& wrapper : m_propertyWrappers) {
if (!wrapper->equals(a, b))
return false;
}
return true;
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
for (auto& wrapper : m_propertyWrappers)
wrapper->blend(destination, from, to, context);
}
#if !LOG_DISABLED
void logBlend(const RenderStyle& from, const RenderStyle& to, const RenderStyle& destination, double progress) const final
{
for (auto& wrapper : m_propertyWrappers)
wrapper->logBlend(from, to, destination, progress);
}
#endif
Vector<AnimationPropertyWrapperBase*> m_propertyWrappers;
};
class PropertyWrapperFlex final : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperFlex()
: AnimationPropertyWrapperBase(CSSPropertyFlex)
{
}
private:
bool equals(const RenderStyle& a, const RenderStyle& b) const final
{
if (&a == &b)
return true;
return a.flexBasis() == b.flexBasis() && a.flexGrow() == b.flexGrow() && a.flexShrink() == b.flexShrink();
}
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
return from.flexGrow() != to.flexGrow() && from.flexShrink() != to.flexShrink() && canInterpolateLengths(from.flexBasis(), to.flexBasis(), false);
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
destination.setFlexBasis(blendFunc(from.flexBasis(), to.flexBasis(), context));
destination.setFlexGrow(blendFunc(from.flexGrow(), to.flexGrow(), context));
destination.setFlexShrink(blendFunc(from.flexShrink(), to.flexShrink(), context));
}
#if !LOG_DISABLED
void logBlend(const RenderStyle&, const RenderStyle&, const RenderStyle&, double progress) const final
{
// FIXME: better logging.
LOG_WITH_STREAM(Animations, stream << " blending flex at " << TextStream::FormatNumberRespectingIntegers(progress));
}
#endif
};
class PropertyWrapperSVGPaint final : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperSVGPaint(CSSPropertyID property, SVGPaintType (RenderStyle::*paintTypeGetter)() const, const Style::Color& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Style::Color&))
: AnimationPropertyWrapperBase(property)
, m_paintTypeGetter(paintTypeGetter)
, m_getter(getter)
, m_setter(setter)
{
}
bool equals(const RenderStyle& a, const RenderStyle& b) const final
{
if (&a == &b)
return true;
if ((a.*m_paintTypeGetter)() != (b.*m_paintTypeGetter)())
return false;
// We only support animations between SVGPaints that are pure Color values.
// For everything else we must return true for this method, otherwise
// we will try to animate between values forever.
if ((a.*m_paintTypeGetter)() == SVGPaintType::RGBColor) {
auto fromStyleColor = (a.*m_getter)();
auto toStyleColor = (b.*m_getter)();
// We don't animate when both are currentcolor
auto fromColor = a.colorResolvingCurrentColor(fromStyleColor);
auto toColor = b.colorResolvingCurrentColor(toStyleColor);
return (fromStyleColor.isCurrentColor() && toStyleColor.isCurrentColor()) || fromColor == toColor;
}
return true;
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
auto isValidPaintType = [](SVGPaintType paintType) {
return paintType == SVGPaintType::RGBColor || paintType == SVGPaintType::CurrentColor;
};
if (!isValidPaintType((from.*m_paintTypeGetter)()) || !isValidPaintType((to.*m_paintTypeGetter)()))
return;
auto fromStyleColor = (from.*m_getter)();
auto toStyleColor = (to.*m_getter)();
// We don't animate when both are currentcolor
if (fromStyleColor.isCurrentColor() && toStyleColor.isCurrentColor())
return;
auto fromColor = from.colorResolvingCurrentColor(fromStyleColor);
auto toColor = to.colorResolvingCurrentColor(toStyleColor);
(destination.*m_setter)(blendFunc(fromColor, toColor, context));
}
#if !LOG_DISABLED
void logBlend(const RenderStyle&, const RenderStyle&, const RenderStyle&, double progress) const final
{
// FIXME: better logging.
LOG_WITH_STREAM(Animations, stream << " blending SVGPaint at " << TextStream::FormatNumberRespectingIntegers(progress));
}
#endif
private:
SVGPaintType (RenderStyle::*m_paintTypeGetter)() const;
const Style::Color& (RenderStyle::*m_getter)() const;
void (RenderStyle::*m_setter)(const Style::Color&);
};
class PropertyWrapperVisitedAffectedSVGPaint : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperVisitedAffectedSVGPaint(CSSPropertyID property, SVGPaintType (RenderStyle::*paintTypeGetter)() const, const Style::Color& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Style::Color&), SVGPaintType (RenderStyle::*visitedPaintTypeGetter)() const, const Style::Color& (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visitedSetter)(const Style::Color&))
: AnimationPropertyWrapperBase(property)
, m_wrapper(makeUnique<PropertyWrapperSVGPaint>(property, paintTypeGetter, getter, setter))
, m_visitedWrapper(makeUnique<PropertyWrapperSVGPaint>(property, visitedPaintTypeGetter, visitedGetter, visitedSetter))
{
}
protected:
bool equals(const RenderStyle& a, const RenderStyle& b) const override
{
return m_wrapper->equals(a, b) && m_visitedWrapper->equals(a, b);
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const override
{
m_wrapper->blend(destination, from, to, context);
m_visitedWrapper->blend(destination, from, to, context);
}
std::unique_ptr<PropertyWrapperSVGPaint> m_wrapper;
std::unique_ptr<PropertyWrapperSVGPaint> m_visitedWrapper;
private:
#if !LOG_DISABLED
void logBlend(const RenderStyle& from, const RenderStyle& to, const RenderStyle& destination, double progress) const final
{
m_wrapper->logBlend(from, to, destination, progress);
m_visitedWrapper->logBlend(from, to, destination, progress);
}
#endif
};
class PropertyWrapperFontWeight final : public PropertyWrapper<FontSelectionValue> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperFontWeight()
: PropertyWrapper(CSSPropertyFontWeight, &RenderStyle::fontWeight, &RenderStyle::setFontWeight)
{
}
private:
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
(destination.*m_setter)(FontSelectionValue(std::clamp(blendFunc(static_cast<float>(this->value(from)), static_cast<float>(this->value(to)), context), 1.0f, 1000.0f)));
}
};
class PropertyWrapperFontStyle final : public PropertyWrapper<std::optional<FontSelectionValue>> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperFontStyle()
: PropertyWrapper(CSSPropertyFontStyle, &RenderStyle::fontItalic, &RenderStyle::setFontItalic)
{
}
private:
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
return from.fontDescription().fontStyleAxis() == FontStyleAxis::slnt && to.fontDescription().fontStyleAxis() == FontStyleAxis::slnt;
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
auto blendedStyleAxis = FontStyleAxis::slnt;
if (context.isDiscrete)
blendedStyleAxis = (context.progress < 0.5 ? from : to).fontDescription().fontStyleAxis();
auto fromFontItalic = from.fontItalic();
auto toFontItalic = to.fontItalic();
auto blendedFontItalic = context.progress < 0.5 ? fromFontItalic : toFontItalic;
if (!context.isDiscrete)
blendedFontItalic = blendFunc(fromFontItalic, toFontItalic, context);
auto description = destination.fontDescription();
description.setItalic(blendedFontItalic);
description.setFontStyleAxis(blendedStyleAxis);
destination.setFontDescription(WTFMove(description));
}
};
class PropertyWrapperFontSizeAdjust final : public PropertyWrapperGetter<FontSizeAdjust> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperFontSizeAdjust()
: PropertyWrapperGetter(CSSPropertyFontSizeAdjust, &RenderStyle::fontSizeAdjust)
{
}
private:
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
auto fromFontSizeAdjust = from.fontSizeAdjust();
auto toFontSizeAdjust = to.fontSizeAdjust();
return fromFontSizeAdjust.metric == toFontSizeAdjust.metric
&& fromFontSizeAdjust.value && toFontSizeAdjust.value;
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
auto blendedFontSizeAdjust = [&]() -> FontSizeAdjust {
if (context.isDiscrete)
return (!context.progress ? from : to).fontSizeAdjust();
ASSERT(from.fontSizeAdjust().value && to.fontSizeAdjust().value);
auto blendedAdjust = blendFunc(*from.fontSizeAdjust().value, *to.fontSizeAdjust().value, context);
ASSERT(from.fontSizeAdjust().metric == to.fontSizeAdjust().metric);
return { to.fontSizeAdjust().metric, FontSizeAdjust::ValueType::Number, std::max(blendedAdjust, 0.0f) };
};
destination.setFontSizeAdjust(blendedFontSizeAdjust());
}
};
class PropertyWrapperBaselineShift final : public PropertyWrapper<SVGLengthValue> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperBaselineShift()
: PropertyWrapper(CSSPropertyBaselineShift, &RenderStyle::baselineShiftValue, &RenderStyle::setBaselineShiftValue)
{
}
private:
bool equals(const RenderStyle& a, const RenderStyle& b) const final
{
return a.svgStyle().baselineShift() == b.svgStyle().baselineShift() && PropertyWrapper::equals(a, b);
}
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation compositeOperation) const final
{
return from.svgStyle().baselineShift() == to.svgStyle().baselineShift() && PropertyWrapper::canInterpolate(from, to, compositeOperation);
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
auto& srcSVGStyle = !context.progress ? from.svgStyle() : to.svgStyle();
destination.accessSVGStyle().setBaselineShift(srcSVGStyle.baselineShift());
PropertyWrapper::blend(destination, from, to, context);
}
};
class PropertyWrapperTextUnderlineOffset final : public PropertyWrapperGetter<TextUnderlineOffset> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperTextUnderlineOffset()
: PropertyWrapperGetter(CSSPropertyTextUnderlineOffset, &RenderStyle::textUnderlineOffset)
{
}
private:
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
auto fromTextUnderlineOffset = from.textUnderlineOffset();
auto toTextUnderlineOffset = to.textUnderlineOffset();
if (fromTextUnderlineOffset.isAuto() || toTextUnderlineOffset.isAuto())
return false;
auto fromValue = fromTextUnderlineOffset.resolve(from.computedFontSize());
auto toValue = toTextUnderlineOffset.resolve(to.computedFontSize());
return fromValue != toValue;
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
auto blendedTextUnderlineOffset = [&]() -> TextUnderlineOffset {
if (context.isDiscrete)
return (!context.progress ? from : to).textUnderlineOffset();
auto fromTextUnderlineOffset = from.textUnderlineOffset();
auto toTextUnderlineOffset = to.textUnderlineOffset();
auto fromValue = fromTextUnderlineOffset.resolve(from.computedFontSize());
auto toValue = toTextUnderlineOffset.resolve(to.computedFontSize());
auto blendedValue = blendFunc(fromValue, toValue, context);
return TextUnderlineOffset::createWithLength(Length(clampTo<float>(blendedValue, minValueForCssLength, maxValueForCssLength), LengthType::Fixed));
};
destination.setTextUnderlineOffset(blendedTextUnderlineOffset());
}
};
class PropertyWrapperTextDecorationThickness final : public PropertyWrapperGetter<TextDecorationThickness> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperTextDecorationThickness()
: PropertyWrapperGetter(CSSPropertyTextDecorationThickness, &RenderStyle::textDecorationThickness)
{
}
private:
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
auto fromTextDecorationThickness = from.textDecorationThickness();
auto toTextDecorationThickness = to.textDecorationThickness();
if (fromTextDecorationThickness.isAuto() || toTextDecorationThickness.isAuto())
return false;
auto fromValue = fromTextDecorationThickness.resolve(from.computedFontSize(), from.metricsOfPrimaryFont());
auto toValue = toTextDecorationThickness.resolve(to.computedFontSize(), to.metricsOfPrimaryFont());
return fromValue != toValue;
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
auto blendedTextDecorationThickness = [&]() -> TextDecorationThickness {
if (context.isDiscrete)
return (!context.progress ? from : to).textDecorationThickness();
auto fromTextDecorationThickness = from.textDecorationThickness();
auto toTextDecorationThickness = to.textDecorationThickness();
auto fromValue = fromTextDecorationThickness.resolve(from.computedFontSize(), from.metricsOfPrimaryFont());
auto toValue = toTextDecorationThickness.resolve(to.computedFontSize(), to.metricsOfPrimaryFont());
auto blendedValue = blendFunc(fromValue, toValue, context);
return TextDecorationThickness::createWithLength(Length(clampTo<float>(blendedValue, minValueForCssLength, maxValueForCssLength), LengthType::Fixed));
};
destination.setTextDecorationThickness(blendedTextDecorationThickness());
}
};
template <typename T>
class AutoPropertyWrapper final : public PropertyWrapper<T> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
AutoPropertyWrapper(CSSPropertyID property, T (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T), bool (RenderStyle::*autoGetter)() const, void (RenderStyle::*autoSetter)(), std::optional<T> minValue = std::nullopt)
: PropertyWrapper<T>(property, getter, setter)
, m_autoGetter(autoGetter)
, m_autoSetter(autoSetter)
, m_minValue(minValue)
{
}
private:
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
return !(from.*m_autoGetter)() && !(to.*m_autoGetter)();
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
auto blendedValue = blendFunc(this->value(from), this->value(to), context);
if (m_minValue)
blendedValue = blendedValue > *m_minValue ? blendedValue : *m_minValue;
(destination.*this->m_setter)(blendedValue);
if (!context.isDiscrete)
return;
ASSERT(!context.progress || context.progress == 1.0);
if (!context.progress) {
if ((from.*m_autoGetter)())
(destination.*m_autoSetter)();
} else {
if ((to.*m_autoGetter)())
(destination.*m_autoSetter)();
}
}
bool (RenderStyle::*m_autoGetter)() const;
void (RenderStyle::*m_autoSetter)();
std::optional<T> m_minValue;
};
class FloatPropertyWrapper : public PropertyWrapper<float> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
enum class ValueRange : uint8_t {
All,
NonNegative,
Positive
};
FloatPropertyWrapper(CSSPropertyID property, float (RenderStyle::*getter)() const, void (RenderStyle::*setter)(float), ValueRange valueRange = ValueRange::All)
: PropertyWrapper(property, getter, setter)
, m_valueRange(valueRange)
{
}
protected:
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const override
{
auto blendedValue = blendFunc(value(from), value(to), context);
if (m_valueRange == ValueRange::NonNegative && blendedValue <= 0)
blendedValue = 0;
else if (m_valueRange == ValueRange::Positive && blendedValue < 0)
blendedValue = std::numeric_limits<float>::epsilon();
(destination.*m_setter)(blendedValue);
}
private:
ValueRange m_valueRange;
};
class LineHeightWrapper final : public LengthPropertyWrapper {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
LineHeightWrapper()
: LengthPropertyWrapper(CSSPropertyLineHeight, &RenderStyle::specifiedLineHeight, &RenderStyle::setLineHeight)
{
}
private:
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation compositeOperation) const final
{
// We must account for how BuilderConverter::convertLineHeight() deals with line-height values:
// - "normal" is converted to LengthType::Percent with a -100 value
// - <number> values are converted to LengthType::Percent
// - <length-percentage> values are converted to LengthType::Fixed
// This means that animating between "normal" and a "<number>" would work with LengthPropertyWrapper::canInterpolate()
// since it would see two LengthType::Percent values. So if either value is "normal" we cannot interpolate since those
// values are either equal or of incompatible types.
auto normalLineHeight = RenderStyle::initialLineHeight();
if (value(from) == normalLineHeight || value(to) == normalLineHeight)
return false;
// The default logic will now apply since <number> and <length-percentage> values
// are converted to different LengthType values.
return LengthPropertyWrapper::canInterpolate(from, to, compositeOperation);
}
};
class VerticalAlignWrapper final : public LengthPropertyWrapper {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
VerticalAlignWrapper()
: LengthPropertyWrapper(CSSPropertyVerticalAlign, &RenderStyle::verticalAlignLength, &RenderStyle::setVerticalAlignLength, LengthPropertyWrapper::Flags::IsLengthPercentage)
{
}
private:
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation compositeOperation) const final
{
return from.verticalAlign() == VerticalAlign::Length && to.verticalAlign() == VerticalAlign::Length && LengthPropertyWrapper::canInterpolate(from, to, compositeOperation);
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
LengthPropertyWrapper::blend(destination, from, to, context);
auto& blendingStyle = context.isDiscrete && context.progress ? to : from;
destination.setVerticalAlign(blendingStyle.verticalAlign());
}
};
class TextIndentWrapper final : public LengthPropertyWrapper {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
TextIndentWrapper()
: LengthPropertyWrapper(CSSPropertyTextIndent, &RenderStyle::textIndent, &RenderStyle::setTextIndent, LengthPropertyWrapper::Flags::IsLengthPercentage)
{
}
private:
bool equals(const RenderStyle& a, const RenderStyle& b) const final
{
if (a.textIndentLine() != b.textIndentLine())
return false;
if (a.textIndentType() != b.textIndentType())
return false;
return LengthPropertyWrapper::equals(a, b);
}
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation compositeOperation) const final
{
if (from.textIndentLine() != to.textIndentLine())
return false;
if (from.textIndentType() != to.textIndentType())
return false;
return LengthPropertyWrapper::canInterpolate(from, to, compositeOperation);
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
auto& blendingStyle = context.isDiscrete && context.progress ? to : from;
destination.setTextIndentLine(blendingStyle.textIndentLine());
destination.setTextIndentType(blendingStyle.textIndentType());
LengthPropertyWrapper::blend(destination, from, to, context);
}
};
class OffsetDistanceWrapper final : public LengthPropertyWrapper {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
OffsetDistanceWrapper()
: LengthPropertyWrapper(CSSPropertyOffsetDistance, &RenderStyle::offsetDistance, &RenderStyle::setOffsetDistance, LengthPropertyWrapper::Flags::IsLengthPercentage)
{
}
private:
bool animationIsAccelerated(const Settings& settings) const final
{
#if ENABLE(THREADED_ANIMATION_RESOLUTION)
return settings.threadedAnimationResolutionEnabled();
#else
UNUSED_PARAM(settings);
return false;
#endif
}
};
class PerspectiveWrapper final : public FloatPropertyWrapper {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PerspectiveWrapper()
: FloatPropertyWrapper(CSSPropertyPerspective, &RenderStyle::perspective, &RenderStyle::setPerspective, FloatPropertyWrapper::ValueRange::NonNegative)
{
}
private:
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation compositeOperation) const final
{
if (!from.hasPerspective() || !to.hasPerspective())
return false;
return FloatPropertyWrapper::canInterpolate(from, to, compositeOperation);
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
if (context.isDiscrete)
(destination.*m_setter)(context.progress ? value(to) : value(from));
else
FloatPropertyWrapper::blend(destination, from, to, context);
}
};
class TabSizePropertyWrapper final : public PropertyWrapper<const TabSize&> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
TabSizePropertyWrapper()
: PropertyWrapper(CSSPropertyTabSize, &RenderStyle::tabSize, &RenderStyle::setTabSize)
{
}
private:
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
return value(from).isSpaces() == value(to).isSpaces();
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
if (context.isDiscrete)
(destination.*m_setter)(context.progress ? value(to) : value(from));
else
PropertyWrapper::blend(destination, from, to, context);
}
};
class PropertyWrapperDynamicRangeLimit final : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperDynamicRangeLimit()
: AnimationPropertyWrapperBase(CSSPropertyDynamicRangeLimit)
{
}
bool equals(const RenderStyle& a, const RenderStyle& b) const final
{
if (&a == &b)
return true;
return a.dynamicRangeLimit() == b.dynamicRangeLimit();
}
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
return Style::canBlend(value(from), value(to));
}
#if !LOG_DISABLED
void logBlend(const RenderStyle& from, const RenderStyle& to, const RenderStyle& destination, double progress) const final
{
LOG_WITH_STREAM(Animations, stream << " blending " << property() << " from " << value(from) << " to " << value(to) << " at " << TextStream::FormatNumberRespectingIntegers(progress) << " -> " << value(destination));
}
#endif
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
return destination.setDynamicRangeLimit(Style::blend(value(from), value(to), context));
}
static const Style::DynamicRangeLimit& value(const RenderStyle& style)
{
return style.dynamicRangeLimit();
}
};
class PropertyWrapperAspectRatio final : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperAspectRatio()
: AnimationPropertyWrapperBase(CSSPropertyAspectRatio)
{
}
bool equals(const RenderStyle& a, const RenderStyle& b) const final
{
if (&a == &b)
return true;
return a.aspectRatioType() == b.aspectRatioType() && a.aspectRatioWidth() == b.aspectRatioWidth() && a.aspectRatioHeight() == b.aspectRatioHeight();
}
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
return (from.aspectRatioType() == AspectRatioType::Ratio && to.aspectRatioType() == AspectRatioType::Ratio) || (from.aspectRatioType() == AspectRatioType::AutoAndRatio && to.aspectRatioType() == AspectRatioType::AutoAndRatio);
}
#if !LOG_DISABLED
void logBlend(const RenderStyle& from, const RenderStyle& to, const RenderStyle& destination, double progress) const final
{
LOG_WITH_STREAM(Animations, stream << " blending " << property() << " from " << from.logicalAspectRatio() << " to " << to.logicalAspectRatio() << " at " << TextStream::FormatNumberRespectingIntegers(progress) << " -> " << destination.logicalAspectRatio());
}
#endif
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
destination.setAspectRatioType(context.progress < 0.5 ? from.aspectRatioType() : to.aspectRatioType());
if (!context.isDiscrete) {
auto aspectRatioDst = WebCore::blend(log(from.logicalAspectRatio()), log(to.logicalAspectRatio()), context);
destination.setAspectRatio(exp(aspectRatioDst), 1);
return;
}
// For auto/auto-zero aspect-ratio we use discrete values, we can't use general
// logic since logicalAspectRatio asserts on aspect-ratio type.
ASSERT(!context.progress || context.progress == 1);
auto& applicableStyle = context.progress ? to : from;
destination.setAspectRatio(applicableStyle.aspectRatioWidth(), applicableStyle.aspectRatioHeight());
}
};
class StrokeDasharrayPropertyWrapper final : public PropertyWrapper<Vector<SVGLengthValue>> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
StrokeDasharrayPropertyWrapper()
: PropertyWrapper(CSSPropertyStrokeDasharray, &RenderStyle::strokeDashArray, &RenderStyle::setStrokeDashArray)
{
}
private:
bool isAdditiveOrCumulative() const final
{
return false;
}
};
class PropertyWrapperContent final : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
PropertyWrapperContent()
: AnimationPropertyWrapperBase(CSSPropertyContent)
{
}
bool canInterpolate(const RenderStyle&, const RenderStyle&, CompositeOperation) const final { return false; }
bool equals(const RenderStyle& a, const RenderStyle& b) const final
{
if (!a.hasContent() && !b.hasContent())
return true;
if (a.hasContent() && b.hasContent())
return *a.contentData() == *b.contentData();
return false;
}
#if !LOG_DISABLED
void logBlend(const RenderStyle&, const RenderStyle&, const RenderStyle&, double progress) const final
{
LOG_WITH_STREAM(Animations, stream << " blending content at " << TextStream::FormatNumberRespectingIntegers(progress) << ".");
}
#endif
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
ASSERT(context.isDiscrete);
ASSERT(!context.progress || context.progress == 1);
auto& style = context.progress ? to : from;
if (auto* content = style.contentData())
destination.setContent(content->clone(), false);
else
destination.clearContent();
}
};
class TextEmphasisStyleWrapper final : public DiscretePropertyWrapper<TextEmphasisMark> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
TextEmphasisStyleWrapper()
: DiscretePropertyWrapper(CSSPropertyTextEmphasisStyle, &RenderStyle::textEmphasisMark, &RenderStyle::setTextEmphasisMark)
{
}
private:
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
destination.setTextEmphasisFill((context.progress > 0.5 ? to : from).textEmphasisFill());
DiscretePropertyWrapper::blend(destination, from, to, context);
}
};
class DiscreteFontDescriptionWrapper : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
DiscreteFontDescriptionWrapper(CSSPropertyID property)
: AnimationPropertyWrapperBase(property)
{
}
protected:
virtual bool propertiesInFontDescriptionAreEqual(const FontCascadeDescription&, const FontCascadeDescription&) const { return false; }
virtual void setPropertiesInFontDescription(const FontCascadeDescription&, FontCascadeDescription&) const { }
private:
bool canInterpolate(const RenderStyle&, const RenderStyle&, CompositeOperation) const override { return false; }
bool equals(const RenderStyle& a, const RenderStyle& b) const override
{
return propertiesInFontDescriptionAreEqual(a.fontDescription(), b.fontDescription());
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const override
{
ASSERT(!context.progress || context.progress == 1.0);
auto destinationDescription = destination.fontDescription();
auto& sourceDescription = (context.progress ? to : from).fontDescription();
setPropertiesInFontDescription(sourceDescription, destinationDescription);
destination.setFontDescription(WTFMove(destinationDescription));
}
#if !LOG_DISABLED
void logBlend(const RenderStyle&, const RenderStyle&, const RenderStyle&, double) const override
{
}
#endif
};
template <typename T>
class DiscreteFontDescriptionTypedWrapper : public DiscreteFontDescriptionWrapper {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
DiscreteFontDescriptionTypedWrapper(CSSPropertyID property, T (FontCascadeDescription::*getter)() const, void (FontCascadeDescription::*setter)(T))
: DiscreteFontDescriptionWrapper(property)
, m_getter(getter)
, m_setter(setter)
{
}
private:
bool propertiesInFontDescriptionAreEqual(const FontCascadeDescription& a, const FontCascadeDescription& b) const override
{
return this->value(a) == this->value(b);
}
void setPropertiesInFontDescription(const FontCascadeDescription& source, FontCascadeDescription& destination) const override
{
(destination.*this->m_setter)(this->value(source));
}
T value(const FontCascadeDescription& description) const
{
return (description.*this->m_getter)();
}
T (FontCascadeDescription::*m_getter)() const;
void (FontCascadeDescription::*m_setter)(T);
};
class FontFamilyWrapper final : public DiscreteFontDescriptionWrapper {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
FontFamilyWrapper()
: DiscreteFontDescriptionWrapper(CSSPropertyFontFamily)
{
}
private:
bool propertiesInFontDescriptionAreEqual(const FontCascadeDescription& a, const FontCascadeDescription& b) const override
{
return a.families() == b.families();
}
void setPropertiesInFontDescription(const FontCascadeDescription& source, FontCascadeDescription& destination) const override
{
destination.setFamilies(source.families());
}
};
class CounterWrapper final : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
CounterWrapper(CSSPropertyID property)
: AnimationPropertyWrapperBase(property)
{
ASSERT(property == CSSPropertyCounterIncrement || property == CSSPropertyCounterReset || property == CSSPropertyCounterSet);
}
bool canInterpolate(const RenderStyle&, const RenderStyle&, CompositeOperation) const override { return false; }
bool equals(const RenderStyle& a, const RenderStyle& b) const final
{
auto& mapA = a.counterDirectives().map;
auto& mapB = b.counterDirectives().map;
if (mapA.size() != mapB.size())
return false;
for (auto& [key, aDirective] : mapA) {
auto it = mapB.find(key);
if (it == mapB.end())
return false;
auto& bDirective = it->value;
if ((property() == CSSPropertyCounterIncrement && aDirective.incrementValue != bDirective.incrementValue)
|| (property() == CSSPropertyCounterReset && aDirective.resetValue != bDirective.resetValue)
|| (property() == CSSPropertyCounterSet && aDirective.setValue != bDirective.setValue))
return false;
}
return true;
}
#if !LOG_DISABLED
void logBlend(const RenderStyle&, const RenderStyle&, const RenderStyle&, double progress) const final
{
LOG_WITH_STREAM(Animations, stream << " blending " << property() << " at " << TextStream::FormatNumberRespectingIntegers(progress) << ".");
}
#endif
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
ASSERT(context.isDiscrete);
ASSERT(!context.progress || context.progress == 1);
// Clear all existing values in the existing set of directives.
for (auto& [key, directive] : destination.accessCounterDirectives().map) {
if (property() == CSSPropertyCounterIncrement)
directive.incrementValue = std::nullopt;
else if (property() == CSSPropertyCounterReset)
directive.resetValue = std::nullopt;
else
directive.setValue = std::nullopt;
}
auto& style = context.progress ? to : from;
auto& targetDirectives = destination.accessCounterDirectives().map;
for (auto& [key, directive] : style.counterDirectives().map) {
auto updateDirective = [&](CounterDirectives& target, const CounterDirectives& source) {
if (property() == CSSPropertyCounterIncrement)
target.incrementValue = source.incrementValue;
else if (property() == CSSPropertyCounterReset)
target.resetValue = source.resetValue;
else
target.setValue = source.setValue;
};
auto it = targetDirectives.find(key);
if (it == targetDirectives.end())
updateDirective(targetDirectives.add(key, CounterDirectives { }).iterator->value, directive);
else
updateDirective(it->value, directive);
}
}
};
class FontFeatureSettingsWrapper final : public DiscreteFontDescriptionWrapper {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
FontFeatureSettingsWrapper()
: DiscreteFontDescriptionWrapper(CSSPropertyFontFeatureSettings)
{
}
private:
bool propertiesInFontDescriptionAreEqual(const FontCascadeDescription& a, const FontCascadeDescription& b) const override
{
return a.featureSettings() == b.featureSettings();
}
void setPropertiesInFontDescription(const FontCascadeDescription& source, FontCascadeDescription& destination) const override
{
destination.setFeatureSettings(FontFeatureSettings(source.featureSettings()));
}
};
class FontVariantEastAsianWrapper final : public DiscreteFontDescriptionWrapper {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
FontVariantEastAsianWrapper()
: DiscreteFontDescriptionWrapper(CSSPropertyFontVariantEastAsian)
{
}
private:
bool propertiesInFontDescriptionAreEqual(const FontCascadeDescription& a, const FontCascadeDescription& b) const override
{
return a.variantEastAsianVariant() == b.variantEastAsianVariant()
&& a.variantEastAsianWidth() == b.variantEastAsianWidth()
&& a.variantEastAsianRuby() == b.variantEastAsianRuby();
}
void setPropertiesInFontDescription(const FontCascadeDescription& source, FontCascadeDescription& destination) const override
{
destination.setVariantEastAsianVariant(source.variantEastAsianVariant());
destination.setVariantEastAsianWidth(source.variantEastAsianWidth());
destination.setVariantEastAsianRuby(source.variantEastAsianRuby());
}
};
class FontVariantLigaturesWrapper final : public DiscreteFontDescriptionWrapper {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
FontVariantLigaturesWrapper()
: DiscreteFontDescriptionWrapper(CSSPropertyFontVariantLigatures)
{
}
private:
bool propertiesInFontDescriptionAreEqual(const FontCascadeDescription& a, const FontCascadeDescription& b) const override
{
return a.variantCommonLigatures() == b.variantCommonLigatures()
&& a.variantDiscretionaryLigatures() == b.variantDiscretionaryLigatures()
&& a.variantHistoricalLigatures() == b.variantHistoricalLigatures()
&& a.variantContextualAlternates() == b.variantContextualAlternates();
}
void setPropertiesInFontDescription(const FontCascadeDescription& source, FontCascadeDescription& destination) const override
{
destination.setVariantCommonLigatures(source.variantCommonLigatures());
destination.setVariantDiscretionaryLigatures(source.variantDiscretionaryLigatures());
destination.setVariantHistoricalLigatures(source.variantHistoricalLigatures());
destination.setVariantContextualAlternates(source.variantContextualAlternates());
}
};
class GridTemplateAreasWrapper final : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
GridTemplateAreasWrapper()
: AnimationPropertyWrapperBase(CSSPropertyGridTemplateAreas)
{
}
bool canInterpolate(const RenderStyle&, const RenderStyle&, CompositeOperation) const override { return false; }
bool equals(const RenderStyle& a, const RenderStyle& b) const final
{
return a.implicitNamedGridColumnLines().map == b.implicitNamedGridColumnLines().map
&& a.implicitNamedGridRowLines().map == b.implicitNamedGridRowLines().map
&& a.namedGridArea().map == b.namedGridArea().map
&& a.namedGridAreaRowCount() == b.namedGridAreaRowCount()
&& a.namedGridAreaColumnCount() == b.namedGridAreaColumnCount();
}
#if !LOG_DISABLED
void logBlend(const RenderStyle&, const RenderStyle&, const RenderStyle&, double progress) const final
{
LOG_WITH_STREAM(Animations, stream << " blending " << property() << " at " << TextStream::FormatNumberRespectingIntegers(progress) << ".");
}
#endif
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const final
{
ASSERT(context.isDiscrete);
ASSERT(!context.progress || context.progress == 1);
auto& source = context.progress ? to : from;
destination.setImplicitNamedGridColumnLines(source.implicitNamedGridColumnLines());
destination.setImplicitNamedGridRowLines(source.implicitNamedGridRowLines());
destination.setNamedGridArea(source.namedGridArea());
destination.setNamedGridAreaRowCount(source.namedGridAreaRowCount());
destination.setNamedGridAreaColumnCount(source.namedGridAreaColumnCount());
}
};
class FontVariantNumericWrapper final : public DiscreteFontDescriptionWrapper {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
FontVariantNumericWrapper()
: DiscreteFontDescriptionWrapper(CSSPropertyFontVariantNumeric)
{
}
private:
bool propertiesInFontDescriptionAreEqual(const FontCascadeDescription& a, const FontCascadeDescription& b) const override
{
return a.variantNumericFigure() == b.variantNumericFigure()
&& a.variantNumericSpacing() == b.variantNumericSpacing()
&& a.variantNumericFraction() == b.variantNumericFraction()
&& a.variantNumericOrdinal() == b.variantNumericOrdinal()
&& a.variantNumericSlashedZero() == b.variantNumericSlashedZero();
}
void setPropertiesInFontDescription(const FontCascadeDescription& source, FontCascadeDescription& destination) const override
{
destination.setVariantNumericFigure(source.variantNumericFigure());
destination.setVariantNumericSpacing(source.variantNumericSpacing());
destination.setVariantNumericFraction(source.variantNumericFraction());
destination.setVariantNumericOrdinal(source.variantNumericOrdinal());
destination.setVariantNumericSlashedZero(source.variantNumericSlashedZero());
}
};
class QuotesWrapper final : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
QuotesWrapper()
: AnimationPropertyWrapperBase(CSSPropertyQuotes)
{
}
private:
bool canInterpolate(const RenderStyle&, const RenderStyle&, CompositeOperation) const override { return false; }
bool equals(const RenderStyle& a, const RenderStyle& b) const override
{
return a.quotes() == b.quotes();
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const override
{
ASSERT(!context.progress || context.progress == 1.0);
destination.setQuotes((context.progress ? to : from).quotes());
}
#if !LOG_DISABLED
void logBlend(const RenderStyle&, const RenderStyle&, const RenderStyle&, double) const override
{
}
#endif
};
class VisibilityWrapper final : public PropertyWrapper<Visibility> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
VisibilityWrapper()
: PropertyWrapper(CSSPropertyVisibility, &RenderStyle::visibility, &RenderStyle::setVisibility)
{
}
private:
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
// https://drafts.csswg.org/web-animations-1/#animating-visibility
// If neither value is visible, then discrete animation is used.
return value(from) == Visibility::Visible || value(to) == Visibility::Visible;
}
};
template <typename T>
class DiscreteSVGPropertyWrapper final : public AnimationPropertyWrapperBase {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
DiscreteSVGPropertyWrapper(CSSPropertyID property, T (SVGRenderStyle::*getter)() const, void (SVGRenderStyle::*setter)(T))
: AnimationPropertyWrapperBase(property)
, m_getter(getter)
, m_setter(setter)
{
}
private:
bool canInterpolate(const RenderStyle&, const RenderStyle&, CompositeOperation) const final { return false; }
bool equals(const RenderStyle& a, const RenderStyle& b) const override
{
return this->value(a) == this->value(b);
}
void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const override
{
ASSERT(!context.progress || context.progress == 1.0);
(destination.accessSVGStyle().*this->m_setter)(this->value(context.progress ? to : from));
}
#if !LOG_DISABLED
void logBlend(const RenderStyle&, const RenderStyle&, const RenderStyle&, double) const override
{
}
#endif
T value(const RenderStyle& style) const
{
return (style.svgStyle().*this->m_getter)();
}
T (SVGRenderStyle::*m_getter)() const;
void (SVGRenderStyle::*m_setter)(T);
};
class DWrapper final : public RefCountedPropertyWrapper<StylePathData> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
DWrapper()
: RefCountedPropertyWrapper(CSSPropertyD, &RenderStyle::d, &RenderStyle::setD)
{
}
private:
bool canInterpolate(const RenderStyle& from, const RenderStyle& to, CompositeOperation) const final
{
auto* fromValue = value(from);
auto* toValue = value(to);
return fromValue && toValue && fromValue->canBlend(*toValue);
}
};
class CSSPropertyAnimationWrapperMap final {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
static CSSPropertyAnimationWrapperMap& singleton()
{
// FIXME: This data is never destroyed. Maybe we should ref count it and toss it when the last CSSAnimationController is destroyed?
static NeverDestroyed<CSSPropertyAnimationWrapperMap> map;
return map;
}
AnimationPropertyWrapperBase* wrapperForProperty(CSSPropertyID propertyID)
{
if (propertyID < firstCSSProperty || propertyID - firstCSSProperty >= numCSSProperties)
return nullptr;
unsigned wrapperIndex = indexFromPropertyID(propertyID);
if (wrapperIndex == cInvalidPropertyWrapperIndex)
return nullptr;
return m_propertyWrappers[wrapperIndex].get();
}
AnimationPropertyWrapperBase* wrapperForIndex(unsigned index)
{
ASSERT(index < m_propertyWrappers.size());
return m_propertyWrappers[index].get();
}
unsigned size()
{
return m_propertyWrappers.size();
}
private:
CSSPropertyAnimationWrapperMap();
~CSSPropertyAnimationWrapperMap() = delete;
unsigned short& indexFromPropertyID(CSSPropertyID propertyID)
{
return m_propertyToIdMap[propertyID - firstCSSProperty];
}
Vector<std::unique_ptr<AnimationPropertyWrapperBase>> m_propertyWrappers;
std::array<unsigned short, numCSSProperties> m_propertyToIdMap;
static const unsigned short cInvalidPropertyWrapperIndex = std::numeric_limits<unsigned short>::max();
friend class WTF::NeverDestroyed<CSSPropertyAnimationWrapperMap>;
};
template <typename T>
class NonNormalizedDiscretePropertyWrapper final : public PropertyWrapper<T> {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Animation);
public:
NonNormalizedDiscretePropertyWrapper(CSSPropertyID property, T (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T))
: PropertyWrapper<T>(property, getter, setter)
{
}
private:
bool canInterpolate(const RenderStyle&, const RenderStyle&, CompositeOperation) const final { return false; }
bool normalizesProgressForDiscreteInterpolation() const final { return false; }
};
CSSPropertyAnimationWrapperMap::CSSPropertyAnimationWrapperMap()
{
// build the list of property wrappers to do the comparisons and blends
AnimationPropertyWrapperBase* animatableLonghandPropertyWrappers[] = {
new LengthPropertyWrapper(CSSPropertyLeft, &RenderStyle::left, &RenderStyle::setLeft, { LengthPropertyWrapper::Flags::IsLengthPercentage }),
new LengthPropertyWrapper(CSSPropertyRight, &RenderStyle::right, &RenderStyle::setRight, { LengthPropertyWrapper::Flags::IsLengthPercentage }),
new LengthPropertyWrapper(CSSPropertyTop, &RenderStyle::top, &RenderStyle::setTop, { LengthPropertyWrapper::Flags::IsLengthPercentage }),
new LengthPropertyWrapper(CSSPropertyBottom, &RenderStyle::bottom, &RenderStyle::setBottom, { LengthPropertyWrapper::Flags::IsLengthPercentage }),
new LengthPropertyWrapper(CSSPropertyWidth, &RenderStyle::width, &RenderStyle::setWidth, { LengthPropertyWrapper::Flags::IsLengthPercentage, LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }),
new LengthPropertyWrapper(CSSPropertyMinWidth, &RenderStyle::minWidth, &RenderStyle::setMinWidth, { LengthPropertyWrapper::Flags::IsLengthPercentage, LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }),
new LengthPropertyWrapper(CSSPropertyMaxWidth, &RenderStyle::maxWidth, &RenderStyle::setMaxWidth, { LengthPropertyWrapper::Flags::IsLengthPercentage, LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }),
new LengthPropertyWrapper(CSSPropertyHeight, &RenderStyle::height, &RenderStyle::setHeight, { LengthPropertyWrapper::Flags::IsLengthPercentage, LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }),
new LengthPropertyWrapper(CSSPropertyMinHeight, &RenderStyle::minHeight, &RenderStyle::setMinHeight, { LengthPropertyWrapper::Flags::IsLengthPercentage, LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }),
new LengthPropertyWrapper(CSSPropertyMaxHeight, &RenderStyle::maxHeight, &RenderStyle::setMaxHeight, { LengthPropertyWrapper::Flags::IsLengthPercentage, LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }),
new PropertyWrapperFlex,
new FloatPropertyWrapper(CSSPropertyBorderLeftWidth, &RenderStyle::borderLeftWidth, &RenderStyle::setBorderLeftWidth, FloatPropertyWrapper::ValueRange::NonNegative),
new FloatPropertyWrapper(CSSPropertyBorderRightWidth, &RenderStyle::borderRightWidth, &RenderStyle::setBorderRightWidth, FloatPropertyWrapper::ValueRange::NonNegative),
new FloatPropertyWrapper(CSSPropertyBorderTopWidth, &RenderStyle::borderTopWidth, &RenderStyle::setBorderTopWidth, FloatPropertyWrapper::ValueRange::NonNegative),
new FloatPropertyWrapper(CSSPropertyBorderBottomWidth, &RenderStyle::borderBottomWidth, &RenderStyle::setBorderBottomWidth, FloatPropertyWrapper::ValueRange::NonNegative),
new LengthPropertyWrapper(CSSPropertyMarginLeft, &RenderStyle::marginLeft, &RenderStyle::setMarginLeft, { LengthPropertyWrapper::Flags::IsLengthPercentage }),
new LengthPropertyWrapper(CSSPropertyMarginRight, &RenderStyle::marginRight, &RenderStyle::setMarginRight, { LengthPropertyWrapper::Flags::IsLengthPercentage }),
new LengthPropertyWrapper(CSSPropertyMarginTop, &RenderStyle::marginTop, &RenderStyle::setMarginTop, { LengthPropertyWrapper::Flags::IsLengthPercentage }),
new LengthPropertyWrapper(CSSPropertyMarginBottom, &RenderStyle::marginBottom, &RenderStyle::setMarginBottom, { LengthPropertyWrapper::Flags::IsLengthPercentage }),
new DiscretePropertyWrapper<OptionSet<MarginTrimType>>(CSSPropertyMarginTrim, &RenderStyle::marginTrim, &RenderStyle::setMarginTrim),
new LengthPropertyWrapper(CSSPropertyPaddingLeft, &RenderStyle::paddingLeft, &RenderStyle::setPaddingLeft, { LengthPropertyWrapper::Flags::IsLengthPercentage, LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }),
new LengthPropertyWrapper(CSSPropertyPaddingRight, &RenderStyle::paddingRight, &RenderStyle::setPaddingRight, { LengthPropertyWrapper::Flags::IsLengthPercentage, LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }),
new LengthPropertyWrapper(CSSPropertyPaddingTop, &RenderStyle::paddingTop, &RenderStyle::setPaddingTop, { LengthPropertyWrapper::Flags::IsLengthPercentage, LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }),
new LengthPropertyWrapper(CSSPropertyPaddingBottom, &RenderStyle::paddingBottom, &RenderStyle::setPaddingBottom, { LengthPropertyWrapper::Flags::IsLengthPercentage, LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }),
new AccentColorPropertyWrapper,
new CaretColorPropertyWrapper,
new ScrollbarColorPropertyWrapper,
new PropertyWrapperVisitedAffectedColor(CSSPropertyColor, &RenderStyle::color, &RenderStyle::setColor, &RenderStyle::visitedLinkColor, &RenderStyle::setVisitedLinkColor),
new PropertyWrapperVisitedAffectedStyleColor(CSSPropertyBackgroundColor, &RenderStyle::backgroundColor, &RenderStyle::setBackgroundColor, &RenderStyle::visitedLinkBackgroundColor, &RenderStyle::setVisitedLinkBackgroundColor),
new FillLayersPropertyWrapper(CSSPropertyBackgroundImage, &RenderStyle::backgroundLayers, &RenderStyle::ensureBackgroundLayers),
new StyleImagePropertyWrapper(CSSPropertyListStyleImage, &RenderStyle::listStyleImage, &RenderStyle::setListStyleImage),
new FillLayersPropertyWrapper(CSSPropertyMaskImage, &RenderStyle::maskLayers, &RenderStyle::ensureMaskLayers),
new StyleImagePropertyWrapper(CSSPropertyBorderImageSource, &RenderStyle::borderImageSource, &RenderStyle::setBorderImageSource),
new LengthBoxPropertyWrapper(CSSPropertyBorderImageSlice, &RenderStyle::borderImageSlices, &RenderStyle::setBorderImageSlices, { LengthBoxPropertyWrapper::Flags::UsesFillKeyword }),
new LengthBoxPropertyWrapper(CSSPropertyBorderImageWidth, &RenderStyle::borderImageWidth, &RenderStyle::setBorderImageWidth, { LengthBoxPropertyWrapper::Flags::IsLengthPercentage, LengthBoxPropertyWrapper::Flags::MayOverrideBorderWidths }),
new LengthBoxPropertyWrapper(CSSPropertyBorderImageOutset, &RenderStyle::borderImageOutset, &RenderStyle::setBorderImageOutset),
new NinePieceImageRepeatWrapper(CSSPropertyBorderImageRepeat, &RenderStyle::borderImageHorizontalRule, &RenderStyle::setBorderImageHorizontalRule, &RenderStyle::borderImageVerticalRule, &RenderStyle::setBorderImageVerticalRule),
new StyleImagePropertyWrapper(CSSPropertyMaskBorderSource, &RenderStyle::maskBorderSource, &RenderStyle::setMaskBorderSource),
new LengthBoxPropertyWrapper(CSSPropertyMaskBorderSlice, &RenderStyle::maskBorderSlices, &RenderStyle::setMaskBorderSlices, { LengthBoxPropertyWrapper::Flags::UsesFillKeyword }),
new LengthBoxPropertyWrapper(CSSPropertyMaskBorderWidth, &RenderStyle::maskBorderWidth, &RenderStyle::setMaskBorderWidth, { LengthBoxPropertyWrapper::Flags::IsLengthPercentage }),
new LengthBoxPropertyWrapper(CSSPropertyMaskBorderOutset, &RenderStyle::maskBorderOutset, &RenderStyle::setMaskBorderOutset),
new NinePieceImageRepeatWrapper(CSSPropertyMaskBorderRepeat, &RenderStyle::maskBorderHorizontalRule, &RenderStyle::setMaskBorderHorizontalRule, &RenderStyle::maskBorderVerticalRule, &RenderStyle::setMaskBorderVerticalRule),
new PropertyWrapper<const NinePieceImage&>(CSSPropertyWebkitMaskBoxImage, &RenderStyle::maskBorder, &RenderStyle::setMaskBorder),
new FillLayersPropertyWrapper(CSSPropertyBackgroundPositionX, &RenderStyle::backgroundLayers, &RenderStyle::ensureBackgroundLayers),
new FillLayersPropertyWrapper(CSSPropertyBackgroundPositionY, &RenderStyle::backgroundLayers, &RenderStyle::ensureBackgroundLayers),
new FillLayersPropertyWrapper(CSSPropertyBackgroundSize, &RenderStyle::backgroundLayers, &RenderStyle::ensureBackgroundLayers),
new FillLayersPropertyWrapper(CSSPropertyWebkitBackgroundSize, &RenderStyle::backgroundLayers, &RenderStyle::ensureBackgroundLayers),
new FillLayersPropertyWrapper(CSSPropertyMaskClip, &RenderStyle::maskLayers, &RenderStyle::ensureMaskLayers),
new FillLayersPropertyWrapper(CSSPropertyMaskComposite, &RenderStyle::maskLayers, &RenderStyle::ensureMaskLayers),
new FillLayersPropertyWrapper(CSSPropertyMaskMode, &RenderStyle::maskLayers, &RenderStyle::ensureMaskLayers),
new FillLayersPropertyWrapper(CSSPropertyMaskOrigin, &RenderStyle::maskLayers, &RenderStyle::ensureMaskLayers),
new FillLayersPropertyWrapper(CSSPropertyWebkitMaskPositionX, &RenderStyle::maskLayers, &RenderStyle::ensureMaskLayers),
new FillLayersPropertyWrapper(CSSPropertyWebkitMaskPositionY, &RenderStyle::maskLayers, &RenderStyle::ensureMaskLayers),
new FillLayersPropertyWrapper(CSSPropertyMaskSize, &RenderStyle::maskLayers, &RenderStyle::ensureMaskLayers),
new DiscretePropertyWrapper<FillRepeatXY>(CSSPropertyMaskRepeat, &RenderStyle::maskRepeat, &RenderStyle::setMaskRepeat),
new LengthPointPropertyWrapper(CSSPropertyObjectPosition, &RenderStyle::objectPosition, &RenderStyle::setObjectPosition),
new PropertyWrapper<float>(CSSPropertyFontSize, &RenderStyle::computedFontSize, &RenderStyle::setFontSize),
new PropertyWrapper<unsigned short>(CSSPropertyColumnRuleWidth, &RenderStyle::columnRuleWidth, &RenderStyle::setColumnRuleWidth),
new LengthVariantPropertyWrapper<GapLength>(CSSPropertyColumnGap, &RenderStyle::columnGap, &RenderStyle::setColumnGap),
new LengthVariantPropertyWrapper<GapLength>(CSSPropertyRowGap, &RenderStyle::rowGap, &RenderStyle::setRowGap),
new AutoPropertyWrapper<unsigned short>(CSSPropertyColumnCount, &RenderStyle::columnCount, &RenderStyle::setColumnCount, &RenderStyle::hasAutoColumnCount, &RenderStyle::setHasAutoColumnCount, 1),
new AutoPropertyWrapper<float>(CSSPropertyColumnWidth, &RenderStyle::columnWidth, &RenderStyle::setColumnWidth, &RenderStyle::hasAutoColumnWidth, &RenderStyle::setHasAutoColumnWidth, 0),
new FloatPropertyWrapper(CSSPropertyWebkitBorderHorizontalSpacing, &RenderStyle::horizontalBorderSpacing, &RenderStyle::setHorizontalBorderSpacing, FloatPropertyWrapper::ValueRange::NonNegative),
new FloatPropertyWrapper(CSSPropertyWebkitBorderVerticalSpacing, &RenderStyle::verticalBorderSpacing, &RenderStyle::setVerticalBorderSpacing, FloatPropertyWrapper::ValueRange::NonNegative),
new AutoPropertyWrapper<int>(CSSPropertyZIndex, &RenderStyle::specifiedZIndex, &RenderStyle::setSpecifiedZIndex, &RenderStyle::hasAutoSpecifiedZIndex, &RenderStyle::setHasAutoSpecifiedZIndex),
new PositivePropertyWrapper<unsigned short>(CSSPropertyOrphans, &RenderStyle::orphans, &RenderStyle::setOrphans),
new PositivePropertyWrapper<unsigned short>(CSSPropertyWidows, &RenderStyle::widows, &RenderStyle::setWidows),
new LineHeightWrapper,
new PropertyWrapper<float>(CSSPropertyOutlineOffset, &RenderStyle::outlineOffset, &RenderStyle::setOutlineOffset),
new FloatPropertyWrapper(CSSPropertyOutlineWidth, &RenderStyle::outlineWidth, &RenderStyle::setOutlineWidth, FloatPropertyWrapper::ValueRange::NonNegative),
new LengthPropertyWrapper(CSSPropertyLetterSpacing, &RenderStyle::computedLetterSpacing, &RenderStyle::setLetterSpacing, LengthPropertyWrapper::Flags::IsLengthPercentage),
new LengthPropertyWrapper(CSSPropertyWordSpacing, &RenderStyle::computedWordSpacing, &RenderStyle::setWordSpacing, LengthPropertyWrapper::Flags::IsLengthPercentage),
new TextIndentWrapper,
new VerticalAlignWrapper,
new PerspectiveWrapper,
new LengthPropertyWrapper(CSSPropertyPerspectiveOriginX, &RenderStyle::perspectiveOriginX, &RenderStyle::setPerspectiveOriginX, LengthPropertyWrapper::Flags::IsLengthPercentage),
new LengthPropertyWrapper(CSSPropertyPerspectiveOriginY, &RenderStyle::perspectiveOriginY, &RenderStyle::setPerspectiveOriginY, LengthPropertyWrapper::Flags::IsLengthPercentage),
new LengthPropertyWrapper(CSSPropertyTransformOriginX, &RenderStyle::transformOriginX, &RenderStyle::setTransformOriginX, LengthPropertyWrapper::Flags::IsLengthPercentage),
new LengthPropertyWrapper(CSSPropertyTransformOriginY, &RenderStyle::transformOriginY, &RenderStyle::setTransformOriginY, LengthPropertyWrapper::Flags::IsLengthPercentage),
new PropertyWrapper<float>(CSSPropertyTransformOriginZ, &RenderStyle::transformOriginZ, &RenderStyle::setTransformOriginZ),
new LengthVariantPropertyWrapper<LengthSize>(CSSPropertyBorderTopLeftRadius, &RenderStyle::borderTopLeftRadius, &RenderStyle::setBorderTopLeftRadius),
new LengthVariantPropertyWrapper<LengthSize>(CSSPropertyBorderTopRightRadius, &RenderStyle::borderTopRightRadius, &RenderStyle::setBorderTopRightRadius),
new LengthVariantPropertyWrapper<LengthSize>(CSSPropertyBorderBottomLeftRadius, &RenderStyle::borderBottomLeftRadius, &RenderStyle::setBorderBottomLeftRadius),
new LengthVariantPropertyWrapper<LengthSize>(CSSPropertyBorderBottomRightRadius, &RenderStyle::borderBottomRightRadius, &RenderStyle::setBorderBottomRightRadius),
new VisibilityWrapper,
new NonNormalizedDiscretePropertyWrapper<DisplayType>(CSSPropertyDisplay, &RenderStyle::display, &RenderStyle::setDisplay),
new ClipWrapper,
new AcceleratedPropertyWrapper<float>(CSSPropertyOpacity, &RenderStyle::opacity, &RenderStyle::setOpacity),
new AcceleratedTransformOperationsPropertyWrapper,
new AcceleratedIndividualTransformPropertyWrapper<ScaleTransformOperation>(CSSPropertyScale, &RenderStyle::scale, &RenderStyle::setScale),
new AcceleratedIndividualTransformPropertyWrapper<RotateTransformOperation>(CSSPropertyRotate, &RenderStyle::rotate, &RenderStyle::setRotate),
new AcceleratedIndividualTransformPropertyWrapper<TranslateTransformOperation>(CSSPropertyTranslate, &RenderStyle::translate, &RenderStyle::setTranslate),
new PropertyWrapperFilter(CSSPropertyFilter, &RenderStyle::filter, &RenderStyle::setFilter),
new PropertyWrapperFilter(CSSPropertyBackdropFilter, &RenderStyle::backdropFilter, &RenderStyle::setBackdropFilter),
new PropertyWrapperFilter(CSSPropertyWebkitBackdropFilter, &RenderStyle::backdropFilter, &RenderStyle::setBackdropFilter),
new PropertyWrapperFilter(CSSPropertyAppleColorFilter, &RenderStyle::appleColorFilter, &RenderStyle::setAppleColorFilter),
new PathOperationPropertyWrapper(CSSPropertyClipPath, &RenderStyle::clipPath, &RenderStyle::setClipPath),
new PropertyWrapperShape(CSSPropertyShapeOutside, &RenderStyle::shapeOutside, &RenderStyle::setShapeOutside),
new LengthPropertyWrapper(CSSPropertyShapeMargin, &RenderStyle::shapeMargin, &RenderStyle::setShapeMargin, { LengthPropertyWrapper::Flags::IsLengthPercentage, LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }),
new PropertyWrapper<float>(CSSPropertyShapeImageThreshold, &RenderStyle::shapeImageThreshold, &RenderStyle::setShapeImageThreshold),
new PropertyWrapperVisitedAffectedStyleColor(CSSPropertyColumnRuleColor, &RenderStyle::columnRuleColor, &RenderStyle::setColumnRuleColor, &RenderStyle::visitedLinkColumnRuleColor, &RenderStyle::setVisitedLinkColumnRuleColor),
new PropertyWrapperVisitedAffectedStyleColor(CSSPropertyWebkitTextStrokeColor, &RenderStyle::textStrokeColor, &RenderStyle::setTextStrokeColor, &RenderStyle::visitedLinkTextStrokeColor, &RenderStyle::setVisitedLinkTextStrokeColor),
new PropertyWrapperVisitedAffectedStyleColor(CSSPropertyWebkitTextFillColor, &RenderStyle::textFillColor, &RenderStyle::setTextFillColor, &RenderStyle::visitedLinkTextFillColor, &RenderStyle::setVisitedLinkTextFillColor),
new PropertyWrapperVisitedAffectedStyleColor(CSSPropertyBorderLeftColor, &RenderStyle::borderLeftColor, &RenderStyle::setBorderLeftColor, &RenderStyle::visitedLinkBorderLeftColor, &RenderStyle::setVisitedLinkBorderLeftColor),
new PropertyWrapperVisitedAffectedStyleColor(CSSPropertyBorderRightColor, &RenderStyle::borderRightColor, &RenderStyle::setBorderRightColor, &RenderStyle::visitedLinkBorderRightColor, &RenderStyle::setVisitedLinkBorderRightColor),
new PropertyWrapperVisitedAffectedStyleColor(CSSPropertyBorderTopColor, &RenderStyle::borderTopColor, &RenderStyle::setBorderTopColor, &RenderStyle::visitedLinkBorderTopColor, &RenderStyle::setVisitedLinkBorderTopColor),
new PropertyWrapperVisitedAffectedStyleColor(CSSPropertyBorderBottomColor, &RenderStyle::borderBottomColor, &RenderStyle::setBorderBottomColor, &RenderStyle::visitedLinkBorderBottomColor, &RenderStyle::setVisitedLinkBorderBottomColor),
new PropertyWrapperVisitedAffectedStyleColor(CSSPropertyOutlineColor, &RenderStyle::outlineColor, &RenderStyle::setOutlineColor, &RenderStyle::visitedLinkOutlineColor, &RenderStyle::setVisitedLinkOutlineColor),
new PropertyWrapperShadow(CSSPropertyBoxShadow, &RenderStyle::boxShadow, &RenderStyle::setBoxShadow),
new PropertyWrapperShadow(CSSPropertyWebkitBoxShadow, &RenderStyle::boxShadow, &RenderStyle::setBoxShadow),
new PropertyWrapperShadow(CSSPropertyTextShadow, &RenderStyle::textShadow, &RenderStyle::setTextShadow),
new PropertyWrapperVisitedAffectedSVGPaint(CSSPropertyFill, &RenderStyle::fillPaintType, &RenderStyle::fillPaintColor, &RenderStyle::setFillPaintColor, &RenderStyle::visitedFillPaintType, &RenderStyle::visitedFillPaintColor, &RenderStyle::setVisitedFillPaintColor),
new PropertyWrapper<float>(CSSPropertyFillOpacity, &RenderStyle::fillOpacity, &RenderStyle::setFillOpacity),
new PropertyWrapperVisitedAffectedSVGPaint(CSSPropertyStroke, &RenderStyle::strokePaintType, &RenderStyle::strokePaintColor, &RenderStyle::setStrokePaintColor, &RenderStyle::visitedStrokePaintType, &RenderStyle::visitedStrokePaintColor, &RenderStyle::setVisitedStrokePaintColor),
new PropertyWrapper<float>(CSSPropertyStrokeOpacity, &RenderStyle::strokeOpacity, &RenderStyle::setStrokeOpacity),
new StrokeDasharrayPropertyWrapper,
new PropertyWrapper<float>(CSSPropertyStrokeMiterlimit, &RenderStyle::strokeMiterLimit, &RenderStyle::setStrokeMiterLimit),
new LengthPropertyWrapper(CSSPropertyCx, &RenderStyle::cx, &RenderStyle::setCx),
new LengthPropertyWrapper(CSSPropertyCy, &RenderStyle::cy, &RenderStyle::setCy),
new LengthPropertyWrapper(CSSPropertyR, &RenderStyle::r, &RenderStyle::setR),
new LengthPropertyWrapper(CSSPropertyRx, &RenderStyle::rx, &RenderStyle::setRx),
new LengthPropertyWrapper(CSSPropertyRy, &RenderStyle::ry, &RenderStyle::setRy),
new LengthPropertyWrapper(CSSPropertyStrokeDashoffset, &RenderStyle::strokeDashOffset, &RenderStyle::setStrokeDashOffset),
new LengthPropertyWrapper(CSSPropertyStrokeWidth, &RenderStyle::strokeWidth, &RenderStyle::setStrokeWidth),
new LengthPropertyWrapper(CSSPropertyX, &RenderStyle::x, &RenderStyle::setX),
new LengthPropertyWrapper(CSSPropertyY, &RenderStyle::y, &RenderStyle::setY),
new DWrapper,
new PropertyWrapper<float>(CSSPropertyFloodOpacity, &RenderStyle::floodOpacity, &RenderStyle::setFloodOpacity),
new PropertyWrapperStyleColor(CSSPropertyFloodColor, &RenderStyle::floodColor, &RenderStyle::setFloodColor),
new PropertyWrapper<float>(CSSPropertyStopOpacity, &RenderStyle::stopOpacity, &RenderStyle::setStopOpacity),
new PropertyWrapperStyleColor(CSSPropertyStopColor, &RenderStyle::stopColor, &RenderStyle::setStopColor),
new PropertyWrapperStyleColor(CSSPropertyLightingColor, &RenderStyle::lightingColor, &RenderStyle::setLightingColor),
new PropertyWrapperStyleColor(CSSPropertyStrokeColor, &RenderStyle::strokeColor, &RenderStyle::setStrokeColor),
new PropertyWrapperBaselineShift,
#if ENABLE(VARIATION_FONTS)
new DiscretePropertyWrapper<FontOpticalSizing>(CSSPropertyFontOpticalSizing, &RenderStyle::fontOpticalSizing, &RenderStyle::setFontOpticalSizing),
new PropertyWrapperFontVariationSettings,
#endif
new PropertyWrapperFontSizeAdjust,
new PropertyWrapperFontWeight,
new PropertyWrapper<FontSelectionValue>(CSSPropertyFontWidth, &RenderStyle::fontWidth, &RenderStyle::setFontWidth),
new PropertyWrapperFontStyle,
new PropertyWrapperTextDecorationThickness,
new PropertyWrapperTextUnderlineOffset,
new PropertyWrapperVisitedAffectedStyleColor(CSSPropertyTextDecorationColor, &RenderStyle::textDecorationColor, &RenderStyle::setTextDecorationColor, &RenderStyle::visitedLinkTextDecorationColor, &RenderStyle::setVisitedLinkTextDecorationColor),
new LengthPropertyWrapper(CSSPropertyFlexBasis, &RenderStyle::flexBasis, &RenderStyle::setFlexBasis, { LengthPropertyWrapper::Flags::IsLengthPercentage, LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }),
new FloatPropertyWrapper(CSSPropertyFlexGrow, &RenderStyle::flexGrow, &RenderStyle::setFlexGrow, FloatPropertyWrapper::ValueRange::NonNegative),
new FloatPropertyWrapper(CSSPropertyFlexShrink, &RenderStyle::flexShrink, &RenderStyle::setFlexShrink, FloatPropertyWrapper::ValueRange::NonNegative),
new PropertyWrapper<int>(CSSPropertyOrder, &RenderStyle::order, &RenderStyle::setOrder),
new TabSizePropertyWrapper,
new DiscretePropertyWrapper<BlockStepAlign>(CSSPropertyBlockStepAlign, &RenderStyle::blockStepAlign, &RenderStyle::setBlockStepAlign),
new DiscretePropertyWrapper<BlockStepInsert>(CSSPropertyBlockStepInsert, &RenderStyle::blockStepInsert, &RenderStyle::setBlockStepInsert),
new DiscretePropertyWrapper<BlockStepRound>(CSSPropertyBlockStepRound, &RenderStyle::blockStepRound, &RenderStyle::setBlockStepRound),
new OptionalLengthPropertyWrapper(CSSPropertyBlockStepSize, &RenderStyle::blockStepSize, &RenderStyle::setBlockStepSize, { OptionalLengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }),
new ContainIntrinsicLengthPropertyWrapper(CSSPropertyContainIntrinsicWidth, &RenderStyle::containIntrinsicWidth, &RenderStyle::setContainIntrinsicWidth, &RenderStyle::containIntrinsicWidthType, &RenderStyle::setContainIntrinsicWidthType),
new ContainIntrinsicLengthPropertyWrapper(CSSPropertyContainIntrinsicHeight, &RenderStyle::containIntrinsicHeight, &RenderStyle::setContainIntrinsicHeight, &RenderStyle::containIntrinsicHeightType, &RenderStyle::setContainIntrinsicHeightType),
new DiscretePropertyWrapper<const StyleContentAlignmentData&>(CSSPropertyAlignContent, &RenderStyle::alignContent, &RenderStyle::setAlignContent),
new DiscretePropertyWrapper<const StyleSelfAlignmentData&>(CSSPropertyAlignItems, &RenderStyle::alignItems, &RenderStyle::setAlignItems),
new DiscretePropertyWrapper<const StyleSelfAlignmentData&>(CSSPropertyAlignSelf, &RenderStyle::alignSelf, &RenderStyle::setAlignSelf),
new DiscretePropertyWrapper<BackfaceVisibility>(CSSPropertyBackfaceVisibility, &RenderStyle::backfaceVisibility, &RenderStyle::setBackfaceVisibility),
new DiscretePropertyWrapper<FillAttachment>(CSSPropertyBackgroundAttachment, &RenderStyle::backgroundAttachment, &RenderStyle::setBackgroundAttachment),
new DiscretePropertyWrapper<FillBox>(CSSPropertyBackgroundClip, &RenderStyle::backgroundClip, &RenderStyle::setBackgroundClip),
new DiscretePropertyWrapper<FillBox>(CSSPropertyBackgroundOrigin, &RenderStyle::backgroundOrigin, &RenderStyle::setBackgroundOrigin),
new DiscretePropertyWrapper<FillRepeatXY>(CSSPropertyBackgroundRepeat, &RenderStyle::backgroundRepeat, &RenderStyle::setBackgroundRepeat),
new DiscretePropertyWrapper<BorderStyle>(CSSPropertyBorderBottomStyle, &RenderStyle::borderBottomStyle, &RenderStyle::setBorderBottomStyle),
new DiscretePropertyWrapper<BorderCollapse>(CSSPropertyBorderCollapse, &RenderStyle::borderCollapse, &RenderStyle::setBorderCollapse),
new DiscretePropertyWrapper<BorderStyle>(CSSPropertyBorderLeftStyle, &RenderStyle::borderLeftStyle, &RenderStyle::setBorderLeftStyle),
new DiscretePropertyWrapper<BorderStyle>(CSSPropertyBorderRightStyle, &RenderStyle::borderRightStyle, &RenderStyle::setBorderRightStyle),
new DiscretePropertyWrapper<BorderStyle>(CSSPropertyBorderTopStyle, &RenderStyle::borderTopStyle, &RenderStyle::setBorderTopStyle),
new DiscretePropertyWrapper<BoxSizing>(CSSPropertyBoxSizing, &RenderStyle::boxSizing, &RenderStyle::setBoxSizing),
new DiscretePropertyWrapper<CaptionSide>(CSSPropertyCaptionSide, &RenderStyle::captionSide, &RenderStyle::setCaptionSide),
new DiscretePropertyWrapper<Clear>(CSSPropertyClear, &RenderStyle::clear, &RenderStyle::setClear),
new DiscretePropertyWrapper<TextEdge>(CSSPropertyTextBoxEdge, &RenderStyle::textBoxEdge, &RenderStyle::setTextBoxEdge),
new DiscretePropertyWrapper<TextEdge>(CSSPropertyLineFitEdge, &RenderStyle::lineFitEdge, &RenderStyle::setLineFitEdge),
new DiscretePropertyWrapper<TextBoxTrim>(CSSPropertyTextBoxTrim, &RenderStyle::textBoxTrim, &RenderStyle::setTextBoxTrim),
new DiscretePropertyWrapper<PrintColorAdjust>(CSSPropertyPrintColorAdjust, &RenderStyle::printColorAdjust, &RenderStyle::setPrintColorAdjust),
new DiscretePropertyWrapper<ColumnFill>(CSSPropertyColumnFill, &RenderStyle::columnFill, &RenderStyle::setColumnFill),
new DiscretePropertyWrapper<ColumnSpan>(CSSPropertyColumnSpan, &RenderStyle::columnSpan, &RenderStyle::setColumnSpan),
new DiscretePropertyWrapper<BorderStyle>(CSSPropertyColumnRuleStyle, &RenderStyle::columnRuleStyle, &RenderStyle::setColumnRuleStyle),
new NonNormalizedDiscretePropertyWrapper<ContentVisibility>(CSSPropertyContentVisibility, &RenderStyle::contentVisibility, &RenderStyle::setContentVisibility),
new DiscretePropertyWrapper<CursorType>(CSSPropertyCursor, &RenderStyle::cursor, &RenderStyle::setCursor),
new DiscretePropertyWrapper<EmptyCell>(CSSPropertyEmptyCells, &RenderStyle::emptyCells, &RenderStyle::setEmptyCells),
new DiscretePropertyWrapper<FlexDirection>(CSSPropertyFlexDirection, &RenderStyle::flexDirection, &RenderStyle::setFlexDirection),
new DiscretePropertyWrapper<FlexWrap>(CSSPropertyFlexWrap, &RenderStyle::flexWrap, &RenderStyle::setFlexWrap),
new DiscretePropertyWrapper<Float>(CSSPropertyFloat, &RenderStyle::floating, &RenderStyle::setFloating),
new DiscretePropertyWrapper<const Vector<GridTrackSize>&>(CSSPropertyGridAutoColumns, &RenderStyle::gridAutoColumns, &RenderStyle::setGridAutoColumns),
new DiscretePropertyWrapper<GridAutoFlow>(CSSPropertyGridAutoFlow, &RenderStyle::gridAutoFlow, &RenderStyle::setGridAutoFlow),
new DiscretePropertyWrapper<const Vector<GridTrackSize>&>(CSSPropertyGridAutoRows, &RenderStyle::gridAutoRows, &RenderStyle::setGridAutoRows),
new GridTemplatePropertyWrapper(CSSPropertyGridTemplateRows, &RenderStyle::gridRowList, &RenderStyle::setGridRowList),
new GridTemplatePropertyWrapper(CSSPropertyGridTemplateColumns, &RenderStyle::gridColumnList, &RenderStyle::setGridColumnList),
new DiscretePropertyWrapper<const GridPosition&>(CSSPropertyGridColumnEnd, &RenderStyle::gridItemColumnEnd, &RenderStyle::setGridItemColumnEnd),
new DiscretePropertyWrapper<const GridPosition&>(CSSPropertyGridColumnStart, &RenderStyle::gridItemColumnStart, &RenderStyle::setGridItemColumnStart),
new DiscretePropertyWrapper<const GridPosition&>(CSSPropertyGridRowEnd, &RenderStyle::gridItemRowEnd, &RenderStyle::setGridItemRowEnd),
new DiscretePropertyWrapper<const GridPosition&>(CSSPropertyGridRowStart, &RenderStyle::gridItemRowStart, &RenderStyle::setGridItemRowStart),
new DiscretePropertyWrapper<OptionSet<HangingPunctuation>>(CSSPropertyHangingPunctuation, &RenderStyle::hangingPunctuation, &RenderStyle::setHangingPunctuation),
new DiscretePropertyWrapper<Hyphens>(CSSPropertyHyphens, &RenderStyle::hyphens, &RenderStyle::setHyphens),
new DiscretePropertyWrapper<const AtomString&>(CSSPropertyHyphenateCharacter, &RenderStyle::hyphenationString, &RenderStyle::setHyphenationString),
new DiscretePropertyWrapper<ImageOrientation>(CSSPropertyImageOrientation, &RenderStyle::imageOrientation, &RenderStyle::setImageOrientation),
new DiscretePropertyWrapper<ImageRendering>(CSSPropertyImageRendering, &RenderStyle::imageRendering, &RenderStyle::setImageRendering),
new DiscretePropertyWrapper<const IntSize&>(CSSPropertyWebkitInitialLetter, &RenderStyle::initialLetter, &RenderStyle::setInitialLetter),
new DiscretePropertyWrapper<const StyleContentAlignmentData&>(CSSPropertyJustifyContent, &RenderStyle::justifyContent, &RenderStyle::setJustifyContent),
new DiscretePropertyWrapper<const StyleSelfAlignmentData&>(CSSPropertyJustifyItems, &RenderStyle::justifyItems, &RenderStyle::setJustifyItems),
new DiscretePropertyWrapper<const StyleSelfAlignmentData&>(CSSPropertyJustifySelf, &RenderStyle::justifySelf, &RenderStyle::setJustifySelf),
new DiscretePropertyWrapper<LineBreak>(CSSPropertyLineBreak, &RenderStyle::lineBreak, &RenderStyle::setLineBreak),
new DiscretePropertyWrapper<ListStylePosition>(CSSPropertyListStylePosition, &RenderStyle::listStylePosition, &RenderStyle::setListStylePosition),
new DiscretePropertyWrapper<ListStyleType>(CSSPropertyListStyleType, &RenderStyle::listStyleType, &RenderStyle::setListStyleType),
new DiscretePropertyWrapper<ObjectFit>(CSSPropertyObjectFit, &RenderStyle::objectFit, &RenderStyle::setObjectFit),
new DiscretePropertyWrapper<BorderStyle>(CSSPropertyOutlineStyle, &RenderStyle::outlineStyle, &RenderStyle::setOutlineStyle),
new DiscretePropertyWrapper<OverflowWrap>(CSSPropertyOverflowWrap, &RenderStyle::overflowWrap, &RenderStyle::setOverflowWrap),
new DiscretePropertyWrapper<Overflow>(CSSPropertyOverflowX, &RenderStyle::overflowX, &RenderStyle::setOverflowX),
new DiscretePropertyWrapper<Overflow>(CSSPropertyOverflowY, &RenderStyle::overflowY, &RenderStyle::setOverflowY),
new DiscretePropertyWrapper<BreakBetween>(CSSPropertyBreakAfter, &RenderStyle::breakAfter, &RenderStyle::setBreakAfter),
new DiscretePropertyWrapper<BreakBetween>(CSSPropertyBreakBefore, &RenderStyle::breakBefore, &RenderStyle::setBreakBefore),
new DiscretePropertyWrapper<BreakInside>(CSSPropertyBreakInside, &RenderStyle::breakInside, &RenderStyle::setBreakInside),
new DiscretePropertyWrapper<PaintOrder>(CSSPropertyPaintOrder, &RenderStyle::paintOrder, &RenderStyle::setPaintOrder),
new DiscretePropertyWrapper<PointerEvents>(CSSPropertyPointerEvents, &RenderStyle::pointerEvents, &RenderStyle::setPointerEvents),
new DiscretePropertyWrapper<PositionType>(CSSPropertyPosition, &RenderStyle::position, &RenderStyle::setPosition),
new DiscretePropertyWrapper<Resize>(CSSPropertyResize, &RenderStyle::resize, &RenderStyle::setResize),
new DiscretePropertyWrapper<RubyPosition>(CSSPropertyRubyPosition, &RenderStyle::rubyPosition, &RenderStyle::setRubyPosition),
new DiscretePropertyWrapper<RubyAlign>(CSSPropertyRubyAlign, &RenderStyle::rubyAlign, &RenderStyle::setRubyAlign),
new DiscretePropertyWrapper<RubyOverhang>(CSSPropertyRubyOverhang, &RenderStyle::rubyOverhang, &RenderStyle::setRubyOverhang),
new DiscretePropertyWrapper<TableLayoutType>(CSSPropertyTableLayout, &RenderStyle::tableLayout, &RenderStyle::setTableLayout),
new DiscretePropertyWrapper<TextAlignMode>(CSSPropertyTextAlign, &RenderStyle::textAlign, &RenderStyle::setTextAlign),
new DiscretePropertyWrapper<TextAlignLast>(CSSPropertyTextAlignLast, &RenderStyle::textAlignLast, &RenderStyle::setTextAlignLast),
new DiscretePropertyWrapper<OptionSet<TextDecorationLine>>(CSSPropertyTextDecorationLine, &RenderStyle::textDecorationLine, &RenderStyle::setTextDecorationLine),
new DiscretePropertyWrapper<TextDecorationStyle>(CSSPropertyTextDecorationStyle, &RenderStyle::textDecorationStyle, &RenderStyle::setTextDecorationStyle),
new PropertyWrapperVisitedAffectedStyleColor(CSSPropertyTextEmphasisColor, &RenderStyle::textEmphasisColor, &RenderStyle::setTextEmphasisColor, &RenderStyle::visitedLinkTextEmphasisColor, &RenderStyle::setVisitedLinkTextEmphasisColor),
new DiscretePropertyWrapper<OptionSet<TextEmphasisPosition>>(CSSPropertyTextEmphasisPosition, &RenderStyle::textEmphasisPosition, &RenderStyle::setTextEmphasisPosition),
new TextEmphasisStyleWrapper,
new DiscretePropertyWrapper<TextGroupAlign>(CSSPropertyTextGroupAlign, &RenderStyle::textGroupAlign, &RenderStyle::setTextGroupAlign),
new DiscretePropertyWrapper<TextJustify>(CSSPropertyTextJustify, &RenderStyle::textJustify, &RenderStyle::setTextJustify),
new DiscretePropertyWrapper<TextOverflow>(CSSPropertyTextOverflow, &RenderStyle::textOverflow, &RenderStyle::setTextOverflow),
new DiscretePropertyWrapper<OptionSet<TouchAction>>(CSSPropertyTouchAction, &RenderStyle::touchActions, &RenderStyle::setTouchActions),
new DiscretePropertyWrapper<OptionSet<TextTransform>>(CSSPropertyTextTransform, &RenderStyle::textTransform, &RenderStyle::setTextTransform),
new DiscretePropertyWrapper<WhiteSpaceCollapse>(CSSPropertyWhiteSpaceCollapse, &RenderStyle::whiteSpaceCollapse, &RenderStyle::setWhiteSpaceCollapse),
new DiscretePropertyWrapper<TextWrapMode>(CSSPropertyTextWrapMode, &RenderStyle::textWrapMode, &RenderStyle::setTextWrapMode),
new DiscretePropertyWrapper<TextWrapStyle>(CSSPropertyTextWrapStyle, &RenderStyle::textWrapStyle, &RenderStyle::setTextWrapStyle),
new DiscretePropertyWrapper<TransformBox>(CSSPropertyTransformBox, &RenderStyle::transformBox, &RenderStyle::setTransformBox),
new DiscretePropertyWrapper<TransformStyle3D>(CSSPropertyTransformStyle, &RenderStyle::transformStyle3D, &RenderStyle::setTransformStyle3D),
new DiscretePropertyWrapper<WordBreak>(CSSPropertyWordBreak, &RenderStyle::wordBreak, &RenderStyle::setWordBreak),
new DiscretePropertyWrapper<OverflowAnchor>(CSSPropertyOverflowAnchor, &RenderStyle::overflowAnchor, &RenderStyle::setOverflowAnchor),
new DiscretePropertyWrapper<TextSpacingTrim>(CSSPropertyTextSpacingTrim, &RenderStyle::textSpacingTrim, &RenderStyle::setTextSpacingTrim),
new DiscretePropertyWrapper<TextAutospace>(CSSPropertyTextAutospace, &RenderStyle::textAutospace, &RenderStyle::setTextAutospace),
new DiscretePropertyWrapper<OptionSet<TextUnderlinePosition>>(CSSPropertyTextUnderlinePosition, &RenderStyle::textUnderlinePosition, &RenderStyle::setTextUnderlinePosition),
new DiscretePropertyWrapper<BoxDecorationBreak>(CSSPropertyWebkitBoxDecorationBreak, &RenderStyle::boxDecorationBreak, &RenderStyle::setBoxDecorationBreak),
new DiscretePropertyWrapper<Isolation>(CSSPropertyIsolation, &RenderStyle::isolation, &RenderStyle::setIsolation),
new DiscretePropertyWrapper<BlendMode>(CSSPropertyMixBlendMode, &RenderStyle::blendMode, &RenderStyle::setBlendMode),
new DiscretePropertyWrapper<BlendMode>(CSSPropertyBackgroundBlendMode, &RenderStyle::backgroundBlendMode, &RenderStyle::setBackgroundBlendMode),
new DiscretePropertyWrapper<StyleAppearance>(CSSPropertyAppearance, &RenderStyle::appearance, &RenderStyle::setAppearance),
#if ENABLE(DARK_MODE_CSS)
new DiscretePropertyWrapper<Style::ColorScheme>(CSSPropertyColorScheme, &RenderStyle::colorScheme, &RenderStyle::setColorScheme),
#endif
#if HAVE(CORE_MATERIAL)
new DiscretePropertyWrapper<AppleVisualEffect>(CSSPropertyAppleVisualEffect, &RenderStyle::appleVisualEffect, &RenderStyle::setAppleVisualEffect),
#endif
new PropertyWrapperAspectRatio,
new DiscretePropertyWrapper<const FontPalette&>(CSSPropertyFontPalette, &RenderStyle::fontPalette, &RenderStyle::setFontPalette),
new PropertyWrapperDynamicRangeLimit,
new OffsetPathWrapper,
new OffsetDistanceWrapper,
new OffsetLengthPointWrapper(CSSPropertyOffsetPosition, &RenderStyle::offsetPosition, &RenderStyle::setOffsetPosition),
new OffsetLengthPointWrapper(CSSPropertyOffsetAnchor, &RenderStyle::offsetAnchor, &RenderStyle::setOffsetAnchor),
new OffsetRotateWrapper,
new PropertyWrapperContent,
new DiscretePropertyWrapper<TextDecorationSkipInk>(CSSPropertyTextDecorationSkipInk, &RenderStyle::textDecorationSkipInk, &RenderStyle::setTextDecorationSkipInk),
new DiscreteSVGPropertyWrapper<ColorInterpolation>(CSSPropertyColorInterpolation, &SVGRenderStyle::colorInterpolation, &SVGRenderStyle::setColorInterpolation),
new DiscreteFontDescriptionTypedWrapper<Kerning>(CSSPropertyFontKerning, &FontCascadeDescription::kerning, &FontCascadeDescription::setKerning),
new FontFeatureSettingsWrapper,
new FontFamilyWrapper,
new DiscreteSVGPropertyWrapper<AlignmentBaseline>(CSSPropertyAlignmentBaseline, &SVGRenderStyle::alignmentBaseline, &SVGRenderStyle::setAlignmentBaseline),
new DiscreteSVGPropertyWrapper<BufferedRendering>(CSSPropertyBufferedRendering, &SVGRenderStyle::bufferedRendering, &SVGRenderStyle::setBufferedRendering),
new DiscreteSVGPropertyWrapper<WindRule>(CSSPropertyClipRule, &SVGRenderStyle::clipRule, &SVGRenderStyle::setClipRule),
new DiscreteSVGPropertyWrapper<ColorInterpolation>(CSSPropertyColorInterpolationFilters, &SVGRenderStyle::colorInterpolationFilters, &SVGRenderStyle::setColorInterpolationFilters),
new DiscreteSVGPropertyWrapper<DominantBaseline>(CSSPropertyDominantBaseline, &SVGRenderStyle::dominantBaseline, &SVGRenderStyle::setDominantBaseline),
new CounterWrapper(CSSPropertyCounterIncrement),
new CounterWrapper(CSSPropertyCounterReset),
new CounterWrapper(CSSPropertyCounterSet),
new DiscreteSVGPropertyWrapper<WindRule>(CSSPropertyFillRule, &SVGRenderStyle::fillRule, &SVGRenderStyle::setFillRule),
new DiscreteFontDescriptionTypedWrapper<FontSynthesisLonghandValue>(CSSPropertyFontSynthesisWeight, &FontCascadeDescription::fontSynthesisWeight, &FontCascadeDescription::setFontSynthesisWeight),
new DiscreteFontDescriptionTypedWrapper<FontSynthesisLonghandValue>(CSSPropertyFontSynthesisStyle, &FontCascadeDescription::fontSynthesisStyle, &FontCascadeDescription::setFontSynthesisStyle),
new DiscreteFontDescriptionTypedWrapper<FontSynthesisLonghandValue>(CSSPropertyFontSynthesisSmallCaps, &FontCascadeDescription::fontSynthesisSmallCaps, &FontCascadeDescription::setFontSynthesisSmallCaps),
new DiscreteFontDescriptionTypedWrapper<const FontVariantAlternates&>(CSSPropertyFontVariantAlternates, &FontCascadeDescription::variantAlternates, &FontCascadeDescription::setVariantAlternates),
new FontVariantEastAsianWrapper,
new FontVariantLigaturesWrapper,
new FontVariantNumericWrapper,
new DiscreteFontDescriptionTypedWrapper<FontVariantPosition>(CSSPropertyFontVariantPosition, &FontCascadeDescription::variantPosition, &FontCascadeDescription::setVariantPosition),
new DiscreteFontDescriptionTypedWrapper<FontVariantCaps>(CSSPropertyFontVariantCaps, &FontCascadeDescription::variantCaps, &FontCascadeDescription::setVariantCaps),
new DiscreteFontDescriptionTypedWrapper<FontVariantEmoji>(CSSPropertyFontVariantEmoji, &FontCascadeDescription::variantEmoji, &FontCascadeDescription::setVariantEmoji),
new GridTemplateAreasWrapper,
new QuotesWrapper,
new DiscretePropertyWrapper<bool>(CSSPropertyScrollBehavior, &RenderStyle::useSmoothScrolling, &RenderStyle::setUseSmoothScrolling),
new DiscreteFontDescriptionTypedWrapper<TextRenderingMode>(CSSPropertyTextRendering, &FontCascadeDescription::textRenderingMode, &FontCascadeDescription::setTextRenderingMode),
new DiscreteSVGPropertyWrapper<MaskType>(CSSPropertyMaskType, &SVGRenderStyle::maskType, &SVGRenderStyle::setMaskType),
new DiscretePropertyWrapper<LineCap>(CSSPropertyStrokeLinecap, &RenderStyle::capStyle, &RenderStyle::setCapStyle),
new DiscretePropertyWrapper<LineJoin>(CSSPropertyStrokeLinejoin, &RenderStyle::joinStyle, &RenderStyle::setJoinStyle),
new DiscreteSVGPropertyWrapper<TextAnchor>(CSSPropertyTextAnchor, &SVGRenderStyle::textAnchor, &SVGRenderStyle::setTextAnchor),
new DiscreteSVGPropertyWrapper<VectorEffect>(CSSPropertyVectorEffect, &SVGRenderStyle::vectorEffect, &SVGRenderStyle::setVectorEffect),
new DiscreteSVGPropertyWrapper<ShapeRendering>(CSSPropertyShapeRendering, &SVGRenderStyle::shapeRendering, &SVGRenderStyle::setShapeRendering),
new DiscreteSVGPropertyWrapper<const String&>(CSSPropertyMarkerEnd, &SVGRenderStyle::markerEndResource, &SVGRenderStyle::setMarkerEndResource),
new DiscreteSVGPropertyWrapper<const String&>(CSSPropertyMarkerMid, &SVGRenderStyle::markerMidResource, &SVGRenderStyle::setMarkerMidResource),
new DiscreteSVGPropertyWrapper<const String&>(CSSPropertyMarkerStart, &SVGRenderStyle::markerStartResource, &SVGRenderStyle::setMarkerStartResource),
new DiscretePropertyWrapper<ScrollbarGutter>(CSSPropertyScrollbarGutter, &RenderStyle::scrollbarGutter, &RenderStyle::setScrollbarGutter),
new DiscretePropertyWrapper<ScrollbarWidth>(CSSPropertyScrollbarWidth, &RenderStyle::scrollbarWidth, &RenderStyle::setScrollbarWidth),
new DiscretePropertyWrapper<const ScrollSnapAlign&>(CSSPropertyScrollSnapAlign, &RenderStyle::scrollSnapAlign, &RenderStyle::setScrollSnapAlign),
new DiscretePropertyWrapper<ScrollSnapStop>(CSSPropertyScrollSnapStop, &RenderStyle::scrollSnapStop, &RenderStyle::setScrollSnapStop),
new DiscretePropertyWrapper<ScrollSnapType>(CSSPropertyScrollSnapType, &RenderStyle::scrollSnapType, &RenderStyle::setScrollSnapType),
new DiscretePropertyWrapper<const Vector<Style::ScopedName>&>(CSSPropertyViewTransitionClass, &RenderStyle::viewTransitionClasses, &RenderStyle::setViewTransitionClasses),
new DiscretePropertyWrapper<Style::ViewTransitionName>(CSSPropertyViewTransitionName, &RenderStyle::viewTransitionName, &RenderStyle::setViewTransitionName),
new DiscretePropertyWrapper<FieldSizing>(CSSPropertyFieldSizing, &RenderStyle::fieldSizing, &RenderStyle::setFieldSizing),
new DiscretePropertyWrapper<const Vector<Style::ScopedName>&>(CSSPropertyAnchorName, &RenderStyle::anchorNames, &RenderStyle::setAnchorNames),
new DiscretePropertyWrapper<const NameScope&>(CSSPropertyAnchorScope, &RenderStyle::anchorScope, &RenderStyle::setAnchorScope),
new DiscretePropertyWrapper<const std::optional<Style::ScopedName>&>(CSSPropertyPositionAnchor, &RenderStyle::positionAnchor, &RenderStyle::setPositionAnchor),
new DiscretePropertyWrapper<std::optional<PositionArea>>(CSSPropertyPositionArea, &RenderStyle::positionArea, &RenderStyle::setPositionArea),
new DiscretePropertyWrapper<Style::PositionTryOrder>(CSSPropertyPositionTryOrder, &RenderStyle::positionTryOrder, &RenderStyle::setPositionTryOrder),
new DiscretePropertyWrapper<const Vector<PositionTryFallback>&>(CSSPropertyPositionTryFallbacks, &RenderStyle::positionTryFallbacks, &RenderStyle::setPositionTryFallbacks),
new DiscretePropertyWrapper<const BlockEllipsis&>(CSSPropertyBlockEllipsis, &RenderStyle::blockEllipsis, &RenderStyle::setBlockEllipsis),
new DiscretePropertyWrapper<size_t>(CSSPropertyMaxLines, &RenderStyle::maxLines, &RenderStyle::setMaxLines),
new DiscretePropertyWrapper<OverflowContinue>(CSSPropertyContinue, &RenderStyle::overflowContinue, &RenderStyle::setOverflowContinue)
};
const unsigned animatableLonghandPropertiesCount = std::size(animatableLonghandPropertyWrappers);
static constexpr auto animatableShorthandProperties = std::to_array<CSSPropertyID>({
CSSPropertyAll,
CSSPropertyBackground, // for background-color, background-position, background-image
CSSPropertyBackgroundPosition,
CSSPropertyFont, // for font-size, font-weight
CSSPropertyMask, // for mask-position
CSSPropertyWebkitMask, // for mask-position
CSSPropertyMaskPosition,
CSSPropertyWebkitMaskPosition,
CSSPropertyBorderBlock,
CSSPropertyBorderBlockColor,
CSSPropertyBorderBlockStyle,
CSSPropertyBorderBlockWidth,
CSSPropertyBorderInline,
CSSPropertyBorderInlineColor,
CSSPropertyBorderInlineStyle,
CSSPropertyBorderInlineWidth,
CSSPropertyBorderTop, CSSPropertyBorderRight, CSSPropertyBorderBottom, CSSPropertyBorderLeft,
CSSPropertyBorderBlockStart, CSSPropertyBorderBlockEnd, CSSPropertyBorderInlineStart, CSSPropertyBorderInlineEnd,
CSSPropertyBorderColor,
CSSPropertyBorderRadius,
CSSPropertyBorderWidth,
CSSPropertyBorder,
CSSPropertyBorderImage,
CSSPropertyBorderSpacing,
CSSPropertyBlockStep,
CSSPropertyColumns,
CSSPropertyFlex,
CSSPropertyFlexFlow,
CSSPropertyGap,
CSSPropertyGrid,
CSSPropertyGridArea,
CSSPropertyGridColumn,
CSSPropertyGridRow,
CSSPropertyGridTemplate,
CSSPropertyInsetBlock, // logical shorthand
CSSPropertyLineClamp,
CSSPropertyListStyle, // for list-style-image
CSSPropertyMargin,
CSSPropertyMarginBlock, // logical shorthand
CSSPropertyMarginInline, // logical shorthand
CSSPropertyMarker,
CSSPropertyMaskBorder,
CSSPropertyOutline,
CSSPropertyPadding,
CSSPropertyPaddingBlock,
CSSPropertyPaddingInline,
CSSPropertyPageBreakAfter,
CSSPropertyPageBreakBefore,
CSSPropertyPageBreakInside,
CSSPropertyPlaceContent,
CSSPropertyPlaceItems,
CSSPropertyPlaceSelf,
CSSPropertyWebkitTextStroke,
CSSPropertyColumnRule,
CSSPropertyWebkitBorderRadius,
CSSPropertyTextDecoration,
CSSPropertyTextDecorationSkip,
CSSPropertyTransformOrigin,
CSSPropertyPerspectiveOrigin,
CSSPropertyOffset,
CSSPropertyOverflow,
CSSPropertyTextEmphasis,
CSSPropertyFontVariant,
CSSPropertyFontSynthesis,
CSSPropertyContainIntrinsicSize,
CSSPropertyTextBox,
CSSPropertyTextWrap,
CSSPropertyWhiteSpace
});
constexpr unsigned animatableShorthandPropertiesCount = std::size(animatableShorthandProperties);
// Make sure unused slots have a value
for (int i = 0; i < numCSSProperties; ++i)
m_propertyToIdMap[i] = cInvalidPropertyWrapperIndex;
static_assert(animatableLonghandPropertiesCount + animatableShorthandPropertiesCount < std::numeric_limits<unsigned short>::max(), "number of AnimatableProperties must be less than UShrtMax");
m_propertyWrappers.reserveInitialCapacity(animatableLonghandPropertiesCount + animatableShorthandPropertiesCount);
// First we put the non-shorthand property wrappers into the map, so the shorthand-building
// code can find them.
unsigned index = 0;
m_propertyWrappers.appendContainerWithMapping(animatableLonghandPropertyWrappers, [&](auto* wrapper) {
indexFromPropertyID(wrapper->property()) = index++;
return std::unique_ptr<AnimationPropertyWrapperBase>(wrapper);
});
for (size_t i = 0; i < animatableShorthandPropertiesCount; ++i) {
CSSPropertyID propertyID = animatableShorthandProperties[i];
auto shorthand = shorthandForProperty(propertyID);
if (!shorthand.length())
continue;
auto longhandWrappers = WTF::compactMap(shorthand, [&](auto longhand) -> std::optional<AnimationPropertyWrapperBase*> {
unsigned wrapperIndex = indexFromPropertyID(longhand);
if (wrapperIndex == cInvalidPropertyWrapperIndex)
return std::nullopt;
ASSERT(m_propertyWrappers[wrapperIndex]);
return m_propertyWrappers[wrapperIndex].get();
});
m_propertyWrappers.append(makeUnique<ShorthandPropertyWrapper>(propertyID, WTFMove(longhandWrappers)));
indexFromPropertyID(propertyID) = animatableLonghandPropertiesCount + i;
}
#ifndef NDEBUG
for (auto property : allCSSProperties()) {
switch (property) {
// If a property is not animatable per spec, add it to this list of cases.
// When adding a new property, you should make sure it belongs in this list
// or provide a wrapper for it above. If you are adding to this list but the
// property should be animatable, make sure to file a bug.
// To be fixed / untriaged:
case CSSPropertyBorderStyle:
case CSSPropertyInlineSize:
case CSSPropertyInputSecurity:
case CSSPropertyInset:
case CSSPropertyInsetBlockEnd:
case CSSPropertyInsetBlockStart:
case CSSPropertyInsetInline:
case CSSPropertyInsetInlineEnd:
case CSSPropertyInsetInlineStart:
case CSSPropertyMasonryAutoFlow:
case CSSPropertyOverscrollBehavior:
case CSSPropertyOverscrollBehaviorBlock:
case CSSPropertyOverscrollBehaviorInline:
case CSSPropertyOverscrollBehaviorX:
case CSSPropertyOverscrollBehaviorY:
case CSSPropertyPage:
case CSSPropertyScrollMargin:
case CSSPropertyScrollMarginBlock:
case CSSPropertyScrollMarginBlockEnd:
case CSSPropertyScrollMarginBlockStart:
case CSSPropertyScrollMarginBottom:
case CSSPropertyScrollMarginInline:
case CSSPropertyScrollMarginInlineEnd:
case CSSPropertyScrollMarginInlineStart:
case CSSPropertyScrollMarginLeft:
case CSSPropertyScrollMarginRight:
case CSSPropertyScrollMarginTop:
case CSSPropertyScrollPadding:
case CSSPropertyScrollPaddingBlock:
case CSSPropertyScrollPaddingBlockEnd:
case CSSPropertyScrollPaddingBlockStart:
case CSSPropertyScrollPaddingBottom:
case CSSPropertyScrollPaddingInline:
case CSSPropertyScrollPaddingInlineEnd:
case CSSPropertyScrollPaddingInlineStart:
case CSSPropertyScrollPaddingLeft:
case CSSPropertyScrollPaddingRight:
case CSSPropertyScrollPaddingTop:
#if ENABLE(TEXT_AUTOSIZING)
case CSSPropertyWebkitTextSizeAdjust:
#endif
case CSSPropertyViewTimeline:
case CSSPropertyViewTimelineInset: // FIXME: view-timeline-inset should be animatable (bug 265690)
case CSSPropertyWebkitUserSelect:
// Not animatable per-spec:
case CSSPropertyAnimation:
case CSSPropertyAnimationComposition:
case CSSPropertyAnimationDelay:
case CSSPropertyAnimationDirection:
case CSSPropertyAnimationDuration:
case CSSPropertyAnimationFillMode:
case CSSPropertyAnimationIterationCount:
case CSSPropertyAnimationName:
case CSSPropertyAnimationPlayState:
case CSSPropertyAnimationRange:
case CSSPropertyAnimationRangeStart:
case CSSPropertyAnimationRangeEnd:
case CSSPropertyAnimationTimeline:
case CSSPropertyAnimationTimingFunction:
case CSSPropertyContain:
case CSSPropertyContainer:
case CSSPropertyContainerName:
case CSSPropertyContainerType:
case CSSPropertyDirection:
case CSSPropertyGlyphOrientationHorizontal:
case CSSPropertyGlyphOrientationVertical:
case CSSPropertyMathStyle:
case CSSPropertyScrollTimeline:
case CSSPropertyScrollTimelineAxis:
case CSSPropertyScrollTimelineName:
case CSSPropertySpeakAs:
case CSSPropertyTextCombineUpright:
case CSSPropertyTextOrientation:
case CSSPropertyTimelineScope:
case CSSPropertyTransition:
case CSSPropertyTransitionBehavior:
case CSSPropertyTransitionDelay:
case CSSPropertyTransitionDuration:
case CSSPropertyTransitionProperty:
case CSSPropertyTransitionTimingFunction:
case CSSPropertyUnicodeBidi:
case CSSPropertyViewTimelineAxis:
case CSSPropertyViewTimelineName:
case CSSPropertyWillChange:
case CSSPropertyWritingMode:
case CSSPropertyZoom:
// FIXME: This is a descriptor, not a CSS property:
case CSSPropertySize:
// Legacy -webkit- properties.
#if ENABLE(APPLE_PAY)
case CSSPropertyApplePayButtonStyle:
case CSSPropertyApplePayButtonType:
#endif
case CSSPropertyWebkitBackgroundClip:
case CSSPropertyWebkitBackgroundOrigin:
case CSSPropertyWebkitBorderImage:
case CSSPropertyWebkitBoxAlign:
case CSSPropertyWebkitBoxDirection:
case CSSPropertyWebkitBoxFlex:
case CSSPropertyWebkitBoxFlexGroup:
case CSSPropertyWebkitBoxLines:
case CSSPropertyWebkitBoxOrdinalGroup:
case CSSPropertyWebkitBoxOrient:
case CSSPropertyWebkitBoxPack:
case CSSPropertyWebkitBoxReflect:
case CSSPropertyWebkitColumnAxis:
case CSSPropertyWebkitColumnBreakAfter:
case CSSPropertyWebkitColumnBreakBefore:
case CSSPropertyWebkitColumnBreakInside:
case CSSPropertyWebkitColumnProgression:
#if ENABLE(CURSOR_VISIBILITY)
case CSSPropertyWebkitCursorVisibility:
#endif
case CSSPropertyWebkitFontSizeDelta:
case CSSPropertyWebkitFontSmoothing:
case CSSPropertyWebkitHyphenateLimitAfter:
case CSSPropertyWebkitHyphenateLimitBefore:
case CSSPropertyWebkitHyphenateLimitLines:
case CSSPropertyWebkitLineAlign:
case CSSPropertyWebkitLineBoxContain:
case CSSPropertyWebkitLineClamp:
case CSSPropertyWebkitLineGrid:
case CSSPropertyWebkitLineSnap:
case CSSPropertyWebkitLocale:
case CSSPropertyWebkitMarqueeDirection:
case CSSPropertyWebkitMarqueeIncrement:
case CSSPropertyWebkitMarqueeRepetition:
case CSSPropertyWebkitMarqueeSpeed:
case CSSPropertyWebkitMarqueeStyle:
case CSSPropertyWebkitMaskClip:
case CSSPropertyWebkitMaskComposite:
case CSSPropertyWebkitMaskSourceType:
case CSSPropertyWebkitNbspMode:
case CSSPropertyWebkitPerspective:
case CSSPropertyWebkitRubyPosition:
#if ENABLE(OVERFLOW_SCROLLING_TOUCH)
case CSSPropertyWebkitOverflowScrolling:
#endif
case CSSPropertyWebkitRtlOrdering:
#if ENABLE(TOUCH_EVENTS)
case CSSPropertyWebkitTapHighlightColor:
#endif
case CSSPropertyWebkitTextCombine:
case CSSPropertyWebkitTextDecoration:
case CSSPropertyWebkitTextDecorationsInEffect:
case CSSPropertyWebkitTextOrientation:
case CSSPropertyWebkitTextSecurity:
#if ENABLE(TEXT_AUTOSIZING)
case CSSPropertyInternalTextAutosizingStatus:
#endif
case CSSPropertyWebkitTextStroke:
case CSSPropertyWebkitTextStrokeWidth:
case CSSPropertyWebkitTextZoom:
#if PLATFORM(IOS_FAMILY)
case CSSPropertyWebkitTouchCallout:
#endif
case CSSPropertyWebkitUserDrag:
case CSSPropertyWebkitUserModify:
continue;
default:
if (CSSProperty::isDescriptorOnly(property))
continue;
auto resolvedProperty = CSSProperty::resolveDirectionAwareProperty(property, WritingMode());
ASSERT_UNUSED(resolvedProperty, wrapperForProperty(resolvedProperty));
break;
}
}
#endif
}
static void blendStandardProperty(const CSSPropertyBlendingClient& client, CSSPropertyID property, RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, double progress, CompositeOperation compositeOperation, IterationCompositeOperation iterationCompositeOperation, double currentIteration)
{
ASSERT(property != CSSPropertyInvalid && property != CSSPropertyCustom);
AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::singleton().wrapperForProperty(property);
if (wrapper) {
auto isDiscrete = !wrapper->canInterpolate(from, to, compositeOperation);
CSSPropertyBlendingContext context { progress, isDiscrete, compositeOperation, client, property, iterationCompositeOperation, currentIteration };
if (wrapper->normalizesProgressForDiscreteInterpolation())
context.normalizeProgress();
wrapper->blend(destination, from, to, context);
#if !LOG_DISABLED
wrapper->logBlend(from, to, destination, progress);
#endif
}
}
static CSSCustomPropertyValue::NumericSyntaxValue blendFunc(const CSSCustomPropertyValue::NumericSyntaxValue& from, const CSSCustomPropertyValue::NumericSyntaxValue& to, const CSSPropertyBlendingContext& blendingContext)
{
ASSERT(from.unitType == to.unitType);
return { blendFunc(from.value, to.value, blendingContext), from.unitType };
}
static std::optional<CSSCustomPropertyValue::SyntaxValue> blendSyntaxValues(const RenderStyle& fromStyle, const RenderStyle& toStyle, const CSSCustomPropertyValue::SyntaxValue& from, const CSSCustomPropertyValue::SyntaxValue& to, const CSSPropertyBlendingContext& blendingContext)
{
if (std::holds_alternative<Length>(from) && std::holds_alternative<Length>(to))
return blendFunc(std::get<Length>(from), std::get<Length>(to), blendingContext);
if (std::holds_alternative<Style::Color>(from) && std::holds_alternative<Style::Color>(to)) {
auto& fromStyleColor = std::get<Style::Color>(from);
auto& toStyleColor = std::get<Style::Color>(to);
if (!fromStyleColor.isCurrentColor() || !toStyleColor.isCurrentColor())
return blendFunc(fromStyle.colorResolvingCurrentColor(fromStyleColor), toStyle.colorResolvingCurrentColor(toStyleColor), blendingContext);
}
if (std::holds_alternative<CSSCustomPropertyValue::NumericSyntaxValue>(from) && std::holds_alternative<CSSCustomPropertyValue::NumericSyntaxValue>(to)) {
auto& fromNumeric = std::get<CSSCustomPropertyValue::NumericSyntaxValue>(from);
auto& toNumeric = std::get<CSSCustomPropertyValue::NumericSyntaxValue>(to);
if (fromNumeric.unitType == toNumeric.unitType)
return blendFunc(fromNumeric, toNumeric, blendingContext);
}
if (std::holds_alternative<CSSCustomPropertyValue::TransformSyntaxValue>(from) && std::holds_alternative<CSSCustomPropertyValue::TransformSyntaxValue>(to)) {
auto& fromTransformOperation = std::get<CSSCustomPropertyValue::TransformSyntaxValue>(from).transform;
auto& toTransformOperation = std::get<CSSCustomPropertyValue::TransformSyntaxValue>(to).transform;
return CSSCustomPropertyValue::TransformSyntaxValue { blendFunc(fromTransformOperation, toTransformOperation, blendingContext) };
}
return std::nullopt;
}
static std::optional<CSSCustomPropertyValue::SyntaxValue> firstValueInSyntaxValueLists(const CSSCustomPropertyValue::SyntaxValueList& a, const CSSCustomPropertyValue::SyntaxValueList& b)
{
if (!a.values.isEmpty())
return a.values[0];
if (!b.values.isEmpty())
return b.values[0];
return std::nullopt;
}
static std::optional<CSSCustomPropertyValue::SyntaxValueList> blendSyntaxValueLists(const RenderStyle& fromStyle, const RenderStyle& toStyle, const CSSCustomPropertyValue::SyntaxValueList& from, const CSSCustomPropertyValue::SyntaxValueList& to, const CSSPropertyBlendingContext& blendingContext)
{
// We should only attempt to blend lists containing the same types. Since we know all items in a
// list are of the same type, it is sufficient to check the first value from each list.
if (from.values.size() && to.values.size() && from.values.first().index() != to.values.first().index())
return std::nullopt;
// https://drafts.css-houdini.org/css-properties-values-api-1/#animation-behavior-of-custom-properties
auto firstValue = firstValueInSyntaxValueLists(from, to);
if (!firstValue)
return std::nullopt;
// <transform-function> lists are special in that they don't require matching numbers of items.
if (std::holds_alternative<CSSCustomPropertyValue::TransformSyntaxValue>(*firstValue)) {
auto transformOperationsFromSyntaxValueList = [](const CSSCustomPropertyValue::SyntaxValueList& list) {
return TransformOperations {
list.values.map([](auto& syntaxValue) {
ASSERT(std::holds_alternative<CSSCustomPropertyValue::TransformSyntaxValue>(syntaxValue));
return std::get<CSSCustomPropertyValue::TransformSyntaxValue>(syntaxValue).transform.copyRef();
})
};
};
auto fromTransformOperations = transformOperationsFromSyntaxValueList(from);
auto toTransformOperations = transformOperationsFromSyntaxValueList(to);
auto blendedTransformOperations = blendFunc(fromTransformOperations, toTransformOperations, blendingContext);
auto blendedSyntaxValues = WTF::map(blendedTransformOperations, [](auto& transformOperation) -> CSSCustomPropertyValue::SyntaxValue {
return CSSCustomPropertyValue::TransformSyntaxValue { transformOperation.copyRef() };
});
return CSSCustomPropertyValue::SyntaxValueList { WTFMove(blendedSyntaxValues), from.separator };
}
// Other lists must have matching sizes.
if (from.values.size() != to.values.size())
return std::nullopt;
Vector<CSSCustomPropertyValue::SyntaxValue> blendedSyntaxValues;
for (size_t i = 0; i < from.values.size(); ++i) {
auto blendedSyntaxValue = blendSyntaxValues(fromStyle, toStyle, from.values[i], to.values[i], blendingContext);
if (!blendedSyntaxValue)
return std::nullopt;
blendedSyntaxValues.append(*blendedSyntaxValue);
}
return CSSCustomPropertyValue::SyntaxValueList { blendedSyntaxValues, from.separator };
}
static Ref<const CSSCustomPropertyValue> blendedCSSCustomPropertyValue(const RenderStyle& fromStyle, const RenderStyle& toStyle, const CSSCustomPropertyValue& from, const CSSCustomPropertyValue& to, const CSSPropertyBlendingContext& blendingContext)
{
if (std::holds_alternative<CSSCustomPropertyValue::SyntaxValue>(from.value()) && std::holds_alternative<CSSCustomPropertyValue::SyntaxValue>(to.value())) {
auto& fromSyntaxValue = std::get<CSSCustomPropertyValue::SyntaxValue>(from.value());
auto& toSyntaxValue = std::get<CSSCustomPropertyValue::SyntaxValue>(to.value());
if (auto blendedSyntaxValue = blendSyntaxValues(fromStyle, toStyle, fromSyntaxValue, toSyntaxValue, blendingContext))
return CSSCustomPropertyValue::createForSyntaxValue(from.name(), WTFMove(*blendedSyntaxValue));
}
if (std::holds_alternative<CSSCustomPropertyValue::SyntaxValueList>(from.value()) && std::holds_alternative<CSSCustomPropertyValue::SyntaxValueList>(to.value())) {
auto& fromSyntaxValueList = std::get<CSSCustomPropertyValue::SyntaxValueList>(from.value());
auto& toSyntaxValueList = std::get<CSSCustomPropertyValue::SyntaxValueList>(to.value());
if (auto blendedSyntaxValueList = blendSyntaxValueLists(fromStyle, toStyle, fromSyntaxValueList, toSyntaxValueList, blendingContext))
return CSSCustomPropertyValue::createForSyntaxValueList(from.name(), WTFMove(*blendedSyntaxValueList));
}
// Use a discrete interpolation for all other cases.
return blendingContext.progress < 0.5 ? from : to;
}
static std::pair<const CSSCustomPropertyValue*, const CSSCustomPropertyValue*> customPropertyValuesForBlending(const AtomString& customProperty, const RenderStyle& fromStyle, const RenderStyle& toStyle)
{
return {
fromStyle.customPropertyValue(customProperty),
toStyle.customPropertyValue(customProperty)
};
}
static void blendCustomProperty(const CSSPropertyBlendingClient& client, const AtomString& customProperty, RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, double progress, CompositeOperation compositeOperation, IterationCompositeOperation iterationCompositeOperation, double currentIteration)
{
CSSPropertyBlendingContext blendingContext { progress, false, compositeOperation, client, customProperty, iterationCompositeOperation, currentIteration };
auto [fromValue, toValue] = customPropertyValuesForBlending(customProperty, from, to);
if (!fromValue || !toValue)
return;
bool isInherited = client.document()->customPropertyRegistry().isInherited(customProperty);
destination.setCustomPropertyValue(blendedCSSCustomPropertyValue(from, to, *fromValue, *toValue, blendingContext), isInherited);
}
void CSSPropertyAnimation::blendProperty(const CSSPropertyBlendingClient& client, const AnimatableCSSProperty& property, RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, double progress, CompositeOperation compositeOperation, IterationCompositeOperation iterationCompositeOperation, double currentIteration)
{
WTF::switchOn(property,
[&] (CSSPropertyID propertyId) {
blendStandardProperty(client, propertyId, destination, from, to, progress, compositeOperation, iterationCompositeOperation, currentIteration);
}, [&] (const AtomString& customProperty) {
blendCustomProperty(client, customProperty, destination, from, to, progress, compositeOperation, iterationCompositeOperation, currentIteration);
}
);
}
bool CSSPropertyAnimation::isPropertyAnimatable(const AnimatableCSSProperty& property)
{
return WTF::switchOn(property,
[] (CSSPropertyID propertyId) {
return propertyId == CSSPropertyCustom || !!CSSPropertyAnimationWrapperMap::singleton().wrapperForProperty(propertyId);
},
[] (const AtomString&) {
// FIXME: this should only be true for property that are registered custom properties.
return true;
}
);
}
bool CSSPropertyAnimation::isPropertyAdditiveOrCumulative(const AnimatableCSSProperty& property)
{
return WTF::switchOn(property,
[] (CSSPropertyID propertyId) {
if (auto* wrapper = CSSPropertyAnimationWrapperMap::singleton().wrapperForProperty(propertyId))
return wrapper->isAdditiveOrCumulative();
return false;
}, [] (const AtomString&) { return true; }
);
}
static bool syntaxValuesRequireBlendingForAccumulativeIteration(const CSSCustomPropertyValue::SyntaxValue& a, const CSSCustomPropertyValue::SyntaxValue& b, bool isList)
{
return WTF::switchOn(a, [b, isList](const Length& aLength) {
ASSERT(std::holds_alternative<Length>(b));
return !isList && lengthsRequireBlendingForAccumulativeIteration(aLength, std::get<Length>(b));
}, [] (const RefPtr<TransformOperation>&) {
return true;
}, [] (const Style::Color&) {
return true;
}, [] (auto&) {
return false;
});
}
bool CSSPropertyAnimation::propertyRequiresBlendingForAccumulativeIteration(const CSSPropertyBlendingClient&, const AnimatableCSSProperty& property, const RenderStyle& a, const RenderStyle& b)
{
return WTF::switchOn(property,
[&] (CSSPropertyID propertyId) {
if (auto* wrapper = CSSPropertyAnimationWrapperMap::singleton().wrapperForProperty(propertyId))
return wrapper->requiresBlendingForAccumulativeIteration(a, b);
return false;
}, [&] (const AtomString& customProperty) {
auto [from, to] = customPropertyValuesForBlending(customProperty, a, b);
if (!from || !to)
return false;
if (std::holds_alternative<CSSCustomPropertyValue::SyntaxValueList>(from->value()) && std::holds_alternative<CSSCustomPropertyValue::SyntaxValueList>(to->value())) {
auto& fromSyntaxValues = std::get<CSSCustomPropertyValue::SyntaxValueList>(from->value()).values;
auto& toSyntaxValues = std::get<CSSCustomPropertyValue::SyntaxValueList>(to->value()).values;
if (fromSyntaxValues.size() == toSyntaxValues.size()) {
for (size_t i = 0; i < fromSyntaxValues.size(); ++i) {
if (!syntaxValuesRequireBlendingForAccumulativeIteration(fromSyntaxValues[i], toSyntaxValues[i], true))
return false;
}
return true;
}
}
if (std::holds_alternative<CSSCustomPropertyValue::SyntaxValue>(from->value()) && std::holds_alternative<CSSCustomPropertyValue::SyntaxValue>(to->value())) {
auto& fromSyntaxValue = std::get<CSSCustomPropertyValue::SyntaxValue>(from->value());
auto& toSyntaxValue = std::get<CSSCustomPropertyValue::SyntaxValue>(to->value());
return syntaxValuesRequireBlendingForAccumulativeIteration(fromSyntaxValue, toSyntaxValue, false);
}
return false;
}
);
}
bool CSSPropertyAnimation::animationOfPropertyIsAccelerated(const AnimatableCSSProperty& property, const Settings& settings)
{
return WTF::switchOn(property,
[&] (CSSPropertyID cssProperty) {
if (auto* wrapper = CSSPropertyAnimationWrapperMap::singleton().wrapperForProperty(cssProperty))
return wrapper->animationIsAccelerated(settings);
return false;
}, [] (const AtomString&) { return false; }
);
}
bool CSSPropertyAnimation::propertiesEqual(const AnimatableCSSProperty& property, const RenderStyle& a, const RenderStyle& b, const Document&)
{
return WTF::switchOn(property,
[&] (CSSPropertyID propertyId) {
if (auto* wrapper = CSSPropertyAnimationWrapperMap::singleton().wrapperForProperty(propertyId))
return wrapper->equals(a, b);
return true;
}, [&] (const AtomString& customProperty) {
auto [aCustomPropertyValue, bCustomPropertyValue] = customPropertyValuesForBlending(customProperty, a, b);
if (aCustomPropertyValue && bCustomPropertyValue)
return aCustomPropertyValue->equals(*bCustomPropertyValue);
return !aCustomPropertyValue && !bCustomPropertyValue;
}
);
}
static bool typeOfSyntaxValueCanBeInterpolated(const CSSCustomPropertyValue::SyntaxValue& syntaxValue)
{
return WTF::switchOn(syntaxValue,
[] (const Length&) {
return true;
},
[] (const Style::Color&) {
return true;
},
[] (CSSCustomPropertyValue::NumericSyntaxValue) {
return true;
},
[] (const CSSCustomPropertyValue::TransformSyntaxValue&) {
return true;
},
[] (RefPtr<StyleImage>) {
return false;
},
[] (auto&) {
return false;
}
);
}
bool CSSPropertyAnimation::canPropertyBeInterpolated(const AnimatableCSSProperty& property, const RenderStyle& a, const RenderStyle& b, const Document&)
{
return WTF::switchOn(property,
[&] (CSSPropertyID propertyId) {
if (auto* wrapper = CSSPropertyAnimationWrapperMap::singleton().wrapperForProperty(propertyId))
return wrapper->canInterpolate(a, b, CompositeOperation::Replace);
return true;
}, [&] (const AtomString& customProperty) {
auto [aCustomPropertyValue, bCustomPropertyValue] = customPropertyValuesForBlending(customProperty, a, b);
if (!aCustomPropertyValue || !bCustomPropertyValue || aCustomPropertyValue == bCustomPropertyValue)
return false;
auto& aVariantValue = aCustomPropertyValue->value();
auto& bVariantValue = bCustomPropertyValue->value();
if (aVariantValue.index() != bVariantValue.index())
return false;
return WTF::switchOn(aVariantValue,
[bVariantValue] (const CSSCustomPropertyValue::SyntaxValueList& aValueList) {
auto bValueList = std::get<CSSCustomPropertyValue::SyntaxValueList>(bVariantValue);
if (aValueList == bValueList)
return false;
if (auto firstValue = firstValueInSyntaxValueLists(aValueList, bValueList)) {
// List sizes must match except for transform lists.
if (!std::holds_alternative<CSSCustomPropertyValue::TransformSyntaxValue>(*firstValue)
&& aValueList.values.size() != bValueList.values.size()) {
return false;
}
return typeOfSyntaxValueCanBeInterpolated(*firstValue);
}
return false;
},
[bVariantValue] (const CSSCustomPropertyValue::SyntaxValue& aSyntaxValue) {
auto bSyntaxValue = std::get<CSSCustomPropertyValue::SyntaxValue>(bVariantValue);
return aSyntaxValue != bSyntaxValue && typeOfSyntaxValueCanBeInterpolated(aSyntaxValue);
},
[] (auto&) {
return false;
}
);
}
);
}
CSSPropertyID CSSPropertyAnimation::getPropertyAtIndex(int i, std::optional<bool>& isShorthand)
{
CSSPropertyAnimationWrapperMap& map = CSSPropertyAnimationWrapperMap::singleton();
if (i < 0 || static_cast<unsigned>(i) >= map.size())
return CSSPropertyInvalid;
AnimationPropertyWrapperBase* wrapper = map.wrapperForIndex(i);
isShorthand = wrapper->isShorthandWrapper();
return wrapper->property();
}
std::optional<CSSPropertyID> CSSPropertyAnimation::getAcceleratedPropertyAtIndex(int i, const Settings& settings)
{
// FIXME: We really ought to expose an iterator to go over all animatable properties.
// https://bugs.webkit.org/show_bug.cgi?id=252807
auto& map = CSSPropertyAnimationWrapperMap::singleton();
if (i < 0 || static_cast<unsigned>(i) >= map.size())
return std::nullopt;
auto* wrapper = map.wrapperForIndex(i);
if (wrapper->isShorthandWrapper() || !wrapper->animationIsAccelerated(settings))
return std::nullopt;
return wrapper->property();
}
int CSSPropertyAnimation::getNumProperties()
{
return CSSPropertyAnimationWrapperMap::singleton().size();
}
}
|