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
|
/*
* Copyright (C) 1999 Antti Koivisto (koivisto@kde.org)
* Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights
* reserved.
* Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "third_party/blink/renderer/core/style/computed_style.h"
#include <algorithm>
#include <memory>
#include <utility>
#include "base/memory/values_equivalent.h"
#include "base/metrics/histogram_functions.h"
#include "base/numerics/clamped_math.h"
#include "build/build_config.h"
#include "cc/input/overscroll_behavior.h"
#include "cc/paint/paint_flags.h"
#include "third_party/blink/public/mojom/css/preferred_color_scheme.mojom-blink.h"
#include "third_party/blink/renderer/core/animation/css/css_animation_data.h"
#include "third_party/blink/renderer/core/animation/css/css_transition_data.h"
#include "third_party/blink/renderer/core/css/css_paint_value.h"
#include "third_party/blink/renderer/core/css/css_primitive_value.h"
#include "third_party/blink/renderer/core/css/css_property_equality.h"
#include "third_party/blink/renderer/core/css/css_property_names.h"
#include "third_party/blink/renderer/core/css/properties/computed_style_utils.h"
#include "third_party/blink/renderer/core/css/properties/css_property.h"
#include "third_party/blink/renderer/core/css/properties/css_unresolved_property.h"
#include "third_party/blink/renderer/core/css/properties/longhand.h"
#include "third_party/blink/renderer/core/css/properties/longhands.h"
#include "third_party/blink/renderer/core/css/resolver/style_resolver.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/pseudo_element.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/html/forms/html_legend_element.h"
#include "third_party/blink/renderer/core/html/html_body_element.h"
#include "third_party/blink/renderer/core/html/html_html_element.h"
#include "third_party/blink/renderer/core/html/html_li_element.h"
#include "third_party/blink/renderer/core/html/html_progress_element.h"
#include "third_party/blink/renderer/core/layout/custom/layout_worklet.h"
#include "third_party/blink/renderer/core/layout/layout_block.h"
#include "third_party/blink/renderer/core/layout/layout_box.h"
#include "third_party/blink/renderer/core/layout/layout_theme.h"
#include "third_party/blink/renderer/core/layout/map_coordinates_flags.h"
#include "third_party/blink/renderer/core/layout/text_autosizer.h"
#include "third_party/blink/renderer/core/paint/compositing/compositing_reason_finder.h"
#include "third_party/blink/renderer/core/style/applied_text_decoration.h"
#include "third_party/blink/renderer/core/style/basic_shapes.h"
#include "third_party/blink/renderer/core/style/computed_style_constants.h"
#include "third_party/blink/renderer/core/style/computed_style_initial_values.h"
#include "third_party/blink/renderer/core/style/content_data.h"
#include "third_party/blink/renderer/core/style/coord_box_offset_path_operation.h"
#include "third_party/blink/renderer/core/style/cursor_data.h"
#include "third_party/blink/renderer/core/style/gap_data.h"
#include "third_party/blink/renderer/core/style/reference_offset_path_operation.h"
#include "third_party/blink/renderer/core/style/shadow_list.h"
#include "third_party/blink/renderer/core/style/shape_offset_path_operation.h"
#include "third_party/blink/renderer/core/style/style_difference.h"
#include "third_party/blink/renderer/core/style/style_fetched_image.h"
#include "third_party/blink/renderer/core/style/style_generated_image.h"
#include "third_party/blink/renderer/core/style/style_image.h"
#include "third_party/blink/renderer/core/style/style_inherited_variables.h"
#include "third_party/blink/renderer/core/style/style_non_inherited_variables.h"
#include "third_party/blink/renderer/core/style/style_ray.h"
#include "third_party/blink/renderer/core/style/style_shape.h"
#include "third_party/blink/renderer/core/svg/svg_element.h"
#include "third_party/blink/renderer/core/svg/svg_geometry_element.h"
#include "third_party/blink/renderer/core/svg/svg_length_functions.h"
#include "third_party/blink/renderer/platform/fonts/font.h"
#include "third_party/blink/renderer/platform/fonts/font_selector.h"
#include "third_party/blink/renderer/platform/geometry/length_functions.h"
#include "third_party/blink/renderer/platform/geometry/path.h"
#include "third_party/blink/renderer/platform/geometry/path_builder.h"
#include "third_party/blink/renderer/platform/graphics/graphics_context.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/text/capitalize.h"
#include "third_party/blink/renderer/platform/text/character.h"
#include "third_party/blink/renderer/platform/text/quotes_data.h"
#include "third_party/blink/renderer/platform/transforms/rotate_transform_operation.h"
#include "third_party/blink/renderer/platform/transforms/scale_transform_operation.h"
#include "third_party/blink/renderer/platform/transforms/translate_transform_operation.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h"
#include "third_party/blink/renderer/platform/wtf/math_extras.h"
#include "third_party/blink/renderer/platform/wtf/size_assertions.h"
#include "third_party/blink/renderer/platform/wtf/text/case_map.h"
#include "third_party/blink/renderer/platform/wtf/text/math_transform.h"
#include "third_party/blink/renderer/platform/wtf/text/text_offset_map.h"
#include "third_party/blink/renderer/platform/wtf/thread_specific.h"
#include "ui/base/ui_base_features.h"
#include "ui/gfx/geometry/point_f.h"
namespace blink {
// Since different compilers/architectures pack ComputedStyle differently,
// re-create the same structure for an accurate size comparison.
//
// Keep a separate struct for ComputedStyleBase so that we can recreate the
// inheritance structure. Make sure the fields have the same access specifiers
// as in the "real" class since it can affect the layout. Reference the fields
// so that they are not seen as unused (-Wunused-private-field).
struct SameSizeAsComputedStyleBase
: public GarbageCollected<SameSizeAsComputedStyleBase> {
SameSizeAsComputedStyleBase() {
base::debug::Alias(&pointers);
base::debug::Alias(&bitfields);
}
private:
Member<void*> pointers[10];
unsigned bitfields[5];
};
struct SameSizeAsComputedStyle : public SameSizeAsComputedStyleBase {
SameSizeAsComputedStyle() { base::debug::Alias(&own_ptrs); }
private:
Member<void*> own_ptrs[1];
};
// If this assert fails, it means that size of ComputedStyle has changed. Please
// check that you really *do* want to increase the size of ComputedStyle, then
// update the SameSizeAsComputedStyle struct to match the updated storage of
// ComputedStyle.
ASSERT_SIZE(ComputedStyle, SameSizeAsComputedStyle);
StyleCachedData& ComputedStyle::EnsureCachedData() const {
if (!cached_data_) {
cached_data_ = MakeGarbageCollected<StyleCachedData>();
}
return *cached_data_;
}
bool ComputedStyle::HasCachedPseudoElementStyles() const {
return cached_data_ && cached_data_->pseudo_element_styles_ &&
cached_data_->pseudo_element_styles_->size();
}
PseudoElementStyleCache* ComputedStyle::GetPseudoElementStyleCache() const {
if (cached_data_) {
return cached_data_->pseudo_element_styles_.Get();
}
return nullptr;
}
PseudoElementStyleCache& ComputedStyle::EnsurePseudoElementStyleCache() const {
if (!cached_data_ || !cached_data_->pseudo_element_styles_) {
EnsureCachedData().pseudo_element_styles_ =
MakeGarbageCollected<PseudoElementStyleCache>();
}
return *cached_data_->pseudo_element_styles_;
}
const ComputedStyle* ComputedStyle::GetInitialStyleSingleton() {
DEFINE_THREAD_SAFE_STATIC_LOCAL(
ThreadSpecific<Persistent<const ComputedStyle>>,
thread_specific_initial_style, ());
Persistent<const ComputedStyle>& persistent = *thread_specific_initial_style;
if (!persistent) [[unlikely]] {
persistent = MakeGarbageCollected<ComputedStyle>(PassKey());
LEAK_SANITIZER_IGNORE_OBJECT(&persistent);
}
return persistent.Get();
}
namespace {
const ComputedStyle* BuildInitialStyleForImg(
const ComputedStyle& initial_style) {
// This matches the img {} declarations in html.css to avoid copy-on-write
// when only UA styles apply for these properties. See crbug.com/1369454
// for details.
ComputedStyleBuilder builder(initial_style);
builder.SetOverflowX(EOverflow::kClip);
builder.SetOverflowY(EOverflow::kClip);
builder.SetOverflowClipMargin(StyleOverflowClipMargin::CreateContent());
return builder.TakeStyle();
}
} // namespace
const ComputedStyle* ComputedStyle::GetInitialStyleForImgSingleton() {
DEFINE_THREAD_SAFE_STATIC_LOCAL(
ThreadSpecific<Persistent<const ComputedStyle>>,
thread_specific_initial_style, ());
Persistent<const ComputedStyle>& persistent = *thread_specific_initial_style;
if (!persistent) [[unlikely]] {
persistent = BuildInitialStyleForImg(*GetInitialStyleSingleton());
LEAK_SANITIZER_IGNORE_OBJECT(&persistent);
}
return persistent.Get();
}
Vector<AtomicString>* ComputedStyle::GetVariableNamesCache() const {
if (cached_data_) {
return cached_data_->variable_names_.get();
}
return nullptr;
}
Vector<AtomicString>& ComputedStyle::EnsureVariableNamesCache() const {
if (!cached_data_ || !cached_data_->variable_names_) {
EnsureCachedData().variable_names_ =
std::make_unique<Vector<AtomicString>>();
}
return *cached_data_->variable_names_;
}
ALWAYS_INLINE ComputedStyle::ComputedStyle() = default;
ALWAYS_INLINE ComputedStyle::ComputedStyle(const ComputedStyle& initial_style)
: ComputedStyleBase(initial_style) {}
ALWAYS_INLINE ComputedStyle::ComputedStyle(const ComputedStyleBuilder& builder)
: ComputedStyleBase(builder) {}
ALWAYS_INLINE ComputedStyle::ComputedStyle(PassKey key) : ComputedStyle() {}
ALWAYS_INLINE ComputedStyle::ComputedStyle(BuilderPassKey key,
const ComputedStyle& initial_style)
: ComputedStyle(initial_style) {}
ALWAYS_INLINE ComputedStyle::ComputedStyle(BuilderPassKey key,
const ComputedStyleBuilder& builder)
: ComputedStyle(builder) {}
static bool PseudoElementStylesEqual(const ComputedStyle& old_style,
const ComputedStyle& new_style) {
if (!old_style.HasAnyPseudoElementStyles() &&
!new_style.HasAnyPseudoElementStyles()) {
return true;
}
for (PseudoId pseudo_id = kFirstPublicPseudoId;
pseudo_id <= kLastTrackedPublicPseudoId;
pseudo_id = static_cast<PseudoId>(pseudo_id + 1)) {
if (!old_style.HasPseudoElementStyle(pseudo_id) &&
!new_style.HasPseudoElementStyle(pseudo_id)) {
continue;
}
// Highlight pseudo styles are stored in StyleHighlightData, and compared
// like any other inherited field, yielding Difference::kInherited.
if (UsesHighlightPseudoInheritance(pseudo_id)) {
continue;
}
const ComputedStyle* new_pseudo_style =
new_style.GetCachedPseudoElementStyle(pseudo_id);
if (!new_pseudo_style) {
return false;
}
const ComputedStyle* old_pseudo_style =
old_style.GetCachedPseudoElementStyle(pseudo_id);
if (old_pseudo_style && *old_pseudo_style != *new_pseudo_style) {
return false;
}
}
return true;
}
static bool DiffAffectsContainerQueries(const ComputedStyle& old_style,
const ComputedStyle& new_style) {
if (!old_style.IsContainerForSizeContainerQueries() &&
!new_style.IsContainerForSizeContainerQueries() &&
!old_style.IsContainerForScrollStateContainerQueries() &&
!new_style.IsContainerForScrollStateContainerQueries()) {
return false;
}
if (!base::ValuesEquivalent(old_style.ContainerName(),
new_style.ContainerName()) ||
(old_style.ContainerType() != new_style.ContainerType())) {
return true;
}
if (new_style.Display() != old_style.Display()) {
if (new_style.Display() == EDisplay::kNone ||
new_style.Display() == EDisplay::kContents) {
return true;
}
}
return false;
}
static bool DiffAffectsScrollAnimations(const ComputedStyle& old_style,
const ComputedStyle& new_style) {
if (!base::ValuesEquivalent(old_style.ScrollTimelineName(),
new_style.ScrollTimelineName()) ||
(old_style.ScrollTimelineAxis() != new_style.ScrollTimelineAxis())) {
return true;
}
if (!base::ValuesEquivalent(old_style.ViewTimelineName(),
new_style.ViewTimelineName()) ||
(old_style.ViewTimelineAxis() != new_style.ViewTimelineAxis()) ||
(old_style.ViewTimelineInset() != new_style.ViewTimelineInset())) {
return true;
}
if (!base::ValuesEquivalent(old_style.TimelineScope(),
new_style.TimelineScope())) {
return true;
}
return false;
}
bool ComputedStyle::NeedsReattachLayoutTree(const Element& element,
const ComputedStyle* old_style,
const ComputedStyle* new_style) {
if (old_style == new_style) {
return false;
}
if (!old_style || !new_style) {
return true;
}
if (old_style->Display() != new_style->Display()) {
return true;
}
if (old_style->HasPseudoElementStyle(kPseudoIdFirstLetter) !=
new_style->HasPseudoElementStyle(kPseudoIdFirstLetter)) {
return true;
}
if (!old_style->ContentDataEquivalent(*new_style)) {
return true;
}
if (old_style->HasTextCombine() != new_style->HasTextCombine()) {
return true;
}
if (!old_style->ScrollMarkerGroupEqual(*new_style)) {
return true;
}
// We need to perform a reattach if a "display: layout(foo)" has changed to a
// "display: layout(bar)". This is because one custom layout could be
// registered and the other may not, affecting the box-tree construction.
if (old_style->DisplayLayoutCustomName() !=
new_style->DisplayLayoutCustomName()) {
return true;
}
if (old_style->HasEffectiveAppearance() !=
new_style->HasEffectiveAppearance() &&
IsA<HTMLProgressElement>(element)) {
// HTMLProgressElement::CreateLayoutObject creates different LayoutObjects
// based on appearance.
return true;
}
// LayoutObject tree structure for <legend> depends on whether it's a
// rendered legend or not.
if (IsA<HTMLLegendElement>(element) &&
(old_style->IsFloating() != new_style->IsFloating() ||
old_style->HasOutOfFlowPosition() != new_style->HasOutOfFlowPosition()))
[[unlikely]] {
return true;
}
// We use LayoutTextCombine only for vertical writing mode.
if (new_style->HasTextCombine() && old_style->IsHorizontalWritingMode() !=
new_style->IsHorizontalWritingMode()) {
DCHECK_EQ(old_style->HasTextCombine(), new_style->HasTextCombine());
return true;
}
// LayoutNG needs an anonymous inline wrapper if ::first-line is applied.
// Also see |LayoutBlockFlow::NeedsAnonymousInlineWrapper()|.
if (new_style->HasPseudoElementStyle(kPseudoIdFirstLine) &&
!old_style->HasPseudoElementStyle(kPseudoIdFirstLine)) {
return true;
}
if (old_style->Overlay() != new_style->Overlay()) {
return true;
}
if (old_style->ListStylePosition() != new_style->ListStylePosition()) {
return true;
}
return false;
}
ComputedStyle::Difference ComputedStyle::ComputeDifference(
const ComputedStyle* old_style,
const ComputedStyle* new_style) {
if (old_style == new_style) {
return Difference::kEqual;
}
if (!old_style || !new_style) {
return Difference::kInherited;
}
// For inline elements, the new computed first line style will be |new_style|
// inheriting from the parent's first line style. If |new_style| is different
// from |old_style|'s cached inherited first line style, the new computed
// first line style may be different from the old even if |new_style| and
// |old_style| equal. Especially if the difference is on inherited properties,
// we need to propagate the difference to descendants.
// See external/wpt/css/css-pseudo/first-line-change-inline-color*.html.
auto inherited_first_line_style_diff = Difference::kEqual;
if (const ComputedStyle* cached_inherited_first_line_style =
old_style->GetCachedPseudoElementStyle(kPseudoIdFirstLineInherited)) {
DCHECK(
!new_style->GetCachedPseudoElementStyle(kPseudoIdFirstLineInherited));
inherited_first_line_style_diff =
ComputeDifferenceIgnoringInheritedFirstLineStyle(
*cached_inherited_first_line_style, *new_style);
}
return std::max(
inherited_first_line_style_diff,
ComputeDifferenceIgnoringInheritedFirstLineStyle(*old_style, *new_style));
}
ComputedStyle::Difference
ComputedStyle::ComputeDifferenceIgnoringInheritedFirstLineStyle(
const ComputedStyle& old_style,
const ComputedStyle& new_style) {
DCHECK_NE(&old_style, &new_style);
if (DiffAffectsScrollAnimations(old_style, new_style)) {
return Difference::kDescendantAffecting;
}
if (old_style.Display() != new_style.Display() &&
(old_style.BlockifiesChildren() != new_style.BlockifiesChildren() ||
old_style.InlinifiesChildren() != new_style.InlinifiesChildren())) {
return Difference::kDescendantAffecting;
}
if (old_style.ScrollMarkerGroupNone() != new_style.ScrollMarkerGroupNone()) {
return Difference::kDescendantAffecting;
}
// TODO(crbug.com/1213888): Only recalc affected descendants.
if (DiffAffectsContainerQueries(old_style, new_style)) {
return Difference::kDescendantAffecting;
}
if (!old_style.NonIndependentInheritedEqual(new_style)) {
return Difference::kInherited;
}
if (old_style.JustifyItems() != new_style.JustifyItems()) {
return Difference::kInherited;
}
if (old_style.AppliedTextDecorations() !=
new_style.AppliedTextDecorations()) {
return Difference::kInherited;
}
bool non_inherited_equal = old_style.NonInheritedEqual(new_style);
if (!non_inherited_equal && old_style.ChildHasExplicitInheritance()) {
return Difference::kInherited;
}
bool variables_independent =
!old_style.HasVariableReference() && !old_style.HasVariableDeclaration();
bool inherited_variables_equal = old_style.InheritedVariablesEqual(new_style);
if (!inherited_variables_equal && !variables_independent) {
return Difference::kInherited;
}
if (!old_style.IndependentInheritedEqual(new_style) ||
!inherited_variables_equal) {
return Difference::kIndependentInherited;
}
if (non_inherited_equal) {
DCHECK(old_style == new_style);
if (PseudoElementStylesEqual(old_style, new_style)) {
return Difference::kEqual;
}
return Difference::kPseudoElementStyle;
}
if (new_style.HasAnyPseudoElementStyles() ||
old_style.HasAnyPseudoElementStyles()) {
return Difference::kPseudoElementStyle;
}
if (old_style.Display() != new_style.Display() &&
(new_style.IsDisplayListItem() || old_style.IsDisplayListItem())) {
return Difference::kPseudoElementStyle;
}
return Difference::kNonInherited;
}
StyleSelfAlignmentData ResolvedSelfAlignment(
const StyleSelfAlignmentData& value,
const StyleSelfAlignmentData& normal_value_behavior,
bool has_out_of_flow_position) {
if (value.GetPosition() == ItemPosition::kLegacy ||
value.GetPosition() == ItemPosition::kNormal ||
value.GetPosition() == ItemPosition::kAuto) {
return normal_value_behavior;
}
if (!has_out_of_flow_position &&
value.GetPosition() == ItemPosition::kAnchorCenter) {
return {ItemPosition::kCenter, value.Overflow(), value.PositionType()};
}
return value;
}
StyleSelfAlignmentData ComputedStyle::ResolvedAlignSelf(
const StyleSelfAlignmentData& normal_value_behavior,
const ComputedStyle* parent_style) const {
// We will return the behaviour of 'normal' value if needed, which is specific
// of each layout model.
if (!parent_style || AlignSelf().GetPosition() != ItemPosition::kAuto) {
return ResolvedSelfAlignment(AlignSelf(), normal_value_behavior,
HasOutOfFlowPosition());
}
// The 'auto' keyword computes to the parent's align-items computed value.
return ResolvedSelfAlignment(parent_style->AlignItems(),
normal_value_behavior, HasOutOfFlowPosition());
}
StyleSelfAlignmentData ComputedStyle::ResolvedJustifySelf(
const StyleSelfAlignmentData& normal_value_behavior,
const ComputedStyle* parent_style) const {
// We will return the behaviour of 'normal' value if needed, which is specific
// of each layout model.
if (!parent_style || JustifySelf().GetPosition() != ItemPosition::kAuto) {
return ResolvedSelfAlignment(JustifySelf(), normal_value_behavior,
HasOutOfFlowPosition());
}
// The auto keyword computes to the parent's justify-items computed value.
return ResolvedSelfAlignment(parent_style->JustifyItems(),
normal_value_behavior, HasOutOfFlowPosition());
}
bool ComputedStyle::operator==(const ComputedStyle& o) const {
return InheritedEqual(o) && NonInheritedEqual(o) &&
InheritedVariablesEqual(o);
}
bool ComputedStyle::HighlightPseudoElementStylesDependOnRelativeUnits() const {
const StyleHighlightData& highlight_data = HighlightData();
if (highlight_data.Selection() &&
highlight_data.Selection()->HasAnyRelativeUnits()) {
return true;
}
if (highlight_data.TargetText() &&
highlight_data.TargetText()->HasAnyRelativeUnits()) {
return true;
}
if (highlight_data.SpellingError() &&
highlight_data.SpellingError()->HasAnyRelativeUnits()) {
return true;
}
if (highlight_data.GrammarError() &&
highlight_data.GrammarError()->HasAnyRelativeUnits()) {
return true;
}
const CustomHighlightsStyleMap& custom_highlights =
highlight_data.CustomHighlights();
for (auto custom_highlight : custom_highlights) {
if (custom_highlight.value->HasAnyRelativeUnits()) {
return true;
}
}
return false;
}
bool ComputedStyle::HighlightPseudoElementStylesDependOnContainerUnits() const {
const StyleHighlightData& highlight_data = HighlightData();
if (highlight_data.Selection() &&
highlight_data.Selection()->HasContainerRelativeValue()) {
return true;
}
if (highlight_data.TargetText() &&
highlight_data.TargetText()->HasContainerRelativeValue()) {
return true;
}
if (highlight_data.SpellingError() &&
highlight_data.SpellingError()->HasContainerRelativeValue()) {
return true;
}
if (highlight_data.GrammarError() &&
highlight_data.GrammarError()->HasContainerRelativeValue()) {
return true;
}
const CustomHighlightsStyleMap& custom_highlights =
highlight_data.CustomHighlights();
for (auto custom_highlight : custom_highlights) {
if (custom_highlight.value->HasContainerRelativeValue()) {
return true;
}
}
return false;
}
bool ComputedStyle::HighlightPseudoElementStylesDependOnViewportUnits() const {
const StyleHighlightData& highlight_data = HighlightData();
if (highlight_data.Selection() &&
highlight_data.Selection()->HasViewportUnits()) {
return true;
}
if (highlight_data.TargetText() &&
highlight_data.TargetText()->HasViewportUnits()) {
return true;
}
if (highlight_data.SpellingError() &&
highlight_data.SpellingError()->HasViewportUnits()) {
return true;
}
if (highlight_data.GrammarError() &&
highlight_data.GrammarError()->HasViewportUnits()) {
return true;
}
const CustomHighlightsStyleMap& custom_highlights =
highlight_data.CustomHighlights();
for (auto custom_highlight : custom_highlights) {
if (custom_highlight.value->HasViewportUnits()) {
return true;
}
}
return false;
}
bool ComputedStyle::HighlightPseudoElementStylesHaveVariableReferences() const {
const StyleHighlightData& highlight_data = HighlightData();
if (highlight_data.Selection() &&
highlight_data.Selection()->HasVariableReference()) {
return true;
}
if (highlight_data.TargetText() &&
highlight_data.TargetText()->HasVariableReference()) {
return true;
}
if (highlight_data.SpellingError() &&
highlight_data.SpellingError()->HasVariableReference()) {
return true;
}
if (highlight_data.GrammarError() &&
highlight_data.GrammarError()->HasVariableReference()) {
return true;
}
const CustomHighlightsStyleMap& custom_highlights =
highlight_data.CustomHighlights();
for (auto custom_highlight : custom_highlights) {
if (custom_highlight.value->HasVariableReference()) {
return true;
}
}
return false;
}
const ComputedStyle* ComputedStyle::GetCachedPseudoElementStyle(
PseudoId pseudo_id,
const AtomicString& pseudo_argument) const {
if (!HasCachedPseudoElementStyles()) {
return nullptr;
}
for (const auto& pseudo_style : *GetPseudoElementStyleCache()) {
if (pseudo_style->StyleType() == pseudo_id &&
(!PseudoElementHasArguments(pseudo_id) ||
pseudo_style->PseudoArgument() == pseudo_argument)) {
return pseudo_style.Get();
}
}
return nullptr;
}
const ComputedStyle* ComputedStyle::AddCachedPseudoElementStyle(
const ComputedStyle* pseudo,
PseudoId pseudo_id,
const AtomicString& pseudo_argument) const {
DCHECK(pseudo);
// Confirm that the styles being cached are for the (PseudoId,argument) that
// the caller intended (and presumably had checked was not present).
DCHECK_EQ(static_cast<unsigned>(pseudo->StyleType()),
static_cast<unsigned>(pseudo_id));
DCHECK_EQ(pseudo->PseudoArgument(), pseudo_argument);
// The pseudo style cache assumes that only one entry will be added for any
// any given (PseudoId,argument). Adding more than one entry is a bug, even
// if the styles being cached are equal.
DCHECK(!GetCachedPseudoElementStyle(pseudo->StyleType(),
pseudo->PseudoArgument()));
const ComputedStyle* result = pseudo;
EnsurePseudoElementStyleCache().push_back(std::move(pseudo));
return result;
}
const ComputedStyle* ComputedStyle::ReplaceCachedPseudoElementStyle(
const ComputedStyle* pseudo_style,
PseudoId pseudo_id,
const AtomicString& pseudo_argument) const {
DCHECK(pseudo_style->StyleType() != kPseudoIdNone &&
pseudo_style->StyleType() != kPseudoIdFirstLineInherited);
if (HasCachedPseudoElementStyles()) {
for (auto& cached_style : *GetPseudoElementStyleCache()) {
if (cached_style->StyleType() == pseudo_id &&
(!PseudoElementHasArguments(pseudo_id) ||
cached_style->PseudoArgument() == pseudo_argument)) {
SECURITY_CHECK(cached_style->IsEnsuredInDisplayNone());
cached_style = pseudo_style;
return pseudo_style;
}
}
}
return AddCachedPseudoElementStyle(pseudo_style, pseudo_id, pseudo_argument);
}
void ComputedStyle::ClearCachedPseudoElementStyles() const {
if (cached_data_ && cached_data_->pseudo_element_styles_) {
cached_data_->pseudo_element_styles_->clear();
}
}
const ComputedStyle* ComputedStyle::GetBaseComputedStyle() const {
if (StyleBaseData* base_data = BaseData()) {
return base_data->GetBaseComputedStyle();
}
return nullptr;
}
const CSSBitset* ComputedStyle::GetBaseImportantSet() const {
if (StyleBaseData* base_data = BaseData()) {
return base_data->GetBaseImportantSet();
}
return nullptr;
}
bool ComputedStyle::InheritedEqual(const ComputedStyle& other) const {
return IndependentInheritedEqual(other) &&
NonIndependentInheritedEqual(other);
}
bool ComputedStyle::IndependentInheritedEqual(
const ComputedStyle& other) const {
return ComputedStyleBase::IndependentInheritedEqual(other);
}
bool ComputedStyle::NonIndependentInheritedEqual(
const ComputedStyle& other) const {
return ComputedStyleBase::NonIndependentInheritedEqual(other);
}
bool ComputedStyle::NonInheritedEqual(const ComputedStyle& other) const {
// compare everything except the pseudoStyle pointer
return ComputedStyleBase::NonInheritedEqual(other);
}
bool ComputedStyle::InheritedDataShared(const ComputedStyle& other) const {
// We use a by-value check that is a bit more expensive than
// pointer comparison, but yields many more full MPC hits,
// so it generally makes up for it.
return ComputedStyleBase::InheritedDataShared(other);
}
StyleDifference ComputedStyle::VisualInvalidationDiff(
const Document& document,
const ComputedStyle& other) const {
StyleDifference diff;
uint64_t field_diff = FieldInvalidationDiff(*this, other);
if ((field_diff & kReshape) || ShouldWrapLine() != other.ShouldWrapLine()) {
diff.SetNeedsReshape();
diff.SetNeedsFullLayout();
diff.SetNeedsNormalPaintInvalidation();
}
if (IsStackingContextWithoutContainment() !=
other.IsStackingContextWithoutContainment()) {
diff.SetNeedsFullLayout();
diff.SetNeedsNormalPaintInvalidation();
diff.SetZIndexChanged();
}
if ((!diff.NeedsFullLayout() || !diff.NeedsNormalPaintInvalidation()) &&
DiffNeedsFullLayoutAndPaintInvalidation(other, field_diff)) {
diff.SetNeedsFullLayout();
diff.SetNeedsNormalPaintInvalidation();
}
if (!diff.NeedsFullLayout() &&
DiffNeedsFullLayout(document, other, field_diff)) {
diff.SetNeedsFullLayout();
}
if (!diff.NeedsLayout()) {
if ((field_diff & kOutOfFlow) && HasOutOfFlowPosition()) {
diff.SetNeedsPositionedMovementLayout();
} else if ((field_diff & kInset) && HasInFlowPosition()) {
diff.SetNeedsPositionedMovementLayout();
}
}
if (!diff.NeedsNormalPaintInvalidation() &&
DiffNeedsNormalPaintInvalidation(document, other, field_diff)) {
diff.SetNeedsNormalPaintInvalidation();
}
if (DiffNeedsRecomputeVisualOverflow(other, field_diff)) {
diff.SetNeedsRecomputeVisualOverflow();
}
if (DiffCompositingReasonsChanged(other, field_diff)) {
diff.SetCompositingReasonsChanged();
}
if (field_diff & kBackgroundColor) {
// If the background color change is not due to a composited animation,
// then paint invalidation is required; but we can defer the decision until
// we know whether the color change will be rendered by the compositor.
diff.SetBackgroundColorChanged();
}
if (field_diff & kBlendMode) {
diff.SetBlendModeChanged();
}
if (field_diff & kBorderRadius) {
diff.SetBorderRadiusChanged();
}
if (field_diff & kClip) {
bool has_clip = HasOutOfFlowPosition() && !HasAutoClip();
bool other_has_clip = other.HasOutOfFlowPosition() && !other.HasAutoClip();
if (has_clip != other_has_clip || (has_clip && Clip() != other.Clip())) {
diff.SetCSSClipChanged();
}
}
if (field_diff & kClipPath) {
diff.SetClipPathChanged();
}
if (field_diff & kColor) {
diff.SetTextDecorationOrColorChanged();
}
if (field_diff & kFilterData) {
diff.SetFilterChanged();
}
if (field_diff & kHasTransform) {
if (HasTransform() != other.HasTransform()) {
diff.SetOtherTransformPropertyChanged();
}
}
if (field_diff & kMask) {
diff.SetMaskChanged();
}
if (field_diff & kOpacity) {
diff.SetOpacityChanged();
}
if (field_diff & kScrollbarColor) {
if (UsedScrollbarColor() != other.UsedScrollbarColor()) {
diff.SetNeedsNormalPaintInvalidation();
}
}
if (field_diff & kScrollbarStyle) {
if (HasPseudoElementStyle(kPseudoIdScrollbar) !=
other.HasPseudoElementStyle(kPseudoIdScrollbar) ||
UsesStandardScrollbarStyle() != other.UsesStandardScrollbarStyle()) {
diff.SetNeedsFullLayout();
diff.SetNeedsNormalPaintInvalidation();
}
}
if (field_diff & kTextDecoration) {
diff.SetTextDecorationOrColorChanged();
}
if (field_diff & kTransformData) {
diff.SetTransformDataChanged();
}
if (field_diff & kTransformOther) {
diff.SetOtherTransformPropertyChanged();
}
if (field_diff & kTransformProperty) {
diff.SetTransformPropertyChanged();
}
if (field_diff & kVisibility) {
if ((Visibility() == EVisibility::kCollapse) !=
(other.Visibility() == EVisibility::kCollapse)) {
diff.SetNeedsFullLayout();
}
}
if (field_diff & kZIndex) {
diff.SetZIndexChanged();
}
// If the (current)color changes and a filter or backdrop-filter uses it, the
// filter or backdrop-filter needs to be updated. This reads
// `diff.TextDecorationOrColorChanged()` and so needs to be after the setters,
// above.
if (diff.TextDecorationOrColorChanged()) {
if (HasFilter() && Filter().UsesCurrentColor()) {
diff.SetFilterChanged();
}
if (HasBackdropFilter() && BackdropFilter().UsesCurrentColor()) {
// This could be optimized with a targeted backdrop-filter-changed
// invalidation.
diff.SetCompositingReasonsChanged();
}
}
// The following condition needs to be at last, because it may depend on
// conditions in diff computed above.
if ((field_diff & kScrollAnchor) || diff.TransformChanged()) {
diff.SetScrollAnchorDisablingPropertyChanged();
}
// Cursors are not checked, since they will be set appropriately in response
// to mouse events, so they don't need to cause any paint invalidation or
// layout.
// Animations don't need to be checked either. We always set the new style on
// the layoutObject, so we will get a chance to fire off the resulting
// transition properly.
return diff;
}
bool ComputedStyle::DiffNeedsFullLayoutAndPaintInvalidation(
const ComputedStyle& other,
uint64_t field_diff) const {
if (IsDisplayTableType(Display())) {
// In the collapsing border model, 'hidden' suppresses other borders, while
// 'none' does not, so these style differences can be width differences.
if ((BorderCollapse() == EBorderCollapse::kCollapse) &&
((BorderTopStyle() == EBorderStyle::kHidden &&
other.BorderTopStyle() == EBorderStyle::kNone) ||
(BorderTopStyle() == EBorderStyle::kNone &&
other.BorderTopStyle() == EBorderStyle::kHidden) ||
(BorderBottomStyle() == EBorderStyle::kHidden &&
other.BorderBottomStyle() == EBorderStyle::kNone) ||
(BorderBottomStyle() == EBorderStyle::kNone &&
other.BorderBottomStyle() == EBorderStyle::kHidden) ||
(BorderLeftStyle() == EBorderStyle::kHidden &&
other.BorderLeftStyle() == EBorderStyle::kNone) ||
(BorderLeftStyle() == EBorderStyle::kNone &&
other.BorderLeftStyle() == EBorderStyle::kHidden) ||
(BorderRightStyle() == EBorderStyle::kHidden &&
other.BorderRightStyle() == EBorderStyle::kNone) ||
(BorderRightStyle() == EBorderStyle::kNone &&
other.BorderRightStyle() == EBorderStyle::kHidden))) {
return true;
}
}
// Movement of non-static-positioned object is special cased in
// ComputedStyle::VisualInvalidationDiff().
return false;
}
bool ComputedStyle::DiffNeedsFullLayout(const Document& document,
const ComputedStyle& other,
uint64_t field_diff) const {
if (field_diff & kLayout) {
return true;
}
if (field_diff & kBorderWidth) {
if (BorderTopWidth() != other.BorderTopWidth() ||
BorderRightWidth() != other.BorderRightWidth() ||
BorderBottomWidth() != other.BorderBottomWidth() ||
BorderLeftWidth() != other.BorderLeftWidth()) {
return true;
}
}
if ((field_diff & kMargin) && !HasOutOfFlowPosition()) {
return true;
}
if (field_diff & kStroke) {
if (HasStroke() != other.HasStroke()) {
return true;
}
if (HasDashArray() != other.HasDashArray()) {
return true;
}
}
if (IsDisplayLayoutCustomBox() &&
DiffNeedsFullLayoutForLayoutCustom(document, other)) {
return true;
}
if (DisplayLayoutCustomParentName() &&
DiffNeedsFullLayoutForLayoutCustomChild(document, other)) {
return true;
}
if (field_diff & kGapDecorations) {
bool column_rule_style_changed_from_none =
ColumnRuleStyle() ==
ComputedStyleInitialValues::InitialColumnRuleStyle() &&
other.ColumnRuleStyle() !=
ComputedStyleInitialValues::InitialColumnRuleStyle();
bool row_rule_style_changed_from_none =
RowRuleStyle() == ComputedStyleInitialValues::InitialRowRuleStyle() &&
other.RowRuleStyle() !=
ComputedStyleInitialValues::InitialRowRuleStyle();
if (column_rule_style_changed_from_none ||
row_rule_style_changed_from_none) {
return true;
}
}
return false;
}
bool ComputedStyle::DiffNeedsFullLayoutForLayoutCustom(
const Document& document,
const ComputedStyle& other) const {
DCHECK(IsDisplayLayoutCustomBox());
LayoutWorklet* worklet = LayoutWorklet::From(*document.domWindow());
const AtomicString& name = DisplayLayoutCustomName();
if (!worklet->GetDocumentDefinitionMap()->Contains(name)) {
return false;
}
const DocumentLayoutDefinition* definition =
worklet->GetDocumentDefinitionMap()->at(name);
if (definition == kInvalidDocumentLayoutDefinition) {
return false;
}
if (!PropertiesEqual(definition->NativeInvalidationProperties(), other)) {
return true;
}
if (!CustomPropertiesEqual(definition->CustomInvalidationProperties(),
other)) {
return true;
}
return false;
}
bool ComputedStyle::DiffNeedsFullLayoutForLayoutCustomChild(
const Document& document,
const ComputedStyle& other) const {
LayoutWorklet* worklet = LayoutWorklet::From(*document.domWindow());
const AtomicString& name = DisplayLayoutCustomParentName();
if (!worklet->GetDocumentDefinitionMap()->Contains(name)) {
return false;
}
const DocumentLayoutDefinition* definition =
worklet->GetDocumentDefinitionMap()->at(name);
if (definition == kInvalidDocumentLayoutDefinition) {
return false;
}
if (!PropertiesEqual(definition->ChildNativeInvalidationProperties(),
other)) {
return true;
}
if (!CustomPropertiesEqual(definition->ChildCustomInvalidationProperties(),
other)) {
return true;
}
return false;
}
bool ComputedStyle::DiffNeedsNormalPaintInvalidation(
const Document& document,
const ComputedStyle& other,
uint64_t field_diff) const {
if (field_diff & kPaint) {
return true;
}
if ((field_diff & kAccentColor) &&
AccentColorResolved() != other.AccentColorResolved()) {
return true;
}
if ((field_diff & kOutline) && !OutlineVisuallyEqual(other)) {
return true;
}
if ((field_diff & kBackground) &&
!BackgroundInternal().VisuallyEqual(other.BackgroundInternal())) {
return true;
}
if (field_diff & kCurrentcolor) {
// If a property has a value that contains a <color> that depends on
// 'currentcolor', for example:
//
// background-image: linear-gradient(currentColor, #fff)
// background-color: color-mix(in srgb, currentcolor ...)
//
// If the (current)color has changed, we need to recompute it even though
// the old and new property values are identical.
//
// NOTE: This is also handled to some degree by
// LayoutObject::AdjustStyleDifference. We should probably re-distribute
// the responsibilities between these two locations.
if ((GetCurrentColor() != other.GetCurrentColor() ||
GetInternalVisitedCurrentColor() !=
other.GetInternalVisitedCurrentColor()) &&
HasPropertyDependingOnCurrentColor()) {
return true;
}
}
if ((field_diff & kBorderVisual) && !BorderVisuallyEqual(other)) {
return true;
}
if ((field_diff & kBorderOutlineVisitedColor) &&
BorderOutlineVisitedColorChanged(other)) {
return true;
}
if (PaintImagesInternal()) {
for (const auto& image : PaintImagesInternal()->Images()) {
DCHECK(image);
if (DiffNeedsPaintInvalidationForPaintImage(*image, other, document)) {
return true;
}
}
}
return false;
}
bool ComputedStyle::DiffNeedsPaintInvalidationForPaintImage(
const StyleImage& image,
const ComputedStyle& other,
const Document& document) const {
// https://crbug.com/835589: early exit when paint target is associated with
// a link.
if (InsideLink() != EInsideLink::kNotInsideLink) {
return false;
}
CSSPaintValue* value = To<CSSPaintValue>(image.CssValue());
// NOTE: If the invalidation properties vectors are null, we are invalid as
// we haven't yet been painted (and can't provide the invalidation
// properties yet).
if (!value->NativeInvalidationProperties(document) ||
!value->CustomInvalidationProperties(document)) {
return true;
}
if (!PropertiesEqual(*value->NativeInvalidationProperties(document), other)) {
return true;
}
if (!CustomPropertiesEqual(*value->CustomInvalidationProperties(document),
other)) {
return true;
}
return false;
}
bool ComputedStyle::PropertiesEqual(const Vector<CSSPropertyID>& properties,
const ComputedStyle& other) const {
for (CSSPropertyID property_id : properties) {
// TODO(ikilpatrick): remove IsInterpolableProperty check once
// CSSPropertyEquality::PropertiesEqual correctly handles all properties.
const CSSProperty& property = CSSProperty::Get(property_id);
if (!property.IsInterpolable() ||
!CSSPropertyEquality::PropertiesEqual(PropertyHandle(property), *this,
other)) {
return false;
}
}
return true;
}
bool ComputedStyle::CustomPropertiesEqual(
const Vector<AtomicString>& properties,
const ComputedStyle& other) const {
// Short-circuit if neither of the styles have custom properties.
if (!HasVariables() && !other.HasVariables()) {
return true;
}
for (const AtomicString& property_name : properties) {
if (!base::ValuesEquivalent(GetVariableData(property_name),
other.GetVariableData(property_name))) {
return false;
}
if (!base::ValuesEquivalent(GetVariableValue(property_name),
other.GetVariableValue(property_name))) {
return false;
}
}
return true;
}
bool ComputedStyle::PotentialCompositingReasonsFor3DTransformChanged(
const ComputedStyle& other) const {
// Compositing reasons for 3D transforms depend on the LayoutObject type (see:
// |LayoutObject::HasTransformRelatedProperty|)) This will return true for
// some LayoutObjects that end up not supporting transforms.
return CompositingReasonFinder::PotentialCompositingReasonsFor3DTransform(
*this) !=
CompositingReasonFinder::PotentialCompositingReasonsFor3DTransform(
other);
}
bool ComputedStyle::DiffNeedsRecomputeVisualOverflow(
const ComputedStyle& other,
uint64_t field_diff) const {
if (field_diff & kVisualOverflow) {
return true;
}
if ((field_diff & kBorderImage) && !BorderVisualOverflowEqual(other)) {
return true;
}
if ((field_diff & kOutline) && !OutlineVisuallyEqual(other)) {
return true;
}
if ((field_diff & kTextDecoration) &&
TextDecorationVisualOverflowChanged(other)) {
return true;
}
return false;
}
bool ComputedStyle::DiffCompositingReasonsChanged(const ComputedStyle& other,
uint64_t field_diff) const {
if (field_diff & kCompositing) {
return true;
}
if (UsedTransformStyle3D() != other.UsedTransformStyle3D()) {
return true;
}
if (ContainsPaint() != other.ContainsPaint()) {
return true;
}
if (IsOverflowVisibleAlongBothAxes() !=
other.IsOverflowVisibleAlongBothAxes()) {
return true;
}
if (PotentialCompositingReasonsFor3DTransformChanged(other)) {
return true;
}
return false;
}
bool ComputedStyle::HasCSSPaintImagesUsingCustomProperty(
const AtomicString& custom_property_name,
const Document& document) const {
if (PaintImagesInternal()) {
for (const auto& image : PaintImagesInternal()->Images()) {
DCHECK(image);
// IsPaintImage is true for CSS Paint images only, please refer to the
// constructor of StyleGeneratedImage.
if (image->IsPaintImage()) {
return To<StyleGeneratedImage>(image.Get())
->IsUsingCustomProperty(custom_property_name, document);
}
}
}
return false;
}
static bool HasPropertyThatCreatesStackingContext(
const Vector<CSSPropertyID>& properties) {
for (CSSPropertyID property : properties) {
switch (ResolveCSSPropertyID(property)) {
case CSSPropertyID::kOpacity:
case CSSPropertyID::kTransform:
case CSSPropertyID::kTransformStyle:
case CSSPropertyID::kPerspective:
case CSSPropertyID::kTranslate:
case CSSPropertyID::kRotate:
case CSSPropertyID::kScale:
case CSSPropertyID::kOffsetPath:
case CSSPropertyID::kOffsetPosition:
case CSSPropertyID::kMask: // Matches longhand.
case CSSPropertyID::kMaskImage:
case CSSPropertyID::kWebkitMaskBoxImage: // Matches longhand
case CSSPropertyID::kWebkitMaskBoxImageSource:
case CSSPropertyID::kClipPath:
case CSSPropertyID::kWebkitBoxReflect:
case CSSPropertyID::kFilter:
case CSSPropertyID::kBackdropFilter:
case CSSPropertyID::kZIndex:
case CSSPropertyID::kPosition:
case CSSPropertyID::kMixBlendMode:
case CSSPropertyID::kIsolation:
case CSSPropertyID::kContain:
case CSSPropertyID::kViewTransitionName:
return true;
default:
break;
}
}
return false;
}
static bool IsWillChangeTransformHintProperty(CSSPropertyID property) {
switch (ResolveCSSPropertyID(property)) {
case CSSPropertyID::kTransform:
case CSSPropertyID::kPerspective:
case CSSPropertyID::kTransformStyle:
return true;
default:
break;
}
return false;
}
static bool IsWillChangeHintForAnyTransformProperty(CSSPropertyID property) {
switch (ResolveCSSPropertyID(property)) {
case CSSPropertyID::kTransform:
case CSSPropertyID::kPerspective:
case CSSPropertyID::kTranslate:
case CSSPropertyID::kScale:
case CSSPropertyID::kRotate:
case CSSPropertyID::kOffsetPath:
case CSSPropertyID::kOffsetPosition:
case CSSPropertyID::kTransformStyle:
return true;
default:
break;
}
return false;
}
static bool IsWillChangeCompositingHintProperty(CSSPropertyID property) {
if (IsWillChangeHintForAnyTransformProperty(property)) {
return true;
}
switch (ResolveCSSPropertyID(property)) {
case CSSPropertyID::kOpacity:
case CSSPropertyID::kFilter:
case CSSPropertyID::kBackdropFilter:
case CSSPropertyID::kTop:
case CSSPropertyID::kLeft:
case CSSPropertyID::kBottom:
case CSSPropertyID::kRight:
return true;
default:
break;
}
return false;
}
bool ComputedStyle::HasWillChangeCompositingHint() const {
return std::ranges::any_of(WillChangeProperties(),
IsWillChangeCompositingHintProperty);
}
bool ComputedStyle::HasWillChangeTransformHint() const {
return std::ranges::any_of(WillChangeProperties(),
IsWillChangeTransformHintProperty);
}
bool ComputedStyle::HasWillChangeHintForAnyTransformProperty() const {
return std::ranges::any_of(WillChangeProperties(),
IsWillChangeHintForAnyTransformProperty);
}
bool ComputedStyle::RequireTransformOrigin(
ApplyTransformOrigin apply_origin,
ApplyMotionPath apply_motion_path) const {
// transform-origin brackets the transform with translate operations.
// Optimize for the case where the only transform is a translation, since the
// transform-origin is irrelevant in that case.
if (apply_origin != kIncludeTransformOrigin) {
return false;
}
if (apply_motion_path == kIncludeMotionPath) {
return true;
}
for (const auto& operation : Transform().Operations()) {
TransformOperation::OperationType type = operation->GetType();
if (type != TransformOperation::kTranslateX &&
type != TransformOperation::kTranslateY &&
type != TransformOperation::kTranslate &&
type != TransformOperation::kTranslateZ &&
type != TransformOperation::kTranslate3D) {
return true;
}
}
return Scale() || Rotate();
}
InterpolationQuality ComputedStyle::GetInterpolationQuality() const {
if (ImageRendering() == EImageRendering::kPixelated) {
return kInterpolationNone;
}
if (ImageRendering() == EImageRendering::kWebkitOptimizeContrast) {
return kInterpolationLow;
}
return GetDefaultInterpolationQuality();
}
void ComputedStyle::LoadDeferredImages(Document& document) const {
if (HasBackgroundImage()) {
for (const FillLayer* background_layer = &BackgroundLayers();
background_layer; background_layer = background_layer->Next()) {
if (StyleImage* image = background_layer->GetImage()) {
if (image->IsImageResource() && image->IsLazyloadPossiblyDeferred()) {
To<StyleFetchedImage>(image)->LoadDeferredImage(document);
}
}
}
}
}
ETransformBox ComputedStyle::UsedTransformBox(
TransformBoxContext box_context) const {
ETransformBox transform_box = TransformBox();
if (box_context == TransformBoxContext::kSvg) {
// For SVG elements without associated CSS layout box, the used value for
// content-box is fill-box and for border-box is stroke-box.
switch (transform_box) {
case ETransformBox::kContentBox:
transform_box = ETransformBox::kFillBox;
break;
case ETransformBox::kBorderBox:
transform_box = ETransformBox::kStrokeBox;
break;
case ETransformBox::kFillBox:
case ETransformBox::kStrokeBox:
case ETransformBox::kViewBox:
break;
}
// If transform-box is stroke-box and the element has "vector-effect:
// non-scaling-stroke", then the used transform-box is fill-box.
if (transform_box == ETransformBox::kStrokeBox &&
VectorEffect() == EVectorEffect::kNonScalingStroke) {
transform_box = ETransformBox::kFillBox;
}
} else {
// For elements with associated CSS layout box, the used value for fill-box
// is content-box and for stroke-box and view-box is border-box.
switch (transform_box) {
case ETransformBox::kContentBox:
case ETransformBox::kBorderBox:
break;
case ETransformBox::kFillBox:
transform_box = ETransformBox::kContentBox;
break;
case ETransformBox::kStrokeBox:
case ETransformBox::kViewBox:
transform_box = ETransformBox::kBorderBox;
break;
}
}
return transform_box;
}
void ComputedStyle::ApplyTransform(
gfx::Transform& result,
const LayoutBox* box,
const PhysicalRect& reference_box,
ApplyTransformOperations apply_operations,
ApplyTransformOrigin apply_origin,
ApplyMotionPath apply_motion_path,
ApplyIndependentTransformProperties apply_independent_transform_properties)
const {
ApplyTransform(result, box, gfx::RectF(reference_box), apply_operations,
apply_origin, apply_motion_path,
apply_independent_transform_properties);
}
void ComputedStyle::ApplyTransform(
gfx::Transform& result,
const LayoutBox* box,
const gfx::RectF& bounding_box,
ApplyTransformOperations apply_operations,
ApplyTransformOrigin apply_origin,
ApplyMotionPath apply_motion_path,
ApplyIndependentTransformProperties apply_independent_transform_properties)
const {
if (!HasOffset()) {
apply_motion_path = kExcludeMotionPath;
}
bool apply_transform_origin =
RequireTransformOrigin(apply_origin, apply_motion_path);
float origin_x = 0;
float origin_y = 0;
float origin_z = 0;
const gfx::SizeF& box_size = bounding_box.size();
if (apply_transform_origin ||
// We need to calculate originX and originY for applying motion path.
apply_motion_path == kIncludeMotionPath) {
origin_x = FloatValueForLength(GetTransformOrigin().X(), box_size.width()) +
bounding_box.x();
origin_y =
FloatValueForLength(GetTransformOrigin().Y(), box_size.height()) +
bounding_box.y();
if (apply_transform_origin) {
origin_z = GetTransformOrigin().Z();
result.Translate3d(origin_x, origin_y, origin_z);
}
}
if (apply_independent_transform_properties ==
kIncludeIndependentTransformProperties) {
if (Translate()) {
Translate()->Apply(result, box_size);
}
if (Rotate()) {
Rotate()->Apply(result, box_size);
}
if (Scale()) {
Scale()->Apply(result, box_size);
}
}
if (apply_motion_path == kIncludeMotionPath) {
ApplyMotionPathTransform(origin_x, origin_y, box, bounding_box, result);
}
if (apply_operations == kIncludeTransformOperations) {
for (const auto& operation : Transform().Operations()) {
operation->Apply(result, box_size);
}
}
if (apply_transform_origin) {
result.Translate3d(-origin_x, -origin_y, -origin_z);
}
}
namespace {
gfx::RectF GetReferenceBox(const LayoutBox* box, CoordBox coord_box) {
if (box) {
if (const LayoutBlock* containing_block = box->ContainingBlock()) {
// In SVG contexts, all values behave as view-box.
if (box->IsSVG()) {
return gfx::RectF(SVGViewportResolver(*box).ResolveViewport());
}
// https://drafts.csswg.org/css-box-4/#typedef-coord-box
switch (coord_box) {
case CoordBox::kFillBox:
case CoordBox::kContentBox:
return gfx::RectF(containing_block->PhysicalContentBoxRect());
case CoordBox::kPaddingBox:
return gfx::RectF(containing_block->PhysicalPaddingBoxRect());
case CoordBox::kViewBox:
case CoordBox::kStrokeBox:
case CoordBox::kBorderBox:
return gfx::RectF(containing_block->PhysicalBorderBoxRect());
}
}
}
// As the motion path calculations can be called before all the layout
// has been correctly calculated, we can end up here.
return gfx::RectF();
}
gfx::PointF GetOffsetFromContainingBlock(const LayoutBox* box) {
if (box) {
if (const LayoutBlock* containing_block = box->ContainingBlock()) {
gfx::PointF offset = box->LocalToAncestorPoint(
gfx::PointF(), containing_block, kIgnoreTransforms);
return offset;
}
}
return {0, 0};
}
// https://drafts.fxtf.org/motion/#offset-position-property
gfx::PointF GetStartingPointOfThePath(
const gfx::PointF& offset_from_reference_box,
const LengthPoint& offset_position,
const gfx::SizeF& reference_box_size) {
if (offset_position.X().IsAuto()) {
return offset_from_reference_box;
}
if (offset_position.X().IsNone()) {
// Currently all the use cases will behave as "at center".
return PointForLengthPoint(
LengthPoint(Length::Percent(50), Length::Percent(50)),
reference_box_size);
}
return PointForLengthPoint(offset_position, reference_box_size);
}
} // namespace
PointAndTangent ComputedStyle::CalculatePointAndTangentOnBasicShape(
const BasicShape& shape,
const gfx::PointF& starting_point,
const gfx::SizeF& reference_box_size) const {
Path path;
if (const auto* circle_or_ellipse =
DynamicTo<BasicShapeWithCenterAndRadii>(shape);
circle_or_ellipse && !circle_or_ellipse->HasExplicitCenter()) {
// For all <basic-shape>s, if they accept an at <position> argument
// but that argument is omitted, and the element defines
// an offset starting position via offset-position,
// it uses the specified offset starting position for that argument.
path = circle_or_ellipse->GetPathFromCenter(
starting_point, gfx::RectF(reference_box_size), /*path_scale=*/1.f);
} else {
path = shape.GetPath(gfx::RectF(reference_box_size), EffectiveZoom(),
/*path_scale=*/1.f);
}
float shape_length = path.length();
float path_length = FloatValueForLength(OffsetDistance(), shape_length);
// All the shapes are closed at this point.
if (shape_length > 0) {
path_length = fmod(path_length, shape_length);
if (path_length < 0) {
path_length += shape_length;
}
}
return path.PointAndNormalAtLength(path_length);
}
PointAndTangent ComputedStyle::CalculatePointAndTangentOnRay(
const StyleRay& ray,
const LayoutBox* box,
const gfx::PointF& starting_point,
const gfx::SizeF& reference_box_size) const {
float ray_length =
ray.CalculateRayPathLength(starting_point, reference_box_size);
if (ray.Contain() && box) {
// The length of the offset path is reduced so that the element stays
// within the containing block even at offset-distance: 100%.
// Specifically, the path’s length is reduced by half the width
// or half the height of the element’s border box,
// whichever is larger, and floored at zero.
const PhysicalRect border_box_rect = box->PhysicalBorderBoxRect();
const float largest_side = std::max(border_box_rect.Width().ToFloat(),
border_box_rect.Height().ToFloat());
ray_length -= largest_side / 2;
ray_length = std::max(ray_length, 0.f);
}
const float path_length = FloatValueForLength(OffsetDistance(), ray_length);
return ray.PointAndNormalAtLength(starting_point, path_length);
}
PointAndTangent ComputedStyle::CalculatePointAndTangentOnPath(
const Path& path) const {
float zoom = EffectiveZoom();
float path_length = path.length();
float float_distance =
FloatValueForLength(OffsetDistance(), path_length * zoom) / zoom;
float computed_distance;
if (path.IsClosed() && path_length > 0) {
computed_distance = fmod(float_distance, path_length);
if (computed_distance < 0) {
computed_distance += path_length;
}
} else {
computed_distance = ClampTo<float>(float_distance, 0, path_length);
}
PointAndTangent path_position =
path.PointAndNormalAtLength(computed_distance);
path_position.point.Scale(zoom, zoom);
return path_position;
}
void ComputedStyle::ApplyMotionPathTransform(float origin_x,
float origin_y,
const LayoutBox* box,
const gfx::RectF& bounding_box,
gfx::Transform& transform) const {
const OffsetPathOperation* offset_path = OffsetPath();
if (!offset_path) {
return;
}
const LengthPoint& position = OffsetPosition();
const StyleOffsetRotation& rotate = OffsetRotate();
CoordBox coord_box = offset_path->GetCoordBox();
PointAndTangent path_position;
if (const auto* shape_operation =
DynamicTo<ShapeOffsetPathOperation>(offset_path)) {
const BasicShape& basic_shape = shape_operation->GetBasicShape();
switch (basic_shape.GetType()) {
case BasicShape::kStylePathType: {
const StylePath& path = To<StylePath>(basic_shape);
path_position = CalculatePointAndTangentOnPath(path.GetPath());
break;
}
case BasicShape::kStyleRayType: {
const gfx::RectF reference_box = GetReferenceBox(box, coord_box);
const gfx::PointF offset_from_reference_box =
GetOffsetFromContainingBlock(box) -
reference_box.OffsetFromOrigin();
const gfx::SizeF& reference_box_size = reference_box.size();
const StyleRay& ray = To<StyleRay>(basic_shape);
// Specifies the origin of the ray, where the ray’s line begins (the 0%
// position). It’s resolved by using the <position> to position a 0x0
// object area within the box’s containing block. If omitted, it uses
// the offset starting position of the element, given by
// offset-position. If the element doesn’t have an offset starting
// position either, it behaves as at center.
// NOTE: In current parsing implementation:
// if `at position` is omitted, it will be computed as 50% 50%.
gfx::PointF starting_point;
if (ray.HasExplicitCenter() || position.X().IsNone()) {
starting_point = PointForCenterCoordinate(
ray.CenterX(), ray.CenterY(), reference_box_size);
} else {
starting_point = GetStartingPointOfThePath(
offset_from_reference_box, position, reference_box_size);
}
path_position = CalculatePointAndTangentOnRay(ray, box, starting_point,
reference_box_size);
// `path_position.point` is now relative to the containing block.
// Make it relative to the box.
path_position.point -= offset_from_reference_box.OffsetFromOrigin();
break;
}
case BasicShape::kBasicShapeCircleType:
case BasicShape::kBasicShapeEllipseType:
case BasicShape::kBasicShapeInsetType:
case BasicShape::kBasicShapePolygonType:
case BasicShape::kStyleShapeType: {
const gfx::RectF reference_box = GetReferenceBox(box, coord_box);
const gfx::PointF offset_from_reference_box =
GetOffsetFromContainingBlock(box) -
reference_box.OffsetFromOrigin();
const gfx::SizeF& reference_box_size = reference_box.size();
const gfx::PointF starting_point = GetStartingPointOfThePath(
offset_from_reference_box, position, reference_box_size);
path_position = CalculatePointAndTangentOnBasicShape(
basic_shape, starting_point, reference_box_size);
// `path_position.point` is now relative to the containing block.
// Make it relative to the box.
path_position.point -= offset_from_reference_box.OffsetFromOrigin();
break;
}
}
} else if (IsA<CoordBoxOffsetPathOperation>(offset_path)) {
if (box && box->ContainingBlock()) {
BasicShapeInset* inset = MakeGarbageCollected<BasicShapeInset>();
inset->SetTop(Length::Fixed(0));
inset->SetBottom(Length::Fixed(0));
inset->SetLeft(Length::Fixed(0));
inset->SetRight(Length::Fixed(0));
const ComputedStyle& style = box->ContainingBlock()->StyleRef();
inset->SetTopLeftRadius(style.BorderTopLeftRadius());
inset->SetTopRightRadius(style.BorderTopRightRadius());
inset->SetBottomRightRadius(style.BorderBottomRightRadius());
inset->SetBottomLeftRadius(style.BorderBottomLeftRadius());
const gfx::RectF reference_box = GetReferenceBox(box, coord_box);
const gfx::PointF offset_from_reference_box =
GetOffsetFromContainingBlock(box) - reference_box.OffsetFromOrigin();
const gfx::SizeF& reference_box_size = reference_box.size();
const gfx::PointF starting_point = GetStartingPointOfThePath(
offset_from_reference_box, position, reference_box_size);
path_position = CalculatePointAndTangentOnBasicShape(
*inset, starting_point, reference_box_size);
// `path_position.point` is now relative to the containing block.
// Make it relative to the box.
path_position.point -= offset_from_reference_box.OffsetFromOrigin();
}
} else {
const auto* url_operation =
DynamicTo<ReferenceOffsetPathOperation>(offset_path);
if (!url_operation->Resource()) {
return;
}
const auto* target =
DynamicTo<SVGGeometryElement>(url_operation->Resource()->Target());
Path path;
if (!target || !target->GetComputedStyle()) {
// Failure to find a shape should be equivalent to a "m0,0" path.
path = PathBuilder().MoveTo({0, 0}).Finalize();
} else {
path = target->AsPath();
}
path_position = CalculatePointAndTangentOnPath(path);
}
if (rotate.type == OffsetRotationType::kFixed) {
path_position.tangent_in_degrees = 0;
}
transform.Translate(path_position.point.x() - origin_x,
path_position.point.y() - origin_y);
transform.Rotate(path_position.tangent_in_degrees + rotate.angle);
const LengthPoint& anchor = OffsetAnchor();
if (!anchor.X().IsAuto()) {
gfx::PointF anchor_point = PointForLengthPoint(anchor, bounding_box.size());
anchor_point += bounding_box.OffsetFromOrigin();
// Shift the origin back to transform-origin and then move it based on the
// anchor.
transform.Translate(origin_x - anchor_point.x(),
origin_y - anchor_point.y());
}
}
bool ComputedStyle::CanRenderBorderImage() const {
const StyleImage* border_image = BorderImage().GetImage();
return border_image && border_image->CanRender() && border_image->IsLoaded();
}
const CounterDirectiveMap* ComputedStyle::GetCounterDirectives() const {
return CounterDirectivesInternal().get();
}
const CounterDirectives ComputedStyle::GetCounterDirectives(
const AtomicString& identifier) const {
if (GetCounterDirectives()) {
auto it = GetCounterDirectives()->find(identifier);
if (it != GetCounterDirectives()->end()) {
return it->value;
}
}
return CounterDirectives();
}
Hyphenation* ComputedStyle::GetHyphenation() const {
if (GetHyphens() != Hyphens::kAuto) {
return nullptr;
}
if (const LayoutLocale* locale = GetFontDescription().Locale()) {
return locale->GetHyphenation();
}
return nullptr;
}
Hyphenation* ComputedStyle::GetHyphenationWithLimits() const {
if (Hyphenation* hyphenation = GetHyphenation()) {
const StyleHyphenateLimitChars& limits = HyphenateLimitChars();
hyphenation->SetLimits(limits.MinBeforeChars(), limits.MinAfterChars(),
limits.MinWordChars());
return hyphenation;
}
return nullptr;
}
const AtomicString& ComputedStyle::HyphenString() const {
const AtomicString& hyphenation_string = HyphenationString();
if (!hyphenation_string.IsNull()) {
return hyphenation_string;
}
// FIXME: This should depend on locale.
DEFINE_STATIC_LOCAL(AtomicString, hyphen_minus_string,
(base::span_from_ref(kHyphenMinusCharacter)));
DEFINE_STATIC_LOCAL(AtomicString, hyphen_string,
(base::span_from_ref(kHyphenCharacter)));
const SimpleFontData* primary_font = GetFont()->PrimaryFont();
DCHECK(primary_font);
return primary_font && primary_font->GlyphForCharacter(kHyphenCharacter)
? hyphen_string
: hyphen_minus_string;
}
ETextAlign ComputedStyle::GetTextAlign(bool is_last_line) const {
if (!is_last_line) {
return GetTextAlign();
}
// When this is the last line of a block, or the line ends with a forced line
// break.
// https://drafts.csswg.org/css-text-3/#propdef-text-align-last
switch (TextAlignLast()) {
case ETextAlignLast::kStart:
return ETextAlign::kStart;
case ETextAlignLast::kEnd:
return ETextAlign::kEnd;
case ETextAlignLast::kLeft:
return ETextAlign::kLeft;
case ETextAlignLast::kRight:
return ETextAlign::kRight;
case ETextAlignLast::kCenter:
return ETextAlign::kCenter;
case ETextAlignLast::kJustify:
return ETextAlign::kJustify;
case ETextAlignLast::kAuto:
ETextAlign text_align = GetTextAlign();
if (text_align == ETextAlign::kJustify) {
return ETextAlign::kStart;
}
return text_align;
}
NOTREACHED();
}
// Unicode 11 introduced Georgian capital letters (U+1C90 - U+1CBA,
// U+1CB[D-F]), but virtually no font covers them. For now map them back
// to their lowercase counterparts (U+10D0 - U+10FA, U+10F[D-F]).
// https://www.unicode.org/charts/PDF/U10A0.pdf
// https://www.unicode.org/charts/PDF/U1C90.pdf
// See https://crbug.com/865427 .
// TODO(jshin): Make this platform-dependent. For instance, turn this
// off when CrOS gets new Georgian fonts covering capital letters.
// ( https://crbug.com/880144 ).
static String DisableNewGeorgianCapitalLetters(const String& text) {
if (text.IsNull() || text.Is8Bit()) {
return text;
}
unsigned length = text.length();
const StringImpl& input = *(text.Impl());
StringBuilder result;
result.ReserveCapacity(length);
// |input| must be well-formed UTF-16 so that there's no worry
// about surrogate handling.
for (unsigned i = 0; i < length; ++i) {
UChar character = input[i];
if (Character::IsModernGeorgianUppercase(character)) {
result.Append(Character::LowercaseModernGeorgianUppercase(character));
} else {
result.Append(character);
}
}
return result.ToString();
}
namespace {
String ApplyMathAutoTransform(const String& text, TextOffsetMap* offset_map) {
if (text.length() != 1) {
return text;
}
UChar character = text[0];
UChar32 transformed_char = ItalicMathVariant(text[0]);
if (transformed_char == static_cast<UChar32>(character)) {
return text;
}
Vector<UChar> transformed_text(U16_LENGTH(transformed_char));
int i = 0;
U16_APPEND_UNSAFE(transformed_text, i, transformed_char);
String transformed_string = String(transformed_text);
if (offset_map) {
offset_map->Append(text.length(), transformed_string.length());
}
return transformed_string;
}
} // namespace
String ComputedStyle::ApplyTextTransform(const String& text,
UChar previous_character,
TextOffsetMap* offset_map) const {
switch (TextTransform()) {
case ETextTransform::kNone:
return text;
case ETextTransform::kCapitalize: {
if (RuntimeEnabledFeatures::ICUCapitalizationEnabled()) {
const LayoutLocale* locale = GetFontDescription().Locale();
CaseMap case_map(locale ? locale->CaseMapLocale() : CaseMap::Locale());
return case_map.ToTitle(text, offset_map, previous_character);
}
return Capitalize(text, previous_character);
}
case ETextTransform::kUppercase: {
const LayoutLocale* locale = GetFontDescription().Locale();
CaseMap case_map(locale ? locale->CaseMapLocale() : CaseMap::Locale());
return DisableNewGeorgianCapitalLetters(
case_map.ToUpper(text, offset_map));
}
case ETextTransform::kLowercase: {
const LayoutLocale* locale = GetFontDescription().Locale();
CaseMap case_map(locale ? locale->CaseMapLocale() : CaseMap::Locale());
return case_map.ToLower(text, offset_map);
}
case ETextTransform::kMathAuto:
return ApplyMathAutoTransform(text, offset_map);
}
NOTREACHED();
}
const AtomicString& ComputedStyle::TextEmphasisMarkString() const {
switch (GetTextEmphasisMark()) {
case TextEmphasisMark::kNone:
return g_null_atom;
case TextEmphasisMark::kCustom:
return TextEmphasisCustomMark();
case TextEmphasisMark::kDot: {
DEFINE_STATIC_LOCAL(AtomicString, filled_dot_string,
(base::span_from_ref(kBulletCharacter)));
DEFINE_STATIC_LOCAL(AtomicString, open_dot_string,
(base::span_from_ref(kWhiteBulletCharacter)));
return GetTextEmphasisFill() == TextEmphasisFill::kFilled
? filled_dot_string
: open_dot_string;
}
case TextEmphasisMark::kCircle: {
DEFINE_STATIC_LOCAL(AtomicString, filled_circle_string,
(base::span_from_ref(kBlackCircleCharacter)));
DEFINE_STATIC_LOCAL(AtomicString, open_circle_string,
(base::span_from_ref(kWhiteCircleCharacter)));
return GetTextEmphasisFill() == TextEmphasisFill::kFilled
? filled_circle_string
: open_circle_string;
}
case TextEmphasisMark::kDoubleCircle: {
DEFINE_STATIC_LOCAL(AtomicString, filled_double_circle_string,
(base::span_from_ref(kFisheyeCharacter)));
DEFINE_STATIC_LOCAL(AtomicString, open_double_circle_string,
(base::span_from_ref(kBullseyeCharacter)));
return GetTextEmphasisFill() == TextEmphasisFill::kFilled
? filled_double_circle_string
: open_double_circle_string;
}
case TextEmphasisMark::kTriangle: {
DEFINE_STATIC_LOCAL(
AtomicString, filled_triangle_string,
(base::span_from_ref(kBlackUpPointingTriangleCharacter)));
DEFINE_STATIC_LOCAL(
AtomicString, open_triangle_string,
(base::span_from_ref(kWhiteUpPointingTriangleCharacter)));
return GetTextEmphasisFill() == TextEmphasisFill::kFilled
? filled_triangle_string
: open_triangle_string;
}
case TextEmphasisMark::kSesame: {
DEFINE_STATIC_LOCAL(AtomicString, filled_sesame_string,
(base::span_from_ref(kSesameDotCharacter)));
DEFINE_STATIC_LOCAL(AtomicString, open_sesame_string,
(base::span_from_ref(kWhiteSesameDotCharacter)));
return GetTextEmphasisFill() == TextEmphasisFill::kFilled
? filled_sesame_string
: open_sesame_string;
}
case TextEmphasisMark::kAuto:
NOTREACHED();
}
NOTREACHED();
}
LineLogicalSide ComputedStyle::GetTextEmphasisLineLogicalSide() const {
TextEmphasisPosition position = GetTextEmphasisPosition();
if (RuntimeEnabledFeatures::TextEmphasisPositionAutoEnabled() &&
position == TextEmphasisPosition::kAuto) {
if (IsHorizontalWritingMode()) {
return LineLogicalSide::kOver;
}
switch (GetWritingMode()) {
case WritingMode::kVerticalRl:
case WritingMode::kVerticalLr:
case WritingMode::kSidewaysRl:
return LineLogicalSide::kOver;
case WritingMode::kSidewaysLr:
return LineLogicalSide::kUnder;
default:
NOTREACHED();
}
}
if (IsHorizontalWritingMode()) {
return IsOver(position) ? LineLogicalSide::kOver : LineLogicalSide::kUnder;
}
if (GetWritingMode() != WritingMode::kSidewaysLr) {
return IsRight(position) ? LineLogicalSide::kOver : LineLogicalSide::kUnder;
}
return IsLeft(position) ? LineLogicalSide::kOver : LineLogicalSide::kUnder;
}
FontBaseline ComputedStyle::GetFontBaseline() const {
// CssDominantBaseline() always returns kAuto for non-SVG elements,
// and never returns kUseScript, kNoChange, and kResetSize.
// See StyleAdjuster::AdjustComputedStyle().
switch (CssDominantBaseline()) {
case EDominantBaseline::kAuto:
break;
case EDominantBaseline::kMiddle:
return kXMiddleBaseline;
case EDominantBaseline::kAlphabetic:
return kAlphabeticBaseline;
case EDominantBaseline::kHanging:
return kHangingBaseline;
case EDominantBaseline::kCentral:
return kCentralBaseline;
case EDominantBaseline::kTextBeforeEdge:
return kTextOverBaseline;
case EDominantBaseline::kTextAfterEdge:
return kTextUnderBaseline;
case EDominantBaseline::kIdeographic:
return kIdeographicUnderBaseline;
case EDominantBaseline::kMathematical:
return kMathBaseline;
case EDominantBaseline::kUseScript:
case EDominantBaseline::kNoChange:
case EDominantBaseline::kResetSize:
NOTREACHED();
}
// Vertical flow (except 'text-orientation: sideways') uses ideographic
// central baseline.
// https://drafts.csswg.org/css-writing-modes-3/#text-baselines
return !GetFontDescription().IsVerticalAnyUpright() ? kAlphabeticBaseline
: kCentralBaseline;
}
FontHeight ComputedStyle::GetFontHeight(FontBaseline baseline) const {
if (const SimpleFontData* font_data = GetFont()->PrimaryFont()) {
return font_data->GetFontMetrics().GetFontHeight(baseline);
}
return FontHeight();
}
bool ComputedStyle::TextDecorationVisualOverflowChanged(
const ComputedStyle& o) const {
const Vector<AppliedTextDecoration, 1>& applied_with_this =
AppliedTextDecorations();
const Vector<AppliedTextDecoration, 1>& applied_with_other =
o.AppliedTextDecorations();
if (applied_with_this.size() != applied_with_other.size()) {
return true;
}
for (auto decoration_index = 0u; decoration_index < applied_with_this.size();
++decoration_index) {
const AppliedTextDecoration& decoration_from_this =
applied_with_this[decoration_index];
const AppliedTextDecoration& decoration_from_other =
applied_with_other[decoration_index];
if (decoration_from_this.Thickness() != decoration_from_other.Thickness() ||
decoration_from_this.UnderlineOffset() !=
decoration_from_other.UnderlineOffset() ||
decoration_from_this.Style() != decoration_from_other.Style() ||
decoration_from_this.Lines() != decoration_from_other.Lines()) {
return true;
}
}
if (GetTextUnderlinePosition() != o.GetTextUnderlinePosition()) {
return true;
}
return false;
}
TextDecorationLine ComputedStyle::TextDecorationsInEffect() const {
TextDecorationLine decorations = GetTextDecorationLine();
if (const auto& base_decorations = BaseTextDecorationDataInternal()) {
for (const AppliedTextDecoration& decoration : base_decorations->data) {
decorations |= decoration.Lines();
}
}
return decorations;
}
base::RefCountedData<Vector<AppliedTextDecoration, 1>>*
ComputedStyle::EnsureAppliedTextDecorationsCache() const {
DCHECK(IsDecoratingBox());
if (!cached_data_ || !cached_data_->applied_text_decorations_) {
using DecorationsVector = Vector<AppliedTextDecoration, 1>;
DecorationsVector decorations;
if (const auto& base_decorations = BaseTextDecorationDataInternal()) {
decorations.ReserveInitialCapacity(base_decorations->data.size() + 1u);
decorations = base_decorations->data;
}
decorations.emplace_back(
GetTextDecorationLine(), TextDecorationStyle(),
VisitedDependentColor(GetCSSPropertyTextDecorationColor()),
GetTextDecorationThickness(), TextUnderlineOffset());
EnsureCachedData().applied_text_decorations_ =
base::MakeRefCounted<base::RefCountedData<DecorationsVector>>(
std::move(decorations));
}
return cached_data_->applied_text_decorations_.get();
}
const Vector<AppliedTextDecoration, 1>& ComputedStyle::AppliedTextDecorations()
const {
if (!HasAppliedTextDecorations()) {
using DecorationsVector = Vector<AppliedTextDecoration, 1>;
DEFINE_STATIC_LOCAL(DecorationsVector, empty, ());
return empty;
}
if (!IsDecoratingBox()) {
const auto& base_decorations = BaseTextDecorationDataInternal();
DCHECK(base_decorations);
DCHECK_GE(base_decorations->data.size(), 1u);
return base_decorations->data;
}
return EnsureAppliedTextDecorationsCache()->data;
}
static bool HasInitialVariables(const StyleInitialData* initial_data) {
return initial_data && initial_data->HasInitialVariables();
}
bool ComputedStyle::HasVariables() const {
return InheritedVariables() || NonInheritedVariables() ||
HasInitialVariables(InitialData());
}
wtf_size_t ComputedStyle::GetVariableNamesCount() const {
if (!HasVariables()) {
return 0;
}
return GetVariableNames().size();
}
const Vector<AtomicString>& ComputedStyle::GetVariableNames() const {
if (auto* cache = GetVariableNamesCache()) {
return *cache;
}
Vector<AtomicString>& cache = EnsureVariableNamesCache();
HashSet<AtomicString> names;
if (auto* initial_data = InitialData()) {
initial_data->CollectVariableNames(names);
}
if (auto* inherited_variables = InheritedVariables()) {
inherited_variables->CollectNames(names);
}
if (auto* non_inherited_variables = NonInheritedVariables()) {
non_inherited_variables->CollectNames(names);
}
cache.assign(names);
return cache;
}
const StyleInheritedVariables* ComputedStyle::InheritedVariables() const {
return InheritedVariablesInternal().Get();
}
const StyleNonInheritedVariables* ComputedStyle::NonInheritedVariables() const {
return NonInheritedVariablesInternal().Get();
}
bool ComputedStyle::HasPropertyDependingOnCurrentColor() const {
for (CSSPropertyID property_id : kCSSIncludesCurrentColorProperties) {
auto& property = CSSProperty::Get(property_id);
DCHECK(property.IsLonghand());
if (static_cast<const Longhand&>(property).IsAffectedByCurrentColor(
*this)) {
return true;
}
}
return false;
}
namespace {
template <typename T>
CSSVariableData* GetVariableData(
const T& style_or_builder,
const AtomicString& name,
std::optional<bool> inherited_hint = std::nullopt) {
if (inherited_hint.value_or(true) && style_or_builder.InheritedVariables()) {
if (auto data = style_or_builder.InheritedVariables()->GetData(name)) {
return *data;
}
}
if (!inherited_hint.value_or(false) &&
style_or_builder.NonInheritedVariables()) {
if (auto data = style_or_builder.NonInheritedVariables()->GetData(name)) {
return *data;
}
}
if (StyleInitialData* initial_data = style_or_builder.InitialData()) {
return initial_data->GetVariableData(name);
}
return nullptr;
}
template <typename T>
const CSSValue* GetVariableValue(
const T& style_or_builder,
const AtomicString& name,
std::optional<bool> inherited_hint = std::nullopt) {
if (inherited_hint.value_or(true) && style_or_builder.InheritedVariables()) {
if (auto data = style_or_builder.InheritedVariables()->GetValue(name)) {
return *data;
}
}
if (!inherited_hint.value_or(false) &&
style_or_builder.NonInheritedVariables()) {
if (auto data = style_or_builder.NonInheritedVariables()->GetValue(name)) {
return *data;
}
}
if (StyleInitialData* initial_data = style_or_builder.InitialData()) {
return initial_data->GetVariableValue(name);
}
return nullptr;
}
} // namespace
CSSVariableData* ComputedStyle::GetVariableData(
const AtomicString& name) const {
return blink::GetVariableData(*this, name);
}
CSSVariableData* ComputedStyle::GetVariableData(
const AtomicString& name,
bool is_inherited_property) const {
return blink::GetVariableData(*this, name, is_inherited_property);
}
const CSSValue* ComputedStyle::GetVariableValue(
const AtomicString& name) const {
return blink::GetVariableValue(*this, name);
}
const CSSValue* ComputedStyle::GetVariableValue(
const AtomicString& name,
bool is_inherited_property) const {
return blink::GetVariableValue(*this, name, is_inherited_property);
}
bool ComputedStyle::HasCustomScrollbarStyle(Element* element) const {
if (!element) {
return false;
}
// Ignore ::-webkit-scrollbar when the web setting to prefer default scrollbar
// styling is true. The exception to this case is when 'display' is set to
// 'none'.
if (RuntimeEnabledFeatures::PreferDefaultScrollbarStylesEnabled() &&
PrefersDefaultScrollbarStyles() && element &&
!ScrollbarIsHiddenByCustomStyle(element)) {
return false;
}
// Ignore non-standard ::-webkit-scrollbar when standard properties are in
// use.
return HasPseudoElementStyle(kPseudoIdScrollbar) &&
!UsesStandardScrollbarStyle();
}
EScrollbarWidth ComputedStyle::UsedScrollbarWidth() const {
if (PrefersDefaultScrollbarStyles() &&
ScrollbarWidth() != EScrollbarWidth::kNone) {
return EScrollbarWidth::kAuto;
}
return ScrollbarWidth();
}
StyleScrollbarColor* ComputedStyle::UsedScrollbarColor() const {
if (PrefersDefaultScrollbarStyles()) {
return nullptr;
}
return ScrollbarColor();
}
Length ComputedStyle::LineHeight() const {
const Length& lh = LineHeightInternal();
// Unlike getFontDescription().computedSize() and hence fontSize(), this is
// recalculated on demand as we only store the specified line height.
// FIXME: Should consider scaling the fixed part of any calc expressions
// too, though this involves messily poking into CalcExpressionLength.
if (lh.IsFixed()) {
float multiplier = TextAutosizingMultiplier();
return Length::Fixed(TextAutosizer::ComputeAutosizedFontSize(
lh.Pixels(), multiplier, EffectiveZoom()));
}
return lh;
}
float ComputedStyle::ComputedLineHeight(const Length& lh, const Font& font) {
// For "normal" line-height use the font's built-in spacing if available.
if (lh.IsAuto()) {
if (font.PrimaryFont()) {
return font.PrimaryFont()->GetFontMetrics().LineSpacing();
}
return 0.0f;
}
if (lh.HasPercent()) {
return MinimumValueForLength(
lh, LayoutUnit(font.GetFontDescription().ComputedSize()));
}
DCHECK(lh.IsFixed());
return lh.Pixels();
}
float ComputedStyle::ComputedLineHeight() const {
return ComputedLineHeight(LineHeight(), *GetFont());
}
LayoutUnit ComputedStyle::ComputedLineHeightAsFixed(const Font& font) const {
const Length& lh = LineHeight();
// For "normal" line-height use the font's built-in spacing if available.
if (lh.IsAuto()) {
if (font.PrimaryFont()) {
return font.PrimaryFont()->GetFontMetrics().FixedLineSpacing();
}
return LayoutUnit();
}
if (lh.HasPercent()) {
return MinimumValueForLength(lh, ComputedFontSizeAsFixed(font));
}
DCHECK(lh.IsFixed());
return LayoutUnit::FromFloatRound(lh.Pixels());
}
LayoutUnit ComputedStyle::ComputedLineHeightAsFixed() const {
return ComputedLineHeightAsFixed(*GetFont());
}
StyleColor ComputedStyle::DecorationColorIncludingFallback(
bool visited_link) const {
StyleColor style_color = visited_link ? InternalVisitedTextDecorationColor()
: TextDecorationColor();
if (!style_color.IsCurrentColor()) {
return style_color;
}
if (TextStrokeWidth()) {
// Prefer stroke color if possible, but not if it's fully transparent.
StyleColor text_stroke_style_color =
visited_link ? InternalVisitedTextStrokeColor() : TextStrokeColor();
if (!text_stroke_style_color.IsCurrentColor() &&
!text_stroke_style_color.Resolve(blink::Color(), UsedColorScheme())
.IsFullyTransparent()) {
return text_stroke_style_color;
}
}
return visited_link ? InternalVisitedTextFillColor() : TextFillColor();
}
bool ComputedStyle::HasBackground() const {
// Ostensibly, we should call VisitedDependentColor() here,
// but visited does not affect alpha (see VisitedDependentColor()
// implementation).
blink::Color color = GetCSSPropertyBackgroundColor().ColorIncludingFallback(
false, *this,
/*is_current_color=*/nullptr);
if (!color.IsFullyTransparent()) {
return true;
}
// When background color animation is running on the compositor thread, we
// need to trigger repaint even if the background is transparent to collect
// artifacts in order to run the animation on the compositor.
if (RuntimeEnabledFeatures::CompositeBGColorAnimationEnabled() &&
HasCurrentBackgroundColorAnimation()) {
return true;
}
return HasBackgroundImage();
}
Color ComputedStyle::VisitedDependentColor(const Longhand& color_property,
bool* is_current_color) const {
DCHECK(!color_property.IsVisited());
blink::Color unvisited_color =
color_property.ColorIncludingFallback(false, *this, is_current_color);
if (InsideLink() != EInsideLink::kInsideVisitedLink) {
return unvisited_color;
}
// Properties that provide a GetVisitedProperty() must use the
// ColorIncludingFallback function on that property.
//
// TODO(andruud): Simplify this when all properties support
// GetVisitedProperty.
const CSSProperty* visited_property = &color_property;
if (const CSSProperty* visited = color_property.GetVisitedProperty()) {
visited_property = visited;
}
// Overwrite is_current_color based on the visited color.
blink::Color visited_color =
To<Longhand>(*visited_property)
.ColorIncludingFallback(true, *this, is_current_color);
// Take the alpha from the unvisited color, but get the RGB values from the
// visited color.
//
// Ideally we would set the |is_current_color| flag to true if the unvisited
// color is ‘currentColor’, because the result depends on the unvisited alpha,
// to tell the highlight painter to resolve the color again with a different
// current color, but that’s not possible with the current interface.
//
// In reality, the highlight painter just throws away the whole color and
// falls back to the layer or next layer or originating ‘color’, so setting
// the flag when the unvisited color is ‘currentColor’ would break tests like
// css/css-pseudo/selection-link-001 and css/css-pseudo/target-text-008.
// TODO(dazabani@igalia.com) improve behaviour where unvisited is currentColor
return Color::FromColorSpace(visited_color.GetColorSpace(),
visited_color.Param0(), visited_color.Param1(),
visited_color.Param2(), unvisited_color.Alpha());
}
blink::Color ComputedStyle::VisitedDependentGapColor(
const StyleColor& gap_color,
const ComputedStyle& style,
bool is_column_rule) const {
CHECK(RuntimeEnabledFeatures::CSSGapDecorationEnabled());
blink::Color unvisited_gap_color;
// `StyleColor::IsCurrentColor()` is used down the pipeline to determine if
// `gap_color` is `currentColor`.
if (ShouldForceColor(gap_color)) {
unvisited_gap_color =
GetInternalForcedCurrentColor(/*is_current_color=*/nullptr);
} else {
unvisited_gap_color = gap_color.Resolve(
GetCurrentColor(), UsedColorScheme(), /*is_current_color=*/nullptr);
}
if (InsideLink() != EInsideLink::kInsideVisitedLink) {
return unvisited_gap_color;
}
// For `row-rule-color`, :visited styling is not supported.
if (!is_column_rule) {
return unvisited_gap_color;
}
blink::Color visited_gap_color;
if (ShouldForceColor(gap_color)) {
visited_gap_color =
GetInternalForcedVisitedCurrentColor(/*is_current_color=*/nullptr);
} else {
visited_gap_color =
style.InternalVisitedColumnRuleColor().GetLegacyValue().Resolve(
GetInternalVisitedCurrentColor(), UsedColorScheme(),
/*is_current_color=*/nullptr);
}
return visited_gap_color;
}
blink::Color ComputedStyle::VisitedDependentContextFill(
const SVGPaint& context_paint,
const ComputedStyle& context_style) const {
return VisitedDependentContextPaint(context_paint,
context_style.InternalVisitedFillPaint());
}
blink::Color ComputedStyle::VisitedDependentContextStroke(
const SVGPaint& context_paint,
const ComputedStyle& context_style) const {
return VisitedDependentContextPaint(
context_paint, context_style.InternalVisitedStrokePaint());
}
blink::Color ComputedStyle::VisitedDependentContextPaint(
const SVGPaint& context_paint,
const SVGPaint& context_visited_paint) const {
blink::Color unvisited_color =
ShouldForceColor(context_paint.GetColor())
? GetInternalForcedCurrentColor(nullptr)
: context_paint.GetColor().Resolve(GetCurrentColor(),
UsedColorScheme(), nullptr);
if (InsideLink() != EInsideLink::kInsideVisitedLink) {
return unvisited_color;
}
if (!context_visited_paint.HasColor()) {
return unvisited_color;
}
if (ShouldForceColor(context_visited_paint.GetColor())) {
return GetInternalForcedVisitedCurrentColor(nullptr);
}
return context_visited_paint.GetColor().Resolve(
GetInternalVisitedCurrentColor(), UsedColorScheme(), nullptr);
}
blink::Color ComputedStyle::ResolvedColor(const StyleColor& color,
bool* is_current_color) const {
bool visited_link = (InsideLink() == EInsideLink::kInsideVisitedLink);
blink::Color current_color =
visited_link ? GetInternalVisitedCurrentColor() : GetCurrentColor();
return color.Resolve(current_color, UsedColorScheme(), is_current_color);
}
bool ComputedStyle::ColumnRuleEquivalent(
const ComputedStyle& other_style) const {
return ColumnRuleStyle() == other_style.ColumnRuleStyle() &&
ColumnRuleWidth() == other_style.ColumnRuleWidth() &&
VisitedDependentColor(GetCSSPropertyColumnRuleColor()) ==
other_style.VisitedDependentColor(GetCSSPropertyColumnRuleColor());
}
TextEmphasisMark ComputedStyle::GetTextEmphasisMark() const {
TextEmphasisMark mark = TextEmphasisMarkInternal();
if (mark != TextEmphasisMark::kAuto) {
return mark;
}
// https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-style
// If only `filled` or `open` is specified, the shape keyword computes to
// `circle` in horizontal typographic modes and `sesame` in vertical
// typographic modes.
if (IsHorizontalTypographicMode()) {
return TextEmphasisMark::kDot;
}
return TextEmphasisMark::kSesame;
}
PhysicalBoxStrut ComputedStyle::ImageOutsets(
const NinePieceImage& image) const {
return {
NinePieceImage::ComputeOutset(image.Outset().Top(), BorderTopWidth()),
NinePieceImage::ComputeOutset(image.Outset().Right(), BorderRightWidth()),
NinePieceImage::ComputeOutset(image.Outset().Bottom(),
BorderBottomWidth()),
NinePieceImage::ComputeOutset(image.Outset().Left(), BorderLeftWidth())};
}
bool ComputedStyle::BorderObscuresBackground() const {
if (!HasBorder()) {
return false;
}
// Bail if we have any border-image for now. We could look at the image alpha
// to improve this.
if (BorderImage().GetImage()) {
return false;
}
BorderEdgeArray edges;
GetBorderEdgeInfo(edges);
for (unsigned int i = static_cast<unsigned>(BoxSide::kTop);
i <= static_cast<unsigned>(BoxSide::kLeft); ++i) {
const BorderEdge& curr_edge = edges[i];
if (!curr_edge.ObscuresBackground()) {
return false;
}
}
return true;
}
PhysicalBoxStrut ComputedStyle::BoxDecorationOutsets() const {
DCHECK(HasVisualOverflowingEffect());
PhysicalBoxStrut outsets;
if (const ShadowList* box_shadow = BoxShadow()) {
outsets =
PhysicalBoxStrut::Enclosing(box_shadow->RectOutsetsIncludingOriginal());
}
if (HasBorderImageOutsets()) {
outsets.Unite(BorderImageOutsets());
}
if (HasMaskBoxImageOutsets()) {
outsets.Unite(MaskBoxImageOutsets());
}
return outsets;
}
void ComputedStyle::GetBorderEdgeInfo(BorderEdgeArray& edges,
PhysicalBoxSides sides_to_include) const {
edges[static_cast<unsigned>(BoxSide::kTop)] = BorderEdge(
BorderTopWidth(), VisitedDependentColor(GetCSSPropertyBorderTopColor()),
BorderTopStyle(), sides_to_include.top);
edges[static_cast<unsigned>(BoxSide::kRight)] =
BorderEdge(BorderRightWidth(),
VisitedDependentColor(GetCSSPropertyBorderRightColor()),
BorderRightStyle(), sides_to_include.right);
edges[static_cast<unsigned>(BoxSide::kBottom)] =
BorderEdge(BorderBottomWidth(),
VisitedDependentColor(GetCSSPropertyBorderBottomColor()),
BorderBottomStyle(), sides_to_include.bottom);
edges[static_cast<unsigned>(BoxSide::kLeft)] = BorderEdge(
BorderLeftWidth(), VisitedDependentColor(GetCSSPropertyBorderLeftColor()),
BorderLeftStyle(), sides_to_include.left);
}
void ComputedStyle::CopyChildDependentFlagsFrom(
const ComputedStyle& other) const {
if (other.ChildHasExplicitInheritance()) {
SetChildHasExplicitInheritance();
}
}
blink::Color ComputedStyle::GetCurrentColor(bool* is_current_color) const {
DCHECK(!Color().IsCurrentColor());
if (is_current_color) {
*is_current_color = ColorIsCurrentColor();
}
return Color().Resolve(blink::Color(), UsedColorScheme());
}
blink::Color ComputedStyle::GetInternalVisitedCurrentColor(
bool* is_current_color) const {
DCHECK(!InternalVisitedColor().IsCurrentColor());
if (is_current_color) {
*is_current_color = InternalVisitedColorIsCurrentColor();
}
return InternalVisitedColor().Resolve(blink::Color(), UsedColorScheme());
}
blink::Color ComputedStyle::GetInternalForcedCurrentColor(
bool* is_current_color) const {
DCHECK(!InternalForcedColor().IsCurrentColor());
if (Color().IsSystemColorIncludingDeprecated()) {
return GetCurrentColor(is_current_color);
}
return InternalForcedColor().Resolve(blink::Color(), UsedColorScheme(),
is_current_color);
}
blink::Color ComputedStyle::GetInternalForcedVisitedCurrentColor(
bool* is_current_color) const {
DCHECK(!InternalForcedVisitedColor().IsCurrentColor());
if (InternalVisitedColor().IsSystemColorIncludingDeprecated()) {
return GetInternalVisitedCurrentColor(is_current_color);
}
return InternalForcedVisitedColor().Resolve(blink::Color(), UsedColorScheme(),
is_current_color);
}
bool ComputedStyle::ShadowListHasCurrentColor(const ShadowList* shadow_list) {
return shadow_list &&
std::ranges::any_of(shadow_list->Shadows(),
[](const ShadowData& shadow) {
return shadow.GetColor().DependsOnCurrentColor();
});
}
const AtomicString& ComputedStyle::ListStyleStringValue() const {
if (!ListStyleType() || !ListStyleType()->IsString()) {
return g_null_atom;
}
return ListStyleType()->GetStringValue();
}
bool ComputedStyle::MarkerShouldBeInside(
const Element& parent,
const DisplayStyle& marker_style) const {
// https://w3c.github.io/csswg-drafts/css-lists/#list-style-position-outside
// > If the list item is an inline box: this value is equivalent to inside.
if (Display() == EDisplay::kInlineListItem ||
ListStylePosition() == EListStylePosition::kInside) {
return true;
}
// Force the marker of <li> elements with no <ol> or <ul> ancestor to have
// an inside position.
// TODO(crbug.com/41241289): This quirk predates WebKit, it was added to match
// the behavior of the Internet Explorer from that time. However, Microsoft
// ended up removing it (before switching to Blink), and Firefox never had it,
// so it may be possible to get rid of it.
if (IsA<HTMLLIElement>(parent) && !IsInsideListElement() &&
PseudoElementLayoutObjectIsNeeded(kPseudoIdMarker, marker_style,
&parent)) {
parent.GetDocument().CountUse(WebFeature::kInsideListMarkerPositionQuirk);
return true;
}
return false;
}
std::optional<blink::Color> ComputedStyle::AccentColorResolved() const {
const StyleAutoColor& auto_color = AccentColor();
if (auto_color.IsAutoColor()) {
return std::nullopt;
}
return auto_color.Resolve(GetCurrentColor(), UsedColorScheme());
}
std::optional<blink::Color> ComputedStyle::ScrollbarThumbColorResolved() const {
if (const StyleScrollbarColor* scrollbar_color = UsedScrollbarColor()) {
return scrollbar_color->GetThumbColor().Resolve(GetCurrentColor(),
UsedColorScheme());
}
return std::nullopt;
}
std::optional<blink::Color> ComputedStyle::ScrollbarTrackColorResolved() const {
if (const StyleScrollbarColor* scrollbar_color = UsedScrollbarColor()) {
return scrollbar_color->GetTrackColor().Resolve(GetCurrentColor(),
UsedColorScheme());
}
return std::nullopt;
}
bool ComputedStyle::ShouldApplyAnyContainment(const Element& element,
const DisplayStyle& display_style,
unsigned effective_containment) {
DCHECK(IsA<HTMLBodyElement>(element) || IsA<HTMLHtmlElement>(element))
<< "Since elements can override the computed display for which box type "
"to create, this method is not generally correct. Use "
"LayoutObject::ShouldApplyAnyContainment if possible.";
if (effective_containment & kContainsStyle) {
return true;
}
if (!element.LayoutObjectIsNeeded(display_style)) {
return false;
}
EDisplay display = display_style.Display();
if (display == EDisplay::kInline) {
return false;
}
if ((effective_containment & kContainsSize) &&
(!IsDisplayTableType(display) || display == EDisplay::kTableCaption ||
ShouldUseContentDataForElement(display_style.GetContentData()))) {
return true;
}
return (effective_containment & (kContainsLayout | kContainsPaint)) &&
(!IsDisplayTableType(display) || IsDisplayTableBox(display) ||
display == EDisplay::kTableCell ||
display == EDisplay::kTableCaption);
}
bool ComputedStyle::CanMatchSizeContainerQueries(const Element& element) const {
return IsContainerForSizeContainerQueries() &&
(!element.IsSVGElement() ||
To<SVGElement>(element).IsOutermostSVGSVGElement());
}
bool ComputedStyle::IsInterleavingRoot(const ComputedStyle* style) {
const ComputedStyle* unensured = ComputedStyle::NullifyEnsured(style);
return unensured && (unensured->IsContainerForSizeContainerQueries() ||
unensured->GetPositionTryFallbacks() ||
unensured->HasAnchorFunctions());
}
bool ComputedStyle::ScrollbarIsHiddenByCustomStyle(Element* element) const {
// It is necessary to check the cached styles because native input
// controls are styled this way.
const ComputedStyle* cached_scrollbar_style =
GetCachedPseudoElementStyle(kPseudoIdScrollbar);
if (cached_scrollbar_style &&
cached_scrollbar_style->Display() == EDisplay::kNone) {
return true;
}
if (!element) {
return false;
}
const ComputedStyle* uncached_scrollbar_style =
element->UncachedStyleForPseudoElement(
StyleRequest(kPseudoIdScrollbar, StyleRequest::kForComputedStyle));
return uncached_scrollbar_style &&
uncached_scrollbar_style->Display() == EDisplay::kNone;
}
bool ComputedStyle::CalculateIsStackingContextWithoutContainment() const {
// Force a stacking context for transform-style: preserve-3d. This happens
// even if preserves-3d is ignored due to a 'grouping property' being
// present which requires flattening. See:
// ComputedStyle::HasGroupingPropertyForUsedTransformStyle3D().
// This is legacy behavior that is left ambiguous in the official specs.
// See https://crbug.com/663650 for more details.
if (TransformStyle3D() == ETransformStyle3D::kPreserve3d) {
return true;
}
if (ForcesStackingContext()) {
return true;
}
if (StyleType() == kPseudoIdBackdrop) {
return true;
}
if (HasTransformRelatedProperty()) {
return true;
}
if (HasStackingGroupingProperty(BoxReflect())) {
return true;
}
if (GetPosition() == EPosition::kFixed) {
return true;
}
if (GetPosition() == EPosition::kSticky) {
return true;
}
if (HasPropertyThatCreatesStackingContext(WillChangeProperties())) {
return true;
}
if (ShouldCompositeForCurrentAnimations()) {
// TODO(882625): This becomes unnecessary when will-change correctly takes
// into account active animations.
return true;
}
return false;
}
bool ComputedStyle::GapRuleColorIsTransparent(
const GapDataList<StyleColor>& gap_rule_color) const {
const blink::Color& current_color = GetCurrentColor();
const mojom::blink::ColorScheme& color_scheme = UsedColorScheme();
return std::ranges::all_of(
gap_rule_color.GetGapDataList(),
[&](const GapData<StyleColor>& gap_data) {
// If it’s a simple value, just test it directly.
if (!gap_data.IsRepeaterData()) {
const StyleColor& v = gap_data.GetValue();
return v.Resolve(current_color, color_scheme).IsFullyTransparent();
}
// Otherwise it’s a repeater: walk through its RepeatedValues(), and
// only return true if all values are transparent.
const auto* rep = gap_data.GetValueRepeater();
return std::ranges::all_of(
rep->RepeatedValues(), [&](const StyleColor& v) {
return v.Resolve(current_color, color_scheme)
.IsFullyTransparent();
});
});
}
bool ComputedStyle::IsRenderedInTopLayer(const Element& element) const {
return (element.IsInTopLayer() && Overlay() == EOverlay::kAuto) ||
StyleType() == kPseudoIdBackdrop;
}
bool ComputedStyle::ApplyControlFixedSize(const Node* node) const {
if (FieldSizing() == EFieldSizing::kFixed) {
return true;
}
if (!node) {
return false;
}
const auto* control = DynamicTo<HTMLFormControlElement>(node);
if (!control) {
control = DynamicTo<HTMLFormControlElement>(node->OwnerShadowHost());
}
return control && control->GetAutofillState() != WebAutofillState::kNotFilled;
}
ComputedStyleBuilder::ComputedStyleBuilder(const ComputedStyle& style)
: ComputedStyleBuilderBase(style) {}
ComputedStyleBuilder::ComputedStyleBuilder(
const ComputedStyle& initial_style,
const ComputedStyle& parent_style,
IsAtShadowBoundary is_at_shadow_boundary)
: ComputedStyleBuilderBase(initial_style, parent_style) {
// Even if surrounding content is user-editable, shadow DOM should act as a
// single unit, and not necessarily be editable
if (is_at_shadow_boundary == kAtShadowBoundary) {
SetUserModify(initial_style.UserModify());
}
// TODO(crbug.com/1410068): Once `user-select` isn't inherited, we should
// get rid of following if-statement.
if (parent_style.UserSelect() == EUserSelect::kContain) {
SetUserSelect(EUserSelect::kAuto); // FIXME(sesse): Is this right?
}
// TODO(sesse): Why do we do this?
SetBaseTextDecorationData(parent_style.AppliedTextDecorationData());
}
const ComputedStyle* ComputedStyleBuilder::TakeStyle() {
return MakeGarbageCollected<ComputedStyle>(ComputedStyle::BuilderPassKey(),
*this);
}
const ComputedStyle* ComputedStyleBuilder::CloneStyle() const {
ResetAccess();
has_own_inherited_variables_ = false;
has_own_non_inherited_variables_ = false;
return MakeGarbageCollected<ComputedStyle>(ComputedStyle::BuilderPassKey(),
*this);
}
void ComputedStyleBuilder::PropagateIndependentInheritedProperties(
const ComputedStyle& parent_style) {
ComputedStyleBuilderBase::PropagateIndependentInheritedProperties(
parent_style);
if (!HasVariableReference() && !HasVariableDeclaration() &&
(InheritedVariablesInternal().Get() !=
parent_style.InheritedVariables())) {
has_own_inherited_variables_ = false;
MutableInheritedVariablesInternal() =
parent_style.InheritedVariablesInternal();
}
}
void ComputedStyleBuilder::ClearBackgroundImage() {
FillLayer* curr_child = &AccessBackgroundLayers();
curr_child->SetImage(
FillLayer::InitialFillImage(EFillLayerType::kBackground));
for (curr_child = curr_child->Next(); curr_child;
curr_child = curr_child->Next()) {
curr_child->ClearImage();
}
}
bool ComputedStyleBuilder::SetEffectiveZoom(float f) {
// Clamp the effective zoom value to a smaller (but hopeful still large
// enough) range, to avoid overflow in derived computations.
float clamped_effective_zoom = ClampTo<float>(f, 1e-6, 1e6);
if (EffectiveZoom() == clamped_effective_zoom) {
return false;
}
SetEffectiveZoomInternal(clamped_effective_zoom);
// Record UMA for the effective zoom in order to assess the relative
// importance of sub-pixel behavior, and related features and bugs.
// Clamp to a max of 400%, to make the histogram behave better at no
// real cost to our understanding of the zooms in use.
base::UmaHistogramSparse(
"Blink.EffectiveZoom",
std::clamp<float>(clamped_effective_zoom * 100, 0, 400));
return true;
}
// Compute the FontOrientation from this style. It's derived from WritingMode
// and TextOrientation.
FontOrientation ComputedStyleBuilder::ComputeFontOrientation() const {
// https://drafts.csswg.org/css-writing-modes/#propdef-text-orientation
// > the property has no effect in horizontal typographic modes.
if (IsHorizontalTypographicMode(GetWritingMode())) {
return FontOrientation::kHorizontal;
}
switch (GetTextOrientation()) {
case ETextOrientation::kMixed:
return FontOrientation::kVerticalMixed;
case ETextOrientation::kUpright:
return FontOrientation::kVerticalUpright;
case ETextOrientation::kSideways:
return FontOrientation::kVerticalRotated;
default:
NOTREACHED();
}
}
// Update FontOrientation in FontDescription if it is different. FontBuilder
// takes care of updating it, but if WritingMode or TextOrientation were
// changed after the style was constructed, this function synchronizes
// FontOrientation to match to this style.
void ComputedStyleBuilder::UpdateFontOrientation() {
FontOrientation orientation = ComputeFontOrientation();
if (GetFontDescription().Orientation() == orientation) {
return;
}
FontDescription font_description = GetFontDescription();
font_description.SetOrientation(orientation);
SetFontDescription(font_description);
}
void ComputedStyleBuilder::SetTextAutosizingMultiplier(float multiplier) {
if (TextAutosizingMultiplier() == multiplier) {
return;
}
SetTextAutosizingMultiplierInternal(multiplier);
float size = GetFontDescription().SpecifiedSize();
DCHECK(std::isfinite(size));
if (!std::isfinite(size) || size < 0) {
size = 0;
} else {
size = std::min(kMaximumAllowedFontSize, size);
}
FontDescription desc(GetFontDescription());
desc.SetSpecifiedSize(size);
float computed_size = size * EffectiveZoom();
float autosized_font_size = TextAutosizer::ComputeAutosizedFontSize(
computed_size, multiplier, EffectiveZoom());
desc.SetComputedSize(std::min(kMaximumAllowedFontSize, autosized_font_size));
SetFontDescription(desc);
}
void ComputedStyleBuilder::SetUsedColorScheme(
ColorSchemeFlags flags,
mojom::blink::PreferredColorScheme preferred_color_scheme,
bool force_dark) {
bool prefers_dark =
preferred_color_scheme == mojom::blink::PreferredColorScheme::kDark;
bool has_dark = flags & static_cast<ColorSchemeFlags>(ColorSchemeFlag::kDark);
bool has_light =
flags & static_cast<ColorSchemeFlags>(ColorSchemeFlag::kLight);
bool has_only = flags & static_cast<ColorSchemeFlags>(ColorSchemeFlag::kOnly);
bool dark_scheme =
// Dark scheme because the preferred scheme is dark and color-scheme
// contains dark.
(has_dark && prefers_dark) ||
// Dark scheme because the the only recognized color-scheme is dark.
(has_dark && !has_light) ||
// Dark scheme because we have a dark color-scheme override for forced
// darkening and no 'only' which opts out.
(force_dark && !has_only) ||
// Typically, forced darkening should be used with a dark preferred
// color-scheme. This is to support the FORCE_DARK_ONLY behavior from
// WebView where this combination is passed to the renderer.
(force_dark && !prefers_dark);
SetDarkColorScheme(dark_scheme);
bool forced_scheme =
// No dark in the color-scheme property, but we still forced it to dark.
(!has_dark && dark_scheme) ||
// Always use forced color-scheme for preferred light color-scheme with
// forced darkening. The combination of preferred color-scheme of light
// with a color-scheme property value of "light dark" chooses the light
// color-scheme. Typically, forced darkening should be used with a dark
// preferred color-scheme. This is to support the FORCE_DARK_ONLY
// behavior from WebView where this combination is passed to the
// renderer.
(force_dark && !prefers_dark);
SetColorSchemeForced(forced_scheme);
const bool is_normal =
flags == static_cast<ColorSchemeFlags>(ColorSchemeFlag::kNormal);
SetColorSchemeFlagsIsNormal(is_normal);
}
CSSVariableData* ComputedStyleBuilder::GetVariableData(
const AtomicString& name,
bool is_inherited_property) const {
return blink::GetVariableData(*this, name, is_inherited_property);
}
StyleInheritedVariables& ComputedStyleBuilder::MutableInheritedVariables() {
Member<StyleInheritedVariables>& variables =
MutableInheritedVariablesInternal();
if (!has_own_inherited_variables_) {
variables = variables
? MakeGarbageCollected<StyleInheritedVariables>(*variables)
: MakeGarbageCollected<StyleInheritedVariables>();
}
has_own_inherited_variables_ = true;
DCHECK(variables);
return *variables;
}
StyleNonInheritedVariables&
ComputedStyleBuilder::MutableNonInheritedVariables() {
Member<StyleNonInheritedVariables>& variables =
MutableNonInheritedVariablesInternal();
if (!has_own_non_inherited_variables_) {
variables =
variables ? MakeGarbageCollected<StyleNonInheritedVariables>(*variables)
: MakeGarbageCollected<StyleNonInheritedVariables>();
}
has_own_non_inherited_variables_ = true;
DCHECK(variables);
return *variables;
}
void ComputedStyleBuilder::SetInheritedVariablesFrom(
const ComputedStyle* style) {
MutableInheritedVariablesInternal() = style->InheritedVariablesInternal();
has_own_inherited_variables_ = false;
}
void ComputedStyleBuilder::SetNonInheritedVariablesFrom(
const ComputedStyle* style) {
MutableNonInheritedVariablesInternal() =
style->NonInheritedVariablesInternal();
has_own_non_inherited_variables_ = false;
}
STATIC_ASSERT_ENUM(cc::OverscrollBehavior::Type::kAuto,
EOverscrollBehavior::kAuto);
STATIC_ASSERT_ENUM(cc::OverscrollBehavior::Type::kContain,
EOverscrollBehavior::kContain);
STATIC_ASSERT_ENUM(cc::OverscrollBehavior::Type::kNone,
EOverscrollBehavior::kNone);
} // namespace blink
|