1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326
|
/*
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
* Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
* Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
* Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
* Copyright (C) 2007, 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 "CSSStyleSelector.h"
#include "CSSBorderImageValue.h"
#include "CSSCursorImageValue.h"
#include "CSSFontFace.h"
#include "CSSFontFaceRule.h"
#include "CSSFontFaceSource.h"
#include "CSSImportRule.h"
#include "CSSMediaRule.h"
#include "CSSPrimitiveValueMappings.h"
#include "CSSProperty.h"
#include "CSSPropertyNames.h"
#include "CSSReflectValue.h"
#include "CSSRuleList.h"
#include "CSSSelector.h"
#include "CSSStyleRule.h"
#include "CSSStyleSheet.h"
#include "CSSTimingFunctionValue.h"
#include "CSSValueList.h"
#include "CachedImage.h"
#include "Counter.h"
#include "FontFamilyValue.h"
#include "FontValue.h"
#include "Frame.h"
#include "FrameView.h"
#include "HTMLDocument.h"
#include "HTMLElement.h"
#include "HTMLInputElement.h"
#include "HTMLNames.h"
#include "MediaList.h"
#include "MediaQueryEvaluator.h"
#include "Page.h"
#include "PageGroup.h"
#include "Pair.h"
#include "Rect.h"
#include "RenderTheme.h"
#include "SelectionController.h"
#include "Settings.h"
#include "ShadowValue.h"
#include "StyleSheetList.h"
#include "Text.h"
#include "UserAgentStyleSheets.h"
#include "XMLNames.h"
#include "loader.h"
#include <wtf/Vector.h>
#if ENABLE(DASHBOARD_SUPPORT)
#include "DashboardRegion.h"
#endif
#if ENABLE(SVG)
#include "XLinkNames.h"
#include "SVGNames.h"
#endif
using namespace std;
namespace WebCore {
using namespace HTMLNames;
// #define STYLE_SHARING_STATS 1
#define HANDLE_INHERIT(prop, Prop) \
if (isInherit) { \
m_style->set##Prop(m_parentStyle->prop()); \
return; \
}
#define HANDLE_INHERIT_AND_INITIAL(prop, Prop) \
HANDLE_INHERIT(prop, Prop) \
if (isInitial) { \
m_style->set##Prop(RenderStyle::initial##Prop()); \
return; \
}
#define HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(prop, Prop, Value) \
HANDLE_INHERIT(prop, Prop) \
if (isInitial) { \
m_style->set##Prop(RenderStyle::initial##Value());\
return;\
}
#define HANDLE_FILL_LAYER_INHERIT_AND_INITIAL(layerType, LayerType, prop, Prop) \
if (isInherit) { \
FillLayer* currChild = m_style->access##LayerType##Layers(); \
FillLayer* prevChild = 0; \
const FillLayer* currParent = m_parentStyle->layerType##Layers(); \
while (currParent && currParent->is##Prop##Set()) { \
if (!currChild) { \
/* Need to make a new layer.*/ \
currChild = new FillLayer(LayerType##FillLayer); \
prevChild->setNext(currChild); \
} \
currChild->set##Prop(currParent->prop()); \
prevChild = currChild; \
currChild = prevChild->next(); \
currParent = currParent->next(); \
} \
\
while (currChild) { \
/* Reset any remaining layers to not have the property set. */ \
currChild->clear##Prop(); \
currChild = currChild->next(); \
} \
} else if (isInitial) { \
FillLayer* currChild = m_style->access##LayerType##Layers(); \
currChild->set##Prop(FillLayer::initialFill##Prop(LayerType##FillLayer)); \
for (currChild = currChild->next(); currChild; currChild = currChild->next()) \
currChild->clear##Prop(); \
}
#define HANDLE_FILL_LAYER_VALUE(layerType, LayerType, prop, Prop, value) { \
HANDLE_FILL_LAYER_INHERIT_AND_INITIAL(layerType, LayerType, prop, Prop) \
if (isInherit || isInitial) \
return; \
FillLayer* currChild = m_style->access##LayerType##Layers(); \
FillLayer* prevChild = 0; \
if (value->isValueList()) { \
/* Walk each value and put it into a layer, creating new layers as needed. */ \
CSSValueList* valueList = static_cast<CSSValueList*>(value); \
for (unsigned int i = 0; i < valueList->length(); i++) { \
if (!currChild) { \
/* Need to make a new layer to hold this value */ \
currChild = new FillLayer(LayerType##FillLayer); \
prevChild->setNext(currChild); \
} \
mapFill##Prop(currChild, valueList->itemWithoutBoundsCheck(i)); \
prevChild = currChild; \
currChild = currChild->next(); \
} \
} else { \
mapFill##Prop(currChild, value); \
currChild = currChild->next(); \
} \
while (currChild) { \
/* Reset all remaining layers to not have the property set. */ \
currChild->clear##Prop(); \
currChild = currChild->next(); \
} }
#define HANDLE_BACKGROUND_INHERIT_AND_INITIAL(prop, Prop) \
HANDLE_FILL_LAYER_INHERIT_AND_INITIAL(background, Background, prop, Prop)
#define HANDLE_BACKGROUND_VALUE(prop, Prop, value) \
HANDLE_FILL_LAYER_VALUE(background, Background, prop, Prop, value)
#define HANDLE_MASK_INHERIT_AND_INITIAL(prop, Prop) \
HANDLE_FILL_LAYER_INHERIT_AND_INITIAL(mask, Mask, prop, Prop)
#define HANDLE_MASK_VALUE(prop, Prop, value) \
HANDLE_FILL_LAYER_VALUE(mask, Mask, prop, Prop, value)
#define HANDLE_TRANSITION_INHERIT_AND_INITIAL(prop, Prop) \
if (isInherit) { \
Transition* currChild = m_style->accessTransitions(); \
Transition* prevChild = 0; \
const Transition* currParent = m_parentStyle->transitions(); \
while (currParent && currParent->is##Prop##Set()) { \
if (!currChild) { \
/* Need to make a new layer.*/ \
currChild = new Transition(); \
prevChild->setNext(currChild); \
} \
currChild->set##Prop(currParent->prop()); \
prevChild = currChild; \
currChild = prevChild->next(); \
currParent = currParent->next(); \
} \
\
while (currChild) { \
/* Reset any remaining layers to not have the property set. */ \
currChild->clear##Prop(); \
currChild = currChild->next(); \
} \
} else if (isInitial) { \
Transition* currChild = m_style->accessTransitions(); \
currChild->set##Prop(RenderStyle::initialTransition##Prop()); \
for (currChild = currChild->next(); currChild; currChild = currChild->next()) \
currChild->clear##Prop(); \
}
#define HANDLE_TRANSITION_VALUE(prop, Prop, value) { \
HANDLE_TRANSITION_INHERIT_AND_INITIAL(prop, Prop) \
if (isInherit || isInitial) \
return; \
Transition* currChild = m_style->accessTransitions(); \
Transition* prevChild = 0; \
if (value->isValueList()) { \
/* Walk each value and put it into a layer, creating new layers as needed. */ \
CSSValueList* valueList = static_cast<CSSValueList*>(value); \
for (unsigned int i = 0; i < valueList->length(); i++) { \
if (!currChild) { \
/* Need to make a new layer to hold this value */ \
currChild = new Transition(); \
prevChild->setNext(currChild); \
} \
mapTransition##Prop(currChild, valueList->itemWithoutBoundsCheck(i)); \
prevChild = currChild; \
currChild = currChild->next(); \
} \
} else { \
mapTransition##Prop(currChild, value); \
currChild = currChild->next(); \
} \
while (currChild) { \
/* Reset all remaining layers to not have the property set. */ \
currChild->clear##Prop(); \
currChild = currChild->next(); \
} }
#define HANDLE_INHERIT_COND(propID, prop, Prop) \
if (id == propID) { \
m_style->set##Prop(m_parentStyle->prop()); \
return; \
}
#define HANDLE_INHERIT_COND_WITH_BACKUP(propID, prop, propAlt, Prop) \
if (id == propID) { \
if (m_parentStyle->prop().isValid()) \
m_style->set##Prop(m_parentStyle->prop()); \
else \
m_style->set##Prop(m_parentStyle->propAlt()); \
return; \
}
#define HANDLE_INITIAL_COND(propID, Prop) \
if (id == propID) { \
m_style->set##Prop(RenderStyle::initial##Prop()); \
return; \
}
#define HANDLE_INITIAL_COND_WITH_VALUE(propID, Prop, Value) \
if (id == propID) { \
m_style->set##Prop(RenderStyle::initial##Value()); \
return; \
}
class CSSRuleSet {
public:
CSSRuleSet();
~CSSRuleSet();
typedef HashMap<AtomicStringImpl*, CSSRuleDataList*> AtomRuleMap;
void addRulesFromSheet(CSSStyleSheet*, const MediaQueryEvaluator&, CSSStyleSelector* = 0);
void addRule(CSSStyleRule* rule, CSSSelector* sel);
void addToRuleSet(AtomicStringImpl* key, AtomRuleMap& map,
CSSStyleRule* rule, CSSSelector* sel);
CSSRuleDataList* getIDRules(AtomicStringImpl* key) { return m_idRules.get(key); }
CSSRuleDataList* getClassRules(AtomicStringImpl* key) { return m_classRules.get(key); }
CSSRuleDataList* getTagRules(AtomicStringImpl* key) { return m_tagRules.get(key); }
CSSRuleDataList* getUniversalRules() { return m_universalRules; }
public:
AtomRuleMap m_idRules;
AtomRuleMap m_classRules;
AtomRuleMap m_tagRules;
CSSRuleDataList* m_universalRules;
unsigned m_ruleCount;
};
static CSSRuleSet* defaultStyle;
static CSSRuleSet* defaultQuirksStyle;
static CSSRuleSet* defaultPrintStyle;
static CSSRuleSet* defaultViewSourceStyle;
RenderStyle* CSSStyleSelector::s_styleNotYetAvailable;
static PseudoState pseudoState;
static void loadDefaultStyle();
static const MediaQueryEvaluator& screenEval()
{
static const MediaQueryEvaluator staticScreenEval("screen");
return staticScreenEval;
}
static const MediaQueryEvaluator& printEval()
{
static const MediaQueryEvaluator staticPrintEval("print");
return staticPrintEval;
}
CSSStyleSelector::CSSStyleSelector(Document* doc, const String& userStyleSheet, StyleSheetList* styleSheets, CSSStyleSheet* mappedElementSheet, bool strictParsing, bool matchAuthorAndUserStyles)
: m_backgroundData(BackgroundFillLayer)
, m_checker(doc, strictParsing, false)
, m_fontSelector(CSSFontSelector::create(doc))
{
init();
m_matchAuthorAndUserStyles = matchAuthorAndUserStyles;
if (!defaultStyle)
loadDefaultStyle();
m_userStyle = 0;
// construct document root element default style. this is needed
// to evaluate media queries that contain relative constraints, like "screen and (max-width: 10em)"
// This is here instead of constructor, because when constructor is run,
// document doesn't have documentElement
// NOTE: this assumes that element that gets passed to styleForElement -call
// is always from the document that owns the style selector
FrameView* view = doc->view();
if (view)
m_medium = new MediaQueryEvaluator(view->mediaType());
else
m_medium = new MediaQueryEvaluator("all");
Element* root = doc->documentElement();
if (root)
m_rootDefaultStyle = styleForElement(root, 0, false, true); // dont ref, because the RenderStyle is allocated from global heap
if (m_rootDefaultStyle && view) {
delete m_medium;
m_medium = new MediaQueryEvaluator(view->mediaType(), view->frame(), m_rootDefaultStyle);
}
// FIXME: This sucks! The user sheet is reparsed every time!
if (!userStyleSheet.isEmpty()) {
m_userSheet = new CSSStyleSheet(doc);
m_userSheet->parseString(userStyleSheet, strictParsing);
m_userStyle = new CSSRuleSet();
m_userStyle->addRulesFromSheet(m_userSheet.get(), *m_medium, this);
}
// add stylesheets from document
m_authorStyle = new CSSRuleSet();
// Add rules from elments like SVG's <font-face>
if (mappedElementSheet)
m_authorStyle->addRulesFromSheet(mappedElementSheet, *m_medium, this);
unsigned length = styleSheets->length();
for (unsigned i = 0; i < length; i++) {
StyleSheet* sheet = styleSheets->item(i);
if (sheet->isCSSStyleSheet() && !sheet->disabled())
m_authorStyle->addRulesFromSheet(static_cast<CSSStyleSheet*>(sheet), *m_medium, this);
}
}
void CSSStyleSelector::init()
{
m_element = 0;
m_matchedDecls.clear();
m_ruleList = 0;
m_rootDefaultStyle = 0;
m_medium = 0;
}
CSSStyleSelector::~CSSStyleSelector()
{
delete m_medium;
::delete m_rootDefaultStyle;
delete m_authorStyle;
delete m_userStyle;
deleteAllValues(m_viewportDependentMediaQueryResults);
}
static CSSStyleSheet* parseUASheet(const char* characters, unsigned size)
{
CSSStyleSheet* const parent = 0;
CSSStyleSheet* sheet = new CSSStyleSheet(parent);
sheet->ref(); // leak the sheet on purpose
sheet->parseString(String(characters, size));
return sheet;
}
static void loadDefaultStyle()
{
ASSERT(!defaultStyle);
defaultStyle = new CSSRuleSet;
defaultPrintStyle = new CSSRuleSet;
defaultQuirksStyle = new CSSRuleSet;
defaultViewSourceStyle = new CSSRuleSet;
// Strict-mode rules.
CSSStyleSheet* defaultSheet = parseUASheet(html4UserAgentStyleSheet, sizeof(html4UserAgentStyleSheet));
RenderTheme::adjustDefaultStyleSheet(defaultSheet);
defaultStyle->addRulesFromSheet(defaultSheet, screenEval());
defaultPrintStyle->addRulesFromSheet(defaultSheet, printEval());
// Quirks-mode rules.
defaultQuirksStyle->addRulesFromSheet(parseUASheet(quirksUserAgentStyleSheet, sizeof(quirksUserAgentStyleSheet)), screenEval());
// View source rules.
defaultViewSourceStyle->addRulesFromSheet(parseUASheet(sourceUserAgentStyleSheet, sizeof(sourceUserAgentStyleSheet)), screenEval());
}
void CSSStyleSelector::matchRules(CSSRuleSet* rules, int& firstRuleIndex, int& lastRuleIndex)
{
m_matchedRules.clear();
if (!rules || !m_element)
return;
// We need to collect the rules for id, class, tag, and everything else into a buffer and
// then sort the buffer.
if (m_element->hasID())
matchRulesForList(rules->getIDRules(m_element->getIDAttribute().impl()), firstRuleIndex, lastRuleIndex);
if (m_element->hasClass()) {
ASSERT(m_styledElement);
const ClassNames& classNames = m_styledElement->classNames();
size_t size = classNames.size();
for (size_t i = 0; i < size; ++i)
matchRulesForList(rules->getClassRules(classNames[i].impl()), firstRuleIndex, lastRuleIndex);
}
matchRulesForList(rules->getTagRules(m_element->localName().impl()), firstRuleIndex, lastRuleIndex);
matchRulesForList(rules->getUniversalRules(), firstRuleIndex, lastRuleIndex);
// If we didn't match any rules, we're done.
if (m_matchedRules.isEmpty())
return;
// Sort the set of matched rules.
sortMatchedRules(0, m_matchedRules.size());
// Now transfer the set of matched rules over to our list of decls.
if (!m_checker.m_collectRulesOnly) {
for (unsigned i = 0; i < m_matchedRules.size(); i++)
addMatchedDeclaration(m_matchedRules[i]->rule()->declaration());
} else {
for (unsigned i = 0; i < m_matchedRules.size(); i++) {
if (!m_ruleList)
m_ruleList = CSSRuleList::create();
m_ruleList->append(m_matchedRules[i]->rule());
}
}
}
void CSSStyleSelector::matchRulesForList(CSSRuleDataList* rules, int& firstRuleIndex, int& lastRuleIndex)
{
if (!rules)
return;
for (CSSRuleData* d = rules->first(); d; d = d->next()) {
CSSStyleRule* rule = d->rule();
const AtomicString& localName = m_element->localName();
const AtomicString& selectorLocalName = d->selector()->m_tag.localName();
if ((localName == selectorLocalName || selectorLocalName == starAtom) && checkSelector(d->selector())) {
// If the rule has no properties to apply, then ignore it.
CSSMutableStyleDeclaration* decl = rule->declaration();
if (!decl || !decl->length())
continue;
// If we're matching normal rules, set a pseudo bit if
// we really just matched a pseudo-element.
if (m_dynamicPseudo != RenderStyle::NOPSEUDO && m_checker.m_pseudoStyle == RenderStyle::NOPSEUDO) {
if (m_checker.m_collectRulesOnly)
return;
if (m_dynamicPseudo < RenderStyle::FIRST_INTERNAL_PSEUDOID)
m_style->setHasPseudoStyle(m_dynamicPseudo);
} else {
// Update our first/last rule indices in the matched rules array.
lastRuleIndex = m_matchedDecls.size() + m_matchedRules.size();
if (firstRuleIndex == -1)
firstRuleIndex = lastRuleIndex;
// Add this rule to our list of matched rules.
addMatchedRule(d);
}
}
}
}
bool operator >(CSSRuleData& r1, CSSRuleData& r2)
{
int spec1 = r1.selector()->specificity();
int spec2 = r2.selector()->specificity();
return (spec1 == spec2) ? r1.position() > r2.position() : spec1 > spec2;
}
bool operator <=(CSSRuleData& r1, CSSRuleData& r2)
{
return !(r1 > r2);
}
void CSSStyleSelector::sortMatchedRules(unsigned start, unsigned end)
{
if (start >= end || (end - start == 1))
return; // Sanity check.
if (end - start <= 6) {
// Apply a bubble sort for smaller lists.
for (unsigned i = end - 1; i > start; i--) {
bool sorted = true;
for (unsigned j = start; j < i; j++) {
CSSRuleData* elt = m_matchedRules[j];
CSSRuleData* elt2 = m_matchedRules[j + 1];
if (*elt > *elt2) {
sorted = false;
m_matchedRules[j] = elt2;
m_matchedRules[j + 1] = elt;
}
}
if (sorted)
return;
}
return;
}
// Peform a merge sort for larger lists.
unsigned mid = (start + end) / 2;
sortMatchedRules(start, mid);
sortMatchedRules(mid, end);
CSSRuleData* elt = m_matchedRules[mid - 1];
CSSRuleData* elt2 = m_matchedRules[mid];
// Handle the fast common case (of equal specificity). The list may already
// be completely sorted.
if (*elt <= *elt2)
return;
// We have to merge sort. Ensure our merge buffer is big enough to hold
// all the items.
Vector<CSSRuleData*> rulesMergeBuffer;
rulesMergeBuffer.reserveCapacity(end - start);
unsigned i1 = start;
unsigned i2 = mid;
elt = m_matchedRules[i1];
elt2 = m_matchedRules[i2];
while (i1 < mid || i2 < end) {
if (i1 < mid && (i2 == end || *elt <= *elt2)) {
rulesMergeBuffer.append(elt);
if (++i1 < mid)
elt = m_matchedRules[i1];
} else {
rulesMergeBuffer.append(elt2);
if (++i2 < end)
elt2 = m_matchedRules[i2];
}
}
for (unsigned i = start; i < end; i++)
m_matchedRules[i] = rulesMergeBuffer[i - start];
}
void CSSStyleSelector::initElementAndPseudoState(Element* e)
{
m_element = e;
if (m_element && m_element->isStyledElement())
m_styledElement = static_cast<StyledElement*>(m_element);
else
m_styledElement = 0;
pseudoState = PseudoUnknown;
}
void CSSStyleSelector::initForStyleResolve(Element* e, RenderStyle* parentStyle, RenderStyle::PseudoId pseudoID)
{
m_checker.m_pseudoStyle = pseudoID;
m_parentNode = e->parentNode();
#if ENABLE(SVG)
if (!m_parentNode && e->isSVGElement() && e->isShadowNode())
m_parentNode = e->shadowParentNode();
#endif
if (parentStyle)
m_parentStyle = parentStyle;
else
m_parentStyle = m_parentNode ? m_parentNode->renderStyle() : 0;
m_style = 0;
m_matchedDecls.clear();
m_ruleList = 0;
m_fontDirty = false;
}
static inline const AtomicString* linkAttribute(Node* node)
{
if (!node->isLink())
return 0;
ASSERT(node->isElementNode());
Element* element = static_cast<Element*>(node);
if (element->isHTMLElement())
return &element->getAttribute(hrefAttr);
#if ENABLE(SVG)
if (element->isSVGElement())
return &element->getAttribute(XLinkNames::hrefAttr);
#endif
return 0;
}
CSSStyleSelector::SelectorChecker::SelectorChecker(Document* document, bool strictParsing, bool collectRulesOnly)
: m_document(document)
, m_strictParsing(strictParsing)
, m_collectRulesOnly(collectRulesOnly)
, m_pseudoStyle(RenderStyle::NOPSEUDO)
, m_documentIsHTML(document->isHTMLDocument())
{
}
PseudoState CSSStyleSelector::SelectorChecker::checkPseudoState(Element* element, bool checkVisited) const
{
const AtomicString* attr = linkAttribute(element);
if (!attr || attr->isNull())
return PseudoNone;
if (!checkVisited)
return PseudoAnyLink;
unsigned hash = m_document->visitedLinkHash(*attr);
if (!hash)
return PseudoLink;
Frame* frame = m_document->frame();
if (!frame)
return PseudoLink;
Page* page = frame->page();
if (!page)
return PseudoLink;
m_linksCheckedForVisitedState.add(hash);
return page->group().isLinkVisited(hash) ? PseudoVisited : PseudoLink;
}
bool CSSStyleSelector::SelectorChecker::checkSelector(CSSSelector* sel, Element* element) const
{
pseudoState = PseudoUnknown;
RenderStyle::PseudoId dynamicPseudo = RenderStyle::NOPSEUDO;
return checkSelector(sel, element, 0, dynamicPseudo, true, false) == SelectorMatches;
}
// a helper function for parsing nth-arguments
static bool parseNth(const String& nth, int &a, int &b)
{
if (nth.isEmpty())
return false;
a = 0;
b = 0;
if (nth == "odd") {
a = 2;
b = 1;
} else if (nth == "even") {
a = 2;
b = 0;
} else {
int n = nth.find('n');
if (n != -1) {
if (nth[0] == '-') {
if (n == 1)
a = -1; // -n == -1n
else
a = nth.substring(0, n).toInt();
} else if (!n)
a = 1; // n == 1n
else
a = nth.substring(0, n).toInt();
int p = nth.find('+', n);
if (p != -1)
b = nth.substring(p + 1, nth.length() - p - 1).toInt();
else {
p = nth.find('-', n);
b = -nth.substring(p + 1, nth.length() - p - 1).toInt();
}
} else
b = nth.toInt();
}
return true;
}
// a helper function for checking nth-arguments
static bool matchNth(int count, int a, int b)
{
if (!a)
return count == b;
else if (a > 0) {
if (count < b)
return false;
return (count - b) % a == 0;
} else {
if (count > b)
return false;
return (b - count) % (-a) == 0;
}
}
#ifdef STYLE_SHARING_STATS
static int fraction = 0;
static int total = 0;
#endif
static const unsigned cStyleSearchThreshold = 10;
Node* CSSStyleSelector::locateCousinList(Element* parent, unsigned depth)
{
if (parent && parent->isStyledElement()) {
StyledElement* p = static_cast<StyledElement*>(parent);
if (!p->inlineStyleDecl() && !p->hasID()) {
Node* r = p->previousSibling();
unsigned subcount = 0;
RenderStyle* st = p->renderStyle();
while (r) {
if (r->renderStyle() == st)
return r->lastChild();
if (subcount++ == cStyleSearchThreshold)
return 0;
r = r->previousSibling();
}
if (!r && depth < cStyleSearchThreshold)
r = locateCousinList(static_cast<Element*>(parent->parentNode()), depth + 1);
while (r) {
if (r->renderStyle() == st)
return r->lastChild();
if (subcount++ == cStyleSearchThreshold)
return 0;
r = r->previousSibling();
}
}
}
return 0;
}
bool CSSStyleSelector::canShareStyleWithElement(Node* n)
{
if (n->isStyledElement()) {
StyledElement* s = static_cast<StyledElement*>(n);
RenderStyle* style = s->renderStyle();
if (style && !style->unique() &&
(s->tagQName() == m_element->tagQName()) && !s->hasID() &&
(s->hasClass() == m_element->hasClass()) && !s->inlineStyleDecl() &&
(s->hasMappedAttributes() == m_styledElement->hasMappedAttributes()) &&
(s->isLink() == m_element->isLink()) &&
!style->affectedByAttributeSelectors() &&
(s->hovered() == m_element->hovered()) &&
(s->active() == m_element->active()) &&
(s->focused() == m_element->focused()) &&
(s != s->document()->getCSSTarget() && m_element != m_element->document()->getCSSTarget()) &&
(s->getAttribute(typeAttr) == m_element->getAttribute(typeAttr)) &&
(s->getAttribute(XMLNames::langAttr) == m_element->getAttribute(XMLNames::langAttr)) &&
(s->getAttribute(langAttr) == m_element->getAttribute(langAttr)) &&
(s->getAttribute(readonlyAttr) == m_element->getAttribute(readonlyAttr)) &&
(s->getAttribute(cellpaddingAttr) == m_element->getAttribute(cellpaddingAttr))) {
bool isControl = s->isControl();
if (isControl != m_element->isControl())
return false;
if (isControl && (s->isEnabled() != m_element->isEnabled()) ||
(s->isIndeterminate() != m_element->isIndeterminate()) ||
(s->isChecked() != m_element->isChecked()))
return false;
if (style->transitions())
return false;
bool classesMatch = true;
if (s->hasClass()) {
const AtomicString& class1 = m_element->getAttribute(classAttr);
const AtomicString& class2 = s->getAttribute(classAttr);
classesMatch = (class1 == class2);
}
if (classesMatch) {
bool mappedAttrsMatch = true;
if (s->hasMappedAttributes())
mappedAttrsMatch = s->mappedAttributes()->mapsEquivalent(m_styledElement->mappedAttributes());
if (mappedAttrsMatch) {
bool linksMatch = true;
if (s->isLink()) {
// We need to check to see if the visited state matches.
if (pseudoState == PseudoUnknown) {
const Color& linkColor = m_element->document()->linkColor();
const Color& visitedColor = m_element->document()->visitedLinkColor();
pseudoState = m_checker.checkPseudoState(m_element, style->pseudoState() != PseudoAnyLink || linkColor != visitedColor);
}
linksMatch = (pseudoState == style->pseudoState());
}
if (linksMatch)
return true;
}
}
}
}
return false;
}
RenderStyle* CSSStyleSelector::locateSharedStyle()
{
if (m_styledElement && !m_styledElement->inlineStyleDecl() && !m_styledElement->hasID() && !m_styledElement->document()->usesSiblingRules()) {
// Check previous siblings.
unsigned count = 0;
Node* n;
for (n = m_element->previousSibling(); n && !n->isElementNode(); n = n->previousSibling()) { }
while (n) {
if (canShareStyleWithElement(n))
return n->renderStyle();
if (count++ == cStyleSearchThreshold)
return 0;
for (n = n->previousSibling(); n && !n->isElementNode(); n = n->previousSibling()) { }
}
if (!n)
n = locateCousinList(static_cast<Element*>(m_element->parentNode()));
while (n) {
if (canShareStyleWithElement(n))
return n->renderStyle();
if (count++ == cStyleSearchThreshold)
return 0;
for (n = n->previousSibling(); n && !n->isElementNode(); n = n->previousSibling()) { }
}
}
return 0;
}
void CSSStyleSelector::matchUARules(int& firstUARule, int& lastUARule)
{
// First we match rules from the user agent sheet.
CSSRuleSet* userAgentStyleSheet = m_medium->mediaTypeMatchSpecific("print")
? defaultPrintStyle : defaultStyle;
matchRules(userAgentStyleSheet, firstUARule, lastUARule);
// In quirks mode, we match rules from the quirks user agent sheet.
if (!m_checker.m_strictParsing)
matchRules(defaultQuirksStyle, firstUARule, lastUARule);
// If we're in view source mode, then we match rules from the view source style sheet.
if (m_checker.m_document->frame() && m_checker.m_document->frame()->inViewSourceMode())
matchRules(defaultViewSourceStyle, firstUARule, lastUARule);
}
// If resolveForRootDefault is true, style based on user agent style sheet only. This is used in media queries, where
// relative units are interpreted according to document root element style, styled only with UA stylesheet
RenderStyle* CSSStyleSelector::styleForElement(Element* e, RenderStyle* defaultParent, bool allowSharing, bool resolveForRootDefault)
{
// Once an element has a renderer, we don't try to destroy it, since otherwise the renderer
// will vanish if a style recalc happens during loading.
if (allowSharing && !e->document()->haveStylesheetsLoaded() && !e->renderer()) {
if (!s_styleNotYetAvailable) {
s_styleNotYetAvailable = ::new RenderStyle;
s_styleNotYetAvailable->ref();
s_styleNotYetAvailable->setDisplay(NONE);
s_styleNotYetAvailable->font().update(m_fontSelector);
}
s_styleNotYetAvailable->ref();
e->document()->setHasNodesWithPlaceholderStyle();
return s_styleNotYetAvailable;
}
initElementAndPseudoState(e);
if (allowSharing) {
m_style = locateSharedStyle();
#ifdef STYLE_SHARING_STATS
fraction += m_style != 0;
total++;
printf("Sharing %d out of %d\n", fraction, total);
#endif
if (m_style) {
m_style->ref();
return m_style;
}
}
initForStyleResolve(e, defaultParent);
if (resolveForRootDefault) {
m_style = ::new RenderStyle();
// don't ref, because we want to delete this, but we cannot unref it
} else {
m_style = new (e->document()->renderArena()) RenderStyle();
m_style->ref();
}
if (m_parentStyle)
m_style->inheritFrom(m_parentStyle);
else
m_parentStyle = m_style;
#if ENABLE(SVG)
static bool loadedSVGUserAgentSheet;
if (e->isSVGElement() && !loadedSVGUserAgentSheet) {
// SVG rules.
loadedSVGUserAgentSheet = true;
CSSStyleSheet* svgSheet = parseUASheet(svgUserAgentStyleSheet, sizeof(svgUserAgentStyleSheet));
defaultStyle->addRulesFromSheet(svgSheet, screenEval());
defaultPrintStyle->addRulesFromSheet(svgSheet, printEval());
}
#endif
int firstUARule = -1, lastUARule = -1;
int firstUserRule = -1, lastUserRule = -1;
int firstAuthorRule = -1, lastAuthorRule = -1;
matchUARules(firstUARule, lastUARule);
if (!resolveForRootDefault) {
// 4. Now we check user sheet rules.
if (m_matchAuthorAndUserStyles)
matchRules(m_userStyle, firstUserRule, lastUserRule);
// 5. Now check author rules, beginning first with presentational attributes
// mapped from HTML.
if (m_styledElement) {
// Ask if the HTML element has mapped attributes.
if (m_styledElement->hasMappedAttributes()) {
// Walk our attribute list and add in each decl.
const NamedMappedAttrMap* map = m_styledElement->mappedAttributes();
for (unsigned i = 0; i < map->length(); i++) {
Attribute* attr = map->attributeItem(i);
if (attr->isMappedAttribute()) {
MappedAttribute* mappedAttr = static_cast<MappedAttribute*>(attr);
if (mappedAttr->decl()) {
lastAuthorRule = m_matchedDecls.size();
if (firstAuthorRule == -1)
firstAuthorRule = lastAuthorRule;
addMatchedDeclaration(mappedAttr->decl());
}
}
}
}
// Now we check additional mapped declarations.
// Tables and table cells share an additional mapped rule that must be applied
// after all attributes, since their mapped style depends on the values of multiple attributes.
if (m_styledElement->canHaveAdditionalAttributeStyleDecls()) {
m_additionalAttributeStyleDecls.clear();
m_styledElement->additionalAttributeStyleDecls(m_additionalAttributeStyleDecls);
if (!m_additionalAttributeStyleDecls.isEmpty()) {
unsigned additionalDeclsSize = m_additionalAttributeStyleDecls.size();
if (firstAuthorRule == -1)
firstAuthorRule = m_matchedDecls.size();
lastAuthorRule = m_matchedDecls.size() + additionalDeclsSize - 1;
for (unsigned i = 0; i < additionalDeclsSize; i++)
addMatchedDeclaration(m_additionalAttributeStyleDecls[i]);
}
}
}
// 6. Check the rules in author sheets next.
if (m_matchAuthorAndUserStyles)
matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule);
// 7. Now check our inline style attribute.
if (m_matchAuthorAndUserStyles && m_styledElement) {
CSSMutableStyleDeclaration* inlineDecl = m_styledElement->inlineStyleDecl();
if (inlineDecl) {
lastAuthorRule = m_matchedDecls.size();
if (firstAuthorRule == -1)
firstAuthorRule = lastAuthorRule;
addMatchedDeclaration(inlineDecl);
}
}
}
// Now we have all of the matched rules in the appropriate order. Walk the rules and apply
// high-priority properties first, i.e., those properties that other properties depend on.
// The order is (1) high-priority not important, (2) high-priority important, (3) normal not important
// and (4) normal important.
m_lineHeightValue = 0;
applyDeclarations(true, false, 0, m_matchedDecls.size() - 1);
if (!resolveForRootDefault) {
applyDeclarations(true, true, firstAuthorRule, lastAuthorRule);
applyDeclarations(true, true, firstUserRule, lastUserRule);
}
applyDeclarations(true, true, firstUARule, lastUARule);
// If our font got dirtied, go ahead and update it now.
if (m_fontDirty)
updateFont();
// Line-height is set when we are sure we decided on the font-size
if (m_lineHeightValue)
applyProperty(CSSPropertyLineHeight, m_lineHeightValue);
// Now do the normal priority UA properties.
applyDeclarations(false, false, firstUARule, lastUARule);
// Cache our border and background so that we can examine them later.
cacheBorderAndBackground();
// Now do the author and user normal priority properties and all the !important properties.
if (!resolveForRootDefault) {
applyDeclarations(false, false, lastUARule + 1, m_matchedDecls.size() - 1);
applyDeclarations(false, true, firstAuthorRule, lastAuthorRule);
applyDeclarations(false, true, firstUserRule, lastUserRule);
}
applyDeclarations(false, true, firstUARule, lastUARule);
// If our font got dirtied by one of the non-essential font props,
// go ahead and update it a second time.
if (m_fontDirty)
updateFont();
// Clean up our style object's display and text decorations (among other fixups).
adjustRenderStyle(m_style, e);
// If we are a link, cache the determined pseudo-state.
if (e->isLink())
m_style->setPseudoState(pseudoState);
// If we have first-letter pseudo style, do not share this style
if (m_style->hasPseudoStyle(RenderStyle::FIRST_LETTER))
m_style->setUnique();
// Now return the style.
return m_style;
}
RenderStyle* CSSStyleSelector::pseudoStyleForElement(RenderStyle::PseudoId pseudo, Element* e, RenderStyle* parentStyle)
{
if (!e)
return 0;
initElementAndPseudoState(e);
initForStyleResolve(e, parentStyle, pseudo);
m_style = parentStyle;
// Since we don't use pseudo-elements in any of our quirk/print user agent rules, don't waste time walking
// those rules.
// Check UA, user and author rules.
int firstUARule = -1, lastUARule = -1, firstUserRule = -1, lastUserRule = -1, firstAuthorRule = -1, lastAuthorRule = -1;
matchUARules(firstUARule, lastUARule);
if (m_matchAuthorAndUserStyles) {
matchRules(m_userStyle, firstUserRule, lastUserRule);
matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule);
}
if (m_matchedDecls.isEmpty())
return 0;
m_style = new (e->document()->renderArena()) RenderStyle();
m_style->ref();
if (parentStyle)
m_style->inheritFrom(parentStyle);
m_style->noninherited_flags._styleType = pseudo;
m_lineHeightValue = 0;
// High-priority properties.
applyDeclarations(true, false, 0, m_matchedDecls.size() - 1);
applyDeclarations(true, true, firstAuthorRule, lastAuthorRule);
applyDeclarations(true, true, firstUserRule, lastUserRule);
applyDeclarations(true, true, firstUARule, lastUARule);
// If our font got dirtied, go ahead and update it now.
if (m_fontDirty)
updateFont();
// Line-height is set when we are sure we decided on the font-size
if (m_lineHeightValue)
applyProperty(CSSPropertyLineHeight, m_lineHeightValue);
// Now do the normal priority properties.
applyDeclarations(false, false, firstUARule, lastUARule);
// Cache our border and background so that we can examine them later.
cacheBorderAndBackground();
applyDeclarations(false, false, lastUARule + 1, m_matchedDecls.size() - 1);
applyDeclarations(false, true, firstAuthorRule, lastAuthorRule);
applyDeclarations(false, true, firstUserRule, lastUserRule);
applyDeclarations(false, true, firstUARule, lastUARule);
// If our font got dirtied by one of the non-essential font props,
// go ahead and update it a second time.
if (m_fontDirty)
updateFont();
// Clean up our style object's display and text decorations (among other fixups).
adjustRenderStyle(m_style, 0);
// Now return the style.
return m_style;
}
static void addIntrinsicMargins(RenderStyle* style)
{
// Intrinsic margin value.
const int intrinsicMargin = 2;
// FIXME: Using width/height alone and not also dealing with min-width/max-width is flawed.
// FIXME: Using "quirk" to decide the margin wasn't set is kind of lame.
if (style->width().isIntrinsicOrAuto()) {
if (style->marginLeft().quirk())
style->setMarginLeft(Length(intrinsicMargin, Fixed));
if (style->marginRight().quirk())
style->setMarginRight(Length(intrinsicMargin, Fixed));
}
if (style->height().isAuto()) {
if (style->marginTop().quirk())
style->setMarginTop(Length(intrinsicMargin, Fixed));
if (style->marginBottom().quirk())
style->setMarginBottom(Length(intrinsicMargin, Fixed));
}
}
void CSSStyleSelector::adjustRenderStyle(RenderStyle* style, Element *e)
{
// Cache our original display.
style->setOriginalDisplay(style->display());
if (style->display() != NONE) {
// If we have a <td> that specifies a float property, in quirks mode we just drop the float
// property.
// Sites also commonly use display:inline/block on <td>s and <table>s. In quirks mode we force
// these tags to retain their display types.
if (!m_checker.m_strictParsing && e) {
if (e->hasTagName(tdTag)) {
style->setDisplay(TABLE_CELL);
style->setFloating(FNONE);
}
else if (e->hasTagName(tableTag))
style->setDisplay(style->isDisplayInlineType() ? INLINE_TABLE : TABLE);
}
// Tables never support the -webkit-* values for text-align and will reset back to the default.
if (e && e->hasTagName(tableTag) && (style->textAlign() == WEBKIT_LEFT || style->textAlign() == WEBKIT_CENTER || style->textAlign() == WEBKIT_RIGHT))
style->setTextAlign(TAAUTO);
// Frames and framesets never honor position:relative or position:absolute. This is necessary to
// fix a crash where a site tries to position these objects. They also never honor display.
if (e && (e->hasTagName(frameTag) || e->hasTagName(framesetTag))) {
style->setPosition(StaticPosition);
style->setDisplay(BLOCK);
}
// Table headers with a text-align of auto will change the text-align to center.
if (e && e->hasTagName(thTag) && style->textAlign() == TAAUTO)
style->setTextAlign(CENTER);
// Mutate the display to BLOCK or TABLE for certain cases, e.g., if someone attempts to
// position or float an inline, compact, or run-in. Cache the original display, since it
// may be needed for positioned elements that have to compute their static normal flow
// positions. We also force inline-level roots to be block-level.
if (style->display() != BLOCK && style->display() != TABLE && style->display() != BOX &&
(style->position() == AbsolutePosition || style->position() == FixedPosition || style->floating() != FNONE ||
(e && e->document()->documentElement() == e))) {
if (style->display() == INLINE_TABLE)
style->setDisplay(TABLE);
else if (style->display() == INLINE_BOX)
style->setDisplay(BOX);
else if (style->display() == LIST_ITEM) {
// It is a WinIE bug that floated list items lose their bullets, so we'll emulate the quirk,
// but only in quirks mode.
if (!m_checker.m_strictParsing && style->floating() != FNONE)
style->setDisplay(BLOCK);
}
else
style->setDisplay(BLOCK);
}
// After performing the display mutation, check table rows. We do not honor position:relative on
// table rows or cells. This has been established in CSS2.1 (and caused a crash in containingBlock()
// on some sites).
if ((style->display() == TABLE_HEADER_GROUP || style->display() == TABLE_ROW_GROUP ||
style->display() == TABLE_FOOTER_GROUP || style->display() == TABLE_ROW || style->display() == TABLE_CELL) &&
style->position() == RelativePosition)
style->setPosition(StaticPosition);
}
// Make sure our z-index value is only applied if the object is positioned.
if (style->position() == StaticPosition)
style->setHasAutoZIndex();
// Auto z-index becomes 0 for the root element and transparent objects. This prevents
// cases where objects that should be blended as a single unit end up with a non-transparent
// object wedged in between them. Auto z-index also becomes 0 for objects that specify transforms/masks/reflections.
if (style->hasAutoZIndex() && ((e && e->document()->documentElement() == e) || style->opacity() < 1.0f ||
style->hasTransform() || style->hasMask() || style->boxReflect()))
style->setZIndex(0);
// Button, legend, input, select and textarea all consider width values of 'auto' to be 'intrinsic'.
// This will be important when we use block flows for all form controls.
if (e && (e->hasTagName(legendTag) || e->hasTagName(buttonTag) || e->hasTagName(inputTag) ||
e->hasTagName(selectTag) || e->hasTagName(textareaTag))) {
if (style->width().isAuto())
style->setWidth(Length(Intrinsic));
}
// Finally update our text decorations in effect, but don't allow text-decoration to percolate through
// tables, inline blocks, inline tables, or run-ins.
if (style->display() == TABLE || style->display() == INLINE_TABLE || style->display() == RUN_IN
|| style->display() == INLINE_BLOCK || style->display() == INLINE_BOX)
style->setTextDecorationsInEffect(style->textDecoration());
else
style->addToTextDecorationsInEffect(style->textDecoration());
// If either overflow value is not visible, change to auto.
if (style->overflowX() == OMARQUEE && style->overflowY() != OMARQUEE)
style->setOverflowY(OMARQUEE);
else if (style->overflowY() == OMARQUEE && style->overflowX() != OMARQUEE)
style->setOverflowX(OMARQUEE);
else if (style->overflowX() == OVISIBLE && style->overflowY() != OVISIBLE)
style->setOverflowX(OAUTO);
else if (style->overflowY() == OVISIBLE && style->overflowX() != OVISIBLE)
style->setOverflowY(OAUTO);
// Table rows, sections and the table itself will support overflow:hidden and will ignore scroll/auto.
// FIXME: Eventually table sections will support auto and scroll.
if (style->display() == TABLE || style->display() == INLINE_TABLE ||
style->display() == TABLE_ROW_GROUP || style->display() == TABLE_ROW) {
if (style->overflowX() != OVISIBLE && style->overflowX() != OHIDDEN)
style->setOverflowX(OVISIBLE);
if (style->overflowY() != OVISIBLE && style->overflowY() != OHIDDEN)
style->setOverflowY(OVISIBLE);
}
// Cull out any useless layers and also repeat patterns into additional layers.
style->adjustBackgroundLayers();
style->adjustMaskLayers();
// Do the same for transitions.
style->adjustTransitions();
// Important: Intrinsic margins get added to controls before the theme has adjusted the style, since the theme will
// alter fonts and heights/widths.
if (e && e->isControl() && style->fontSize() >= 11) {
// Don't apply intrinsic margins to image buttons. The designer knows how big the images are,
// so we have to treat all image buttons as though they were explicitly sized.
if (!e->hasTagName(inputTag) || static_cast<HTMLInputElement*>(e)->inputType() != HTMLInputElement::IMAGE)
addIntrinsicMargins(style);
}
// Let the theme also have a crack at adjusting the style.
if (style->hasAppearance())
theme()->adjustStyle(this, style, e, m_hasUAAppearance, m_borderData, m_backgroundData, m_backgroundColor);
#if ENABLE(SVG)
if (e && e->isSVGElement()) {
// Spec: http://www.w3.org/TR/SVG/masking.html#OverflowProperty
if (style->overflowY() == OSCROLL)
style->setOverflowY(OHIDDEN);
else if (style->overflowY() == OAUTO)
style->setOverflowY(OVISIBLE);
if (style->overflowX() == OSCROLL)
style->setOverflowX(OHIDDEN);
else if (style->overflowX() == OAUTO)
style->setOverflowX(OVISIBLE);
// Only the root <svg> element in an SVG document fragment tree honors css position
if (!(e->hasTagName(SVGNames::svgTag) && e->parentNode() && !e->parentNode()->isSVGElement()))
style->setPosition(RenderStyle::initialPosition());
}
#endif
}
void CSSStyleSelector::updateFont()
{
checkForTextSizeAdjust();
checkForGenericFamilyChange(m_style, m_parentStyle);
checkForZoomChange(m_style, m_parentStyle);
m_style->font().update(m_fontSelector);
m_fontDirty = false;
}
void CSSStyleSelector::cacheBorderAndBackground()
{
m_hasUAAppearance = m_style->hasAppearance();
if (m_hasUAAppearance) {
m_borderData = m_style->border();
m_backgroundData = *m_style->backgroundLayers();
m_backgroundColor = m_style->backgroundColor();
}
}
PassRefPtr<CSSRuleList> CSSStyleSelector::styleRulesForElement(Element* e, bool authorOnly)
{
if (!e || !e->document()->haveStylesheetsLoaded())
return 0;
m_checker.m_collectRulesOnly = true;
initElementAndPseudoState(e);
initForStyleResolve(e);
if (!authorOnly) {
int firstUARule = -1, lastUARule = -1;
// First we match rules from the user agent sheet.
matchUARules(firstUARule, lastUARule);
// Now we check user sheet rules.
if (m_matchAuthorAndUserStyles) {
int firstUserRule = -1, lastUserRule = -1;
matchRules(m_userStyle, firstUserRule, lastUserRule);
}
}
if (m_matchAuthorAndUserStyles) {
// Check the rules in author sheets.
int firstAuthorRule = -1, lastAuthorRule = -1;
matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule);
}
m_checker.m_collectRulesOnly = false;
return m_ruleList.release();
}
PassRefPtr<CSSRuleList> CSSStyleSelector::pseudoStyleRulesForElement(Element*, const String& pseudoStyle, bool authorOnly)
{
// FIXME: Implement this.
return 0;
}
bool CSSStyleSelector::checkSelector(CSSSelector* sel)
{
m_dynamicPseudo = RenderStyle::NOPSEUDO;
// Check the selector
SelectorMatch match = m_checker.checkSelector(sel, m_element, &m_selectorAttrs, m_dynamicPseudo, true, false, m_style, m_parentStyle);
if (match != SelectorMatches)
return false;
if (m_checker.m_pseudoStyle != RenderStyle::NOPSEUDO && m_checker.m_pseudoStyle != m_dynamicPseudo)
return false;
return true;
}
// Recursive check of selectors and combinators
// It can return 3 different values:
// * SelectorMatches - the selector matches the element e
// * SelectorFailsLocally - the selector fails for the element e
// * SelectorFailsCompletely - the selector fails for e and any sibling or ancestor of e
CSSStyleSelector::SelectorMatch CSSStyleSelector::SelectorChecker::checkSelector(CSSSelector* sel, Element* e, HashSet<AtomicStringImpl*>* selectorAttrs, RenderStyle::PseudoId& dynamicPseudo, bool isAncestor, bool isSubSelector, RenderStyle* elementStyle, RenderStyle* elementParentStyle) const
{
#if ENABLE(SVG)
// Spec: CSS2 selectors cannot be applied to the (conceptually) cloned DOM tree
// because its contents are not part of the formal document structure.
if (e->isSVGElement() && e->isShadowNode())
return SelectorFailsCompletely;
#endif
// first selector has to match
if (!checkOneSelector(sel, e, selectorAttrs, dynamicPseudo, isAncestor, isSubSelector, elementStyle, elementParentStyle))
return SelectorFailsLocally;
// The rest of the selectors has to match
CSSSelector::Relation relation = sel->relation();
// Prepare next sel
sel = sel->m_tagHistory;
if (!sel)
return SelectorMatches;
if (relation != CSSSelector::SubSelector)
// Bail-out if this selector is irrelevant for the pseudoStyle
if (m_pseudoStyle != RenderStyle::NOPSEUDO && m_pseudoStyle != dynamicPseudo)
return SelectorFailsCompletely;
switch (relation) {
case CSSSelector::Descendant:
while (true) {
Node* n = e->parentNode();
if (!n || !n->isElementNode())
return SelectorFailsCompletely;
e = static_cast<Element*>(n);
SelectorMatch match = checkSelector(sel, e, selectorAttrs, dynamicPseudo, true, false);
if (match != SelectorFailsLocally)
return match;
}
break;
case CSSSelector::Child:
{
Node* n = e->parentNode();
if (!n || !n->isElementNode())
return SelectorFailsCompletely;
e = static_cast<Element*>(n);
return checkSelector(sel, e, selectorAttrs, dynamicPseudo, true, false);
}
case CSSSelector::DirectAdjacent:
{
if (!m_collectRulesOnly && e->parentNode() && e->parentNode()->isElementNode()) {
RenderStyle* parentStyle = elementStyle ? elementParentStyle : e->parentNode()->renderStyle();
if (parentStyle)
parentStyle->setChildrenAffectedByDirectAdjacentRules();
}
Node* n = e->previousSibling();
while (n && !n->isElementNode())
n = n->previousSibling();
if (!n)
return SelectorFailsLocally;
e = static_cast<Element*>(n);
return checkSelector(sel, e, selectorAttrs, dynamicPseudo, false, false);
}
case CSSSelector::IndirectAdjacent:
if (!m_collectRulesOnly && e->parentNode() && e->parentNode()->isElementNode()) {
RenderStyle* parentStyle = elementStyle ? elementParentStyle : e->parentNode()->renderStyle();
if (parentStyle)
parentStyle->setChildrenAffectedByForwardPositionalRules();
}
while (true) {
Node* n = e->previousSibling();
while (n && !n->isElementNode())
n = n->previousSibling();
if (!n)
return SelectorFailsLocally;
e = static_cast<Element*>(n);
SelectorMatch match = checkSelector(sel, e, selectorAttrs, dynamicPseudo, false, false);
if (match != SelectorFailsLocally)
return match;
};
break;
case CSSSelector::SubSelector:
// a selector is invalid if something follows a pseudo-element
if (elementStyle && dynamicPseudo != RenderStyle::NOPSEUDO)
return SelectorFailsCompletely;
return checkSelector(sel, e, selectorAttrs, dynamicPseudo, isAncestor, true, elementStyle, elementParentStyle);
}
return SelectorFailsCompletely;
}
static void addLocalNameToSet(HashSet<AtomicStringImpl*>* set, const QualifiedName& qName)
{
set->add(qName.localName().impl());
}
static HashSet<AtomicStringImpl*>* createHtmlCaseInsensitiveAttributesSet()
{
// This is the list of attributes in HTML 4.01 with values marked as "[CI]" or case-insensitive
// Mozilla treats all other values as case-sensitive, thus so do we.
HashSet<AtomicStringImpl*>* attrSet = new HashSet<AtomicStringImpl*>;
addLocalNameToSet(attrSet, accept_charsetAttr);
addLocalNameToSet(attrSet, acceptAttr);
addLocalNameToSet(attrSet, alignAttr);
addLocalNameToSet(attrSet, alinkAttr);
addLocalNameToSet(attrSet, axisAttr);
addLocalNameToSet(attrSet, bgcolorAttr);
addLocalNameToSet(attrSet, charsetAttr);
addLocalNameToSet(attrSet, checkedAttr);
addLocalNameToSet(attrSet, clearAttr);
addLocalNameToSet(attrSet, codetypeAttr);
addLocalNameToSet(attrSet, colorAttr);
addLocalNameToSet(attrSet, compactAttr);
addLocalNameToSet(attrSet, declareAttr);
addLocalNameToSet(attrSet, deferAttr);
addLocalNameToSet(attrSet, dirAttr);
addLocalNameToSet(attrSet, disabledAttr);
addLocalNameToSet(attrSet, enctypeAttr);
addLocalNameToSet(attrSet, faceAttr);
addLocalNameToSet(attrSet, frameAttr);
addLocalNameToSet(attrSet, hreflangAttr);
addLocalNameToSet(attrSet, http_equivAttr);
addLocalNameToSet(attrSet, langAttr);
addLocalNameToSet(attrSet, languageAttr);
addLocalNameToSet(attrSet, linkAttr);
addLocalNameToSet(attrSet, mediaAttr);
addLocalNameToSet(attrSet, methodAttr);
addLocalNameToSet(attrSet, multipleAttr);
addLocalNameToSet(attrSet, nohrefAttr);
addLocalNameToSet(attrSet, noresizeAttr);
addLocalNameToSet(attrSet, noshadeAttr);
addLocalNameToSet(attrSet, nowrapAttr);
addLocalNameToSet(attrSet, readonlyAttr);
addLocalNameToSet(attrSet, relAttr);
addLocalNameToSet(attrSet, revAttr);
addLocalNameToSet(attrSet, rulesAttr);
addLocalNameToSet(attrSet, scopeAttr);
addLocalNameToSet(attrSet, scrollingAttr);
addLocalNameToSet(attrSet, selectedAttr);
addLocalNameToSet(attrSet, shapeAttr);
addLocalNameToSet(attrSet, targetAttr);
addLocalNameToSet(attrSet, textAttr);
addLocalNameToSet(attrSet, typeAttr);
addLocalNameToSet(attrSet, valignAttr);
addLocalNameToSet(attrSet, valuetypeAttr);
addLocalNameToSet(attrSet, vlinkAttr);
return attrSet;
}
static bool htmlAttributeHasCaseInsensitiveValue(const QualifiedName& attr)
{
static HashSet<AtomicStringImpl*>* htmlCaseInsensitiveAttributesSet = createHtmlCaseInsensitiveAttributesSet();
bool isPossibleHTMLAttr = !attr.hasPrefix() && (attr.namespaceURI() == nullAtom);
return isPossibleHTMLAttr && htmlCaseInsensitiveAttributesSet->contains(attr.localName().impl());
}
bool CSSStyleSelector::SelectorChecker::checkOneSelector(CSSSelector* sel, Element* e, HashSet<AtomicStringImpl*>* selectorAttrs, RenderStyle::PseudoId& dynamicPseudo, bool isAncestor, bool isSubSelector, RenderStyle* elementStyle, RenderStyle* elementParentStyle) const
{
if (!e)
return false;
if (sel->hasTag()) {
const AtomicString& selLocalName = sel->m_tag.localName();
if (selLocalName != starAtom && selLocalName != e->localName())
return false;
const AtomicString& selNS = sel->m_tag.namespaceURI();
if (selNS != starAtom && selNS != e->namespaceURI())
return false;
}
if (sel->hasAttribute()) {
if (sel->m_match == CSSSelector::Class)
return e->hasClass() && static_cast<StyledElement*>(e)->classNames().contains(sel->m_value);
if (sel->m_match == CSSSelector::Id)
return e->hasID() && e->getIDAttribute() == sel->m_value;
// FIXME: Handle the case were elementStyle is 0.
if (elementStyle && (!e->isStyledElement() || (!static_cast<StyledElement*>(e)->isMappedAttribute(sel->m_attr) && sel->m_attr != typeAttr && sel->m_attr != readonlyAttr))) {
elementStyle->setAffectedByAttributeSelectors(); // Special-case the "type" and "readonly" attributes so input form controls can share style.
if (selectorAttrs)
selectorAttrs->add(sel->m_attr.localName().impl());
}
const AtomicString& value = e->getAttribute(sel->m_attr);
if (value.isNull())
return false; // attribute is not set
bool caseSensitive = !m_documentIsHTML || !htmlAttributeHasCaseInsensitiveValue(sel->m_attr);
switch (sel->m_match) {
case CSSSelector::Exact:
if (caseSensitive ? sel->m_value != value : !equalIgnoringCase(sel->m_value, value))
return false;
break;
case CSSSelector::List:
{
// Ignore empty selectors or selectors containing spaces
if (sel->m_value.contains(' ') || sel->m_value.isEmpty())
return false;
int startSearchAt = 0;
while (true) {
int foundPos = value.find(sel->m_value, startSearchAt, caseSensitive);
if (foundPos == -1)
return false;
if (foundPos == 0 || value[foundPos-1] == ' ') {
unsigned endStr = foundPos + sel->m_value.length();
if (endStr == value.length() || value[endStr] == ' ')
break; // We found a match.
}
// No match. Keep looking.
startSearchAt = foundPos + 1;
}
break;
}
case CSSSelector::Contain:
if (!value.contains(sel->m_value, caseSensitive) || sel->m_value.isEmpty())
return false;
break;
case CSSSelector::Begin:
if (!value.startsWith(sel->m_value, caseSensitive) || sel->m_value.isEmpty())
return false;
break;
case CSSSelector::End:
if (!value.endsWith(sel->m_value, caseSensitive) || sel->m_value.isEmpty())
return false;
break;
case CSSSelector::Hyphen:
if (value.length() < sel->m_value.length())
return false;
if (!value.startsWith(sel->m_value, caseSensitive))
return false;
// It they start the same, check for exact match or following '-':
if (value.length() != sel->m_value.length() && value[sel->m_value.length()] != '-')
return false;
break;
case CSSSelector::PseudoClass:
case CSSSelector::PseudoElement:
default:
break;
}
}
if (sel->m_match == CSSSelector::PseudoClass) {
switch (sel->pseudoType()) {
// Pseudo classes:
case CSSSelector::PseudoEmpty: {
bool result = true;
for (Node* n = e->firstChild(); n; n = n->nextSibling()) {
if (n->isElementNode()) {
result = false;
break;
} else if (n->isTextNode()) {
Text* textNode = static_cast<Text*>(n);
if (!textNode->data().isEmpty()) {
result = false;
break;
}
}
}
if (!m_collectRulesOnly) {
if (elementStyle)
elementStyle->setEmptyState(result);
else if (e->renderStyle() && (e->document()->usesSiblingRules() || e->renderStyle()->unique()))
e->renderStyle()->setEmptyState(result);
}
return result;
}
case CSSSelector::PseudoFirstChild: {
// first-child matches the first child that is an element
if (e->parentNode() && e->parentNode()->isElementNode()) {
bool result = false;
Node* n = e->previousSibling();
while (n && !n->isElementNode())
n = n->previousSibling();
if (!n)
result = true;
if (!m_collectRulesOnly) {
RenderStyle* childStyle = elementStyle ? elementStyle : e->renderStyle();
RenderStyle* parentStyle = elementStyle ? elementParentStyle : e->parentNode()->renderStyle();
if (parentStyle)
parentStyle->setChildrenAffectedByFirstChildRules();
if (result && childStyle)
childStyle->setFirstChildState();
}
return result;
}
break;
}
case CSSSelector::PseudoFirstOfType: {
// first-of-type matches the first element of its type
if (e->parentNode() && e->parentNode()->isElementNode()) {
bool result = false;
const QualifiedName& type = e->tagQName();
Node* n = e->previousSibling();
while (n) {
if (n->isElementNode() && static_cast<Element*>(n)->hasTagName(type))
break;
n = n->previousSibling();
}
if (!n)
result = true;
if (!m_collectRulesOnly) {
RenderStyle* parentStyle = elementStyle ? elementParentStyle : e->parentNode()->renderStyle();
if (parentStyle)
parentStyle->setChildrenAffectedByForwardPositionalRules();
}
return result;
}
break;
}
case CSSSelector::PseudoLastChild: {
// last-child matches the last child that is an element
if (e->parentNode() && e->parentNode()->isElementNode()) {
Element* parentNode = static_cast<Element*>(e->parentNode());
bool result = false;
if (parentNode->isFinishedParsingChildren()) {
Node* n = e->nextSibling();
while (n && !n->isElementNode())
n = n->nextSibling();
if (!n)
result = true;
}
if (!m_collectRulesOnly) {
RenderStyle* childStyle = elementStyle ? elementStyle : e->renderStyle();
RenderStyle* parentStyle = elementStyle ? elementParentStyle : parentNode->renderStyle();
if (parentStyle)
parentStyle->setChildrenAffectedByLastChildRules();
if (result && childStyle)
childStyle->setLastChildState();
}
return result;
}
break;
}
case CSSSelector::PseudoLastOfType: {
// last-of-type matches the last element of its type
if (e->parentNode() && e->parentNode()->isElementNode()) {
Element* parentNode = static_cast<Element*>(e->parentNode());
if (!m_collectRulesOnly) {
RenderStyle* parentStyle = elementStyle ? elementParentStyle : parentNode->renderStyle();
if (parentStyle)
parentStyle->setChildrenAffectedByBackwardPositionalRules();
}
if (!parentNode->isFinishedParsingChildren())
return false;
bool result = false;
const QualifiedName& type = e->tagQName();
Node* n = e->nextSibling();
while (n) {
if (n->isElementNode() && static_cast<Element*>(n)->hasTagName(type))
break;
n = n->nextSibling();
}
if (!n)
result = true;
return result;
}
break;
}
case CSSSelector::PseudoOnlyChild: {
if (e->parentNode() && e->parentNode()->isElementNode()) {
Element* parentNode = static_cast<Element*>(e->parentNode());
bool firstChild = false;
bool lastChild = false;
Node* n = e->previousSibling();
while (n && !n->isElementNode())
n = n->previousSibling();
if (!n)
firstChild = true;
if (firstChild && parentNode->isFinishedParsingChildren()) {
n = e->nextSibling();
while (n && !n->isElementNode())
n = n->nextSibling();
if (!n)
lastChild = true;
}
if (!m_collectRulesOnly) {
RenderStyle* childStyle = elementStyle ? elementStyle : e->renderStyle();
RenderStyle* parentStyle = elementStyle ? elementParentStyle : parentNode->renderStyle();
if (parentStyle) {
parentStyle->setChildrenAffectedByFirstChildRules();
parentStyle->setChildrenAffectedByLastChildRules();
}
if (firstChild && childStyle)
childStyle->setFirstChildState();
if (lastChild && childStyle)
childStyle->setLastChildState();
}
return firstChild && lastChild;
}
break;
}
case CSSSelector::PseudoOnlyOfType: {
// FIXME: This selector is very slow.
if (e->parentNode() && e->parentNode()->isElementNode()) {
Element* parentNode = static_cast<Element*>(e->parentNode());
if (!m_collectRulesOnly) {
RenderStyle* parentStyle = elementStyle ? elementParentStyle : parentNode->renderStyle();
if (parentStyle) {
parentStyle->setChildrenAffectedByForwardPositionalRules();
parentStyle->setChildrenAffectedByBackwardPositionalRules();
}
}
if (!parentNode->isFinishedParsingChildren())
return false;
bool firstChild = false;
bool lastChild = false;
const QualifiedName& type = e->tagQName();
Node* n = e->previousSibling();
while (n) {
if (n->isElementNode() && static_cast<Element*>(n)->hasTagName(type))
break;
n = n->previousSibling();
}
if (!n)
firstChild = true;
if (firstChild) {
n = e->nextSibling();
while (n) {
if (n->isElementNode() && static_cast<Element*>(n)->hasTagName(type))
break;
n = n->nextSibling();
}
if (!n)
lastChild = true;
}
return firstChild && lastChild;
}
break;
}
case CSSSelector::PseudoNthChild: {
int a, b;
// calculate a and b every time we run through checkOneSelector
// this should probably be saved after we calculate it once, but currently
// would require increasing the size of CSSSelector
if (!parseNth(sel->m_argument, a, b))
break;
if (e->parentNode() && e->parentNode()->isElementNode()) {
int count = 1;
Node* n = e->previousSibling();
while (n) {
if (n->isElementNode()) {
RenderStyle* s = n->renderStyle();
unsigned index = s ? s->childIndex() : 0;
if (index) {
count += index;
break;
}
count++;
}
n = n->previousSibling();
}
if (!m_collectRulesOnly) {
RenderStyle* childStyle = elementStyle ? elementStyle : e->renderStyle();
RenderStyle* parentStyle = elementStyle ? elementParentStyle : e->parentNode()->renderStyle();
if (childStyle)
childStyle->setChildIndex(count);
if (parentStyle)
parentStyle->setChildrenAffectedByForwardPositionalRules();
}
if (matchNth(count, a, b))
return true;
}
break;
}
case CSSSelector::PseudoNthOfType: {
// FIXME: This selector is very slow.
int a, b;
// calculate a and b every time we run through checkOneSelector (see above)
if (!parseNth(sel->m_argument, a, b))
break;
if (e->parentNode() && e->parentNode()->isElementNode()) {
int count = 1;
const QualifiedName& type = e->tagQName();
Node* n = e->previousSibling();
while (n) {
if (n->isElementNode() && static_cast<Element*>(n)->hasTagName(type))
count++;
n = n->previousSibling();
}
if (!m_collectRulesOnly) {
RenderStyle* parentStyle = elementStyle ? elementParentStyle : e->parentNode()->renderStyle();
if (parentStyle)
parentStyle->setChildrenAffectedByForwardPositionalRules();
}
if (matchNth(count, a, b))
return true;
}
break;
}
case CSSSelector::PseudoNthLastChild: {
int a, b;
// calculate a and b every time we run through checkOneSelector
// this should probably be saved after we calculate it once, but currently
// would require increasing the size of CSSSelector
if (!parseNth(sel->m_argument, a, b))
break;
if (e->parentNode() && e->parentNode()->isElementNode()) {
Element* parentNode = static_cast<Element*>(e->parentNode());
if (!m_collectRulesOnly) {
RenderStyle* parentStyle = elementStyle ? elementParentStyle : parentNode->renderStyle();
if (parentStyle)
parentStyle->setChildrenAffectedByBackwardPositionalRules();
}
if (!parentNode->isFinishedParsingChildren())
return false;
int count = 1;
Node* n = e->nextSibling();
while (n) {
if (n->isElementNode())
count++;
n = n->nextSibling();
}
if (matchNth(count, a, b))
return true;
}
break;
}
case CSSSelector::PseudoNthLastOfType: {
// FIXME: This selector is very slow.
int a, b;
// calculate a and b every time we run through checkOneSelector (see above)
if (!parseNth(sel->m_argument, a, b))
break;
if (e->parentNode() && e->parentNode()->isElementNode()) {
Element* parentNode = static_cast<Element*>(e->parentNode());
if (!m_collectRulesOnly) {
RenderStyle* parentStyle = elementStyle ? elementParentStyle : parentNode->renderStyle();
if (parentStyle)
parentStyle->setChildrenAffectedByBackwardPositionalRules();
}
if (!parentNode->isFinishedParsingChildren())
return false;
int count = 1;
const QualifiedName& type = e->tagQName();
Node* n = e->nextSibling();
while (n) {
if (n->isElementNode() && static_cast<Element*>(n)->hasTagName(type))
count++;
n = n->nextSibling();
}
if (matchNth(count, a, b))
return true;
}
break;
}
case CSSSelector::PseudoTarget:
if (e == e->document()->getCSSTarget())
return true;
break;
case CSSSelector::PseudoAnyLink:
if (pseudoState == PseudoUnknown)
pseudoState = checkPseudoState(e, false);
if (pseudoState == PseudoAnyLink || pseudoState == PseudoLink || pseudoState == PseudoVisited)
return true;
break;
case CSSSelector::PseudoAutofill:
if (e && e->hasTagName(inputTag))
return static_cast<HTMLInputElement*>(e)->autofilled();
break;
case CSSSelector::PseudoLink:
if (pseudoState == PseudoUnknown || pseudoState == PseudoAnyLink)
pseudoState = checkPseudoState(e);
if (pseudoState == PseudoLink)
return true;
break;
case CSSSelector::PseudoVisited:
if (pseudoState == PseudoUnknown || pseudoState == PseudoAnyLink)
pseudoState = checkPseudoState(e);
if (pseudoState == PseudoVisited)
return true;
break;
case CSSSelector::PseudoDrag: {
if (elementStyle)
elementStyle->setAffectedByDragRules(true);
else if (e->renderStyle())
e->renderStyle()->setAffectedByDragRules(true);
if (e->renderer() && e->renderer()->isDragging())
return true;
break;
}
case CSSSelector::PseudoFocus:
if (e && e->focused() && e->document()->frame()->selectionController()->isFocusedAndActive())
return true;
break;
case CSSSelector::PseudoHover: {
// If we're in quirks mode, then hover should never match anchors with no
// href and *:hover should not match anything. This is important for sites like wsj.com.
if (m_strictParsing || isSubSelector || (sel->hasTag() && !e->hasTagName(aTag)) || e->isLink()) {
if (elementStyle)
elementStyle->setAffectedByHoverRules(true);
else if (e->renderStyle())
e->renderStyle()->setAffectedByHoverRules(true);
if (e->hovered())
return true;
}
break;
}
case CSSSelector::PseudoActive:
// If we're in quirks mode, then :active should never match anchors with no
// href and *:active should not match anything.
if (m_strictParsing || isSubSelector || (sel->hasTag() && !e->hasTagName(aTag)) || e->isLink()) {
if (elementStyle)
elementStyle->setAffectedByActiveRules(true);
else if (e->renderStyle())
e->renderStyle()->setAffectedByActiveRules(true);
if (e->active())
return true;
}
break;
case CSSSelector::PseudoEnabled:
if (e && e->isControl() && !e->isInputTypeHidden())
// The UI spec states that you can't match :enabled unless you are an object that can
// "receive focus and be activated." We will limit matching of this pseudo-class to elements
// that are non-"hidden" controls.
return e->isEnabled();
break;
case CSSSelector::PseudoDisabled:
if (e && e->isControl() && !e->isInputTypeHidden())
// The UI spec states that you can't match :enabled unless you are an object that can
// "receive focus and be activated." We will limit matching of this pseudo-class to elements
// that are non-"hidden" controls.
return !e->isEnabled();
break;
case CSSSelector::PseudoChecked:
// Even though WinIE allows checked and indeterminate to co-exist, the CSS selector spec says that
// you can't be both checked and indeterminate. We will behave like WinIE behind the scenes and just
// obey the CSS spec here in the test for matching the pseudo.
if (e && e->isChecked() && !e->isIndeterminate())
return true;
break;
case CSSSelector::PseudoIndeterminate:
if (e && e->isIndeterminate())
return true;
break;
case CSSSelector::PseudoRoot:
if (e == e->document()->documentElement())
return true;
break;
case CSSSelector::PseudoLang: {
Node* n = e;
AtomicString value;
// The language property is inherited, so we iterate over the parents
// to find the first language.
while (n && value.isEmpty()) {
if (n->isElementNode()) {
// Spec: xml:lang takes precedence -- http://www.w3.org/TR/xhtml1/#C_7
value = static_cast<Element*>(n)->getAttribute(XMLNames::langAttr);
if (value.isEmpty())
value = static_cast<Element*>(n)->getAttribute(langAttr);
} else if (n->isDocumentNode())
// checking the MIME content-language
value = static_cast<Document*>(n)->contentLanguage();
n = n->parent();
}
if (value.isEmpty() || !value.startsWith(sel->m_argument, false))
break;
if (value.length() != sel->m_argument.length() && value[sel->m_argument.length()] != '-')
break;
return true;
}
case CSSSelector::PseudoNot: {
// check the simple selector
for (CSSSelector* subSel = sel->m_simpleSelector; subSel; subSel = subSel->m_tagHistory) {
// :not cannot nest. I don't really know why this is a
// restriction in CSS3, but it is, so let's honour it.
if (subSel->m_simpleSelector)
break;
if (!checkOneSelector(subSel, e, selectorAttrs, dynamicPseudo, isAncestor, true, elementStyle, elementParentStyle))
return true;
}
break;
}
case CSSSelector::PseudoUnknown:
case CSSSelector::PseudoNotParsed:
default:
ASSERT_NOT_REACHED();
break;
}
return false;
}
if (sel->m_match == CSSSelector::PseudoElement) {
if (!elementStyle)
return false;
switch (sel->pseudoType()) {
// Pseudo-elements:
case CSSSelector::PseudoFirstLine:
dynamicPseudo = RenderStyle::FIRST_LINE;
return true;
case CSSSelector::PseudoFirstLetter:
dynamicPseudo = RenderStyle::FIRST_LETTER;
if (Document* doc = e->document())
doc->setUsesFirstLetterRules(true);
return true;
case CSSSelector::PseudoSelection:
dynamicPseudo = RenderStyle::SELECTION;
return true;
case CSSSelector::PseudoBefore:
dynamicPseudo = RenderStyle::BEFORE;
return true;
case CSSSelector::PseudoAfter:
dynamicPseudo = RenderStyle::AFTER;
return true;
case CSSSelector::PseudoFileUploadButton:
dynamicPseudo = RenderStyle::FILE_UPLOAD_BUTTON;
return true;
case CSSSelector::PseudoSliderThumb:
dynamicPseudo = RenderStyle::SLIDER_THUMB;
return true;
case CSSSelector::PseudoSearchCancelButton:
dynamicPseudo = RenderStyle::SEARCH_CANCEL_BUTTON;
return true;
case CSSSelector::PseudoSearchDecoration:
dynamicPseudo = RenderStyle::SEARCH_DECORATION;
return true;
case CSSSelector::PseudoSearchResultsDecoration:
dynamicPseudo = RenderStyle::SEARCH_RESULTS_DECORATION;
return true;
case CSSSelector::PseudoSearchResultsButton:
dynamicPseudo = RenderStyle::SEARCH_RESULTS_BUTTON;
return true;
case CSSSelector::PseudoMediaControlsPanel:
dynamicPseudo = RenderStyle::MEDIA_CONTROLS_PANEL;
return true;
case CSSSelector::PseudoMediaControlsMuteButton:
dynamicPseudo = RenderStyle::MEDIA_CONTROLS_MUTE_BUTTON;
return true;
case CSSSelector::PseudoMediaControlsPlayButton:
dynamicPseudo = RenderStyle::MEDIA_CONTROLS_PLAY_BUTTON;
return true;
case CSSSelector::PseudoMediaControlsTimeDisplay:
dynamicPseudo = RenderStyle::MEDIA_CONTROLS_TIME_DISPLAY;
return true;
case CSSSelector::PseudoMediaControlsTimeline:
dynamicPseudo = RenderStyle::MEDIA_CONTROLS_TIMELINE;
return true;
case CSSSelector::PseudoMediaControlsSeekBackButton:
dynamicPseudo = RenderStyle::MEDIA_CONTROLS_SEEK_BACK_BUTTON;
return true;
case CSSSelector::PseudoMediaControlsSeekForwardButton:
dynamicPseudo = RenderStyle::MEDIA_CONTROLS_SEEK_FORWARD_BUTTON;
return true;
case CSSSelector::PseudoMediaControlsFullscreenButton:
dynamicPseudo = RenderStyle::MEDIA_CONTROLS_FULLSCREEN_BUTTON;
return true;
case CSSSelector::PseudoUnknown:
case CSSSelector::PseudoNotParsed:
default:
ASSERT_NOT_REACHED();
break;
}
return false;
}
// ### add the rest of the checks...
return true;
}
// -----------------------------------------------------------------
CSSRuleSet::CSSRuleSet()
{
m_universalRules = 0;
m_ruleCount = 0;
}
CSSRuleSet::~CSSRuleSet()
{
deleteAllValues(m_idRules);
deleteAllValues(m_classRules);
deleteAllValues(m_tagRules);
delete m_universalRules;
}
void CSSRuleSet::addToRuleSet(AtomicStringImpl* key, AtomRuleMap& map,
CSSStyleRule* rule, CSSSelector* sel)
{
if (!key) return;
CSSRuleDataList* rules = map.get(key);
if (!rules) {
rules = new CSSRuleDataList(m_ruleCount++, rule, sel);
map.set(key, rules);
} else
rules->append(m_ruleCount++, rule, sel);
}
void CSSRuleSet::addRule(CSSStyleRule* rule, CSSSelector* sel)
{
if (sel->m_match == CSSSelector::Id) {
addToRuleSet(sel->m_value.impl(), m_idRules, rule, sel);
return;
}
if (sel->m_match == CSSSelector::Class) {
addToRuleSet(sel->m_value.impl(), m_classRules, rule, sel);
return;
}
const AtomicString& localName = sel->m_tag.localName();
if (localName != starAtom) {
addToRuleSet(localName.impl(), m_tagRules, rule, sel);
return;
}
// Just put it in the universal rule set.
if (!m_universalRules)
m_universalRules = new CSSRuleDataList(m_ruleCount++, rule, sel);
else
m_universalRules->append(m_ruleCount++, rule, sel);
}
void CSSRuleSet::addRulesFromSheet(CSSStyleSheet* sheet, const MediaQueryEvaluator& medium, CSSStyleSelector* styleSelector)
{
if (!sheet || !sheet->isCSSStyleSheet())
return;
// No media implies "all", but if a media list exists it must
// contain our current medium
if (sheet->media() && !medium.eval(sheet->media(), styleSelector))
return; // the style sheet doesn't apply
int len = sheet->length();
for (int i = 0; i < len; i++) {
StyleBase* item = sheet->item(i);
if (item->isStyleRule()) {
CSSStyleRule* rule = static_cast<CSSStyleRule*>(item);
for (CSSSelector* s = rule->selector(); s; s = s->next())
addRule(rule, s);
}
else if (item->isImportRule()) {
CSSImportRule* import = static_cast<CSSImportRule*>(item);
if (!import->media() || medium.eval(import->media(), styleSelector))
addRulesFromSheet(import->styleSheet(), medium, styleSelector);
}
else if (item->isMediaRule()) {
CSSMediaRule* r = static_cast<CSSMediaRule*>(item);
CSSRuleList* rules = r->cssRules();
if ((!r->media() || medium.eval(r->media(), styleSelector)) && rules) {
// Traverse child elements of the @media rule.
for (unsigned j = 0; j < rules->length(); j++) {
CSSRule *childItem = rules->item(j);
if (childItem->isStyleRule()) {
// It is a StyleRule, so append it to our list
CSSStyleRule* rule = static_cast<CSSStyleRule*>(childItem);
for (CSSSelector* s = rule->selector(); s; s = s->next())
addRule(rule, s);
} else if (item->isFontFaceRule() && styleSelector) {
// Add this font face to our set.
const CSSFontFaceRule* fontFaceRule = static_cast<CSSFontFaceRule*>(item);
styleSelector->fontSelector()->addFontFaceRule(fontFaceRule);
}
} // for rules
} // if rules
} else if (item->isFontFaceRule() && styleSelector) {
// Add this font face to our set.
const CSSFontFaceRule* fontFaceRule = static_cast<CSSFontFaceRule*>(item);
styleSelector->fontSelector()->addFontFaceRule(fontFaceRule);
}
}
}
// -------------------------------------------------------------------------------------
// this is mostly boring stuff on how to apply a certain rule to the renderstyle...
static Length convertToLength(CSSPrimitiveValue *primitiveValue, RenderStyle *style, bool *ok = 0)
{
Length l;
if (!primitiveValue) {
if (ok)
*ok = false;
} else {
int type = primitiveValue->primitiveType();
if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
l = Length(primitiveValue->computeLengthIntForLength(style), Fixed);
else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
l = Length(primitiveValue->getDoubleValue(), Percent);
else if (type == CSSPrimitiveValue::CSS_NUMBER)
l = Length(primitiveValue->getDoubleValue() * 100.0, Percent);
else if (ok)
*ok = false;
}
return l;
}
void CSSStyleSelector::applyDeclarations(bool applyFirst, bool isImportant,
int startIndex, int endIndex)
{
if (startIndex == -1) return;
for (int i = startIndex; i <= endIndex; i++) {
CSSMutableStyleDeclaration* decl = m_matchedDecls[i];
DeprecatedValueListConstIterator<CSSProperty> end;
for (DeprecatedValueListConstIterator<CSSProperty> it = decl->valuesIterator(); it != end; ++it) {
const CSSProperty& current = *it;
// give special priority to font-xxx, color properties
if (isImportant == current.isImportant()) {
bool first;
switch (current.id()) {
case CSSPropertyLineHeight:
m_lineHeightValue = current.value();
first = !applyFirst; // we apply line-height later
break;
case CSSPropertyColor:
case CSSPropertyDirection:
case CSSPropertyDisplay:
case CSSPropertyFont:
case CSSPropertyFontSize:
case CSSPropertyFontStyle:
case CSSPropertyFontFamily:
case CSSPropertyFontWeight:
case CSSPropertyWebkitTextSizeAdjust:
case CSSPropertyFontVariant:
case CSSPropertyZoom:
// these have to be applied first, because other properties use the computed
// values of these porperties.
first = true;
break;
default:
first = false;
break;
}
if (first == applyFirst)
applyProperty(current.id(), current.value());
}
}
}
}
static void applyCounterList(RenderStyle* style, CSSValueList* list, bool isReset)
{
CounterDirectiveMap& map = style->accessCounterDirectives();
typedef CounterDirectiveMap::iterator Iterator;
Iterator end = map.end();
for (Iterator it = map.begin(); it != end; ++it)
if (isReset)
it->second.m_reset = false;
else
it->second.m_increment = false;
int length = list ? list->length() : 0;
for (int i = 0; i < length; ++i) {
Pair* pair = static_cast<CSSPrimitiveValue*>(list->itemWithoutBoundsCheck(i))->getPairValue();
AtomicString identifier = static_cast<CSSPrimitiveValue*>(pair->first())->getStringValue();
// FIXME: What about overflow?
int value = static_cast<CSSPrimitiveValue*>(pair->second())->getIntValue();
CounterDirectives& directives = map.add(identifier.impl(), CounterDirectives()).first->second;
if (isReset) {
directives.m_reset = true;
directives.m_resetValue = value;
} else {
if (directives.m_increment)
directives.m_incrementValue += value;
else {
directives.m_increment = true;
directives.m_incrementValue = value;
}
}
}
}
void CSSStyleSelector::applyProperty(int id, CSSValue *value)
{
CSSPrimitiveValue* primitiveValue = 0;
if (value->isPrimitiveValue())
primitiveValue = static_cast<CSSPrimitiveValue*>(value);
float zoomFactor = m_style->effectiveZoom();
Length l;
bool apply = false;
unsigned short valueType = value->cssValueType();
bool isInherit = m_parentNode && valueType == CSSValue::CSS_INHERIT;
bool isInitial = valueType == CSSValue::CSS_INITIAL || (!m_parentNode && valueType == CSSValue::CSS_INHERIT);
// These properties are used to set the correct margins/padding on RTL lists.
if (id == CSSPropertyWebkitMarginStart)
id = m_style->direction() == LTR ? CSSPropertyMarginLeft : CSSPropertyMarginRight;
else if (id == CSSPropertyWebkitPaddingStart)
id = m_style->direction() == LTR ? CSSPropertyPaddingLeft : CSSPropertyPaddingRight;
// What follows is a list that maps the CSS properties into their corresponding front-end
// RenderStyle values. Shorthands (e.g. border, background) occur in this list as well and
// are only hit when mapping "inherit" or "initial" into front-end values.
switch (static_cast<CSSPropertyID>(id)) {
// ident only properties
case CSSPropertyBackgroundAttachment:
HANDLE_BACKGROUND_VALUE(attachment, Attachment, value)
return;
case CSSPropertyWebkitBackgroundClip:
HANDLE_BACKGROUND_VALUE(clip, Clip, value)
return;
case CSSPropertyWebkitBackgroundComposite:
HANDLE_BACKGROUND_VALUE(composite, Composite, value)
return;
case CSSPropertyWebkitBackgroundOrigin:
HANDLE_BACKGROUND_VALUE(origin, Origin, value)
return;
case CSSPropertyBackgroundRepeat:
HANDLE_BACKGROUND_VALUE(repeat, Repeat, value)
return;
case CSSPropertyWebkitBackgroundSize:
HANDLE_BACKGROUND_VALUE(size, Size, value)
return;
case CSSPropertyWebkitMaskAttachment:
HANDLE_MASK_VALUE(attachment, Attachment, value)
return;
case CSSPropertyWebkitMaskClip:
HANDLE_MASK_VALUE(clip, Clip, value)
return;
case CSSPropertyWebkitMaskComposite:
HANDLE_MASK_VALUE(composite, Composite, value)
return;
case CSSPropertyWebkitMaskOrigin:
HANDLE_MASK_VALUE(origin, Origin, value)
return;
case CSSPropertyWebkitMaskRepeat:
HANDLE_MASK_VALUE(repeat, Repeat, value)
return;
case CSSPropertyWebkitMaskSize:
HANDLE_MASK_VALUE(size, Size, value)
return;
case CSSPropertyBorderCollapse:
HANDLE_INHERIT_AND_INITIAL(borderCollapse, BorderCollapse)
if (!primitiveValue)
return;
switch (primitiveValue->getIdent()) {
case CSSValueCollapse:
m_style->setBorderCollapse(true);
break;
case CSSValueSeparate:
m_style->setBorderCollapse(false);
break;
default:
return;
}
return;
case CSSPropertyBorderTopStyle:
HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(borderTopStyle, BorderTopStyle, BorderStyle)
if (primitiveValue)
m_style->setBorderTopStyle(*primitiveValue);
return;
case CSSPropertyBorderRightStyle:
HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(borderRightStyle, BorderRightStyle, BorderStyle)
if (primitiveValue)
m_style->setBorderRightStyle(*primitiveValue);
return;
case CSSPropertyBorderBottomStyle:
HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(borderBottomStyle, BorderBottomStyle, BorderStyle)
if (primitiveValue)
m_style->setBorderBottomStyle(*primitiveValue);
return;
case CSSPropertyBorderLeftStyle:
HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(borderLeftStyle, BorderLeftStyle, BorderStyle)
if (primitiveValue)
m_style->setBorderLeftStyle(*primitiveValue);
return;
case CSSPropertyOutlineStyle:
HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(outlineStyle, OutlineStyle, BorderStyle)
if (primitiveValue) {
if (primitiveValue->getIdent() == CSSValueAuto)
m_style->setOutlineStyle(DOTTED, true);
else
m_style->setOutlineStyle(*primitiveValue);
}
return;
case CSSPropertyCaptionSide:
{
HANDLE_INHERIT_AND_INITIAL(captionSide, CaptionSide)
if (primitiveValue)
m_style->setCaptionSide(*primitiveValue);
return;
}
case CSSPropertyClear:
{
HANDLE_INHERIT_AND_INITIAL(clear, Clear)
if (primitiveValue)
m_style->setClear(*primitiveValue);
return;
}
case CSSPropertyDirection:
{
HANDLE_INHERIT_AND_INITIAL(direction, Direction)
if (primitiveValue)
m_style->setDirection(*primitiveValue);
return;
}
case CSSPropertyDisplay:
{
HANDLE_INHERIT_AND_INITIAL(display, Display)
if (primitiveValue)
m_style->setDisplay(*primitiveValue);
return;
}
case CSSPropertyEmptyCells:
{
HANDLE_INHERIT_AND_INITIAL(emptyCells, EmptyCells)
if (primitiveValue)
m_style->setEmptyCells(*primitiveValue);
return;
}
case CSSPropertyFloat:
{
HANDLE_INHERIT_AND_INITIAL(floating, Floating)
if (primitiveValue)
m_style->setFloating(*primitiveValue);
return;
}
case CSSPropertyFontStyle:
{
FontDescription fontDescription = m_style->fontDescription();
if (isInherit)
fontDescription.setItalic(m_parentStyle->fontDescription().italic());
else if (isInitial)
fontDescription.setItalic(false);
else {
if (!primitiveValue)
return;
switch (primitiveValue->getIdent()) {
case CSSValueOblique:
// FIXME: oblique is the same as italic for the moment...
case CSSValueItalic:
fontDescription.setItalic(true);
break;
case CSSValueNormal:
fontDescription.setItalic(false);
break;
default:
return;
}
}
if (m_style->setFontDescription(fontDescription))
m_fontDirty = true;
return;
}
case CSSPropertyFontVariant:
{
FontDescription fontDescription = m_style->fontDescription();
if (isInherit)
fontDescription.setSmallCaps(m_parentStyle->fontDescription().smallCaps());
else if (isInitial)
fontDescription.setSmallCaps(false);
else {
if (!primitiveValue)
return;
int id = primitiveValue->getIdent();
if (id == CSSValueNormal)
fontDescription.setSmallCaps(false);
else if (id == CSSValueSmallCaps)
fontDescription.setSmallCaps(true);
else
return;
}
if (m_style->setFontDescription(fontDescription))
m_fontDirty = true;
return;
}
case CSSPropertyFontWeight:
{
FontDescription fontDescription = m_style->fontDescription();
if (isInherit)
fontDescription.setWeight(m_parentStyle->fontDescription().weight());
else if (isInitial)
fontDescription.setWeight(FontWeightNormal);
else {
if (!primitiveValue)
return;
if (primitiveValue->getIdent()) {
switch (primitiveValue->getIdent()) {
case CSSValueBolder:
fontDescription.setWeight(fontDescription.bolderWeight());
break;
case CSSValueLighter:
fontDescription.setWeight(fontDescription.lighterWeight());
break;
case CSSValueBold:
case CSSValue700:
fontDescription.setWeight(FontWeightBold);
break;
case CSSValueNormal:
case CSSValue400:
fontDescription.setWeight(FontWeightNormal);
break;
case CSSValue900:
fontDescription.setWeight(FontWeight900);
break;
case CSSValue800:
fontDescription.setWeight(FontWeight800);
break;
case CSSValue600:
fontDescription.setWeight(FontWeight600);
break;
case CSSValue500:
fontDescription.setWeight(FontWeight500);
break;
case CSSValue300:
fontDescription.setWeight(FontWeight300);
break;
case CSSValue200:
fontDescription.setWeight(FontWeight200);
break;
case CSSValue100:
fontDescription.setWeight(FontWeight100);
break;
default:
return;
}
} else
ASSERT_NOT_REACHED();
}
if (m_style->setFontDescription(fontDescription))
m_fontDirty = true;
return;
}
case CSSPropertyListStylePosition:
{
HANDLE_INHERIT_AND_INITIAL(listStylePosition, ListStylePosition)
if (primitiveValue)
m_style->setListStylePosition(*primitiveValue);
return;
}
case CSSPropertyListStyleType:
{
HANDLE_INHERIT_AND_INITIAL(listStyleType, ListStyleType)
if (primitiveValue)
m_style->setListStyleType(*primitiveValue);
return;
}
case CSSPropertyOverflow:
{
if (isInherit) {
m_style->setOverflowX(m_parentStyle->overflowX());
m_style->setOverflowY(m_parentStyle->overflowY());
return;
}
if (isInitial) {
m_style->setOverflowX(RenderStyle::initialOverflowX());
m_style->setOverflowY(RenderStyle::initialOverflowY());
return;
}
EOverflow o = *primitiveValue;
m_style->setOverflowX(o);
m_style->setOverflowY(o);
return;
}
case CSSPropertyOverflowX:
{
HANDLE_INHERIT_AND_INITIAL(overflowX, OverflowX)
m_style->setOverflowX(*primitiveValue);
return;
}
case CSSPropertyOverflowY:
{
HANDLE_INHERIT_AND_INITIAL(overflowY, OverflowY)
m_style->setOverflowY(*primitiveValue);
return;
}
case CSSPropertyPageBreakBefore:
{
HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(pageBreakBefore, PageBreakBefore, PageBreak)
if (primitiveValue)
m_style->setPageBreakBefore(*primitiveValue);
return;
}
case CSSPropertyPageBreakAfter:
{
HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(pageBreakAfter, PageBreakAfter, PageBreak)
if (primitiveValue)
m_style->setPageBreakAfter(*primitiveValue);
return;
}
case CSSPropertyPageBreakInside: {
HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(pageBreakInside, PageBreakInside, PageBreak)
if (!primitiveValue)
return;
EPageBreak pageBreak = *primitiveValue;
if (pageBreak != PBALWAYS)
m_style->setPageBreakInside(pageBreak);
return;
}
case CSSPropertyPosition:
{
HANDLE_INHERIT_AND_INITIAL(position, Position)
if (primitiveValue)
m_style->setPosition(*primitiveValue);
return;
}
case CSSPropertyTableLayout: {
HANDLE_INHERIT_AND_INITIAL(tableLayout, TableLayout)
ETableLayout l = *primitiveValue;
if (l == TAUTO)
l = RenderStyle::initialTableLayout();
m_style->setTableLayout(l);
return;
}
case CSSPropertyUnicodeBidi: {
HANDLE_INHERIT_AND_INITIAL(unicodeBidi, UnicodeBidi)
m_style->setUnicodeBidi(*primitiveValue);
return;
}
case CSSPropertyTextTransform: {
HANDLE_INHERIT_AND_INITIAL(textTransform, TextTransform)
m_style->setTextTransform(*primitiveValue);
return;
}
case CSSPropertyVisibility:
{
HANDLE_INHERIT_AND_INITIAL(visibility, Visibility)
m_style->setVisibility(*primitiveValue);
return;
}
case CSSPropertyWhiteSpace:
HANDLE_INHERIT_AND_INITIAL(whiteSpace, WhiteSpace)
m_style->setWhiteSpace(*primitiveValue);
return;
case CSSPropertyBackgroundPosition:
HANDLE_BACKGROUND_INHERIT_AND_INITIAL(xPosition, XPosition);
HANDLE_BACKGROUND_INHERIT_AND_INITIAL(yPosition, YPosition);
return;
case CSSPropertyBackgroundPositionX: {
HANDLE_BACKGROUND_VALUE(xPosition, XPosition, value)
return;
}
case CSSPropertyBackgroundPositionY: {
HANDLE_BACKGROUND_VALUE(yPosition, YPosition, value)
return;
}
case CSSPropertyWebkitMaskPosition:
HANDLE_MASK_INHERIT_AND_INITIAL(xPosition, XPosition);
HANDLE_MASK_INHERIT_AND_INITIAL(yPosition, YPosition);
return;
case CSSPropertyWebkitMaskPositionX: {
HANDLE_MASK_VALUE(xPosition, XPosition, value)
return;
}
case CSSPropertyWebkitMaskPositionY: {
HANDLE_MASK_VALUE(yPosition, YPosition, value)
return;
}
case CSSPropertyBorderSpacing: {
if (isInherit) {
m_style->setHorizontalBorderSpacing(m_parentStyle->horizontalBorderSpacing());
m_style->setVerticalBorderSpacing(m_parentStyle->verticalBorderSpacing());
}
else if (isInitial) {
m_style->setHorizontalBorderSpacing(0);
m_style->setVerticalBorderSpacing(0);
}
return;
}
case CSSPropertyWebkitBorderHorizontalSpacing: {
HANDLE_INHERIT_AND_INITIAL(horizontalBorderSpacing, HorizontalBorderSpacing)
if (!primitiveValue)
return;
short spacing = primitiveValue->computeLengthShort(m_style, zoomFactor);
m_style->setHorizontalBorderSpacing(spacing);
return;
}
case CSSPropertyWebkitBorderVerticalSpacing: {
HANDLE_INHERIT_AND_INITIAL(verticalBorderSpacing, VerticalBorderSpacing)
if (!primitiveValue)
return;
short spacing = primitiveValue->computeLengthShort(m_style, zoomFactor);
m_style->setVerticalBorderSpacing(spacing);
return;
}
case CSSPropertyCursor:
if (isInherit) {
m_style->setCursor(m_parentStyle->cursor());
m_style->setCursorList(m_parentStyle->cursors());
return;
}
m_style->clearCursorList();
if (isInitial) {
m_style->setCursor(RenderStyle::initialCursor());
return;
}
if (value->isValueList()) {
CSSValueList* list = static_cast<CSSValueList*>(value);
int len = list->length();
m_style->setCursor(CURSOR_AUTO);
for (int i = 0; i < len; i++) {
CSSValue* item = list->itemWithoutBoundsCheck(i);
if (!item->isPrimitiveValue())
continue;
primitiveValue = static_cast<CSSPrimitiveValue*>(item);
int type = primitiveValue->primitiveType();
if (type == CSSPrimitiveValue::CSS_URI) {
CSSCursorImageValue* image = static_cast<CSSCursorImageValue*>(primitiveValue);
if (image->updateIfSVGCursorIsUsed(m_element)) // Elements with SVG cursors are not allowed to share style.
m_style->setUnique();
// FIXME: Temporary clumsiness to pass off a CachedImage to an API that will eventually convert to using
// StyleImage.
RefPtr<StyleCachedImage> styleCachedImage(image->cachedImage(m_element->document()->docLoader()));
if (styleCachedImage)
m_style->addCursor(styleCachedImage->cachedImage(), image->hotspot());
} else if (type == CSSPrimitiveValue::CSS_IDENT)
m_style->setCursor(*primitiveValue);
}
} else if (primitiveValue) {
int type = primitiveValue->primitiveType();
if (type == CSSPrimitiveValue::CSS_IDENT)
m_style->setCursor(*primitiveValue);
}
return;
// colors || inherit
case CSSPropertyColor:
// If the 'currentColor' keyword is set on the 'color' property itself,
// it is treated as 'color:inherit' at parse time
if (primitiveValue && primitiveValue->getIdent() == CSSValueCurrentcolor)
isInherit = true;
case CSSPropertyBackgroundColor:
case CSSPropertyBorderTopColor:
case CSSPropertyBorderRightColor:
case CSSPropertyBorderBottomColor:
case CSSPropertyBorderLeftColor:
case CSSPropertyOutlineColor:
case CSSPropertyWebkitColumnRuleColor:
case CSSPropertyWebkitTextStrokeColor:
case CSSPropertyWebkitTextFillColor: {
Color col;
if (isInherit) {
HANDLE_INHERIT_COND(CSSPropertyBackgroundColor, backgroundColor, BackgroundColor)
HANDLE_INHERIT_COND_WITH_BACKUP(CSSPropertyBorderTopColor, borderTopColor, color, BorderTopColor)
HANDLE_INHERIT_COND_WITH_BACKUP(CSSPropertyBorderBottomColor, borderBottomColor, color, BorderBottomColor)
HANDLE_INHERIT_COND_WITH_BACKUP(CSSPropertyBorderRightColor, borderRightColor, color, BorderRightColor)
HANDLE_INHERIT_COND_WITH_BACKUP(CSSPropertyBorderLeftColor, borderLeftColor, color, BorderLeftColor)
HANDLE_INHERIT_COND(CSSPropertyColor, color, Color)
HANDLE_INHERIT_COND_WITH_BACKUP(CSSPropertyOutlineColor, outlineColor, color, OutlineColor)
HANDLE_INHERIT_COND_WITH_BACKUP(CSSPropertyWebkitColumnRuleColor, columnRuleColor, color, ColumnRuleColor)
HANDLE_INHERIT_COND_WITH_BACKUP(CSSPropertyWebkitTextStrokeColor, textStrokeColor, color, TextStrokeColor)
HANDLE_INHERIT_COND_WITH_BACKUP(CSSPropertyWebkitTextFillColor, textFillColor, color, TextFillColor)
return;
}
if (isInitial) {
// The border/outline colors will just map to the invalid color |col| above. This will have the
// effect of forcing the use of the currentColor when it comes time to draw the borders (and of
// not painting the background since the color won't be valid).
if (id == CSSPropertyColor)
col = RenderStyle::initialColor();
} else {
if (!primitiveValue)
return;
col = getColorFromPrimitiveValue(primitiveValue);
}
switch (id) {
case CSSPropertyBackgroundColor:
m_style->setBackgroundColor(col);
break;
case CSSPropertyBorderTopColor:
m_style->setBorderTopColor(col);
break;
case CSSPropertyBorderRightColor:
m_style->setBorderRightColor(col);
break;
case CSSPropertyBorderBottomColor:
m_style->setBorderBottomColor(col);
break;
case CSSPropertyBorderLeftColor:
m_style->setBorderLeftColor(col);
break;
case CSSPropertyColor:
m_style->setColor(col);
break;
case CSSPropertyOutlineColor:
m_style->setOutlineColor(col);
break;
case CSSPropertyWebkitColumnRuleColor:
m_style->setColumnRuleColor(col);
break;
case CSSPropertyWebkitTextStrokeColor:
m_style->setTextStrokeColor(col);
break;
case CSSPropertyWebkitTextFillColor:
m_style->setTextFillColor(col);
break;
}
return;
}
// uri || inherit
case CSSPropertyBackgroundImage:
HANDLE_BACKGROUND_VALUE(image, Image, value)
return;
case CSSPropertyWebkitMaskImage:
HANDLE_MASK_VALUE(image, Image, value)
return;
case CSSPropertyListStyleImage:
{
HANDLE_INHERIT_AND_INITIAL(listStyleImage, ListStyleImage)
m_style->setListStyleImage(styleImage(value));
return;
}
// length
case CSSPropertyBorderTopWidth:
case CSSPropertyBorderRightWidth:
case CSSPropertyBorderBottomWidth:
case CSSPropertyBorderLeftWidth:
case CSSPropertyOutlineWidth:
case CSSPropertyWebkitColumnRuleWidth:
{
if (isInherit) {
HANDLE_INHERIT_COND(CSSPropertyBorderTopWidth, borderTopWidth, BorderTopWidth)
HANDLE_INHERIT_COND(CSSPropertyBorderRightWidth, borderRightWidth, BorderRightWidth)
HANDLE_INHERIT_COND(CSSPropertyBorderBottomWidth, borderBottomWidth, BorderBottomWidth)
HANDLE_INHERIT_COND(CSSPropertyBorderLeftWidth, borderLeftWidth, BorderLeftWidth)
HANDLE_INHERIT_COND(CSSPropertyOutlineWidth, outlineWidth, OutlineWidth)
HANDLE_INHERIT_COND(CSSPropertyWebkitColumnRuleWidth, columnRuleWidth, ColumnRuleWidth)
return;
}
else if (isInitial) {
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyBorderTopWidth, BorderTopWidth, BorderWidth)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyBorderRightWidth, BorderRightWidth, BorderWidth)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyBorderBottomWidth, BorderBottomWidth, BorderWidth)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyBorderLeftWidth, BorderLeftWidth, BorderWidth)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyOutlineWidth, OutlineWidth, BorderWidth)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyWebkitColumnRuleWidth, ColumnRuleWidth, BorderWidth)
return;
}
if (!primitiveValue)
return;
short width = 3;
switch (primitiveValue->getIdent()) {
case CSSValueThin:
width = 1;
break;
case CSSValueMedium:
width = 3;
break;
case CSSValueThick:
width = 5;
break;
case CSSValueInvalid:
width = primitiveValue->computeLengthShort(m_style, zoomFactor);
break;
default:
return;
}
if (width < 0) return;
switch (id) {
case CSSPropertyBorderTopWidth:
m_style->setBorderTopWidth(width);
break;
case CSSPropertyBorderRightWidth:
m_style->setBorderRightWidth(width);
break;
case CSSPropertyBorderBottomWidth:
m_style->setBorderBottomWidth(width);
break;
case CSSPropertyBorderLeftWidth:
m_style->setBorderLeftWidth(width);
break;
case CSSPropertyOutlineWidth:
m_style->setOutlineWidth(width);
break;
case CSSPropertyWebkitColumnRuleWidth:
m_style->setColumnRuleWidth(width);
break;
default:
return;
}
return;
}
case CSSPropertyLetterSpacing:
case CSSPropertyWordSpacing:
{
if (isInherit) {
HANDLE_INHERIT_COND(CSSPropertyLetterSpacing, letterSpacing, LetterSpacing)
HANDLE_INHERIT_COND(CSSPropertyWordSpacing, wordSpacing, WordSpacing)
return;
}
else if (isInitial) {
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyLetterSpacing, LetterSpacing, LetterWordSpacing)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyWordSpacing, WordSpacing, LetterWordSpacing)
return;
}
int width = 0;
if (primitiveValue && primitiveValue->getIdent() == CSSValueNormal){
width = 0;
} else {
if (!primitiveValue)
return;
width = primitiveValue->computeLengthInt(m_style, zoomFactor);
}
switch (id) {
case CSSPropertyLetterSpacing:
m_style->setLetterSpacing(width);
break;
case CSSPropertyWordSpacing:
m_style->setWordSpacing(width);
break;
// ### needs the definitions in renderstyle
default: break;
}
return;
}
case CSSPropertyWordBreak: {
HANDLE_INHERIT_AND_INITIAL(wordBreak, WordBreak)
m_style->setWordBreak(*primitiveValue);
return;
}
case CSSPropertyWordWrap: {
HANDLE_INHERIT_AND_INITIAL(wordWrap, WordWrap)
m_style->setWordWrap(*primitiveValue);
return;
}
case CSSPropertyWebkitNbspMode:
{
HANDLE_INHERIT_AND_INITIAL(nbspMode, NBSPMode)
m_style->setNBSPMode(*primitiveValue);
return;
}
case CSSPropertyWebkitLineBreak:
{
HANDLE_INHERIT_AND_INITIAL(khtmlLineBreak, KHTMLLineBreak)
m_style->setKHTMLLineBreak(*primitiveValue);
return;
}
case CSSPropertyWebkitMatchNearestMailBlockquoteColor:
{
HANDLE_INHERIT_AND_INITIAL(matchNearestMailBlockquoteColor, MatchNearestMailBlockquoteColor)
m_style->setMatchNearestMailBlockquoteColor(*primitiveValue);
return;
}
case CSSPropertyResize:
{
HANDLE_INHERIT_AND_INITIAL(resize, Resize)
if (!primitiveValue->getIdent())
return;
EResize r = RESIZE_NONE;
if (primitiveValue->getIdent() == CSSValueAuto) {
if (Settings* settings = m_checker.m_document->settings())
r = settings->textAreasAreResizable() ? RESIZE_BOTH : RESIZE_NONE;
} else
r = *primitiveValue;
m_style->setResize(r);
return;
}
// length, percent
case CSSPropertyMaxWidth:
// +none +inherit
if (primitiveValue && primitiveValue->getIdent() == CSSValueNone)
apply = true;
case CSSPropertyTop:
case CSSPropertyLeft:
case CSSPropertyRight:
case CSSPropertyBottom:
case CSSPropertyWidth:
case CSSPropertyMinWidth:
case CSSPropertyMarginTop:
case CSSPropertyMarginRight:
case CSSPropertyMarginBottom:
case CSSPropertyMarginLeft:
// +inherit +auto
if (id == CSSPropertyWidth || id == CSSPropertyMinWidth || id == CSSPropertyMaxWidth) {
if (primitiveValue && primitiveValue->getIdent() == CSSValueIntrinsic) {
l = Length(Intrinsic);
apply = true;
}
else if (primitiveValue && primitiveValue->getIdent() == CSSValueMinIntrinsic) {
l = Length(MinIntrinsic);
apply = true;
}
}
if (id != CSSPropertyMaxWidth && primitiveValue && primitiveValue->getIdent() == CSSValueAuto)
apply = true;
case CSSPropertyPaddingTop:
case CSSPropertyPaddingRight:
case CSSPropertyPaddingBottom:
case CSSPropertyPaddingLeft:
case CSSPropertyTextIndent:
// +inherit
{
if (isInherit) {
HANDLE_INHERIT_COND(CSSPropertyMaxWidth, maxWidth, MaxWidth)
HANDLE_INHERIT_COND(CSSPropertyBottom, bottom, Bottom)
HANDLE_INHERIT_COND(CSSPropertyTop, top, Top)
HANDLE_INHERIT_COND(CSSPropertyLeft, left, Left)
HANDLE_INHERIT_COND(CSSPropertyRight, right, Right)
HANDLE_INHERIT_COND(CSSPropertyWidth, width, Width)
HANDLE_INHERIT_COND(CSSPropertyMinWidth, minWidth, MinWidth)
HANDLE_INHERIT_COND(CSSPropertyPaddingTop, paddingTop, PaddingTop)
HANDLE_INHERIT_COND(CSSPropertyPaddingRight, paddingRight, PaddingRight)
HANDLE_INHERIT_COND(CSSPropertyPaddingBottom, paddingBottom, PaddingBottom)
HANDLE_INHERIT_COND(CSSPropertyPaddingLeft, paddingLeft, PaddingLeft)
HANDLE_INHERIT_COND(CSSPropertyMarginTop, marginTop, MarginTop)
HANDLE_INHERIT_COND(CSSPropertyMarginRight, marginRight, MarginRight)
HANDLE_INHERIT_COND(CSSPropertyMarginBottom, marginBottom, MarginBottom)
HANDLE_INHERIT_COND(CSSPropertyMarginLeft, marginLeft, MarginLeft)
HANDLE_INHERIT_COND(CSSPropertyTextIndent, textIndent, TextIndent)
return;
}
else if (isInitial) {
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyMaxWidth, MaxWidth, MaxSize)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyBottom, Bottom, Offset)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyTop, Top, Offset)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyLeft, Left, Offset)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyRight, Right, Offset)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyWidth, Width, Size)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyMinWidth, MinWidth, MinSize)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyPaddingTop, PaddingTop, Padding)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyPaddingRight, PaddingRight, Padding)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyPaddingBottom, PaddingBottom, Padding)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyPaddingLeft, PaddingLeft, Padding)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyMarginTop, MarginTop, Margin)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyMarginRight, MarginRight, Margin)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyMarginBottom, MarginBottom, Margin)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyMarginLeft, MarginLeft, Margin)
HANDLE_INITIAL_COND(CSSPropertyTextIndent, TextIndent)
return;
}
if (primitiveValue && !apply) {
int type = primitiveValue->primitiveType();
if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
// Handle our quirky margin units if we have them.
l = Length(primitiveValue->computeLengthIntForLength(m_style, zoomFactor), Fixed,
primitiveValue->isQuirkValue());
else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
l = Length(primitiveValue->getDoubleValue(), Percent);
else
return;
if (id == CSSPropertyPaddingLeft || id == CSSPropertyPaddingRight ||
id == CSSPropertyPaddingTop || id == CSSPropertyPaddingBottom)
// Padding can't be negative
apply = !((l.isFixed() || l.isPercent()) && l.calcValue(100) < 0);
else
apply = true;
}
if (!apply) return;
switch (id) {
case CSSPropertyMaxWidth:
m_style->setMaxWidth(l);
break;
case CSSPropertyBottom:
m_style->setBottom(l);
break;
case CSSPropertyTop:
m_style->setTop(l);
break;
case CSSPropertyLeft:
m_style->setLeft(l);
break;
case CSSPropertyRight:
m_style->setRight(l);
break;
case CSSPropertyWidth:
m_style->setWidth(l);
break;
case CSSPropertyMinWidth:
m_style->setMinWidth(l);
break;
case CSSPropertyPaddingTop:
m_style->setPaddingTop(l);
break;
case CSSPropertyPaddingRight:
m_style->setPaddingRight(l);
break;
case CSSPropertyPaddingBottom:
m_style->setPaddingBottom(l);
break;
case CSSPropertyPaddingLeft:
m_style->setPaddingLeft(l);
break;
case CSSPropertyMarginTop:
m_style->setMarginTop(l);
break;
case CSSPropertyMarginRight:
m_style->setMarginRight(l);
break;
case CSSPropertyMarginBottom:
m_style->setMarginBottom(l);
break;
case CSSPropertyMarginLeft:
m_style->setMarginLeft(l);
break;
case CSSPropertyTextIndent:
m_style->setTextIndent(l);
break;
default:
break;
}
return;
}
case CSSPropertyMaxHeight:
if (primitiveValue && primitiveValue->getIdent() == CSSValueNone) {
l = Length(undefinedLength, Fixed);
apply = true;
}
case CSSPropertyHeight:
case CSSPropertyMinHeight:
if (primitiveValue && primitiveValue->getIdent() == CSSValueIntrinsic) {
l = Length(Intrinsic);
apply = true;
} else if (primitiveValue && primitiveValue->getIdent() == CSSValueMinIntrinsic) {
l = Length(MinIntrinsic);
apply = true;
} else if (id != CSSPropertyMaxHeight && primitiveValue && primitiveValue->getIdent() == CSSValueAuto)
apply = true;
if (isInherit) {
HANDLE_INHERIT_COND(CSSPropertyMaxHeight, maxHeight, MaxHeight)
HANDLE_INHERIT_COND(CSSPropertyHeight, height, Height)
HANDLE_INHERIT_COND(CSSPropertyMinHeight, minHeight, MinHeight)
return;
}
if (isInitial) {
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyMaxHeight, MaxHeight, MaxSize)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyHeight, Height, Size)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyMinHeight, MinHeight, MinSize)
return;
}
if (primitiveValue && !apply) {
unsigned short type = primitiveValue->primitiveType();
if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
l = Length(primitiveValue->computeLengthIntForLength(m_style, zoomFactor), Fixed);
else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
l = Length(primitiveValue->getDoubleValue(), Percent);
else
return;
apply = true;
}
if (apply)
switch (id) {
case CSSPropertyMaxHeight:
m_style->setMaxHeight(l);
break;
case CSSPropertyHeight:
m_style->setHeight(l);
break;
case CSSPropertyMinHeight:
m_style->setMinHeight(l);
break;
}
return;
case CSSPropertyVerticalAlign:
HANDLE_INHERIT_AND_INITIAL(verticalAlign, VerticalAlign)
if (!primitiveValue)
return;
if (primitiveValue->getIdent()) {
EVerticalAlign align;
switch (primitiveValue->getIdent()) {
case CSSValueTop:
align = TOP; break;
case CSSValueBottom:
align = BOTTOM; break;
case CSSValueMiddle:
align = MIDDLE; break;
case CSSValueBaseline:
align = BASELINE; break;
case CSSValueTextBottom:
align = TEXT_BOTTOM; break;
case CSSValueTextTop:
align = TEXT_TOP; break;
case CSSValueSub:
align = SUB; break;
case CSSValueSuper:
align = SUPER; break;
case CSSValueWebkitBaselineMiddle:
align = BASELINE_MIDDLE; break;
default:
return;
}
m_style->setVerticalAlign(align);
return;
} else {
int type = primitiveValue->primitiveType();
Length l;
if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
l = Length(primitiveValue->computeLengthIntForLength(m_style, zoomFactor), Fixed);
else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
l = Length(primitiveValue->getDoubleValue(), Percent);
m_style->setVerticalAlign(LENGTH);
m_style->setVerticalAlignLength(l);
}
return;
case CSSPropertyFontSize:
{
FontDescription fontDescription = m_style->fontDescription();
fontDescription.setKeywordSize(0);
bool familyIsFixed = fontDescription.genericFamily() == FontDescription::MonospaceFamily;
float oldSize = 0;
float size = 0;
bool parentIsAbsoluteSize = false;
if (m_parentNode) {
oldSize = m_parentStyle->fontDescription().specifiedSize();
parentIsAbsoluteSize = m_parentStyle->fontDescription().isAbsoluteSize();
}
if (isInherit) {
size = oldSize;
if (m_parentNode)
fontDescription.setKeywordSize(m_parentStyle->fontDescription().keywordSize());
} else if (isInitial) {
size = fontSizeForKeyword(CSSValueMedium, m_style->htmlHacks(), familyIsFixed);
fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1);
} else if (primitiveValue->getIdent()) {
// Keywords are being used.
switch (primitiveValue->getIdent()) {
case CSSValueXxSmall:
case CSSValueXSmall:
case CSSValueSmall:
case CSSValueMedium:
case CSSValueLarge:
case CSSValueXLarge:
case CSSValueXxLarge:
case CSSValueWebkitXxxLarge:
size = fontSizeForKeyword(primitiveValue->getIdent(), m_style->htmlHacks(), familyIsFixed);
fontDescription.setKeywordSize(primitiveValue->getIdent() - CSSValueXxSmall + 1);
break;
case CSSValueLarger:
size = largerFontSize(oldSize, m_style->htmlHacks());
break;
case CSSValueSmaller:
size = smallerFontSize(oldSize, m_style->htmlHacks());
break;
default:
return;
}
fontDescription.setIsAbsoluteSize(parentIsAbsoluteSize &&
(primitiveValue->getIdent() == CSSValueLarger ||
primitiveValue->getIdent() == CSSValueSmaller));
} else {
int type = primitiveValue->primitiveType();
fontDescription.setIsAbsoluteSize(parentIsAbsoluteSize ||
(type != CSSPrimitiveValue::CSS_PERCENTAGE &&
type != CSSPrimitiveValue::CSS_EMS &&
type != CSSPrimitiveValue::CSS_EXS));
if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
size = primitiveValue->computeLengthFloat(m_parentStyle, true);
else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
size = (primitiveValue->getFloatValue() * oldSize) / 100.0f;
else
return;
}
if (size < 0)
return;
setFontSize(fontDescription, size);
if (m_style->setFontDescription(fontDescription))
m_fontDirty = true;
return;
}
case CSSPropertyZIndex: {
if (isInherit) {
if (m_parentStyle->hasAutoZIndex())
m_style->setHasAutoZIndex();
else
m_style->setZIndex(m_parentStyle->zIndex());
return;
} else if (isInitial || primitiveValue->getIdent() == CSSValueAuto) {
m_style->setHasAutoZIndex();
return;
}
// FIXME: Should clamp all sorts of other integer properties too.
const double minIntAsDouble = INT_MIN;
const double maxIntAsDouble = INT_MAX;
m_style->setZIndex(static_cast<int>(max(minIntAsDouble, min(primitiveValue->getDoubleValue(), maxIntAsDouble))));
return;
}
case CSSPropertyWidows:
{
HANDLE_INHERIT_AND_INITIAL(widows, Widows)
if (!primitiveValue || primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_NUMBER)
return;
m_style->setWidows(primitiveValue->getIntValue());
return;
}
case CSSPropertyOrphans:
{
HANDLE_INHERIT_AND_INITIAL(orphans, Orphans)
if (!primitiveValue || primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_NUMBER)
return;
m_style->setOrphans(primitiveValue->getIntValue());
return;
}
// length, percent, number
case CSSPropertyLineHeight:
{
HANDLE_INHERIT_AND_INITIAL(lineHeight, LineHeight)
if (!primitiveValue)
return;
Length lineHeight;
int type = primitiveValue->primitiveType();
if (primitiveValue->getIdent() == CSSValueNormal)
lineHeight = Length(-100.0, Percent);
else if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG) {
double multiplier = m_style->effectiveZoom();
if (m_style->textSizeAdjust() && m_checker.m_document->frame() && m_checker.m_document->frame()->shouldApplyTextZoom())
multiplier *= m_checker.m_document->frame()->textZoomFactor();
lineHeight = Length(primitiveValue->computeLengthIntForLength(m_style, multiplier), Fixed);
} else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
lineHeight = Length((m_style->fontSize() * primitiveValue->getIntValue()) / 100, Fixed);
else if (type == CSSPrimitiveValue::CSS_NUMBER)
lineHeight = Length(primitiveValue->getDoubleValue() * 100.0, Percent);
else
return;
m_style->setLineHeight(lineHeight);
return;
}
// string
case CSSPropertyTextAlign:
{
HANDLE_INHERIT_AND_INITIAL(textAlign, TextAlign)
if (!primitiveValue)
return;
int id = primitiveValue->getIdent();
if (id == CSSValueStart)
m_style->setTextAlign(m_style->direction() == LTR ? LEFT : RIGHT);
else if (id == CSSValueEnd)
m_style->setTextAlign(m_style->direction() == LTR ? RIGHT : LEFT);
else
m_style->setTextAlign(*primitiveValue);
return;
}
// rect
case CSSPropertyClip:
{
Length top;
Length right;
Length bottom;
Length left;
bool hasClip = true;
if (isInherit) {
if (m_parentStyle->hasClip()) {
top = m_parentStyle->clipTop();
right = m_parentStyle->clipRight();
bottom = m_parentStyle->clipBottom();
left = m_parentStyle->clipLeft();
}
else {
hasClip = false;
top = right = bottom = left = Length();
}
} else if (isInitial) {
hasClip = false;
top = right = bottom = left = Length();
} else if (!primitiveValue) {
return;
} else if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_RECT) {
Rect* rect = primitiveValue->getRectValue();
if (!rect)
return;
top = convertToLength(rect->top(), m_style);
right = convertToLength(rect->right(), m_style);
bottom = convertToLength(rect->bottom(), m_style);
left = convertToLength(rect->left(), m_style);
} else if (primitiveValue->getIdent() != CSSValueAuto) {
return;
}
m_style->setClip(top, right, bottom, left);
m_style->setHasClip(hasClip);
// rect, ident
return;
}
// lists
case CSSPropertyContent:
// list of string, uri, counter, attr, i
{
// FIXME: In CSS3, it will be possible to inherit content. In CSS2 it is not. This
// note is a reminder that eventually "inherit" needs to be supported.
if (isInitial) {
m_style->clearContent();
return;
}
if (!value->isValueList())
return;
CSSValueList* list = static_cast<CSSValueList*>(value);
int len = list->length();
bool didSet = false;
for (int i = 0; i < len; i++) {
CSSValue* item = list->itemWithoutBoundsCheck(i);
if (item->isImageGeneratorValue()) {
m_style->setContent(static_cast<CSSImageGeneratorValue*>(item)->generatedImage(), didSet);
didSet = true;
}
if (!item->isPrimitiveValue())
continue;
CSSPrimitiveValue* val = static_cast<CSSPrimitiveValue*>(item);
switch (val->primitiveType()) {
case CSSPrimitiveValue::CSS_STRING:
m_style->setContent(val->getStringValue().impl(), didSet);
didSet = true;
break;
case CSSPrimitiveValue::CSS_ATTR: {
// FIXME: Can a namespace be specified for an attr(foo)?
if (m_style->styleType() == RenderStyle::NOPSEUDO)
m_style->setUnique();
else
m_parentStyle->setUnique();
QualifiedName attr(nullAtom, val->getStringValue().impl(), nullAtom);
m_style->setContent(m_element->getAttribute(attr).impl(), didSet);
didSet = true;
// register the fact that the attribute value affects the style
m_selectorAttrs.add(attr.localName().impl());
break;
}
case CSSPrimitiveValue::CSS_URI: {
CSSImageValue* image = static_cast<CSSImageValue*>(val);
m_style->setContent(image->cachedImage(m_element->document()->docLoader()), didSet);
didSet = true;
break;
}
case CSSPrimitiveValue::CSS_COUNTER: {
Counter* counterValue = val->getCounterValue();
CounterContent* counter = new CounterContent(counterValue->identifier(),
(EListStyleType)counterValue->listStyleNumber(), counterValue->separator());
m_style->setContent(counter, didSet);
didSet = true;
}
}
}
if (!didSet)
m_style->clearContent();
return;
}
case CSSPropertyCounterIncrement:
applyCounterList(m_style, value->isValueList() ? static_cast<CSSValueList*>(value) : 0, false);
return;
case CSSPropertyCounterReset:
applyCounterList(m_style, value->isValueList() ? static_cast<CSSValueList*>(value) : 0, true);
return;
case CSSPropertyFontFamily: {
// list of strings and ids
if (isInherit) {
FontDescription parentFontDescription = m_parentStyle->fontDescription();
FontDescription fontDescription = m_style->fontDescription();
fontDescription.setGenericFamily(parentFontDescription.genericFamily());
fontDescription.setFamily(parentFontDescription.firstFamily());
if (m_style->setFontDescription(fontDescription))
m_fontDirty = true;
return;
}
else if (isInitial) {
FontDescription initialDesc = FontDescription();
FontDescription fontDescription = m_style->fontDescription();
// We need to adjust the size to account for the generic family change from monospace
// to non-monospace.
if (fontDescription.keywordSize() && fontDescription.genericFamily() == FontDescription::MonospaceFamily)
setFontSize(fontDescription, fontSizeForKeyword(CSSValueXxSmall + fontDescription.keywordSize() - 1, m_style->htmlHacks(), false));
fontDescription.setGenericFamily(initialDesc.genericFamily());
if (!initialDesc.firstFamily().familyIsEmpty())
fontDescription.setFamily(initialDesc.firstFamily());
if (m_style->setFontDescription(fontDescription))
m_fontDirty = true;
return;
}
if (!value->isValueList()) return;
FontDescription fontDescription = m_style->fontDescription();
CSSValueList *list = static_cast<CSSValueList*>(value);
int len = list->length();
FontFamily& firstFamily = fontDescription.firstFamily();
FontFamily *currFamily = 0;
// Before mapping in a new font-family property, we should reset the generic family.
bool oldFamilyIsMonospace = fontDescription.genericFamily() == FontDescription::MonospaceFamily;
fontDescription.setGenericFamily(FontDescription::NoFamily);
for (int i = 0; i < len; i++) {
CSSValue *item = list->itemWithoutBoundsCheck(i);
if (!item->isPrimitiveValue()) continue;
CSSPrimitiveValue *val = static_cast<CSSPrimitiveValue*>(item);
AtomicString face;
Settings* settings = m_checker.m_document->settings();
if (val->primitiveType() == CSSPrimitiveValue::CSS_STRING)
face = static_cast<FontFamilyValue*>(val)->familyName();
else if (val->primitiveType() == CSSPrimitiveValue::CSS_IDENT && settings) {
switch (val->getIdent()) {
case CSSValueWebkitBody:
face = settings->standardFontFamily();
break;
case CSSValueSerif:
face = "-webkit-serif";
fontDescription.setGenericFamily(FontDescription::SerifFamily);
break;
case CSSValueSansSerif:
face = "-webkit-sans-serif";
fontDescription.setGenericFamily(FontDescription::SansSerifFamily);
break;
case CSSValueCursive:
face = "-webkit-cursive";
fontDescription.setGenericFamily(FontDescription::CursiveFamily);
break;
case CSSValueFantasy:
face = "-webkit-fantasy";
fontDescription.setGenericFamily(FontDescription::FantasyFamily);
break;
case CSSValueMonospace:
face = "-webkit-monospace";
fontDescription.setGenericFamily(FontDescription::MonospaceFamily);
break;
}
}
if (!face.isEmpty()) {
if (!currFamily) {
// Filling in the first family.
firstFamily.setFamily(face);
currFamily = &firstFamily;
}
else {
RefPtr<SharedFontFamily> newFamily = SharedFontFamily::create();
newFamily->setFamily(face);
currFamily->appendFamily(newFamily);
currFamily = newFamily.get();
}
if (fontDescription.keywordSize() && (fontDescription.genericFamily() == FontDescription::MonospaceFamily) != oldFamilyIsMonospace)
setFontSize(fontDescription, fontSizeForKeyword(CSSValueXxSmall + fontDescription.keywordSize() - 1, m_style->htmlHacks(), !oldFamilyIsMonospace));
if (m_style->setFontDescription(fontDescription))
m_fontDirty = true;
}
}
return;
}
case CSSPropertyTextDecoration: {
// list of ident
HANDLE_INHERIT_AND_INITIAL(textDecoration, TextDecoration)
int t = RenderStyle::initialTextDecoration();
if (primitiveValue && primitiveValue->getIdent() == CSSValueNone) {
// do nothing
} else {
if (!value->isValueList()) return;
CSSValueList *list = static_cast<CSSValueList*>(value);
int len = list->length();
for (int i = 0; i < len; i++)
{
CSSValue *item = list->itemWithoutBoundsCheck(i);
if (!item->isPrimitiveValue()) continue;
primitiveValue = static_cast<CSSPrimitiveValue*>(item);
switch (primitiveValue->getIdent()) {
case CSSValueNone:
t = TDNONE; break;
case CSSValueUnderline:
t |= UNDERLINE; break;
case CSSValueOverline:
t |= OVERLINE; break;
case CSSValueLineThrough:
t |= LINE_THROUGH; break;
case CSSValueBlink:
t |= BLINK; break;
default:
return;
}
}
}
m_style->setTextDecoration(t);
return;
}
case CSSPropertyZoom:
{
// Reset the zoom in effect before we do anything. This allows the setZoom method to accurately compute a new
// zoom in effect.
m_style->setEffectiveZoom(m_parentStyle ? m_parentStyle->effectiveZoom() : RenderStyle::initialZoom());
// Now we can handle inherit and initial.
HANDLE_INHERIT_AND_INITIAL(zoom, Zoom)
// Handle normal/reset, numbers and percentages.
int type = primitiveValue->primitiveType();
if (primitiveValue->getIdent() == CSSValueNormal)
m_style->setZoom(RenderStyle::initialZoom());
else if (primitiveValue->getIdent() == CSSValueReset) {
m_style->setEffectiveZoom(RenderStyle::initialZoom());
m_style->setZoom(RenderStyle::initialZoom());
} else if (type == CSSPrimitiveValue::CSS_PERCENTAGE) {
if (primitiveValue->getFloatValue())
m_style->setZoom(primitiveValue->getFloatValue() / 100.0f);
} else if (type == CSSPrimitiveValue::CSS_NUMBER) {
if (primitiveValue->getFloatValue())
m_style->setZoom(primitiveValue->getFloatValue());
}
m_fontDirty = true;
return;
}
// shorthand properties
case CSSPropertyBackground:
if (isInitial) {
m_style->clearBackgroundLayers();
m_style->setBackgroundColor(Color());
}
else if (isInherit) {
m_style->inheritBackgroundLayers(*m_parentStyle->backgroundLayers());
m_style->setBackgroundColor(m_parentStyle->backgroundColor());
}
return;
case CSSPropertyWebkitMask:
if (isInitial)
m_style->clearMaskLayers();
else if (isInherit)
m_style->inheritMaskLayers(*m_parentStyle->maskLayers());
return;
case CSSPropertyBorder:
case CSSPropertyBorderStyle:
case CSSPropertyBorderWidth:
case CSSPropertyBorderColor:
if (id == CSSPropertyBorder || id == CSSPropertyBorderColor)
{
if (isInherit) {
m_style->setBorderTopColor(m_parentStyle->borderTopColor().isValid() ? m_parentStyle->borderTopColor() : m_parentStyle->color());
m_style->setBorderBottomColor(m_parentStyle->borderBottomColor().isValid() ? m_parentStyle->borderBottomColor() : m_parentStyle->color());
m_style->setBorderLeftColor(m_parentStyle->borderLeftColor().isValid() ? m_parentStyle->borderLeftColor() : m_parentStyle->color());
m_style->setBorderRightColor(m_parentStyle->borderRightColor().isValid() ? m_parentStyle->borderRightColor(): m_parentStyle->color());
}
else if (isInitial) {
m_style->setBorderTopColor(Color()); // Reset to invalid color so currentColor is used instead.
m_style->setBorderBottomColor(Color());
m_style->setBorderLeftColor(Color());
m_style->setBorderRightColor(Color());
}
}
if (id == CSSPropertyBorder || id == CSSPropertyBorderStyle)
{
if (isInherit) {
m_style->setBorderTopStyle(m_parentStyle->borderTopStyle());
m_style->setBorderBottomStyle(m_parentStyle->borderBottomStyle());
m_style->setBorderLeftStyle(m_parentStyle->borderLeftStyle());
m_style->setBorderRightStyle(m_parentStyle->borderRightStyle());
}
else if (isInitial) {
m_style->setBorderTopStyle(RenderStyle::initialBorderStyle());
m_style->setBorderBottomStyle(RenderStyle::initialBorderStyle());
m_style->setBorderLeftStyle(RenderStyle::initialBorderStyle());
m_style->setBorderRightStyle(RenderStyle::initialBorderStyle());
}
}
if (id == CSSPropertyBorder || id == CSSPropertyBorderWidth)
{
if (isInherit) {
m_style->setBorderTopWidth(m_parentStyle->borderTopWidth());
m_style->setBorderBottomWidth(m_parentStyle->borderBottomWidth());
m_style->setBorderLeftWidth(m_parentStyle->borderLeftWidth());
m_style->setBorderRightWidth(m_parentStyle->borderRightWidth());
}
else if (isInitial) {
m_style->setBorderTopWidth(RenderStyle::initialBorderWidth());
m_style->setBorderBottomWidth(RenderStyle::initialBorderWidth());
m_style->setBorderLeftWidth(RenderStyle::initialBorderWidth());
m_style->setBorderRightWidth(RenderStyle::initialBorderWidth());
}
}
return;
case CSSPropertyBorderTop:
if (isInherit) {
m_style->setBorderTopColor(m_parentStyle->borderTopColor().isValid() ? m_parentStyle->borderTopColor() : m_parentStyle->color());
m_style->setBorderTopStyle(m_parentStyle->borderTopStyle());
m_style->setBorderTopWidth(m_parentStyle->borderTopWidth());
}
else if (isInitial)
m_style->resetBorderTop();
return;
case CSSPropertyBorderRight:
if (isInherit) {
m_style->setBorderRightColor(m_parentStyle->borderRightColor().isValid() ? m_parentStyle->borderRightColor() : m_parentStyle->color());
m_style->setBorderRightStyle(m_parentStyle->borderRightStyle());
m_style->setBorderRightWidth(m_parentStyle->borderRightWidth());
}
else if (isInitial)
m_style->resetBorderRight();
return;
case CSSPropertyBorderBottom:
if (isInherit) {
m_style->setBorderBottomColor(m_parentStyle->borderBottomColor().isValid() ? m_parentStyle->borderBottomColor() : m_parentStyle->color());
m_style->setBorderBottomStyle(m_parentStyle->borderBottomStyle());
m_style->setBorderBottomWidth(m_parentStyle->borderBottomWidth());
}
else if (isInitial)
m_style->resetBorderBottom();
return;
case CSSPropertyBorderLeft:
if (isInherit) {
m_style->setBorderLeftColor(m_parentStyle->borderLeftColor().isValid() ? m_parentStyle->borderLeftColor() : m_parentStyle->color());
m_style->setBorderLeftStyle(m_parentStyle->borderLeftStyle());
m_style->setBorderLeftWidth(m_parentStyle->borderLeftWidth());
}
else if (isInitial)
m_style->resetBorderLeft();
return;
case CSSPropertyMargin:
if (isInherit) {
m_style->setMarginTop(m_parentStyle->marginTop());
m_style->setMarginBottom(m_parentStyle->marginBottom());
m_style->setMarginLeft(m_parentStyle->marginLeft());
m_style->setMarginRight(m_parentStyle->marginRight());
}
else if (isInitial)
m_style->resetMargin();
return;
case CSSPropertyPadding:
if (isInherit) {
m_style->setPaddingTop(m_parentStyle->paddingTop());
m_style->setPaddingBottom(m_parentStyle->paddingBottom());
m_style->setPaddingLeft(m_parentStyle->paddingLeft());
m_style->setPaddingRight(m_parentStyle->paddingRight());
}
else if (isInitial)
m_style->resetPadding();
return;
case CSSPropertyFont:
if (isInherit) {
FontDescription fontDescription = m_parentStyle->fontDescription();
m_style->setLineHeight(m_parentStyle->lineHeight());
m_lineHeightValue = 0;
if (m_style->setFontDescription(fontDescription))
m_fontDirty = true;
} else if (isInitial) {
Settings* settings = m_checker.m_document->settings();
FontDescription fontDescription;
fontDescription.setGenericFamily(FontDescription::StandardFamily);
fontDescription.setRenderingMode(settings->fontRenderingMode());
fontDescription.setUsePrinterFont(m_checker.m_document->printing());
const AtomicString& standardFontFamily = m_checker.m_document->settings()->standardFontFamily();
if (!standardFontFamily.isEmpty()) {
fontDescription.firstFamily().setFamily(standardFontFamily);
fontDescription.firstFamily().appendFamily(0);
}
fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1);
setFontSize(fontDescription, fontSizeForKeyword(CSSValueMedium, m_style->htmlHacks(), false));
m_style->setLineHeight(RenderStyle::initialLineHeight());
m_lineHeightValue = 0;
if (m_style->setFontDescription(fontDescription))
m_fontDirty = true;
} else if (primitiveValue) {
m_style->setLineHeight(RenderStyle::initialLineHeight());
m_lineHeightValue = 0;
FontDescription fontDescription;
theme()->systemFont(primitiveValue->getIdent(), fontDescription);
// Double-check and see if the theme did anything. If not, don't bother updating the font.
if (fontDescription.isAbsoluteSize()) {
// Handle the zoom factor.
fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(fontDescription.isAbsoluteSize(), fontDescription.specifiedSize()));
if (m_style->setFontDescription(fontDescription))
m_fontDirty = true;
}
} else if (value->isFontValue()) {
FontValue *font = static_cast<FontValue*>(value);
if (!font->style || !font->variant || !font->weight ||
!font->size || !font->lineHeight || !font->family)
return;
applyProperty(CSSPropertyFontStyle, font->style.get());
applyProperty(CSSPropertyFontVariant, font->variant.get());
applyProperty(CSSPropertyFontWeight, font->weight.get());
applyProperty(CSSPropertyFontSize, font->size.get());
m_lineHeightValue = font->lineHeight.get();
applyProperty(CSSPropertyFontFamily, font->family.get());
}
return;
case CSSPropertyListStyle:
if (isInherit) {
m_style->setListStyleType(m_parentStyle->listStyleType());
m_style->setListStyleImage(m_parentStyle->listStyleImage());
m_style->setListStylePosition(m_parentStyle->listStylePosition());
}
else if (isInitial) {
m_style->setListStyleType(RenderStyle::initialListStyleType());
m_style->setListStyleImage(RenderStyle::initialListStyleImage());
m_style->setListStylePosition(RenderStyle::initialListStylePosition());
}
return;
case CSSPropertyOutline:
if (isInherit) {
m_style->setOutlineWidth(m_parentStyle->outlineWidth());
m_style->setOutlineColor(m_parentStyle->outlineColor().isValid() ? m_parentStyle->outlineColor() : m_parentStyle->color());
m_style->setOutlineStyle(m_parentStyle->outlineStyle());
}
else if (isInitial)
m_style->resetOutline();
return;
// CSS3 Properties
case CSSPropertyWebkitAppearance: {
HANDLE_INHERIT_AND_INITIAL(appearance, Appearance)
if (!primitiveValue)
return;
m_style->setAppearance(*primitiveValue);
return;
}
case CSSPropertyWebkitBinding: {
#if ENABLE(XBL)
if (isInitial || (primitiveValue && primitiveValue->getIdent() == CSSValueNone)) {
m_style->deleteBindingURIs();
return;
}
else if (isInherit) {
if (m_parentStyle->bindingURIs())
m_style->inheritBindingURIs(m_parentStyle->bindingURIs());
else
m_style->deleteBindingURIs();
return;
}
if (!value->isValueList()) return;
CSSValueList* list = static_cast<CSSValueList*>(value);
bool firstBinding = true;
for (unsigned int i = 0; i < list->length(); i++) {
CSSValue *item = list->itemWithoutBoundsCheck(i);
CSSPrimitiveValue *val = static_cast<CSSPrimitiveValue*>(item);
if (val->primitiveType() == CSSPrimitiveValue::CSS_URI) {
if (firstBinding) {
firstBinding = false;
m_style->deleteBindingURIs();
}
m_style->addBindingURI(val->getStringValue());
}
}
#endif
return;
}
case CSSPropertyWebkitBorderImage:
case CSSPropertyWebkitMaskBoxImage: {
if (isInherit) {
HANDLE_INHERIT_COND(CSSPropertyWebkitBorderImage, borderImage, BorderImage)
HANDLE_INHERIT_COND(CSSPropertyWebkitMaskBoxImage, maskBoxImage, MaskBoxImage)
return;
} else if (isInitial) {
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyWebkitBorderImage, BorderImage, NinePieceImage)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyWebkitMaskBoxImage, MaskBoxImage, NinePieceImage)
return;
}
NinePieceImage image;
mapNinePieceImage(value, image);
if (id == CSSPropertyWebkitBorderImage)
m_style->setBorderImage(image);
else
m_style->setMaskBoxImage(image);
return;
}
case CSSPropertyWebkitBorderRadius:
if (isInherit) {
m_style->setBorderTopLeftRadius(m_parentStyle->borderTopLeftRadius());
m_style->setBorderTopRightRadius(m_parentStyle->borderTopRightRadius());
m_style->setBorderBottomLeftRadius(m_parentStyle->borderBottomLeftRadius());
m_style->setBorderBottomRightRadius(m_parentStyle->borderBottomRightRadius());
return;
}
if (isInitial) {
m_style->resetBorderRadius();
return;
}
// Fall through
case CSSPropertyWebkitBorderTopLeftRadius:
case CSSPropertyWebkitBorderTopRightRadius:
case CSSPropertyWebkitBorderBottomLeftRadius:
case CSSPropertyWebkitBorderBottomRightRadius: {
if (isInherit) {
HANDLE_INHERIT_COND(CSSPropertyWebkitBorderTopLeftRadius, borderTopLeftRadius, BorderTopLeftRadius)
HANDLE_INHERIT_COND(CSSPropertyWebkitBorderTopRightRadius, borderTopRightRadius, BorderTopRightRadius)
HANDLE_INHERIT_COND(CSSPropertyWebkitBorderBottomLeftRadius, borderBottomLeftRadius, BorderBottomLeftRadius)
HANDLE_INHERIT_COND(CSSPropertyWebkitBorderBottomRightRadius, borderBottomRightRadius, BorderBottomRightRadius)
return;
}
if (isInitial) {
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyWebkitBorderTopLeftRadius, BorderTopLeftRadius, BorderRadius)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyWebkitBorderTopRightRadius, BorderTopRightRadius, BorderRadius)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyWebkitBorderBottomLeftRadius, BorderBottomLeftRadius, BorderRadius)
HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyWebkitBorderBottomRightRadius, BorderBottomRightRadius, BorderRadius)
return;
}
if (!primitiveValue)
return;
Pair* pair = primitiveValue->getPairValue();
if (!pair)
return;
int width = pair->first()->computeLengthInt(m_style, zoomFactor);
int height = pair->second()->computeLengthInt(m_style, zoomFactor);
if (width < 0 || height < 0)
return;
if (width == 0)
height = 0; // Null out the other value.
else if (height == 0)
width = 0; // Null out the other value.
IntSize size(width, height);
switch (id) {
case CSSPropertyWebkitBorderTopLeftRadius:
m_style->setBorderTopLeftRadius(size);
break;
case CSSPropertyWebkitBorderTopRightRadius:
m_style->setBorderTopRightRadius(size);
break;
case CSSPropertyWebkitBorderBottomLeftRadius:
m_style->setBorderBottomLeftRadius(size);
break;
case CSSPropertyWebkitBorderBottomRightRadius:
m_style->setBorderBottomRightRadius(size);
break;
default:
m_style->setBorderRadius(size);
break;
}
return;
}
case CSSPropertyOutlineOffset:
HANDLE_INHERIT_AND_INITIAL(outlineOffset, OutlineOffset)
m_style->setOutlineOffset(primitiveValue->computeLengthInt(m_style, zoomFactor));
return;
case CSSPropertyTextShadow:
case CSSPropertyWebkitBoxShadow: {
if (isInherit) {
if (id == CSSPropertyTextShadow)
return m_style->setTextShadow(m_parentStyle->textShadow() ? new ShadowData(*m_parentStyle->textShadow()) : 0);
return m_style->setBoxShadow(m_parentStyle->boxShadow() ? new ShadowData(*m_parentStyle->boxShadow()) : 0);
}
if (isInitial || primitiveValue) // initial | none
return id == CSSPropertyTextShadow ? m_style->setTextShadow(0) : m_style->setBoxShadow(0);
if (!value->isValueList())
return;
CSSValueList *list = static_cast<CSSValueList*>(value);
int len = list->length();
for (int i = 0; i < len; i++) {
ShadowValue* item = static_cast<ShadowValue*>(list->itemWithoutBoundsCheck(i));
int x = item->x->computeLengthInt(m_style, zoomFactor);
int y = item->y->computeLengthInt(m_style, zoomFactor);
int blur = item->blur ? item->blur->computeLengthInt(m_style, zoomFactor) : 0;
Color color;
if (item->color)
color = getColorFromPrimitiveValue(item->color.get());
ShadowData* shadowData = new ShadowData(x, y, blur, color.isValid() ? color : Color::transparent);
if (id == CSSPropertyTextShadow)
m_style->setTextShadow(shadowData, i != 0);
else
m_style->setBoxShadow(shadowData, i != 0);
}
return;
}
case CSSPropertyWebkitBoxReflect: {
HANDLE_INHERIT_AND_INITIAL(boxReflect, BoxReflect)
if (primitiveValue) {
m_style->setBoxReflect(RenderStyle::initialBoxReflect());
return;
}
CSSReflectValue* reflectValue = static_cast<CSSReflectValue*>(value);
RefPtr<StyleReflection> reflection = StyleReflection::create();
reflection->setDirection(reflectValue->direction());
if (reflectValue->offset()) {
int type = reflectValue->offset()->primitiveType();
if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
reflection->setOffset(Length(reflectValue->offset()->getDoubleValue(), Percent));
else
reflection->setOffset(Length(reflectValue->offset()->computeLengthIntForLength(m_style, zoomFactor), Fixed));
}
NinePieceImage mask;
mapNinePieceImage(reflectValue->mask(), mask);
reflection->setMask(mask);
m_style->setBoxReflect(reflection.release());
return;
}
case CSSPropertyOpacity:
HANDLE_INHERIT_AND_INITIAL(opacity, Opacity)
if (!primitiveValue || primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_NUMBER)
return; // Error case.
// Clamp opacity to the range 0-1
m_style->setOpacity(min(1.0f, max(0.0f, primitiveValue->getFloatValue())));
return;
case CSSPropertyWebkitBoxAlign:
{
HANDLE_INHERIT_AND_INITIAL(boxAlign, BoxAlign)
if (!primitiveValue)
return;
EBoxAlignment boxAlignment = *primitiveValue;
if (boxAlignment != BJUSTIFY)
m_style->setBoxAlign(boxAlignment);
return;
}
case CSSPropertySrc: // Only used in @font-face rules.
return;
case CSSPropertyUnicodeRange: // Only used in @font-face rules.
return;
case CSSPropertyWebkitBoxDirection:
HANDLE_INHERIT_AND_INITIAL(boxDirection, BoxDirection)
if (primitiveValue)
m_style->setBoxDirection(*primitiveValue);
return;
case CSSPropertyWebkitBoxLines:
HANDLE_INHERIT_AND_INITIAL(boxLines, BoxLines)
if (primitiveValue)
m_style->setBoxLines(*primitiveValue);
return;
case CSSPropertyWebkitBoxOrient:
HANDLE_INHERIT_AND_INITIAL(boxOrient, BoxOrient)
if (primitiveValue)
m_style->setBoxOrient(*primitiveValue);
return;
case CSSPropertyWebkitBoxPack:
{
HANDLE_INHERIT_AND_INITIAL(boxPack, BoxPack)
if (!primitiveValue)
return;
EBoxAlignment boxPack = *primitiveValue;
if (boxPack != BSTRETCH && boxPack != BBASELINE)
m_style->setBoxPack(boxPack);
return;
}
case CSSPropertyWebkitBoxFlex:
HANDLE_INHERIT_AND_INITIAL(boxFlex, BoxFlex)
if (!primitiveValue || primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_NUMBER)
return; // Error case.
m_style->setBoxFlex(primitiveValue->getFloatValue());
return;
case CSSPropertyWebkitBoxFlexGroup:
HANDLE_INHERIT_AND_INITIAL(boxFlexGroup, BoxFlexGroup)
if (!primitiveValue || primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_NUMBER)
return; // Error case.
m_style->setBoxFlexGroup((unsigned int)(primitiveValue->getDoubleValue()));
return;
case CSSPropertyWebkitBoxOrdinalGroup:
HANDLE_INHERIT_AND_INITIAL(boxOrdinalGroup, BoxOrdinalGroup)
if (!primitiveValue || primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_NUMBER)
return; // Error case.
m_style->setBoxOrdinalGroup((unsigned int)(primitiveValue->getDoubleValue()));
return;
case CSSPropertyWebkitBoxSizing:
HANDLE_INHERIT_AND_INITIAL(boxSizing, BoxSizing)
if (!primitiveValue)
return;
if (primitiveValue->getIdent() == CSSValueContentBox)
m_style->setBoxSizing(CONTENT_BOX);
else
m_style->setBoxSizing(BORDER_BOX);
return;
case CSSPropertyWebkitColumnCount: {
if (isInherit) {
if (m_parentStyle->hasAutoColumnCount())
m_style->setHasAutoColumnCount();
else
m_style->setColumnCount(m_parentStyle->columnCount());
return;
} else if (isInitial || primitiveValue->getIdent() == CSSValueAuto) {
m_style->setHasAutoColumnCount();
return;
}
m_style->setColumnCount(static_cast<unsigned short>(primitiveValue->getDoubleValue()));
return;
}
case CSSPropertyWebkitColumnGap: {
if (isInherit) {
if (m_parentStyle->hasNormalColumnGap())
m_style->setHasNormalColumnGap();
else
m_style->setColumnGap(m_parentStyle->columnGap());
return;
} else if (isInitial || primitiveValue->getIdent() == CSSValueNormal) {
m_style->setHasNormalColumnGap();
return;
}
m_style->setColumnGap(primitiveValue->computeLengthFloat(m_style, zoomFactor));
return;
}
case CSSPropertyWebkitColumnWidth: {
if (isInherit) {
if (m_parentStyle->hasAutoColumnWidth())
m_style->setHasAutoColumnWidth();
else
m_style->setColumnWidth(m_parentStyle->columnWidth());
return;
} else if (isInitial || primitiveValue->getIdent() == CSSValueAuto) {
m_style->setHasAutoColumnWidth();
return;
}
m_style->setColumnWidth(primitiveValue->computeLengthFloat(m_style, zoomFactor));
return;
}
case CSSPropertyWebkitColumnRuleStyle:
HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(columnRuleStyle, ColumnRuleStyle, BorderStyle)
m_style->setColumnRuleStyle(*primitiveValue);
return;
case CSSPropertyWebkitColumnBreakBefore: {
HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(columnBreakBefore, ColumnBreakBefore, PageBreak)
m_style->setColumnBreakBefore(*primitiveValue);
return;
}
case CSSPropertyWebkitColumnBreakAfter: {
HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(columnBreakAfter, ColumnBreakAfter, PageBreak)
m_style->setColumnBreakAfter(*primitiveValue);
return;
}
case CSSPropertyWebkitColumnBreakInside: {
HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(columnBreakInside, ColumnBreakInside, PageBreak)
EPageBreak pb = *primitiveValue;
if (pb != PBALWAYS)
m_style->setColumnBreakInside(pb);
return;
}
case CSSPropertyWebkitColumnRule:
if (isInherit) {
m_style->setColumnRuleColor(m_parentStyle->columnRuleColor().isValid() ? m_parentStyle->columnRuleColor() : m_parentStyle->color());
m_style->setColumnRuleStyle(m_parentStyle->columnRuleStyle());
m_style->setColumnRuleWidth(m_parentStyle->columnRuleWidth());
}
else if (isInitial)
m_style->resetColumnRule();
return;
case CSSPropertyWebkitColumns:
if (isInherit) {
if (m_parentStyle->hasAutoColumnWidth())
m_style->setHasAutoColumnWidth();
else
m_style->setColumnWidth(m_parentStyle->columnWidth());
m_style->setColumnCount(m_parentStyle->columnCount());
} else if (isInitial) {
m_style->setHasAutoColumnWidth();
m_style->setColumnCount(RenderStyle::initialColumnCount());
}
return;
case CSSPropertyWebkitMarquee:
if (valueType != CSSValue::CSS_INHERIT || !m_parentNode) return;
m_style->setMarqueeDirection(m_parentStyle->marqueeDirection());
m_style->setMarqueeIncrement(m_parentStyle->marqueeIncrement());
m_style->setMarqueeSpeed(m_parentStyle->marqueeSpeed());
m_style->setMarqueeLoopCount(m_parentStyle->marqueeLoopCount());
m_style->setMarqueeBehavior(m_parentStyle->marqueeBehavior());
return;
case CSSPropertyWebkitMarqueeRepetition: {
HANDLE_INHERIT_AND_INITIAL(marqueeLoopCount, MarqueeLoopCount)
if (!primitiveValue)
return;
if (primitiveValue->getIdent() == CSSValueInfinite)
m_style->setMarqueeLoopCount(-1); // -1 means repeat forever.
else if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_NUMBER)
m_style->setMarqueeLoopCount(primitiveValue->getIntValue());
return;
}
case CSSPropertyWebkitMarqueeSpeed: {
HANDLE_INHERIT_AND_INITIAL(marqueeSpeed, MarqueeSpeed)
if (!primitiveValue)
return;
if (primitiveValue->getIdent()) {
switch (primitiveValue->getIdent()) {
case CSSValueSlow:
m_style->setMarqueeSpeed(500); // 500 msec.
break;
case CSSValueNormal:
m_style->setMarqueeSpeed(85); // 85msec. The WinIE default.
break;
case CSSValueFast:
m_style->setMarqueeSpeed(10); // 10msec. Super fast.
break;
}
}
else if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_S)
m_style->setMarqueeSpeed(1000 * primitiveValue->getIntValue());
else if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_MS)
m_style->setMarqueeSpeed(primitiveValue->getIntValue());
else if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_NUMBER) // For scrollamount support.
m_style->setMarqueeSpeed(primitiveValue->getIntValue());
return;
}
case CSSPropertyWebkitMarqueeIncrement: {
HANDLE_INHERIT_AND_INITIAL(marqueeIncrement, MarqueeIncrement)
if (!primitiveValue)
return;
if (primitiveValue->getIdent()) {
switch (primitiveValue->getIdent()) {
case CSSValueSmall:
m_style->setMarqueeIncrement(Length(1, Fixed)); // 1px.
break;
case CSSValueNormal:
m_style->setMarqueeIncrement(Length(6, Fixed)); // 6px. The WinIE default.
break;
case CSSValueLarge:
m_style->setMarqueeIncrement(Length(36, Fixed)); // 36px.
break;
}
}
else {
bool ok = true;
Length l = convertToLength(primitiveValue, m_style, &ok);
if (ok)
m_style->setMarqueeIncrement(l);
}
return;
}
case CSSPropertyWebkitMarqueeStyle: {
HANDLE_INHERIT_AND_INITIAL(marqueeBehavior, MarqueeBehavior)
if (primitiveValue)
m_style->setMarqueeBehavior(*primitiveValue);
return;
}
case CSSPropertyWebkitMarqueeDirection: {
HANDLE_INHERIT_AND_INITIAL(marqueeDirection, MarqueeDirection)
if (primitiveValue)
m_style->setMarqueeDirection(*primitiveValue);
return;
}
case CSSPropertyWebkitUserDrag: {
HANDLE_INHERIT_AND_INITIAL(userDrag, UserDrag)
if (primitiveValue)
m_style->setUserDrag(*primitiveValue);
return;
}
case CSSPropertyWebkitUserModify: {
HANDLE_INHERIT_AND_INITIAL(userModify, UserModify)
if (primitiveValue)
m_style->setUserModify(*primitiveValue);
return;
}
case CSSPropertyWebkitUserSelect: {
HANDLE_INHERIT_AND_INITIAL(userSelect, UserSelect)
if (primitiveValue)
m_style->setUserSelect(*primitiveValue);
return;
}
case CSSPropertyTextOverflow: {
// This property is supported by WinIE, and so we leave off the "-webkit-" in order to
// work with WinIE-specific pages that use the property.
HANDLE_INHERIT_AND_INITIAL(textOverflow, TextOverflow)
if (!primitiveValue || !primitiveValue->getIdent())
return;
m_style->setTextOverflow(primitiveValue->getIdent() == CSSValueEllipsis);
return;
}
case CSSPropertyWebkitMarginCollapse: {
if (isInherit) {
m_style->setMarginTopCollapse(m_parentStyle->marginTopCollapse());
m_style->setMarginBottomCollapse(m_parentStyle->marginBottomCollapse());
}
else if (isInitial) {
m_style->setMarginTopCollapse(MCOLLAPSE);
m_style->setMarginBottomCollapse(MCOLLAPSE);
}
return;
}
case CSSPropertyWebkitMarginTopCollapse: {
HANDLE_INHERIT_AND_INITIAL(marginTopCollapse, MarginTopCollapse)
if (primitiveValue)
m_style->setMarginTopCollapse(*primitiveValue);
return;
}
case CSSPropertyWebkitMarginBottomCollapse: {
HANDLE_INHERIT_AND_INITIAL(marginBottomCollapse, MarginBottomCollapse)
if (primitiveValue)
m_style->setMarginBottomCollapse(*primitiveValue);
return;
}
// Apple-specific changes. Do not merge these properties into KHTML.
case CSSPropertyWebkitLineClamp: {
HANDLE_INHERIT_AND_INITIAL(lineClamp, LineClamp)
if (!primitiveValue)
return;
m_style->setLineClamp(primitiveValue->getIntValue(CSSPrimitiveValue::CSS_PERCENTAGE));
return;
}
case CSSPropertyWebkitHighlight: {
HANDLE_INHERIT_AND_INITIAL(highlight, Highlight);
if (primitiveValue->getIdent() == CSSValueNone)
m_style->setHighlight(nullAtom);
else
m_style->setHighlight(primitiveValue->getStringValue());
return;
}
case CSSPropertyWebkitBorderFit: {
HANDLE_INHERIT_AND_INITIAL(borderFit, BorderFit);
if (primitiveValue->getIdent() == CSSValueBorder)
m_style->setBorderFit(BorderFitBorder);
else
m_style->setBorderFit(BorderFitLines);
return;
}
case CSSPropertyWebkitTextSizeAdjust: {
HANDLE_INHERIT_AND_INITIAL(textSizeAdjust, TextSizeAdjust)
if (!primitiveValue || !primitiveValue->getIdent()) return;
m_style->setTextSizeAdjust(primitiveValue->getIdent() == CSSValueAuto);
m_fontDirty = true;
return;
}
case CSSPropertyWebkitTextSecurity: {
HANDLE_INHERIT_AND_INITIAL(textSecurity, TextSecurity)
if (primitiveValue)
m_style->setTextSecurity(*primitiveValue);
return;
}
#if ENABLE(DASHBOARD_SUPPORT)
case CSSPropertyWebkitDashboardRegion: {
HANDLE_INHERIT_AND_INITIAL(dashboardRegions, DashboardRegions)
if (!primitiveValue)
return;
if (primitiveValue->getIdent() == CSSValueNone) {
m_style->setDashboardRegions(RenderStyle::noneDashboardRegions());
return;
}
DashboardRegion *region = primitiveValue->getDashboardRegionValue();
if (!region)
return;
DashboardRegion *first = region;
while (region) {
Length top = convertToLength (region->top(), m_style);
Length right = convertToLength (region->right(), m_style);
Length bottom = convertToLength (region->bottom(), m_style);
Length left = convertToLength (region->left(), m_style);
if (region->m_isCircle)
m_style->setDashboardRegion(StyleDashboardRegion::Circle, region->m_label, top, right, bottom, left, region == first ? false : true);
else if (region->m_isRectangle)
m_style->setDashboardRegion(StyleDashboardRegion::Rectangle, region->m_label, top, right, bottom, left, region == first ? false : true);
region = region->m_next.get();
}
m_element->document()->setHasDashboardRegions(true);
return;
}
#endif
case CSSPropertyWebkitRtlOrdering:
HANDLE_INHERIT_AND_INITIAL(visuallyOrdered, VisuallyOrdered)
if (!primitiveValue || !primitiveValue->getIdent())
return;
m_style->setVisuallyOrdered(primitiveValue->getIdent() == CSSValueVisual);
return;
case CSSPropertyWebkitTextStrokeWidth: {
HANDLE_INHERIT_AND_INITIAL(textStrokeWidth, TextStrokeWidth)
float width = 0;
switch (primitiveValue->getIdent()) {
case CSSValueThin:
case CSSValueMedium:
case CSSValueThick: {
double result = 1.0 / 48;
if (primitiveValue->getIdent() == CSSValueMedium)
result *= 3;
else if (primitiveValue->getIdent() == CSSValueThick)
result *= 5;
CSSPrimitiveValue val(result, CSSPrimitiveValue::CSS_EMS);
width = val.computeLengthFloat(m_style, zoomFactor);
break;
}
default:
width = primitiveValue->computeLengthFloat(m_style, zoomFactor);
break;
}
m_style->setTextStrokeWidth(width);
return;
}
case CSSPropertyWebkitTransform: {
HANDLE_INHERIT_AND_INITIAL(transform, Transform);
TransformOperations operations;
if (!value->isPrimitiveValue()) {
CSSValueList* list = static_cast<CSSValueList*>(value);
unsigned size = list->length();
for (unsigned i = 0; i < size; i++) {
CSSTransformValue* val = static_cast<CSSTransformValue*>(list->itemWithoutBoundsCheck(i));
CSSValueList* values = val->values();
CSSPrimitiveValue* firstValue = static_cast<CSSPrimitiveValue*>(values->itemWithoutBoundsCheck(0));
switch (val->type()) {
case CSSTransformValue::ScaleTransformOperation:
case CSSTransformValue::ScaleXTransformOperation:
case CSSTransformValue::ScaleYTransformOperation: {
double sx = 1.0;
double sy = 1.0;
if (val->type() == CSSTransformValue::ScaleYTransformOperation)
sy = firstValue->getDoubleValue();
else {
sx = firstValue->getDoubleValue();
if (val->type() == CSSTransformValue::ScaleTransformOperation) {
if (values->length() > 1) {
CSSPrimitiveValue* secondValue = static_cast<CSSPrimitiveValue*>(values->itemWithoutBoundsCheck(1));
sy = secondValue->getDoubleValue();
} else
sy = sx;
}
}
operations.append(ScaleTransformOperation::create(sx, sy));
break;
}
case CSSTransformValue::TranslateTransformOperation:
case CSSTransformValue::TranslateXTransformOperation:
case CSSTransformValue::TranslateYTransformOperation: {
bool ok;
Length tx = Length(0, Fixed);
Length ty = Length(0, Fixed);
if (val->type() == CSSTransformValue::TranslateYTransformOperation)
ty = convertToLength(firstValue, m_style, &ok);
else {
tx = convertToLength(firstValue, m_style, &ok);
if (val->type() == CSSTransformValue::TranslateTransformOperation) {
if (values->length() > 1) {
CSSPrimitiveValue* secondValue = static_cast<CSSPrimitiveValue*>(values->itemWithoutBoundsCheck(1));
ty = convertToLength(secondValue, m_style, &ok);
}
}
}
operations.append(TranslateTransformOperation::create(tx, ty));
break;
}
case CSSTransformValue::RotateTransformOperation: {
double angle = firstValue->getDoubleValue();
if (firstValue->primitiveType() == CSSPrimitiveValue::CSS_RAD)
angle = rad2deg(angle);
else if (firstValue->primitiveType() == CSSPrimitiveValue::CSS_GRAD)
angle = grad2deg(angle);
operations.append(RotateTransformOperation::create(angle));
break;
}
case CSSTransformValue::SkewTransformOperation:
case CSSTransformValue::SkewXTransformOperation:
case CSSTransformValue::SkewYTransformOperation: {
double angleX = 0;
double angleY = 0;
double angle = firstValue->getDoubleValue();
if (firstValue->primitiveType() == CSSPrimitiveValue::CSS_RAD)
angle = rad2deg(angle);
else if (firstValue->primitiveType() == CSSPrimitiveValue::CSS_GRAD)
angle = grad2deg(angle);
if (val->type() == CSSTransformValue::SkewYTransformOperation)
angleY = angle;
else {
angleX = angle;
if (val->type() == CSSTransformValue::SkewTransformOperation) {
if (values->length() > 1) {
CSSPrimitiveValue* secondValue = static_cast<CSSPrimitiveValue*>(values->itemWithoutBoundsCheck(1));
angleY = secondValue->getDoubleValue();
if (secondValue->primitiveType() == CSSPrimitiveValue::CSS_RAD)
angleY = rad2deg(angle);
else if (secondValue->primitiveType() == CSSPrimitiveValue::CSS_GRAD)
angleY = grad2deg(angle);
} else
angleY = angleX;
}
}
operations.append(SkewTransformOperation::create(angleX, angleY));
break;
}
case CSSTransformValue::MatrixTransformOperation: {
double a = firstValue->getDoubleValue();
double b = static_cast<CSSPrimitiveValue*>(values->itemWithoutBoundsCheck(1))->getDoubleValue();
double c = static_cast<CSSPrimitiveValue*>(values->itemWithoutBoundsCheck(2))->getDoubleValue();
double d = static_cast<CSSPrimitiveValue*>(values->itemWithoutBoundsCheck(3))->getDoubleValue();
double e = static_cast<CSSPrimitiveValue*>(values->itemWithoutBoundsCheck(4))->getDoubleValue();
double f = static_cast<CSSPrimitiveValue*>(values->itemWithoutBoundsCheck(5))->getDoubleValue();
operations.append(MatrixTransformOperation::create(a, b, c, d, e, f));
break;
}
case CSSTransformValue::UnknownTransformOperation:
ASSERT_NOT_REACHED();
break;
}
}
}
m_style->setTransform(operations);
return;
}
case CSSPropertyWebkitTransformOrigin:
HANDLE_INHERIT_AND_INITIAL(transformOriginX, TransformOriginX)
HANDLE_INHERIT_AND_INITIAL(transformOriginY, TransformOriginY)
return;
case CSSPropertyWebkitTransformOriginX: {
HANDLE_INHERIT_AND_INITIAL(transformOriginX, TransformOriginX)
CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
Length l;
int type = primitiveValue->primitiveType();
if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
l = Length(primitiveValue->computeLengthIntForLength(m_style, zoomFactor), Fixed);
else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
l = Length(primitiveValue->getDoubleValue(), Percent);
else
return;
m_style->setTransformOriginX(l);
break;
}
case CSSPropertyWebkitTransformOriginY: {
HANDLE_INHERIT_AND_INITIAL(transformOriginY, TransformOriginY)
CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
Length l;
int type = primitiveValue->primitiveType();
if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
l = Length(primitiveValue->computeLengthIntForLength(m_style, zoomFactor), Fixed);
else if(type == CSSPrimitiveValue::CSS_PERCENTAGE)
l = Length(primitiveValue->getDoubleValue(), Percent);
else
return;
m_style->setTransformOriginY(l);
break;
}
case CSSPropertyWebkitTransition:
if (isInitial)
m_style->clearTransitions();
else if (isInherit)
m_style->inheritTransitions(m_parentStyle->transitions());
return;
case CSSPropertyWebkitTransitionDuration:
HANDLE_TRANSITION_VALUE(duration, Duration, value)
return;
case CSSPropertyWebkitTransitionRepeatCount:
HANDLE_TRANSITION_VALUE(repeatCount, RepeatCount, value)
return;
case CSSPropertyWebkitTransitionTimingFunction:
HANDLE_TRANSITION_VALUE(timingFunction, TimingFunction, value)
return;
case CSSPropertyWebkitTransitionProperty:
HANDLE_TRANSITION_VALUE(property, Property, value)
return;
case CSSPropertyInvalid:
return;
case CSSPropertyFontStretch:
case CSSPropertyPage:
case CSSPropertyQuotes:
case CSSPropertyScrollbar3dlightColor:
case CSSPropertyScrollbarArrowColor:
case CSSPropertyScrollbarDarkshadowColor:
case CSSPropertyScrollbarFaceColor:
case CSSPropertyScrollbarHighlightColor:
case CSSPropertyScrollbarShadowColor:
case CSSPropertyScrollbarTrackColor:
case CSSPropertySize:
case CSSPropertyTextLineThrough:
case CSSPropertyTextLineThroughColor:
case CSSPropertyTextLineThroughMode:
case CSSPropertyTextLineThroughStyle:
case CSSPropertyTextLineThroughWidth:
case CSSPropertyTextOverline:
case CSSPropertyTextOverlineColor:
case CSSPropertyTextOverlineMode:
case CSSPropertyTextOverlineStyle:
case CSSPropertyTextOverlineWidth:
case CSSPropertyTextUnderline:
case CSSPropertyTextUnderlineColor:
case CSSPropertyTextUnderlineMode:
case CSSPropertyTextUnderlineStyle:
case CSSPropertyTextUnderlineWidth:
case CSSPropertyWebkitFontSizeDelta:
case CSSPropertyWebkitMarginStart:
case CSSPropertyWebkitPaddingStart:
case CSSPropertyWebkitTextDecorationsInEffect:
case CSSPropertyWebkitTextStroke:
return;
#if ENABLE(SVG)
default:
// Try the SVG properties
applySVGProperty(id, value);
#endif
}
}
void CSSStyleSelector::mapFillAttachment(FillLayer* layer, CSSValue* value)
{
if (value->cssValueType() == CSSValue::CSS_INITIAL) {
layer->setAttachment(FillLayer::initialFillAttachment(layer->type()));
return;
}
if (!value->isPrimitiveValue())
return;
CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
switch (primitiveValue->getIdent()) {
case CSSValueFixed:
layer->setAttachment(false);
break;
case CSSValueScroll:
layer->setAttachment(true);
break;
default:
return;
}
}
void CSSStyleSelector::mapFillClip(FillLayer* layer, CSSValue* value)
{
if (value->cssValueType() == CSSValue::CSS_INITIAL) {
layer->setClip(FillLayer::initialFillClip(layer->type()));
return;
}
if (!value->isPrimitiveValue())
return;
CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
layer->setClip(*primitiveValue);
}
void CSSStyleSelector::mapFillComposite(FillLayer* layer, CSSValue* value)
{
if (value->cssValueType() == CSSValue::CSS_INITIAL) {
layer->setComposite(FillLayer::initialFillComposite(layer->type()));
return;
}
if (!value->isPrimitiveValue())
return;
CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
layer->setComposite(*primitiveValue);
}
void CSSStyleSelector::mapFillOrigin(FillLayer* layer, CSSValue* value)
{
if (value->cssValueType() == CSSValue::CSS_INITIAL) {
layer->setOrigin(FillLayer::initialFillOrigin(layer->type()));
return;
}
if (!value->isPrimitiveValue())
return;
CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
layer->setOrigin(*primitiveValue);
}
StyleImage* CSSStyleSelector::styleImage(CSSValue* value)
{
if (value->isImageValue())
return static_cast<CSSImageValue*>(value)->cachedImage(m_element->document()->docLoader());
if (value->isImageGeneratorValue())
return static_cast<CSSImageGeneratorValue*>(value)->generatedImage();
return 0;
}
void CSSStyleSelector::mapFillImage(FillLayer* layer, CSSValue* value)
{
if (value->cssValueType() == CSSValue::CSS_INITIAL) {
layer->setImage(FillLayer::initialFillImage(layer->type()));
return;
}
layer->setImage(styleImage(value));
}
void CSSStyleSelector::mapFillRepeat(FillLayer* layer, CSSValue* value)
{
if (value->cssValueType() == CSSValue::CSS_INITIAL) {
layer->setRepeat(FillLayer::initialFillRepeat(layer->type()));
return;
}
if (!value->isPrimitiveValue())
return;
CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
layer->setRepeat(*primitiveValue);
}
void CSSStyleSelector::mapFillSize(FillLayer* layer, CSSValue* value)
{
LengthSize b = FillLayer::initialFillSize(layer->type());
if (value->cssValueType() == CSSValue::CSS_INITIAL) {
layer->setSize(b);
return;
}
if (!value->isPrimitiveValue())
return;
CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
Pair* pair = primitiveValue->getPairValue();
if (!pair)
return;
CSSPrimitiveValue* first = static_cast<CSSPrimitiveValue*>(pair->first());
CSSPrimitiveValue* second = static_cast<CSSPrimitiveValue*>(pair->second());
if (!first || !second)
return;
Length firstLength, secondLength;
int firstType = first->primitiveType();
int secondType = second->primitiveType();
float zoomFactor = m_style->effectiveZoom();
if (firstType == CSSPrimitiveValue::CSS_UNKNOWN)
firstLength = Length(Auto);
else if (firstType > CSSPrimitiveValue::CSS_PERCENTAGE && firstType < CSSPrimitiveValue::CSS_DEG)
firstLength = Length(first->computeLengthIntForLength(m_style, zoomFactor), Fixed);
else if (firstType == CSSPrimitiveValue::CSS_PERCENTAGE)
firstLength = Length(first->getDoubleValue(), Percent);
else
return;
if (secondType == CSSPrimitiveValue::CSS_UNKNOWN)
secondLength = Length(Auto);
else if (secondType > CSSPrimitiveValue::CSS_PERCENTAGE && secondType < CSSPrimitiveValue::CSS_DEG)
secondLength = Length(second->computeLengthIntForLength(m_style, zoomFactor), Fixed);
else if (secondType == CSSPrimitiveValue::CSS_PERCENTAGE)
secondLength = Length(second->getDoubleValue(), Percent);
else
return;
b.width = firstLength;
b.height = secondLength;
layer->setSize(b);
}
void CSSStyleSelector::mapFillXPosition(FillLayer* layer, CSSValue* value)
{
if (value->cssValueType() == CSSValue::CSS_INITIAL) {
layer->setXPosition(FillLayer::initialFillXPosition(layer->type()));
return;
}
if (!value->isPrimitiveValue())
return;
float zoomFactor = m_style->effectiveZoom();
CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
Length l;
int type = primitiveValue->primitiveType();
if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
l = Length(primitiveValue->computeLengthIntForLength(m_style, zoomFactor), Fixed);
else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
l = Length(primitiveValue->getDoubleValue(), Percent);
else
return;
layer->setXPosition(l);
}
void CSSStyleSelector::mapFillYPosition(FillLayer* layer, CSSValue* value)
{
if (value->cssValueType() == CSSValue::CSS_INITIAL) {
layer->setYPosition(FillLayer::initialFillYPosition(layer->type()));
return;
}
if (!value->isPrimitiveValue())
return;
float zoomFactor = m_style->effectiveZoom();
CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
Length l;
int type = primitiveValue->primitiveType();
if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
l = Length(primitiveValue->computeLengthIntForLength(m_style, zoomFactor), Fixed);
else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
l = Length(primitiveValue->getDoubleValue(), Percent);
else
return;
layer->setYPosition(l);
}
void CSSStyleSelector::mapTransitionDuration(Transition* transition, CSSValue* value)
{
if (value->cssValueType() == CSSValue::CSS_INITIAL) {
transition->setDuration(RenderStyle::initialTransitionDuration());
return;
}
if (!value->isPrimitiveValue())
return;
CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_S)
transition->setDuration(int(1000*primitiveValue->getFloatValue()));
else if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_MS)
transition->setDuration(int(primitiveValue->getFloatValue()));
}
void CSSStyleSelector::mapTransitionRepeatCount(Transition* transition, CSSValue* value)
{
if (value->cssValueType() == CSSValue::CSS_INITIAL) {
transition->setRepeatCount(RenderStyle::initialTransitionRepeatCount());
return;
}
if (!value->isPrimitiveValue())
return;
CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
if (primitiveValue->getIdent() == CSSValueInfinite)
transition->setRepeatCount(-1);
else
transition->setRepeatCount(int(primitiveValue->getFloatValue()));
}
void CSSStyleSelector::mapTransitionTimingFunction(Transition* transition, CSSValue* value)
{
if (value->cssValueType() == CSSValue::CSS_INITIAL) {
transition->setTimingFunction(RenderStyle::initialTransitionTimingFunction());
return;
}
if (value->isPrimitiveValue()) {
CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
switch (primitiveValue->getIdent()) {
case CSSValueLinear:
transition->setTimingFunction(TimingFunction(LinearTimingFunction));
break;
case CSSValueEase:
transition->setTimingFunction(TimingFunction());
break;
case CSSValueEaseIn:
transition->setTimingFunction(TimingFunction(CubicBezierTimingFunction, .42, .0, 1.0, 1.0));
break;
case CSSValueEaseOut:
transition->setTimingFunction(TimingFunction(CubicBezierTimingFunction, .0, .0, .58, 1.0));
break;
case CSSValueEaseInOut:
transition->setTimingFunction(TimingFunction(CubicBezierTimingFunction, .42, .0, .58, 1.0));
break;
}
return;
}
if (value->isTransitionTimingFunctionValue()) {
CSSTimingFunctionValue* timingFunction = static_cast<CSSTimingFunctionValue*>(value);
transition->setTimingFunction(TimingFunction(CubicBezierTimingFunction, timingFunction->x1(), timingFunction->y1(), timingFunction->x2(), timingFunction->y2()));
}
}
void CSSStyleSelector::mapTransitionProperty(Transition* transition, CSSValue* value)
{
if (value->cssValueType() == CSSValue::CSS_INITIAL) {
transition->setProperty(RenderStyle::initialTransitionProperty());
return;
}
if (!value->isPrimitiveValue())
return;
CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
transition->setProperty(primitiveValue->getIdent());
}
void CSSStyleSelector::mapNinePieceImage(CSSValue* value, NinePieceImage& image)
{
// If we're a primitive value, then we are "none" and don't need to alter the empty image at all.
if (!value || value->isPrimitiveValue())
return;
// Retrieve the border image value.
CSSBorderImageValue* borderImage = static_cast<CSSBorderImageValue*>(value);
// Set the image (this kicks off the load).
image.m_image = styleImage(borderImage->imageValue());
// Set up a length box to represent our image slices.
LengthBox& l = image.m_slices;
Rect* r = borderImage->m_imageSliceRect.get();
if (r->top()->primitiveType() == CSSPrimitiveValue::CSS_PERCENTAGE)
l.top = Length(r->top()->getDoubleValue(), Percent);
else
l.top = Length(r->top()->getIntValue(CSSPrimitiveValue::CSS_NUMBER), Fixed);
if (r->bottom()->primitiveType() == CSSPrimitiveValue::CSS_PERCENTAGE)
l.bottom = Length(r->bottom()->getDoubleValue(), Percent);
else
l.bottom = Length((int)r->bottom()->getFloatValue(CSSPrimitiveValue::CSS_NUMBER), Fixed);
if (r->left()->primitiveType() == CSSPrimitiveValue::CSS_PERCENTAGE)
l.left = Length(r->left()->getDoubleValue(), Percent);
else
l.left = Length(r->left()->getIntValue(CSSPrimitiveValue::CSS_NUMBER), Fixed);
if (r->right()->primitiveType() == CSSPrimitiveValue::CSS_PERCENTAGE)
l.right = Length(r->right()->getDoubleValue(), Percent);
else
l.right = Length(r->right()->getIntValue(CSSPrimitiveValue::CSS_NUMBER), Fixed);
// Set the appropriate rules for stretch/round/repeat of the slices
switch (borderImage->m_horizontalSizeRule) {
case CSSValueStretch:
image.m_horizontalRule = StretchImageRule;
break;
case CSSValueRound:
image.m_horizontalRule = RoundImageRule;
break;
default: // CSSValueRepeat
image.m_horizontalRule = RepeatImageRule;
break;
}
switch (borderImage->m_verticalSizeRule) {
case CSSValueStretch:
image.m_verticalRule = StretchImageRule;
break;
case CSSValueRound:
image.m_verticalRule = RoundImageRule;
break;
default: // CSSValueRepeat
image.m_verticalRule = RepeatImageRule;
break;
}
}
void CSSStyleSelector::checkForTextSizeAdjust()
{
if (m_style->textSizeAdjust())
return;
FontDescription newFontDescription(m_style->fontDescription());
newFontDescription.setComputedSize(newFontDescription.specifiedSize());
m_style->setFontDescription(newFontDescription);
}
void CSSStyleSelector::checkForZoomChange(RenderStyle* style, RenderStyle* parentStyle)
{
if (style->effectiveZoom() == parentStyle->effectiveZoom())
return;
const FontDescription& childFont = style->fontDescription();
FontDescription newFontDescription(childFont);
setFontSize(newFontDescription, childFont.specifiedSize());
style->setFontDescription(newFontDescription);
}
void CSSStyleSelector::checkForGenericFamilyChange(RenderStyle* style, RenderStyle* parentStyle)
{
const FontDescription& childFont = style->fontDescription();
if (childFont.isAbsoluteSize() || !parentStyle)
return;
const FontDescription& parentFont = parentStyle->fontDescription();
if (childFont.genericFamily() == parentFont.genericFamily())
return;
// For now, lump all families but monospace together.
if (childFont.genericFamily() != FontDescription::MonospaceFamily &&
parentFont.genericFamily() != FontDescription::MonospaceFamily)
return;
// We know the parent is monospace or the child is monospace, and that font
// size was unspecified. We want to scale our font size as appropriate.
// If the font uses a keyword size, then we refetch from the table rather than
// multiplying by our scale factor.
float size;
if (childFont.keywordSize()) {
size = fontSizeForKeyword(CSSValueXxSmall + childFont.keywordSize() - 1, style->htmlHacks(),
childFont.genericFamily() == FontDescription::MonospaceFamily);
} else {
Settings* settings = m_checker.m_document->settings();
float fixedScaleFactor = settings
? static_cast<float>(settings->defaultFixedFontSize()) / settings->defaultFontSize()
: 1;
size = (parentFont.genericFamily() == FontDescription::MonospaceFamily) ?
childFont.specifiedSize()/fixedScaleFactor :
childFont.specifiedSize()*fixedScaleFactor;
}
FontDescription newFontDescription(childFont);
setFontSize(newFontDescription, size);
style->setFontDescription(newFontDescription);
}
void CSSStyleSelector::setFontSize(FontDescription& fontDescription, float size)
{
fontDescription.setSpecifiedSize(size);
fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(fontDescription.isAbsoluteSize(), size));
}
float CSSStyleSelector::getComputedSizeFromSpecifiedSize(bool isAbsoluteSize, float specifiedSize)
{
// We support two types of minimum font size. The first is a hard override that applies to
// all fonts. This is "minSize." The second type of minimum font size is a "smart minimum"
// that is applied only when the Web page can't know what size it really asked for, e.g.,
// when it uses logical sizes like "small" or expresses the font-size as a percentage of
// the user's default font setting.
// With the smart minimum, we never want to get smaller than the minimum font size to keep fonts readable.
// However we always allow the page to set an explicit pixel size that is smaller,
// since sites will mis-render otherwise (e.g., http://www.gamespot.com with a 9px minimum).
Settings* settings = m_checker.m_document->settings();
if (!settings)
return 1.0f;
int minSize = settings->minimumFontSize();
int minLogicalSize = settings->minimumLogicalFontSize();
float zoomFactor = m_style->effectiveZoom();
if (m_checker.m_document->frame() && m_checker.m_document->frame()->shouldApplyTextZoom())
zoomFactor *= m_checker.m_document->frame()->textZoomFactor();
float zoomedSize = specifiedSize * zoomFactor;
// Apply the hard minimum first. We only apply the hard minimum if after zooming we're still too small.
if (zoomedSize < minSize)
zoomedSize = minSize;
// Now apply the "smart minimum." This minimum is also only applied if we're still too small
// after zooming. The font size must either be relative to the user default or the original size
// must have been acceptable. In other words, we only apply the smart minimum whenever we're positive
// doing so won't disrupt the layout.
if (zoomedSize < minLogicalSize && (specifiedSize >= minLogicalSize || !isAbsoluteSize))
zoomedSize = minLogicalSize;
// Also clamp to a reasonable maximum to prevent insane font sizes from causing crashes on various
// platforms (I'm looking at you, Windows.)
return min(1000000.0f, max(zoomedSize, 1.0f));
}
const int fontSizeTableMax = 16;
const int fontSizeTableMin = 9;
const int totalKeywords = 8;
// WinIE/Nav4 table for font sizes. Designed to match the legacy font mapping system of HTML.
static const int quirksFontSizeTable[fontSizeTableMax - fontSizeTableMin + 1][totalKeywords] =
{
{ 9, 9, 9, 9, 11, 14, 18, 28 },
{ 9, 9, 9, 10, 12, 15, 20, 31 },
{ 9, 9, 9, 11, 13, 17, 22, 34 },
{ 9, 9, 10, 12, 14, 18, 24, 37 },
{ 9, 9, 10, 13, 16, 20, 26, 40 }, // fixed font default (13)
{ 9, 9, 11, 14, 17, 21, 28, 42 },
{ 9, 10, 12, 15, 17, 23, 30, 45 },
{ 9, 10, 13, 16, 18, 24, 32, 48 } // proportional font default (16)
};
// HTML 1 2 3 4 5 6 7
// CSS xxs xs s m l xl xxl
// |
// user pref
// Strict mode table matches MacIE and Mozilla's settings exactly.
static const int strictFontSizeTable[fontSizeTableMax - fontSizeTableMin + 1][totalKeywords] =
{
{ 9, 9, 9, 9, 11, 14, 18, 27 },
{ 9, 9, 9, 10, 12, 15, 20, 30 },
{ 9, 9, 10, 11, 13, 17, 22, 33 },
{ 9, 9, 10, 12, 14, 18, 24, 36 },
{ 9, 10, 12, 13, 16, 20, 26, 39 }, // fixed font default (13)
{ 9, 10, 12, 14, 17, 21, 28, 42 },
{ 9, 10, 13, 15, 18, 23, 30, 45 },
{ 9, 10, 13, 16, 18, 24, 32, 48 } // proportional font default (16)
};
// HTML 1 2 3 4 5 6 7
// CSS xxs xs s m l xl xxl
// |
// user pref
// For values outside the range of the table, we use Todd Fahrner's suggested scale
// factors for each keyword value.
static const float fontSizeFactors[totalKeywords] = { 0.60f, 0.75f, 0.89f, 1.0f, 1.2f, 1.5f, 2.0f, 3.0f };
float CSSStyleSelector::fontSizeForKeyword(int keyword, bool quirksMode, bool fixed) const
{
Settings* settings = m_checker.m_document->settings();
if (!settings)
return 1.0f;
int mediumSize = fixed ? settings->defaultFixedFontSize() : settings->defaultFontSize();
if (mediumSize >= fontSizeTableMin && mediumSize <= fontSizeTableMax) {
// Look up the entry in the table.
int row = mediumSize - fontSizeTableMin;
int col = (keyword - CSSValueXxSmall);
return quirksMode ? quirksFontSizeTable[row][col] : strictFontSizeTable[row][col];
}
// Value is outside the range of the table. Apply the scale factor instead.
float minLogicalSize = max(settings->minimumLogicalFontSize(), 1);
return max(fontSizeFactors[keyword - CSSValueXxSmall]*mediumSize, minLogicalSize);
}
float CSSStyleSelector::largerFontSize(float size, bool quirksMode) const
{
// FIXME: Figure out where we fall in the size ranges (xx-small to xxx-large) and scale up to
// the next size level.
return size * 1.2f;
}
float CSSStyleSelector::smallerFontSize(float size, bool quirksMode) const
{
// FIXME: Figure out where we fall in the size ranges (xx-small to xxx-large) and scale down to
// the next size level.
return size / 1.2f;
}
static Color colorForCSSValue(int cssValueId)
{
struct ColorValue {
int cssValueId;
RGBA32 color;
};
static const ColorValue colorValues[] = {
{ CSSValueAqua, 0xFF00FFFF },
{ CSSValueBlack, 0xFF000000 },
{ CSSValueBlue, 0xFF0000FF },
{ CSSValueFuchsia, 0xFFFF00FF },
{ CSSValueGray, 0xFF808080 },
{ CSSValueGreen, 0xFF008000 },
{ CSSValueGrey, 0xFF808080 },
{ CSSValueLime, 0xFF00FF00 },
{ CSSValueMaroon, 0xFF800000 },
{ CSSValueNavy, 0xFF000080 },
{ CSSValueOlive, 0xFF808000 },
{ CSSValueOrange, 0xFFFFA500 },
{ CSSValuePurple, 0xFF800080 },
{ CSSValueRed, 0xFFFF0000 },
{ CSSValueSilver, 0xFFC0C0C0 },
{ CSSValueTeal, 0xFF008080 },
{ CSSValueTransparent, 0x00000000 },
{ CSSValueWhite, 0xFFFFFFFF },
{ CSSValueYellow, 0xFFFFFF00 },
{ 0, 0 }
};
for (const ColorValue* col = colorValues; col->cssValueId; ++col) {
if (col->cssValueId == cssValueId)
return col->color;
}
return theme()->systemColor(cssValueId);
}
Color CSSStyleSelector::getColorFromPrimitiveValue(CSSPrimitiveValue* primitiveValue)
{
Color col;
int ident = primitiveValue->getIdent();
if (ident) {
if (ident == CSSValueWebkitText)
col = m_element->document()->textColor();
else if (ident == CSSValueWebkitLink) {
const Color& linkColor = m_element->document()->linkColor();
const Color& visitedColor = m_element->document()->visitedLinkColor();
if (linkColor == visitedColor)
col = linkColor;
else {
if (pseudoState == PseudoUnknown || pseudoState == PseudoAnyLink)
pseudoState = m_checker.checkPseudoState(m_element);
col = (pseudoState == PseudoLink) ? linkColor : visitedColor;
}
} else if (ident == CSSValueWebkitActivelink)
col = m_element->document()->activeLinkColor();
else if (ident == CSSValueWebkitFocusRingColor)
col = focusRingColor();
else if (ident == CSSValueCurrentcolor)
col = m_style->color();
else
col = colorForCSSValue(ident);
} else if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_RGBCOLOR)
col.setRGB(primitiveValue->getRGBColorValue());
return col;
}
bool CSSStyleSelector::hasSelectorForAttribute(const AtomicString &attrname)
{
return m_selectorAttrs.contains(attrname.impl());
}
void CSSStyleSelector::addViewportDependentMediaQueryResult(const MediaQueryExp* expr, bool result)
{
m_viewportDependentMediaQueryResults.append(new MediaQueryResult(*expr, result));
}
bool CSSStyleSelector::affectedByViewportChange() const
{
unsigned s = m_viewportDependentMediaQueryResults.size();
for (unsigned i = 0; i < s; i++) {
if (m_medium->eval(&m_viewportDependentMediaQueryResults[i]->m_expression) != m_viewportDependentMediaQueryResults[i]->m_result)
return true;
}
return false;
}
void CSSStyleSelector::SelectorChecker::allVisitedStateChanged()
{
if (m_linksCheckedForVisitedState.isEmpty())
return;
for (Node* node = m_document; node; node = node->traverseNextNode()) {
if (node->isLink())
node->setChanged();
}
}
void CSSStyleSelector::SelectorChecker::visitedStateChanged(unsigned visitedHash)
{
if (!m_linksCheckedForVisitedState.contains(visitedHash))
return;
for (Node* node = m_document; node; node = node->traverseNextNode()) {
const AtomicString* attr = linkAttribute(node);
if (attr && m_document->visitedLinkHash(*attr) == visitedHash)
node->setChanged();
}
}
} // namespace WebCore
|