1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Copyright (C) 2016 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "config.h"
#include "CSSPropertyParser.h"
#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
#include "CSSAnimationTriggerScrollValue.h"
#endif
#include "CSSAspectRatioValue.h"
#include "CSSBasicShapes.h"
#include "CSSBorderImage.h"
#include "CSSBorderImageSliceValue.h"
#include "CSSContentDistributionValue.h"
#include "CSSCursorImageValue.h"
#include "CSSCustomIdentValue.h"
#include "CSSFontFaceSrcValue.h"
#include "CSSFontFeatureValue.h"
#if ENABLE(VARIATION_FONTS)
#include "CSSFontVariationValue.h"
#endif
#include "CSSFunctionValue.h"
#include "CSSGridAutoRepeatValue.h"
#include "CSSGridLineNamesValue.h"
#include "CSSGridTemplateAreasValue.h"
#include "CSSInheritedValue.h"
#include "CSSInitialValue.h"
#include "CSSLineBoxContainValue.h"
#include "CSSParserFastPaths.h"
#include "CSSParserIdioms.h"
#include "CSSPendingSubstitutionValue.h"
#include "CSSPrimitiveValueMappings.h"
#include "CSSPropertyParserHelpers.h"
#include "CSSReflectValue.h"
#include "CSSRevertValue.h"
#include "CSSShadowValue.h"
#include "CSSTimingFunctionValue.h"
#include "CSSUnicodeRangeValue.h"
#include "CSSUnsetValue.h"
#include "CSSVariableParser.h"
#include "CSSVariableReferenceValue.h"
#include "Counter.h"
#if ENABLE(DASHBOARD_SUPPORT)
#include "DashboardRegion.h"
#endif
#include "FontFace.h"
#include "HashTools.h"
// FIXME-NEWPARSER: Replace Pair and Rect with actual CSSValue subclasses (CSSValuePair and CSSQuadValue).
#include "Pair.h"
#include "Rect.h"
#include "RenderTheme.h"
#include "RuntimeEnabledFeatures.h"
#include "SVGPathByteStream.h"
#include "SVGPathUtilities.h"
#include "StylePropertyShorthand.h"
#include "StylePropertyShorthandFunctions.h"
#include <bitset>
#include <memory>
#include <wtf/text/StringBuilder.h>
using namespace WTF;
namespace WebCore {
bool isCustomPropertyName(const String& propertyName)
{
return propertyName.length() > 2 && propertyName.characterAt(0) == '-' && propertyName.characterAt(1) == '-';
}
static bool hasPrefix(const char* string, unsigned length, const char* prefix)
{
for (unsigned i = 0; i < length; ++i) {
if (!prefix[i])
return true;
if (string[i] != prefix[i])
return false;
}
return false;
}
#if PLATFORM(IOS)
void cssPropertyNameIOSAliasing(const char* propertyName, const char*& propertyNameAlias, unsigned& newLength)
{
if (!strcmp(propertyName, "-webkit-hyphenate-locale")) {
// Worked in iOS 4.2.
static const char webkitLocale[] = "-webkit-locale";
propertyNameAlias = webkitLocale;
newLength = strlen(webkitLocale);
}
}
#endif
template <typename CharacterType>
static CSSPropertyID cssPropertyID(const CharacterType* propertyName, unsigned length)
{
char buffer[maxCSSPropertyNameLength + 1 + 1]; // 1 to turn "apple"/"khtml" into "webkit", 1 for null character
for (unsigned i = 0; i != length; ++i) {
CharacterType c = propertyName[i];
if (!c || c >= 0x7F)
return CSSPropertyInvalid; // illegal character
buffer[i] = toASCIILower(c);
}
buffer[length] = '\0';
const char* name = buffer;
if (buffer[0] == '-') {
#if ENABLE(LEGACY_CSS_VENDOR_PREFIXES)
// If the prefix is -apple- or -khtml-, change it to -webkit-.
// This makes the string one character longer.
if (RuntimeEnabledFeatures::sharedFeatures().legacyCSSVendorPrefixesEnabled()
&& (hasPrefix(buffer, length, "-apple-") || hasPrefix(buffer, length, "-khtml-"))) {
memmove(buffer + 7, buffer + 6, length + 1 - 6);
memcpy(buffer, "-webkit", 7);
++length;
}
#endif
#if PLATFORM(IOS)
cssPropertyNameIOSAliasing(buffer, name, length);
#endif
}
const Property* hashTableEntry = findProperty(name, length);
return hashTableEntry ? static_cast<CSSPropertyID>(hashTableEntry->id) : CSSPropertyInvalid;
}
static bool isAppleLegacyCssValueKeyword(const char* valueKeyword, unsigned length)
{
static const char applePrefix[] = "-apple-";
static const char appleSystemPrefix[] = "-apple-system";
static const char applePayPrefix[] = "-apple-pay";
static const char* appleWirelessPlaybackTargetActive = getValueName(CSSValueAppleWirelessPlaybackTargetActive);
return hasPrefix(valueKeyword, length, applePrefix)
&& !hasPrefix(valueKeyword, length, appleSystemPrefix)
&& !hasPrefix(valueKeyword, length, applePayPrefix)
&& !WTF::equal(reinterpret_cast<const LChar*>(valueKeyword), reinterpret_cast<const LChar*>(appleWirelessPlaybackTargetActive), length);
}
template <typename CharacterType>
static CSSValueID cssValueKeywordID(const CharacterType* valueKeyword, unsigned length)
{
char buffer[maxCSSValueKeywordLength + 1 + 1]; // 1 to turn "apple"/"khtml" into "webkit", 1 for null character
for (unsigned i = 0; i != length; ++i) {
CharacterType c = valueKeyword[i];
if (!c || c >= 0x7F)
return CSSValueInvalid; // illegal keyword.
buffer[i] = WTF::toASCIILower(c);
}
buffer[length] = '\0';
if (buffer[0] == '-') {
// If the prefix is -apple- or -khtml-, change it to -webkit-.
// This makes the string one character longer.
// On iOS we don't want to change values starting with -apple-system to -webkit-system.
// FIXME: Remove this mangling without breaking the web.
if (isAppleLegacyCssValueKeyword(buffer, length) || hasPrefix(buffer, length, "-khtml-")) {
memmove(buffer + 7, buffer + 6, length + 1 - 6);
memcpy(buffer, "-webkit", 7);
++length;
}
}
const Value* hashTableEntry = findValue(buffer, length);
return hashTableEntry ? static_cast<CSSValueID>(hashTableEntry->id) : CSSValueInvalid;
}
CSSValueID cssValueKeywordID(StringView string)
{
unsigned length = string.length();
if (!length)
return CSSValueInvalid;
if (length > maxCSSValueKeywordLength)
return CSSValueInvalid;
return string.is8Bit() ? cssValueKeywordID(string.characters8(), length) : cssValueKeywordID(string.characters16(), length);
}
CSSPropertyID cssPropertyID(StringView string)
{
unsigned length = string.length();
if (!length)
return CSSPropertyInvalid;
if (length > maxCSSPropertyNameLength)
return CSSPropertyInvalid;
return string.is8Bit() ? cssPropertyID(string.characters8(), length) : cssPropertyID(string.characters16(), length);
}
using namespace CSSPropertyParserHelpers;
CSSPropertyParser::CSSPropertyParser(const CSSParserTokenRange& range, const CSSParserContext& context, StyleSheetContents* styleSheetContents, Vector<CSSProperty, 256>* parsedProperties)
: m_range(range)
, m_context(context)
, m_styleSheetContents(styleSheetContents)
, m_parsedProperties(parsedProperties)
{
m_range.consumeWhitespace();
}
void CSSPropertyParser::addProperty(CSSPropertyID property, CSSPropertyID currentShorthand, Ref<CSSValue>&& value, bool important, bool implicit)
{
int shorthandIndex = 0;
bool setFromShorthand = false;
if (currentShorthand) {
auto shorthands = matchingShorthandsForLonghand(property);
setFromShorthand = true;
if (shorthands.size() > 1)
shorthandIndex = indexOfShorthandForLonghand(currentShorthand, shorthands);
}
m_parsedProperties->append(CSSProperty(property, WTFMove(value), important, setFromShorthand, shorthandIndex, implicit));
}
void CSSPropertyParser::addExpandedPropertyForValue(CSSPropertyID property, Ref<CSSValue>&& value, bool important)
{
const StylePropertyShorthand& shorthand = shorthandForProperty(property);
unsigned shorthandLength = shorthand.length();
ASSERT(shorthandLength);
const CSSPropertyID* longhands = shorthand.properties();
for (unsigned i = 0; i < shorthandLength; ++i)
addProperty(longhands[i], property, value.copyRef(), important);
}
bool CSSPropertyParser::parseValue(CSSPropertyID propertyID, bool important, const CSSParserTokenRange& range, const CSSParserContext& context, StyleSheetContents* styleSheetContents, ParsedPropertyVector& parsedProperties, StyleRule::Type ruleType)
{
int parsedPropertiesSize = parsedProperties.size();
CSSPropertyParser parser(range, context, styleSheetContents, &parsedProperties);
bool parseSuccess;
#if ENABLE(CSS_DEVICE_ADAPTATION)
if (ruleType == StyleRule::Viewport)
parseSuccess = parser.parseViewportDescriptor(propertyID, important);
else
#endif
if (ruleType == StyleRule::FontFace)
parseSuccess = parser.parseFontFaceDescriptor(propertyID);
else
parseSuccess = parser.parseValueStart(propertyID, important);
if (!parseSuccess)
parsedProperties.shrink(parsedPropertiesSize);
return parseSuccess;
}
RefPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID property, const CSSParserTokenRange& range, const CSSParserContext& context, StyleSheetContents* styleSheetContents)
{
CSSPropertyParser parser(range, context, styleSheetContents, nullptr);
RefPtr<CSSValue> value = parser.parseSingleValue(property);
if (!value || !parser.m_range.atEnd())
return nullptr;
return value;
}
static bool isLegacyBreakProperty(CSSPropertyID propertyID)
{
switch (propertyID) {
case CSSPropertyPageBreakAfter:
case CSSPropertyPageBreakBefore:
case CSSPropertyPageBreakInside:
case CSSPropertyWebkitColumnBreakAfter:
case CSSPropertyWebkitColumnBreakBefore:
case CSSPropertyWebkitColumnBreakInside:
#if ENABLE(CSS_REGIONS)
case CSSPropertyWebkitRegionBreakAfter:
case CSSPropertyWebkitRegionBreakBefore:
case CSSPropertyWebkitRegionBreakInside:
#endif
return true;
default:
break;
}
return false;
}
bool CSSPropertyParser::parseValueStart(CSSPropertyID propertyID, bool important)
{
if (consumeCSSWideKeyword(propertyID, important))
return true;
CSSParserTokenRange originalRange = m_range;
bool isShorthand = isShorthandCSSProperty(propertyID);
if (isShorthand) {
// Variable references will fail to parse here and will fall out to the variable ref parser below.
if (parseShorthand(propertyID, important))
return true;
} else if (isLegacyBreakProperty(propertyID)) {
// FIXME-NEWPARSER: Can turn this into a shorthand once old parser is gone, and then
// we don't need the special case.
if (consumeLegacyBreakProperty(propertyID, important))
return true;
} else {
RefPtr<CSSValue> parsedValue = parseSingleValue(propertyID);
if (parsedValue && m_range.atEnd()) {
addProperty(propertyID, CSSPropertyInvalid, *parsedValue, important);
return true;
}
}
if (CSSVariableParser::containsValidVariableReferences(originalRange)) {
RefPtr<CSSVariableReferenceValue> variable = CSSVariableReferenceValue::create(CSSVariableData::create(originalRange));
if (isShorthand) {
RefPtr<CSSPendingSubstitutionValue> pendingValue = CSSPendingSubstitutionValue::create(propertyID, variable.releaseNonNull());
addExpandedPropertyForValue(propertyID, pendingValue.releaseNonNull(), important);
} else
addProperty(propertyID, CSSPropertyInvalid, variable.releaseNonNull(), important);
return true;
}
return false;
}
bool CSSPropertyParser::consumeCSSWideKeyword(CSSPropertyID propertyID, bool important)
{
CSSParserTokenRange rangeCopy = m_range;
CSSValueID valueID = rangeCopy.consumeIncludingWhitespace().id();
if (!rangeCopy.atEnd())
return false;
RefPtr<CSSValue> value;
if (valueID == CSSValueInherit)
value = CSSValuePool::singleton().createInheritedValue();
else if (valueID == CSSValueInitial)
value = CSSValuePool::singleton().createExplicitInitialValue();
else if (valueID == CSSValueUnset)
value = CSSValuePool::singleton().createUnsetValue();
else if (valueID == CSSValueRevert)
value = CSSValuePool::singleton().createRevertValue();
else
return false;
const StylePropertyShorthand& shorthand = shorthandForProperty(propertyID);
if (!shorthand.length()) {
if (CSSProperty::isDescriptorOnly(propertyID))
return false;
addProperty(propertyID, CSSPropertyInvalid, value.releaseNonNull(), important);
} else
addExpandedPropertyForValue(propertyID, value.releaseNonNull(), important);
m_range = rangeCopy;
return true;
}
bool CSSPropertyParser::consumeTransformOrigin(bool important)
{
RefPtr<CSSPrimitiveValue> resultX;
RefPtr<CSSPrimitiveValue> resultY;
if (consumeOneOrTwoValuedPosition(m_range, m_context.mode, UnitlessQuirk::Forbid, resultX, resultY)) {
m_range.consumeWhitespace();
bool atEnd = m_range.atEnd();
RefPtr<CSSPrimitiveValue> resultZ = consumeLength(m_range, m_context.mode, ValueRangeAll);
bool hasZ = resultZ;
if (!hasZ && !atEnd)
return false;
addProperty(CSSPropertyTransformOriginX, CSSPropertyTransformOrigin, resultX.releaseNonNull(), important);
addProperty(CSSPropertyTransformOriginY, CSSPropertyTransformOrigin, resultY.releaseNonNull(), important);
addProperty(CSSPropertyTransformOriginZ, CSSPropertyTransformOrigin, resultZ ? resultZ.releaseNonNull() : CSSValuePool::singleton().createValue(0, CSSPrimitiveValue::UnitType::CSS_PX), important, !hasZ);
return true;
}
return false;
}
bool CSSPropertyParser::consumePerspectiveOrigin(bool important)
{
RefPtr<CSSPrimitiveValue> resultX;
RefPtr<CSSPrimitiveValue> resultY;
if (consumePosition(m_range, m_context.mode, UnitlessQuirk::Forbid, resultX, resultY)) {
addProperty(CSSPropertyPerspectiveOriginX, CSSPropertyPerspectiveOrigin, resultX.releaseNonNull(), important);
addProperty(CSSPropertyPerspectiveOriginY, CSSPropertyPerspectiveOrigin, resultY.releaseNonNull(), important);
return true;
}
return false;
}
// Methods for consuming non-shorthand properties starts here.
static RefPtr<CSSValue> consumeWillChange(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueAuto)
return consumeIdent(range);
RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
// Every comma-separated list of identifiers is a valid will-change value,
// unless the list includes an explicitly disallowed identifier.
while (true) {
if (range.peek().type() != IdentToken)
return nullptr;
CSSPropertyID propertyID = cssPropertyID(range.peek().value());
if (propertyID != CSSPropertyInvalid) {
// Now "all" is used by both CSSValue and CSSPropertyValue.
// Need to return nullptr when currentValue is CSSPropertyAll.
if (propertyID == CSSPropertyWillChange || propertyID == CSSPropertyAll)
return nullptr;
// FIXME-NEWPARSER: Use CSSCustomIdentValue someday.
values->append(CSSValuePool::singleton().createIdentifierValue(propertyID));
range.consumeIncludingWhitespace();
} else {
switch (range.peek().id()) {
case CSSValueNone:
case CSSValueAll:
case CSSValueAuto:
case CSSValueDefault:
case CSSValueInitial:
case CSSValueInherit:
return nullptr;
case CSSValueContents:
case CSSValueScrollPosition:
values->append(consumeIdent(range).releaseNonNull());
break;
default:
// Append properties we don't recognize, but that are legal, as strings.
values->append(consumeCustomIdent(range).releaseNonNull());
break;
}
}
if (range.atEnd())
break;
if (!consumeCommaIncludingWhitespace(range))
return nullptr;
}
return values;
}
static RefPtr<CSSFontFeatureValue> consumeFontFeatureTag(CSSParserTokenRange& range)
{
// Feature tag name consists of 4-letter characters.
static const unsigned tagNameLength = 4;
const CSSParserToken& token = range.consumeIncludingWhitespace();
// Feature tag name comes first
if (token.type() != StringToken)
return nullptr;
if (token.value().length() != tagNameLength)
return nullptr;
FontTag tag;
for (unsigned i = 0; i < tag.size(); ++i) {
// Limits the range of characters to 0x20-0x7E, following the tag name rules defiend in the OpenType specification.
UChar character = token.value()[i];
if (character < 0x20 || character > 0x7E)
return nullptr;
tag[i] = toASCIILower(character);
}
int tagValue = 1;
// Feature tag values could follow: <integer> | on | off
if (range.peek().type() == NumberToken && range.peek().numericValueType() == IntegerValueType && range.peek().numericValue() >= 0) {
tagValue = clampTo<int>(range.consumeIncludingWhitespace().numericValue());
if (tagValue < 0)
return nullptr;
} else if (range.peek().id() == CSSValueOn || range.peek().id() == CSSValueOff) {
tagValue = range.consumeIncludingWhitespace().id() == CSSValueOn;
}
return CSSFontFeatureValue::create(WTFMove(tag), tagValue);
}
static RefPtr<CSSValue> consumeFontFeatureSettings(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueNormal)
return consumeIdent(range);
RefPtr<CSSValueList> settings = CSSValueList::createCommaSeparated();
do {
RefPtr<CSSFontFeatureValue> fontFeatureValue = consumeFontFeatureTag(range);
if (!fontFeatureValue)
return nullptr;
settings->append(fontFeatureValue.releaseNonNull());
} while (consumeCommaIncludingWhitespace(range));
return settings;
}
#if ENABLE(VARIATION_FONTS)
static RefPtr<CSSValue> consumeFontVariationTag(CSSParserTokenRange& range)
{
if (range.peek().type() != StringToken)
return nullptr;
auto string = range.consumeIncludingWhitespace().value().toString();
FontTag tag;
if (string.length() != tag.size())
return nullptr;
for (unsigned i = 0; i < tag.size(); ++i) {
// Limits the range of characters to 0x20-0x7E, following the tag name rules defiend in the OpenType specification.
UChar character = string[i];
if (character < 0x20 || character > 0x7E)
return nullptr;
tag[i] = character;
}
if (range.atEnd() || range.peek().type() != NumberToken)
return nullptr;
float tagValue = range.consumeIncludingWhitespace().numericValue();
return CSSFontVariationValue::create(tag, tagValue);
}
static RefPtr<CSSValue> consumeFontVariationSettings(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueNormal)
return consumeIdent(range);
auto settings = CSSValueList::createCommaSeparated();
do {
RefPtr<CSSValue> variationValue = consumeFontVariationTag(range);
if (!variationValue)
return nullptr;
settings->append(variationValue.releaseNonNull());
} while (consumeCommaIncludingWhitespace(range));
if (!settings->length())
return nullptr;
return WTFMove(settings);
}
#endif // ENABLE(VARIATION_FONTS)
static RefPtr<CSSValue> consumePage(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueAuto)
return consumeIdent(range);
return consumeCustomIdent(range);
}
static RefPtr<CSSValue> consumeQuotes(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
while (!range.atEnd()) {
RefPtr<CSSPrimitiveValue> parsedValue = consumeString(range);
if (!parsedValue)
return nullptr;
values->append(parsedValue.releaseNonNull());
}
if (values->length() && values->length() % 2 == 0)
return values;
return nullptr;
}
class FontVariantLigaturesParser {
public:
FontVariantLigaturesParser()
: m_sawCommonLigaturesValue(false)
, m_sawDiscretionaryLigaturesValue(false)
, m_sawHistoricalLigaturesValue(false)
, m_sawContextualLigaturesValue(false)
, m_result(CSSValueList::createSpaceSeparated())
{
}
enum class ParseResult {
ConsumedValue,
DisallowedValue,
UnknownValue
};
ParseResult consumeLigature(CSSParserTokenRange& range)
{
CSSValueID valueID = range.peek().id();
switch (valueID) {
case CSSValueNoCommonLigatures:
case CSSValueCommonLigatures:
if (m_sawCommonLigaturesValue)
return ParseResult::DisallowedValue;
m_sawCommonLigaturesValue = true;
break;
case CSSValueNoDiscretionaryLigatures:
case CSSValueDiscretionaryLigatures:
if (m_sawDiscretionaryLigaturesValue)
return ParseResult::DisallowedValue;
m_sawDiscretionaryLigaturesValue = true;
break;
case CSSValueNoHistoricalLigatures:
case CSSValueHistoricalLigatures:
if (m_sawHistoricalLigaturesValue)
return ParseResult::DisallowedValue;
m_sawHistoricalLigaturesValue = true;
break;
case CSSValueNoContextual:
case CSSValueContextual:
if (m_sawContextualLigaturesValue)
return ParseResult::DisallowedValue;
m_sawContextualLigaturesValue = true;
break;
default:
return ParseResult::UnknownValue;
}
m_result->append(consumeIdent(range).releaseNonNull());
return ParseResult::ConsumedValue;
}
RefPtr<CSSValue> finalizeValue()
{
if (!m_result->length())
return CSSValuePool::singleton().createIdentifierValue(CSSValueNormal);
return m_result.release();
}
private:
bool m_sawCommonLigaturesValue;
bool m_sawDiscretionaryLigaturesValue;
bool m_sawHistoricalLigaturesValue;
bool m_sawContextualLigaturesValue;
RefPtr<CSSValueList> m_result;
};
static RefPtr<CSSValue> consumeFontVariantLigatures(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueNormal || range.peek().id() == CSSValueNone)
return consumeIdent(range);
FontVariantLigaturesParser ligaturesParser;
do {
if (ligaturesParser.consumeLigature(range) !=
FontVariantLigaturesParser::ParseResult::ConsumedValue)
return nullptr;
} while (!range.atEnd());
return ligaturesParser.finalizeValue();
}
static RefPtr<CSSValue> consumeFontVariantEastAsian(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueNormal)
return consumeIdent(range);
RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
FontVariantEastAsianVariant variant = FontVariantEastAsianVariant::Normal;
FontVariantEastAsianWidth width = FontVariantEastAsianWidth::Normal;
FontVariantEastAsianRuby ruby = FontVariantEastAsianRuby::Normal;
while (!range.atEnd()) {
if (range.peek().type() != IdentToken)
return nullptr;
auto id = range.peek().id();
switch (id) {
case CSSValueJis78:
variant = FontVariantEastAsianVariant::Jis78;
break;
case CSSValueJis83:
variant = FontVariantEastAsianVariant::Jis83;
break;
case CSSValueJis90:
variant = FontVariantEastAsianVariant::Jis90;
break;
case CSSValueJis04:
variant = FontVariantEastAsianVariant::Jis04;
break;
case CSSValueSimplified:
variant = FontVariantEastAsianVariant::Simplified;
break;
case CSSValueTraditional:
variant = FontVariantEastAsianVariant::Traditional;
break;
case CSSValueFullWidth:
width = FontVariantEastAsianWidth::Full;
break;
case CSSValueProportionalWidth:
width = FontVariantEastAsianWidth::Proportional;
break;
case CSSValueRuby:
ruby = FontVariantEastAsianRuby::Yes;
break;
default:
return nullptr;
}
range.consumeIncludingWhitespace();
}
switch (variant) {
case FontVariantEastAsianVariant::Normal:
break;
case FontVariantEastAsianVariant::Jis78:
values->append(CSSValuePool::singleton().createIdentifierValue(CSSValueJis78));
break;
case FontVariantEastAsianVariant::Jis83:
values->append(CSSValuePool::singleton().createIdentifierValue(CSSValueJis83));
break;
case FontVariantEastAsianVariant::Jis90:
values->append(CSSValuePool::singleton().createIdentifierValue(CSSValueJis90));
break;
case FontVariantEastAsianVariant::Jis04:
values->append(CSSValuePool::singleton().createIdentifierValue(CSSValueJis04));
break;
case FontVariantEastAsianVariant::Simplified:
values->append(CSSValuePool::singleton().createIdentifierValue(CSSValueSimplified));
break;
case FontVariantEastAsianVariant::Traditional:
values->append(CSSValuePool::singleton().createIdentifierValue(CSSValueTraditional));
break;
}
switch (width) {
case FontVariantEastAsianWidth::Normal:
break;
case FontVariantEastAsianWidth::Full:
values->append(CSSValuePool::singleton().createIdentifierValue(CSSValueFullWidth));
break;
case FontVariantEastAsianWidth::Proportional:
values->append(CSSValuePool::singleton().createIdentifierValue(CSSValueProportionalWidth));
break;
}
switch (ruby) {
case FontVariantEastAsianRuby::Normal:
break;
case FontVariantEastAsianRuby::Yes:
values->append(CSSValuePool::singleton().createIdentifierValue(CSSValueRuby));
}
if (!values->length())
return nullptr;
return values;
}
static RefPtr<CSSPrimitiveValue> consumeFontVariantCaps(CSSParserTokenRange& range)
{
return consumeIdent<CSSValueNormal, CSSValueSmallCaps, CSSValueAllSmallCaps,
CSSValuePetiteCaps, CSSValueAllPetiteCaps,
CSSValueUnicase, CSSValueTitlingCaps>(range);
}
static RefPtr<CSSPrimitiveValue> consumeFontVariantAlternates(CSSParserTokenRange& range)
{
return consumeIdent<CSSValueNormal, CSSValueHistoricalForms>(range);
}
static RefPtr<CSSPrimitiveValue> consumeFontVariantPosition(CSSParserTokenRange& range)
{
return consumeIdent<CSSValueNormal, CSSValueSub, CSSValueSuper>(range);
}
class FontVariantNumericParser {
public:
FontVariantNumericParser()
: m_sawNumericFigureValue(false)
, m_sawNumericSpacingValue(false)
, m_sawNumericFractionValue(false)
, m_sawOrdinalValue(false)
, m_sawSlashedZeroValue(false)
, m_result(CSSValueList::createSpaceSeparated())
{
}
enum class ParseResult {
ConsumedValue,
DisallowedValue,
UnknownValue
};
ParseResult consumeNumeric(CSSParserTokenRange& range)
{
CSSValueID valueID = range.peek().id();
switch (valueID) {
case CSSValueLiningNums:
case CSSValueOldstyleNums:
if (m_sawNumericFigureValue)
return ParseResult::DisallowedValue;
m_sawNumericFigureValue = true;
break;
case CSSValueProportionalNums:
case CSSValueTabularNums:
if (m_sawNumericSpacingValue)
return ParseResult::DisallowedValue;
m_sawNumericSpacingValue = true;
break;
case CSSValueDiagonalFractions:
case CSSValueStackedFractions:
if (m_sawNumericFractionValue)
return ParseResult::DisallowedValue;
m_sawNumericFractionValue = true;
break;
case CSSValueOrdinal:
if (m_sawOrdinalValue)
return ParseResult::DisallowedValue;
m_sawOrdinalValue = true;
break;
case CSSValueSlashedZero:
if (m_sawSlashedZeroValue)
return ParseResult::DisallowedValue;
m_sawSlashedZeroValue = true;
break;
default:
return ParseResult::UnknownValue;
}
m_result->append(consumeIdent(range).releaseNonNull());
return ParseResult::ConsumedValue;
}
RefPtr<CSSValue> finalizeValue()
{
if (!m_result->length())
return CSSValuePool::singleton().createIdentifierValue(CSSValueNormal);
return m_result.release();
}
private:
bool m_sawNumericFigureValue;
bool m_sawNumericSpacingValue;
bool m_sawNumericFractionValue;
bool m_sawOrdinalValue;
bool m_sawSlashedZeroValue;
RefPtr<CSSValueList> m_result;
};
static RefPtr<CSSValue> consumeFontVariantNumeric(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueNormal)
return consumeIdent(range);
FontVariantNumericParser numericParser;
do {
if (numericParser.consumeNumeric(range) !=
FontVariantNumericParser::ParseResult::ConsumedValue)
return nullptr;
} while (!range.atEnd());
return numericParser.finalizeValue();
}
static RefPtr<CSSPrimitiveValue> consumeFontVariantCSS21(CSSParserTokenRange& range)
{
return consumeIdent<CSSValueNormal, CSSValueSmallCaps>(range);
}
static RefPtr<CSSPrimitiveValue> consumeFontWeight(CSSParserTokenRange& range)
{
const CSSParserToken& token = range.peek();
if (token.id() >= CSSValueNormal && token.id() <= CSSValueLighter)
return consumeIdent(range);
int weight;
if (!consumePositiveIntegerRaw(range, weight))
return nullptr;
if ((weight % 100) || weight < 100 || weight > 900)
return nullptr;
return CSSValuePool::singleton().createIdentifierValue(static_cast<CSSValueID>(CSSValue100 + weight / 100 - 1));
}
static String concatenateFamilyName(CSSParserTokenRange& range)
{
StringBuilder builder;
bool addedSpace = false;
const CSSParserToken& firstToken = range.peek();
while (range.peek().type() == IdentToken) {
if (!builder.isEmpty()) {
builder.append(' ');
addedSpace = true;
}
builder.append(range.consumeIncludingWhitespace().value());
}
if (!addedSpace && isCSSWideKeyword(firstToken.id()))
return String();
return builder.toString();
}
static RefPtr<CSSValue> consumeFamilyName(CSSParserTokenRange& range)
{
if (range.peek().type() == StringToken)
return CSSValuePool::singleton().createFontFamilyValue(range.consumeIncludingWhitespace().value().toString());
if (range.peek().type() != IdentToken)
return nullptr;
String familyName = concatenateFamilyName(range);
if (familyName.isNull())
return nullptr;
return CSSValuePool::singleton().createFontFamilyValue(familyName);
}
static RefPtr<CSSValue> consumeGenericFamily(CSSParserTokenRange& range)
{
return consumeIdentRange(range, CSSValueSerif, CSSValueWebkitBody);
}
static RefPtr<CSSValueList> consumeFontFamily(CSSParserTokenRange& range)
{
RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
do {
RefPtr<CSSValue> parsedValue = consumeGenericFamily(range);
if (parsedValue) {
list->append(parsedValue.releaseNonNull());
} else {
parsedValue = consumeFamilyName(range);
if (parsedValue) {
list->append(parsedValue.releaseNonNull());
} else {
return nullptr;
}
}
} while (consumeCommaIncludingWhitespace(range));
return list;
}
static RefPtr<CSSValueList> consumeFontFamilyDescriptor(CSSParserTokenRange& range)
{
// FIXME-NEWPARSER: For compatibility with the old parser, we have to make
// a list here, even though the list always contains only a single family name.
// Once the old parser is gone, we can delete this function, make the caller
// use consumeFamilyName instead, and then patch the @font-face code to
// not expect a list with a single name in it.
RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
RefPtr<CSSValue> parsedValue = consumeFamilyName(range);
if (parsedValue)
list->append(parsedValue.releaseNonNull());
if (!range.atEnd() || !list->length())
return nullptr;
return list;
}
static RefPtr<CSSValue> consumeFontSynthesis(CSSParserTokenRange& range)
{
// none | [ weight || style || small-caps ]
CSSValueID id = range.peek().id();
if (id == CSSValueNone)
return consumeIdent(range);
RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
while (true) {
auto ident = consumeIdent<CSSValueWeight, CSSValueStyle, CSSValueSmallCaps>(range);
if (!ident)
break;
if (list->hasValue(ident.get()))
return nullptr;
list->append(ident.releaseNonNull());
}
if (!list->length())
return nullptr;
return list;
}
static RefPtr<CSSValue> consumeLetterSpacing(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
if (range.peek().id() == CSSValueNormal)
return consumeIdent(range);
return consumeLength(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Allow);
}
static RefPtr<CSSValue> consumeWordSpacing(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
if (range.peek().id() == CSSValueNormal)
return consumeIdent(range);
return consumeLengthOrPercent(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Allow);
}
static RefPtr<CSSValue> consumeTabSize(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
RefPtr<CSSPrimitiveValue> parsedValue = consumeInteger(range, 0);
if (parsedValue)
return parsedValue;
return consumeLength(range, cssParserMode, ValueRangeNonNegative);
}
#if ENABLE(TEXT_AUTOSIZING)
static RefPtr<CSSValue> consumeTextSizeAdjust(CSSParserTokenRange& range, CSSParserMode /* cssParserMode */)
{
if (range.peek().id() == CSSValueAuto)
return consumeIdent(range);
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
return consumePercent(range, ValueRangeNonNegative);
}
#endif
static RefPtr<CSSValue> consumeFontSize(CSSParserTokenRange& range, CSSParserMode cssParserMode, UnitlessQuirk unitless = UnitlessQuirk::Forbid)
{
if (range.peek().id() >= CSSValueXxSmall && range.peek().id() <= CSSValueLarger)
return consumeIdent(range);
return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative, unitless);
}
static RefPtr<CSSPrimitiveValue> consumeLineHeight(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
if (range.peek().id() == CSSValueNormal)
return consumeIdent(range);
RefPtr<CSSPrimitiveValue> lineHeight = consumeNumber(range, ValueRangeNonNegative);
if (lineHeight)
return lineHeight;
return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative);
}
template<typename... Args>
static Ref<CSSPrimitiveValue> createPrimitiveValuePair(Args&&... args)
{
return CSSValuePool::singleton().createValue(Pair::create(std::forward<Args>(args)...));
}
static RefPtr<CSSValue> consumeCounter(CSSParserTokenRange& range, int defaultValue)
{
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
do {
RefPtr<CSSPrimitiveValue> counterName = consumeCustomIdent(range);
if (!counterName)
return nullptr;
int i = defaultValue;
if (RefPtr<CSSPrimitiveValue> counterValue = consumeInteger(range))
i = counterValue->intValue();
list->append(createPrimitiveValuePair(counterName.releaseNonNull(), CSSPrimitiveValue::create(i, CSSPrimitiveValue::UnitType::CSS_NUMBER), Pair::IdenticalValueEncoding::Coalesce));
} while (!range.atEnd());
return list;
}
static RefPtr<CSSValue> consumePageSize(CSSParserTokenRange& range)
{
return consumeIdent<CSSValueA3, CSSValueA4, CSSValueA5, CSSValueB4, CSSValueB5, CSSValueLedger, CSSValueLegal, CSSValueLetter>(range);
}
static RefPtr<CSSValueList> consumeSize(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
RefPtr<CSSValueList> result = CSSValueList::createSpaceSeparated();
if (range.peek().id() == CSSValueAuto) {
result->append(consumeIdent(range).releaseNonNull());
return result;
}
if (RefPtr<CSSValue> width = consumeLength(range, cssParserMode, ValueRangeNonNegative)) {
RefPtr<CSSValue> height = consumeLength(range, cssParserMode, ValueRangeNonNegative);
result->append(width.releaseNonNull());
if (height)
result->append(height.releaseNonNull());
return result;
}
RefPtr<CSSValue> pageSize = consumePageSize(range);
RefPtr<CSSValue> orientation = consumeIdent<CSSValuePortrait, CSSValueLandscape>(range);
if (!pageSize)
pageSize = consumePageSize(range);
if (!orientation && !pageSize)
return nullptr;
if (pageSize)
result->append(pageSize.releaseNonNull());
if (orientation)
result->append(orientation.releaseNonNull());
return result;
}
static RefPtr<CSSValue> consumeTextIndent(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
// [ <length> | <percentage> ] && hanging? && each-line?
// Keywords only allowed when css3Text is enabled.
RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
bool hasLengthOrPercentage = false;
// bool hasEachLine = false;
bool hasHanging = false;
do {
if (!hasLengthOrPercentage) {
if (RefPtr<CSSValue> textIndent = consumeLengthOrPercent(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Allow)) {
list->append(*textIndent);
hasLengthOrPercentage = true;
continue;
}
}
CSSValueID id = range.peek().id();
/* FIXME-NEWPARSER: We don't support this yet.
if (!hasEachLine && id == CSSValueEachLine) {
list->append(*consumeIdent(range));
hasEachLine = true;
continue;
}
*/
if (!hasHanging && id == CSSValueHanging) {
list->append(consumeIdent(range).releaseNonNull());
hasHanging = true;
continue;
}
return nullptr;
} while (!range.atEnd());
if (!hasLengthOrPercentage)
return nullptr;
return list;
}
// FIXME-NEWPARSER: Drop the prefix on min-content, max-content and fit-content.
static bool validWidthOrHeightKeyword(CSSValueID id, const CSSParserContext& /*context*/)
{
if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic || id == CSSValueWebkitMinContent || id == CSSValueWebkitMaxContent || id == CSSValueWebkitFillAvailable || id == CSSValueWebkitFitContent) {
return true;
}
return false;
}
static RefPtr<CSSValue> consumeMaxWidthOrHeight(CSSParserTokenRange& range, const CSSParserContext& context, UnitlessQuirk unitless = UnitlessQuirk::Forbid)
{
if (range.peek().id() == CSSValueNone || validWidthOrHeightKeyword(range.peek().id(), context))
return consumeIdent(range);
return consumeLengthOrPercent(range, context.mode, ValueRangeNonNegative, unitless);
}
static RefPtr<CSSValue> consumeWidthOrHeight(CSSParserTokenRange& range, const CSSParserContext& context, UnitlessQuirk unitless = UnitlessQuirk::Forbid)
{
if (range.peek().id() == CSSValueAuto || validWidthOrHeightKeyword(range.peek().id(), context))
return consumeIdent(range);
return consumeLengthOrPercent(range, context.mode, ValueRangeNonNegative, unitless);
}
static RefPtr<CSSValue> consumeMarginOrOffset(CSSParserTokenRange& range, CSSParserMode cssParserMode, UnitlessQuirk unitless)
{
if (range.peek().id() == CSSValueAuto)
return consumeIdent(range);
return consumeLengthOrPercent(range, cssParserMode, ValueRangeAll, unitless);
}
static RefPtr<CSSPrimitiveValue> consumeClipComponent(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
if (range.peek().id() == CSSValueAuto)
return consumeIdent(range);
return consumeLength(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Allow);
}
static RefPtr<CSSValue> consumeClip(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
if (range.peek().id() == CSSValueAuto)
return consumeIdent(range);
if (range.peek().functionId() != CSSValueRect)
return nullptr;
CSSParserTokenRange args = consumeFunction(range);
// rect(t, r, b, l) || rect(t r b l)
RefPtr<CSSPrimitiveValue> top = consumeClipComponent(args, cssParserMode);
if (!top)
return nullptr;
bool needsComma = consumeCommaIncludingWhitespace(args);
RefPtr<CSSPrimitiveValue> right = consumeClipComponent(args, cssParserMode);
if (!right || (needsComma && !consumeCommaIncludingWhitespace(args)))
return nullptr;
RefPtr<CSSPrimitiveValue> bottom = consumeClipComponent(args, cssParserMode);
if (!bottom || (needsComma && !consumeCommaIncludingWhitespace(args)))
return nullptr;
RefPtr<CSSPrimitiveValue> left = consumeClipComponent(args, cssParserMode);
if (!left || !args.atEnd())
return nullptr;
auto rect = Rect::create();
rect->setLeft(left.releaseNonNull());
rect->setTop(top.releaseNonNull());
rect->setRight(right.releaseNonNull());
rect->setBottom(bottom.releaseNonNull());
return CSSValuePool::singleton().createValue(WTFMove(rect));
}
#if ENABLE(TOUCH_EVENTS)
static RefPtr<CSSValue> consumeTouchAction(CSSParserTokenRange& range)
{
RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
CSSValueID id = range.peek().id();
if (id == CSSValueAuto || id == CSSValueNone || id == CSSValueManipulation) {
list->append(consumeIdent(range).releaseNonNull());
return list;
}
// FIXME-NEWPARSER: Support pan.
return nullptr;
}
#endif
static RefPtr<CSSPrimitiveValue> consumeLineClamp(CSSParserTokenRange& range)
{
RefPtr<CSSPrimitiveValue> clampValue = consumePercent(range, ValueRangeNonNegative);
if (clampValue)
return clampValue;
// When specifying number of lines, don't allow 0 as a valid value.
return consumePositiveInteger(range);
}
static RefPtr<CSSValue> consumeLocale(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueAuto)
return consumeIdent(range);
return consumeString(range);
}
static RefPtr<CSSValue> consumeHyphenateLimit(CSSParserTokenRange& range, CSSValueID valueID)
{
if (range.peek().id() == valueID)
return consumeIdent(range);
return consumeNumber(range, ValueRangeNonNegative);
}
static RefPtr<CSSValue> consumeColumnWidth(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueAuto)
return consumeIdent(range);
// Always parse lengths in strict mode here, since it would be ambiguous otherwise when used in
// the 'columns' shorthand property.
RefPtr<CSSPrimitiveValue> columnWidth = consumeLength(range, HTMLStandardMode, ValueRangeNonNegative);
if (!columnWidth || (!columnWidth->isCalculated() && !columnWidth->doubleValue()) || (columnWidth->cssCalcValue() && !columnWidth->cssCalcValue()->doubleValue()))
return nullptr;
return columnWidth;
}
static RefPtr<CSSValue> consumeColumnCount(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueAuto)
return consumeIdent(range);
return consumePositiveInteger(range);
}
static RefPtr<CSSValue> consumeColumnGap(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
if (range.peek().id() == CSSValueNormal)
return consumeIdent(range);
return consumeLength(range, cssParserMode, ValueRangeNonNegative);
}
static RefPtr<CSSValue> consumeColumnSpan(CSSParserTokenRange& range)
{
return consumeIdent<CSSValueAll, CSSValueNone>(range);
}
static RefPtr<CSSValue> consumeZoom(CSSParserTokenRange& range, const CSSParserContext& /*context*/)
{
const CSSParserToken& token = range.peek();
RefPtr<CSSPrimitiveValue> zoom;
if (token.type() == IdentToken)
zoom = consumeIdent<CSSValueNormal, CSSValueReset, CSSValueDocument>(range);
else {
zoom = consumePercent(range, ValueRangeNonNegative);
if (!zoom)
zoom = consumeNumber(range, ValueRangeNonNegative);
}
return zoom;
}
static RefPtr<CSSValue> consumeAnimationIterationCount(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueInfinite)
return consumeIdent(range);
return consumeNumber(range, ValueRangeNonNegative);
}
static RefPtr<CSSValue> consumeAnimationName(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
if (range.peek().type() == StringToken) {
const CSSParserToken& token = range.consumeIncludingWhitespace();
if (equalIgnoringASCIICase(token.value(), "none"))
return CSSValuePool::singleton().createIdentifierValue(CSSValueNone);
// FIXME-NEWPARSER: Want to use a CSSCustomIdentValue here eventually.
return CSSValuePool::singleton().createValue(token.value().toString(), CSSPrimitiveValue::UnitType::CSS_STRING);
}
return consumeCustomIdent(range);
}
static RefPtr<CSSValue> consumeTransitionProperty(CSSParserTokenRange& range)
{
const CSSParserToken& token = range.peek();
if (token.type() != IdentToken)
return nullptr;
if (token.id() == CSSValueNone)
return consumeIdent(range);
if (CSSPropertyID property = token.parseAsCSSPropertyID()) {
range.consumeIncludingWhitespace();
// FIXME-NEWPARSER: No reason why we can't use the "all" property now that it exists.
// The old parser used a value keyword for "all", though, since it predated support for
// the property.
if (property == CSSPropertyAll)
return CSSValuePool::singleton().createIdentifierValue(CSSValueAll);
// FIXME-NEWPARSER: Want to use a CSSCustomIdentValue here eventually.
return CSSValuePool::singleton().createIdentifierValue(property);
}
return consumeCustomIdent(range);
}
static RefPtr<CSSValue> consumeSteps(CSSParserTokenRange& range) {
ASSERT(range.peek().functionId() == CSSValueSteps);
CSSParserTokenRange rangeCopy = range;
CSSParserTokenRange args = consumeFunction(rangeCopy);
RefPtr<CSSPrimitiveValue> steps = consumePositiveInteger(args);
if (!steps)
return nullptr;
// FIXME-NEWPARSER: Support the middle value and change from a boolean to an enum.
bool stepAtStart = false;
if (consumeCommaIncludingWhitespace(args)) {
switch (args.consumeIncludingWhitespace().id()) {
case CSSValueStart:
stepAtStart = true;
break;
case CSSValueEnd:
stepAtStart = false;
break;
default:
return nullptr;
}
}
if (!args.atEnd())
return nullptr;
range = rangeCopy;
return CSSStepsTimingFunctionValue::create(steps->intValue(), stepAtStart);
}
static RefPtr<CSSValue> consumeCubicBezier(CSSParserTokenRange& range)
{
ASSERT(range.peek().functionId() == CSSValueCubicBezier);
CSSParserTokenRange rangeCopy = range;
CSSParserTokenRange args = consumeFunction(rangeCopy);
double x1, y1, x2, y2;
if (consumeNumberRaw(args, x1)
&& x1 >= 0 && x1 <= 1
&& consumeCommaIncludingWhitespace(args)
&& consumeNumberRaw(args, y1)
&& consumeCommaIncludingWhitespace(args)
&& consumeNumberRaw(args, x2)
&& x2 >= 0 && x2 <= 1
&& consumeCommaIncludingWhitespace(args)
&& consumeNumberRaw(args, y2)
&& args.atEnd()) {
range = rangeCopy;
return CSSCubicBezierTimingFunctionValue::create(x1, y1, x2, y2);
}
return nullptr;
}
static RefPtr<CSSValue> consumeSpringFunction(CSSParserTokenRange& range)
{
ASSERT(range.peek().functionId() == CSSValueSpring);
CSSParserTokenRange rangeCopy = range;
CSSParserTokenRange args = consumeFunction(rangeCopy);
// Mass must be greater than 0.
double mass;
if (!consumeNumberRaw(args, mass) || mass <= 0)
return nullptr;
// Stiffness must be greater than 0.
double stiffness;
if (!consumeNumberRaw(args, stiffness) || stiffness <= 0)
return nullptr;
// Damping coefficient must be greater than or equal to 0.
double damping;
if (!consumeNumberRaw(args, damping) || damping < 0)
return nullptr;
// Initial velocity may have any value.
double initialVelocity;
if (!consumeNumberRaw(args, initialVelocity))
return nullptr;
if (!args.atEnd())
return nullptr;
range = rangeCopy;
return CSSSpringTimingFunctionValue::create(mass, stiffness, damping, initialVelocity);
}
static RefPtr<CSSValue> consumeAnimationTimingFunction(CSSParserTokenRange& range, const CSSParserContext& context)
{
CSSValueID id = range.peek().id();
if (id == CSSValueEase || id == CSSValueLinear || id == CSSValueEaseIn
|| id == CSSValueEaseOut || id == CSSValueEaseInOut || id == CSSValueStepStart || id == CSSValueStepEnd)
return consumeIdent(range);
CSSValueID function = range.peek().functionId();
if (function == CSSValueCubicBezier)
return consumeCubicBezier(range);
if (function == CSSValueSteps)
return consumeSteps(range);
if (context.springTimingFunctionEnabled && function == CSSValueSpring)
return consumeSpringFunction(range);
return nullptr;
}
#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
static RefPtr<CSSValue> consumeWebkitAnimationTrigger(CSSParserTokenRange& range, CSSParserMode mode)
{
if (range.peek().id() == CSSValueAuto)
return consumeIdent(range);
if (range.peek().functionId() != CSSValueContainerScroll)
return nullptr;
CSSParserTokenRange rangeCopy = range;
CSSParserTokenRange args = consumeFunction(rangeCopy);
RefPtr<CSSPrimitiveValue> startValue = consumeLength(args, mode, ValueRangeAll, UnitlessQuirk::Forbid);
if (!startValue)
return nullptr;
if (args.atEnd()) {
range = rangeCopy;
return CSSAnimationTriggerScrollValue::create(startValue.releaseNonNull());
}
if (!consumeCommaIncludingWhitespace(args))
return nullptr;
RefPtr<CSSPrimitiveValue> endValue = consumeLength(args, mode, ValueRangeAll, UnitlessQuirk::Forbid);
if (!endValue || !args.atEnd())
return nullptr;
range = rangeCopy;
return CSSAnimationTriggerScrollValue::create(startValue.releaseNonNull(), endValue.releaseNonNull());
}
#endif
static RefPtr<CSSValue> consumeAnimationValue(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& context)
{
switch (property) {
case CSSPropertyAnimationDelay:
case CSSPropertyTransitionDelay:
return consumeTime(range, context.mode, ValueRangeAll, UnitlessQuirk::Forbid);
case CSSPropertyAnimationDirection:
return consumeIdent<CSSValueNormal, CSSValueAlternate, CSSValueReverse, CSSValueAlternateReverse>(range);
case CSSPropertyAnimationDuration:
case CSSPropertyTransitionDuration:
return consumeTime(range, context.mode, ValueRangeNonNegative, UnitlessQuirk::Allow);
case CSSPropertyAnimationFillMode:
return consumeIdent<CSSValueNone, CSSValueForwards, CSSValueBackwards, CSSValueBoth>(range);
case CSSPropertyAnimationIterationCount:
return consumeAnimationIterationCount(range);
case CSSPropertyAnimationName:
return consumeAnimationName(range);
case CSSPropertyAnimationPlayState:
return consumeIdent<CSSValueRunning, CSSValuePaused>(range);
case CSSPropertyTransitionProperty:
return consumeTransitionProperty(range);
case CSSPropertyAnimationTimingFunction:
case CSSPropertyTransitionTimingFunction:
return consumeAnimationTimingFunction(range, context);
#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
case CSSPropertyWebkitAnimationTrigger:
return consumeWebkitAnimationTrigger(range, context.mode);
#endif
default:
ASSERT_NOT_REACHED();
return nullptr;
}
}
static bool isValidAnimationPropertyList(CSSPropertyID property, const CSSValueList& valueList)
{
if (property != CSSPropertyTransitionProperty || valueList.length() < 2)
return true;
for (auto& value : valueList) {
if (value->isPrimitiveValue() && downcast<CSSPrimitiveValue>(value.get()).isValueID()
&& downcast<CSSPrimitiveValue>(value.get()).valueID() == CSSValueNone)
return false;
}
return true;
}
static RefPtr<CSSValue> consumeAnimationPropertyList(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& context)
{
RefPtr<CSSValueList> list;
RefPtr<CSSValue> singleton;
do {
RefPtr<CSSValue> currentValue = consumeAnimationValue(property, range, context);
if (!currentValue)
return nullptr;
if (singleton && !list) {
list = CSSValueList::createCommaSeparated();
list->append(singleton.releaseNonNull());
}
if (list)
list->append(currentValue.releaseNonNull());
else
singleton = WTFMove(currentValue);
} while (consumeCommaIncludingWhitespace(range));
if (list) {
if (!isValidAnimationPropertyList(property, *list))
return nullptr;
ASSERT(list->length());
return list;
}
return singleton;
}
bool CSSPropertyParser::consumeAnimationShorthand(const StylePropertyShorthand& shorthand, bool important)
{
const unsigned longhandCount = shorthand.length();
RefPtr<CSSValueList> longhands[8];
ASSERT(longhandCount <= 8);
for (size_t i = 0; i < longhandCount; ++i)
longhands[i] = CSSValueList::createCommaSeparated();
do {
bool parsedLonghand[8] = { false };
do {
bool foundProperty = false;
for (size_t i = 0; i < longhandCount; ++i) {
if (parsedLonghand[i])
continue;
if (RefPtr<CSSValue> value = consumeAnimationValue(shorthand.properties()[i], m_range, m_context)) {
parsedLonghand[i] = true;
foundProperty = true;
longhands[i]->append(*value);
break;
}
}
if (!foundProperty)
return false;
} while (!m_range.atEnd() && m_range.peek().type() != CommaToken);
// FIXME: This will make invalid longhands, see crbug.com/386459
for (size_t i = 0; i < longhandCount; ++i) {
if (!parsedLonghand[i])
longhands[i]->append(CSSValuePool::singleton().createImplicitInitialValue());
parsedLonghand[i] = false;
}
} while (consumeCommaIncludingWhitespace(m_range));
for (size_t i = 0; i < longhandCount; ++i) {
if (!isValidAnimationPropertyList(shorthand.properties()[i], *longhands[i]))
return false;
}
for (size_t i = 0; i < longhandCount; ++i)
addProperty(shorthand.properties()[i], shorthand.id(), *longhands[i], important);
return m_range.atEnd();
}
static RefPtr<CSSValue> consumeZIndex(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueAuto)
return consumeIdent(range);
return consumeInteger(range);
}
static RefPtr<CSSValue> consumeShadow(CSSParserTokenRange& range, CSSParserMode cssParserMode, bool isBoxShadowProperty)
{
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
RefPtr<CSSValueList> shadowValueList = CSSValueList::createCommaSeparated();
do {
if (RefPtr<CSSShadowValue> shadowValue = consumeSingleShadow(range, cssParserMode, isBoxShadowProperty, isBoxShadowProperty))
shadowValueList->append(*shadowValue);
else
return nullptr;
} while (consumeCommaIncludingWhitespace(range));
return shadowValueList;
}
static RefPtr<CSSValue> consumeTextDecorationLine(CSSParserTokenRange& range)
{
CSSValueID id = range.peek().id();
if (id == CSSValueNone)
return consumeIdent(range);
RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
while (true) {
#if ENABLE(LETTERPRESS)
RefPtr<CSSPrimitiveValue> ident = consumeIdent<CSSValueBlink, CSSValueUnderline, CSSValueOverline, CSSValueLineThrough, CSSValueWebkitLetterpress>(range);
#else
RefPtr<CSSPrimitiveValue> ident = consumeIdent<CSSValueBlink, CSSValueUnderline, CSSValueOverline, CSSValueLineThrough>(range);
#endif
if (!ident)
break;
if (list->hasValue(ident.get()))
return nullptr;
list->append(ident.releaseNonNull());
}
if (!list->length())
return nullptr;
return list;
}
static RefPtr<CSSValue> consumeTextDecorationSkip(CSSParserTokenRange& range)
{
CSSValueID id = range.peek().id();
if (id == CSSValueNone)
return consumeIdent(range);
RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
while (true) {
auto ident = consumeIdent<CSSValueAuto, CSSValueInk, CSSValueObjects>(range);
if (!ident)
break;
if (list->hasValue(ident.get()))
return nullptr;
list->append(ident.releaseNonNull());
}
if (!list->length())
return nullptr;
return list;
}
static RefPtr<CSSValue> consumeTextEmphasisStyle(CSSParserTokenRange& range)
{
CSSValueID id = range.peek().id();
if (id == CSSValueNone)
return consumeIdent(range);
if (RefPtr<CSSValue> textEmphasisStyle = consumeString(range))
return textEmphasisStyle;
RefPtr<CSSPrimitiveValue> fill = consumeIdent<CSSValueFilled, CSSValueOpen>(range);
RefPtr<CSSPrimitiveValue> shape = consumeIdent<CSSValueDot, CSSValueCircle, CSSValueDoubleCircle, CSSValueTriangle, CSSValueSesame>(range);
if (!fill)
fill = consumeIdent<CSSValueFilled, CSSValueOpen>(range);
if (fill && shape) {
RefPtr<CSSValueList> parsedValues = CSSValueList::createSpaceSeparated();
parsedValues->append(fill.releaseNonNull());
parsedValues->append(shape.releaseNonNull());
return parsedValues;
}
if (fill)
return fill;
if (shape)
return shape;
return nullptr;
}
static RefPtr<CSSValue> consumeOutlineColor(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
// Allow the special focus color even in HTML Standard parsing mode.
if (range.peek().id() == CSSValueWebkitFocusRingColor)
return consumeIdent(range);
return consumeColor(range, cssParserMode);
}
static RefPtr<CSSPrimitiveValue> consumeLineWidth(CSSParserTokenRange& range, CSSParserMode cssParserMode, UnitlessQuirk unitless)
{
CSSValueID id = range.peek().id();
if (id == CSSValueThin || id == CSSValueMedium || id == CSSValueThick)
return consumeIdent(range);
return consumeLength(range, cssParserMode, ValueRangeNonNegative, unitless);
}
static RefPtr<CSSPrimitiveValue> consumeBorderWidth(CSSParserTokenRange& range, CSSParserMode cssParserMode, UnitlessQuirk unitless)
{
return consumeLineWidth(range, cssParserMode, unitless);
}
static RefPtr<CSSPrimitiveValue> consumeTextStrokeWidth(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
return consumeLineWidth(range, cssParserMode, UnitlessQuirk::Forbid);
}
static RefPtr<CSSPrimitiveValue> consumeColumnRuleWidth(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
return consumeLineWidth(range, cssParserMode, UnitlessQuirk::Forbid);
}
static bool consumeTranslate3d(CSSParserTokenRange& args, CSSParserMode cssParserMode, RefPtr<CSSFunctionValue>& transformValue)
{
unsigned numberOfArguments = 2;
RefPtr<CSSValue> parsedValue;
do {
parsedValue = consumeLengthOrPercent(args, cssParserMode, ValueRangeAll);
if (!parsedValue)
return false;
transformValue->append(*parsedValue);
if (!consumeCommaIncludingWhitespace(args))
return false;
} while (--numberOfArguments);
parsedValue = consumeLength(args, cssParserMode, ValueRangeAll);
if (!parsedValue)
return false;
transformValue->append(*parsedValue);
return true;
}
static bool consumeNumbers(CSSParserTokenRange& args, RefPtr<CSSFunctionValue>& transformValue, unsigned numberOfArguments)
{
do {
RefPtr<CSSPrimitiveValue> parsedValue = consumeNumber(args, ValueRangeAll);
if (!parsedValue)
return false;
transformValue->append(parsedValue.releaseNonNull());
if (--numberOfArguments && !consumeCommaIncludingWhitespace(args))
return false;
} while (numberOfArguments);
return true;
}
static bool consumePerspective(CSSParserTokenRange& args, CSSParserMode cssParserMode, RefPtr<CSSFunctionValue>& transformValue)
{
RefPtr<CSSPrimitiveValue> parsedValue = consumeLength(args, cssParserMode, ValueRangeNonNegative);
if (!parsedValue) {
double perspective;
if (!consumeNumberRaw(args, perspective) || perspective < 0)
return false;
parsedValue = CSSPrimitiveValue::create(perspective, CSSPrimitiveValue::UnitType::CSS_PX);
}
if (!parsedValue)
return false;
transformValue->append(parsedValue.releaseNonNull());
return true;
}
static RefPtr<CSSValue> consumeTransformValue(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
CSSValueID functionId = range.peek().functionId();
if (functionId == CSSValueInvalid)
return nullptr;
CSSParserTokenRange args = consumeFunction(range);
if (args.atEnd())
return nullptr;
RefPtr<CSSFunctionValue> transformValue = CSSFunctionValue::create(functionId);
RefPtr<CSSValue> parsedValue;
switch (functionId) {
case CSSValueRotate:
case CSSValueRotateX:
case CSSValueRotateY:
case CSSValueRotateZ:
case CSSValueSkewX:
case CSSValueSkewY:
case CSSValueSkew:
parsedValue = consumeAngle(args, cssParserMode, UnitlessQuirk::Forbid);
if (!parsedValue)
return nullptr;
if (functionId == CSSValueSkew && consumeCommaIncludingWhitespace(args)) {
transformValue->append(*parsedValue);
parsedValue = consumeAngle(args, cssParserMode, UnitlessQuirk::Forbid);
if (!parsedValue)
return nullptr;
}
break;
case CSSValueScaleX:
case CSSValueScaleY:
case CSSValueScaleZ:
case CSSValueScale:
parsedValue = consumeNumber(args, ValueRangeAll);
if (!parsedValue)
return nullptr;
if (functionId == CSSValueScale && consumeCommaIncludingWhitespace(args)) {
transformValue->append(*parsedValue);
parsedValue = consumeNumber(args, ValueRangeAll);
if (!parsedValue)
return nullptr;
}
break;
case CSSValuePerspective:
if (!consumePerspective(args, cssParserMode, transformValue))
return nullptr;
break;
case CSSValueTranslateX:
case CSSValueTranslateY:
case CSSValueTranslate:
parsedValue = consumeLengthOrPercent(args, cssParserMode, ValueRangeAll);
if (!parsedValue)
return nullptr;
if (functionId == CSSValueTranslate && consumeCommaIncludingWhitespace(args)) {
transformValue->append(*parsedValue);
parsedValue = consumeLengthOrPercent(args, cssParserMode, ValueRangeAll);
if (!parsedValue)
return nullptr;
}
break;
case CSSValueTranslateZ:
parsedValue = consumeLength(args, cssParserMode, ValueRangeAll);
break;
case CSSValueMatrix:
case CSSValueMatrix3d:
if (!consumeNumbers(args, transformValue, (functionId == CSSValueMatrix3d) ? 16 : 6))
return nullptr;
break;
case CSSValueScale3d:
if (!consumeNumbers(args, transformValue, 3))
return nullptr;
break;
case CSSValueRotate3d:
if (!consumeNumbers(args, transformValue, 3) || !consumeCommaIncludingWhitespace(args))
return nullptr;
parsedValue = consumeAngle(args, cssParserMode, UnitlessQuirk::Forbid);
if (!parsedValue)
return nullptr;
break;
case CSSValueTranslate3d:
if (!consumeTranslate3d(args, cssParserMode, transformValue))
return nullptr;
break;
default:
return nullptr;
}
if (parsedValue)
transformValue->append(*parsedValue);
if (!args.atEnd())
return nullptr;
return transformValue;
}
static RefPtr<CSSValue> consumeTransform(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
do {
RefPtr<CSSValue> parsedTransformValue = consumeTransformValue(range, cssParserMode);
if (!parsedTransformValue)
return nullptr;
list->append(parsedTransformValue.releaseNonNull());
} while (!range.atEnd());
return list;
}
template <CSSValueID start, CSSValueID end>
static RefPtr<CSSPrimitiveValue> consumePositionLonghand(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
if (range.peek().type() == IdentToken) {
CSSValueID id = range.peek().id();
int percent;
if (id == start)
percent = 0;
else if (id == CSSValueCenter)
percent = 50;
else if (id == end)
percent = 100;
else
return nullptr;
range.consumeIncludingWhitespace();
return CSSPrimitiveValue::create(percent, CSSPrimitiveValue::UnitType::CSS_PERCENTAGE);
}
return consumeLengthOrPercent(range, cssParserMode, ValueRangeAll);
}
static RefPtr<CSSPrimitiveValue> consumePositionX(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
return consumePositionLonghand<CSSValueLeft, CSSValueRight>(range, cssParserMode);
}
static RefPtr<CSSPrimitiveValue> consumePositionY(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
return consumePositionLonghand<CSSValueTop, CSSValueBottom>(range, cssParserMode);
}
static RefPtr<CSSValue> consumePaintStroke(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
RefPtr<CSSPrimitiveValue> url = consumeUrl(range);
if (url) {
RefPtr<CSSValue> parsedValue;
if (range.peek().id() == CSSValueNone)
parsedValue = consumeIdent(range);
else
parsedValue = consumeColor(range, cssParserMode);
if (parsedValue) {
RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
values->append(url.releaseNonNull());
values->append(parsedValue.releaseNonNull());
return values;
}
return url;
}
return consumeColor(range, cssParserMode);
}
static RefPtr<CSSValue> consumeGlyphOrientation(CSSParserTokenRange& range, CSSParserMode mode, CSSPropertyID property)
{
if (range.peek().id() == CSSValueAuto) {
if (property == CSSPropertyGlyphOrientationVertical)
return consumeIdent(range);
return nullptr;
}
return consumeAngle(range, mode, UnitlessQuirk::Allow);
}
static RefPtr<CSSValue> consumePaintOrder(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueNormal)
return consumeIdent(range);
Vector<CSSValueID, 3> paintTypeList;
RefPtr<CSSPrimitiveValue> fill;
RefPtr<CSSPrimitiveValue> stroke;
RefPtr<CSSPrimitiveValue> markers;
do {
CSSValueID id = range.peek().id();
if (id == CSSValueFill && !fill)
fill = consumeIdent(range);
else if (id == CSSValueStroke && !stroke)
stroke = consumeIdent(range);
else if (id == CSSValueMarkers && !markers)
markers = consumeIdent(range);
else
return nullptr;
paintTypeList.append(id);
} while (!range.atEnd());
// After parsing we serialize the paint-order list. Since it is not possible to
// pop a last list items from CSSValueList without bigger cost, we create the
// list after parsing.
CSSValueID firstPaintOrderType = paintTypeList.at(0);
RefPtr<CSSValueList> paintOrderList = CSSValueList::createSpaceSeparated();
switch (firstPaintOrderType) {
case CSSValueFill:
case CSSValueStroke:
paintOrderList->append(firstPaintOrderType == CSSValueFill ? fill.releaseNonNull() : stroke.releaseNonNull());
if (paintTypeList.size() > 1) {
if (paintTypeList.at(1) == CSSValueMarkers)
paintOrderList->append(markers.releaseNonNull());
}
break;
case CSSValueMarkers:
paintOrderList->append(markers.releaseNonNull());
if (paintTypeList.size() > 1) {
if (paintTypeList.at(1) == CSSValueStroke)
paintOrderList->append(stroke.releaseNonNull());
}
break;
default:
ASSERT_NOT_REACHED();
}
return paintOrderList;
}
static RefPtr<CSSValue> consumeNoneOrURI(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
return consumeUrl(range);
}
static RefPtr<CSSValue> consumeFlexBasis(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
// FIXME: Support intrinsic dimensions too.
if (range.peek().id() == CSSValueAuto)
return consumeIdent(range);
return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative);
}
static RefPtr<CSSValue> consumeKerning(CSSParserTokenRange& range, CSSParserMode mode)
{
RefPtr<CSSValue> result = consumeIdent<CSSValueAuto, CSSValueNormal>(range);
if (result)
return result;
return consumeLength(range, mode, ValueRangeAll, UnitlessQuirk::Allow);
}
static RefPtr<CSSValue> consumeStrokeDasharray(CSSParserTokenRange& range)
{
CSSValueID id = range.peek().id();
if (id == CSSValueNone)
return consumeIdent(range);
RefPtr<CSSValueList> dashes = CSSValueList::createCommaSeparated();
do {
RefPtr<CSSPrimitiveValue> dash = consumeLengthOrPercent(range, SVGAttributeMode, ValueRangeNonNegative);
if (!dash || (consumeCommaIncludingWhitespace(range) && range.atEnd()))
return nullptr;
dashes->append(dash.releaseNonNull());
} while (!range.atEnd());
return dashes;
}
static RefPtr<CSSPrimitiveValue> consumeBaselineShift(CSSParserTokenRange& range)
{
CSSValueID id = range.peek().id();
if (id == CSSValueBaseline || id == CSSValueSub || id == CSSValueSuper)
return consumeIdent(range);
return consumeLengthOrPercent(range, SVGAttributeMode, ValueRangeAll);
}
static RefPtr<CSSPrimitiveValue> consumeRxOrRy(CSSParserTokenRange& range)
{
// FIXME-NEWPARSER: We don't support auto values when mapping, so for now turn this
// off until we can figure out if we're even supposed to support it.
// if (range.peek().id() == CSSValueAuto)
// return consumeIdent(range);
return consumeLengthOrPercent(range, SVGAttributeMode, ValueRangeAll, UnitlessQuirk::Forbid);
}
static RefPtr<CSSValue> consumeCursor(CSSParserTokenRange& range, const CSSParserContext& context, bool inQuirksMode)
{
RefPtr<CSSValueList> list;
while (RefPtr<CSSValue> image = consumeImage(range, context, ConsumeGeneratedImage::Forbid)) {
double num;
IntPoint hotSpot(-1, -1);
bool hotSpotSpecified = false;
if (consumeNumberRaw(range, num)) {
hotSpot.setX(int(num));
if (!consumeNumberRaw(range, num))
return nullptr;
hotSpot.setY(int(num));
hotSpotSpecified = true;
}
if (!list)
list = CSSValueList::createCommaSeparated();
list->append(CSSCursorImageValue::create(image.releaseNonNull(), hotSpotSpecified, hotSpot));
if (!consumeCommaIncludingWhitespace(range))
return nullptr;
}
CSSValueID id = range.peek().id();
RefPtr<CSSValue> cursorType;
if (id == CSSValueHand) {
if (!inQuirksMode) // Non-standard behavior
return nullptr;
cursorType = CSSValuePool::singleton().createIdentifierValue(CSSValuePointer);
range.consumeIncludingWhitespace();
} else if ((id >= CSSValueAuto && id <= CSSValueWebkitZoomOut) || id == CSSValueCopy || id == CSSValueNone) {
cursorType = consumeIdent(range);
} else {
return nullptr;
}
if (!list)
return cursorType;
list->append(cursorType.releaseNonNull());
return list;
}
static RefPtr<CSSValue> consumeAttr(CSSParserTokenRange args, CSSParserContext context)
{
if (args.peek().type() != IdentToken)
return nullptr;
CSSParserToken token = args.consumeIncludingWhitespace();
auto attrName = token.value().toAtomicString();
if (context.isHTMLDocument)
attrName = attrName.convertToASCIILowercase();
if (!args.atEnd())
return nullptr;
// FIXME-NEWPARSER: We want to use a CSSCustomIdentValue here eventually for the attrName.
// FIXME-NEWPARSER: We want to use a CSSFunctionValue rather than relying on a custom
// attr() primitive value.
return CSSValuePool::singleton().createValue(attrName, CSSPrimitiveValue::CSS_ATTR);
}
static RefPtr<CSSValue> consumeCounterContent(CSSParserTokenRange args, bool counters)
{
RefPtr<CSSPrimitiveValue> identifier = consumeCustomIdent(args);
if (!identifier)
return nullptr;
RefPtr<CSSPrimitiveValue> separator;
if (!counters)
separator = CSSPrimitiveValue::create(String(), CSSPrimitiveValue::UnitType::CSS_STRING);
else {
if (!consumeCommaIncludingWhitespace(args) || args.peek().type() != StringToken)
return nullptr;
separator = CSSPrimitiveValue::create(args.consumeIncludingWhitespace().value().toString(), CSSPrimitiveValue::UnitType::CSS_STRING);
}
RefPtr<CSSPrimitiveValue> listStyle;
if (consumeCommaIncludingWhitespace(args)) {
CSSValueID id = args.peek().id();
if ((id != CSSValueNone && (id < CSSValueDisc || id > CSSValueKatakanaIroha)))
return nullptr;
listStyle = consumeIdent(args);
} else
listStyle = CSSValuePool::singleton().createIdentifierValue(CSSValueDecimal);
if (!args.atEnd())
return nullptr;
// FIXME-NEWPARSER: Should just have a CSSCounterValue.
return CSSValuePool::singleton().createValue(Counter::create(identifier.releaseNonNull(), listStyle.releaseNonNull(), separator.releaseNonNull()));
}
static RefPtr<CSSValue> consumeContent(CSSParserTokenRange& range, CSSParserContext context)
{
if (identMatches<CSSValueNone, CSSValueNormal>(range.peek().id()))
return consumeIdent(range);
RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
do {
RefPtr<CSSValue> parsedValue = consumeImage(range, context);
if (!parsedValue)
parsedValue = consumeIdent<CSSValueOpenQuote, CSSValueCloseQuote, CSSValueNoOpenQuote, CSSValueNoCloseQuote>(range);
if (!parsedValue)
parsedValue = consumeString(range);
if (!parsedValue) {
if (range.peek().functionId() == CSSValueAttr)
parsedValue = consumeAttr(consumeFunction(range), context);
else if (range.peek().functionId() == CSSValueCounter)
parsedValue = consumeCounterContent(consumeFunction(range), false);
else if (range.peek().functionId() == CSSValueCounters)
parsedValue = consumeCounterContent(consumeFunction(range), true);
if (!parsedValue)
return nullptr;
}
values->append(parsedValue.releaseNonNull());
} while (!range.atEnd());
return values;
}
static RefPtr<CSSPrimitiveValue> consumePerspective(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
RefPtr<CSSPrimitiveValue> parsedValue = consumeLength(range, cssParserMode, ValueRangeAll);
if (!parsedValue) {
// FIXME: Make this quirk only apply to the webkit prefixed version of the property.
double perspective;
if (!consumeNumberRaw(range, perspective))
return nullptr;
parsedValue = CSSPrimitiveValue::create(perspective, CSSPrimitiveValue::UnitType::CSS_PX);
}
if (parsedValue && (parsedValue->isCalculated() || parsedValue->doubleValue() > 0))
return parsedValue;
return nullptr;
}
#if ENABLE(CSS_SCROLL_SNAP)
static RefPtr<CSSValueList> consumeScrollSnapAlign(CSSParserTokenRange& range)
{
RefPtr<CSSValueList> alignmentValue = CSSValueList::createSpaceSeparated();
if (RefPtr<CSSPrimitiveValue> firstValue = consumeIdent<CSSValueNone, CSSValueStart, CSSValueCenter, CSSValueEnd>(range)) {
alignmentValue->append(firstValue.releaseNonNull());
if (auto secondValue = consumeIdent<CSSValueNone, CSSValueStart, CSSValueCenter, CSSValueEnd>(range))
alignmentValue->append(secondValue.releaseNonNull());
}
return alignmentValue->length() ? alignmentValue : nullptr;
}
static RefPtr<CSSValueList> consumeScrollSnapType(CSSParserTokenRange& range)
{
RefPtr<CSSValueList> typeValue = CSSValueList::createSpaceSeparated();
RefPtr<CSSPrimitiveValue> secondValue;
auto firstValue = consumeIdent<CSSValueX, CSSValueY, CSSValueBlock, CSSValueInline, CSSValueBoth>(range);
if (firstValue)
secondValue = consumeIdent<CSSValueProximity, CSSValueMandatory>(range);
else
firstValue = consumeIdent<CSSValueNone, CSSValueProximity, CSSValueMandatory>(range);
if (!firstValue)
return nullptr;
typeValue->append(firstValue.releaseNonNull());
if (secondValue)
typeValue->append(secondValue.releaseNonNull());
return typeValue;
}
#endif
static RefPtr<CSSValue> consumeBorderRadiusCorner(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
RefPtr<CSSPrimitiveValue> parsedValue1 = consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative);
if (!parsedValue1)
return nullptr;
RefPtr<CSSPrimitiveValue> parsedValue2 = consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative);
if (!parsedValue2)
parsedValue2 = parsedValue1;
return createPrimitiveValuePair(parsedValue1.releaseNonNull(), parsedValue2.releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce);
}
static RefPtr<CSSPrimitiveValue> consumeVerticalAlign(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
RefPtr<CSSPrimitiveValue> parsedValue = consumeIdentRange(range, CSSValueBaseline, CSSValueWebkitBaselineMiddle);
if (!parsedValue)
parsedValue = consumeLengthOrPercent(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Allow);
return parsedValue;
}
static RefPtr<CSSPrimitiveValue> consumeShapeRadius(CSSParserTokenRange& args, CSSParserMode cssParserMode)
{
if (identMatches<CSSValueClosestSide, CSSValueFarthestSide>(args.peek().id()))
return consumeIdent(args);
return consumeLengthOrPercent(args, cssParserMode, ValueRangeNonNegative);
}
static RefPtr<CSSBasicShapeCircle> consumeBasicShapeCircle(CSSParserTokenRange& args, const CSSParserContext& context)
{
// spec: https://drafts.csswg.org/css-shapes/#supported-basic-shapes
// circle( [<shape-radius>]? [at <position>]? )
RefPtr<CSSBasicShapeCircle> shape = CSSBasicShapeCircle::create();
if (RefPtr<CSSPrimitiveValue> radius = consumeShapeRadius(args, context.mode))
shape->setRadius(radius.releaseNonNull());
if (consumeIdent<CSSValueAt>(args)) {
RefPtr<CSSPrimitiveValue> centerX;
RefPtr<CSSPrimitiveValue> centerY;
if (!consumePosition(args, context.mode, UnitlessQuirk::Forbid, centerX, centerY))
return nullptr;
shape->setCenterX(centerX.releaseNonNull());
shape->setCenterY(centerY.releaseNonNull());
}
return shape;
}
static RefPtr<CSSBasicShapeEllipse> consumeBasicShapeEllipse(CSSParserTokenRange& args, const CSSParserContext& context)
{
// spec: https://drafts.csswg.org/css-shapes/#supported-basic-shapes
// ellipse( [<shape-radius>{2}]? [at <position>]? )
RefPtr<CSSBasicShapeEllipse> shape = CSSBasicShapeEllipse::create();
if (RefPtr<CSSPrimitiveValue> radiusX = consumeShapeRadius(args, context.mode)) {
shape->setRadiusX(radiusX.releaseNonNull());
if (RefPtr<CSSPrimitiveValue> radiusY = consumeShapeRadius(args, context.mode))
shape->setRadiusY(radiusY.releaseNonNull());
}
if (consumeIdent<CSSValueAt>(args)) {
RefPtr<CSSPrimitiveValue> centerX;
RefPtr<CSSPrimitiveValue> centerY;
if (!consumePosition(args, context.mode, UnitlessQuirk::Forbid, centerX, centerY))
return nullptr;
shape->setCenterX(centerX.releaseNonNull());
shape->setCenterY(centerY.releaseNonNull());
}
return shape;
}
static RefPtr<CSSBasicShapePolygon> consumeBasicShapePolygon(CSSParserTokenRange& args, const CSSParserContext& context)
{
RefPtr<CSSBasicShapePolygon> shape = CSSBasicShapePolygon::create();
if (identMatches<CSSValueEvenodd, CSSValueNonzero>(args.peek().id())) {
shape->setWindRule(args.consumeIncludingWhitespace().id() == CSSValueEvenodd ? RULE_EVENODD : RULE_NONZERO);
if (!consumeCommaIncludingWhitespace(args))
return nullptr;
}
do {
RefPtr<CSSPrimitiveValue> xLength = consumeLengthOrPercent(args, context.mode, ValueRangeAll);
if (!xLength)
return nullptr;
RefPtr<CSSPrimitiveValue> yLength = consumeLengthOrPercent(args, context.mode, ValueRangeAll);
if (!yLength)
return nullptr;
shape->appendPoint(xLength.releaseNonNull(), yLength.releaseNonNull());
} while (consumeCommaIncludingWhitespace(args));
return shape;
}
static RefPtr<CSSBasicShapePath> consumeBasicShapePath(CSSParserTokenRange& args)
{
WindRule windRule = RULE_NONZERO;
if (identMatches<CSSValueEvenodd, CSSValueNonzero>(args.peek().id())) {
windRule = args.consumeIncludingWhitespace().id() == CSSValueEvenodd ? RULE_EVENODD : RULE_NONZERO;
if (!consumeCommaIncludingWhitespace(args))
return nullptr;
}
if (args.peek().type() != StringToken)
return nullptr;
auto byteStream = std::make_unique<SVGPathByteStream>();
if (!buildSVGPathByteStreamFromString(args.consumeIncludingWhitespace().value().toString(), *byteStream, UnalteredParsing))
return nullptr;
auto shape = CSSBasicShapePath::create(WTFMove(byteStream));
shape->setWindRule(windRule);
return WTFMove(shape);
}
static void complete4Sides(RefPtr<CSSPrimitiveValue> side[4])
{
if (side[3])
return;
if (!side[2]) {
if (!side[1])
side[1] = side[0];
side[2] = side[0];
}
side[3] = side[1];
}
static bool consumeRadii(RefPtr<CSSPrimitiveValue> horizontalRadii[4], RefPtr<CSSPrimitiveValue> verticalRadii[4], CSSParserTokenRange& range, CSSParserMode cssParserMode, bool useLegacyParsing)
{
unsigned i = 0;
for (; i < 4 && !range.atEnd() && range.peek().type() != DelimiterToken; ++i) {
horizontalRadii[i] = consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative);
if (!horizontalRadii[i])
return false;
}
if (!horizontalRadii[0])
return false;
if (range.atEnd()) {
// Legacy syntax: -webkit-border-radius: l1 l2; is equivalent to border-radius: l1 / l2;
if (useLegacyParsing && i == 2) {
verticalRadii[0] = horizontalRadii[1];
horizontalRadii[1] = nullptr;
} else {
complete4Sides(horizontalRadii);
for (unsigned i = 0; i < 4; ++i)
verticalRadii[i] = horizontalRadii[i];
return true;
}
} else {
if (!consumeSlashIncludingWhitespace(range))
return false;
for (i = 0; i < 4 && !range.atEnd(); ++i) {
verticalRadii[i] = consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative);
if (!verticalRadii[i])
return false;
}
if (!verticalRadii[0] || !range.atEnd())
return false;
}
complete4Sides(horizontalRadii);
complete4Sides(verticalRadii);
return true;
}
static RefPtr<CSSBasicShapeInset> consumeBasicShapeInset(CSSParserTokenRange& args, const CSSParserContext& context)
{
RefPtr<CSSBasicShapeInset> shape = CSSBasicShapeInset::create();
RefPtr<CSSPrimitiveValue> top = consumeLengthOrPercent(args, context.mode, ValueRangeAll);
if (!top)
return nullptr;
RefPtr<CSSPrimitiveValue> right = consumeLengthOrPercent(args, context.mode, ValueRangeAll);
RefPtr<CSSPrimitiveValue> bottom;
RefPtr<CSSPrimitiveValue> left;
if (right) {
bottom = consumeLengthOrPercent(args, context.mode, ValueRangeAll);
if (bottom)
left = consumeLengthOrPercent(args, context.mode, ValueRangeAll);
}
if (left)
shape->updateShapeSize4Values(top.releaseNonNull(), right.releaseNonNull(), bottom.releaseNonNull(), left.releaseNonNull());
else if (bottom)
shape->updateShapeSize3Values(top.releaseNonNull(), right.releaseNonNull(), bottom.releaseNonNull());
else if (right)
shape->updateShapeSize2Values(top.releaseNonNull(), right.releaseNonNull());
else
shape->updateShapeSize1Value(top.releaseNonNull());
if (consumeIdent<CSSValueRound>(args)) {
RefPtr<CSSPrimitiveValue> horizontalRadii[4] = { 0 };
RefPtr<CSSPrimitiveValue> verticalRadii[4] = { 0 };
if (!consumeRadii(horizontalRadii, verticalRadii, args, context.mode, false))
return nullptr;
shape->setTopLeftRadius(createPrimitiveValuePair(horizontalRadii[0].releaseNonNull(), verticalRadii[0].releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce));
shape->setTopRightRadius(createPrimitiveValuePair(horizontalRadii[1].releaseNonNull(), verticalRadii[1].releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce));
shape->setBottomRightRadius(createPrimitiveValuePair(horizontalRadii[2].releaseNonNull(), verticalRadii[2].releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce));
shape->setBottomLeftRadius(createPrimitiveValuePair(horizontalRadii[3].releaseNonNull(), verticalRadii[3].releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce));
}
return shape;
}
static RefPtr<CSSValue> consumeBasicShape(CSSParserTokenRange& range, const CSSParserContext& context)
{
RefPtr<CSSValue> result;
if (range.peek().type() != FunctionToken)
return nullptr;
CSSValueID id = range.peek().functionId();
CSSParserTokenRange rangeCopy = range;
CSSParserTokenRange args = consumeFunction(rangeCopy);
// FIXME-NEWPARSER: CSSBasicShape should be a CSSValue, and shapes should not be primitive values.
RefPtr<CSSBasicShape> shape;
if (id == CSSValueCircle)
shape = consumeBasicShapeCircle(args, context);
else if (id == CSSValueEllipse)
shape = consumeBasicShapeEllipse(args, context);
else if (id == CSSValuePolygon)
shape = consumeBasicShapePolygon(args, context);
else if (id == CSSValueInset)
shape = consumeBasicShapeInset(args, context);
else if (id == CSSValuePath)
shape = consumeBasicShapePath(args);
if (!shape)
return nullptr;
range = rangeCopy;
if (!args.atEnd())
return nullptr;
return CSSValuePool::singleton().createValue(shape.releaseNonNull());
}
static RefPtr<CSSValue> consumeBasicShapeOrBox(CSSParserTokenRange& range, const CSSParserContext& context)
{
RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
bool shapeFound = false;
bool boxFound = false;
while (!range.atEnd() && !(shapeFound && boxFound)) {
RefPtr<CSSValue> componentValue;
if (range.peek().type() == FunctionToken && !shapeFound) {
componentValue = consumeBasicShape(range, context);
shapeFound = true;
} else if (range.peek().type() == IdentToken && !boxFound) {
componentValue = consumeIdent<CSSValueContentBox, CSSValuePaddingBox, CSSValueBorderBox, CSSValueMarginBox, CSSValueFill, CSSValueStroke, CSSValueViewBox>(range);
boxFound = true;
}
if (!componentValue)
return nullptr;
list->append(componentValue.releaseNonNull());
}
if (!range.atEnd() || !list->length())
return nullptr;
return list;
}
static RefPtr<CSSValue> consumeWebkitClipPath(CSSParserTokenRange& range, const CSSParserContext& context)
{
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
if (RefPtr<CSSPrimitiveValue> url = consumeUrl(range))
return url;
return consumeBasicShapeOrBox(range, context);
}
static RefPtr<CSSValue> consumeShapeOutside(CSSParserTokenRange& range, const CSSParserContext& context)
{
if (RefPtr<CSSValue> imageValue = consumeImageOrNone(range, context))
return imageValue;
RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
if (RefPtr<CSSValue> boxValue = consumeIdent<CSSValueContentBox, CSSValuePaddingBox, CSSValueBorderBox, CSSValueMarginBox>(range))
list->append(boxValue.releaseNonNull());
if (RefPtr<CSSValue> shapeValue = consumeBasicShape(range, context)) {
list->append(shapeValue.releaseNonNull());
if (list->length() < 2) {
if (RefPtr<CSSValue> boxValue = consumeIdent<CSSValueContentBox, CSSValuePaddingBox, CSSValueBorderBox, CSSValueMarginBox>(range))
list->append(boxValue.releaseNonNull());
}
}
if (!list->length())
return nullptr;
return list;
}
static RefPtr<CSSValue> consumeContentDistributionOverflowPosition(CSSParserTokenRange& range)
{
if (identMatches<CSSValueNormal, CSSValueBaseline, CSSValueLastBaseline>(range.peek().id()))
return CSSContentDistributionValue::create(CSSValueInvalid, range.consumeIncludingWhitespace().id(), CSSValueInvalid);
CSSValueID distribution = CSSValueInvalid;
CSSValueID position = CSSValueInvalid;
CSSValueID overflow = CSSValueInvalid;
do {
CSSValueID id = range.peek().id();
if (identMatches<CSSValueSpaceBetween, CSSValueSpaceAround, CSSValueSpaceEvenly, CSSValueStretch>(id)) {
if (distribution != CSSValueInvalid)
return nullptr;
distribution = id;
} else if (identMatches<CSSValueStart, CSSValueEnd, CSSValueCenter, CSSValueFlexStart, CSSValueFlexEnd, CSSValueLeft, CSSValueRight>(id)) {
if (position != CSSValueInvalid)
return nullptr;
position = id;
} else if (identMatches<CSSValueUnsafe, CSSValueSafe>(id)) {
if (overflow != CSSValueInvalid)
return nullptr;
overflow = id;
} else {
return nullptr;
}
range.consumeIncludingWhitespace();
} while (!range.atEnd());
// The grammar states that we should have at least <content-distribution> or <content-position>.
if (position == CSSValueInvalid && distribution == CSSValueInvalid)
return nullptr;
// The grammar states that <overflow-position> must be associated to <content-position>.
if (overflow != CSSValueInvalid && position == CSSValueInvalid)
return nullptr;
return CSSContentDistributionValue::create(distribution, position, overflow);
}
static RefPtr<CSSPrimitiveValue> consumeBorderImageRepeatKeyword(CSSParserTokenRange& range)
{
return consumeIdent<CSSValueStretch, CSSValueRepeat, CSSValueSpace, CSSValueRound>(range);
}
static RefPtr<CSSValue> consumeBorderImageRepeat(CSSParserTokenRange& range)
{
RefPtr<CSSPrimitiveValue> horizontal = consumeBorderImageRepeatKeyword(range);
if (!horizontal)
return nullptr;
RefPtr<CSSPrimitiveValue> vertical = consumeBorderImageRepeatKeyword(range);
if (!vertical)
vertical = horizontal;
return createPrimitiveValuePair(horizontal.releaseNonNull(), vertical.releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce);
}
static RefPtr<CSSValue> consumeBorderImageSlice(CSSPropertyID property, CSSParserTokenRange& range)
{
bool fill = consumeIdent<CSSValueFill>(range);
RefPtr<CSSPrimitiveValue> slices[4] = { 0 };
for (size_t index = 0; index < 4; ++index) {
RefPtr<CSSPrimitiveValue> value = consumePercent(range, ValueRangeNonNegative);
if (!value)
value = consumeNumber(range, ValueRangeNonNegative);
if (!value)
break;
slices[index] = value;
}
if (!slices[0])
return nullptr;
if (consumeIdent<CSSValueFill>(range)) {
if (fill)
return nullptr;
fill = true;
}
complete4Sides(slices);
// FIXME: For backwards compatibility, -webkit-border-image, -webkit-mask-box-image and -webkit-box-reflect have to do a fill by default.
// FIXME: What do we do with -webkit-box-reflect and -webkit-mask-box-image? Probably just have to leave them filling...
if (property == CSSPropertyWebkitBorderImage || property == CSSPropertyWebkitMaskBoxImage || property == CSSPropertyWebkitBoxReflect)
fill = true;
// Now build a rect value to hold all four of our primitive values.
// FIXME-NEWPARSER: Should just have a CSSQuadValue.
auto quad = Quad::create();
quad->setTop(slices[0].releaseNonNull());
quad->setRight(slices[1].releaseNonNull());
quad->setBottom(slices[2].releaseNonNull());
quad->setLeft(slices[3].releaseNonNull());
// Make our new border image value now.
return CSSBorderImageSliceValue::create(CSSValuePool::singleton().createValue(WTFMove(quad)), fill);
}
static RefPtr<CSSValue> consumeBorderImageOutset(CSSParserTokenRange& range)
{
RefPtr<CSSPrimitiveValue> outsets[4] = { 0 };
RefPtr<CSSPrimitiveValue> value;
for (size_t index = 0; index < 4; ++index) {
value = consumeNumber(range, ValueRangeNonNegative);
if (!value)
value = consumeLength(range, HTMLStandardMode, ValueRangeNonNegative);
if (!value)
break;
outsets[index] = value;
}
if (!outsets[0])
return nullptr;
complete4Sides(outsets);
// FIXME-NEWPARSER: Should just have a CSSQuadValue.
auto quad = Quad::create();
quad->setTop(outsets[0].releaseNonNull());
quad->setRight(outsets[1].releaseNonNull());
quad->setBottom(outsets[2].releaseNonNull());
quad->setLeft(outsets[3].releaseNonNull());
return CSSValuePool::singleton().createValue(WTFMove(quad));
}
static RefPtr<CSSValue> consumeBorderImageWidth(CSSParserTokenRange& range)
{
RefPtr<CSSPrimitiveValue> widths[4];
RefPtr<CSSPrimitiveValue> value;
for (size_t index = 0; index < 4; ++index) {
value = consumeNumber(range, ValueRangeNonNegative);
if (!value)
value = consumeLengthOrPercent(range, HTMLStandardMode, ValueRangeNonNegative, UnitlessQuirk::Forbid);
if (!value)
value = consumeIdent<CSSValueAuto>(range);
if (!value)
break;
widths[index] = value;
}
if (!widths[0])
return nullptr;
complete4Sides(widths);
// FIXME-NEWPARSER: Should just have a CSSQuadValue.
auto quad = Quad::create();
quad->setTop(widths[0].releaseNonNull());
quad->setRight(widths[1].releaseNonNull());
quad->setBottom(widths[2].releaseNonNull());
quad->setLeft(widths[3].releaseNonNull());
return CSSValuePool::singleton().createValue(WTFMove(quad));
}
static bool consumeBorderImageComponents(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& context, RefPtr<CSSValue>& source,
RefPtr<CSSValue>& slice, RefPtr<CSSValue>& width, RefPtr<CSSValue>& outset, RefPtr<CSSValue>& repeat)
{
do {
if (!source) {
source = consumeImageOrNone(range, context);
if (source)
continue;
}
if (!repeat) {
repeat = consumeBorderImageRepeat(range);
if (repeat)
continue;
}
if (!slice) {
slice = consumeBorderImageSlice(property, range);
if (slice) {
ASSERT(!width && !outset);
if (consumeSlashIncludingWhitespace(range)) {
width = consumeBorderImageWidth(range);
if (consumeSlashIncludingWhitespace(range)) {
outset = consumeBorderImageOutset(range);
if (!outset)
return false;
} else if (!width) {
return false;
}
}
} else {
return false;
}
} else {
return false;
}
} while (!range.atEnd());
return true;
}
static RefPtr<CSSValue> consumeWebkitBorderImage(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& context)
{
RefPtr<CSSValue> source;
RefPtr<CSSValue> slice;
RefPtr<CSSValue> width;
RefPtr<CSSValue> outset;
RefPtr<CSSValue> repeat;
if (consumeBorderImageComponents(property, range, context, source, slice, width, outset, repeat))
return createBorderImageValue(WTFMove(source), WTFMove(slice), WTFMove(width), WTFMove(outset), WTFMove(repeat));
return nullptr;
}
static RefPtr<CSSValue> consumeReflect(CSSParserTokenRange& range, const CSSParserContext& context)
{
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
RefPtr<CSSPrimitiveValue> direction = consumeIdent<CSSValueAbove, CSSValueBelow, CSSValueLeft, CSSValueRight>(range);
if (!direction)
return nullptr;
RefPtr<CSSPrimitiveValue> offset;
if (range.atEnd())
offset = CSSValuePool::singleton().createValue(0, CSSPrimitiveValue::UnitType::CSS_PX);
else {
offset = consumeLengthOrPercent(range, context.mode, ValueRangeAll, UnitlessQuirk::Forbid);
if (!offset)
return nullptr;
}
RefPtr<CSSValue> mask;
if (!range.atEnd()) {
mask = consumeWebkitBorderImage(CSSPropertyWebkitBoxReflect, range, context);
if (!mask)
return nullptr;
}
return CSSReflectValue::create(direction.releaseNonNull(), offset.releaseNonNull(), WTFMove(mask));
}
#if ENABLE(CSS_IMAGE_ORIENTATION)
static RefPtr<CSSValue> consumeImageOrientation(CSSParserTokenRange& range, CSSParserMode cssParserMode, UnitlessQuirk unitless = UnitlessQuirk::Forbid)
{
if (range.peek().type() != NumberToken) {
RefPtr<CSSPrimitiveValue> angle = consumeAngle(range, cssParserMode, unitless);
if (angle && angle->doubleValue() == 0)
return angle;
}
return nullptr;
}
#endif
static RefPtr<CSSPrimitiveValue> consumeBackgroundBlendMode(CSSParserTokenRange& range)
{
CSSValueID id = range.peek().id();
if (id == CSSValueNormal || id == CSSValueOverlay || (id >= CSSValueMultiply && id <= CSSValueLuminosity))
return consumeIdent(range);
return nullptr;
}
static RefPtr<CSSPrimitiveValue> consumeBackgroundAttachment(CSSParserTokenRange& range)
{
return consumeIdent<CSSValueScroll, CSSValueFixed, CSSValueLocal>(range);
}
static RefPtr<CSSPrimitiveValue> consumeBackgroundBox(CSSParserTokenRange& range)
{
return consumeIdent<CSSValueBorderBox, CSSValuePaddingBox, CSSValueContentBox, CSSValueWebkitText>(range);
}
static RefPtr<CSSPrimitiveValue> consumeBackgroundComposite(CSSParserTokenRange& range)
{
return consumeIdentRange(range, CSSValueClear, CSSValuePlusLighter);
}
static RefPtr<CSSPrimitiveValue> consumeWebkitMaskSourceType(CSSParserTokenRange& range)
{
return consumeIdent<CSSValueAuto, CSSValueAlpha, CSSValueLuminance>(range);
}
static RefPtr<CSSPrimitiveValue> consumePrefixedBackgroundBox(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& /*context*/)
{
// The values 'border', 'padding' and 'content' are deprecated and do not apply to the version of the property that has the -webkit- prefix removed.
if (RefPtr<CSSPrimitiveValue> value = consumeIdentRange(range, CSSValueBorder, CSSValuePaddingBox))
return value;
if (range.peek().id() == CSSValueWebkitText || ((property == CSSPropertyWebkitBackgroundClip || property == CSSPropertyWebkitMaskClip) && range.peek().id() == CSSValueText))
return consumeIdent(range);
return nullptr;
}
static RefPtr<CSSPrimitiveValue> consumeBackgroundSize(CSSPropertyID property, CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
if (identMatches<CSSValueContain, CSSValueCover>(range.peek().id()))
return consumeIdent(range);
// FIXME: We're allowing the unitless quirk on this property because our
// tests assume that. Other browser engines don't allow it though.
RefPtr<CSSPrimitiveValue> horizontal = consumeIdent<CSSValueAuto>(range);
if (!horizontal)
horizontal = consumeLengthOrPercent(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Allow);
RefPtr<CSSPrimitiveValue> vertical;
if (!range.atEnd()) {
if (range.peek().id() == CSSValueAuto) // `auto' is the default
range.consumeIncludingWhitespace();
else
vertical = consumeLengthOrPercent(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Allow);
} else if (!vertical && property == CSSPropertyWebkitBackgroundSize) {
// Legacy syntax: "-webkit-background-size: 10px" is equivalent to "background-size: 10px 10px".
vertical = horizontal;
}
if (!vertical)
return horizontal;
return createPrimitiveValuePair(horizontal.releaseNonNull(), vertical.releaseNonNull(), property == CSSPropertyWebkitBackgroundSize ? Pair::IdenticalValueEncoding::Coalesce : Pair::IdenticalValueEncoding::DoNotCoalesce);
}
static RefPtr<CSSValueList> consumeGridAutoFlow(CSSParserTokenRange& range)
{
RefPtr<CSSPrimitiveValue> rowOrColumnValue = consumeIdent<CSSValueRow, CSSValueColumn>(range);
RefPtr<CSSPrimitiveValue> denseAlgorithm = consumeIdent<CSSValueDense>(range);
if (!rowOrColumnValue) {
rowOrColumnValue = consumeIdent<CSSValueRow, CSSValueColumn>(range);
if (!rowOrColumnValue && !denseAlgorithm)
return nullptr;
}
RefPtr<CSSValueList> parsedValues = CSSValueList::createSpaceSeparated();
if (rowOrColumnValue)
parsedValues->append(rowOrColumnValue.releaseNonNull());
if (denseAlgorithm)
parsedValues->append(denseAlgorithm.releaseNonNull());
return parsedValues;
}
static RefPtr<CSSValue> consumeBackgroundComponent(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& context)
{
switch (property) {
case CSSPropertyBackgroundClip:
return consumeBackgroundBox(range);
case CSSPropertyBackgroundBlendMode:
return consumeBackgroundBlendMode(range);
case CSSPropertyBackgroundAttachment:
return consumeBackgroundAttachment(range);
case CSSPropertyBackgroundOrigin:
return consumeBackgroundBox(range);
case CSSPropertyWebkitMaskComposite:
case CSSPropertyWebkitBackgroundComposite:
return consumeBackgroundComposite(range);
case CSSPropertyWebkitBackgroundClip:
case CSSPropertyWebkitBackgroundOrigin:
case CSSPropertyWebkitMaskClip:
case CSSPropertyWebkitMaskOrigin:
return consumePrefixedBackgroundBox(property, range, context);
case CSSPropertyBackgroundImage:
case CSSPropertyWebkitMaskImage:
return consumeImageOrNone(range, context);
case CSSPropertyWebkitMaskSourceType:
return consumeWebkitMaskSourceType(range);
case CSSPropertyBackgroundPositionX:
case CSSPropertyWebkitMaskPositionX:
return consumePositionX(range, context.mode);
case CSSPropertyBackgroundPositionY:
case CSSPropertyWebkitMaskPositionY:
return consumePositionY(range, context.mode);
case CSSPropertyBackgroundSize:
case CSSPropertyWebkitBackgroundSize:
case CSSPropertyWebkitMaskSize:
return consumeBackgroundSize(property, range, context.mode);
case CSSPropertyBackgroundColor:
return consumeColor(range, context.mode);
default:
break;
};
return nullptr;
}
static void addBackgroundValue(RefPtr<CSSValue>& list, Ref<CSSValue>&& value)
{
if (list) {
if (!list->isBaseValueList()) {
RefPtr<CSSValue> firstValue = list;
list = CSSValueList::createCommaSeparated();
downcast<CSSValueList>(*list).append(firstValue.releaseNonNull());
}
downcast<CSSValueList>(*list).append(WTFMove(value));
} else {
// To conserve memory we don't actually wrap a single value in a list.
list = WTFMove(value);
}
}
static RefPtr<CSSValue> consumeCommaSeparatedBackgroundComponent(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& context)
{
RefPtr<CSSValue> result;
do {
RefPtr<CSSValue> value = consumeBackgroundComponent(property, range, context);
if (!value)
return nullptr;
addBackgroundValue(result, value.releaseNonNull());
} while (consumeCommaIncludingWhitespace(range));
return result;
}
static RefPtr<CSSPrimitiveValue> consumeSelfPositionKeyword(CSSParserTokenRange& range)
{
CSSValueID id = range.peek().id();
if (id == CSSValueStart || id == CSSValueEnd || id == CSSValueCenter
|| id == CSSValueSelfStart || id == CSSValueSelfEnd || id == CSSValueFlexStart
|| id == CSSValueFlexEnd || id == CSSValueLeft || id == CSSValueRight)
return consumeIdent(range);
return nullptr;
}
static RefPtr<CSSValue> consumeSelfPositionOverflowPosition(CSSParserTokenRange& range)
{
if (identMatches<CSSValueAuto, CSSValueNormal, CSSValueStretch, CSSValueBaseline, CSSValueLastBaseline>(range.peek().id()))
return consumeIdent(range);
RefPtr<CSSPrimitiveValue> overflowPosition = consumeIdent<CSSValueUnsafe, CSSValueSafe>(range);
RefPtr<CSSPrimitiveValue> selfPosition = consumeSelfPositionKeyword(range);
if (!selfPosition)
return nullptr;
if (!overflowPosition)
overflowPosition = consumeIdent<CSSValueUnsafe, CSSValueSafe>(range);
if (overflowPosition)
return createPrimitiveValuePair(selfPosition.releaseNonNull(), overflowPosition.releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce);
return selfPosition;
}
static RefPtr<CSSValue> consumeAlignItems(CSSParserTokenRange& range)
{
// align-items property does not allow the 'auto' value.
if (identMatches<CSSValueAuto>(range.peek().id()))
return nullptr;
return consumeSelfPositionOverflowPosition(range);
}
static RefPtr<CSSValue> consumeJustifyItems(CSSParserTokenRange& range)
{
CSSParserTokenRange rangeCopy = range;
RefPtr<CSSPrimitiveValue> legacy = consumeIdent<CSSValueLegacy>(rangeCopy);
RefPtr<CSSPrimitiveValue> positionKeyword = consumeIdent<CSSValueCenter, CSSValueLeft, CSSValueRight>(rangeCopy);
if (!legacy)
legacy = consumeIdent<CSSValueLegacy>(rangeCopy);
if (legacy && positionKeyword) {
range = rangeCopy;
return createPrimitiveValuePair(legacy.releaseNonNull(), positionKeyword.releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce);
}
return consumeSelfPositionOverflowPosition(range);
}
static RefPtr<CSSValue> consumeFitContent(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
CSSParserTokenRange rangeCopy = range;
CSSParserTokenRange args = consumeFunction(rangeCopy);
RefPtr<CSSPrimitiveValue> length = consumeLengthOrPercent(args, cssParserMode, ValueRangeNonNegative, UnitlessQuirk::Allow);
if (!length || !args.atEnd())
return nullptr;
range = rangeCopy;
RefPtr<CSSFunctionValue> result = CSSFunctionValue::create(CSSValueFitContent);
result->append(length.releaseNonNull());
return result;
}
static RefPtr<CSSPrimitiveValue> consumeCustomIdentForGridLine(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueAuto || range.peek().id() == CSSValueSpan)
return nullptr;
return consumeCustomIdent(range);
}
static RefPtr<CSSValue> consumeGridLine(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueAuto)
return consumeIdent(range);
RefPtr<CSSPrimitiveValue> spanValue;
RefPtr<CSSPrimitiveValue> gridLineName;
RefPtr<CSSPrimitiveValue> numericValue = consumeInteger(range);
if (numericValue) {
gridLineName = consumeCustomIdentForGridLine(range);
spanValue = consumeIdent<CSSValueSpan>(range);
} else {
spanValue = consumeIdent<CSSValueSpan>(range);
if (spanValue) {
numericValue = consumeInteger(range);
gridLineName = consumeCustomIdentForGridLine(range);
if (!numericValue)
numericValue = consumeInteger(range);
} else {
gridLineName = consumeCustomIdentForGridLine(range);
if (gridLineName) {
numericValue = consumeInteger(range);
spanValue = consumeIdent<CSSValueSpan>(range);
if (!spanValue && !numericValue)
return gridLineName;
} else {
return nullptr;
}
}
}
if (spanValue && !numericValue && !gridLineName)
return nullptr; // "span" keyword alone is invalid.
if (spanValue && numericValue && numericValue->intValue() < 0)
return nullptr; // Negative numbers are not allowed for span.
if (numericValue && numericValue->intValue() == 0)
return nullptr; // An <integer> value of zero makes the declaration invalid.
RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
if (spanValue)
values->append(spanValue.releaseNonNull());
if (numericValue)
values->append(numericValue.releaseNonNull());
if (gridLineName)
values->append(gridLineName.releaseNonNull());
ASSERT(values->length());
return values;
}
static bool isGridTrackFixedSized(const CSSPrimitiveValue& primitiveValue)
{
CSSValueID valueID = primitiveValue.valueID();
if (valueID == CSSValueWebkitMinContent || valueID == CSSValueWebkitMaxContent || valueID == CSSValueAuto || primitiveValue.isFlex())
return false;
return true;
}
static bool isGridTrackFixedSized(const CSSValue& value)
{
if (value.isPrimitiveValue())
return isGridTrackFixedSized(downcast<CSSPrimitiveValue>(value));
ASSERT(value.isFunctionValue());
auto& function = downcast<CSSFunctionValue>(value);
if (function.name() == CSSValueFitContent || function.length() < 2)
return false;
const CSSValue* minPrimitiveValue = downcast<CSSPrimitiveValue>(function.item(0));
const CSSValue* maxPrimitiveValue = downcast<CSSPrimitiveValue>(function.item(1));
return isGridTrackFixedSized(*minPrimitiveValue) || isGridTrackFixedSized(*maxPrimitiveValue);
}
static Vector<String> parseGridTemplateAreasColumnNames(const String& gridRowNames)
{
ASSERT(!gridRowNames.isEmpty());
Vector<String> columnNames;
// Using StringImpl to avoid checks and indirection in every call to String::operator[].
StringImpl& text = *gridRowNames.impl();
StringBuilder areaName;
for (unsigned i = 0; i < text.length(); ++i) {
if (isCSSSpace(text[i])) {
if (!areaName.isEmpty()) {
columnNames.append(areaName.toString());
areaName.clear();
}
continue;
}
if (text[i] == '.') {
if (areaName == ".")
continue;
if (!areaName.isEmpty()) {
columnNames.append(areaName.toString());
areaName.clear();
}
} else {
if (!isNameCodePoint(text[i]))
return Vector<String>();
if (areaName == ".") {
columnNames.append(areaName.toString());
areaName.clear();
}
}
areaName.append(text[i]);
}
if (!areaName.isEmpty())
columnNames.append(areaName.toString());
return columnNames;
}
static bool parseGridTemplateAreasRow(const String& gridRowNames, NamedGridAreaMap& gridAreaMap, const size_t rowCount, size_t& columnCount)
{
if (gridRowNames.isEmpty() || gridRowNames.containsOnlyWhitespace())
return false;
Vector<String> columnNames = parseGridTemplateAreasColumnNames(gridRowNames);
if (rowCount == 0) {
columnCount = columnNames.size();
if (columnCount == 0)
return false;
} else if (columnCount != columnNames.size()) {
// The declaration is invalid if all the rows don't have the number of columns.
return false;
}
for (size_t currentColumn = 0; currentColumn < columnCount; ++currentColumn) {
const String& gridAreaName = columnNames[currentColumn];
// Unamed areas are always valid (we consider them to be 1x1).
if (gridAreaName == ".")
continue;
size_t lookAheadColumn = currentColumn + 1;
while (lookAheadColumn < columnCount && columnNames[lookAheadColumn] == gridAreaName)
lookAheadColumn++;
NamedGridAreaMap::iterator gridAreaIt = gridAreaMap.find(gridAreaName);
if (gridAreaIt == gridAreaMap.end()) {
gridAreaMap.add(gridAreaName, GridArea(GridSpan::translatedDefiniteGridSpan(rowCount, rowCount + 1), GridSpan::translatedDefiniteGridSpan(currentColumn, lookAheadColumn)));
} else {
GridArea& gridArea = gridAreaIt->value;
// The following checks test that the grid area is a single filled-in rectangle.
// 1. The new row is adjacent to the previously parsed row.
if (rowCount != gridArea.rows.endLine())
return false;
// 2. The new area starts at the same position as the previously parsed area.
if (currentColumn != gridArea.columns.startLine())
return false;
// 3. The new area ends at the same position as the previously parsed area.
if (lookAheadColumn != gridArea.columns.endLine())
return false;
gridArea.rows = GridSpan::translatedDefiniteGridSpan(gridArea.rows.startLine(), gridArea.rows.endLine() + 1);
}
currentColumn = lookAheadColumn - 1;
}
return true;
}
static RefPtr<CSSPrimitiveValue> consumeGridBreadth(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
const CSSParserToken& token = range.peek();
if (identMatches<CSSValueWebkitMinContent, CSSValueWebkitMaxContent, CSSValueAuto>(token.id()))
return consumeIdent(range);
if (token.type() == DimensionToken && token.unitType() == CSSPrimitiveValue::UnitType::CSS_FR) {
if (range.peek().numericValue() < 0)
return nullptr;
return CSSPrimitiveValue::create(range.consumeIncludingWhitespace().numericValue(), CSSPrimitiveValue::UnitType::CSS_FR);
}
return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative, UnitlessQuirk::Allow);
}
static RefPtr<CSSValue> consumeGridTrackSize(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
const CSSParserToken& token = range.peek();
if (identMatches<CSSValueAuto>(token.id()))
return consumeIdent(range);
if (token.functionId() == CSSValueMinmax) {
CSSParserTokenRange rangeCopy = range;
CSSParserTokenRange args = consumeFunction(rangeCopy);
RefPtr<CSSPrimitiveValue> minTrackBreadth = consumeGridBreadth(args, cssParserMode);
if (!minTrackBreadth || minTrackBreadth->isFlex() || !consumeCommaIncludingWhitespace(args))
return nullptr;
RefPtr<CSSPrimitiveValue> maxTrackBreadth = consumeGridBreadth(args, cssParserMode);
if (!maxTrackBreadth || !args.atEnd())
return nullptr;
range = rangeCopy;
RefPtr<CSSFunctionValue> result = CSSFunctionValue::create(CSSValueMinmax);
result->append(minTrackBreadth.releaseNonNull());
result->append(maxTrackBreadth.releaseNonNull());
return result;
}
if (token.functionId() == CSSValueFitContent)
return consumeFitContent(range, cssParserMode);
return consumeGridBreadth(range, cssParserMode);
}
// Appends to the passed in CSSGridLineNamesValue if any, otherwise creates a new one.
static RefPtr<CSSGridLineNamesValue> consumeGridLineNames(CSSParserTokenRange& range, CSSGridLineNamesValue* lineNames = nullptr)
{
CSSParserTokenRange rangeCopy = range;
if (rangeCopy.consumeIncludingWhitespace().type() != LeftBracketToken)
return nullptr;
RefPtr<CSSGridLineNamesValue> result = lineNames;
if (!result)
result = CSSGridLineNamesValue::create();
while (RefPtr<CSSPrimitiveValue> lineName = consumeCustomIdentForGridLine(rangeCopy))
result->append(lineName.releaseNonNull());
if (rangeCopy.consumeIncludingWhitespace().type() != RightBracketToken)
return nullptr;
range = rangeCopy;
return result;
}
static bool consumeGridTrackRepeatFunction(CSSParserTokenRange& range, CSSParserMode cssParserMode, CSSValueList& list, bool& isAutoRepeat, bool& allTracksAreFixedSized)
{
CSSParserTokenRange args = consumeFunction(range);
// The number of repetitions for <auto-repeat> is not important at parsing level
// because it will be computed later, let's set it to 1.
size_t repetitions = 1;
isAutoRepeat = identMatches<CSSValueAutoFill, CSSValueAutoFit>(args.peek().id());
RefPtr<CSSValueList> repeatedValues;
if (isAutoRepeat)
repeatedValues = CSSGridAutoRepeatValue::create(args.consumeIncludingWhitespace().id());
else {
// FIXME: a consumeIntegerRaw would be more efficient here.
RefPtr<CSSPrimitiveValue> repetition = consumePositiveInteger(args);
if (!repetition)
return false;
repetitions = clampTo<size_t>(repetition->doubleValue(), 0, kGridMaxTracks);
repeatedValues = CSSValueList::createSpaceSeparated();
}
if (!consumeCommaIncludingWhitespace(args))
return false;
RefPtr<CSSGridLineNamesValue> lineNames = consumeGridLineNames(args);
if (lineNames)
repeatedValues->append(lineNames.releaseNonNull());
size_t numberOfTracks = 0;
while (!args.atEnd()) {
RefPtr<CSSValue> trackSize = consumeGridTrackSize(args, cssParserMode);
if (!trackSize)
return false;
if (allTracksAreFixedSized)
allTracksAreFixedSized = isGridTrackFixedSized(*trackSize);
repeatedValues->append(trackSize.releaseNonNull());
++numberOfTracks;
lineNames = consumeGridLineNames(args);
if (lineNames)
repeatedValues->append(lineNames.releaseNonNull());
}
// We should have found at least one <track-size> or else it is not a valid <track-list>.
if (!numberOfTracks)
return false;
if (isAutoRepeat)
list.append(repeatedValues.releaseNonNull());
else {
// We clamp the repetitions to a multiple of the repeat() track list's size, while staying below the max grid size.
repetitions = std::min(repetitions, kGridMaxTracks / numberOfTracks);
for (size_t i = 0; i < repetitions; ++i) {
for (size_t j = 0; j < repeatedValues->length(); ++j)
list.append(*repeatedValues->itemWithoutBoundsCheck(j));
}
}
return true;
}
enum TrackListType { GridTemplate, GridTemplateNoRepeat, GridAuto };
static RefPtr<CSSValue> consumeGridTrackList(CSSParserTokenRange& range, CSSParserMode cssParserMode, TrackListType trackListType)
{
bool allowGridLineNames = trackListType != GridAuto;
RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
RefPtr<CSSGridLineNamesValue> lineNames = consumeGridLineNames(range);
if (lineNames) {
if (!allowGridLineNames)
return nullptr;
values->append(lineNames.releaseNonNull());
}
bool allowRepeat = trackListType == GridTemplate;
bool seenAutoRepeat = false;
bool allTracksAreFixedSized = true;
do {
bool isAutoRepeat;
if (range.peek().functionId() == CSSValueRepeat) {
if (!allowRepeat)
return nullptr;
if (!consumeGridTrackRepeatFunction(range, cssParserMode, *values, isAutoRepeat, allTracksAreFixedSized))
return nullptr;
if (isAutoRepeat && seenAutoRepeat)
return nullptr;
seenAutoRepeat = seenAutoRepeat || isAutoRepeat;
} else if (RefPtr<CSSValue> value = consumeGridTrackSize(range, cssParserMode)) {
if (allTracksAreFixedSized)
allTracksAreFixedSized = isGridTrackFixedSized(*value);
values->append(value.releaseNonNull());
} else {
return nullptr;
}
if (seenAutoRepeat && !allTracksAreFixedSized)
return nullptr;
lineNames = consumeGridLineNames(range);
if (lineNames) {
if (!allowGridLineNames)
return nullptr;
values->append(lineNames.releaseNonNull());
}
} while (!range.atEnd() && range.peek().type() != DelimiterToken);
return values;
}
static RefPtr<CSSValue> consumeGridTemplatesRowsOrColumns(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
return consumeGridTrackList(range, cssParserMode, GridTemplate);
}
static RefPtr<CSSValue> consumeGridTemplateAreas(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
NamedGridAreaMap gridAreaMap;
size_t rowCount = 0;
size_t columnCount = 0;
while (range.peek().type() == StringToken) {
if (!parseGridTemplateAreasRow(range.consumeIncludingWhitespace().value().toString(), gridAreaMap, rowCount, columnCount))
return nullptr;
++rowCount;
}
if (rowCount == 0)
return nullptr;
ASSERT(columnCount);
return CSSGridTemplateAreasValue::create(gridAreaMap, rowCount, columnCount);
}
#if ENABLE(CSS_REGIONS)
static RefPtr<CSSValue> consumeFlowProperty(CSSParserTokenRange& range)
{
RefPtr<CSSValue> result;
if (range.peek().id() == CSSValueNone)
result = consumeIdent(range);
else
result = consumeCustomIdent(range);
return result;
}
#endif
static RefPtr<CSSValue> consumeLineBoxContain(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
LineBoxContain lineBoxContain = LineBoxContainNone;
while (range.peek().type() == IdentToken) {
auto id = range.peek().id();
if (id == CSSValueBlock) {
if (lineBoxContain & LineBoxContainBlock)
return nullptr;
lineBoxContain |= LineBoxContainBlock;
} else if (id == CSSValueInline) {
if (lineBoxContain & LineBoxContainInline)
return nullptr;
lineBoxContain |= LineBoxContainInline;
} else if (id == CSSValueFont) {
if (lineBoxContain & LineBoxContainFont)
return nullptr;
lineBoxContain |= LineBoxContainFont;
} else if (id == CSSValueGlyphs) {
if (lineBoxContain & LineBoxContainGlyphs)
return nullptr;
lineBoxContain |= LineBoxContainGlyphs;
} else if (id == CSSValueReplaced) {
if (lineBoxContain & LineBoxContainReplaced)
return nullptr;
lineBoxContain |= LineBoxContainReplaced;
} else if (id == CSSValueInlineBox) {
if (lineBoxContain & LineBoxContainInlineBox)
return nullptr;
lineBoxContain |= LineBoxContainInlineBox;
} else if (id == CSSValueInitialLetter) {
if (lineBoxContain & LineBoxContainInitialLetter)
return nullptr;
lineBoxContain |= LineBoxContainInitialLetter;
} else
return nullptr;
range.consumeIncludingWhitespace();
}
if (!lineBoxContain)
return nullptr;
return CSSLineBoxContainValue::create(lineBoxContain);
}
static RefPtr<CSSValue> consumeLineGrid(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
return consumeCustomIdent(range);
}
static RefPtr<CSSValue> consumeInitialLetter(CSSParserTokenRange& range)
{
RefPtr<CSSValue> ident = consumeIdent<CSSValueNormal>(range);
if (ident)
return ident;
RefPtr<CSSPrimitiveValue> height = consumeNumber(range, ValueRangeNonNegative);
if (!height)
return nullptr;
RefPtr<CSSPrimitiveValue> position;
if (!range.atEnd()) {
position = consumeNumber(range, ValueRangeNonNegative);
if (!position || !range.atEnd())
return nullptr;
} else
position = height.copyRef();
return createPrimitiveValuePair(position.releaseNonNull(), WTFMove(height));
}
static RefPtr<CSSValue> consumeHangingPunctuation(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
std::bitset<numCSSValueKeywords> seenValues;
bool seenForceEnd = false;
bool seenAllowEnd = false;
bool seenFirst = false;
bool seenLast = false;
while (!range.atEnd()) {
CSSValueID valueID = range.peek().id();
if ((valueID == CSSValueFirst && seenFirst)
|| (valueID == CSSValueLast && seenLast)
|| (valueID == CSSValueAllowEnd && (seenAllowEnd || seenForceEnd))
|| (valueID == CSSValueForceEnd && (seenAllowEnd || seenForceEnd)))
return nullptr;
RefPtr<CSSValue> ident = consumeIdent<CSSValueAllowEnd, CSSValueForceEnd, CSSValueFirst, CSSValueLast>(range);
if (!ident)
return nullptr;
switch (valueID) {
case CSSValueAllowEnd:
seenAllowEnd = true;
break;
case CSSValueForceEnd:
seenForceEnd = true;
break;
case CSSValueFirst:
seenFirst = true;
break;
case CSSValueLast:
seenLast = true;
break;
default:
break;
}
list->append(ident.releaseNonNull());
}
return list->length() ? list : nullptr;
}
static RefPtr<CSSValue> consumeWebkitMarqueeIncrement(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
if (range.peek().type() == IdentToken)
return consumeIdent<CSSValueSmall, CSSValueMedium, CSSValueLarge>(range);
return consumeLengthOrPercent(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Allow);
}
static RefPtr<CSSValue> consumeWebkitMarqueeRepetition(CSSParserTokenRange& range)
{
if (range.peek().type() == IdentToken)
return consumeIdent<CSSValueInfinite>(range);
return consumeNumber(range, ValueRangeNonNegative);
}
static RefPtr<CSSValue> consumeWebkitMarqueeSpeed(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
if (range.peek().type() == IdentToken)
return consumeIdent<CSSValueSlow, CSSValueNormal, CSSValueFast>(range);
return consumeTime(range, cssParserMode, ValueRangeNonNegative, UnitlessQuirk::Allow);
}
static RefPtr<CSSValue> consumeAlt(CSSParserTokenRange& range, const CSSParserContext& context)
{
if (range.peek().type() == StringToken)
return consumeString(range);
if (range.peek().functionId() != CSSValueAttr)
return nullptr;
return consumeAttr(consumeFunction(range), context);
}
static RefPtr<CSSValue> consumeWebkitAspectRatio(CSSParserTokenRange& range)
{
if (range.peek().type() == IdentToken)
return consumeIdent<CSSValueAuto, CSSValueFromDimensions, CSSValueFromIntrinsic>(range);
RefPtr<CSSPrimitiveValue> leftValue = consumeNumber(range, ValueRangeNonNegative);
if (!leftValue || !leftValue->floatValue() || range.atEnd() || !consumeSlashIncludingWhitespace(range))
return nullptr;
RefPtr<CSSPrimitiveValue> rightValue = consumeNumber(range, ValueRangeNonNegative);
if (!rightValue || !rightValue->floatValue())
return nullptr;
return CSSAspectRatioValue::create(leftValue->floatValue(), rightValue->floatValue());
}
static RefPtr<CSSValue> consumeTextEmphasisPosition(CSSParserTokenRange& range)
{
bool foundOverOrUnder = false;
CSSValueID overUnderValueID = CSSValueOver;
bool foundLeftOrRight = false;
CSSValueID leftRightValueID = CSSValueRight;
while (!range.atEnd()) {
switch (range.peek().id()) {
case CSSValueOver:
if (foundOverOrUnder)
return nullptr;
foundOverOrUnder = true;
overUnderValueID = CSSValueOver;
break;
case CSSValueUnder:
if (foundOverOrUnder)
return nullptr;
foundOverOrUnder = true;
overUnderValueID = CSSValueUnder;
break;
case CSSValueLeft:
if (foundLeftOrRight)
return nullptr;
foundLeftOrRight = true;
leftRightValueID = CSSValueLeft;
break;
case CSSValueRight:
if (foundLeftOrRight)
return nullptr;
foundLeftOrRight = true;
leftRightValueID = CSSValueRight;
break;
default:
return nullptr;
}
range.consumeIncludingWhitespace();
}
if (!foundOverOrUnder)
return nullptr;
RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
list->append(CSSValuePool::singleton().createIdentifierValue(overUnderValueID));
if (foundLeftOrRight)
list->append(CSSValuePool::singleton().createIdentifierValue(leftRightValueID));
return list;
}
#if ENABLE(DASHBOARD_SUPPORT)
static RefPtr<CSSValue> consumeWebkitDashboardRegion(CSSParserTokenRange& range, CSSParserMode mode)
{
if (range.atEnd())
return nullptr;
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
auto firstRegion = DashboardRegion::create();
DashboardRegion* region = nullptr;
bool requireCommas = false;
while (!range.atEnd()) {
if (!region)
region = firstRegion.ptr();
else {
auto nextRegion = DashboardRegion::create();
region->m_next = nextRegion.copyRef();
region = nextRegion.ptr();
}
if (range.peek().functionId() != CSSValueDashboardRegion)
return nullptr;
CSSParserTokenRange rangeCopy = range;
CSSParserTokenRange args = consumeFunction(rangeCopy);
if (rangeCopy.end() == args.end())
return nullptr; // No ) was found. Be strict about this, since tests are.
// First arg is a label.
if (args.peek().type() != IdentToken)
return nullptr;
region->m_label = args.consumeIncludingWhitespace().value().toString();
// Comma is optional, so don't fail if we can't consume one.
requireCommas = consumeCommaIncludingWhitespace(args);
// Second arg is a type.
if (args.peek().type() != IdentToken)
return nullptr;
region->m_geometryType = args.consumeIncludingWhitespace().value().toString();
if (equalLettersIgnoringASCIICase(region->m_geometryType, "circle"))
region->m_isCircle = true;
else if (equalLettersIgnoringASCIICase(region->m_geometryType, "rectangle"))
region->m_isRectangle = true;
else
return nullptr;
if (args.atEnd()) {
// This originally used CSSValueInvalid by accident. It might be more logical to use something else.
RefPtr<CSSPrimitiveValue> amount = CSSValuePool::singleton().createIdentifierValue(CSSValueInvalid);
region->setTop(amount.copyRef());
region->setRight(amount.copyRef());
region->setBottom(amount.copyRef());
region->setLeft(WTFMove(amount));
range = rangeCopy;
continue;
}
// Next four arguments must be offset numbers or auto.
for (int i = 0; i < 4; ++i) {
if (args.atEnd() || (requireCommas && !consumeCommaIncludingWhitespace(args)))
return nullptr;
if (args.atEnd())
return nullptr;
RefPtr<CSSPrimitiveValue> amount;
if (args.peek().id() == CSSValueAuto)
amount = consumeIdent(args);
else
amount = consumeLength(args, mode, ValueRangeAll);
if (!i)
region->setTop(WTFMove(amount));
else if (i == 1)
region->setRight(WTFMove(amount));
else if (i == 2)
region->setBottom(WTFMove(amount));
else
region->setLeft(WTFMove(amount));
}
if (!args.atEnd())
return nullptr;
range = rangeCopy;
}
return CSSValuePool::singleton().createValue(RefPtr<DashboardRegion>(WTFMove(firstRegion)));
}
#endif
RefPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID property, CSSPropertyID currentShorthand)
{
if (CSSParserFastPaths::isKeywordPropertyID(property)) {
if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(property, m_range.peek().id(), m_context.mode))
return nullptr;
return consumeIdent(m_range);
}
switch (property) {
case CSSPropertyWillChange:
return consumeWillChange(m_range);
case CSSPropertyPage:
return consumePage(m_range);
case CSSPropertyQuotes:
return consumeQuotes(m_range);
case CSSPropertyFontVariantCaps:
return consumeFontVariantCaps(m_range);
case CSSPropertyFontVariantLigatures:
return consumeFontVariantLigatures(m_range);
case CSSPropertyFontVariantNumeric:
return consumeFontVariantNumeric(m_range);
case CSSPropertyFontVariantEastAsian:
return consumeFontVariantEastAsian(m_range);
case CSSPropertyFontFeatureSettings:
return consumeFontFeatureSettings(m_range);
case CSSPropertyFontFamily:
return consumeFontFamily(m_range);
case CSSPropertyFontWeight:
return consumeFontWeight(m_range);
case CSSPropertyFontSynthesis:
return consumeFontSynthesis(m_range);
#if ENABLE(VARIATION_FONTS)
case CSSPropertyFontVariationSettings:
return consumeFontVariationSettings(m_range);
#endif
case CSSPropertyLetterSpacing:
return consumeLetterSpacing(m_range, m_context.mode);
case CSSPropertyWordSpacing:
return consumeWordSpacing(m_range, m_context.mode);
case CSSPropertyTabSize:
return consumeTabSize(m_range, m_context.mode);
#if ENABLE(TEXT_AUTOSIZING)
case CSSPropertyWebkitTextSizeAdjust:
// FIXME: Support toggling the validation of this property via a runtime setting that is independent of
// whether isTextAutosizingEnabled() is true. We want to enable this property on iOS, when simulating
// a iOS device in Safari's responsive design mode and when optionally enabled in DRT/WTR. Otherwise,
// this property should be disabled by default.
#if !PLATFORM(IOS)
if (!m_context.textAutosizingEnabled)
return nullptr;
#endif
return consumeTextSizeAdjust(m_range, m_context.mode);
#endif
case CSSPropertyFontSize:
return consumeFontSize(m_range, m_context.mode, UnitlessQuirk::Allow);
case CSSPropertyLineHeight:
return consumeLineHeight(m_range, m_context.mode);
case CSSPropertyWebkitBorderHorizontalSpacing:
case CSSPropertyWebkitBorderVerticalSpacing:
return consumeLength(m_range, m_context.mode, ValueRangeNonNegative);
case CSSPropertyCounterIncrement:
case CSSPropertyCounterReset:
return consumeCounter(m_range, property == CSSPropertyCounterIncrement ? 1 : 0);
case CSSPropertySize:
return consumeSize(m_range, m_context.mode);
case CSSPropertyTextIndent:
return consumeTextIndent(m_range, m_context.mode);
case CSSPropertyMaxWidth:
case CSSPropertyMaxHeight:
return consumeMaxWidthOrHeight(m_range, m_context, UnitlessQuirk::Allow);
case CSSPropertyWebkitMaxLogicalWidth:
case CSSPropertyWebkitMaxLogicalHeight:
return consumeMaxWidthOrHeight(m_range, m_context);
case CSSPropertyMinWidth:
case CSSPropertyMinHeight:
case CSSPropertyWidth:
case CSSPropertyHeight:
return consumeWidthOrHeight(m_range, m_context, UnitlessQuirk::Allow);
case CSSPropertyWebkitMinLogicalWidth:
case CSSPropertyWebkitMinLogicalHeight:
case CSSPropertyWebkitLogicalWidth:
case CSSPropertyWebkitLogicalHeight:
return consumeWidthOrHeight(m_range, m_context);
case CSSPropertyMarginTop:
case CSSPropertyMarginRight:
case CSSPropertyMarginBottom:
case CSSPropertyMarginLeft:
case CSSPropertyBottom:
case CSSPropertyLeft:
case CSSPropertyRight:
case CSSPropertyTop:
return consumeMarginOrOffset(m_range, m_context.mode, UnitlessQuirk::Allow);
case CSSPropertyWebkitMarginStart:
case CSSPropertyWebkitMarginEnd:
case CSSPropertyWebkitMarginBefore:
case CSSPropertyWebkitMarginAfter:
return consumeMarginOrOffset(m_range, m_context.mode, UnitlessQuirk::Forbid);
case CSSPropertyPaddingTop:
case CSSPropertyPaddingRight:
case CSSPropertyPaddingBottom:
case CSSPropertyPaddingLeft:
return consumeLengthOrPercent(m_range, m_context.mode, ValueRangeNonNegative, UnitlessQuirk::Allow);
case CSSPropertyWebkitPaddingStart:
case CSSPropertyWebkitPaddingEnd:
case CSSPropertyWebkitPaddingBefore:
case CSSPropertyWebkitPaddingAfter:
return consumeLengthOrPercent(m_range, m_context.mode, ValueRangeNonNegative, UnitlessQuirk::Forbid);
#if ENABLE(CSS_SCROLL_SNAP)
case CSSPropertyScrollSnapMarginBottom:
case CSSPropertyScrollSnapMarginLeft:
case CSSPropertyScrollSnapMarginRight:
case CSSPropertyScrollSnapMarginTop:
return consumeLength(m_range, m_context.mode, ValueRangeAll);
case CSSPropertyScrollPaddingBottom:
case CSSPropertyScrollPaddingLeft:
case CSSPropertyScrollPaddingRight:
case CSSPropertyScrollPaddingTop:
return consumeLengthOrPercent(m_range, m_context.mode, ValueRangeAll);
case CSSPropertyScrollSnapAlign:
return consumeScrollSnapAlign(m_range);
case CSSPropertyScrollSnapType:
return consumeScrollSnapType(m_range);
#endif
case CSSPropertyClip:
return consumeClip(m_range, m_context.mode);
#if ENABLE(TOUCH_EVENTS)
case CSSPropertyTouchAction:
return consumeTouchAction(m_range);
#endif
case CSSPropertyObjectPosition:
return consumePosition(m_range, m_context.mode, UnitlessQuirk::Forbid);
case CSSPropertyWebkitLineClamp:
return consumeLineClamp(m_range);
case CSSPropertyWebkitFontSizeDelta:
return consumeLength(m_range, m_context.mode, ValueRangeAll, UnitlessQuirk::Allow);
case CSSPropertyWebkitHyphenateCharacter:
case CSSPropertyWebkitLocale:
return consumeLocale(m_range);
case CSSPropertyWebkitHyphenateLimitBefore:
case CSSPropertyWebkitHyphenateLimitAfter:
return consumeHyphenateLimit(m_range, CSSValueAuto);
case CSSPropertyWebkitHyphenateLimitLines:
return consumeHyphenateLimit(m_range, CSSValueNoLimit);
case CSSPropertyColumnWidth:
return consumeColumnWidth(m_range);
case CSSPropertyColumnCount:
return consumeColumnCount(m_range);
case CSSPropertyColumnGap:
return consumeColumnGap(m_range, m_context.mode);
case CSSPropertyColumnSpan:
return consumeColumnSpan(m_range);
case CSSPropertyZoom:
return consumeZoom(m_range, m_context);
case CSSPropertyAnimationDelay:
case CSSPropertyTransitionDelay:
case CSSPropertyAnimationDirection:
case CSSPropertyAnimationDuration:
case CSSPropertyTransitionDuration:
case CSSPropertyAnimationFillMode:
case CSSPropertyAnimationIterationCount:
case CSSPropertyAnimationName:
case CSSPropertyAnimationPlayState:
case CSSPropertyTransitionProperty:
case CSSPropertyAnimationTimingFunction:
case CSSPropertyTransitionTimingFunction:
#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
case CSSPropertyWebkitAnimationTrigger:
#endif
return consumeAnimationPropertyList(property, m_range, m_context);
case CSSPropertyGridColumnGap:
case CSSPropertyGridRowGap:
return consumeLength(m_range, m_context.mode, ValueRangeNonNegative);
case CSSPropertyShapeMargin:
return consumeLengthOrPercent(m_range, m_context.mode, ValueRangeNonNegative);
case CSSPropertyShapeImageThreshold:
return consumeNumber(m_range, ValueRangeAll);
case CSSPropertyWebkitBoxOrdinalGroup:
case CSSPropertyOrphans:
case CSSPropertyWidows:
return consumePositiveInteger(m_range);
case CSSPropertyWebkitTextDecorationColor:
return consumeColor(m_range, m_context.mode);
case CSSPropertyWebkitTextDecorationSkip:
return consumeTextDecorationSkip(m_range);
case CSSPropertyWebkitTextStrokeWidth:
return consumeTextStrokeWidth(m_range, m_context.mode);
case CSSPropertyWebkitTextFillColor:
#if ENABLE(TOUCH_EVENTS)
case CSSPropertyWebkitTapHighlightColor:
#endif
case CSSPropertyWebkitTextEmphasisColor:
case CSSPropertyWebkitBorderStartColor:
case CSSPropertyWebkitBorderEndColor:
case CSSPropertyWebkitBorderBeforeColor:
case CSSPropertyWebkitBorderAfterColor:
case CSSPropertyWebkitTextStrokeColor:
case CSSPropertyStopColor:
case CSSPropertyFloodColor:
case CSSPropertyLightingColor:
case CSSPropertyColumnRuleColor:
return consumeColor(m_range, m_context.mode);
case CSSPropertyColor:
case CSSPropertyBackgroundColor:
return consumeColor(m_range, m_context.mode, inQuirksMode());
case CSSPropertyWebkitBorderStartWidth:
case CSSPropertyWebkitBorderEndWidth:
case CSSPropertyWebkitBorderBeforeWidth:
case CSSPropertyWebkitBorderAfterWidth:
return consumeBorderWidth(m_range, m_context.mode, UnitlessQuirk::Forbid);
case CSSPropertyBorderBottomColor:
case CSSPropertyBorderLeftColor:
case CSSPropertyBorderRightColor:
case CSSPropertyBorderTopColor: {
bool allowQuirkyColors = inQuirksMode()
&& (currentShorthand == CSSPropertyInvalid || currentShorthand == CSSPropertyBorderColor);
return consumeColor(m_range, m_context.mode, allowQuirkyColors);
}
case CSSPropertyBorderBottomWidth:
case CSSPropertyBorderLeftWidth:
case CSSPropertyBorderRightWidth:
case CSSPropertyBorderTopWidth: {
bool allowQuirkyLengths = inQuirksMode()
&& (currentShorthand == CSSPropertyInvalid || currentShorthand == CSSPropertyBorderWidth);
UnitlessQuirk unitless = allowQuirkyLengths ? UnitlessQuirk::Allow : UnitlessQuirk::Forbid;
return consumeBorderWidth(m_range, m_context.mode, unitless);
}
case CSSPropertyZIndex:
return consumeZIndex(m_range);
case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS3, so treat as CSS3
case CSSPropertyBoxShadow:
case CSSPropertyWebkitBoxShadow:
case CSSPropertyWebkitSvgShadow:
return consumeShadow(m_range, m_context.mode, property == CSSPropertyBoxShadow || property == CSSPropertyWebkitBoxShadow);
case CSSPropertyFilter:
#if ENABLE(FILTERS_LEVEL_2)
case CSSPropertyWebkitBackdropFilter:
#endif
return consumeFilter(m_range, m_context);
case CSSPropertyTextDecoration:
case CSSPropertyWebkitTextDecorationsInEffect:
case CSSPropertyWebkitTextDecorationLine:
return consumeTextDecorationLine(m_range);
case CSSPropertyWebkitTextEmphasisStyle:
return consumeTextEmphasisStyle(m_range);
case CSSPropertyOutlineColor:
return consumeOutlineColor(m_range, m_context.mode);
case CSSPropertyOutlineOffset:
return consumeLength(m_range, m_context.mode, ValueRangeAll);
case CSSPropertyOutlineWidth:
return consumeLineWidth(m_range, m_context.mode, UnitlessQuirk::Forbid);
case CSSPropertyTransform:
return consumeTransform(m_range, m_context.mode);
case CSSPropertyTransformOriginX:
case CSSPropertyPerspectiveOriginX:
return consumePositionX(m_range, m_context.mode);
case CSSPropertyTransformOriginY:
case CSSPropertyPerspectiveOriginY:
return consumePositionY(m_range, m_context.mode);
case CSSPropertyTransformOriginZ:
return consumeLength(m_range, m_context.mode, ValueRangeAll);
case CSSPropertyFill:
case CSSPropertyStroke:
return consumePaintStroke(m_range, m_context.mode);
case CSSPropertyGlyphOrientationVertical:
case CSSPropertyGlyphOrientationHorizontal:
return consumeGlyphOrientation(m_range, m_context.mode, property);
case CSSPropertyPaintOrder:
return consumePaintOrder(m_range);
case CSSPropertyMarkerStart:
case CSSPropertyMarkerMid:
case CSSPropertyMarkerEnd:
case CSSPropertyClipPath:
case CSSPropertyMask:
return consumeNoneOrURI(m_range);
case CSSPropertyFlexBasis:
return consumeFlexBasis(m_range, m_context.mode);
case CSSPropertyFlexGrow:
case CSSPropertyFlexShrink:
return consumeNumber(m_range, ValueRangeNonNegative);
case CSSPropertyStrokeDasharray:
return consumeStrokeDasharray(m_range);
case CSSPropertyColumnRuleWidth:
return consumeColumnRuleWidth(m_range, m_context.mode);
case CSSPropertyStrokeOpacity:
case CSSPropertyFillOpacity:
case CSSPropertyStopOpacity:
case CSSPropertyFloodOpacity:
case CSSPropertyOpacity:
case CSSPropertyWebkitBoxFlex:
return consumeNumber(m_range, ValueRangeAll);
case CSSPropertyBaselineShift:
return consumeBaselineShift(m_range);
case CSSPropertyKerning:
return consumeKerning(m_range, m_context.mode);
case CSSPropertyStrokeMiterlimit:
return consumeNumber(m_range, ValueRangeNonNegative);
case CSSPropertyStrokeWidth:
case CSSPropertyStrokeDashoffset:
case CSSPropertyCx:
case CSSPropertyCy:
case CSSPropertyX:
case CSSPropertyY:
case CSSPropertyR:
return consumeLengthOrPercent(m_range, SVGAttributeMode, ValueRangeAll, UnitlessQuirk::Forbid);
case CSSPropertyRx:
case CSSPropertyRy:
return consumeRxOrRy(m_range);
case CSSPropertyCursor:
return consumeCursor(m_range, m_context, inQuirksMode());
case CSSPropertyContent:
return consumeContent(m_range, m_context);
case CSSPropertyListStyleImage:
case CSSPropertyBorderImageSource:
case CSSPropertyWebkitMaskBoxImageSource:
return consumeImageOrNone(m_range, m_context);
case CSSPropertyPerspective:
return consumePerspective(m_range, m_context.mode);
case CSSPropertyBorderTopRightRadius:
case CSSPropertyBorderTopLeftRadius:
case CSSPropertyBorderBottomLeftRadius:
case CSSPropertyBorderBottomRightRadius:
return consumeBorderRadiusCorner(m_range, m_context.mode);
case CSSPropertyWebkitBoxFlexGroup:
return consumeInteger(m_range, 0);
case CSSPropertyOrder:
return consumeInteger(m_range);
case CSSPropertyWebkitTextUnderlinePosition:
// auto | alphabetic | [ under || [ left | right ] ], but we only support auto | alphabetic | under for now
return consumeIdent<CSSValueAuto, CSSValueUnder, CSSValueAlphabetic>(m_range);
case CSSPropertyVerticalAlign:
return consumeVerticalAlign(m_range, m_context.mode);
case CSSPropertyShapeOutside:
return consumeShapeOutside(m_range, m_context);
case CSSPropertyWebkitClipPath:
return consumeWebkitClipPath(m_range, m_context);
case CSSPropertyJustifyContent:
case CSSPropertyAlignContent:
return consumeContentDistributionOverflowPosition(m_range);
case CSSPropertyBorderImageRepeat:
case CSSPropertyWebkitMaskBoxImageRepeat:
return consumeBorderImageRepeat(m_range);
case CSSPropertyBorderImageSlice:
case CSSPropertyWebkitMaskBoxImageSlice:
return consumeBorderImageSlice(property, m_range);
case CSSPropertyBorderImageOutset:
case CSSPropertyWebkitMaskBoxImageOutset:
return consumeBorderImageOutset(m_range);
case CSSPropertyBorderImageWidth:
case CSSPropertyWebkitMaskBoxImageWidth:
return consumeBorderImageWidth(m_range);
case CSSPropertyWebkitBorderImage:
case CSSPropertyWebkitMaskBoxImage:
return consumeWebkitBorderImage(property, m_range, m_context);
case CSSPropertyWebkitBoxReflect:
return consumeReflect(m_range, m_context);
case CSSPropertyWebkitLineBoxContain:
return consumeLineBoxContain(m_range);
#if ENABLE(CSS_IMAGE_ORIENTATION)
case CSSPropertyImageOrientation:
return consumeImageOrientation(m_range, m_context.mode);
#endif
case CSSPropertyBackgroundAttachment:
case CSSPropertyBackgroundBlendMode:
case CSSPropertyBackgroundClip:
case CSSPropertyBackgroundImage:
case CSSPropertyBackgroundOrigin:
case CSSPropertyBackgroundPositionX:
case CSSPropertyBackgroundPositionY:
case CSSPropertyBackgroundSize:
case CSSPropertyWebkitBackgroundClip:
case CSSPropertyWebkitBackgroundOrigin:
case CSSPropertyWebkitBackgroundComposite:
case CSSPropertyWebkitBackgroundSize:
case CSSPropertyWebkitMaskClip:
case CSSPropertyWebkitMaskComposite:
case CSSPropertyWebkitMaskImage:
case CSSPropertyWebkitMaskOrigin:
case CSSPropertyWebkitMaskPositionX:
case CSSPropertyWebkitMaskPositionY:
case CSSPropertyWebkitMaskSize:
case CSSPropertyWebkitMaskSourceType:
return consumeCommaSeparatedBackgroundComponent(property, m_range, m_context);
case CSSPropertyWebkitMaskRepeatX:
case CSSPropertyWebkitMaskRepeatY:
return nullptr;
case CSSPropertyAlignItems:
if (!m_context.cssGridLayoutEnabled)
return nullptr;
return consumeAlignItems(m_range);
case CSSPropertyJustifySelf:
case CSSPropertyAlignSelf:
if (!m_context.cssGridLayoutEnabled)
return nullptr;
return consumeSelfPositionOverflowPosition(m_range);
case CSSPropertyJustifyItems:
if (!m_context.cssGridLayoutEnabled)
return nullptr;
return consumeJustifyItems(m_range);
case CSSPropertyGridColumnEnd:
case CSSPropertyGridColumnStart:
case CSSPropertyGridRowEnd:
case CSSPropertyGridRowStart:
if (!m_context.cssGridLayoutEnabled)
return nullptr;
return consumeGridLine(m_range);
case CSSPropertyGridAutoColumns:
case CSSPropertyGridAutoRows:
if (!m_context.cssGridLayoutEnabled)
return nullptr;
return consumeGridTrackList(m_range, m_context.mode, GridAuto);
case CSSPropertyGridTemplateColumns:
case CSSPropertyGridTemplateRows:
if (!m_context.cssGridLayoutEnabled)
return nullptr;
return consumeGridTemplatesRowsOrColumns(m_range, m_context.mode);
case CSSPropertyGridTemplateAreas:
if (!m_context.cssGridLayoutEnabled)
return nullptr;
return consumeGridTemplateAreas(m_range);
case CSSPropertyGridAutoFlow:
if (!m_context.cssGridLayoutEnabled)
return nullptr;
return consumeGridAutoFlow(m_range);
#if ENABLE(CSS_REGIONS)
case CSSPropertyWebkitFlowInto:
case CSSPropertyWebkitFlowFrom:
return consumeFlowProperty(m_range);
#endif
case CSSPropertyWebkitLineGrid:
return consumeLineGrid(m_range);
case CSSPropertyWebkitInitialLetter:
return consumeInitialLetter(m_range);
case CSSPropertyHangingPunctuation:
return consumeHangingPunctuation(m_range);
case CSSPropertyWebkitMarqueeIncrement:
return consumeWebkitMarqueeIncrement(m_range, m_context.mode);
case CSSPropertyWebkitMarqueeRepetition:
return consumeWebkitMarqueeRepetition(m_range);
case CSSPropertyWebkitMarqueeSpeed:
return consumeWebkitMarqueeSpeed(m_range, m_context.mode);
case CSSPropertyAlt:
return consumeAlt(m_range, m_context);
case CSSPropertyWebkitAspectRatio:
return consumeWebkitAspectRatio(m_range);
case CSSPropertyWebkitTextEmphasisPosition:
return consumeTextEmphasisPosition(m_range);
#if ENABLE(DASHBOARD_SUPPORT)
case CSSPropertyWebkitDashboardRegion:
return consumeWebkitDashboardRegion(m_range, m_context.mode);
#endif
default:
return nullptr;
}
}
static RefPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParserTokenRange& range)
{
RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
do {
const CSSParserToken& token = range.consumeIncludingWhitespace();
if (token.type() != UnicodeRangeToken)
return nullptr;
UChar32 start = token.unicodeRangeStart();
UChar32 end = token.unicodeRangeEnd();
if (start > end)
return nullptr;
values->append(CSSUnicodeRangeValue::create(start, end));
} while (consumeCommaIncludingWhitespace(range));
return values;
}
static RefPtr<CSSValue> consumeFontFaceSrcURI(CSSParserTokenRange& range, const CSSParserContext& context)
{
String url = consumeUrlAsStringView(range).toString();
if (url.isNull())
return nullptr;
RefPtr<CSSFontFaceSrcValue> uriValue = CSSFontFaceSrcValue::create(context.completeURL(url));
if (range.peek().functionId() != CSSValueFormat)
return uriValue;
// FIXME: https://drafts.csswg.org/css-fonts says that format() contains a comma-separated list of strings,
// but CSSFontFaceSrcValue stores only one format. Allowing one format for now.
// FIXME: We're allowing the format to be an identifier as well as a string, because the old
// parser did. It's not clear if we need to continue to support this behavior, but we have lots of
// layout tests that rely on it.
CSSParserTokenRange args = consumeFunction(range);
const CSSParserToken& arg = args.consumeIncludingWhitespace();
if ((arg.type() != StringToken && arg.type() != IdentToken) || !args.atEnd())
return nullptr;
uriValue->setFormat(arg.value().toString());
return uriValue;
}
static RefPtr<CSSValue> consumeFontFaceSrcLocal(CSSParserTokenRange& range)
{
CSSParserTokenRange args = consumeFunction(range);
if (args.peek().type() == StringToken) {
const CSSParserToken& arg = args.consumeIncludingWhitespace();
if (!args.atEnd())
return nullptr;
return CSSFontFaceSrcValue::createLocal(arg.value().toString());
}
if (args.peek().type() == IdentToken) {
String familyName = concatenateFamilyName(args);
if (!args.atEnd())
return nullptr;
return CSSFontFaceSrcValue::createLocal(familyName);
}
return nullptr;
}
static RefPtr<CSSValueList> consumeFontFaceSrc(CSSParserTokenRange& range, const CSSParserContext& context)
{
RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
do {
const CSSParserToken& token = range.peek();
RefPtr<CSSValue> parsedValue;
if (token.functionId() == CSSValueLocal)
parsedValue = consumeFontFaceSrcLocal(range);
else
parsedValue = consumeFontFaceSrcURI(range, context);
if (!parsedValue)
return nullptr;
values->append(parsedValue.releaseNonNull());
} while (consumeCommaIncludingWhitespace(range));
return values;
}
bool CSSPropertyParser::parseFontFaceDescriptor(CSSPropertyID propId)
{
RefPtr<CSSValue> parsedValue;
switch (propId) {
case CSSPropertyFontFamily:
parsedValue = consumeFontFamilyDescriptor(m_range);
break;
case CSSPropertySrc: // This is a list of urls or local references.
parsedValue = consumeFontFaceSrc(m_range, m_context);
break;
case CSSPropertyUnicodeRange:
parsedValue = consumeFontFaceUnicodeRange(m_range);
break;
case CSSPropertyFontStretch:
case CSSPropertyFontStyle: {
CSSValueID id = m_range.consumeIncludingWhitespace().id();
if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(propId, id, m_context.mode))
return false;
parsedValue = CSSValuePool::singleton().createIdentifierValue(id);
break;
}
case CSSPropertyFontVariantCaps:
parsedValue = consumeFontVariantCaps(m_range);
break;
case CSSPropertyFontVariantLigatures:
parsedValue = consumeFontVariantLigatures(m_range);
break;
case CSSPropertyFontVariantNumeric:
parsedValue = consumeFontVariantNumeric(m_range);
break;
case CSSPropertyFontVariantEastAsian:
parsedValue = consumeFontVariantEastAsian(m_range);
break;
case CSSPropertyFontVariantAlternates:
parsedValue = consumeFontVariantAlternates(m_range);
break;
case CSSPropertyFontVariantPosition:
parsedValue = consumeFontVariantPosition(m_range);
break;
case CSSPropertyFontVariant:
return consumeFontVariantShorthand(false);
case CSSPropertyFontWeight:
parsedValue = consumeFontWeight(m_range);
break;
case CSSPropertyFontFeatureSettings:
parsedValue = consumeFontFeatureSettings(m_range);
break;
default:
break;
}
if (!parsedValue || !m_range.atEnd())
return false;
addProperty(propId, CSSPropertyInvalid, *parsedValue, false);
return true;
}
bool CSSPropertyParser::consumeSystemFont(bool important)
{
CSSValueID systemFontID = m_range.consumeIncludingWhitespace().id();
ASSERT(systemFontID >= CSSValueCaption && systemFontID <= CSSValueStatusBar);
if (!m_range.atEnd())
return false;
FontCascadeDescription fontDescription;
RenderTheme::defaultTheme()->systemFont(systemFontID, fontDescription);
if (!fontDescription.isAbsoluteSize())
return false;
addProperty(CSSPropertyFontStyle, CSSPropertyFont, CSSValuePool::singleton().createIdentifierValue(fontDescription.italic() == FontItalicOn ? CSSValueItalic : CSSValueNormal), important);
addProperty(CSSPropertyFontWeight, CSSPropertyFont, CSSValuePool::singleton().createValue(fontDescription.weight()), important);
addProperty(CSSPropertyFontSize, CSSPropertyFont, CSSValuePool::singleton().createValue(fontDescription.specifiedSize(), CSSPrimitiveValue::CSS_PX), important);
Ref<CSSValueList> fontFamilyList = CSSValueList::createCommaSeparated();
fontFamilyList->append(CSSValuePool::singleton().createFontFamilyValue(fontDescription.familyAt(0), FromSystemFontID::Yes));
addProperty(CSSPropertyFontFamily, CSSPropertyFont, WTFMove(fontFamilyList), important);
addProperty(CSSPropertyFontVariantCaps, CSSPropertyFont, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important);
addProperty(CSSPropertyLineHeight, CSSPropertyFont, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important);
// FIXME_NEWPARSER: What about FontVariantNumeric and FontVariantLigatures?
return true;
}
bool CSSPropertyParser::consumeFont(bool important)
{
// Let's check if there is an inherit or initial somewhere in the shorthand.
CSSParserTokenRange range = m_range;
while (!range.atEnd()) {
CSSValueID id = range.consumeIncludingWhitespace().id();
if (id == CSSValueInherit || id == CSSValueInitial)
return false;
}
// Optional font-style, font-variant, font-stretch and font-weight.
RefPtr<CSSPrimitiveValue> fontStyle;
RefPtr<CSSPrimitiveValue> fontVariantCaps;
RefPtr<CSSPrimitiveValue> fontWeight;
// FIXME-NEWPARSER: Implement. RefPtr<CSSPrimitiveValue> fontStretch;
while (!m_range.atEnd()) {
CSSValueID id = m_range.peek().id();
if (!fontStyle && CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyFontStyle, id, m_context.mode)) {
fontStyle = consumeIdent(m_range);
continue;
}
if (!fontVariantCaps && (id == CSSValueNormal || id == CSSValueSmallCaps)) {
// Font variant in the shorthand is particular, it only accepts normal or small-caps.
// See https://drafts.csswg.org/css-fonts/#propdef-font
fontVariantCaps = consumeFontVariantCSS21(m_range);
if (fontVariantCaps)
continue;
}
if (!fontWeight) {
fontWeight = consumeFontWeight(m_range);
if (fontWeight)
continue;
}
/* FIXME-NEWPARSER: Implement
if (!fontStretch && CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyFontStretch, id, m_context.mode, m_styleSheetContents))
fontStretch = consumeIdent(m_range);
else*/
break;
}
if (m_range.atEnd())
return false;
bool hasStyle = fontStyle;
bool hasVariant = fontVariantCaps;
bool hasWeight = fontWeight;
addProperty(CSSPropertyFontStyle, CSSPropertyFont, fontStyle ? fontStyle.releaseNonNull() : CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, !hasStyle);
addProperty(CSSPropertyFontVariantCaps, CSSPropertyFont, fontVariantCaps ? fontVariantCaps.releaseNonNull() : CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, !hasVariant);
/*
// FIXME-NEWPARSER: What do we do with these? They aren't part of our fontShorthand().
addProperty(CSSPropertyFontVariantLigatures, CSSPropertyFont, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, true);
addProperty(CSSPropertyFontVariantNumeric, CSSPropertyFont, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, true);
*/
addProperty(CSSPropertyFontWeight, CSSPropertyFont, fontWeight ? fontWeight.releaseNonNull() : CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, !hasWeight);
// Now a font size _must_ come.
RefPtr<CSSValue> fontSize = consumeFontSize(m_range, m_context.mode);
if (!fontSize || m_range.atEnd())
return false;
addProperty(CSSPropertyFontSize, CSSPropertyFont, *fontSize, important);
if (consumeSlashIncludingWhitespace(m_range)) {
RefPtr<CSSPrimitiveValue> lineHeight = consumeLineHeight(m_range, m_context.mode);
if (!lineHeight)
return false;
addProperty(CSSPropertyLineHeight, CSSPropertyFont, lineHeight.releaseNonNull(), important);
} else {
addProperty(CSSPropertyLineHeight, CSSPropertyFont, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, true);
}
// Font family must come now.
RefPtr<CSSValue> parsedFamilyValue = consumeFontFamily(m_range);
if (!parsedFamilyValue)
return false;
addProperty(CSSPropertyFontFamily, CSSPropertyFont, parsedFamilyValue.releaseNonNull(), important);
return m_range.atEnd();
}
bool CSSPropertyParser::consumeFontVariantShorthand(bool important)
{
if (identMatches<CSSValueNormal, CSSValueNone>(m_range.peek().id())) {
addProperty(CSSPropertyFontVariantLigatures, CSSPropertyFontVariant, consumeIdent(m_range).releaseNonNull(), important);
addProperty(CSSPropertyFontVariantCaps, CSSPropertyFontVariant, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important);
addProperty(CSSPropertyFontVariantEastAsian, CSSPropertyFontVariant, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important);
addProperty(CSSPropertyFontVariantPosition, CSSPropertyFontVariant, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important);
return m_range.atEnd();
}
RefPtr<CSSPrimitiveValue> capsValue;
RefPtr<CSSPrimitiveValue> alternatesValue;
RefPtr<CSSPrimitiveValue> positionValue;
RefPtr<CSSValue> eastAsianValue;
FontVariantLigaturesParser ligaturesParser;
FontVariantNumericParser numericParser;
do {
if (!capsValue) {
capsValue = consumeFontVariantCaps(m_range);
if (capsValue)
continue;
}
if (!positionValue) {
positionValue = consumeFontVariantPosition(m_range);
if (positionValue)
continue;
}
if (!alternatesValue) {
alternatesValue = consumeFontVariantAlternates(m_range);
if (alternatesValue)
continue;
}
FontVariantLigaturesParser::ParseResult ligaturesParseResult = ligaturesParser.consumeLigature(m_range);
FontVariantNumericParser::ParseResult numericParseResult = numericParser.consumeNumeric(m_range);
if (ligaturesParseResult == FontVariantLigaturesParser::ParseResult::ConsumedValue
|| numericParseResult == FontVariantNumericParser::ParseResult::ConsumedValue)
continue;
if (ligaturesParseResult == FontVariantLigaturesParser::ParseResult::DisallowedValue
|| numericParseResult == FontVariantNumericParser::ParseResult::DisallowedValue)
return false;
if (!eastAsianValue) {
eastAsianValue = consumeFontVariantEastAsian(m_range);
if (eastAsianValue)
continue;
}
// Saw some value that didn't match anything else.
return false;
} while (!m_range.atEnd());
addProperty(CSSPropertyFontVariantLigatures, CSSPropertyFontVariant, ligaturesParser.finalizeValue().releaseNonNull(), important);
addProperty(CSSPropertyFontVariantNumeric, CSSPropertyFontVariant, numericParser.finalizeValue().releaseNonNull(), important);
addProperty(CSSPropertyFontVariantCaps, CSSPropertyFontVariant, capsValue ? capsValue.releaseNonNull() : CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important);
addProperty(CSSPropertyFontVariantAlternates, CSSPropertyFontVariant, alternatesValue ? alternatesValue.releaseNonNull() : CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important);
addProperty(CSSPropertyFontVariantPosition, CSSPropertyFontVariant, positionValue ? positionValue.releaseNonNull() : CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important);
if (!eastAsianValue)
eastAsianValue = CSSValuePool::singleton().createIdentifierValue(CSSValueNormal);
addProperty(CSSPropertyFontVariantEastAsian, CSSPropertyFontVariant, eastAsianValue.releaseNonNull(), important);
return true;
}
bool CSSPropertyParser::consumeBorderSpacing(bool important)
{
RefPtr<CSSValue> horizontalSpacing = consumeLength(m_range, m_context.mode, ValueRangeNonNegative, UnitlessQuirk::Allow);
if (!horizontalSpacing)
return false;
RefPtr<CSSValue> verticalSpacing = horizontalSpacing;
if (!m_range.atEnd())
verticalSpacing = consumeLength(m_range, m_context.mode, ValueRangeNonNegative, UnitlessQuirk::Allow);
if (!verticalSpacing || !m_range.atEnd())
return false;
addProperty(CSSPropertyWebkitBorderHorizontalSpacing, CSSPropertyBorderSpacing, horizontalSpacing.releaseNonNull(), important);
addProperty(CSSPropertyWebkitBorderVerticalSpacing, CSSPropertyBorderSpacing, verticalSpacing.releaseNonNull(), important);
return true;
}
#if ENABLE(CSS_DEVICE_ADAPTATION)
static RefPtr<CSSValue> consumeSingleViewportDescriptor(CSSParserTokenRange& range, CSSPropertyID propId, CSSParserMode cssParserMode)
{
CSSValueID id = range.peek().id();
switch (propId) {
case CSSPropertyMinWidth:
case CSSPropertyMaxWidth:
case CSSPropertyMinHeight:
case CSSPropertyMaxHeight:
if (id == CSSValueAuto)
return consumeIdent(range);
return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative);
case CSSPropertyMinZoom:
case CSSPropertyMaxZoom:
case CSSPropertyZoom: {
if (id == CSSValueAuto)
return consumeIdent(range);
RefPtr<CSSValue> parsedValue = consumeNumber(range, ValueRangeNonNegative);
if (parsedValue)
return parsedValue;
return consumePercent(range, ValueRangeNonNegative);
}
case CSSPropertyUserZoom:
return consumeIdent<CSSValueZoom, CSSValueFixed>(range);
case CSSPropertyOrientation:
return consumeIdent<CSSValueAuto, CSSValuePortrait, CSSValueLandscape>(range);
default:
ASSERT_NOT_REACHED();
break;
}
ASSERT_NOT_REACHED();
return nullptr;
}
bool CSSPropertyParser::parseViewportDescriptor(CSSPropertyID propId, bool important)
{
switch (propId) {
case CSSPropertyWidth: {
RefPtr<CSSValue> minWidth = consumeSingleViewportDescriptor(m_range, CSSPropertyMinWidth, m_context.mode);
if (!minWidth)
return false;
RefPtr<CSSValue> maxWidth = minWidth;
if (!m_range.atEnd())
maxWidth = consumeSingleViewportDescriptor(m_range, CSSPropertyMaxWidth, m_context.mode);
if (!maxWidth || !m_range.atEnd())
return false;
addProperty(CSSPropertyMinWidth, CSSPropertyInvalid, *minWidth, important);
addProperty(CSSPropertyMaxWidth, CSSPropertyInvalid, *maxWidth, important);
return true;
}
case CSSPropertyHeight: {
RefPtr<CSSValue> minHeight = consumeSingleViewportDescriptor(m_range, CSSPropertyMinHeight, m_context.mode);
if (!minHeight)
return false;
RefPtr<CSSValue> maxHeight = minHeight;
if (!m_range.atEnd())
maxHeight = consumeSingleViewportDescriptor(m_range, CSSPropertyMaxHeight, m_context.mode);
if (!maxHeight || !m_range.atEnd())
return false;
addProperty(CSSPropertyMinHeight, CSSPropertyInvalid, *minHeight, important);
addProperty(CSSPropertyMaxHeight, CSSPropertyInvalid, *maxHeight, important);
return true;
}
case CSSPropertyMinWidth:
case CSSPropertyMaxWidth:
case CSSPropertyMinHeight:
case CSSPropertyMaxHeight:
case CSSPropertyMinZoom:
case CSSPropertyMaxZoom:
case CSSPropertyZoom:
case CSSPropertyUserZoom:
case CSSPropertyOrientation: {
RefPtr<CSSValue> parsedValue = consumeSingleViewportDescriptor(m_range, propId, m_context.mode);
if (!parsedValue || !m_range.atEnd())
return false;
addProperty(propId, CSSPropertyInvalid, parsedValue.releaseNonNull(), important);
return true;
}
default:
return false;
}
}
#endif
bool CSSPropertyParser::consumeColumns(bool important)
{
RefPtr<CSSValue> columnWidth;
RefPtr<CSSValue> columnCount;
bool hasPendingExplicitAuto = false;
for (unsigned propertiesParsed = 0; propertiesParsed < 2 && !m_range.atEnd(); ++propertiesParsed) {
if (!propertiesParsed && m_range.peek().id() == CSSValueAuto) {
// 'auto' is a valid value for any of the two longhands, and at this point
// we don't know which one(s) it is meant for. We need to see if there are other values first.
consumeIdent(m_range);
hasPendingExplicitAuto = true;
} else {
if (!columnWidth) {
if ((columnWidth = consumeColumnWidth(m_range)))
continue;
}
if (!columnCount) {
if ((columnCount = consumeColumnCount(m_range)))
continue;
}
// If we didn't find at least one match, this is an invalid shorthand and we have to ignore it.
return false;
}
}
if (!m_range.atEnd())
return false;
// Any unassigned property at this point will become implicit 'auto'.
if (columnWidth)
addProperty(CSSPropertyColumnWidth, CSSPropertyInvalid, columnWidth.releaseNonNull(), important);
else {
addProperty(CSSPropertyColumnWidth, CSSPropertyInvalid, CSSValuePool::singleton().createIdentifierValue(CSSValueAuto), important, !hasPendingExplicitAuto /* implicit */);
hasPendingExplicitAuto = false;
}
if (columnCount)
addProperty(CSSPropertyColumnCount, CSSPropertyInvalid, columnCount.releaseNonNull(), important);
else
addProperty(CSSPropertyColumnCount, CSSPropertyInvalid, CSSValuePool::singleton().createIdentifierValue(CSSValueAuto), important, !hasPendingExplicitAuto /* implicit */);
return true;
}
bool CSSPropertyParser::consumeShorthandGreedily(const StylePropertyShorthand& shorthand, bool important)
{
ASSERT(shorthand.length() <= 6); // Existing shorthands have at most 6 longhands.
RefPtr<CSSValue> longhands[6];
const CSSPropertyID* shorthandProperties = shorthand.properties();
do {
bool foundLonghand = false;
for (size_t i = 0; !foundLonghand && i < shorthand.length(); ++i) {
if (longhands[i])
continue;
longhands[i] = parseSingleValue(shorthandProperties[i], shorthand.id());
if (longhands[i])
foundLonghand = true;
}
if (!foundLonghand)
return false;
} while (!m_range.atEnd());
for (size_t i = 0; i < shorthand.length(); ++i) {
if (longhands[i])
addProperty(shorthandProperties[i], shorthand.id(), longhands[i].releaseNonNull(), important);
else
addProperty(shorthandProperties[i], shorthand.id(), CSSValuePool::singleton().createImplicitInitialValue(), important);
}
return true;
}
bool CSSPropertyParser::consumeFlex(bool important)
{
static const double unsetValue = -1;
double flexGrow = unsetValue;
double flexShrink = unsetValue;
RefPtr<CSSPrimitiveValue> flexBasis;
if (m_range.peek().id() == CSSValueNone) {
flexGrow = 0;
flexShrink = 0;
flexBasis = CSSValuePool::singleton().createIdentifierValue(CSSValueAuto);
m_range.consumeIncludingWhitespace();
} else {
unsigned index = 0;
while (!m_range.atEnd() && index++ < 3) {
double num;
if (consumeNumberRaw(m_range, num)) {
if (num < 0)
return false;
if (flexGrow == unsetValue)
flexGrow = num;
else if (flexShrink == unsetValue)
flexShrink = num;
else if (!num) // flex only allows a basis of 0 (sans units) if flex-grow and flex-shrink values have already been set.
flexBasis = CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::CSS_PX);
else
return false;
} else if (!flexBasis) {
if (m_range.peek().id() == CSSValueAuto)
flexBasis = consumeIdent(m_range);
if (!flexBasis)
flexBasis = consumeLengthOrPercent(m_range, m_context.mode, ValueRangeNonNegative);
if (index == 2 && !m_range.atEnd())
return false;
}
}
if (index == 0)
return false;
if (flexGrow == unsetValue)
flexGrow = 1;
if (flexShrink == unsetValue)
flexShrink = 1;
if (!flexBasis)
flexBasis = CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::CSS_PX);
}
if (!m_range.atEnd())
return false;
addProperty(CSSPropertyFlexGrow, CSSPropertyFlex, CSSPrimitiveValue::create(clampTo<float>(flexGrow), CSSPrimitiveValue::UnitType::CSS_NUMBER), important);
addProperty(CSSPropertyFlexShrink, CSSPropertyFlex, CSSPrimitiveValue::create(clampTo<float>(flexShrink), CSSPrimitiveValue::UnitType::CSS_NUMBER), important);
addProperty(CSSPropertyFlexBasis, CSSPropertyFlex, flexBasis.releaseNonNull(), important);
return true;
}
bool CSSPropertyParser::consumeBorder(bool important)
{
RefPtr<CSSValue> width;
RefPtr<CSSValue> style;
RefPtr<CSSValue> color;
while (!width || !style || !color) {
if (!width) {
width = consumeLineWidth(m_range, m_context.mode, UnitlessQuirk::Forbid);
if (width)
continue;
}
if (!style) {
style = parseSingleValue(CSSPropertyBorderLeftStyle, CSSPropertyBorder);
if (style)
continue;
}
if (!color) {
color = consumeColor(m_range, m_context.mode);
if (color)
continue;
}
break;
}
if (!width && !style && !color)
return false;
if (!width)
width = CSSValuePool::singleton().createImplicitInitialValue();
if (!style)
style = CSSValuePool::singleton().createImplicitInitialValue();
if (!color)
color = CSSValuePool::singleton().createImplicitInitialValue();
addExpandedPropertyForValue(CSSPropertyBorderWidth, width.releaseNonNull(), important);
addExpandedPropertyForValue(CSSPropertyBorderStyle, style.releaseNonNull(), important);
addExpandedPropertyForValue(CSSPropertyBorderColor, color.releaseNonNull(), important);
addExpandedPropertyForValue(CSSPropertyBorderImage, CSSValuePool::singleton().createImplicitInitialValue(), important);
return m_range.atEnd();
}
bool CSSPropertyParser::consume4Values(const StylePropertyShorthand& shorthand, bool important)
{
ASSERT(shorthand.length() == 4);
const CSSPropertyID* longhands = shorthand.properties();
RefPtr<CSSValue> top = parseSingleValue(longhands[0], shorthand.id());
if (!top)
return false;
RefPtr<CSSValue> right = parseSingleValue(longhands[1], shorthand.id());
RefPtr<CSSValue> bottom;
RefPtr<CSSValue> left;
if (right) {
bottom = parseSingleValue(longhands[2], shorthand.id());
if (bottom)
left = parseSingleValue(longhands[3], shorthand.id());
}
bool rightImplicit = !right;
bool bottomImplicit = !bottom;
bool leftImplicit = !left;
if (!right)
right = top;
if (!bottom)
bottom = top;
if (!left)
left = right;
addProperty(longhands[0], shorthand.id(), top.releaseNonNull(), important);
addProperty(longhands[1], shorthand.id(), right.releaseNonNull(), important, rightImplicit);
addProperty(longhands[2], shorthand.id(), bottom.releaseNonNull(), important, bottomImplicit);
addProperty(longhands[3], shorthand.id(), left.releaseNonNull(), important, leftImplicit);
return m_range.atEnd();
}
bool CSSPropertyParser::consumeBorderImage(CSSPropertyID property, bool important)
{
RefPtr<CSSValue> source;
RefPtr<CSSValue> slice;
RefPtr<CSSValue> width;
RefPtr<CSSValue> outset;
RefPtr<CSSValue> repeat;
if (consumeBorderImageComponents(property, m_range, m_context, source, slice, width, outset, repeat)) {
if (!source)
source = CSSValuePool::singleton().createImplicitInitialValue();
if (!slice)
slice = CSSValuePool::singleton().createImplicitInitialValue();
if (!width)
width = CSSValuePool::singleton().createImplicitInitialValue();
if (!outset)
outset = CSSValuePool::singleton().createImplicitInitialValue();
if (!repeat)
repeat = CSSValuePool::singleton().createImplicitInitialValue();
switch (property) {
case CSSPropertyWebkitMaskBoxImage:
addProperty(CSSPropertyWebkitMaskBoxImageSource, CSSPropertyWebkitMaskBoxImage, source.releaseNonNull(), important);
addProperty(CSSPropertyWebkitMaskBoxImageSlice, CSSPropertyWebkitMaskBoxImage, slice.releaseNonNull(), important);
addProperty(CSSPropertyWebkitMaskBoxImageWidth, CSSPropertyWebkitMaskBoxImage, width.releaseNonNull(), important);
addProperty(CSSPropertyWebkitMaskBoxImageOutset, CSSPropertyWebkitMaskBoxImage, outset.releaseNonNull(), important);
addProperty(CSSPropertyWebkitMaskBoxImageRepeat, CSSPropertyWebkitMaskBoxImage, repeat.releaseNonNull(), important);
return true;
case CSSPropertyBorderImage:
addProperty(CSSPropertyBorderImageSource, CSSPropertyBorderImage, source.releaseNonNull(), important);
addProperty(CSSPropertyBorderImageSlice, CSSPropertyBorderImage, slice.releaseNonNull(), important);
addProperty(CSSPropertyBorderImageWidth, CSSPropertyBorderImage, width.releaseNonNull() , important);
addProperty(CSSPropertyBorderImageOutset, CSSPropertyBorderImage, outset.releaseNonNull(), important);
addProperty(CSSPropertyBorderImageRepeat, CSSPropertyBorderImage, repeat.releaseNonNull(), important);
return true;
default:
ASSERT_NOT_REACHED();
return false;
}
}
return false;
}
static inline CSSValueID mapFromPageBreakBetween(CSSValueID value)
{
if (value == CSSValueAlways)
return CSSValuePage;
if (value == CSSValueAuto || value == CSSValueLeft || value == CSSValueRight)
return value;
if (value == CSSValueAvoid)
return CSSValueAvoidPage;
return CSSValueInvalid;
}
static inline CSSValueID mapFromColumnBreakBetween(CSSValueID value)
{
if (value == CSSValueAlways)
return CSSValueColumn;
if (value == CSSValueAuto)
return value;
if (value == CSSValueAvoid)
return CSSValueAvoidColumn;
return CSSValueInvalid;
}
#if ENABLE(CSS_REGIONS)
static inline CSSValueID mapFromRegionBreakBetween(CSSValueID value)
{
if (value == CSSValueAlways)
return CSSValueRegion;
if (value == CSSValueAuto)
return value;
if (value == CSSValueAvoid)
return CSSValueAvoidRegion;
return CSSValueInvalid;
}
#endif
static inline CSSValueID mapFromColumnRegionOrPageBreakInside(CSSValueID value)
{
if (value == CSSValueAuto || value == CSSValueAvoid)
return value;
return CSSValueInvalid;
}
static inline CSSPropertyID mapFromLegacyBreakProperty(CSSPropertyID property)
{
if (property == CSSPropertyPageBreakAfter || property == CSSPropertyWebkitColumnBreakAfter)
return CSSPropertyBreakAfter;
if (property == CSSPropertyPageBreakBefore || property == CSSPropertyWebkitColumnBreakBefore)
return CSSPropertyBreakBefore;
#if ENABLE(CSS_REGIONS)
if (property == CSSPropertyWebkitRegionBreakAfter)
return CSSPropertyBreakAfter;
if (property == CSSPropertyWebkitRegionBreakBefore)
return CSSPropertyBreakBefore;
ASSERT(property == CSSPropertyPageBreakInside || property == CSSPropertyWebkitColumnBreakInside || property == CSSPropertyWebkitRegionBreakInside);
#else
ASSERT(property == CSSPropertyPageBreakInside || property == CSSPropertyWebkitColumnBreakInside);
#endif
return CSSPropertyBreakInside;
}
bool CSSPropertyParser::consumeLegacyBreakProperty(CSSPropertyID property, bool important)
{
// The fragmentation spec says that page-break-(after|before|inside) are to be treated as
// shorthands for their break-(after|before|inside) counterparts. We'll do the same for the
// non-standard properties -webkit-column-break-(after|before|inside).
RefPtr<CSSPrimitiveValue> keyword = consumeIdent(m_range);
if (!keyword)
return false;
if (!m_range.atEnd())
return false;
CSSValueID value = keyword->valueID();
switch (property) {
case CSSPropertyPageBreakAfter:
case CSSPropertyPageBreakBefore:
value = mapFromPageBreakBetween(value);
break;
case CSSPropertyWebkitColumnBreakAfter:
case CSSPropertyWebkitColumnBreakBefore:
value = mapFromColumnBreakBetween(value);
break;
#if ENABLE(CSS_REGIONS)
case CSSPropertyWebkitRegionBreakAfter:
case CSSPropertyWebkitRegionBreakBefore:
value = mapFromRegionBreakBetween(value);
break;
case CSSPropertyWebkitRegionBreakInside:
#endif
case CSSPropertyPageBreakInside:
case CSSPropertyWebkitColumnBreakInside:
value = mapFromColumnRegionOrPageBreakInside(value);
break;
default:
ASSERT_NOT_REACHED();
}
if (value == CSSValueInvalid)
return false;
CSSPropertyID genericBreakProperty = mapFromLegacyBreakProperty(property);
addProperty(genericBreakProperty, property, CSSValuePool::singleton().createIdentifierValue(value), important);
return true;
}
static bool consumeBackgroundPosition(CSSParserTokenRange& range, const CSSParserContext& context, UnitlessQuirk unitless, RefPtr<CSSValue>& resultX, RefPtr<CSSValue>& resultY)
{
do {
RefPtr<CSSPrimitiveValue> positionX;
RefPtr<CSSPrimitiveValue> positionY;
if (!consumePosition(range, context.mode, unitless, positionX, positionY))
return false;
addBackgroundValue(resultX, positionX.releaseNonNull());
addBackgroundValue(resultY, positionY.releaseNonNull());
} while (consumeCommaIncludingWhitespace(range));
return true;
}
static bool consumeRepeatStyleComponent(CSSParserTokenRange& range, RefPtr<CSSPrimitiveValue>& value1, RefPtr<CSSPrimitiveValue>& value2, bool& implicit)
{
if (consumeIdent<CSSValueRepeatX>(range)) {
value1 = CSSValuePool::singleton().createIdentifierValue(CSSValueRepeat);
value2 = CSSValuePool::singleton().createIdentifierValue(CSSValueNoRepeat);
implicit = true;
return true;
}
if (consumeIdent<CSSValueRepeatY>(range)) {
value1 = CSSValuePool::singleton().createIdentifierValue(CSSValueNoRepeat);
value2 = CSSValuePool::singleton().createIdentifierValue(CSSValueRepeat);
implicit = true;
return true;
}
value1 = consumeIdent<CSSValueRepeat, CSSValueNoRepeat, CSSValueRound, CSSValueSpace>(range);
if (!value1)
return false;
value2 = consumeIdent<CSSValueRepeat, CSSValueNoRepeat, CSSValueRound, CSSValueSpace>(range);
if (!value2) {
value2 = value1;
implicit = true;
}
return true;
}
static bool consumeRepeatStyle(CSSParserTokenRange& range, RefPtr<CSSValue>& resultX, RefPtr<CSSValue>& resultY, bool& implicit)
{
do {
RefPtr<CSSPrimitiveValue> repeatX;
RefPtr<CSSPrimitiveValue> repeatY;
if (!consumeRepeatStyleComponent(range, repeatX, repeatY, implicit))
return false;
addBackgroundValue(resultX, repeatX.releaseNonNull());
addBackgroundValue(resultY, repeatY.releaseNonNull());
} while (consumeCommaIncludingWhitespace(range));
return true;
}
// Note: consumeBackgroundShorthand assumes y properties (for example background-position-y) follow
// the x properties in the shorthand array.
bool CSSPropertyParser::consumeBackgroundShorthand(const StylePropertyShorthand& shorthand, bool important)
{
const unsigned longhandCount = shorthand.length();
RefPtr<CSSValue> longhands[10];
ASSERT(longhandCount <= 10);
bool implicit = false;
do {
bool parsedLonghand[10] = { false };
RefPtr<CSSValue> originValue;
do {
bool foundProperty = false;
for (size_t i = 0; i < longhandCount; ++i) {
if (parsedLonghand[i])
continue;
RefPtr<CSSValue> value;
RefPtr<CSSValue> valueY;
CSSPropertyID property = shorthand.properties()[i];
if (property == CSSPropertyBackgroundRepeatX || property == CSSPropertyWebkitMaskRepeatX) {
RefPtr<CSSPrimitiveValue> primitiveValue;
RefPtr<CSSPrimitiveValue> primitiveValueY;
consumeRepeatStyleComponent(m_range, primitiveValue, primitiveValueY, implicit);
value = primitiveValue;
valueY = primitiveValueY;
} else if (property == CSSPropertyBackgroundPositionX || property == CSSPropertyWebkitMaskPositionX) {
CSSParserTokenRange rangeCopy = m_range;
RefPtr<CSSPrimitiveValue> primitiveValue;
RefPtr<CSSPrimitiveValue> primitiveValueY;
if (!consumePosition(rangeCopy, m_context.mode, UnitlessQuirk::Forbid, primitiveValue, primitiveValueY))
continue;
value = primitiveValue;
valueY = primitiveValueY;
m_range = rangeCopy;
} else if (property == CSSPropertyBackgroundSize || property == CSSPropertyWebkitMaskSize) {
if (!consumeSlashIncludingWhitespace(m_range))
continue;
value = consumeBackgroundSize(property, m_range, m_context.mode);
if (!value || !parsedLonghand[i - 1]) // Position must have been parsed in the current layer.
return false;
} else if (property == CSSPropertyBackgroundPositionY || property == CSSPropertyBackgroundRepeatY
|| property == CSSPropertyWebkitMaskPositionY || property == CSSPropertyWebkitMaskRepeatY) {
continue;
} else {
value = consumeBackgroundComponent(property, m_range, m_context);
}
if (value) {
if (property == CSSPropertyBackgroundOrigin || property == CSSPropertyWebkitMaskOrigin)
originValue = value;
parsedLonghand[i] = true;
foundProperty = true;
addBackgroundValue(longhands[i], value.releaseNonNull());
if (valueY) {
parsedLonghand[i + 1] = true;
addBackgroundValue(longhands[i + 1], valueY.releaseNonNull());
}
}
}
if (!foundProperty)
return false;
} while (!m_range.atEnd() && m_range.peek().type() != CommaToken);
// FIXME: This will make invalid longhands, see crbug.com/386459
for (size_t i = 0; i < longhandCount; ++i) {
CSSPropertyID property = shorthand.properties()[i];
if (property == CSSPropertyBackgroundColor && !m_range.atEnd()) {
if (parsedLonghand[i])
return false; // Colors are only allowed in the last layer.
continue;
}
if ((property == CSSPropertyBackgroundClip || property == CSSPropertyWebkitMaskClip) && !parsedLonghand[i] && originValue) {
addBackgroundValue(longhands[i], originValue.releaseNonNull());
continue;
}
if (!parsedLonghand[i])
addBackgroundValue(longhands[i], CSSValuePool::singleton().createImplicitInitialValue());
}
} while (consumeCommaIncludingWhitespace(m_range));
if (!m_range.atEnd())
return false;
for (size_t i = 0; i < longhandCount; ++i) {
CSSPropertyID property = shorthand.properties()[i];
if (property == CSSPropertyBackgroundSize && longhands[i] && m_context.useLegacyBackgroundSizeShorthandBehavior)
continue;
addProperty(property, shorthand.id(), *longhands[i], important, implicit);
}
return true;
}
// FIXME-NEWPARSER: Hack to work around the fact that we aren't using CSSCustomIdentValue
// for stuff yet. This can be replaced by CSSValue::isCustomIdentValue() once we switch
// to using CSSCustomIdentValue everywhere.
static bool isCustomIdentValue(const CSSValue& value)
{
return is<CSSPrimitiveValue>(value) && downcast<CSSPrimitiveValue>(value).isString();
}
bool CSSPropertyParser::consumeGridItemPositionShorthand(CSSPropertyID shorthandId, bool important)
{
const StylePropertyShorthand& shorthand = shorthandForProperty(shorthandId);
ASSERT(shorthand.length() == 2);
RefPtr<CSSValue> startValue = consumeGridLine(m_range);
if (!startValue)
return false;
RefPtr<CSSValue> endValue;
if (consumeSlashIncludingWhitespace(m_range)) {
endValue = consumeGridLine(m_range);
if (!endValue)
return false;
} else {
endValue = isCustomIdentValue(*startValue) ? startValue : CSSValuePool::singleton().createIdentifierValue(CSSValueAuto);
}
if (!m_range.atEnd())
return false;
addProperty(shorthand.properties()[0], shorthandId, startValue.releaseNonNull(), important);
addProperty(shorthand.properties()[1], shorthandId, endValue.releaseNonNull(), important);
return true;
}
bool CSSPropertyParser::consumeGridAreaShorthand(bool important)
{
RefPtr<CSSValue> rowStartValue = consumeGridLine(m_range);
if (!rowStartValue)
return false;
RefPtr<CSSValue> columnStartValue;
RefPtr<CSSValue> rowEndValue;
RefPtr<CSSValue> columnEndValue;
if (consumeSlashIncludingWhitespace(m_range)) {
columnStartValue = consumeGridLine(m_range);
if (!columnStartValue)
return false;
if (consumeSlashIncludingWhitespace(m_range)) {
rowEndValue = consumeGridLine(m_range);
if (!rowEndValue)
return false;
if (consumeSlashIncludingWhitespace(m_range)) {
columnEndValue = consumeGridLine(m_range);
if (!columnEndValue)
return false;
}
}
}
if (!m_range.atEnd())
return false;
if (!columnStartValue)
columnStartValue = isCustomIdentValue(*rowStartValue) ? rowStartValue : CSSValuePool::singleton().createIdentifierValue(CSSValueAuto);
if (!rowEndValue)
rowEndValue = isCustomIdentValue(*rowStartValue) ? rowStartValue : CSSValuePool::singleton().createIdentifierValue(CSSValueAuto);
if (!columnEndValue)
columnEndValue = isCustomIdentValue(*columnStartValue) ? columnStartValue : CSSValuePool::singleton().createIdentifierValue(CSSValueAuto);
addProperty(CSSPropertyGridRowStart, CSSPropertyGridArea, rowStartValue.releaseNonNull(), important);
addProperty(CSSPropertyGridColumnStart, CSSPropertyGridArea, columnStartValue.releaseNonNull(), important);
addProperty(CSSPropertyGridRowEnd, CSSPropertyGridArea, rowEndValue.releaseNonNull(), important);
addProperty(CSSPropertyGridColumnEnd, CSSPropertyGridArea, columnEndValue.releaseNonNull(), important);
return true;
}
bool CSSPropertyParser::consumeGridTemplateRowsAndAreasAndColumns(CSSPropertyID shorthandId, bool important)
{
NamedGridAreaMap gridAreaMap;
size_t rowCount = 0;
size_t columnCount = 0;
RefPtr<CSSValueList> templateRows = CSSValueList::createSpaceSeparated();
// Persists between loop iterations so we can use the same value for
// consecutive <line-names> values
RefPtr<CSSGridLineNamesValue> lineNames;
do {
// Handle leading <custom-ident>*.
bool hasPreviousLineNames = lineNames;
lineNames = consumeGridLineNames(m_range, lineNames.get());
if (lineNames && !hasPreviousLineNames)
templateRows->append(*lineNames);
// Handle a template-area's row.
if (m_range.peek().type() != StringToken || !parseGridTemplateAreasRow(m_range.consumeIncludingWhitespace().value().toString(), gridAreaMap, rowCount, columnCount))
return false;
++rowCount;
// Handle template-rows's track-size.
RefPtr<CSSValue> value = consumeGridTrackSize(m_range, m_context.mode);
if (!value)
value = CSSValuePool::singleton().createIdentifierValue(CSSValueAuto);
templateRows->append(*value);
// This will handle the trailing/leading <custom-ident>* in the grammar.
lineNames = consumeGridLineNames(m_range);
if (lineNames)
templateRows->append(lineNames.releaseNonNull());
} while (!m_range.atEnd() && !(m_range.peek().type() == DelimiterToken && m_range.peek().delimiter() == '/'));
RefPtr<CSSValue> columnsValue;
if (!m_range.atEnd()) {
if (!consumeSlashIncludingWhitespace(m_range))
return false;
columnsValue = consumeGridTrackList(m_range, m_context.mode, GridTemplateNoRepeat);
if (!columnsValue || !m_range.atEnd())
return false;
} else {
columnsValue = CSSValuePool::singleton().createIdentifierValue(CSSValueNone);
}
addProperty(CSSPropertyGridTemplateRows, shorthandId, templateRows.releaseNonNull(), important);
addProperty(CSSPropertyGridTemplateColumns, shorthandId, columnsValue.releaseNonNull(), important);
addProperty(CSSPropertyGridTemplateAreas, shorthandId, CSSGridTemplateAreasValue::create(gridAreaMap, rowCount, columnCount), important);
return true;
}
bool CSSPropertyParser::consumeGridTemplateShorthand(CSSPropertyID shorthandId, bool important)
{
CSSParserTokenRange rangeCopy = m_range;
RefPtr<CSSValue> rowsValue = consumeIdent<CSSValueNone>(m_range);
// 1- 'none' case.
if (rowsValue && m_range.atEnd()) {
addProperty(CSSPropertyGridTemplateRows, shorthandId, CSSValuePool::singleton().createIdentifierValue(CSSValueNone), important);
addProperty(CSSPropertyGridTemplateColumns, shorthandId, CSSValuePool::singleton().createIdentifierValue(CSSValueNone), important);
addProperty(CSSPropertyGridTemplateAreas, shorthandId, CSSValuePool::singleton().createIdentifierValue(CSSValueNone), important);
return true;
}
// 2- <grid-template-rows> / <grid-template-columns>
if (!rowsValue)
rowsValue = consumeGridTrackList(m_range, m_context.mode, GridTemplate);
if (rowsValue) {
if (!consumeSlashIncludingWhitespace(m_range))
return false;
RefPtr<CSSValue> columnsValue = consumeGridTemplatesRowsOrColumns(m_range, m_context.mode);
if (!columnsValue || !m_range.atEnd())
return false;
addProperty(CSSPropertyGridTemplateRows, shorthandId, rowsValue.releaseNonNull(), important);
addProperty(CSSPropertyGridTemplateColumns, shorthandId, columnsValue.releaseNonNull(), important);
addProperty(CSSPropertyGridTemplateAreas, shorthandId, CSSValuePool::singleton().createIdentifierValue(CSSValueNone), important);
return true;
}
// 3- [ <line-names>? <string> <track-size>? <line-names>? ]+ [ / <track-list> ]?
m_range = rangeCopy;
return consumeGridTemplateRowsAndAreasAndColumns(shorthandId, important);
}
static RefPtr<CSSValue> consumeImplicitGridAutoFlow(CSSParserTokenRange& range, Ref<CSSPrimitiveValue>&& flowDirection)
{
// [ auto-flow && dense? ]
if (range.atEnd())
return nullptr;
auto list = CSSValueList::createSpaceSeparated();
list->append(WTFMove(flowDirection));
if (range.peek().id() == CSSValueAutoFlow) {
range.consumeIncludingWhitespace();
RefPtr<CSSValue> denseIdent = consumeIdent<CSSValueDense>(range);
if (denseIdent)
list->append(denseIdent.releaseNonNull());
} else {
// Dense case
if (range.peek().id() != CSSValueDense)
return nullptr;
range.consumeIncludingWhitespace();
if (range.atEnd() || range.peek().id() != CSSValueAutoFlow)
return nullptr;
range.consumeIncludingWhitespace();
list->append(CSSValuePool::singleton().createIdentifierValue(CSSValueDense));
}
return WTFMove(list);
}
bool CSSPropertyParser::consumeGridShorthand(bool important)
{
ASSERT(shorthandForProperty(CSSPropertyGrid).length() == 8);
CSSParserTokenRange rangeCopy = m_range;
// 1- <grid-template>
if (consumeGridTemplateShorthand(CSSPropertyGrid, important)) {
// It can only be specified the explicit or the implicit grid properties in a single grid declaration.
// The sub-properties not specified are set to their initial value, as normal for shorthands.
addProperty(CSSPropertyGridAutoFlow, CSSPropertyGrid, CSSValuePool::singleton().createImplicitInitialValue(), important);
addProperty(CSSPropertyGridAutoColumns, CSSPropertyGrid, CSSValuePool::singleton().createImplicitInitialValue(), important);
addProperty(CSSPropertyGridAutoRows, CSSPropertyGrid, CSSValuePool::singleton().createImplicitInitialValue(), important);
addProperty(CSSPropertyGridColumnGap, CSSPropertyGrid, CSSValuePool::singleton().createImplicitInitialValue(), important);
addProperty(CSSPropertyGridRowGap, CSSPropertyGrid, CSSValuePool::singleton().createImplicitInitialValue(), important);
return true;
}
m_range = rangeCopy;
RefPtr<CSSValue> autoColumnsValue;
RefPtr<CSSValue> autoRowsValue;
RefPtr<CSSValue> templateRows;
RefPtr<CSSValue> templateColumns;
RefPtr<CSSValue> gridAutoFlow;
if (m_range.peek().id() == CSSValueAutoFlow || m_range.peek().id() == CSSValueDense) {
// 2- [ auto-flow && dense? ] <grid-auto-rows>? / <grid-template-columns>
gridAutoFlow = consumeImplicitGridAutoFlow(m_range, CSSValuePool::singleton().createIdentifierValue(CSSValueRow));
if (!gridAutoFlow || m_range.atEnd())
return false;
if (consumeSlashIncludingWhitespace(m_range))
autoRowsValue = CSSValuePool::singleton().createImplicitInitialValue();
else {
autoRowsValue = consumeGridTrackList(m_range, m_context.mode, GridAuto);
if (!autoRowsValue)
return false;
if (!consumeSlashIncludingWhitespace(m_range))
return false;
}
if (m_range.atEnd())
return false;
templateColumns = consumeGridTemplatesRowsOrColumns(m_range, m_context.mode);
if (!templateColumns)
return false;
templateRows = CSSValuePool::singleton().createImplicitInitialValue();
autoColumnsValue = CSSValuePool::singleton().createImplicitInitialValue();
} else {
// 3- <grid-template-rows> / [ auto-flow && dense? ] <grid-auto-columns>?
templateRows = consumeGridTemplatesRowsOrColumns(m_range, m_context.mode);
if (!templateRows)
return false;
if (!consumeSlashIncludingWhitespace(m_range) || m_range.atEnd())
return false;
gridAutoFlow = consumeImplicitGridAutoFlow(m_range, CSSValuePool::singleton().createIdentifierValue(CSSValueColumn));
if (!gridAutoFlow)
return false;
if (m_range.atEnd())
autoColumnsValue = CSSValuePool::singleton().createImplicitInitialValue();
else {
autoColumnsValue = consumeGridTrackList(m_range, m_context.mode, GridAuto);
if (!autoColumnsValue)
return false;
}
templateColumns = CSSValuePool::singleton().createImplicitInitialValue();
autoRowsValue = CSSValuePool::singleton().createImplicitInitialValue();
}
if (!m_range.atEnd())
return false;
// It can only be specified the explicit or the implicit grid properties in a single grid declaration.
// The sub-properties not specified are set to their initial value, as normal for shorthands.
addProperty(CSSPropertyGridTemplateColumns, CSSPropertyGrid, templateColumns.releaseNonNull(), important);
addProperty(CSSPropertyGridTemplateRows, CSSPropertyGrid, templateRows.releaseNonNull(), important);
addProperty(CSSPropertyGridTemplateAreas, CSSPropertyGrid, CSSValuePool::singleton().createImplicitInitialValue(), important);
addProperty(CSSPropertyGridAutoFlow, CSSPropertyGrid, gridAutoFlow.releaseNonNull(), important);
addProperty(CSSPropertyGridAutoColumns, CSSPropertyGrid, autoColumnsValue.releaseNonNull(), important);
addProperty(CSSPropertyGridAutoRows, CSSPropertyGrid, autoRowsValue.releaseNonNull(), important);
addProperty(CSSPropertyGridColumnGap, CSSPropertyGrid, CSSValuePool::singleton().createImplicitInitialValue(), important);
addProperty(CSSPropertyGridRowGap, CSSPropertyGrid, CSSValuePool::singleton().createImplicitInitialValue(), important);
return true;
}
bool CSSPropertyParser::parseShorthand(CSSPropertyID property, bool important)
{
switch (property) {
case CSSPropertyWebkitMarginCollapse: {
CSSValueID id = m_range.consumeIncludingWhitespace().id();
if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyWebkitMarginBeforeCollapse, id, m_context.mode))
return false;
addProperty(CSSPropertyWebkitMarginBeforeCollapse, CSSPropertyWebkitMarginCollapse, CSSValuePool::singleton().createIdentifierValue(id), important);
if (m_range.atEnd()) {
addProperty(CSSPropertyWebkitMarginAfterCollapse, CSSPropertyWebkitMarginCollapse, CSSValuePool::singleton().createIdentifierValue(id), important);
return true;
}
id = m_range.consumeIncludingWhitespace().id();
if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyWebkitMarginAfterCollapse, id, m_context.mode))
return false;
addProperty(CSSPropertyWebkitMarginAfterCollapse, CSSPropertyWebkitMarginCollapse, CSSValuePool::singleton().createIdentifierValue(id), important);
return true;
}
case CSSPropertyOverflow: {
CSSValueID id = m_range.consumeIncludingWhitespace().id();
if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyOverflowY, id, m_context.mode))
return false;
if (!m_range.atEnd())
return false;
RefPtr<CSSValue> overflowYValue = CSSValuePool::singleton().createIdentifierValue(id);
RefPtr<CSSValue> overflowXValue;
// FIXME: -webkit-paged-x or -webkit-paged-y only apply to overflow-y. If this value has been
// set using the shorthand, then for now overflow-x will default to auto, but once we implement
// pagination controls, it should default to hidden. If the overflow-y value is anything but
// paged-x or paged-y, then overflow-x and overflow-y should have the same value.
if (id == CSSValueWebkitPagedX || id == CSSValueWebkitPagedY)
overflowXValue = CSSValuePool::singleton().createIdentifierValue(CSSValueAuto);
else
overflowXValue = overflowYValue;
addProperty(CSSPropertyOverflowX, CSSPropertyOverflow, *overflowXValue, important);
addProperty(CSSPropertyOverflowY, CSSPropertyOverflow, *overflowYValue, important);
return true;
}
case CSSPropertyFont: {
const CSSParserToken& token = m_range.peek();
if (token.id() >= CSSValueCaption && token.id() <= CSSValueStatusBar)
return consumeSystemFont(important);
return consumeFont(important);
}
case CSSPropertyFontVariant:
return consumeFontVariantShorthand(important);
case CSSPropertyBorderSpacing:
return consumeBorderSpacing(important);
case CSSPropertyColumns:
return consumeColumns(important);
case CSSPropertyAnimation:
return consumeAnimationShorthand(animationShorthandForParsing(), important);
case CSSPropertyTransition:
return consumeAnimationShorthand(transitionShorthandForParsing(), important);
case CSSPropertyTextDecoration:
case CSSPropertyWebkitTextDecoration:
// FIXME-NEWPARSER: We need to unprefix -line/-style/-color ASAP and get rid
// of -webkit-text-decoration completely.
return consumeShorthandGreedily(webkitTextDecorationShorthand(), important);
case CSSPropertyMargin:
return consume4Values(marginShorthand(), important);
case CSSPropertyPadding:
return consume4Values(paddingShorthand(), important);
#if ENABLE(CSS_SCROLL_SNAP)
case CSSPropertyScrollSnapMargin:
return consume4Values(scrollSnapMarginShorthand(), important);
case CSSPropertyScrollPadding:
return consume4Values(scrollPaddingShorthand(), important);
#endif
case CSSPropertyWebkitTextEmphasis:
return consumeShorthandGreedily(webkitTextEmphasisShorthand(), important);
case CSSPropertyOutline:
return consumeShorthandGreedily(outlineShorthand(), important);
case CSSPropertyWebkitBorderStart:
return consumeShorthandGreedily(webkitBorderStartShorthand(), important);
case CSSPropertyWebkitBorderEnd:
return consumeShorthandGreedily(webkitBorderEndShorthand(), important);
case CSSPropertyWebkitBorderBefore:
return consumeShorthandGreedily(webkitBorderBeforeShorthand(), important);
case CSSPropertyWebkitBorderAfter:
return consumeShorthandGreedily(webkitBorderAfterShorthand(), important);
case CSSPropertyWebkitTextStroke:
return consumeShorthandGreedily(webkitTextStrokeShorthand(), important);
case CSSPropertyMarker: {
RefPtr<CSSValue> marker = parseSingleValue(CSSPropertyMarkerStart);
if (!marker || !m_range.atEnd())
return false;
auto markerRef = marker.releaseNonNull();
addProperty(CSSPropertyMarkerStart, CSSPropertyMarker, markerRef.copyRef(), important);
addProperty(CSSPropertyMarkerMid, CSSPropertyMarker, markerRef.copyRef(), important);
addProperty(CSSPropertyMarkerEnd, CSSPropertyMarker, markerRef.copyRef(), important);
return true;
}
case CSSPropertyFlex:
return consumeFlex(important);
case CSSPropertyFlexFlow:
return consumeShorthandGreedily(flexFlowShorthand(), important);
case CSSPropertyColumnRule:
return consumeShorthandGreedily(columnRuleShorthand(), important);
case CSSPropertyListStyle:
return consumeShorthandGreedily(listStyleShorthand(), important);
case CSSPropertyBorderRadius:
case CSSPropertyWebkitBorderRadius: {
RefPtr<CSSPrimitiveValue> horizontalRadii[4];
RefPtr<CSSPrimitiveValue> verticalRadii[4];
if (!consumeRadii(horizontalRadii, verticalRadii, m_range, m_context.mode, property == CSSPropertyWebkitBorderRadius))
return false;
addProperty(CSSPropertyBorderTopLeftRadius, CSSPropertyBorderRadius, createPrimitiveValuePair(horizontalRadii[0].releaseNonNull(), verticalRadii[0].releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce), important);
addProperty(CSSPropertyBorderTopRightRadius, CSSPropertyBorderRadius, createPrimitiveValuePair(horizontalRadii[1].releaseNonNull(), verticalRadii[1].releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce), important);
addProperty(CSSPropertyBorderBottomRightRadius, CSSPropertyBorderRadius, createPrimitiveValuePair(horizontalRadii[2].releaseNonNull(), verticalRadii[2].releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce), important);
addProperty(CSSPropertyBorderBottomLeftRadius, CSSPropertyBorderRadius, createPrimitiveValuePair(horizontalRadii[3].releaseNonNull(), verticalRadii[3].releaseNonNull(), Pair::IdenticalValueEncoding::Coalesce), important);
return true;
}
case CSSPropertyBorderColor:
return consume4Values(borderColorShorthand(), important);
case CSSPropertyBorderStyle:
return consume4Values(borderStyleShorthand(), important);
case CSSPropertyBorderWidth:
return consume4Values(borderWidthShorthand(), important);
case CSSPropertyBorderTop:
return consumeShorthandGreedily(borderTopShorthand(), important);
case CSSPropertyBorderRight:
return consumeShorthandGreedily(borderRightShorthand(), important);
case CSSPropertyBorderBottom:
return consumeShorthandGreedily(borderBottomShorthand(), important);
case CSSPropertyBorderLeft:
return consumeShorthandGreedily(borderLeftShorthand(), important);
case CSSPropertyBorder:
return consumeBorder(important);
case CSSPropertyBorderImage:
return consumeBorderImage(property, important);
case CSSPropertyWebkitMaskPosition:
case CSSPropertyBackgroundPosition: {
RefPtr<CSSValue> resultX;
RefPtr<CSSValue> resultY;
if (!consumeBackgroundPosition(m_range, m_context, UnitlessQuirk::Allow, resultX, resultY) || !m_range.atEnd())
return false;
addProperty(property == CSSPropertyBackgroundPosition ? CSSPropertyBackgroundPositionX : CSSPropertyWebkitMaskPositionX, property, resultX.releaseNonNull(), important);
addProperty(property == CSSPropertyBackgroundPosition ? CSSPropertyBackgroundPositionY : CSSPropertyWebkitMaskPositionY, property, resultY.releaseNonNull(), important);
return true;
}
case CSSPropertyBackgroundRepeat:
case CSSPropertyWebkitMaskRepeat: {
RefPtr<CSSValue> resultX;
RefPtr<CSSValue> resultY;
bool implicit = false;
if (!consumeRepeatStyle(m_range, resultX, resultY, implicit) || !m_range.atEnd())
return false;
addProperty(property == CSSPropertyBackgroundRepeat ? CSSPropertyBackgroundRepeatX : CSSPropertyWebkitMaskRepeatX, property, resultX.releaseNonNull(), important, implicit);
addProperty(property == CSSPropertyBackgroundRepeat ? CSSPropertyBackgroundRepeatY : CSSPropertyWebkitMaskRepeatY, property, resultY.releaseNonNull(), important, implicit);
return true;
}
case CSSPropertyBackground:
return consumeBackgroundShorthand(backgroundShorthand(), important);
case CSSPropertyWebkitMask:
return consumeBackgroundShorthand(webkitMaskShorthand(), important);
case CSSPropertyTransformOrigin:
return consumeTransformOrigin(important);
case CSSPropertyPerspectiveOrigin:
return consumePerspectiveOrigin(important);
case CSSPropertyGridGap: {
RefPtr<CSSValue> rowGap = consumeLength(m_range, m_context.mode, ValueRangeNonNegative);
RefPtr<CSSValue> columnGap = consumeLength(m_range, m_context.mode, ValueRangeNonNegative);
if (!rowGap || !m_range.atEnd())
return false;
if (!columnGap)
columnGap = rowGap;
addProperty(CSSPropertyGridRowGap, CSSPropertyGridGap, rowGap.releaseNonNull(), important);
addProperty(CSSPropertyGridColumnGap, CSSPropertyGridGap, columnGap.releaseNonNull(), important);
return true;
}
case CSSPropertyGridColumn:
case CSSPropertyGridRow:
return consumeGridItemPositionShorthand(property, important);
case CSSPropertyGridArea:
return consumeGridAreaShorthand(important);
case CSSPropertyGridTemplate:
return consumeGridTemplateShorthand(CSSPropertyGridTemplate, important);
case CSSPropertyGrid:
return consumeGridShorthand(important);
case CSSPropertyWebkitMarquee:
return consumeShorthandGreedily(webkitMarqueeShorthand(), important);
default:
return false;
}
}
} // namespace WebCore
|