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
|
/*
* Copyright (C) 2003 Lars Knoll (knoll@kde.org)
* Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
* Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
* Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
* Copyright (C) 2008 Eric Seidel <eric@webkit.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "CSSParser.h"
#include "CString.h"
#include "CSSTimingFunctionValue.h"
#include "CSSBorderImageValue.h"
#include "CSSCanvasValue.h"
#include "CSSCharsetRule.h"
#include "CSSCursorImageValue.h"
#include "CSSHelper.h"
#include "CSSImageValue.h"
#include "CSSFontFaceRule.h"
#include "CSSFontFaceSrcValue.h"
#include "CSSGradientValue.h"
#include "CSSImportRule.h"
#include "CSSInheritedValue.h"
#include "CSSInitialValue.h"
#include "CSSMediaRule.h"
#include "CSSMutableStyleDeclaration.h"
#include "CSSPrimitiveValue.h"
#include "CSSProperty.h"
#include "CSSPropertyNames.h"
#include "CSSQuirkPrimitiveValue.h"
#include "CSSReflectValue.h"
#include "CSSRuleList.h"
#include "CSSSelector.h"
#include "CSSStyleRule.h"
#include "CSSStyleSheet.h"
#include "CSSTransformValue.h"
#include "CSSUnicodeRangeValue.h"
#include "CSSValueKeywords.h"
#include "CSSValueList.h"
#include "Counter.h"
#include "Document.h"
#include "FloatConversion.h"
#include "FontFamilyValue.h"
#include "FontValue.h"
#include "MediaList.h"
#include "MediaQueryExp.h"
#include "Pair.h"
#include "Rect.h"
#include "ShadowValue.h"
#include <kjs/dtoa.h>
#if ENABLE(DASHBOARD_SUPPORT)
#include "DashboardRegion.h"
#endif
#define YYDEBUG 0
#if YYDEBUG > 0
extern int cssyydebug;
#endif
extern int cssyyparse(void* parser);
using namespace std;
using namespace WTF;
#include "CSSPropertyNames.cpp"
#include "CSSValueKeywords.c"
namespace WebCore {
static bool equal(const ParseString& a, const char* b)
{
for (int i = 0; i < a.length; ++i) {
if (!b[i])
return false;
if (a.characters[i] != b[i])
return false;
}
return !b[a.length];
}
static bool equalIgnoringCase(const ParseString& a, const char* b)
{
for (int i = 0; i < a.length; ++i) {
if (!b[i])
return false;
ASSERT(!isASCIIUpper(b[i]));
if (toASCIILower(a.characters[i]) != b[i])
return false;
}
return !b[a.length];
}
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;
}
ValueList::~ValueList()
{
size_t numValues = m_values.size();
for (size_t i = 0; i < numValues; i++)
if (m_values[i].unit == Value::Function)
delete m_values[i].function;
}
CSSParser::CSSParser(bool strictParsing)
: m_strict(strictParsing)
, m_important(false)
, m_id(0)
, m_styleSheet(0)
, m_mediaQuery(0)
, m_valueList(0)
, m_parsedProperties(static_cast<CSSProperty**>(fastMalloc(32 * sizeof(CSSProperty*))))
, m_numParsedProperties(0)
, m_maxParsedProperties(32)
, m_inParseShorthand(0)
, m_currentShorthand(0)
, m_implicitShorthand(false)
, m_defaultNamespace(starAtom)
, m_data(0)
, yy_start(1)
, m_floatingMediaQuery(0)
, m_floatingMediaQueryExp(0)
, m_floatingMediaQueryExpList(0)
{
#if YYDEBUG > 0
cssyydebug = 1;
#endif
}
CSSParser::~CSSParser()
{
clearProperties();
fastFree(m_parsedProperties);
delete m_valueList;
fastFree(m_data);
if (m_floatingMediaQueryExpList) {
deleteAllValues(*m_floatingMediaQueryExpList);
delete m_floatingMediaQueryExpList;
}
delete m_floatingMediaQueryExp;
delete m_floatingMediaQuery;
deleteAllValues(m_floatingSelectors);
deleteAllValues(m_floatingValueLists);
deleteAllValues(m_floatingFunctions);
}
void ParseString::lower()
{
// FIXME: If we need Unicode lowercasing here, then we probably want the real kind
// that can potentially change the length of the string rather than the character
// by character kind. If we don't need Unicode lowercasing, it would be good to
// simplify this function.
if (charactersAreAllASCII(characters, length)) {
// Fast case for all-ASCII.
for (int i = 0; i < length; i++)
characters[i] = toASCIILower(characters[i]);
} else {
for (int i = 0; i < length; i++)
characters[i] = Unicode::toLower(characters[i]);
}
}
void CSSParser::setupParser(const char* prefix, const String& string, const char* suffix)
{
int length = string.length() + strlen(prefix) + strlen(suffix) + 2;
fastFree(m_data);
m_data = static_cast<UChar*>(fastMalloc(length * sizeof(UChar)));
for (unsigned i = 0; i < strlen(prefix); i++)
m_data[i] = prefix[i];
memcpy(m_data + strlen(prefix), string.characters(), string.length() * sizeof(UChar));
unsigned start = strlen(prefix) + string.length();
unsigned end = start + strlen(suffix);
for (unsigned i = start; i < end; i++)
m_data[i] = suffix[i - start];
m_data[length - 1] = 0;
m_data[length - 2] = 0;
yy_hold_char = 0;
yyleng = 0;
yytext = yy_c_buf_p = m_data;
yy_hold_char = *yy_c_buf_p;
}
void CSSParser::parseSheet(CSSStyleSheet* sheet, const String& string)
{
m_styleSheet = sheet;
m_defaultNamespace = starAtom; // Reset the default namespace.
setupParser("", string, "");
cssyyparse(this);
m_rule = 0;
}
PassRefPtr<CSSRule> CSSParser::parseRule(CSSStyleSheet* sheet, const String& string)
{
m_styleSheet = sheet;
setupParser("@-webkit-rule{", string, "} ");
cssyyparse(this);
return m_rule.release();
}
bool CSSParser::parseValue(CSSMutableStyleDeclaration* declaration, int id, const String& string, bool important)
{
ASSERT(!declaration->stylesheet() || declaration->stylesheet()->isCSSStyleSheet());
m_styleSheet = static_cast<CSSStyleSheet*>(declaration->stylesheet());
setupParser("@-webkit-value{", string, "} ");
m_id = id;
m_important = important;
cssyyparse(this);
m_rule = 0;
bool ok = false;
if (m_numParsedProperties) {
ok = true;
declaration->addParsedProperties(m_parsedProperties, m_numParsedProperties);
clearProperties();
}
return ok;
}
// color will only be changed when string contains a valid css color, making it
// possible to set up a default color.
bool CSSParser::parseColor(RGBA32& color, const String& string, bool strict)
{
color = 0;
CSSParser parser(true);
// First try creating a color specified by name or the "#" syntax.
if (!parser.parseColor(string, color, strict)) {
RefPtr<CSSMutableStyleDeclaration> dummyStyleDeclaration(new CSSMutableStyleDeclaration);
// Now try to create a color from the rgb() or rgba() syntax.
if (parser.parseColor(dummyStyleDeclaration.get(), string)) {
CSSValue* value = parser.m_parsedProperties[0]->value();
if (value->cssValueType() == CSSValue::CSS_PRIMITIVE_VALUE) {
CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
color = primitiveValue->getRGBColorValue();
}
} else
return false;
}
return true;
}
bool CSSParser::parseColor(CSSMutableStyleDeclaration* declaration, const String& string)
{
ASSERT(!declaration->stylesheet() || declaration->stylesheet()->isCSSStyleSheet());
m_styleSheet = static_cast<CSSStyleSheet*>(declaration->stylesheet());
setupParser("@-webkit-decls{color:", string, "} ");
cssyyparse(this);
m_rule = 0;
return (m_numParsedProperties && m_parsedProperties[0]->m_id == CSSPropertyColor);
}
bool CSSParser::parseDeclaration(CSSMutableStyleDeclaration* declaration, const String& string)
{
ASSERT(!declaration->stylesheet() || declaration->stylesheet()->isCSSStyleSheet());
m_styleSheet = static_cast<CSSStyleSheet*>(declaration->stylesheet());
setupParser("@-webkit-decls{", string, "} ");
cssyyparse(this);
m_rule = 0;
bool ok = false;
if (m_numParsedProperties) {
ok = true;
declaration->addParsedProperties(m_parsedProperties, m_numParsedProperties);
clearProperties();
}
return ok;
}
bool CSSParser::parseMediaQuery(MediaList* queries, const String& string)
{
if (string.isEmpty())
return true;
m_mediaQuery = 0;
// can't use { because tokenizer state switches from mediaquery to initial state when it sees { token.
// instead insert one " " (which is WHITESPACE in CSSGrammar.y)
setupParser ("@-webkit-mediaquery ", string, "} ");
cssyyparse(this);
bool ok = false;
if (m_mediaQuery) {
ok = true;
queries->appendMediaQuery(m_mediaQuery);
m_mediaQuery = 0;
}
return ok;
}
void CSSParser::addProperty(int propId, PassRefPtr<CSSValue> value, bool important)
{
CSSProperty* prop = new CSSProperty(propId, value, important, m_currentShorthand, m_implicitShorthand);
if (m_numParsedProperties >= m_maxParsedProperties) {
m_maxParsedProperties += 32;
m_parsedProperties = static_cast<CSSProperty**>(fastRealloc(m_parsedProperties,
m_maxParsedProperties * sizeof(CSSProperty*)));
}
m_parsedProperties[m_numParsedProperties++] = prop;
}
void CSSParser::rollbackLastProperties(int num)
{
ASSERT(num >= 0);
ASSERT(m_numParsedProperties >= num);
for (int i = 0; i < num; ++i)
delete m_parsedProperties[--m_numParsedProperties];
}
void CSSParser::clearProperties()
{
for (int i = 0; i < m_numParsedProperties; i++)
delete m_parsedProperties[i];
m_numParsedProperties = 0;
}
Document* CSSParser::document() const
{
StyleBase* root = m_styleSheet;
Document* doc = 0;
while (root->parent())
root = root->parent();
if (root->isCSSStyleSheet())
doc = static_cast<CSSStyleSheet*>(root)->doc();
return doc;
}
bool CSSParser::validUnit(Value* value, Units unitflags, bool strict)
{
if (unitflags & FNonNeg && value->fValue < 0)
return false;
bool b = false;
switch(value->unit) {
case CSSPrimitiveValue::CSS_NUMBER:
b = (unitflags & FNumber);
if (!b && ((unitflags & (FLength | FAngle)) && (value->fValue == 0 || !strict))) {
value->unit = (unitflags & FLength) ? CSSPrimitiveValue::CSS_PX : CSSPrimitiveValue::CSS_DEG;
b = true;
}
if (!b && (unitflags & FInteger) && value->isInt)
b = true;
break;
case CSSPrimitiveValue::CSS_PERCENTAGE:
b = (unitflags & FPercent);
break;
case Value::Q_EMS:
case CSSPrimitiveValue::CSS_EMS:
case CSSPrimitiveValue::CSS_EXS:
case CSSPrimitiveValue::CSS_PX:
case CSSPrimitiveValue::CSS_CM:
case CSSPrimitiveValue::CSS_MM:
case CSSPrimitiveValue::CSS_IN:
case CSSPrimitiveValue::CSS_PT:
case CSSPrimitiveValue::CSS_PC:
b = (unitflags & FLength);
break;
case CSSPrimitiveValue::CSS_MS:
case CSSPrimitiveValue::CSS_S:
b = (unitflags & FTime);
break;
case CSSPrimitiveValue::CSS_DEG:
case CSSPrimitiveValue::CSS_RAD:
case CSSPrimitiveValue::CSS_GRAD:
b = (unitflags & FAngle);
break;
case CSSPrimitiveValue::CSS_HZ:
case CSSPrimitiveValue::CSS_KHZ:
case CSSPrimitiveValue::CSS_DIMENSION:
default:
break;
}
return b;
}
static int unitFromString(Value* value)
{
if (value->unit != CSSPrimitiveValue::CSS_IDENT || value->id)
return 0;
if (equal(value->string, "em"))
return CSSPrimitiveValue::CSS_EMS;
if (equal(value->string, "ex"))
return CSSPrimitiveValue::CSS_EXS;
if (equal(value->string, "px"))
return CSSPrimitiveValue::CSS_PX;
if (equal(value->string, "cm"))
return CSSPrimitiveValue::CSS_CM;
if (equal(value->string, "mm"))
return CSSPrimitiveValue::CSS_MM;
if (equal(value->string, "in"))
return CSSPrimitiveValue::CSS_IN;
if (equal(value->string, "pt"))
return CSSPrimitiveValue::CSS_PT;
if (equal(value->string, "pc"))
return CSSPrimitiveValue::CSS_PC;
if (equal(value->string, "deg"))
return CSSPrimitiveValue::CSS_DEG;
if (equal(value->string, "rad"))
return CSSPrimitiveValue::CSS_RAD;
if (equal(value->string, "grad"))
return CSSPrimitiveValue::CSS_GRAD;
if (equal(value->string, "ms"))
return CSSPrimitiveValue::CSS_MS;
if (equal(value->string, "s"))
return CSSPrimitiveValue::CSS_S;
if (equal(value->string, "Hz"))
return CSSPrimitiveValue::CSS_HZ;
if (equal(value->string, "kHz"))
return CSSPrimitiveValue::CSS_KHZ;
return 0;
}
void CSSParser::checkForOrphanedUnits()
{
if (m_strict || inShorthand())
return;
// The purpose of this code is to implement the WinIE quirk that allows unit types to be separated from their numeric values
// by whitespace, so e.g., width: 20 px instead of width:20px. This is invalid CSS, so we don't do this in strict mode.
Value* numericVal = 0;
unsigned size = m_valueList->size();
for (unsigned i = 0; i < size; i++) {
Value* value = m_valueList->valueAt(i);
if (numericVal) {
// Change the unit type of the numeric val to match.
int unit = unitFromString(value);
if (unit) {
numericVal->unit = unit;
numericVal = 0;
// Now delete the bogus unit value.
m_valueList->deleteValueAt(i);
i--; // We're safe even though |i| is unsigned, since we only hit this code if we had a previous numeric value (so |i| is always > 0 here).
size--;
continue;
}
}
numericVal = (value->unit == CSSPrimitiveValue::CSS_NUMBER) ? value : 0;
}
}
bool CSSParser::parseValue(int propId, bool important)
{
if (!m_valueList)
return false;
Value *value = m_valueList->current();
if (!value)
return false;
int id = value->id;
int num = inShorthand() ? 1 : m_valueList->size();
if (id == CSSValueInherit) {
if (num != 1)
return false;
addProperty(propId, new CSSInheritedValue(), important);
return true;
}
else if (id == CSSValueInitial) {
if (num != 1)
return false;
addProperty(propId, new CSSInitialValue(false), important);
return true;
}
bool valid_primitive = false;
RefPtr<CSSValue> parsedValue;
// In quirks mode, we will look for units that have been incorrectly separated from the number they belong to
// by a space. We go ahead and associate the unit with the number even though it is invalid CSS.
checkForOrphanedUnits();
switch (static_cast<CSSPropertyID>(propId)) {
/* The comment to the left defines all valid value of this properties as defined
* in CSS 2, Appendix F. Property index
*/
/* All the CSS properties are not supported by the renderer at the moment.
* Note that all the CSS2 Aural properties are only checked, if CSS_AURAL is defined
* (see parseAuralValues). As we don't support them at all this seems reasonable.
*/
case CSSPropertySize: // <length>{1,2} | auto | portrait | landscape | inherit
case CSSPropertyQuotes: // [<string> <string>]+ | none | inherit
if (id)
valid_primitive = true;
break;
case CSSPropertyUnicodeBidi: // normal | embed | bidi-override | inherit
if (id == CSSValueNormal ||
id == CSSValueEmbed ||
id == CSSValueBidiOverride)
valid_primitive = true;
break;
case CSSPropertyPosition: // static | relative | absolute | fixed | inherit
if (id == CSSValueStatic ||
id == CSSValueRelative ||
id == CSSValueAbsolute ||
id == CSSValueFixed)
valid_primitive = true;
break;
case CSSPropertyPageBreakAfter: // auto | always | avoid | left | right | inherit
case CSSPropertyPageBreakBefore:
case CSSPropertyWebkitColumnBreakAfter:
case CSSPropertyWebkitColumnBreakBefore:
if (id == CSSValueAuto ||
id == CSSValueAlways ||
id == CSSValueAvoid ||
id == CSSValueLeft ||
id == CSSValueRight)
valid_primitive = true;
break;
case CSSPropertyPageBreakInside: // avoid | auto | inherit
case CSSPropertyWebkitColumnBreakInside:
if (id == CSSValueAuto || id == CSSValueAvoid)
valid_primitive = true;
break;
case CSSPropertyEmptyCells: // show | hide | inherit
if (id == CSSValueShow ||
id == CSSValueHide)
valid_primitive = true;
break;
case CSSPropertyContent: // [ <string> | <uri> | <counter> | attr(X) | open-quote |
// close-quote | no-open-quote | no-close-quote ]+ | inherit
return parseContent(propId, important);
case CSSPropertyWhiteSpace: // normal | pre | nowrap | inherit
if (id == CSSValueNormal ||
id == CSSValuePre ||
id == CSSValuePreWrap ||
id == CSSValuePreLine ||
id == CSSValueNowrap)
valid_primitive = true;
break;
case CSSPropertyClip: // <shape> | auto | inherit
if (id == CSSValueAuto)
valid_primitive = true;
else if (value->unit == Value::Function)
return parseShape(propId, important);
break;
/* Start of supported CSS properties with validation. This is needed for parseShorthand to work
* correctly and allows optimization in WebCore::applyRule(..)
*/
case CSSPropertyCaptionSide: // top | bottom | left | right | inherit
if (id == CSSValueLeft || id == CSSValueRight ||
id == CSSValueTop || id == CSSValueBottom)
valid_primitive = true;
break;
case CSSPropertyBorderCollapse: // collapse | separate | inherit
if (id == CSSValueCollapse || id == CSSValueSeparate)
valid_primitive = true;
break;
case CSSPropertyVisibility: // visible | hidden | collapse | inherit
if (id == CSSValueVisible || id == CSSValueHidden || id == CSSValueCollapse)
valid_primitive = true;
break;
case CSSPropertyOverflow: {
ShorthandScope scope(this, propId);
if (num != 1 || !parseValue(CSSPropertyOverflowX, important))
return false;
CSSValue* value = m_parsedProperties[m_numParsedProperties - 1]->value();
addProperty(CSSPropertyOverflowY, value, important);
return true;
}
case CSSPropertyOverflowX:
case CSSPropertyOverflowY: // visible | hidden | scroll | auto | marquee | overlay | inherit
if (id == CSSValueVisible || id == CSSValueHidden || id == CSSValueScroll || id == CSSValueAuto ||
id == CSSValueOverlay || id == CSSValueWebkitMarquee)
valid_primitive = true;
break;
case CSSPropertyListStylePosition: // inside | outside | inherit
if (id == CSSValueInside || id == CSSValueOutside)
valid_primitive = true;
break;
case CSSPropertyListStyleType:
// disc | circle | square | decimal | decimal-leading-zero | lower-roman |
// upper-roman | lower-greek | lower-alpha | lower-latin | upper-alpha |
// upper-latin | hebrew | armenian | georgian | cjk-ideographic | hiragana |
// katakana | hiragana-iroha | katakana-iroha | none | inherit
if ((id >= CSSValueDisc && id <= CSSValueKatakanaIroha) || id == CSSValueNone)
valid_primitive = true;
break;
case CSSPropertyDisplay:
// inline | block | list-item | run-in | inline-block | table |
// inline-table | table-row-group | table-header-group | table-footer-group | table-row |
// table-column-group | table-column | table-cell | table-caption | box | inline-box | none | inherit
if ((id >= CSSValueInline && id <= CSSValueWebkitInlineBox) || id == CSSValueNone)
valid_primitive = true;
break;
case CSSPropertyDirection: // ltr | rtl | inherit
if (id == CSSValueLtr || id == CSSValueRtl)
valid_primitive = true;
break;
case CSSPropertyTextTransform: // capitalize | uppercase | lowercase | none | inherit
if ((id >= CSSValueCapitalize && id <= CSSValueLowercase) || id == CSSValueNone)
valid_primitive = true;
break;
case CSSPropertyFloat: // left | right | none | inherit + center for buggy CSS
if (id == CSSValueLeft || id == CSSValueRight ||
id == CSSValueNone || id == CSSValueCenter)
valid_primitive = true;
break;
case CSSPropertyClear: // none | left | right | both | inherit
if (id == CSSValueNone || id == CSSValueLeft ||
id == CSSValueRight|| id == CSSValueBoth)
valid_primitive = true;
break;
case CSSPropertyTextAlign:
// left | right | center | justify | webkit_left | webkit_right | webkit_center | start | end | <string> | inherit
if ((id >= CSSValueWebkitAuto && id <= CSSValueWebkitCenter) || id == CSSValueStart || id == CSSValueEnd ||
value->unit == CSSPrimitiveValue::CSS_STRING)
valid_primitive = true;
break;
case CSSPropertyOutlineStyle: // <border-style> | auto | inherit
if (id == CSSValueAuto) {
valid_primitive = true;
break;
} // Fall through!
case CSSPropertyBorderTopStyle: //// <border-style> | inherit
case CSSPropertyBorderRightStyle: // Defined as: none | hidden | dotted | dashed |
case CSSPropertyBorderBottomStyle: // solid | double | groove | ridge | inset | outset
case CSSPropertyBorderLeftStyle:
case CSSPropertyWebkitColumnRuleStyle:
if (id >= CSSValueNone && id <= CSSValueDouble)
valid_primitive = true;
break;
case CSSPropertyFontWeight: // normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit
if (id >= CSSValueNormal && id <= CSSValue900) {
// Valid weight keyword
valid_primitive = true;
} else if (validUnit(value, FInteger | FNonNeg, false)) {
int weight = static_cast<int>(value->fValue);
if (weight % 100)
break;
weight /= 100;
if (weight >= 1 && weight <= 9) {
id = CSSValue100 + weight - 1;
valid_primitive = true;
}
}
break;
case CSSPropertyBorderSpacing: {
const int properties[2] = { CSSPropertyWebkitBorderHorizontalSpacing,
CSSPropertyWebkitBorderVerticalSpacing };
if (num == 1) {
ShorthandScope scope(this, CSSPropertyBorderSpacing);
if (!parseValue(properties[0], important))
return false;
CSSValue* value = m_parsedProperties[m_numParsedProperties-1]->value();
addProperty(properties[1], value, important);
return true;
}
else if (num == 2) {
ShorthandScope scope(this, CSSPropertyBorderSpacing);
if (!parseValue(properties[0], important) || !parseValue(properties[1], important))
return false;
return true;
}
return false;
}
case CSSPropertyWebkitBorderHorizontalSpacing:
case CSSPropertyWebkitBorderVerticalSpacing:
valid_primitive = validUnit(value, FLength|FNonNeg, m_strict);
break;
case CSSPropertyScrollbarFaceColor: // IE5.5
case CSSPropertyScrollbarShadowColor: // IE5.5
case CSSPropertyScrollbarHighlightColor: // IE5.5
case CSSPropertyScrollbar3dlightColor: // IE5.5
case CSSPropertyScrollbarDarkshadowColor: // IE5.5
case CSSPropertyScrollbarTrackColor: // IE5.5
case CSSPropertyScrollbarArrowColor: // IE5.5
if (m_strict)
break;
/* nobreak */
case CSSPropertyOutlineColor: // <color> | invert | inherit
// Outline color has "invert" as additional keyword.
// Also, we want to allow the special focus color even in strict parsing mode.
if (propId == CSSPropertyOutlineColor && (id == CSSValueInvert || id == CSSValueWebkitFocusRingColor)) {
valid_primitive = true;
break;
}
/* nobreak */
case CSSPropertyBackgroundColor: // <color> | inherit
case CSSPropertyBorderTopColor: // <color> | inherit
case CSSPropertyBorderRightColor: // <color> | inherit
case CSSPropertyBorderBottomColor: // <color> | inherit
case CSSPropertyBorderLeftColor: // <color> | inherit
case CSSPropertyColor: // <color> | inherit
case CSSPropertyTextLineThroughColor: // CSS3 text decoration colors
case CSSPropertyTextUnderlineColor:
case CSSPropertyTextOverlineColor:
case CSSPropertyWebkitColumnRuleColor:
case CSSPropertyWebkitTextFillColor:
case CSSPropertyWebkitTextStrokeColor:
if (id == CSSValueWebkitText)
valid_primitive = true; // Always allow this, even when strict parsing is on,
// since we use this in our UA sheets.
else if (id == CSSValueCurrentcolor)
valid_primitive = true;
else if (id >= CSSValueAqua && id <= CSSValueWindowtext || id == CSSValueMenu ||
(id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText && !m_strict)) {
valid_primitive = true;
} else {
parsedValue = parseColor();
if (parsedValue)
m_valueList->next();
}
break;
case CSSPropertyCursor: {
// [<uri>,]* [ auto | crosshair | default | pointer | progress | move | e-resize | ne-resize |
// nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize | ew-resize |
// ns-resize | nesw-resize | nwse-resize | col-resize | row-resize | text | wait | help ] ] | inherit
RefPtr<CSSValueList> list;
while (value && value->unit == CSSPrimitiveValue::CSS_URI) {
if (!list)
list = new CSSValueList;
String uri = parseURL(value->string);
Vector<int> coords;
value = m_valueList->next();
while (value && value->unit == CSSPrimitiveValue::CSS_NUMBER) {
coords.append(int(value->fValue));
value = m_valueList->next();
}
IntPoint hotspot;
int nrcoords = coords.size();
if (nrcoords > 0 && nrcoords != 2) {
if (m_strict) // only support hotspot pairs in strict mode
return false;
} else if (m_strict && nrcoords == 2)
hotspot = IntPoint(coords[0], coords[1]);
if (m_strict || coords.size() == 0) {
if (!uri.isNull())
list->append(CSSCursorImageValue::create(KURL(m_styleSheet->baseURL(), uri).string(), hotspot));
}
if ((m_strict && !value) || (value && !(value->unit == Value::Operator && value->iValue == ',')))
return false;
value = m_valueList->next(); // comma
}
if (list) {
if (!value) { // no value after url list (MSIE 5 compatibility)
if (list->length() != 1)
return false;
} else if (!m_strict && value->id == CSSValueHand) // MSIE 5 compatibility :/
list->append(new CSSPrimitiveValue(CSSValuePointer));
else if (value && ((value->id >= CSSValueAuto && value->id <= CSSValueAllScroll) || value->id == CSSValueCopy || value->id == CSSValueNone))
list->append(new CSSPrimitiveValue(value->id));
m_valueList->next();
parsedValue = list.release();
break;
}
id = value->id;
if (!m_strict && value->id == CSSValueHand) { // MSIE 5 compatibility :/
id = CSSValuePointer;
valid_primitive = true;
} else if ((value->id >= CSSValueAuto && value->id <= CSSValueAllScroll) || value->id == CSSValueCopy || value->id == CSSValueNone)
valid_primitive = true;
break;
}
case CSSPropertyBackgroundAttachment:
case CSSPropertyWebkitBackgroundClip:
case CSSPropertyWebkitBackgroundComposite:
case CSSPropertyBackgroundImage:
case CSSPropertyWebkitBackgroundOrigin:
case CSSPropertyBackgroundPosition:
case CSSPropertyBackgroundPositionX:
case CSSPropertyBackgroundPositionY:
case CSSPropertyWebkitBackgroundSize:
case CSSPropertyBackgroundRepeat:
case CSSPropertyWebkitMaskAttachment:
case CSSPropertyWebkitMaskClip:
case CSSPropertyWebkitMaskComposite:
case CSSPropertyWebkitMaskImage:
case CSSPropertyWebkitMaskOrigin:
case CSSPropertyWebkitMaskPosition:
case CSSPropertyWebkitMaskPositionX:
case CSSPropertyWebkitMaskPositionY:
case CSSPropertyWebkitMaskSize:
case CSSPropertyWebkitMaskRepeat: {
RefPtr<CSSValue> val1;
RefPtr<CSSValue> val2;
int propId1, propId2;
if (parseFillProperty(propId, propId1, propId2, val1, val2)) {
addProperty(propId1, val1.release(), important);
if (val2)
addProperty(propId2, val2.release(), important);
return true;
}
return false;
}
case CSSPropertyListStyleImage: // <uri> | none | inherit
if (id == CSSValueNone) {
parsedValue = CSSImageValue::create();
m_valueList->next();
} else if (value->unit == CSSPrimitiveValue::CSS_URI) {
// ### allow string in non strict mode?
String uri = parseURL(value->string);
if (!uri.isNull()) {
parsedValue = CSSImageValue::create(KURL(m_styleSheet->baseURL(), uri).string());
m_valueList->next();
}
} else if (value->unit == Value::Function && equalIgnoringCase(value->function->name, "-webkit-gradient(")) {
if (parseGradient(parsedValue))
m_valueList->next();
else
return false;
}
break;
case CSSPropertyWebkitTextStrokeWidth:
case CSSPropertyOutlineWidth: // <border-width> | inherit
case CSSPropertyBorderTopWidth: //// <border-width> | inherit
case CSSPropertyBorderRightWidth: // Which is defined as
case CSSPropertyBorderBottomWidth: // thin | medium | thick | <length>
case CSSPropertyBorderLeftWidth:
case CSSPropertyWebkitColumnRuleWidth:
if (id == CSSValueThin || id == CSSValueMedium || id == CSSValueThick)
valid_primitive = true;
else
valid_primitive = validUnit(value, FLength, m_strict);
break;
case CSSPropertyLetterSpacing: // normal | <length> | inherit
case CSSPropertyWordSpacing: // normal | <length> | inherit
if (id == CSSValueNormal)
valid_primitive = true;
else
valid_primitive = validUnit(value, FLength, m_strict);
break;
case CSSPropertyWordBreak: // normal | break-all | break-word (this is a custom extension)
if (id == CSSValueNormal || id == CSSValueBreakAll || id == CSSValueBreakWord)
valid_primitive = true;
break;
case CSSPropertyWordWrap: // normal | break-word
if (id == CSSValueNormal || id == CSSValueBreakWord)
valid_primitive = true;
break;
case CSSPropertyTextIndent: // <length> | <percentage> | inherit
case CSSPropertyPaddingTop: //// <padding-width> | inherit
case CSSPropertyPaddingRight: // Which is defined as
case CSSPropertyPaddingBottom: // <length> | <percentage>
case CSSPropertyPaddingLeft: ////
case CSSPropertyWebkitPaddingStart:
valid_primitive = (!id && validUnit(value, FLength|FPercent, m_strict));
break;
case CSSPropertyMaxHeight: // <length> | <percentage> | none | inherit
case CSSPropertyMaxWidth: // <length> | <percentage> | none | inherit
if (id == CSSValueNone || id == CSSValueIntrinsic || id == CSSValueMinIntrinsic) {
valid_primitive = true;
break;
}
/* nobreak */
case CSSPropertyMinHeight: // <length> | <percentage> | inherit
case CSSPropertyMinWidth: // <length> | <percentage> | inherit
if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic)
valid_primitive = true;
else
valid_primitive = (!id && validUnit(value, FLength|FPercent|FNonNeg, m_strict));
break;
case CSSPropertyFontSize:
// <absolute-size> | <relative-size> | <length> | <percentage> | inherit
if (id >= CSSValueXxSmall && id <= CSSValueLarger)
valid_primitive = true;
else
valid_primitive = (validUnit(value, FLength|FPercent|FNonNeg, m_strict));
break;
case CSSPropertyFontStyle: // normal | italic | oblique | inherit
if (id == CSSValueNormal || id == CSSValueItalic || id == CSSValueOblique)
valid_primitive = true;
break;
case CSSPropertyFontVariant: // normal | small-caps | inherit
if (id == CSSValueNormal || id == CSSValueSmallCaps)
valid_primitive = true;
break;
case CSSPropertyVerticalAlign:
// baseline | sub | super | top | text-top | middle | bottom | text-bottom |
// <percentage> | <length> | inherit
if (id >= CSSValueBaseline && id <= CSSValueWebkitBaselineMiddle)
valid_primitive = true;
else
valid_primitive = (!id && validUnit(value, FLength|FPercent, m_strict));
break;
case CSSPropertyHeight: // <length> | <percentage> | auto | inherit
case CSSPropertyWidth: // <length> | <percentage> | auto | inherit
if (id == CSSValueAuto || id == CSSValueIntrinsic || id == CSSValueMinIntrinsic)
valid_primitive = true;
else
// ### handle multilength case where we allow relative units
valid_primitive = (!id && validUnit(value, FLength|FPercent|FNonNeg, m_strict));
break;
case CSSPropertyBottom: // <length> | <percentage> | auto | inherit
case CSSPropertyLeft: // <length> | <percentage> | auto | inherit
case CSSPropertyRight: // <length> | <percentage> | auto | inherit
case CSSPropertyTop: // <length> | <percentage> | auto | inherit
case CSSPropertyMarginTop: //// <margin-width> | inherit
case CSSPropertyMarginRight: // Which is defined as
case CSSPropertyMarginBottom: // <length> | <percentage> | auto | inherit
case CSSPropertyMarginLeft: ////
case CSSPropertyWebkitMarginStart:
if (id == CSSValueAuto)
valid_primitive = true;
else
valid_primitive = (!id && validUnit(value, FLength|FPercent, m_strict));
break;
case CSSPropertyZIndex: // auto | <integer> | inherit
if (id == CSSValueAuto) {
valid_primitive = true;
break;
}
/* nobreak */
case CSSPropertyOrphans: // <integer> | inherit
case CSSPropertyWidows: // <integer> | inherit
// ### not supported later on
valid_primitive = (!id && validUnit(value, FInteger, false));
break;
case CSSPropertyLineHeight: // normal | <number> | <length> | <percentage> | inherit
if (id == CSSValueNormal)
valid_primitive = true;
else
valid_primitive = (!id && validUnit(value, FNumber|FLength|FPercent|FNonNeg, m_strict));
break;
case CSSPropertyCounterIncrement: // [ <identifier> <integer>? ]+ | none | inherit
if (id != CSSValueNone)
return parseCounter(propId, 1, important);
valid_primitive = true;
break;
case CSSPropertyCounterReset: // [ <identifier> <integer>? ]+ | none | inherit
if (id != CSSValueNone)
return parseCounter(propId, 0, important);
valid_primitive = true;
break;
case CSSPropertyFontFamily:
// [[ <family-name> | <generic-family> ],]* [<family-name> | <generic-family>] | inherit
{
parsedValue = parseFontFamily();
break;
}
case CSSPropertyTextDecoration:
case CSSPropertyWebkitTextDecorationsInEffect:
// none | [ underline || overline || line-through || blink ] | inherit
if (id == CSSValueNone) {
valid_primitive = true;
} else {
RefPtr<CSSValueList> list(new CSSValueList);
bool is_valid = true;
while(is_valid && value) {
switch (value->id) {
case CSSValueBlink:
break;
case CSSValueUnderline:
case CSSValueOverline:
case CSSValueLineThrough:
list->append(new CSSPrimitiveValue(value->id));
break;
default:
is_valid = false;
}
value = m_valueList->next();
}
if (list->length() && is_valid) {
parsedValue = list.release();
m_valueList->next();
}
}
break;
case CSSPropertyZoom: // normal | reset | <number> | <percentage> | inherit
if (id == CSSValueNormal || id == CSSValueReset)
valid_primitive = true;
else
valid_primitive = (!id && validUnit(value, FNumber | FPercent | FNonNeg, true));
break;
case CSSPropertyTableLayout: // auto | fixed | inherit
if (id == CSSValueAuto || id == CSSValueFixed)
valid_primitive = true;
break;
case CSSPropertySrc: // Only used within @font-face, so cannot use inherit | initial or be !important. This is a list of urls or local references.
return parseFontFaceSrc();
case CSSPropertyUnicodeRange:
return parseFontFaceUnicodeRange();
/* CSS3 properties */
case CSSPropertyWebkitAppearance:
if ((id >= CSSValueCheckbox && id <= CSSValueTextarea) || id == CSSValueNone)
valid_primitive = true;
break;
case CSSPropertyWebkitBinding:
#if ENABLE(XBL)
if (id == CSSValueNone)
valid_primitive = true;
else {
RefPtr<CSSValueList> values(new CSSValueList());
Value* val;
RefPtr<CSSValue> parsedValue;
while ((val = m_valueList->current())) {
if (val->unit == CSSPrimitiveValue::CSS_URI) {
String value = parseURL(val->string);
parsedValue = new CSSPrimitiveValue(KURL(m_styleSheet->baseURL(), value).string(),
CSSPrimitiveValue::CSS_URI);
}
if (!parsedValue)
break;
// FIXME: We can't use release() here since we might hit this path twice
// but that logic seems wrong to me to begin with, we convert all non-uri values
// into the last seen URI value!?
// -webkit-binding: url(foo.xml), 1, 2; (if that were valid) is treated as:
// -webkit-binding: url(foo.xml), url(foo.xml), url(foo.xml); !?
values->append(parsedValue.get());
m_valueList->next();
}
if (!values->length())
return false;
addProperty(propId, values.release(), important);
m_valueList->next();
return true;
}
#endif
break;
case CSSPropertyWebkitBorderImage:
case CSSPropertyWebkitMaskBoxImage:
if (id == CSSValueNone)
valid_primitive = true;
else {
RefPtr<CSSValue> result;
if (parseBorderImage(propId, important, result)) {
addProperty(propId, result, important);
return true;
}
}
break;
case CSSPropertyWebkitBorderTopRightRadius:
case CSSPropertyWebkitBorderTopLeftRadius:
case CSSPropertyWebkitBorderBottomLeftRadius:
case CSSPropertyWebkitBorderBottomRightRadius:
case CSSPropertyWebkitBorderRadius: {
if (num != 1 && num != 2)
return false;
valid_primitive = validUnit(value, FLength, m_strict);
if (!valid_primitive)
return false;
RefPtr<CSSPrimitiveValue> parsedValue1 = new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
RefPtr<CSSPrimitiveValue> parsedValue2;
if (num == 2) {
value = m_valueList->next();
valid_primitive = validUnit(value, FLength, m_strict);
if (!valid_primitive)
return false;
parsedValue2 = new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
} else
parsedValue2 = parsedValue1;
RefPtr<Pair> pair = Pair::create(parsedValue1.release(), parsedValue2.release());
RefPtr<CSSPrimitiveValue> val = new CSSPrimitiveValue(pair.release());
if (propId == CSSPropertyWebkitBorderRadius) {
const int properties[4] = { CSSPropertyWebkitBorderTopRightRadius,
CSSPropertyWebkitBorderTopLeftRadius,
CSSPropertyWebkitBorderBottomLeftRadius,
CSSPropertyWebkitBorderBottomRightRadius };
for (int i = 0; i < 4; i++)
addProperty(properties[i], val.get(), important);
} else
addProperty(propId, val.release(), important);
return true;
}
case CSSPropertyOutlineOffset:
valid_primitive = validUnit(value, FLength, m_strict);
break;
case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS3, so treat as CSS3
case CSSPropertyWebkitBoxShadow:
if (id == CSSValueNone)
valid_primitive = true;
else
return parseShadow(propId, important);
break;
case CSSPropertyWebkitBoxReflect:
if (id == CSSValueNone)
valid_primitive = true;
else
return parseReflect(propId, important);
break;
case CSSPropertyOpacity:
valid_primitive = validUnit(value, FNumber, m_strict);
break;
case CSSPropertyWebkitBoxAlign:
if (id == CSSValueStretch || id == CSSValueStart || id == CSSValueEnd ||
id == CSSValueCenter || id == CSSValueBaseline)
valid_primitive = true;
break;
case CSSPropertyWebkitBoxDirection:
if (id == CSSValueNormal || id == CSSValueReverse)
valid_primitive = true;
break;
case CSSPropertyWebkitBoxLines:
if (id == CSSValueSingle || id == CSSValueMultiple)
valid_primitive = true;
break;
case CSSPropertyWebkitBoxOrient:
if (id == CSSValueHorizontal || id == CSSValueVertical ||
id == CSSValueInlineAxis || id == CSSValueBlockAxis)
valid_primitive = true;
break;
case CSSPropertyWebkitBoxPack:
if (id == CSSValueStart || id == CSSValueEnd ||
id == CSSValueCenter || id == CSSValueJustify)
valid_primitive = true;
break;
case CSSPropertyWebkitBoxFlex:
valid_primitive = validUnit(value, FNumber, m_strict);
break;
case CSSPropertyWebkitBoxFlexGroup:
case CSSPropertyWebkitBoxOrdinalGroup:
valid_primitive = validUnit(value, FInteger|FNonNeg, true);
break;
case CSSPropertyWebkitBoxSizing:
valid_primitive = id == CSSValueBorderBox || id == CSSValueContentBox;
break;
case CSSPropertyWebkitMarquee: {
const int properties[5] = { CSSPropertyWebkitMarqueeDirection, CSSPropertyWebkitMarqueeIncrement,
CSSPropertyWebkitMarqueeRepetition,
CSSPropertyWebkitMarqueeStyle, CSSPropertyWebkitMarqueeSpeed };
return parseShorthand(propId, properties, 5, important);
}
case CSSPropertyWebkitMarqueeDirection:
if (id == CSSValueForwards || id == CSSValueBackwards || id == CSSValueAhead ||
id == CSSValueReverse || id == CSSValueLeft || id == CSSValueRight || id == CSSValueDown ||
id == CSSValueUp || id == CSSValueAuto)
valid_primitive = true;
break;
case CSSPropertyWebkitMarqueeIncrement:
if (id == CSSValueSmall || id == CSSValueLarge || id == CSSValueMedium)
valid_primitive = true;
else
valid_primitive = validUnit(value, FLength|FPercent, m_strict);
break;
case CSSPropertyWebkitMarqueeStyle:
if (id == CSSValueNone || id == CSSValueSlide || id == CSSValueScroll || id == CSSValueAlternate)
valid_primitive = true;
break;
case CSSPropertyWebkitMarqueeRepetition:
if (id == CSSValueInfinite)
valid_primitive = true;
else
valid_primitive = validUnit(value, FInteger|FNonNeg, m_strict);
break;
case CSSPropertyWebkitMarqueeSpeed:
if (id == CSSValueNormal || id == CSSValueSlow || id == CSSValueFast)
valid_primitive = true;
else
valid_primitive = validUnit(value, FTime|FInteger|FNonNeg, m_strict);
break;
case CSSPropertyWebkitUserDrag: // auto | none | element
if (id == CSSValueAuto || id == CSSValueNone || id == CSSValueElement)
valid_primitive = true;
break;
case CSSPropertyWebkitUserModify: // read-only | read-write
if (id == CSSValueReadOnly || id == CSSValueReadWrite || id == CSSValueReadWritePlaintextOnly)
valid_primitive = true;
break;
case CSSPropertyWebkitUserSelect: // auto | none | text
if (id == CSSValueAuto || id == CSSValueNone || id == CSSValueText)
valid_primitive = true;
break;
case CSSPropertyTextOverflow: // clip | ellipsis
if (id == CSSValueClip || id == CSSValueEllipsis)
valid_primitive = true;
break;
case CSSPropertyWebkitTransform:
if (id == CSSValueNone)
valid_primitive = true;
else {
PassRefPtr<CSSValue> val = parseTransform();
if (val) {
addProperty(propId, val, important);
return true;
}
return false;
}
break;
case CSSPropertyWebkitTransformOrigin:
case CSSPropertyWebkitTransformOriginX:
case CSSPropertyWebkitTransformOriginY: {
RefPtr<CSSValue> val1;
RefPtr<CSSValue> val2;
int propId1, propId2;
if (parseTransformOrigin(propId, propId1, propId2, val1, val2)) {
addProperty(propId1, val1.release(), important);
if (val2)
addProperty(propId2, val2.release(), important);
return true;
}
return false;
}
case CSSPropertyWebkitTransitionDuration:
case CSSPropertyWebkitTransitionRepeatCount:
case CSSPropertyWebkitTransitionTimingFunction:
case CSSPropertyWebkitTransitionProperty: {
RefPtr<CSSValue> val;
if (parseTransitionProperty(propId, val)) {
addProperty(propId, val.release(), important);
return true;
}
return false;
}
case CSSPropertyWebkitMarginCollapse: {
const int properties[2] = { CSSPropertyWebkitMarginTopCollapse,
CSSPropertyWebkitMarginBottomCollapse };
if (num == 1) {
ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
if (!parseValue(properties[0], important))
return false;
CSSValue* value = m_parsedProperties[m_numParsedProperties-1]->value();
addProperty(properties[1], value, important);
return true;
}
else if (num == 2) {
ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
if (!parseValue(properties[0], important) || !parseValue(properties[1], important))
return false;
return true;
}
return false;
}
case CSSPropertyWebkitMarginTopCollapse:
case CSSPropertyWebkitMarginBottomCollapse:
if (id == CSSValueCollapse || id == CSSValueSeparate || id == CSSValueDiscard)
valid_primitive = true;
break;
case CSSPropertyTextLineThroughMode:
case CSSPropertyTextOverlineMode:
case CSSPropertyTextUnderlineMode:
if (id == CSSValueContinuous || id == CSSValueSkipWhiteSpace)
valid_primitive = true;
break;
case CSSPropertyTextLineThroughStyle:
case CSSPropertyTextOverlineStyle:
case CSSPropertyTextUnderlineStyle:
if (id == CSSValueNone || id == CSSValueSolid || id == CSSValueDouble ||
id == CSSValueDashed || id == CSSValueDotDash || id == CSSValueDotDotDash ||
id == CSSValueWave)
valid_primitive = true;
break;
case CSSPropertyTextLineThroughWidth:
case CSSPropertyTextOverlineWidth:
case CSSPropertyTextUnderlineWidth:
if (id == CSSValueAuto || id == CSSValueNormal || id == CSSValueThin ||
id == CSSValueMedium || id == CSSValueThick)
valid_primitive = true;
else
valid_primitive = !id && validUnit(value, FNumber|FLength|FPercent, m_strict);
break;
case CSSPropertyResize: // none | both | horizontal | vertical | auto
if (id == CSSValueNone || id == CSSValueBoth || id == CSSValueHorizontal || id == CSSValueVertical || id == CSSValueAuto)
valid_primitive = true;
break;
case CSSPropertyWebkitColumnCount:
if (id == CSSValueAuto)
valid_primitive = true;
else
valid_primitive = !id && validUnit(value, FInteger | FNonNeg, false);
break;
case CSSPropertyWebkitColumnGap: // normal | <length>
if (id == CSSValueNormal)
valid_primitive = true;
else
valid_primitive = validUnit(value, FLength | FNonNeg, m_strict);
break;
case CSSPropertyWebkitColumnWidth: // auto | <length>
if (id == CSSValueAuto)
valid_primitive = true;
else // Always parse this property in strict mode, since it would be ambiguous otherwise when used in the 'columns' shorthand property.
valid_primitive = validUnit(value, FLength, true);
break;
// End of CSS3 properties
// Apple specific properties. These will never be standardized and are purely to
// support custom WebKit-based Apple applications.
case CSSPropertyWebkitLineClamp:
valid_primitive = (!id && validUnit(value, FPercent, false));
break;
case CSSPropertyWebkitTextSizeAdjust:
if (id == CSSValueAuto || id == CSSValueNone)
valid_primitive = true;
break;
case CSSPropertyWebkitRtlOrdering:
if (id == CSSValueLogical || id == CSSValueVisual)
valid_primitive = true;
break;
case CSSPropertyWebkitFontSizeDelta: // <length>
valid_primitive = validUnit(value, FLength, m_strict);
break;
case CSSPropertyWebkitNbspMode: // normal | space
if (id == CSSValueNormal || id == CSSValueSpace)
valid_primitive = true;
break;
case CSSPropertyWebkitLineBreak: // normal | after-white-space
if (id == CSSValueNormal || id == CSSValueAfterWhiteSpace)
valid_primitive = true;
break;
case CSSPropertyWebkitMatchNearestMailBlockquoteColor: // normal | match
if (id == CSSValueNormal || id == CSSValueMatch)
valid_primitive = true;
break;
case CSSPropertyWebkitHighlight:
if (id == CSSValueNone || value->unit == CSSPrimitiveValue::CSS_STRING)
valid_primitive = true;
break;
case CSSPropertyWebkitBorderFit:
if (id == CSSValueBorder || id == CSSValueLines)
valid_primitive = true;
break;
case CSSPropertyWebkitTextSecurity:
// disc | circle | square | none | inherit
if (id == CSSValueDisc || id == CSSValueCircle || id == CSSValueSquare|| id == CSSValueNone)
valid_primitive = true;
break;
#if ENABLE(DASHBOARD_SUPPORT)
case CSSPropertyWebkitDashboardRegion: // <dashboard-region> | <dashboard-region>
if (value->unit == Value::Function || id == CSSValueNone)
return parseDashboardRegions(propId, important);
break;
#endif
// End Apple-specific properties
/* shorthand properties */
case CSSPropertyBackground: {
// Position must come before color in this array because a plain old "0" is a legal color
// in quirks mode but it's usually the X coordinate of a position.
// FIXME: Add CSSPropertyWebkitBackgroundSize to the shorthand.
const int properties[] = { CSSPropertyBackgroundImage, CSSPropertyBackgroundRepeat,
CSSPropertyBackgroundAttachment, CSSPropertyBackgroundPosition, CSSPropertyWebkitBackgroundClip,
CSSPropertyWebkitBackgroundOrigin, CSSPropertyBackgroundColor };
return parseFillShorthand(propId, properties, 7, important);
}
case CSSPropertyWebkitMask: {
const int properties[] = { CSSPropertyWebkitMaskImage, CSSPropertyWebkitMaskRepeat,
CSSPropertyWebkitMaskAttachment, CSSPropertyWebkitMaskPosition, CSSPropertyWebkitMaskClip,
CSSPropertyWebkitMaskOrigin };
return parseFillShorthand(propId, properties, 6, important);
}
case CSSPropertyBorder:
// [ 'border-width' || 'border-style' || <color> ] | inherit
{
const int properties[3] = { CSSPropertyBorderWidth, CSSPropertyBorderStyle,
CSSPropertyBorderColor };
return parseShorthand(propId, properties, 3, important);
}
case CSSPropertyBorderTop:
// [ 'border-top-width' || 'border-style' || <color> ] | inherit
{
const int properties[3] = { CSSPropertyBorderTopWidth, CSSPropertyBorderTopStyle,
CSSPropertyBorderTopColor};
return parseShorthand(propId, properties, 3, important);
}
case CSSPropertyBorderRight:
// [ 'border-right-width' || 'border-style' || <color> ] | inherit
{
const int properties[3] = { CSSPropertyBorderRightWidth, CSSPropertyBorderRightStyle,
CSSPropertyBorderRightColor };
return parseShorthand(propId, properties, 3, important);
}
case CSSPropertyBorderBottom:
// [ 'border-bottom-width' || 'border-style' || <color> ] | inherit
{
const int properties[3] = { CSSPropertyBorderBottomWidth, CSSPropertyBorderBottomStyle,
CSSPropertyBorderBottomColor };
return parseShorthand(propId, properties, 3, important);
}
case CSSPropertyBorderLeft:
// [ 'border-left-width' || 'border-style' || <color> ] | inherit
{
const int properties[3] = { CSSPropertyBorderLeftWidth, CSSPropertyBorderLeftStyle,
CSSPropertyBorderLeftColor };
return parseShorthand(propId, properties, 3, important);
}
case CSSPropertyOutline:
// [ 'outline-color' || 'outline-style' || 'outline-width' ] | inherit
{
const int properties[3] = { CSSPropertyOutlineWidth, CSSPropertyOutlineStyle,
CSSPropertyOutlineColor };
return parseShorthand(propId, properties, 3, important);
}
case CSSPropertyBorderColor:
// <color>{1,4} | inherit
{
const int properties[4] = { CSSPropertyBorderTopColor, CSSPropertyBorderRightColor,
CSSPropertyBorderBottomColor, CSSPropertyBorderLeftColor };
return parse4Values(propId, properties, important);
}
case CSSPropertyBorderWidth:
// <border-width>{1,4} | inherit
{
const int properties[4] = { CSSPropertyBorderTopWidth, CSSPropertyBorderRightWidth,
CSSPropertyBorderBottomWidth, CSSPropertyBorderLeftWidth };
return parse4Values(propId, properties, important);
}
case CSSPropertyBorderStyle:
// <border-style>{1,4} | inherit
{
const int properties[4] = { CSSPropertyBorderTopStyle, CSSPropertyBorderRightStyle,
CSSPropertyBorderBottomStyle, CSSPropertyBorderLeftStyle };
return parse4Values(propId, properties, important);
}
case CSSPropertyMargin:
// <margin-width>{1,4} | inherit
{
const int properties[4] = { CSSPropertyMarginTop, CSSPropertyMarginRight,
CSSPropertyMarginBottom, CSSPropertyMarginLeft };
return parse4Values(propId, properties, important);
}
case CSSPropertyPadding:
// <padding-width>{1,4} | inherit
{
const int properties[4] = { CSSPropertyPaddingTop, CSSPropertyPaddingRight,
CSSPropertyPaddingBottom, CSSPropertyPaddingLeft };
return parse4Values(propId, properties, important);
}
case CSSPropertyFont:
// [ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]?
// 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inherit
if (id >= CSSValueCaption && id <= CSSValueStatusBar)
valid_primitive = true;
else
return parseFont(important);
break;
case CSSPropertyListStyle:
{
const int properties[3] = { CSSPropertyListStyleType, CSSPropertyListStylePosition,
CSSPropertyListStyleImage };
return parseShorthand(propId, properties, 3, important);
}
case CSSPropertyWebkitColumns: {
const int properties[2] = { CSSPropertyWebkitColumnWidth, CSSPropertyWebkitColumnCount };
return parseShorthand(propId, properties, 2, important);
}
case CSSPropertyWebkitColumnRule: {
const int properties[3] = { CSSPropertyWebkitColumnRuleWidth, CSSPropertyWebkitColumnRuleStyle,
CSSPropertyWebkitColumnRuleColor };
return parseShorthand(propId, properties, 3, important);
}
case CSSPropertyWebkitTextStroke: {
const int properties[2] = { CSSPropertyWebkitTextStrokeWidth, CSSPropertyWebkitTextStrokeColor };
return parseShorthand(propId, properties, 2, important);
}
case CSSPropertyWebkitTransition:
return parseTransitionShorthand(important);
case CSSPropertyInvalid:
return false;
case CSSPropertyFontStretch:
case CSSPropertyPage:
case CSSPropertyTextLineThrough:
case CSSPropertyTextOverline:
case CSSPropertyTextUnderline:
return false;
#if ENABLE(SVG)
default:
return parseSVGValue(propId, important);
#endif
}
if (valid_primitive) {
if (id != 0)
parsedValue = new CSSPrimitiveValue(id);
else if (value->unit == CSSPrimitiveValue::CSS_STRING)
parsedValue = new CSSPrimitiveValue(value->string, (CSSPrimitiveValue::UnitTypes) value->unit);
else if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
parsedValue = new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit);
else if (value->unit >= Value::Q_EMS)
parsedValue = new CSSQuirkPrimitiveValue(value->fValue, CSSPrimitiveValue::CSS_EMS);
m_valueList->next();
}
if (parsedValue) {
if (!m_valueList->current() || inShorthand()) {
addProperty(propId, parsedValue.release(), important);
return true;
}
}
return false;
}
void CSSParser::addFillValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval)
{
if (lval) {
if (lval->isValueList())
static_cast<CSSValueList*>(lval.get())->append(rval);
else {
PassRefPtr<CSSValue> oldlVal(lval.release());
PassRefPtr<CSSValueList> list(new CSSValueList());
list->append(oldlVal);
list->append(rval);
lval = list;
}
}
else
lval = rval;
}
const int cMaxFillProperties = 7;
bool CSSParser::parseFillShorthand(int propId, const int* properties, int numProperties, bool important)
{
ASSERT(numProperties <= cMaxFillProperties);
if (numProperties > cMaxFillProperties)
return false;
ShorthandScope scope(this, propId);
bool parsedProperty[cMaxFillProperties] = { false };
RefPtr<CSSValue> values[cMaxFillProperties];
RefPtr<CSSValue> positionYValue;
int i;
while (m_valueList->current()) {
Value* val = m_valueList->current();
if (val->unit == Value::Operator && val->iValue == ',') {
// We hit the end. Fill in all remaining values with the initial value.
m_valueList->next();
for (i = 0; i < numProperties; ++i) {
if (properties[i] == CSSPropertyBackgroundColor && parsedProperty[i])
// Color is not allowed except as the last item in a list for backgrounds.
// Reject the entire property.
return false;
if (!parsedProperty[i] && properties[i] != CSSPropertyBackgroundColor) {
addFillValue(values[i], new CSSInitialValue(true));
if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
addFillValue(positionYValue, new CSSInitialValue(true));
}
parsedProperty[i] = false;
}
if (!m_valueList->current())
break;
}
bool found = false;
for (i = 0; !found && i < numProperties; ++i) {
if (!parsedProperty[i]) {
RefPtr<CSSValue> val1;
RefPtr<CSSValue> val2;
int propId1, propId2;
if (parseFillProperty(properties[i], propId1, propId2, val1, val2)) {
parsedProperty[i] = found = true;
addFillValue(values[i], val1.release());
if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
addFillValue(positionYValue, val2.release());
}
}
}
// if we didn't find at least one match, this is an
// invalid shorthand and we have to ignore it
if (!found)
return false;
}
// Fill in any remaining properties with the initial value.
for (i = 0; i < numProperties; ++i) {
if (!parsedProperty[i]) {
addFillValue(values[i], new CSSInitialValue(true));
if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
addFillValue(positionYValue, new CSSInitialValue(true));
}
}
// Now add all of the properties we found.
for (i = 0; i < numProperties; i++) {
if (properties[i] == CSSPropertyBackgroundPosition) {
addProperty(CSSPropertyBackgroundPositionX, values[i].release(), important);
// it's OK to call positionYValue.release() since we only see CSSPropertyBackgroundPosition once
addProperty(CSSPropertyBackgroundPositionY, positionYValue.release(), important);
} else if (properties[i] == CSSPropertyWebkitMaskPosition) {
addProperty(CSSPropertyWebkitMaskPositionX, values[i].release(), important);
// it's OK to call positionYValue.release() since we only see CSSPropertyWebkitMaskPosition once
addProperty(CSSPropertyWebkitMaskPositionY, positionYValue.release(), important);
} else
addProperty(properties[i], values[i].release(), important);
}
return true;
}
void CSSParser::addTransitionValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval)
{
if (lval) {
if (lval->isValueList())
static_cast<CSSValueList*>(lval.get())->append(rval);
else {
PassRefPtr<CSSValue> oldVal(lval.release());
PassRefPtr<CSSValueList> list(new CSSValueList());
list->append(oldVal);
list->append(rval);
lval = list;
}
}
else
lval = rval;
}
bool CSSParser::parseTransitionShorthand(bool important)
{
const int properties[] = { CSSPropertyWebkitTransitionProperty, CSSPropertyWebkitTransitionDuration,
CSSPropertyWebkitTransitionTimingFunction, CSSPropertyWebkitTransitionRepeatCount };
const int numProperties = sizeof(properties) / sizeof(properties[0]);
ShorthandScope scope(this, CSSPropertyWebkitTransition);
bool parsedProperty[numProperties] = { false }; // compiler will repeat false as necessary
RefPtr<CSSValue> values[numProperties];
int i;
while (m_valueList->current()) {
Value* val = m_valueList->current();
if (val->unit == Value::Operator && val->iValue == ',') {
// We hit the end. Fill in all remaining values with the initial value.
m_valueList->next();
for (i = 0; i < numProperties; ++i) {
if (!parsedProperty[i])
addTransitionValue(values[i], new CSSInitialValue(true));
parsedProperty[i] = false;
}
if (!m_valueList->current())
break;
}
bool found = false;
for (i = 0; !found && i < numProperties; ++i) {
if (!parsedProperty[i]) {
RefPtr<CSSValue> val;
if (parseTransitionProperty(properties[i], val)) {
parsedProperty[i] = found = true;
addTransitionValue(values[i], val.release());
}
}
}
// if we didn't find at least one match, this is an
// invalid shorthand and we have to ignore it
if (!found)
return false;
}
// Fill in any remaining properties with the initial value.
for (i = 0; i < numProperties; ++i) {
if (!parsedProperty[i])
addTransitionValue(values[i], new CSSInitialValue(true));
}
// Now add all of the properties we found.
for (i = 0; i < numProperties; i++)
addProperty(properties[i], values[i].release(), important);
return true;
}
bool CSSParser::parseShorthand(int propId, const int *properties, int numProperties, bool important)
{
// We try to match as many properties as possible
// We set up an array of booleans to mark which property has been found,
// and we try to search for properties until it makes no longer any sense.
ShorthandScope scope(this, propId);
bool found = false;
bool fnd[6]; // Trust me ;)
for (int i = 0; i < numProperties; i++)
fnd[i] = false;
while (m_valueList->current()) {
found = false;
for (int propIndex = 0; !found && propIndex < numProperties; ++propIndex) {
if (!fnd[propIndex]) {
if (parseValue(properties[propIndex], important))
fnd[propIndex] = found = true;
}
}
// if we didn't find at least one match, this is an
// invalid shorthand and we have to ignore it
if (!found)
return false;
}
// Fill in any remaining properties with the initial value.
m_implicitShorthand = true;
for (int i = 0; i < numProperties; ++i) {
if (!fnd[i])
addProperty(properties[i], new CSSInitialValue(true), important);
}
m_implicitShorthand = false;
return true;
}
bool CSSParser::parse4Values(int propId, const int *properties, bool important)
{
/* From the CSS 2 specs, 8.3
* If there is only one value, it applies to all sides. If there are two values, the top and
* bottom margins are set to the first value and the right and left margins are set to the second.
* If there are three values, the top is set to the first value, the left and right are set to the
* second, and the bottom is set to the third. If there are four values, they apply to the top,
* right, bottom, and left, respectively.
*/
int num = inShorthand() ? 1 : m_valueList->size();
ShorthandScope scope(this, propId);
// the order is top, right, bottom, left
switch (num) {
case 1: {
if (!parseValue(properties[0], important))
return false;
CSSValue *value = m_parsedProperties[m_numParsedProperties-1]->value();
m_implicitShorthand = true;
addProperty(properties[1], value, important);
addProperty(properties[2], value, important);
addProperty(properties[3], value, important);
m_implicitShorthand = false;
break;
}
case 2: {
if (!parseValue(properties[0], important) || !parseValue(properties[1], important))
return false;
CSSValue *value = m_parsedProperties[m_numParsedProperties-2]->value();
m_implicitShorthand = true;
addProperty(properties[2], value, important);
value = m_parsedProperties[m_numParsedProperties-2]->value();
addProperty(properties[3], value, important);
m_implicitShorthand = false;
break;
}
case 3: {
if (!parseValue(properties[0], important) || !parseValue(properties[1], important) || !parseValue(properties[2], important))
return false;
CSSValue *value = m_parsedProperties[m_numParsedProperties-2]->value();
m_implicitShorthand = true;
addProperty(properties[3], value, important);
m_implicitShorthand = false;
break;
}
case 4: {
if (!parseValue(properties[0], important) || !parseValue(properties[1], important) ||
!parseValue(properties[2], important) || !parseValue(properties[3], important))
return false;
break;
}
default: {
return false;
}
}
return true;
}
// [ <string> | <uri> | <counter> | attr(X) | open-quote | close-quote | no-open-quote | no-close-quote ]+ | inherit
// in CSS 2.1 this got somewhat reduced:
// [ <string> | attr(X) | open-quote | close-quote | no-open-quote | no-close-quote ]+ | inherit
bool CSSParser::parseContent(int propId, bool important)
{
RefPtr<CSSValueList> values = new CSSValueList;
while (Value* val = m_valueList->current()) {
RefPtr<CSSValue> parsedValue;
if (val->unit == CSSPrimitiveValue::CSS_URI) {
// url
String value = parseURL(val->string);
parsedValue = CSSImageValue::create(KURL(m_styleSheet->baseURL(), value).string());
} else if (val->unit == Value::Function) {
// attr(X) | counter(X [,Y]) | counters(X, Y, [,Z]) | -webkit-gradient(...)
ValueList* args = val->function->args;
if (!args)
return false;
if (equalIgnoringCase(val->function->name, "attr(")) {
if (args->size() != 1)
return false;
Value* a = args->current();
if (a->unit != CSSPrimitiveValue::CSS_IDENT)
return false;
String attrName = a->string;
// CSS allows identifiers with "-" at the start, like "-webkit-mask-image".
// But HTML attribute names can't have those characters, and we should not
// even parse them inside attr().
if (attrName[0] == '-')
return false;
if (document()->isHTMLDocument())
attrName = attrName.lower();
parsedValue = new CSSPrimitiveValue(attrName, CSSPrimitiveValue::CSS_ATTR);
} else if (equalIgnoringCase(val->function->name, "counter(")) {
parsedValue = parseCounterContent(args, false);
if (!parsedValue)
return false;
} else if (equalIgnoringCase(val->function->name, "counters(")) {
parsedValue = parseCounterContent(args, true);
if (!parsedValue)
return false;
} else if (equalIgnoringCase(val->function->name, "-webkit-gradient(")) {
if (!parseGradient(parsedValue))
return false;
} else if (equalIgnoringCase(val->function->name, "-webkit-canvas(")) {
if (!parseCanvas(parsedValue))
return false;
} else
return false;
} else if (val->unit == CSSPrimitiveValue::CSS_IDENT) {
// open-quote
// close-quote
// no-open-quote
// no-close-quote
// FIXME: These are not yet implemented (http://bugs.webkit.org/show_bug.cgi?id=6503).
} else if (val->unit == CSSPrimitiveValue::CSS_STRING) {
parsedValue = new CSSPrimitiveValue(val->string, CSSPrimitiveValue::CSS_STRING);
}
if (!parsedValue)
break;
values->append(parsedValue.release());
m_valueList->next();
}
if (values->length()) {
addProperty(propId, values.release(), important);
m_valueList->next();
return true;
}
return false;
}
PassRefPtr<CSSValue> CSSParser::parseBackgroundColor()
{
int id = m_valueList->current()->id;
if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu || id == CSSValueCurrentcolor ||
(id >= CSSValueGrey && id < CSSValueWebkitText && !m_strict))
return new CSSPrimitiveValue(id);
return parseColor();
}
bool CSSParser::parseFillImage(RefPtr<CSSValue>& value)
{
if (m_valueList->current()->id == CSSValueNone) {
value = CSSImageValue::create();
return true;
}
if (m_valueList->current()->unit == CSSPrimitiveValue::CSS_URI) {
String uri = parseURL(m_valueList->current()->string);
if (!uri.isNull())
value = CSSImageValue::create(KURL(m_styleSheet->baseURL(), uri).string());
return true;
}
if (m_valueList->current()->unit == Value::Function) {
if (equalIgnoringCase(m_valueList->current()->function->name, "-webkit-gradient("))
return parseGradient(value);
if (equalIgnoringCase(m_valueList->current()->function->name, "-webkit-canvas("))
return parseCanvas(value);
}
return false;
}
PassRefPtr<CSSValue> CSSParser::parseFillPositionXY(bool& xFound, bool& yFound)
{
int id = m_valueList->current()->id;
if (id == CSSValueLeft || id == CSSValueTop || id == CSSValueRight || id == CSSValueBottom || id == CSSValueCenter) {
int percent = 0;
if (id == CSSValueLeft || id == CSSValueRight) {
if (xFound)
return 0;
xFound = true;
if (id == CSSValueRight)
percent = 100;
}
else if (id == CSSValueTop || id == CSSValueBottom) {
if (yFound)
return 0;
yFound = true;
if (id == CSSValueBottom)
percent = 100;
}
else if (id == CSSValueCenter)
// Center is ambiguous, so we're not sure which position we've found yet, an x or a y.
percent = 50;
return new CSSPrimitiveValue(percent, CSSPrimitiveValue::CSS_PERCENTAGE);
}
if (validUnit(m_valueList->current(), FPercent|FLength, m_strict))
return new CSSPrimitiveValue(m_valueList->current()->fValue,
(CSSPrimitiveValue::UnitTypes)m_valueList->current()->unit);
return 0;
}
void CSSParser::parseFillPosition(RefPtr<CSSValue>& value1, RefPtr<CSSValue>& value2)
{
Value* value = m_valueList->current();
// Parse the first value. We're just making sure that it is one of the valid keywords or a percentage/length.
bool value1IsX = false, value1IsY = false;
value1 = parseFillPositionXY(value1IsX, value1IsY);
if (!value1)
return;
// It only takes one value for background-position to be correctly parsed if it was specified in a shorthand (since we
// can assume that any other values belong to the rest of the shorthand). If we're not parsing a shorthand, though, the
// value was explicitly specified for our property.
value = m_valueList->next();
// First check for the comma. If so, we are finished parsing this value or value pair.
if (value && value->unit == Value::Operator && value->iValue == ',')
value = 0;
bool value2IsX = false, value2IsY = false;
if (value) {
value2 = parseFillPositionXY(value2IsX, value2IsY);
if (value2)
m_valueList->next();
else {
if (!inShorthand()) {
value1.clear();
return;
}
}
}
if (!value2)
// Only one value was specified. If that value was not a keyword, then it sets the x position, and the y position
// is simply 50%. This is our default.
// For keywords, the keyword was either an x-keyword (left/right), a y-keyword (top/bottom), or an ambiguous keyword (center).
// For left/right/center, the default of 50% in the y is still correct.
value2 = new CSSPrimitiveValue(50, CSSPrimitiveValue::CSS_PERCENTAGE);
if (value1IsY || value2IsX)
value1.swap(value2);
}
PassRefPtr<CSSValue> CSSParser::parseFillSize()
{
Value* value = m_valueList->current();
CSSPrimitiveValue* parsedValue1;
if (value->id == CSSValueAuto)
parsedValue1 = new CSSPrimitiveValue(0, CSSPrimitiveValue::CSS_UNKNOWN);
else {
if (!validUnit(value, FLength|FPercent, m_strict))
return 0;
parsedValue1 = new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
}
CSSPrimitiveValue* parsedValue2 = parsedValue1;
if ((value = m_valueList->next())) {
if (value->id == CSSValueAuto)
parsedValue2 = new CSSPrimitiveValue(0, CSSPrimitiveValue::CSS_UNKNOWN);
else {
if (!validUnit(value, FLength|FPercent, m_strict)) {
delete parsedValue1;
return 0;
}
parsedValue2 = new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
}
}
RefPtr<Pair> pair = Pair::create(parsedValue1, parsedValue2);
return new CSSPrimitiveValue(pair.release());
}
bool CSSParser::parseFillProperty(int propId, int& propId1, int& propId2,
RefPtr<CSSValue>& retValue1, RefPtr<CSSValue>& retValue2)
{
RefPtr<CSSValueList> values;
RefPtr<CSSValueList> values2;
Value* val;
RefPtr<CSSValue> value;
RefPtr<CSSValue> value2;
bool allowComma = false;
retValue1 = retValue2 = 0;
propId1 = propId;
propId2 = propId;
if (propId == CSSPropertyBackgroundPosition) {
propId1 = CSSPropertyBackgroundPositionX;
propId2 = CSSPropertyBackgroundPositionY;
} else if (propId == CSSPropertyWebkitMaskPosition) {
propId1 = CSSPropertyWebkitMaskPositionX;
propId2 = CSSPropertyWebkitMaskPositionY;
}
while ((val = m_valueList->current())) {
RefPtr<CSSValue> currValue;
RefPtr<CSSValue> currValue2;
if (allowComma) {
if (val->unit != Value::Operator || val->iValue != ',')
return false;
m_valueList->next();
allowComma = false;
} else {
switch (propId) {
case CSSPropertyBackgroundColor:
currValue = parseBackgroundColor();
if (currValue)
m_valueList->next();
break;
case CSSPropertyBackgroundAttachment:
case CSSPropertyWebkitMaskAttachment:
if (val->id == CSSValueScroll || val->id == CSSValueFixed) {
currValue = new CSSPrimitiveValue(val->id);
m_valueList->next();
}
break;
case CSSPropertyBackgroundImage:
case CSSPropertyWebkitMaskImage:
if (parseFillImage(currValue))
m_valueList->next();
break;
case CSSPropertyWebkitBackgroundClip:
case CSSPropertyWebkitBackgroundOrigin:
case CSSPropertyWebkitMaskClip:
case CSSPropertyWebkitMaskOrigin:
if (val->id == CSSValueBorder || val->id == CSSValuePadding || val->id == CSSValueContent || val->id == CSSValueText) {
currValue = new CSSPrimitiveValue(val->id);
m_valueList->next();
}
break;
case CSSPropertyBackgroundPosition:
case CSSPropertyWebkitMaskPosition:
parseFillPosition(currValue, currValue2);
// unlike the other functions, parseFillPosition advances the m_valueList pointer
break;
case CSSPropertyBackgroundPositionX:
case CSSPropertyWebkitMaskPositionX: {
bool xFound = false, yFound = true;
currValue = parseFillPositionXY(xFound, yFound);
if (currValue)
m_valueList->next();
break;
}
case CSSPropertyBackgroundPositionY:
case CSSPropertyWebkitMaskPositionY: {
bool xFound = true, yFound = false;
currValue = parseFillPositionXY(xFound, yFound);
if (currValue)
m_valueList->next();
break;
}
case CSSPropertyWebkitBackgroundComposite:
case CSSPropertyWebkitMaskComposite:
if ((val->id >= CSSValueClear && val->id <= CSSValuePlusLighter) || val->id == CSSValueHighlight) {
currValue = new CSSPrimitiveValue(val->id);
m_valueList->next();
}
break;
case CSSPropertyBackgroundRepeat:
case CSSPropertyWebkitMaskRepeat:
if (val->id >= CSSValueRepeat && val->id <= CSSValueNoRepeat) {
currValue = new CSSPrimitiveValue(val->id);
m_valueList->next();
}
break;
case CSSPropertyWebkitBackgroundSize:
case CSSPropertyWebkitMaskSize:
currValue = parseFillSize();
if (currValue)
m_valueList->next();
break;
}
if (!currValue)
return false;
if (value && !values) {
values = new CSSValueList();
values->append(value.release());
}
if (value2 && !values2) {
values2 = new CSSValueList();
values2->append(value2.release());
}
if (values)
values->append(currValue.release());
else
value = currValue.release();
if (currValue2) {
if (values2)
values2->append(currValue2.release());
else
value2 = currValue2.release();
}
allowComma = true;
}
// When parsing any fill shorthand property, we let it handle building up the lists for all
// properties.
if (inShorthand())
break;
}
if (values && values->length()) {
retValue1 = values.release();
if (values2 && values2->length())
retValue2 = values2.release();
return true;
}
if (value) {
retValue1 = value.release();
retValue2 = value2.release();
return true;
}
return false;
}
PassRefPtr<CSSValue> CSSParser::parseTransitionDuration()
{
Value* value = m_valueList->current();
if (validUnit(value, FTime, m_strict))
return new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
return 0;
}
PassRefPtr<CSSValue> CSSParser::parseTransitionRepeatCount()
{
Value* value = m_valueList->current();
if (value->id == CSSValueInfinite)
return new CSSPrimitiveValue(value->id);
if (validUnit(value, FInteger|FNonNeg, m_strict))
return new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
return 0;
}
bool CSSParser::parseTimingFunctionValue(ValueList*& args, double& result)
{
Value* v = args->current();
if (!validUnit(v, FNumber, m_strict))
return false;
result = v->fValue;
if (result < 0 || result > 1.0)
return false;
v = args->next();
if (!v)
// The last number in the function has no comma after it, so we're done.
return true;
if (v->unit != Value::Operator && v->iValue != ',')
return false;
v = args->next();
return true;
}
PassRefPtr<CSSValue> CSSParser::parseTransitionTimingFunction()
{
Value* value = m_valueList->current();
if (value->id == CSSValueEase || value->id == CSSValueLinear || value->id == CSSValueEaseIn || value->id == CSSValueEaseOut || value->id == CSSValueEaseInOut)
return new CSSPrimitiveValue(value->id);
// We must be a function.
if (value->unit != Value::Function)
return 0;
// The only timing function we accept for now is a cubic bezier function. 4 points must be specified.
ValueList* args = value->function->args;
if (!equalIgnoringCase(value->function->name, "cubic-bezier(") || !args || args->size() != 7)
return 0;
// There are two points specified. The values must be between 0 and 1.
double x1, y1, x2, y2;
if (!parseTimingFunctionValue(args, x1))
return 0;
if (!parseTimingFunctionValue(args, y1))
return 0;
if (!parseTimingFunctionValue(args, x2))
return 0;
if (!parseTimingFunctionValue(args, y2))
return 0;
return new CSSTimingFunctionValue(x1, y1, x2, y2);
}
PassRefPtr<CSSValue> CSSParser::parseTransitionProperty()
{
Value* value = m_valueList->current();
if (value->unit != CSSPrimitiveValue::CSS_IDENT)
return 0;
int result = cssPropertyID(value->string);
if (result)
return new CSSPrimitiveValue(result);
if (equalIgnoringCase(value->string, "all"))
return new CSSPrimitiveValue(cAnimateAll);
if (equalIgnoringCase(value->string, "none"))
return new CSSPrimitiveValue(cAnimateNone);
return 0;
}
bool CSSParser::parseTransitionProperty(int propId, RefPtr<CSSValue>& result)
{
RefPtr<CSSValueList> values;
Value* val;
RefPtr<CSSValue> value;
bool allowComma = false;
result = 0;
while ((val = m_valueList->current())) {
RefPtr<CSSValue> currValue;
if (allowComma) {
if (val->unit != Value::Operator || val->iValue != ',')
return false;
m_valueList->next();
allowComma = false;
}
else {
switch (propId) {
case CSSPropertyWebkitTransitionDuration:
currValue = parseTransitionDuration();
if (currValue)
m_valueList->next();
break;
case CSSPropertyWebkitTransitionRepeatCount:
currValue = parseTransitionRepeatCount();
if (currValue)
m_valueList->next();
break;
case CSSPropertyWebkitTransitionTimingFunction:
currValue = parseTransitionTimingFunction();
if (currValue)
m_valueList->next();
break;
case CSSPropertyWebkitTransitionProperty:
currValue = parseTransitionProperty();
if (currValue)
m_valueList->next();
break;
}
if (!currValue)
return false;
if (value && !values) {
values = new CSSValueList();
values->append(value.release());
}
if (values)
values->append(currValue.release());
else
value = currValue.release();
allowComma = true;
}
// When parsing the 'transition' shorthand property, we let it handle building up the lists for all
// properties.
if (inShorthand())
break;
}
if (values && values->length()) {
result = values.release();
return true;
}
if (value) {
result = value.release();
return true;
}
return false;
}
#if ENABLE(DASHBOARD_SUPPORT)
#define DASHBOARD_REGION_NUM_PARAMETERS 6
#define DASHBOARD_REGION_SHORT_NUM_PARAMETERS 2
static Value *skipCommaInDashboardRegion (ValueList *args)
{
if (args->size() == (DASHBOARD_REGION_NUM_PARAMETERS*2-1) ||
args->size() == (DASHBOARD_REGION_SHORT_NUM_PARAMETERS*2-1)) {
Value *current = args->current();
if (current->unit == Value::Operator && current->iValue == ',')
return args->next();
}
return args->current();
}
bool CSSParser::parseDashboardRegions(int propId, bool important)
{
bool valid = true;
Value *value = m_valueList->current();
if (value->id == CSSValueNone) {
if (m_valueList->next())
return false;
addProperty(propId, new CSSPrimitiveValue(value->id), important);
return valid;
}
RefPtr<DashboardRegion> firstRegion = DashboardRegion::create();
DashboardRegion* region = 0;
while (value) {
if (region == 0) {
region = firstRegion.get();
} else {
RefPtr<DashboardRegion> nextRegion = DashboardRegion::create();
region->m_next = nextRegion;
region = nextRegion.get();
}
if (value->unit != Value::Function) {
valid = false;
break;
}
// Commas count as values, so allow:
// dashboard-region(label, type, t, r, b, l) or dashboard-region(label type t r b l)
// dashboard-region(label, type, t, r, b, l) or dashboard-region(label type t r b l)
// also allow
// dashboard-region(label, type) or dashboard-region(label type)
// dashboard-region(label, type) or dashboard-region(label type)
ValueList* args = value->function->args;
if (!equalIgnoringCase(value->function->name, "dashboard-region(") || !args) {
valid = false;
break;
}
int numArgs = args->size();
if ((numArgs != DASHBOARD_REGION_NUM_PARAMETERS && numArgs != (DASHBOARD_REGION_NUM_PARAMETERS*2-1)) &&
(numArgs != DASHBOARD_REGION_SHORT_NUM_PARAMETERS && numArgs != (DASHBOARD_REGION_SHORT_NUM_PARAMETERS*2-1))){
valid = false;
break;
}
// First arg is a label.
Value* arg = args->current();
if (arg->unit != CSSPrimitiveValue::CSS_IDENT) {
valid = false;
break;
}
region->m_label = arg->string;
// Second arg is a type.
arg = args->next();
arg = skipCommaInDashboardRegion (args);
if (arg->unit != CSSPrimitiveValue::CSS_IDENT) {
valid = false;
break;
}
if (equalIgnoringCase(arg->string, "circle"))
region->m_isCircle = true;
else if (equalIgnoringCase(arg->string, "rectangle"))
region->m_isRectangle = true;
else {
valid = false;
break;
}
region->m_geometryType = arg->string;
if (numArgs == DASHBOARD_REGION_SHORT_NUM_PARAMETERS || numArgs == (DASHBOARD_REGION_SHORT_NUM_PARAMETERS*2-1)) {
// This originally used CSSValueInvalid by accident. It might be more logical to use something else.
CSSPrimitiveValue *amount = new CSSPrimitiveValue(CSSValueInvalid);
region->setTop(amount);
region->setRight(amount);
region->setBottom(amount);
region->setLeft(amount);
}
else {
// Next four arguments must be offset numbers
int i;
for (i = 0; i < 4; i++) {
arg = args->next();
arg = skipCommaInDashboardRegion (args);
valid = arg->id == CSSValueAuto || validUnit(arg, FLength, m_strict);
if (!valid)
break;
CSSPrimitiveValue *amount = arg->id == CSSValueAuto ?
new CSSPrimitiveValue(CSSValueAuto) :
new CSSPrimitiveValue(arg->fValue, (CSSPrimitiveValue::UnitTypes) arg->unit);
if (i == 0)
region->setTop(amount);
else if (i == 1)
region->setRight(amount);
else if (i == 2)
region->setBottom(amount);
else
region->setLeft(amount);
}
}
if (args->next())
return false;
value = m_valueList->next();
}
if (valid)
addProperty(propId, new CSSPrimitiveValue(firstRegion.release()), important);
return valid;
}
#endif /* ENABLE(DASHBOARD_SUPPORT) */
PassRefPtr<CSSValue> CSSParser::parseCounterContent(ValueList* args, bool counters)
{
unsigned numArgs = args->size();
if (counters && numArgs != 3 && numArgs != 5)
return 0;
if (!counters && numArgs != 1 && numArgs != 3)
return 0;
Value* i = args->current();
RefPtr<CSSPrimitiveValue> identifier = new CSSPrimitiveValue(i->string, CSSPrimitiveValue::CSS_STRING);
RefPtr<CSSPrimitiveValue> separator;
if (!counters)
separator = new CSSPrimitiveValue(String(), CSSPrimitiveValue::CSS_STRING);
else {
i = args->next();
if (i->unit != Value::Operator || i->iValue != ',')
return 0;
i = args->next();
if (i->unit != CSSPrimitiveValue::CSS_STRING)
return 0;
separator = new CSSPrimitiveValue(i->string, (CSSPrimitiveValue::UnitTypes) i->unit);
}
RefPtr<CSSPrimitiveValue> listStyle;
i = args->next();
if (!i) // Make the list style default decimal
listStyle = new CSSPrimitiveValue(CSSValueDecimal - CSSValueDisc, CSSPrimitiveValue::CSS_NUMBER);
else {
if (i->unit != Value::Operator || i->iValue != ',')
return 0;
i = args->next();
if (i->unit != CSSPrimitiveValue::CSS_IDENT)
return 0;
short ls = 0;
if (i->id == CSSValueNone)
ls = CSSValueKatakanaIroha - CSSValueDisc + 1;
else if (i->id >= CSSValueDisc && i->id <= CSSValueKatakanaIroha)
ls = i->id - CSSValueDisc;
else
return 0;
listStyle = new CSSPrimitiveValue(ls, (CSSPrimitiveValue::UnitTypes) i->unit);
}
return new CSSPrimitiveValue(Counter::create(identifier.release(), listStyle.release(), separator.release()));
}
bool CSSParser::parseShape(int propId, bool important)
{
Value* value = m_valueList->current();
ValueList* args = value->function->args;
if (!equalIgnoringCase(value->function->name, "rect(") || !args)
return false;
// rect(t, r, b, l) || rect(t r b l)
if (args->size() != 4 && args->size() != 7)
return false;
RefPtr<Rect> rect = Rect::create();
bool valid = true;
int i = 0;
Value *a = args->current();
while (a) {
valid = a->id == CSSValueAuto || validUnit(a, FLength, m_strict);
if (!valid)
break;
CSSPrimitiveValue *length = a->id == CSSValueAuto ?
new CSSPrimitiveValue(CSSValueAuto) :
new CSSPrimitiveValue(a->fValue, (CSSPrimitiveValue::UnitTypes) a->unit);
if (i == 0)
rect->setTop(length);
else if (i == 1)
rect->setRight(length);
else if (i == 2)
rect->setBottom(length);
else
rect->setLeft(length);
a = args->next();
if (a && args->size() == 7) {
if (a->unit == Value::Operator && a->iValue == ',') {
a = args->next();
} else {
valid = false;
break;
}
}
i++;
}
if (valid) {
addProperty(propId, new CSSPrimitiveValue(rect.release()), important);
m_valueList->next();
return true;
}
return false;
}
// [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]? 'font-family'
bool CSSParser::parseFont(bool important)
{
bool valid = true;
Value *value = m_valueList->current();
RefPtr<FontValue> font = new FontValue;
// optional font-style, font-variant and font-weight
while (value) {
int id = value->id;
if (id) {
if (id == CSSValueNormal) {
// do nothing, it's the inital value for all three
} else if (id == CSSValueItalic || id == CSSValueOblique) {
if (font->style)
return false;
font->style = new CSSPrimitiveValue(id);
} else if (id == CSSValueSmallCaps) {
if (font->variant)
return false;
font->variant = new CSSPrimitiveValue(id);
} else if (id >= CSSValueBold && id <= CSSValueLighter) {
if (font->weight)
return false;
font->weight = new CSSPrimitiveValue(id);
} else {
valid = false;
}
} else if (!font->weight && validUnit(value, FInteger|FNonNeg, true)) {
int weight = (int)value->fValue;
int val = 0;
if (weight == 100)
val = CSSValue100;
else if (weight == 200)
val = CSSValue200;
else if (weight == 300)
val = CSSValue300;
else if (weight == 400)
val = CSSValue400;
else if (weight == 500)
val = CSSValue500;
else if (weight == 600)
val = CSSValue600;
else if (weight == 700)
val = CSSValue700;
else if (weight == 800)
val = CSSValue800;
else if (weight == 900)
val = CSSValue900;
if (val)
font->weight = new CSSPrimitiveValue(val);
else
valid = false;
} else {
valid = false;
}
if (!valid)
break;
value = m_valueList->next();
}
if (!value)
return false;
// set undefined values to default
if (!font->style)
font->style = new CSSPrimitiveValue(CSSValueNormal);
if (!font->variant)
font->variant = new CSSPrimitiveValue(CSSValueNormal);
if (!font->weight)
font->weight = new CSSPrimitiveValue(CSSValueNormal);
// now a font size _must_ come
// <absolute-size> | <relative-size> | <length> | <percentage> | inherit
if (value->id >= CSSValueXxSmall && value->id <= CSSValueLarger)
font->size = new CSSPrimitiveValue(value->id);
else if (validUnit(value, FLength|FPercent|FNonNeg, m_strict))
font->size = new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit);
value = m_valueList->next();
if (!font->size || !value)
return false;
if (value->unit == Value::Operator && value->iValue == '/') {
// line-height
value = m_valueList->next();
if (!value)
return false;
if (value->id == CSSValueNormal) {
// default value, nothing to do
} else if (validUnit(value, FNumber|FLength|FPercent|FNonNeg, m_strict))
font->lineHeight = new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit);
else
return false;
value = m_valueList->next();
if (!value)
return false;
}
if (!font->lineHeight)
font->lineHeight = new CSSPrimitiveValue(CSSValueNormal);
// font family must come now
font->family = parseFontFamily();
if (m_valueList->current() || !font->family)
return false;
addProperty(CSSPropertyFont, font.release(), important);
return true;
}
PassRefPtr<CSSValueList> CSSParser::parseFontFamily()
{
CSSValueList* list = new CSSValueList;
Value* value = m_valueList->current();
FontFamilyValue* currFamily = 0;
while (value) {
Value* nextValue = m_valueList->next();
bool nextValBreaksFont = !nextValue ||
(nextValue->unit == Value::Operator && nextValue->iValue == ',');
bool nextValIsFontName = nextValue &&
((nextValue->id >= CSSValueSerif && nextValue->id <= CSSValueWebkitBody) ||
(nextValue->unit == CSSPrimitiveValue::CSS_STRING || nextValue->unit == CSSPrimitiveValue::CSS_IDENT));
if (value->id >= CSSValueSerif && value->id <= CSSValueWebkitBody) {
if (currFamily)
currFamily->appendSpaceSeparated(value->string.characters, value->string.length);
else if (nextValBreaksFont || !nextValIsFontName)
list->append(new CSSPrimitiveValue(value->id));
else
list->append(currFamily = new FontFamilyValue(value->string));
}
else if (value->unit == CSSPrimitiveValue::CSS_STRING) {
// Strings never share in a family name.
currFamily = 0;
list->append(new FontFamilyValue(value->string));
}
else if (value->unit == CSSPrimitiveValue::CSS_IDENT) {
if (currFamily)
currFamily->appendSpaceSeparated(value->string.characters, value->string.length);
else if (nextValBreaksFont || !nextValIsFontName)
list->append(new FontFamilyValue(value->string));
else
list->append(currFamily = new FontFamilyValue(value->string));
}
else {
break;
}
if (!nextValue)
break;
if (nextValBreaksFont) {
value = m_valueList->next();
currFamily = 0;
}
else if (nextValIsFontName)
value = nextValue;
else
break;
}
if (!list->length()) {
delete list;
list = 0;
}
return list;
}
bool CSSParser::parseFontFaceSrc()
{
RefPtr<CSSValueList> values(new CSSValueList());
Value* val;
bool expectComma = false;
bool allowFormat = false;
bool failed = false;
RefPtr<CSSFontFaceSrcValue> uriValue;
while ((val = m_valueList->current())) {
RefPtr<CSSFontFaceSrcValue> parsedValue;
if (val->unit == CSSPrimitiveValue::CSS_URI && !expectComma) {
String value = parseURL(val->string);
parsedValue = new CSSFontFaceSrcValue(KURL(m_styleSheet->baseURL(), value).string(), false);
uriValue = parsedValue;
allowFormat = true;
expectComma = true;
} else if (val->unit == Value::Function) {
// There are two allowed functions: local() and format().
ValueList* args = val->function->args;
if (args && args->size() == 1) {
if (equalIgnoringCase(val->function->name, "local(") && !expectComma) {
expectComma = true;
allowFormat = false;
Value* a = args->current();
uriValue.clear();
parsedValue = new CSSFontFaceSrcValue(a->string, true);
} else if (equalIgnoringCase(val->function->name, "format(") && allowFormat && uriValue) {
expectComma = true;
allowFormat = false;
uriValue->setFormat(args->current()->string);
uriValue.clear();
m_valueList->next();
continue;
}
}
} else if (val->unit == Value::Operator && val->iValue == ',' && expectComma) {
expectComma = false;
allowFormat = false;
uriValue.clear();
m_valueList->next();
continue;
}
if (parsedValue)
values->append(parsedValue.release());
else {
failed = true;
break;
}
m_valueList->next();
}
if (values->length() && !failed) {
addProperty(CSSPropertySrc, values.release(), m_important);
m_valueList->next();
return true;
}
return false;
}
bool CSSParser::parseFontFaceUnicodeRange()
{
CSSValueList* values = new CSSValueList();
Value* currentValue;
bool failed = false;
while ((currentValue = m_valueList->current())) {
if (m_valueList->current()->unit != CSSPrimitiveValue::CSS_UNICODE_RANGE) {
failed = true;
break;
}
String rangeString = m_valueList->current()->string;
UChar32 from = 0;
UChar32 to = 0;
unsigned length = rangeString.length();
if (length < 3) {
failed = true;
break;
}
unsigned i = 2;
while (i < length) {
UChar c = rangeString[i];
if (c == '-' || c == '?')
break;
from *= 16;
if (c >= '0' && c <= '9')
from += c - '0';
else if (c >= 'A' && c <= 'F')
from += 10 + c - 'A';
else if (c >= 'a' && c <= 'f')
from += 10 + c - 'a';
else {
failed = true;
break;
}
i++;
}
if (failed)
break;
if (i == length)
to = from;
else if (rangeString[i] == '?') {
unsigned span = 1;
while (i < length && rangeString[i] == '?') {
span *= 16;
from *= 16;
i++;
}
if (i < length)
failed = true;
to = from + span - 1;
} else {
if (length < i + 2) {
failed = true;
break;
}
i++;
while (i < length) {
UChar c = rangeString[i];
to *= 16;
if (c >= '0' && c <= '9')
to += c - '0';
else if (c >= 'A' && c <= 'F')
to += 10 + c - 'A';
else if (c >= 'a' && c <= 'f')
to += 10 + c - 'a';
else {
failed = true;
break;
}
i++;
}
if (failed)
break;
}
values->append(new CSSUnicodeRangeValue(from, to));
m_valueList->next();
}
if (failed || !values->length()) {
delete values;
return false;
}
addProperty(CSSPropertyUnicodeRange, values, m_important);
return true;
}
bool CSSParser::parseColor(const String &name, RGBA32& rgb, bool strict)
{
if (!strict && Color::parseHexColor(name, rgb))
return true;
// try a little harder
Color tc;
tc.setNamedColor(name);
if (tc.isValid()) {
rgb = tc.rgb();
return true;
}
return false;
}
bool CSSParser::parseColorParameters(Value* value, int* colorArray, bool parseAlpha)
{
ValueList* args = value->function->args;
Value* v = args->current();
Units unitType = FUnknown;
// Get the first value and its type
if (validUnit(v, FInteger, true))
unitType = FInteger;
else if (validUnit(v, FPercent, true))
unitType = FPercent;
else
return false;
colorArray[0] = static_cast<int>(v->fValue * (v->unit == CSSPrimitiveValue::CSS_PERCENTAGE ? 256.0 / 100.0 : 1.0));
for (int i = 1; i < 3; i++) {
v = args->next();
if (v->unit != Value::Operator && v->iValue != ',')
return false;
v = args->next();
if (!validUnit(v, unitType, true))
return false;
colorArray[i] = static_cast<int>(v->fValue * (v->unit == CSSPrimitiveValue::CSS_PERCENTAGE ? 256.0 / 100.0 : 1.0));
}
if (parseAlpha) {
v = args->next();
if (v->unit != Value::Operator && v->iValue != ',')
return false;
v = args->next();
if (!validUnit(v, FNumber, true))
return false;
colorArray[3] = static_cast<int>(max(0.0, min(1.0, v->fValue)) * 255);
}
return true;
}
// CSS3 sepcification defines the format of a HSL color as
// hsl(<number>, <percent>, <percent>)
// and with alpha, the format is
// hsla(<number>, <percent>, <percent>, <number>)
// The first value, HUE, is in an angle with a value between 0 and 360
bool CSSParser::parseHSLParameters(Value* value, double* colorArray, bool parseAlpha)
{
ValueList* args = value->function->args;
Value* v = args->current();
// Get the first value
if (!validUnit(v, FNumber, true))
return false;
// normalize the Hue value and change it to be between 0 and 1.0
colorArray[0] = (((static_cast<int>(v->fValue) % 360) + 360) % 360) / 360.0;
for (int i = 1; i < 3; i++) {
v = args->next();
if (v->unit != Value::Operator && v->iValue != ',')
return false;
v = args->next();
if (!validUnit(v, FPercent, true))
return false;
colorArray[i] = max(0.0, min(100.0, v->fValue)) / 100.0; // needs to be value between 0 and 1.0
}
if (parseAlpha) {
v = args->next();
if (v->unit != Value::Operator && v->iValue != ',')
return false;
v = args->next();
if (!validUnit(v, FNumber, true))
return false;
colorArray[3] = max(0.0, min(1.0, v->fValue));
}
return true;
}
PassRefPtr<CSSPrimitiveValue> CSSParser::parseColor(Value* value)
{
RGBA32 c = Color::transparent;
if (!parseColorFromValue(value ? value : m_valueList->current(), c))
return 0;
return new CSSPrimitiveValue(c);
}
bool CSSParser::parseColorFromValue(Value* value, RGBA32& c, bool svg)
{
if (!m_strict && value->unit == CSSPrimitiveValue::CSS_NUMBER &&
value->fValue >= 0. && value->fValue < 1000000.) {
String str = String::format("%06d", (int)(value->fValue+.5));
if (!CSSParser::parseColor(str, c, m_strict))
return false;
} else if (value->unit == CSSPrimitiveValue::CSS_RGBCOLOR ||
value->unit == CSSPrimitiveValue::CSS_IDENT ||
(!m_strict && value->unit == CSSPrimitiveValue::CSS_DIMENSION)) {
if (!CSSParser::parseColor(value->string, c, m_strict && value->unit == CSSPrimitiveValue::CSS_IDENT))
return false;
} else if (value->unit == Value::Function &&
value->function->args != 0 &&
value->function->args->size() == 5 /* rgb + two commas */ &&
equalIgnoringCase(value->function->name, "rgb(")) {
int colorValues[3];
if (!parseColorParameters(value, colorValues, false))
return false;
c = makeRGB(colorValues[0], colorValues[1], colorValues[2]);
} else if (!svg) {
if (value->unit == Value::Function &&
value->function->args != 0 &&
value->function->args->size() == 7 /* rgba + three commas */ &&
equalIgnoringCase(value->function->name, "rgba(")) {
int colorValues[4];
if (!parseColorParameters(value, colorValues, true))
return false;
c = makeRGBA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]);
} else if (value->unit == Value::Function &&
value->function->args != 0 &&
value->function->args->size() == 5 /* hsl + two commas */ &&
equalIgnoringCase(value->function->name, "hsl(")) {
double colorValues[3];
if (!parseHSLParameters(value, colorValues, false))
return false;
c = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], 1.0);
} else if (value->unit == Value::Function &&
value->function->args != 0 &&
value->function->args->size() == 7 /* hsla + three commas */ &&
equalIgnoringCase(value->function->name, "hsla(")) {
double colorValues[4];
if (!parseHSLParameters(value, colorValues, true))
return false;
c = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]);
} else
return false;
} else
return false;
return true;
}
// This class tracks parsing state for shadow values. If it goes out of scope (e.g., due to an early return)
// without the allowBreak bit being set, then it will clean up all of the objects and destroy them.
struct ShadowParseContext {
ShadowParseContext()
: allowX(true)
, allowY(false)
, allowBlur(false)
, allowColor(true)
, allowBreak(true)
{}
bool allowLength() { return allowX || allowY || allowBlur; }
void commitValue() {
// Handle the ,, case gracefully by doing nothing.
if (x || y || blur || color) {
if (!values)
values = new CSSValueList();
// Construct the current shadow value and add it to the list.
values->append(new ShadowValue(x.release(), y.release(), blur.release(), color.release()));
}
// Now reset for the next shadow value.
x = y = blur = color = 0;
allowX = allowColor = allowBreak = true;
allowY = allowBlur = false;
}
void commitLength(Value* v) {
RefPtr<CSSPrimitiveValue> val = new CSSPrimitiveValue(v->fValue, (CSSPrimitiveValue::UnitTypes)v->unit);
if (allowX) {
x = val.release();
allowX = false; allowY = true; allowColor = false; allowBreak = false;
}
else if (allowY) {
y = val.release();
allowY = false; allowBlur = true; allowColor = true; allowBreak = true;
}
else if (allowBlur) {
blur = val.release();
allowBlur = false;
}
}
void commitColor(PassRefPtr<CSSPrimitiveValue> val) {
color = val;
allowColor = false;
if (allowX)
allowBreak = false;
else
allowBlur = false;
}
RefPtr<CSSValueList> values;
RefPtr<CSSPrimitiveValue> x;
RefPtr<CSSPrimitiveValue> y;
RefPtr<CSSPrimitiveValue> blur;
RefPtr<CSSPrimitiveValue> color;
bool allowX;
bool allowY;
bool allowBlur;
bool allowColor;
bool allowBreak;
};
bool CSSParser::parseShadow(int propId, bool important)
{
ShadowParseContext context;
Value* val;
while ((val = m_valueList->current())) {
// Check for a comma break first.
if (val->unit == Value::Operator) {
if (val->iValue != ',' || !context.allowBreak)
// Other operators aren't legal or we aren't done with the current shadow
// value. Treat as invalid.
return false;
// The value is good. Commit it.
context.commitValue();
}
// Check to see if we're a length.
else if (validUnit(val, FLength, true)) {
// We required a length and didn't get one. Invalid.
if (!context.allowLength())
return false;
// A length is allowed here. Construct the value and add it.
context.commitLength(val);
}
else {
// The only other type of value that's ok is a color value.
RefPtr<CSSPrimitiveValue> parsedColor;
bool isColor = (val->id >= CSSValueAqua && val->id <= CSSValueWindowtext || val->id == CSSValueMenu ||
(val->id >= CSSValueWebkitFocusRingColor && val->id <= CSSValueWebkitText && !m_strict));
if (isColor) {
if (!context.allowColor)
return false;
parsedColor = new CSSPrimitiveValue(val->id);
}
if (!parsedColor)
// It's not built-in. Try to parse it as a color.
parsedColor = parseColor(val);
if (!parsedColor || !context.allowColor)
return false; // This value is not a color or length and is invalid or
// it is a color, but a color isn't allowed at this point.
context.commitColor(parsedColor.release());
}
m_valueList->next();
}
if (context.allowBreak) {
context.commitValue();
if (context.values->length()) {
addProperty(propId, context.values.release(), important);
m_valueList->next();
return true;
}
}
return false;
}
bool CSSParser::parseReflect(int propId, bool important)
{
// box-reflect: <direction> <offset> <mask>
// Direction comes first.
Value* val = m_valueList->current();
CSSReflectionDirection direction;
switch (val->id) {
case CSSValueAbove:
direction = ReflectionAbove;
break;
case CSSValueBelow:
direction = ReflectionBelow;
break;
case CSSValueLeft:
direction = ReflectionLeft;
break;
case CSSValueRight:
direction = ReflectionRight;
break;
default:
return false;
}
// The offset comes next.
val = m_valueList->next();
RefPtr<CSSPrimitiveValue> offset;
if (!val)
offset = new CSSPrimitiveValue(0, CSSPrimitiveValue::CSS_PX);
else {
if (!validUnit(val, FLength | FPercent, m_strict))
return false;
offset = new CSSPrimitiveValue(val->fValue, static_cast<CSSPrimitiveValue::UnitTypes>(val->unit));
}
// Now for the mask.
RefPtr<CSSValue> mask;
val = m_valueList->next();
if (val) {
if (!parseBorderImage(propId, important, mask))
return false;
}
RefPtr<CSSReflectValue> reflectValue = CSSReflectValue::create(direction, offset.release(), mask.release());
addProperty(propId, reflectValue.release(), important);
m_valueList->next();
return true;
}
struct BorderImageParseContext
{
BorderImageParseContext()
: m_allowBreak(false)
, m_allowNumber(false)
, m_allowSlash(false)
, m_allowWidth(false)
, m_allowRule(false)
, m_borderTop(0)
, m_borderRight(0)
, m_borderBottom(0)
, m_borderLeft(0)
, m_horizontalRule(0)
, m_verticalRule(0)
{}
bool allowBreak() const { return m_allowBreak; }
bool allowNumber() const { return m_allowNumber; }
bool allowSlash() const { return m_allowSlash; }
bool allowWidth() const { return m_allowWidth; }
bool allowRule() const { return m_allowRule; }
void commitImage(PassRefPtr<CSSValue> image) { m_image = image; m_allowNumber = true; }
void commitNumber(Value* v) {
PassRefPtr<CSSPrimitiveValue> val = new CSSPrimitiveValue(v->fValue, (CSSPrimitiveValue::UnitTypes)v->unit);
if (!m_top)
m_top = val;
else if (!m_right)
m_right = val;
else if (!m_bottom)
m_bottom = val;
else {
ASSERT(!m_left);
m_left = val;
}
m_allowBreak = m_allowSlash = m_allowRule = true;
m_allowNumber = !m_left;
}
void commitSlash() { m_allowBreak = m_allowSlash = m_allowNumber = false; m_allowWidth = true; }
void commitWidth(Value* val) {
if (!m_borderTop)
m_borderTop = val;
else if (!m_borderRight)
m_borderRight = val;
else if (!m_borderBottom)
m_borderBottom = val;
else {
ASSERT(!m_borderLeft);
m_borderLeft = val;
}
m_allowBreak = m_allowRule = true;
m_allowWidth = !m_borderLeft;
}
void commitRule(int keyword) {
if (!m_horizontalRule)
m_horizontalRule = keyword;
else if (!m_verticalRule)
m_verticalRule = keyword;
m_allowRule = !m_verticalRule;
}
PassRefPtr<CSSValue> commitBorderImage(CSSParser* p, bool important) {
// We need to clone and repeat values for any omissions.
if (!m_right) {
m_right = new CSSPrimitiveValue(m_top->getDoubleValue(), (CSSPrimitiveValue::UnitTypes)m_top->primitiveType());
m_bottom = new CSSPrimitiveValue(m_top->getDoubleValue(), (CSSPrimitiveValue::UnitTypes)m_top->primitiveType());
m_left = new CSSPrimitiveValue(m_top->getDoubleValue(), (CSSPrimitiveValue::UnitTypes)m_top->primitiveType());
}
if (!m_bottom) {
m_bottom = new CSSPrimitiveValue(m_top->getDoubleValue(), (CSSPrimitiveValue::UnitTypes)m_top->primitiveType());
m_left = new CSSPrimitiveValue(m_right->getDoubleValue(), (CSSPrimitiveValue::UnitTypes)m_right->primitiveType());
}
if (!m_left)
m_left = new CSSPrimitiveValue(m_right->getDoubleValue(), (CSSPrimitiveValue::UnitTypes)m_right->primitiveType());
// Now build a rect value to hold all four of our primitive values.
RefPtr<Rect> rect = Rect::create();
rect->setTop(m_top);
rect->setRight(m_right);
rect->setBottom(m_bottom);
rect->setLeft(m_left);
// Fill in STRETCH as the default if it wasn't specified.
if (!m_horizontalRule)
m_horizontalRule = CSSValueStretch;
// The vertical rule should match the horizontal rule if unspecified.
if (!m_verticalRule)
m_verticalRule = m_horizontalRule;
// Now we have to deal with the border widths. The best way to deal with these is to actually put these values into a value
// list and then make our parsing machinery do the parsing.
if (m_borderTop) {
ValueList newList;
newList.addValue(*m_borderTop);
if (m_borderRight)
newList.addValue(*m_borderRight);
if (m_borderBottom)
newList.addValue(*m_borderBottom);
if (m_borderLeft)
newList.addValue(*m_borderLeft);
p->m_valueList = &newList;
p->parseValue(CSSPropertyBorderWidth, important);
p->m_valueList = 0;
}
// Make our new border image value now.
return new CSSBorderImageValue(m_image, rect.release(), m_horizontalRule, m_verticalRule);
}
bool m_allowBreak;
bool m_allowNumber;
bool m_allowSlash;
bool m_allowWidth;
bool m_allowRule;
RefPtr<CSSValue> m_image;
RefPtr<CSSPrimitiveValue> m_top;
RefPtr<CSSPrimitiveValue> m_right;
RefPtr<CSSPrimitiveValue> m_bottom;
RefPtr<CSSPrimitiveValue> m_left;
Value* m_borderTop;
Value* m_borderRight;
Value* m_borderBottom;
Value* m_borderLeft;
int m_horizontalRule;
int m_verticalRule;
};
bool CSSParser::parseBorderImage(int propId, bool important, RefPtr<CSSValue>& result)
{
// Look for an image initially. If the first value is not a URI, then we're done.
BorderImageParseContext context;
Value* val = m_valueList->current();
if (val->unit == CSSPrimitiveValue::CSS_URI) {
String uri = parseURL(val->string);
if (uri.isNull())
return false;
context.commitImage(CSSImageValue::create(KURL(m_styleSheet->baseURL(), uri).string()));
} else if (val->unit == Value::Function) {
RefPtr<CSSValue> value;
if ((equalIgnoringCase(val->function->name, "-webkit-gradient(") && parseGradient(value)) ||
(equalIgnoringCase(val->function->name, "-webkit-canvas(") && parseCanvas(value)))
context.commitImage(value);
else
return false;
} else
return false;
while ((val = m_valueList->next())) {
if (context.allowNumber() && validUnit(val, FInteger|FNonNeg|FPercent, true)) {
context.commitNumber(val);
} else if (propId == CSSPropertyWebkitBorderImage && context.allowSlash() && val->unit == Value::Operator && val->iValue == '/') {
context.commitSlash();
} else if (context.allowWidth() &&
(val->id == CSSValueThin || val->id == CSSValueMedium || val->id == CSSValueThick || validUnit(val, FLength, m_strict))) {
context.commitWidth(val);
} else if (context.allowRule() &&
(val->id == CSSValueStretch || val->id == CSSValueRound || val->id == CSSValueRepeat)) {
context.commitRule(val->id);
} else {
// Something invalid was encountered.
return false;
}
}
if (context.allowNumber() && propId != CSSPropertyWebkitBorderImage) {
// Allow the slices to be omitted for images that don't fit to a border. We just set the slices to be 0.
context.m_top = new CSSPrimitiveValue(0, CSSPrimitiveValue::CSS_NUMBER);
context.m_allowBreak = true;
}
if (context.allowBreak()) {
// Need to fully commit as a single value.
result = context.commitBorderImage(this, important);
return true;
}
return false;
}
bool CSSParser::parseCounter(int propId, int defaultValue, bool important)
{
enum { ID, VAL } state = ID;
RefPtr<CSSValueList> list = new CSSValueList;
RefPtr<CSSPrimitiveValue> counterName;
while (true) {
Value* val = m_valueList->current();
switch (state) {
case ID:
if (val && val->unit == CSSPrimitiveValue::CSS_IDENT) {
counterName = new CSSPrimitiveValue(val->string, CSSPrimitiveValue::CSS_STRING);
state = VAL;
m_valueList->next();
continue;
}
break;
case VAL: {
int i = defaultValue;
if (val && val->unit == CSSPrimitiveValue::CSS_NUMBER) {
i = (int)val->fValue;
m_valueList->next();
}
list->append(new CSSPrimitiveValue(Pair::create(counterName.release(),
new CSSPrimitiveValue(i, CSSPrimitiveValue::CSS_NUMBER))));
state = ID;
continue;
}
}
break;
}
if (list->length() > 0) {
addProperty(propId, list.release(), important);
return true;
}
return false;
}
static PassRefPtr<CSSPrimitiveValue> parseGradientPoint(Value* a, bool horizontal)
{
RefPtr<CSSPrimitiveValue> result;
if (a->unit == CSSPrimitiveValue::CSS_IDENT) {
if ((equalIgnoringCase(a->string, "left") && horizontal) ||
(equalIgnoringCase(a->string, "top") && !horizontal))
result = new CSSPrimitiveValue(0., CSSPrimitiveValue::CSS_PERCENTAGE);
else if ((equalIgnoringCase(a->string, "right") && horizontal) ||
(equalIgnoringCase(a->string, "bottom") && !horizontal))
result = new CSSPrimitiveValue(100., CSSPrimitiveValue::CSS_PERCENTAGE);
else if (equalIgnoringCase(a->string, "center"))
result = new CSSPrimitiveValue(50., CSSPrimitiveValue::CSS_PERCENTAGE);
} else if (a->unit == CSSPrimitiveValue::CSS_NUMBER || a->unit == CSSPrimitiveValue::CSS_PERCENTAGE)
result = new CSSPrimitiveValue(a->fValue, (CSSPrimitiveValue::UnitTypes)a->unit);
return result;
}
bool parseGradientColorStop(CSSParser* p, Value* a, CSSGradientColorStop& stop)
{
if (a->unit != Value::Function)
return false;
if (!equalIgnoringCase(a->function->name, "from(") &&
!equalIgnoringCase(a->function->name, "to(") &&
!equalIgnoringCase(a->function->name, "color-stop("))
return false;
ValueList* args = a->function->args;
if (!args)
return false;
if (equalIgnoringCase(a->function->name, "from(") ||
equalIgnoringCase(a->function->name, "to(")) {
// The "from" and "to" stops expect 1 argument.
if (args->size() != 1)
return false;
if (equalIgnoringCase(a->function->name, "from("))
stop.m_stop = 0.f;
else
stop.m_stop = 1.f;
int id = args->current()->id;
if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu)
stop.m_color =new CSSPrimitiveValue(id);
else
stop.m_color = p->parseColor(args->current());
if (!stop.m_color)
return false;
}
// The "color-stop" function expects 3 arguments.
if (equalIgnoringCase(a->function->name, "color-stop(")) {
if (args->size() != 3)
return false;
Value* stopArg = args->current();
if (stopArg->unit == CSSPrimitiveValue::CSS_PERCENTAGE)
stop.m_stop = (float)stopArg->fValue / 100.f;
else if (stopArg->unit == CSSPrimitiveValue::CSS_NUMBER)
stop.m_stop = (float)stopArg->fValue;
else
return false;
stopArg = args->next();
if (stopArg->unit != Value::Operator || stopArg->iValue != ',')
return false;
stopArg = args->next();
int id = stopArg->id;
if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu)
stop.m_color =new CSSPrimitiveValue(id);
else
stop.m_color = p->parseColor(stopArg);
if (!stop.m_color)
return false;
}
return true;
}
bool CSSParser::parseGradient(RefPtr<CSSValue>& gradient)
{
RefPtr<CSSGradientValue> result = new CSSGradientValue;
// Walk the arguments.
ValueList* args = m_valueList->current()->function->args;
if (!args || args->size() == 0)
return false;
// The first argument is the gradient type. It is an identifier.
Value* a = args->current();
if (!a || a->unit != CSSPrimitiveValue::CSS_IDENT)
return false;
if (equalIgnoringCase(a->string, "linear"))
result->setType(CSSLinearGradient);
else if (equalIgnoringCase(a->string, "radial"))
result->setType(CSSRadialGradient);
else
return false;
// Comma.
a = args->next();
if (!a || a->unit != Value::Operator || a->iValue != ',')
return false;
// Next comes the starting point for the gradient as an x y pair. There is no
// comma between the x and the y values.
// First X. It can be left, right, number or percent.
a = args->next();
if (!a)
return false;
RefPtr<CSSPrimitiveValue> point = parseGradientPoint(a, true);
if (!point)
return false;
result->setFirstX(point.release());
// First Y. It can be top, bottom, number or percent.
a = args->next();
if (!a)
return false;
point = parseGradientPoint(a, false);
if (!point)
return false;
result->setFirstY(point.release());
// Comma after the first point.
a = args->next();
if (!a || a->unit != Value::Operator || a->iValue != ',')
return false;
// For radial gradients only, we now expect a numeric radius.
if (result->type() == CSSRadialGradient) {
a = args->next();
if (!a || a->unit != CSSPrimitiveValue::CSS_NUMBER)
return false;
result->setFirstRadius(new CSSPrimitiveValue(a->fValue, CSSPrimitiveValue::CSS_NUMBER));
// Comma after the first radius.
a = args->next();
if (!a || a->unit != Value::Operator || a->iValue != ',')
return false;
}
// Next is the ending point for the gradient as an x, y pair.
// Second X. It can be left, right, number or percent.
a = args->next();
if (!a)
return false;
point = parseGradientPoint(a, true);
if (!point)
return false;
result->setSecondX(point.release());
// Second Y. It can be top, bottom, number or percent.
a = args->next();
if (!a)
return false;
point = parseGradientPoint(a, false);
if (!point)
return false;
result->setSecondY(point.release());
// For radial gradients only, we now expect the second radius.
if (result->type() == CSSRadialGradient) {
// Comma after the second point.
a = args->next();
if (!a || a->unit != Value::Operator || a->iValue != ',')
return false;
a = args->next();
if (!a || a->unit != CSSPrimitiveValue::CSS_NUMBER)
return false;
result->setSecondRadius(new CSSPrimitiveValue(a->fValue, CSSPrimitiveValue::CSS_NUMBER));
}
// We now will accept any number of stops (0 or more).
a = args->next();
while (a) {
// Look for the comma before the next stop.
if (a->unit != Value::Operator || a->iValue != ',')
return false;
// Now examine the stop itself.
a = args->next();
if (!a)
return false;
// The function name needs to be one of "from", "to", or "color-stop."
CSSGradientColorStop stop;
if (!parseGradientColorStop(this, a, stop))
return false;
result->addStop(stop);
// Advance
a = args->next();
}
gradient = result.release();
return true;
}
bool CSSParser::parseCanvas(RefPtr<CSSValue>& canvas)
{
RefPtr<CSSCanvasValue> result = new CSSCanvasValue;
// Walk the arguments.
ValueList* args = m_valueList->current()->function->args;
if (!args || args->size() != 1)
return false;
// The first argument is the canvas name. It is an identifier.
Value* a = args->current();
if (!a || a->unit != CSSPrimitiveValue::CSS_IDENT)
return false;
result->setName(a->string);
canvas = result;
return true;
}
class TransformOperationInfo {
public:
TransformOperationInfo(const ParseString& name)
: m_type(CSSTransformValue::UnknownTransformOperation)
, m_argCount(1)
, m_allowSingleArgument(false)
, m_unit(CSSParser::FUnknown)
{
if (equalIgnoringCase(name, "scale(") || equalIgnoringCase(name, "scalex(") || equalIgnoringCase(name, "scaley(")) {
m_unit = CSSParser::FNumber;
if (equalIgnoringCase(name, "scale("))
m_type = CSSTransformValue::ScaleTransformOperation;
else if (equalIgnoringCase(name, "scalex("))
m_type = CSSTransformValue::ScaleXTransformOperation;
else
m_type = CSSTransformValue::ScaleYTransformOperation;
} else if (equalIgnoringCase(name, "rotate(")) {
m_type = CSSTransformValue::RotateTransformOperation;
m_unit = CSSParser::FAngle;
} else if (equalIgnoringCase(name, "skew(") || equalIgnoringCase(name, "skewx(") || equalIgnoringCase(name, "skewy(")) {
m_unit = CSSParser::FAngle;
if (equalIgnoringCase(name, "skew("))
m_type = CSSTransformValue::SkewTransformOperation;
else if (equalIgnoringCase(name, "skewx("))
m_type = CSSTransformValue::SkewXTransformOperation;
else
m_type = CSSTransformValue::SkewYTransformOperation;
} else if (equalIgnoringCase(name, "translate(") || equalIgnoringCase(name, "translatex(") || equalIgnoringCase(name, "translatey(")) {
m_unit = CSSParser::FLength | CSSParser::FPercent;
if (equalIgnoringCase(name, "translate("))
m_type = CSSTransformValue::TranslateTransformOperation;
else if (equalIgnoringCase(name, "translatex("))
m_type = CSSTransformValue::TranslateXTransformOperation;
else
m_type = CSSTransformValue::TranslateYTransformOperation;
} else if (equalIgnoringCase(name, "matrix(")) {
m_type = CSSTransformValue::MatrixTransformOperation;
m_argCount = 11;
m_unit = CSSParser::FNumber;
}
if (equalIgnoringCase(name, "scale(") || equalIgnoringCase(name, "skew(") || equalIgnoringCase(name, "translate(")) {
m_allowSingleArgument = true;
m_argCount = 3;
}
}
CSSTransformValue::TransformOperationType type() const { return m_type; }
unsigned argCount() const { return m_argCount; }
CSSParser::Units unit() const { return m_unit; }
bool unknown() const { return m_type == CSSTransformValue::UnknownTransformOperation; }
bool hasCorrectArgCount(unsigned argCount) { return m_argCount == argCount || (m_allowSingleArgument && argCount == 1); }
private:
CSSTransformValue::TransformOperationType m_type;
unsigned m_argCount;
bool m_allowSingleArgument;
CSSParser::Units m_unit;
};
PassRefPtr<CSSValueList> CSSParser::parseTransform()
{
if (!m_valueList)
return 0;
// The transform is a list of functional primitives that specify transform operations. We collect a list
// of CSSTransformValues, where each value specifies a single operation.
RefPtr<CSSValueList> list = new CSSValueList;
for (Value* value = m_valueList->current(); value; value = m_valueList->next()) {
if (value->unit != Value::Function || !value->function)
return 0;
// Every primitive requires at least one argument.
ValueList* args = value->function->args;
if (!args)
return 0;
// See if the specified primitive is one we understand.
TransformOperationInfo info(value->function->name);
if (info.unknown())
return 0;
if (!info.hasCorrectArgCount(args->size()))
return 0;
// Create the new CSSTransformValue for this operation and add it to our list.
CSSTransformValue* transformValue = new CSSTransformValue(info.type());
list->append(transformValue);
// Snag our values.
Value* a = args->current();
unsigned argNumber = 0;
while (a) {
CSSParser::Units unit = info.unit();
if (!validUnit(a, unit, true))
return 0;
// Add the value to the current transform operation.
transformValue->addValue(new CSSPrimitiveValue(a->fValue, (CSSPrimitiveValue::UnitTypes) a->unit));
a = args->next();
if (!a)
break;
if (a->unit != Value::Operator || a->iValue != ',')
return 0;
a = args->next();
argNumber++;
}
}
return list.release();
}
bool CSSParser::parseTransformOrigin(int propId, int& propId1, int& propId2, RefPtr<CSSValue>& value, RefPtr<CSSValue>& value2)
{
propId1 = propId;
propId2 = propId;
if (propId == CSSPropertyWebkitTransformOrigin) {
propId1 = CSSPropertyWebkitTransformOriginX;
propId2 = CSSPropertyWebkitTransformOriginY;
}
switch (propId) {
case CSSPropertyWebkitTransformOrigin:
parseFillPosition(value, value2);
// Unlike the other functions, parseFillPosition advances the m_valueList pointer
break;
case CSSPropertyWebkitTransformOriginX: {
bool xFound = false, yFound = true;
value = parseFillPositionXY(xFound, yFound);
if (value)
m_valueList->next();
break;
}
case CSSPropertyWebkitTransformOriginY: {
bool xFound = true, yFound = false;
value = parseFillPositionXY(xFound, yFound);
if (value)
m_valueList->next();
break;
}
}
return value;
}
#ifdef CSS_DEBUG
static inline int yyerror(const char *str)
{
kdDebug(6080) << "CSS parse error " << str << endl;
return 1;
}
#else
static inline int yyerror(const char*) { return 1; }
#endif
#define END_TOKEN 0
#include "CSSGrammar.h"
int CSSParser::lex(void* yylvalWithoutType)
{
YYSTYPE* yylval = static_cast<YYSTYPE*>(yylvalWithoutType);
int token = lex();
int length;
UChar* t = text(&length);
switch(token) {
case WHITESPACE:
case SGML_CD:
case INCLUDES:
case DASHMATCH:
break;
case URI:
case STRING:
case IDENT:
case NTH:
case HEX:
case IDSEL:
case DIMEN:
case UNICODERANGE:
case FUNCTION:
case NOTFUNCTION:
yylval->string.characters = t;
yylval->string.length = length;
break;
case IMPORT_SYM:
case PAGE_SYM:
case MEDIA_SYM:
case FONT_FACE_SYM:
case CHARSET_SYM:
case NAMESPACE_SYM:
case IMPORTANT_SYM:
break;
case QEMS:
length--;
case GRADS:
length--;
case DEGS:
case RADS:
case KHERZ:
length--;
case MSECS:
case HERZ:
case EMS:
case EXS:
case PXS:
case CMS:
case MMS:
case INS:
case PTS:
case PCS:
length--;
case SECS:
case PERCENTAGE:
length--;
case FLOATTOKEN:
case INTEGER:
yylval->number = charactersToDouble(t, length);
break;
default:
break;
}
return token;
}
static inline int toHex(char c)
{
if ('0' <= c && c <= '9')
return c - '0';
if ('a' <= c && c <= 'f')
return c - 'a' + 10;
if ('A' <= c && c<= 'F')
return c - 'A' + 10;
return 0;
}
UChar* CSSParser::text(int *length)
{
UChar* start = yytext;
int l = yyleng;
switch(yyTok) {
case STRING:
l--;
/* nobreak */
case HEX:
case IDSEL:
start++;
l--;
break;
case URI:
// "url("{w}{string}{w}")"
// "url("{w}{url}{w}")"
// strip "url(" and ")"
start += 4;
l -= 5;
// strip {w}
while (l &&
(*start == ' ' || *start == '\t' || *start == '\r' ||
*start == '\n' || *start == '\f')) {
start++; l--;
}
if (*start == '"' || *start == '\'') {
start++; l--;
}
while (l &&
(start[l-1] == ' ' || start[l-1] == '\t' || start[l-1] == '\r' ||
start[l-1] == '\n' || start[l-1] == '\f')) {
l--;
}
if (l && (start[l-1] == '\"' || start[l-1] == '\''))
l--;
default:
break;
}
// process escapes
UChar* out = start;
UChar* escape = 0;
for (int i = 0; i < l; i++) {
UChar* current = start + i;
if (escape == current - 1) {
if ((*current >= '0' && *current <= '9') ||
(*current >= 'a' && *current <= 'f') ||
(*current >= 'A' && *current <= 'F'))
continue;
if (yyTok == STRING &&
(*current == '\n' || *current == '\r' || *current == '\f')) {
// ### handle \r\n case
if (*current != '\r')
escape = 0;
continue;
}
// in all other cases copy the char to output
// ###
*out++ = *current;
escape = 0;
continue;
}
if (escape == current - 2 && yyTok == STRING &&
*(current-1) == '\r' && *current == '\n') {
escape = 0;
continue;
}
if (escape > current - 7 &&
((*current >= '0' && *current <= '9') ||
(*current >= 'a' && *current <= 'f') ||
(*current >= 'A' && *current <= 'F')))
continue;
if (escape) {
// add escaped char
unsigned uc = 0;
escape++;
while (escape < current) {
uc *= 16;
uc += toHex(*escape);
escape++;
}
// can't handle chars outside ucs2
if (uc > 0xffff)
uc = 0xfffd;
*out++ = uc;
escape = 0;
if (*current == ' ' ||
*current == '\t' ||
*current == '\r' ||
*current == '\n' ||
*current == '\f')
continue;
}
if (!escape && *current == '\\') {
escape = current;
continue;
}
*out++ = *current;
}
if (escape) {
// add escaped char
unsigned uc = 0;
escape++;
while (escape < start+l) {
uc *= 16;
uc += toHex(*escape);
escape++;
}
// can't handle chars outside ucs2
if (uc > 0xffff)
uc = 0xfffd;
*out++ = uc;
}
*length = out - start;
return start;
}
CSSSelector* CSSParser::createFloatingSelector()
{
CSSSelector* selector = new CSSSelector;
m_floatingSelectors.add(selector);
return selector;
}
CSSSelector* CSSParser::sinkFloatingSelector(CSSSelector* selector)
{
if (selector) {
ASSERT(m_floatingSelectors.contains(selector));
m_floatingSelectors.remove(selector);
}
return selector;
}
ValueList* CSSParser::createFloatingValueList()
{
ValueList* list = new ValueList;
m_floatingValueLists.add(list);
return list;
}
ValueList* CSSParser::sinkFloatingValueList(ValueList* list)
{
if (list) {
ASSERT(m_floatingValueLists.contains(list));
m_floatingValueLists.remove(list);
}
return list;
}
Function* CSSParser::createFloatingFunction()
{
Function* function = new Function;
m_floatingFunctions.add(function);
return function;
}
Function* CSSParser::sinkFloatingFunction(Function* function)
{
if (function) {
ASSERT(m_floatingFunctions.contains(function));
m_floatingFunctions.remove(function);
}
return function;
}
Value& CSSParser::sinkFloatingValue(Value& value)
{
if (value.unit == Value::Function) {
ASSERT(m_floatingFunctions.contains(value.function));
m_floatingFunctions.remove(value.function);
}
return value;
}
MediaQueryExp* CSSParser::createFloatingMediaQueryExp(const AtomicString& mediaFeature, ValueList* values)
{
delete m_floatingMediaQueryExp;
m_floatingMediaQueryExp = new MediaQueryExp(mediaFeature, values);
return m_floatingMediaQueryExp;
}
MediaQueryExp* CSSParser::sinkFloatingMediaQueryExp(MediaQueryExp* e)
{
ASSERT(e == m_floatingMediaQueryExp);
m_floatingMediaQueryExp = 0;
return e;
}
Vector<MediaQueryExp*>* CSSParser::createFloatingMediaQueryExpList()
{
if (m_floatingMediaQueryExpList) {
deleteAllValues(*m_floatingMediaQueryExpList);
delete m_floatingMediaQueryExpList;
}
m_floatingMediaQueryExpList = new Vector<MediaQueryExp*>;
return m_floatingMediaQueryExpList;
}
Vector<MediaQueryExp*>* CSSParser::sinkFloatingMediaQueryExpList(Vector<MediaQueryExp*>* l)
{
ASSERT(l == m_floatingMediaQueryExpList);
m_floatingMediaQueryExpList = 0;
return l;
}
MediaQuery* CSSParser::createFloatingMediaQuery(MediaQuery::Restrictor r, const String& mediaType, Vector<MediaQueryExp*>* exprs)
{
delete m_floatingMediaQuery;
m_floatingMediaQuery = new MediaQuery(r, mediaType, exprs);
return m_floatingMediaQuery;
}
MediaQuery* CSSParser::createFloatingMediaQuery(Vector<MediaQueryExp*>* exprs)
{
return createFloatingMediaQuery(MediaQuery::None, "all", exprs);
}
MediaQuery* CSSParser::sinkFloatingMediaQuery(MediaQuery* mq)
{
ASSERT(mq == m_floatingMediaQuery);
m_floatingMediaQuery = 0;
return mq;
}
MediaList* CSSParser::createMediaList()
{
MediaList* list = new MediaList;
m_parsedStyleObjects.append(list);
return list;
}
CSSRule* CSSParser::createCharsetRule(const ParseString& charset)
{
if (!m_styleSheet)
return 0;
CSSCharsetRule* rule = new CSSCharsetRule(m_styleSheet, charset);
m_parsedStyleObjects.append(rule);
return rule;
}
CSSRule* CSSParser::createImportRule(const ParseString& url, MediaList* media)
{
if (!media || !m_styleSheet)
return 0;
CSSImportRule* rule = new CSSImportRule(m_styleSheet, url, media);
m_parsedStyleObjects.append(rule);
return rule;
}
CSSRule* CSSParser::createMediaRule(MediaList* media, CSSRuleList* rules)
{
if (!media || !rules || !m_styleSheet)
return 0;
CSSMediaRule* rule = new CSSMediaRule(m_styleSheet, media, rules);
m_parsedStyleObjects.append(rule);
return rule;
}
CSSRuleList* CSSParser::createRuleList()
{
RefPtr<CSSRuleList> list = CSSRuleList::create();
CSSRuleList* listPtr = list.get();
m_parsedRuleLists.append(list.release());
return listPtr;
}
CSSRule* CSSParser::createStyleRule(CSSSelector* selector)
{
CSSStyleRule* rule = 0;
if (selector) {
rule = new CSSStyleRule(m_styleSheet);
m_parsedStyleObjects.append(rule);
rule->setSelector(sinkFloatingSelector(selector));
rule->setDeclaration(new CSSMutableStyleDeclaration(rule, m_parsedProperties, m_numParsedProperties));
}
clearProperties();
return rule;
}
CSSRule* CSSParser::createFontFaceRule()
{
CSSFontFaceRule* rule = new CSSFontFaceRule(m_styleSheet);
m_parsedStyleObjects.append(rule);
rule->setDeclaration(new CSSMutableStyleDeclaration(rule, m_parsedProperties, m_numParsedProperties));
clearProperties();
return rule;
}
static int cssPropertyID(const UChar* propertyName, unsigned length)
{
if (!length)
return 0;
if (length > maxCSSPropertyNameLength)
return 0;
char buffer[maxCSSPropertyNameLength + 1 + 1]; // 1 to turn "apple"/"khtml" into "webkit", 1 for null character
for (unsigned i = 0; i != length; ++i) {
UChar c = propertyName[i];
if (c == 0 || c >= 0x7F)
return 0; // illegal character
buffer[i] = toASCIILower(c);
}
buffer[length] = '\0';
const char* name = buffer;
if (buffer[0] == '-') {
// If the prefix is -apple- or -khtml-, change it to -webkit-.
// This makes the string one character longer.
if (hasPrefix(buffer, length, "-apple-") || hasPrefix(buffer, length, "-khtml-")) {
memmove(buffer + 7, buffer + 6, length + 1 - 6);
memcpy(buffer, "-webkit", 7);
++length;
}
// Honor -webkit-opacity as a synonym for opacity.
// This was the only syntax that worked in Safari 1.1, and may be in use on some websites and widgets.
if (strcmp(buffer, "-webkit-opacity") == 0) {
const char * const opacity = "opacity";
name = opacity;
length = strlen(opacity);
}
}
const props* hashTableEntry = findProp(name, length);
return hashTableEntry ? hashTableEntry->id : 0;
}
int cssPropertyID(const String& string)
{
return cssPropertyID(string.characters(), string.length());
}
int cssPropertyID(const ParseString& string)
{
return cssPropertyID(string.characters, string.length);
}
int cssValueKeywordID(const ParseString& string)
{
unsigned length = string.length;
if (!length)
return 0;
if (length > maxCSSValueKeywordLength)
return 0;
char buffer[maxCSSValueKeywordLength + 1 + 1]; // 1 to turn "apple"/"khtml" into "webkit", 1 for null character
for (unsigned i = 0; i != length; ++i) {
UChar c = string.characters[i];
if (c == 0 || c >= 0x7F)
return 0; // illegal character
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.
if (hasPrefix(buffer, length, "-apple-") || hasPrefix(buffer, length, "-khtml-")) {
memmove(buffer + 7, buffer + 6, length + 1 - 6);
memcpy(buffer, "-webkit", 7);
++length;
}
}
const css_value* hashTableEntry = findValue(buffer, length);
return hashTableEntry ? hashTableEntry->id : 0;
}
#define YY_DECL int CSSParser::lex()
#define yyconst const
typedef int yy_state_type;
typedef unsigned YY_CHAR;
// The following line makes sure we treat non-Latin-1 Unicode characters correctly.
#define YY_SC_TO_UI(c) (c > 0xff ? 0xff : c)
#define YY_DO_BEFORE_ACTION \
yytext = yy_bp; \
yyleng = (int) (yy_cp - yy_bp); \
yy_hold_char = *yy_cp; \
*yy_cp = 0; \
yy_c_buf_p = yy_cp;
#define YY_BREAK break;
#define ECHO
#define YY_RULE_SETUP
#define INITIAL 0
#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
#define yyterminate() yyTok = END_TOKEN; return yyTok
#define YY_FATAL_ERROR(a)
// The following line is needed to build the tokenizer with a condition stack.
// The macro is used in the tokenizer grammar with lines containing
// BEGIN(mediaqueries) and BEGIN(initial). yy_start acts as index to
// tokenizer transition table, and 'mediaqueries' and 'initial' are
// offset multipliers that specify which transitions are active
// in the tokenizer during in each condition (tokenizer state).
#define BEGIN yy_start = 1 + 2 *
#include "tokenizer.cpp"
}
|