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
|
/*
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 1999 Antti Koivisto (koivisto@kde.org)
* (C) 2001 Peter Kelly (pmk@post.com)
* (C) 2001 Dirk Mueller (mueller@kde.org)
* (C) 2007 David Smith (catfish.man@gmail.com)
* Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
* (C) 2007 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 "Element.h"
#include "AXObjectCache.h"
#include "Attr.h"
#include "CSSParser.h"
#include "CSSSelectorList.h"
#include "Chrome.h"
#include "ChromeClient.h"
#include "ClassList.h"
#include "ClientRect.h"
#include "ClientRectList.h"
#include "CustomElementRegistry.h"
#include "DOMTokenList.h"
#include "DatasetDOMStringMap.h"
#include "Document.h"
#include "DocumentFragment.h"
#include "DocumentSharedObjectPool.h"
#include "ElementRareData.h"
#include "EventDispatcher.h"
#include "ExceptionCode.h"
#include "FlowThreadController.h"
#include "FocusController.h"
#include "FocusEvent.h"
#include "Frame.h"
#include "FrameSelection.h"
#include "FrameView.h"
#include "HTMLCollection.h"
#include "HTMLDocument.h"
#include "HTMLElement.h"
#include "HTMLFormControlsCollection.h"
#include "HTMLFrameOwnerElement.h"
#include "HTMLLabelElement.h"
#include "HTMLNameCollection.h"
#include "HTMLNames.h"
#include "HTMLOptionsCollection.h"
#include "HTMLParserIdioms.h"
#include "HTMLTableRowsCollection.h"
#include "InsertionPoint.h"
#include "InspectorInstrumentation.h"
#include "MutationObserverInterestGroup.h"
#include "MutationRecord.h"
#include "NamedNodeMap.h"
#include "NodeList.h"
#include "NodeRenderStyle.h"
#include "NodeRenderingContext.h"
#include "NodeTraversal.h"
#include "Page.h"
#include "PointerLockController.h"
#include "PseudoElement.h"
#include "RenderRegion.h"
#include "RenderTheme.h"
#include "RenderView.h"
#include "RenderWidget.h"
#include "SelectorQuery.h"
#include "Settings.h"
#include "ShadowRoot.h"
#include "StylePropertySet.h"
#include "StyleResolver.h"
#include "Text.h"
#include "TextIterator.h"
#include "VoidCallback.h"
#include "XMLNSNames.h"
#include "XMLNames.h"
#include "htmlediting.h"
#include <wtf/BitVector.h>
#include <wtf/CurrentTime.h>
#include <wtf/text/CString.h>
#if ENABLE(SVG)
#include "SVGDocumentExtensions.h"
#include "SVGElement.h"
#include "SVGNames.h"
#endif
namespace WebCore {
using namespace HTMLNames;
using namespace XMLNames;
static inline bool shouldIgnoreAttributeCase(const Element* e)
{
return e && e->document()->isHTMLDocument() && e->isHTMLElement();
}
class StyleResolverParentPusher {
public:
StyleResolverParentPusher(Element* parent)
: m_parent(parent)
, m_pushedStyleResolver(0)
{
}
void push()
{
if (m_pushedStyleResolver)
return;
m_pushedStyleResolver = m_parent->document()->ensureStyleResolver();
m_pushedStyleResolver->pushParentElement(m_parent);
}
~StyleResolverParentPusher()
{
if (!m_pushedStyleResolver)
return;
// This tells us that our pushed style selector is in a bad state,
// so we should just bail out in that scenario.
ASSERT(m_pushedStyleResolver == m_parent->document()->ensureStyleResolver());
if (m_pushedStyleResolver != m_parent->document()->ensureStyleResolver())
return;
m_pushedStyleResolver->popParentElement(m_parent);
}
private:
Element* m_parent;
StyleResolver* m_pushedStyleResolver;
};
typedef Vector<RefPtr<Attr> > AttrNodeList;
typedef HashMap<Element*, OwnPtr<AttrNodeList> > AttrNodeListMap;
static AttrNodeListMap& attrNodeListMap()
{
DEFINE_STATIC_LOCAL(AttrNodeListMap, map, ());
return map;
}
static AttrNodeList* attrNodeListForElement(Element* element)
{
if (!element->hasSyntheticAttrChildNodes())
return 0;
ASSERT(attrNodeListMap().contains(element));
return attrNodeListMap().get(element);
}
static AttrNodeList* ensureAttrNodeListForElement(Element* element)
{
if (element->hasSyntheticAttrChildNodes()) {
ASSERT(attrNodeListMap().contains(element));
return attrNodeListMap().get(element);
}
ASSERT(!attrNodeListMap().contains(element));
element->setHasSyntheticAttrChildNodes(true);
AttrNodeListMap::AddResult result = attrNodeListMap().add(element, adoptPtr(new AttrNodeList));
return result.iterator->value.get();
}
static void removeAttrNodeListForElement(Element* element)
{
ASSERT(element->hasSyntheticAttrChildNodes());
ASSERT(attrNodeListMap().contains(element));
attrNodeListMap().remove(element);
element->setHasSyntheticAttrChildNodes(false);
}
static Attr* findAttrNodeInList(AttrNodeList* attrNodeList, const QualifiedName& name)
{
for (unsigned i = 0; i < attrNodeList->size(); ++i) {
if (attrNodeList->at(i)->qualifiedName() == name)
return attrNodeList->at(i).get();
}
return 0;
}
PassRefPtr<Element> Element::create(const QualifiedName& tagName, Document* document)
{
return adoptRef(new Element(tagName, document, CreateElement));
}
Element::~Element()
{
#ifndef NDEBUG
if (document() && document()->renderer()) {
// When the document is not destroyed, an element that was part of a named flow
// content nodes should have been removed from the content nodes collection
// and the inNamedFlow flag reset.
ASSERT(!inNamedFlow());
}
#endif
if (hasRareData()) {
ElementRareData* data = elementRareData();
data->setPseudoElement(BEFORE, 0);
data->setPseudoElement(AFTER, 0);
data->clearShadow();
}
if (hasSyntheticAttrChildNodes())
detachAllAttrNodesFromElement();
#if ENABLE(SVG)
if (hasPendingResources()) {
document()->accessSVGExtensions()->removeElementFromPendingResources(this);
ASSERT(!hasPendingResources());
}
#endif
}
inline ElementRareData* Element::elementRareData() const
{
ASSERT(hasRareData());
return static_cast<ElementRareData*>(rareData());
}
inline ElementRareData* Element::ensureElementRareData()
{
return static_cast<ElementRareData*>(ensureRareData());
}
void Element::clearTabIndexExplicitlyIfNeeded()
{
if (hasRareData())
elementRareData()->clearTabIndexExplicitly();
}
void Element::setTabIndexExplicitly(short tabIndex)
{
ensureElementRareData()->setTabIndexExplicitly(tabIndex);
}
bool Element::supportsFocus() const
{
return hasRareData() && elementRareData()->tabIndexSetExplicitly();
}
Element* Element::focusDelegate()
{
return this;
}
short Element::tabIndex() const
{
return hasRareData() ? elementRareData()->tabIndex() : 0;
}
bool Element::isKeyboardFocusable(KeyboardEvent*) const
{
return isFocusable() && tabIndex() >= 0;
}
bool Element::isMouseFocusable() const
{
return isFocusable();
}
bool Element::shouldUseInputMethod()
{
return isContentEditable(UserSelectAllIsAlwaysNonEditable);
}
void Element::dispatchSimulatedClick(Event* underlyingEvent, SimulatedClickMouseEventOptions eventOptions, SimulatedClickVisualOptions visualOptions)
{
EventDispatcher::dispatchSimulatedClick(this, underlyingEvent, eventOptions, visualOptions);
}
DEFINE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(Element, blur);
DEFINE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(Element, error);
DEFINE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(Element, focus);
DEFINE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(Element, load);
PassRefPtr<Node> Element::cloneNode(bool deep)
{
return deep ? cloneElementWithChildren() : cloneElementWithoutChildren();
}
PassRefPtr<Element> Element::cloneElementWithChildren()
{
RefPtr<Element> clone = cloneElementWithoutChildren();
cloneChildNodes(clone.get());
return clone.release();
}
PassRefPtr<Element> Element::cloneElementWithoutChildren()
{
RefPtr<Element> clone = cloneElementWithoutAttributesAndChildren();
// This will catch HTML elements in the wrong namespace that are not correctly copied.
// This is a sanity check as HTML overloads some of the DOM methods.
ASSERT(isHTMLElement() == clone->isHTMLElement());
clone->cloneDataFromElement(*this);
return clone.release();
}
PassRefPtr<Element> Element::cloneElementWithoutAttributesAndChildren()
{
return document()->createElement(tagQName(), false);
}
PassRefPtr<Attr> Element::detachAttribute(unsigned index)
{
ASSERT(elementData());
const Attribute* attribute = elementData()->attributeItem(index);
ASSERT(attribute);
RefPtr<Attr> attrNode = attrIfExists(attribute->name());
if (attrNode)
detachAttrNodeFromElementWithValue(attrNode.get(), attribute->value());
else
attrNode = Attr::create(document(), attribute->name(), attribute->value());
removeAttributeInternal(index, NotInSynchronizationOfLazyAttribute);
return attrNode.release();
}
void Element::removeAttribute(const QualifiedName& name)
{
if (!elementData())
return;
unsigned index = elementData()->getAttributeItemIndex(name);
if (index == ElementData::attributeNotFound)
return;
removeAttributeInternal(index, NotInSynchronizationOfLazyAttribute);
}
void Element::setBooleanAttribute(const QualifiedName& name, bool value)
{
if (value)
setAttribute(name, emptyAtom);
else
removeAttribute(name);
}
NamedNodeMap* Element::attributes() const
{
ElementRareData* rareData = const_cast<Element*>(this)->ensureElementRareData();
if (NamedNodeMap* attributeMap = rareData->attributeMap())
return attributeMap;
rareData->setAttributeMap(NamedNodeMap::create(const_cast<Element*>(this)));
return rareData->attributeMap();
}
Node::NodeType Element::nodeType() const
{
return ELEMENT_NODE;
}
bool Element::hasAttribute(const QualifiedName& name) const
{
return hasAttributeNS(name.namespaceURI(), name.localName());
}
void Element::synchronizeAllAttributes() const
{
if (!elementData())
return;
if (elementData()->m_styleAttributeIsDirty) {
ASSERT(isStyledElement());
static_cast<const StyledElement*>(this)->synchronizeStyleAttributeInternal();
}
#if ENABLE(SVG)
if (elementData()->m_animatedSVGAttributesAreDirty) {
ASSERT(isSVGElement());
toSVGElement(this)->synchronizeAnimatedSVGAttribute(anyQName());
}
#endif
}
inline void Element::synchronizeAttribute(const QualifiedName& name) const
{
if (!elementData())
return;
if (UNLIKELY(name == styleAttr && elementData()->m_styleAttributeIsDirty)) {
ASSERT(isStyledElement());
static_cast<const StyledElement*>(this)->synchronizeStyleAttributeInternal();
return;
}
#if ENABLE(SVG)
if (UNLIKELY(elementData()->m_animatedSVGAttributesAreDirty)) {
ASSERT(isSVGElement());
toSVGElement(this)->synchronizeAnimatedSVGAttribute(name);
}
#endif
}
inline void Element::synchronizeAttribute(const AtomicString& localName) const
{
// This version of synchronizeAttribute() is streamlined for the case where you don't have a full QualifiedName,
// e.g when called from DOM API.
if (!elementData())
return;
if (elementData()->m_styleAttributeIsDirty && equalPossiblyIgnoringCase(localName, styleAttr.localName(), shouldIgnoreAttributeCase(this))) {
ASSERT(isStyledElement());
static_cast<const StyledElement*>(this)->synchronizeStyleAttributeInternal();
return;
}
#if ENABLE(SVG)
if (elementData()->m_animatedSVGAttributesAreDirty) {
// We're not passing a namespace argument on purpose. SVGNames::*Attr are defined w/o namespaces as well.
ASSERT(isSVGElement());
static_cast<const SVGElement*>(this)->synchronizeAnimatedSVGAttribute(QualifiedName(nullAtom, localName, nullAtom));
}
#endif
}
const AtomicString& Element::getAttribute(const QualifiedName& name) const
{
if (!elementData())
return nullAtom;
synchronizeAttribute(name);
if (const Attribute* attribute = getAttributeItem(name))
return attribute->value();
return nullAtom;
}
bool Element::isFocusable() const
{
if (!inDocument() || !supportsFocus())
return false;
// Elements in canvas fallback content are not rendered, but they are allowed to be
// focusable as long as their canvas is displayed and visible.
if (isInCanvasSubtree()) {
const Element* e = this;
while (e && !e->hasLocalName(canvasTag))
e = e->parentElement();
ASSERT(e);
return e->renderer() && e->renderer()->style()->visibility() == VISIBLE;
}
if (renderer())
ASSERT(!renderer()->needsLayout());
else {
// If the node is in a display:none tree it might say it needs style recalc but
// the whole document is actually up to date.
ASSERT(!document()->childNeedsStyleRecalc());
}
// FIXME: Even if we are not visible, we might have a child that is visible.
// Hyatt wants to fix that some day with a "has visible content" flag or the like.
if (!renderer() || renderer()->style()->visibility() != VISIBLE)
return false;
return true;
}
bool Element::isUserActionElementInActiveChain() const
{
ASSERT(isUserActionElement());
return document()->userActionElements().isInActiveChain(this);
}
bool Element::isUserActionElementActive() const
{
ASSERT(isUserActionElement());
return document()->userActionElements().isActive(this);
}
bool Element::isUserActionElementFocused() const
{
ASSERT(isUserActionElement());
return document()->userActionElements().isFocused(this);
}
bool Element::isUserActionElementHovered() const
{
ASSERT(isUserActionElement());
return document()->userActionElements().isHovered(this);
}
void Element::setActive(bool flag, bool pause)
{
if (flag == active())
return;
if (Document* document = this->document())
document->userActionElements().setActive(this, flag);
if (!renderer())
return;
bool reactsToPress = renderStyle()->affectedByActive() || childrenAffectedByActive();
if (reactsToPress)
setNeedsStyleRecalc();
if (renderer()->style()->hasAppearance() && renderer()->theme()->stateChanged(renderer(), PressedState))
reactsToPress = true;
// The rest of this function implements a feature that only works if the
// platform supports immediate invalidations on the ChromeClient, so bail if
// that isn't supported.
if (!document()->page()->chrome().client()->supportsImmediateInvalidation())
return;
if (reactsToPress && pause) {
// The delay here is subtle. It relies on an assumption, namely that the amount of time it takes
// to repaint the "down" state of the control is about the same time as it would take to repaint the
// "up" state. Once you assume this, you can just delay for 100ms - that time (assuming that after you
// leave this method, it will be about that long before the flush of the up state happens again).
#ifdef HAVE_FUNC_USLEEP
double startTime = currentTime();
#endif
Document::updateStyleForAllDocuments();
// Do an immediate repaint.
if (renderer())
renderer()->repaint(true);
// FIXME: Come up with a less ridiculous way of doing this.
#ifdef HAVE_FUNC_USLEEP
// Now pause for a small amount of time (1/10th of a second from before we repainted in the pressed state)
double remainingTime = 0.1 - (currentTime() - startTime);
if (remainingTime > 0)
usleep(static_cast<useconds_t>(remainingTime * 1000000.0));
#endif
}
}
void Element::setFocus(bool flag)
{
if (flag == focused())
return;
if (Document* document = this->document())
document->userActionElements().setFocused(this, flag);
setNeedsStyleRecalc();
}
void Element::setHovered(bool flag)
{
if (flag == hovered())
return;
if (Document* document = this->document())
document->userActionElements().setHovered(this, flag);
if (!renderer()) {
// When setting hover to false, the style needs to be recalc'd even when
// there's no renderer (imagine setting display:none in the :hover class,
// if a nil renderer would prevent this element from recalculating its
// style, it would never go back to its normal style and remain
// stuck in its hovered style).
if (!flag)
setNeedsStyleRecalc();
return;
}
if (renderer()->style()->affectedByHover() || childrenAffectedByHover())
setNeedsStyleRecalc();
if (renderer()->style()->hasAppearance())
renderer()->theme()->stateChanged(renderer(), HoverState);
}
void Element::scrollIntoView(bool alignToTop)
{
document()->updateLayoutIgnorePendingStylesheets();
if (!renderer())
return;
LayoutRect bounds = boundingBox();
// Align to the top / bottom and to the closest edge.
if (alignToTop)
renderer()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignTopAlways);
else
renderer()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignBottomAlways);
}
void Element::scrollIntoViewIfNeeded(bool centerIfNeeded)
{
document()->updateLayoutIgnorePendingStylesheets();
if (!renderer())
return;
LayoutRect bounds = boundingBox();
if (centerIfNeeded)
renderer()->scrollRectToVisible(bounds, ScrollAlignment::alignCenterIfNeeded, ScrollAlignment::alignCenterIfNeeded);
else
renderer()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignToEdgeIfNeeded);
}
void Element::scrollByUnits(int units, ScrollGranularity granularity)
{
document()->updateLayoutIgnorePendingStylesheets();
if (!renderer())
return;
if (!renderer()->hasOverflowClip())
return;
ScrollDirection direction = ScrollDown;
if (units < 0) {
direction = ScrollUp;
units = -units;
}
Node* stopNode = this;
toRenderBox(renderer())->scroll(direction, granularity, units, &stopNode);
}
void Element::scrollByLines(int lines)
{
scrollByUnits(lines, ScrollByLine);
}
void Element::scrollByPages(int pages)
{
scrollByUnits(pages, ScrollByPage);
}
static float localZoomForRenderer(RenderObject* renderer)
{
// FIXME: This does the wrong thing if two opposing zooms are in effect and canceled each
// other out, but the alternative is that we'd have to crawl up the whole render tree every
// time (or store an additional bit in the RenderStyle to indicate that a zoom was specified).
float zoomFactor = 1;
if (renderer->style()->effectiveZoom() != 1) {
// Need to find the nearest enclosing RenderObject that set up
// a differing zoom, and then we divide our result by it to eliminate the zoom.
RenderObject* prev = renderer;
for (RenderObject* curr = prev->parent(); curr; curr = curr->parent()) {
if (curr->style()->effectiveZoom() != prev->style()->effectiveZoom()) {
zoomFactor = prev->style()->zoom();
break;
}
prev = curr;
}
if (prev->isRenderView())
zoomFactor = prev->style()->zoom();
}
return zoomFactor;
}
static int adjustForLocalZoom(LayoutUnit value, RenderObject* renderer)
{
float zoomFactor = localZoomForRenderer(renderer);
if (zoomFactor == 1)
return value;
#if ENABLE(SUBPIXEL_LAYOUT)
return lroundf(value / zoomFactor);
#else
// Needed because computeLengthInt truncates (rather than rounds) when scaling up.
if (zoomFactor > 1)
value++;
return static_cast<int>(value / zoomFactor);
#endif
}
int Element::offsetLeft()
{
document()->updateLayoutIgnorePendingStylesheets();
if (RenderBoxModelObject* renderer = renderBoxModelObject())
return adjustForLocalZoom(renderer->pixelSnappedOffsetLeft(), renderer);
return 0;
}
int Element::offsetTop()
{
document()->updateLayoutIgnorePendingStylesheets();
if (RenderBoxModelObject* renderer = renderBoxModelObject())
return adjustForLocalZoom(renderer->pixelSnappedOffsetTop(), renderer);
return 0;
}
int Element::offsetWidth()
{
document()->updateLayoutIgnorePendingStylesheets();
if (RenderBoxModelObject* renderer = renderBoxModelObject())
#if ENABLE(SUBPIXEL_LAYOUT)
return adjustLayoutUnitForAbsoluteZoom(renderer->pixelSnappedOffsetWidth(), renderer).round();
#else
return adjustForAbsoluteZoom(renderer->pixelSnappedOffsetWidth(), renderer);
#endif
return 0;
}
int Element::offsetHeight()
{
document()->updateLayoutIgnorePendingStylesheets();
if (RenderBoxModelObject* renderer = renderBoxModelObject())
#if ENABLE(SUBPIXEL_LAYOUT)
return adjustLayoutUnitForAbsoluteZoom(renderer->pixelSnappedOffsetHeight(), renderer).round();
#else
return adjustForAbsoluteZoom(renderer->pixelSnappedOffsetHeight(), renderer);
#endif
return 0;
}
Element* Element::bindingsOffsetParent()
{
Element* element = offsetParent();
if (!element || !element->isInShadowTree())
return element;
return element->containingShadowRoot()->type() == ShadowRoot::UserAgentShadowRoot ? 0 : element;
}
Element* Element::offsetParent()
{
document()->updateLayoutIgnorePendingStylesheets();
if (RenderObject* renderer = this->renderer()) {
if (RenderObject* offsetParent = renderer->offsetParent())
return toElement(offsetParent->node());
}
return 0;
}
int Element::clientLeft()
{
document()->updateLayoutIgnorePendingStylesheets();
if (RenderBox* renderer = renderBox())
return adjustForAbsoluteZoom(roundToInt(renderer->clientLeft()), renderer);
return 0;
}
int Element::clientTop()
{
document()->updateLayoutIgnorePendingStylesheets();
if (RenderBox* renderer = renderBox())
return adjustForAbsoluteZoom(roundToInt(renderer->clientTop()), renderer);
return 0;
}
int Element::clientWidth()
{
document()->updateLayoutIgnorePendingStylesheets();
// When in strict mode, clientWidth for the document element should return the width of the containing frame.
// When in quirks mode, clientWidth for the body element should return the width of the containing frame.
bool inQuirksMode = document()->inQuirksMode();
if ((!inQuirksMode && document()->documentElement() == this) ||
(inQuirksMode && isHTMLElement() && document()->body() == this)) {
if (FrameView* view = document()->view()) {
if (RenderView* renderView = document()->renderView())
return adjustForAbsoluteZoom(view->layoutWidth(), renderView);
}
}
if (RenderBox* renderer = renderBox())
#if ENABLE(SUBPIXEL_LAYOUT)
return adjustLayoutUnitForAbsoluteZoom(renderer->pixelSnappedClientWidth(), renderer).round();
#else
return adjustForAbsoluteZoom(renderer->pixelSnappedClientWidth(), renderer);
#endif
return 0;
}
int Element::clientHeight()
{
document()->updateLayoutIgnorePendingStylesheets();
// When in strict mode, clientHeight for the document element should return the height of the containing frame.
// When in quirks mode, clientHeight for the body element should return the height of the containing frame.
bool inQuirksMode = document()->inQuirksMode();
if ((!inQuirksMode && document()->documentElement() == this) ||
(inQuirksMode && isHTMLElement() && document()->body() == this)) {
if (FrameView* view = document()->view()) {
if (RenderView* renderView = document()->renderView())
return adjustForAbsoluteZoom(view->layoutHeight(), renderView);
}
}
if (RenderBox* renderer = renderBox())
#if ENABLE(SUBPIXEL_LAYOUT)
return adjustLayoutUnitForAbsoluteZoom(renderer->pixelSnappedClientHeight(), renderer).round();
#else
return adjustForAbsoluteZoom(renderer->pixelSnappedClientHeight(), renderer);
#endif
return 0;
}
int Element::scrollLeft()
{
document()->updateLayoutIgnorePendingStylesheets();
if (RenderBox* rend = renderBox())
return adjustForAbsoluteZoom(rend->scrollLeft(), rend);
return 0;
}
int Element::scrollTop()
{
document()->updateLayoutIgnorePendingStylesheets();
if (RenderBox* rend = renderBox())
return adjustForAbsoluteZoom(rend->scrollTop(), rend);
return 0;
}
void Element::setScrollLeft(int newLeft)
{
document()->updateLayoutIgnorePendingStylesheets();
if (RenderBox* rend = renderBox())
rend->setScrollLeft(static_cast<int>(newLeft * rend->style()->effectiveZoom()));
}
void Element::setScrollTop(int newTop)
{
document()->updateLayoutIgnorePendingStylesheets();
if (RenderBox* rend = renderBox())
rend->setScrollTop(static_cast<int>(newTop * rend->style()->effectiveZoom()));
}
int Element::scrollWidth()
{
document()->updateLayoutIgnorePendingStylesheets();
if (RenderBox* rend = renderBox())
return adjustForAbsoluteZoom(rend->scrollWidth(), rend);
return 0;
}
int Element::scrollHeight()
{
document()->updateLayoutIgnorePendingStylesheets();
if (RenderBox* rend = renderBox())
return adjustForAbsoluteZoom(rend->scrollHeight(), rend);
return 0;
}
IntRect Element::boundsInRootViewSpace()
{
document()->updateLayoutIgnorePendingStylesheets();
FrameView* view = document()->view();
if (!view)
return IntRect();
Vector<FloatQuad> quads;
#if ENABLE(SVG)
if (isSVGElement() && renderer()) {
// Get the bounding rectangle from the SVG model.
SVGElement* svgElement = toSVGElement(this);
FloatRect localRect;
if (svgElement->getBoundingBox(localRect))
quads.append(renderer()->localToAbsoluteQuad(localRect));
} else
#endif
{
// Get the bounding rectangle from the box model.
if (renderBoxModelObject())
renderBoxModelObject()->absoluteQuads(quads);
}
if (quads.isEmpty())
return IntRect();
IntRect result = quads[0].enclosingBoundingBox();
for (size_t i = 1; i < quads.size(); ++i)
result.unite(quads[i].enclosingBoundingBox());
result = view->contentsToRootView(result);
return result;
}
PassRefPtr<ClientRectList> Element::getClientRects()
{
document()->updateLayoutIgnorePendingStylesheets();
RenderBoxModelObject* renderBoxModelObject = this->renderBoxModelObject();
if (!renderBoxModelObject)
return ClientRectList::create();
// FIXME: Handle SVG elements.
// FIXME: Handle table/inline-table with a caption.
Vector<FloatQuad> quads;
renderBoxModelObject->absoluteQuads(quads);
document()->adjustFloatQuadsForScrollAndAbsoluteZoomAndFrameScale(quads, renderBoxModelObject);
return ClientRectList::create(quads);
}
PassRefPtr<ClientRect> Element::getBoundingClientRect()
{
document()->updateLayoutIgnorePendingStylesheets();
Vector<FloatQuad> quads;
#if ENABLE(SVG)
if (isSVGElement() && renderer() && !renderer()->isSVGRoot()) {
// Get the bounding rectangle from the SVG model.
SVGElement* svgElement = toSVGElement(this);
FloatRect localRect;
if (svgElement->getBoundingBox(localRect))
quads.append(renderer()->localToAbsoluteQuad(localRect));
} else
#endif
{
// Get the bounding rectangle from the box model.
if (renderBoxModelObject())
renderBoxModelObject()->absoluteQuads(quads);
}
if (quads.isEmpty())
return ClientRect::create();
FloatRect result = quads[0].boundingBox();
for (size_t i = 1; i < quads.size(); ++i)
result.unite(quads[i].boundingBox());
document()->adjustFloatRectForScrollAndAbsoluteZoomAndFrameScale(result, renderer());
return ClientRect::create(result);
}
IntRect Element::screenRect() const
{
if (!renderer())
return IntRect();
// FIXME: this should probably respect transforms
return document()->view()->contentsToScreen(renderer()->absoluteBoundingBoxRectIgnoringTransforms());
}
const AtomicString& Element::getAttribute(const AtomicString& localName) const
{
if (!elementData())
return nullAtom;
synchronizeAttribute(localName);
if (const Attribute* attribute = elementData()->getAttributeItem(localName, shouldIgnoreAttributeCase(this)))
return attribute->value();
return nullAtom;
}
const AtomicString& Element::getAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const
{
return getAttribute(QualifiedName(nullAtom, localName, namespaceURI));
}
void Element::setAttribute(const AtomicString& localName, const AtomicString& value, ExceptionCode& ec)
{
if (!Document::isValidName(localName)) {
ec = INVALID_CHARACTER_ERR;
return;
}
synchronizeAttribute(localName);
const AtomicString& caseAdjustedLocalName = shouldIgnoreAttributeCase(this) ? localName.lower() : localName;
unsigned index = elementData() ? elementData()->getAttributeItemIndex(caseAdjustedLocalName, false) : ElementData::attributeNotFound;
const QualifiedName& qName = index != ElementData::attributeNotFound ? attributeItem(index)->name() : QualifiedName(nullAtom, caseAdjustedLocalName, nullAtom);
setAttributeInternal(index, qName, value, NotInSynchronizationOfLazyAttribute);
}
void Element::setAttribute(const QualifiedName& name, const AtomicString& value)
{
synchronizeAttribute(name);
unsigned index = elementData() ? elementData()->getAttributeItemIndex(name) : ElementData::attributeNotFound;
setAttributeInternal(index, name, value, NotInSynchronizationOfLazyAttribute);
}
void Element::setSynchronizedLazyAttribute(const QualifiedName& name, const AtomicString& value)
{
unsigned index = elementData() ? elementData()->getAttributeItemIndex(name) : ElementData::attributeNotFound;
setAttributeInternal(index, name, value, InSynchronizationOfLazyAttribute);
}
inline void Element::setAttributeInternal(unsigned index, const QualifiedName& name, const AtomicString& newValue, SynchronizationOfLazyAttribute inSynchronizationOfLazyAttribute)
{
if (newValue.isNull()) {
if (index != ElementData::attributeNotFound)
removeAttributeInternal(index, inSynchronizationOfLazyAttribute);
return;
}
if (index == ElementData::attributeNotFound) {
addAttributeInternal(name, newValue, inSynchronizationOfLazyAttribute);
return;
}
if (!inSynchronizationOfLazyAttribute)
willModifyAttribute(name, attributeItem(index)->value(), newValue);
if (newValue != attributeItem(index)->value()) {
// If there is an Attr node hooked to this attribute, the Attr::setValue() call below
// will write into the ElementData.
// FIXME: Refactor this so it makes some sense.
if (RefPtr<Attr> attrNode = inSynchronizationOfLazyAttribute ? 0 : attrIfExists(name))
attrNode->setValue(newValue);
else
ensureUniqueElementData()->attributeItem(index)->setValue(newValue);
}
if (!inSynchronizationOfLazyAttribute)
didModifyAttribute(name, newValue);
}
static inline AtomicString makeIdForStyleResolution(const AtomicString& value, bool inQuirksMode)
{
if (inQuirksMode)
return value.lower();
return value;
}
static bool checkNeedsStyleInvalidationForIdChange(const AtomicString& oldId, const AtomicString& newId, StyleResolver* styleResolver)
{
ASSERT(newId != oldId);
if (!oldId.isEmpty() && styleResolver->hasSelectorForId(oldId))
return true;
if (!newId.isEmpty() && styleResolver->hasSelectorForId(newId))
return true;
return false;
}
void Element::attributeChanged(const QualifiedName& name, const AtomicString& newValue, AttributeModificationReason)
{
parseAttribute(name, newValue);
document()->incDOMTreeVersion();
StyleResolver* styleResolver = document()->styleResolverIfExists();
bool testShouldInvalidateStyle = attached() && styleResolver && styleChangeType() < FullStyleChange;
bool shouldInvalidateStyle = false;
if (isIdAttributeName(name)) {
AtomicString oldId = elementData()->idForStyleResolution();
AtomicString newId = makeIdForStyleResolution(newValue, document()->inQuirksMode());
if (newId != oldId) {
elementData()->setIdForStyleResolution(newId);
shouldInvalidateStyle = testShouldInvalidateStyle && checkNeedsStyleInvalidationForIdChange(oldId, newId, styleResolver);
}
} else if (name == classAttr)
classAttributeChanged(newValue);
else if (name == HTMLNames::nameAttr)
elementData()->m_hasNameAttribute = !newValue.isNull();
else if (name == HTMLNames::pseudoAttr)
shouldInvalidateStyle |= testShouldInvalidateStyle && isInShadowTree();
invalidateNodeListCachesInAncestors(&name, this);
// If there is currently no StyleResolver, we can't be sure that this attribute change won't affect style.
shouldInvalidateStyle |= !styleResolver;
if (shouldInvalidateStyle)
setNeedsStyleRecalc();
if (AXObjectCache* cache = document()->existingAXObjectCache())
cache->handleAttributeChanged(name, this);
}
inline void Element::attributeChangedFromParserOrByCloning(const QualifiedName& name, const AtomicString& newValue, AttributeModificationReason reason)
{
#if ENABLE(CUSTOM_ELEMENTS)
if (name == isAttr) {
if (CustomElementRegistry* registry = document()->registry())
registry->didGiveTypeExtension(this);
}
#endif
attributeChanged(name, newValue, reason);
}
template <typename CharacterType>
static inline bool classStringHasClassName(const CharacterType* characters, unsigned length)
{
ASSERT(length > 0);
unsigned i = 0;
do {
if (isNotHTMLSpace(characters[i]))
break;
++i;
} while (i < length);
return i < length;
}
static inline bool classStringHasClassName(const AtomicString& newClassString)
{
unsigned length = newClassString.length();
if (!length)
return false;
if (newClassString.is8Bit())
return classStringHasClassName(newClassString.characters8(), length);
return classStringHasClassName(newClassString.characters16(), length);
}
template<typename Checker>
static bool checkSelectorForClassChange(const SpaceSplitString& changedClasses, const Checker& checker)
{
unsigned changedSize = changedClasses.size();
for (unsigned i = 0; i < changedSize; ++i) {
if (checker.hasSelectorForClass(changedClasses[i]))
return true;
}
return false;
}
template<typename Checker>
static bool checkSelectorForClassChange(const SpaceSplitString& oldClasses, const SpaceSplitString& newClasses, const Checker& checker)
{
unsigned oldSize = oldClasses.size();
if (!oldSize)
return checkSelectorForClassChange(newClasses, checker);
BitVector remainingClassBits;
remainingClassBits.ensureSize(oldSize);
// Class vectors tend to be very short. This is faster than using a hash table.
unsigned newSize = newClasses.size();
for (unsigned i = 0; i < newSize; ++i) {
for (unsigned j = 0; j < oldSize; ++j) {
if (newClasses[i] == oldClasses[j]) {
remainingClassBits.quickSet(j);
continue;
}
}
if (checker.hasSelectorForClass(newClasses[i]))
return true;
}
for (unsigned i = 0; i < oldSize; ++i) {
// If the bit is not set the the corresponding class has been removed.
if (remainingClassBits.quickGet(i))
continue;
if (checker.hasSelectorForClass(oldClasses[i]))
return true;
}
return false;
}
void Element::classAttributeChanged(const AtomicString& newClassString)
{
StyleResolver* styleResolver = document()->styleResolverIfExists();
bool testShouldInvalidateStyle = attached() && styleResolver && styleChangeType() < FullStyleChange;
bool shouldInvalidateStyle = false;
if (classStringHasClassName(newClassString)) {
const bool shouldFoldCase = document()->inQuirksMode();
const SpaceSplitString oldClasses = elementData()->classNames();
elementData()->setClass(newClassString, shouldFoldCase);
const SpaceSplitString& newClasses = elementData()->classNames();
shouldInvalidateStyle = testShouldInvalidateStyle && checkSelectorForClassChange(oldClasses, newClasses, *styleResolver);
} else {
const SpaceSplitString& oldClasses = elementData()->classNames();
shouldInvalidateStyle = testShouldInvalidateStyle && checkSelectorForClassChange(oldClasses, *styleResolver);
elementData()->clearClass();
}
if (hasRareData())
elementRareData()->clearClassListValueForQuirksMode();
if (shouldInvalidateStyle)
setNeedsStyleRecalc();
}
// Returns true is the given attribute is an event handler.
// We consider an event handler any attribute that begins with "on".
// It is a simple solution that has the advantage of not requiring any
// code or configuration change if a new event handler is defined.
static inline bool isEventHandlerAttribute(const Attribute& attribute)
{
return attribute.name().namespaceURI().isNull() && attribute.name().localName().startsWith("on");
}
bool Element::isJavaScriptURLAttribute(const Attribute& attribute) const
{
return isURLAttribute(attribute) && protocolIsJavaScript(stripLeadingAndTrailingHTMLSpaces(attribute.value()));
}
void Element::stripScriptingAttributes(Vector<Attribute>& attributeVector) const
{
size_t destination = 0;
for (size_t source = 0; source < attributeVector.size(); ++source) {
if (isEventHandlerAttribute(attributeVector[source])
|| isJavaScriptURLAttribute(attributeVector[source])
|| isHTMLContentAttribute(attributeVector[source]))
continue;
if (source != destination)
attributeVector[destination] = attributeVector[source];
++destination;
}
attributeVector.shrink(destination);
}
void Element::parserSetAttributes(const Vector<Attribute>& attributeVector)
{
ASSERT(!inDocument());
ASSERT(!parentNode());
ASSERT(!m_elementData);
if (attributeVector.isEmpty())
return;
if (document() && document()->sharedObjectPool())
m_elementData = document()->sharedObjectPool()->cachedShareableElementDataWithAttributes(attributeVector);
else
m_elementData = ShareableElementData::createWithAttributes(attributeVector);
// Use attributeVector instead of m_elementData because attributeChanged might modify m_elementData.
for (unsigned i = 0; i < attributeVector.size(); ++i)
attributeChangedFromParserOrByCloning(attributeVector[i].name(), attributeVector[i].value(), ModifiedDirectly);
}
bool Element::hasAttributes() const
{
synchronizeAllAttributes();
return elementData() && elementData()->length();
}
bool Element::hasEquivalentAttributes(const Element* other) const
{
synchronizeAllAttributes();
other->synchronizeAllAttributes();
if (elementData() == other->elementData())
return true;
if (elementData())
return elementData()->isEquivalent(other->elementData());
if (other->elementData())
return other->elementData()->isEquivalent(elementData());
return true;
}
String Element::nodeName() const
{
return m_tagName.toString();
}
String Element::nodeNamePreservingCase() const
{
return m_tagName.toString();
}
void Element::setPrefix(const AtomicString& prefix, ExceptionCode& ec)
{
ec = 0;
checkSetPrefix(prefix, ec);
if (ec)
return;
m_tagName.setPrefix(prefix.isEmpty() ? AtomicString() : prefix);
}
KURL Element::baseURI() const
{
const AtomicString& baseAttribute = getAttribute(baseAttr);
KURL base(KURL(), baseAttribute);
if (!base.protocol().isEmpty())
return base;
ContainerNode* parent = parentNode();
if (!parent)
return base;
const KURL& parentBase = parent->baseURI();
if (parentBase.isNull())
return base;
return KURL(parentBase, baseAttribute);
}
const AtomicString& Element::imageSourceURL() const
{
return getAttribute(srcAttr);
}
bool Element::rendererIsNeeded(const NodeRenderingContext& context)
{
return context.style()->display() != NONE;
}
RenderObject* Element::createRenderer(RenderArena*, RenderStyle* style)
{
return RenderObject::createObject(this, style);
}
bool Element::isDisabledFormControl() const
{
#if ENABLE(DIALOG_ELEMENT)
// FIXME: disabled and inert are separate concepts in the spec, but now we treat them as the same.
// For example, an inert, non-disabled form control should not be grayed out.
if (isInert())
return true;
#endif
return false;
}
#if ENABLE(DIALOG_ELEMENT)
bool Element::isInert() const
{
Element* dialog = document()->activeModalDialog();
return dialog && !containsIncludingShadowDOM(dialog) && !dialog->containsIncludingShadowDOM(this);
}
#endif
Node::InsertionNotificationRequest Element::insertedInto(ContainerNode* insertionPoint)
{
bool wasInDocument = inDocument();
// need to do superclass processing first so inDocument() is true
// by the time we reach updateId
ContainerNode::insertedInto(insertionPoint);
ASSERT(!wasInDocument || inDocument());
#if ENABLE(FULLSCREEN_API)
if (containsFullScreenElement() && parentElement() && !parentElement()->containsFullScreenElement())
setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(true);
#endif
if (Element* before = pseudoElement(BEFORE))
before->insertedInto(insertionPoint);
if (Element* after = pseudoElement(AFTER))
after->insertedInto(insertionPoint);
if (!insertionPoint->isInTreeScope())
return InsertionDone;
if (hasRareData())
elementRareData()->clearClassListValueForQuirksMode();
TreeScope* newScope = insertionPoint->treeScope();
HTMLDocument* newDocument = !wasInDocument && inDocument() && newScope->documentScope()->isHTMLDocument() ? toHTMLDocument(newScope->documentScope()) : 0;
if (newScope != treeScope())
newScope = 0;
const AtomicString& idValue = getIdAttribute();
if (!idValue.isNull()) {
if (newScope)
updateIdForTreeScope(newScope, nullAtom, idValue);
if (newDocument)
updateIdForDocument(newDocument, nullAtom, idValue, AlwaysUpdateHTMLDocumentNamedItemMaps);
}
const AtomicString& nameValue = getNameAttribute();
if (!nameValue.isNull()) {
if (newScope)
updateNameForTreeScope(newScope, nullAtom, nameValue);
if (newDocument)
updateNameForDocument(newDocument, nullAtom, nameValue);
}
if (newScope && hasTagName(labelTag)) {
if (newScope->shouldCacheLabelsByForAttribute())
updateLabel(newScope, nullAtom, fastGetAttribute(forAttr));
}
return InsertionDone;
}
void Element::removedFrom(ContainerNode* insertionPoint)
{
#if ENABLE(SVG)
bool wasInDocument = insertionPoint->document();
#endif
if (Element* before = pseudoElement(BEFORE))
before->removedFrom(insertionPoint);
if (Element* after = pseudoElement(AFTER))
after->removedFrom(insertionPoint);
#if ENABLE(DIALOG_ELEMENT)
document()->removeFromTopLayer(this);
#endif
#if ENABLE(FULLSCREEN_API)
if (containsFullScreenElement())
setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(false);
#endif
#if ENABLE(POINTER_LOCK)
if (document()->page())
document()->page()->pointerLockController()->elementRemoved(this);
#endif
setSavedLayerScrollOffset(IntSize());
if (insertionPoint->isInTreeScope()) {
TreeScope* oldScope = insertionPoint->treeScope();
HTMLDocument* oldDocument = inDocument() && oldScope->documentScope()->isHTMLDocument() ? toHTMLDocument(oldScope->documentScope()) : 0;
if (oldScope != treeScope())
oldScope = 0;
const AtomicString& idValue = getIdAttribute();
if (!idValue.isNull()) {
if (oldScope)
updateIdForTreeScope(oldScope, idValue, nullAtom);
if (oldDocument)
updateIdForDocument(oldDocument, idValue, nullAtom, AlwaysUpdateHTMLDocumentNamedItemMaps);
}
const AtomicString& nameValue = getNameAttribute();
if (!nameValue.isNull()) {
if (oldScope)
updateNameForTreeScope(oldScope, nameValue, nullAtom);
if (oldDocument)
updateNameForDocument(oldDocument, nameValue, nullAtom);
}
if (oldScope && hasTagName(labelTag)) {
if (oldScope->shouldCacheLabelsByForAttribute())
updateLabel(oldScope, fastGetAttribute(forAttr), nullAtom);
}
}
ContainerNode::removedFrom(insertionPoint);
#if ENABLE(SVG)
if (wasInDocument && hasPendingResources())
document()->accessSVGExtensions()->removeElementFromPendingResources(this);
#endif
}
void Element::createRendererIfNeeded(const AttachContext& context)
{
NodeRenderingContext(this, context).createRendererForElementIfNeeded();
}
void Element::attach(const AttachContext& context)
{
PostAttachCallbackDisabler callbackDisabler(this);
StyleResolverParentPusher parentPusher(this);
WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
createRendererIfNeeded(context);
if (parentElement() && parentElement()->isInCanvasSubtree())
setIsInCanvasSubtree(true);
updatePseudoElement(BEFORE);
// When a shadow root exists, it does the work of attaching the children.
if (ElementShadow* shadow = this->shadow()) {
parentPusher.push();
shadow->attach(context);
} else if (firstChild())
parentPusher.push();
ContainerNode::attach(context);
updatePseudoElement(AFTER);
if (hasRareData()) {
ElementRareData* data = elementRareData();
if (data->needsFocusAppearanceUpdateSoonAfterAttach()) {
if (isFocusable() && document()->focusedElement() == this)
document()->updateFocusAppearanceSoon(false /* don't restore selection */);
data->setNeedsFocusAppearanceUpdateSoonAfterAttach(false);
}
}
}
void Element::unregisterNamedFlowContentNode()
{
if (document()->cssRegionsEnabled() && inNamedFlow() && document()->renderView())
document()->renderView()->flowThreadController()->unregisterNamedFlowContentNode(this);
}
void Element::detach(const AttachContext& context)
{
WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
unregisterNamedFlowContentNode();
cancelFocusAppearanceUpdate();
if (hasRareData()) {
ElementRareData* data = elementRareData();
data->setPseudoElement(BEFORE, 0);
data->setPseudoElement(AFTER, 0);
data->setIsInCanvasSubtree(false);
data->resetComputedStyle();
data->resetDynamicRestyleObservations();
data->setIsInsideRegion(false);
}
if (ElementShadow* shadow = this->shadow())
shadow->detach(context);
// Do not remove the element's hovered and active status
// if performing a reattach.
if (!context.performingReattach) {
if (isUserActionElement()) {
if (hovered())
document()->hoveredElementDidDetach(this);
if (inActiveChain())
document()->elementInActiveChainDidDetach(this);
document()->userActionElements().didDetach(this);
}
}
ContainerNode::detach(context);
}
bool Element::pseudoStyleCacheIsInvalid(const RenderStyle* currentStyle, RenderStyle* newStyle)
{
ASSERT(currentStyle == renderStyle());
ASSERT(renderer());
if (!currentStyle)
return false;
const PseudoStyleCache* pseudoStyleCache = currentStyle->cachedPseudoStyles();
if (!pseudoStyleCache)
return false;
size_t cacheSize = pseudoStyleCache->size();
for (size_t i = 0; i < cacheSize; ++i) {
RefPtr<RenderStyle> newPseudoStyle;
PseudoId pseudoId = pseudoStyleCache->at(i)->styleType();
if (pseudoId == FIRST_LINE || pseudoId == FIRST_LINE_INHERITED)
newPseudoStyle = renderer()->uncachedFirstLineStyle(newStyle);
else
newPseudoStyle = renderer()->getUncachedPseudoStyle(PseudoStyleRequest(pseudoId), newStyle, newStyle);
if (!newPseudoStyle)
return true;
if (*newPseudoStyle != *pseudoStyleCache->at(i)) {
if (pseudoId < FIRST_INTERNAL_PSEUDOID)
newStyle->setHasPseudoStyle(pseudoId);
newStyle->addCachedPseudoStyle(newPseudoStyle);
if (pseudoId == FIRST_LINE || pseudoId == FIRST_LINE_INHERITED) {
// FIXME: We should do an actual diff to determine whether a repaint vs. layout
// is needed, but for now just assume a layout will be required. The diff code
// in RenderObject::setStyle would need to be factored out so that it could be reused.
renderer()->setNeedsLayoutAndPrefWidthsRecalc();
}
return true;
}
}
return false;
}
PassRefPtr<RenderStyle> Element::styleForRenderer()
{
if (hasCustomStyleCallbacks()) {
if (RefPtr<RenderStyle> style = customStyleForRenderer())
return style.release();
}
return document()->ensureStyleResolver()->styleForElement(this);
}
void Element::recalcStyle(StyleChange change)
{
if (hasCustomStyleCallbacks()) {
if (!willRecalcStyle(change))
return;
}
// Ref currentStyle in case it would otherwise be deleted when setting the new style in the renderer.
RefPtr<RenderStyle> currentStyle(renderStyle());
bool hasParentStyle = parentNodeForRenderingAndStyle() ? static_cast<bool>(parentNodeForRenderingAndStyle()->renderStyle()) : false;
bool hasDirectAdjacentRules = childrenAffectedByDirectAdjacentRules();
bool hasIndirectAdjacentRules = childrenAffectedByForwardPositionalRules();
if ((change > NoChange || needsStyleRecalc())) {
if (hasRareData())
elementRareData()->resetComputedStyle();
}
if (hasParentStyle && (change >= Inherit || needsStyleRecalc())) {
StyleChange localChange = Detach;
RefPtr<RenderStyle> newStyle;
if (currentStyle) {
newStyle = styleForRenderer();
localChange = Node::diff(currentStyle.get(), newStyle.get(), document());
}
if (localChange == Detach) {
AttachContext reattachContext;
reattachContext.resolvedStyle = newStyle.get();
reattach(reattachContext);
// attach recalculates the style for all children. No need to do it twice.
clearNeedsStyleRecalc();
clearChildNeedsStyleRecalc();
if (hasCustomStyleCallbacks())
didRecalcStyle(change);
return;
}
if (RenderObject* renderer = this->renderer()) {
if (localChange != NoChange || pseudoStyleCacheIsInvalid(currentStyle.get(), newStyle.get()) || (change == Force && renderer->requiresForcedStyleRecalcPropagation()) || styleChangeType() == SyntheticStyleChange)
renderer->setAnimatableStyle(newStyle.get());
else if (needsStyleRecalc()) {
// Although no change occurred, we use the new style so that the cousin style sharing code won't get
// fooled into believing this style is the same.
renderer->setStyleInternal(newStyle.get());
}
}
// If "rem" units are used anywhere in the document, and if the document element's font size changes, then go ahead and force font updating
// all the way down the tree. This is simpler than having to maintain a cache of objects (and such font size changes should be rare anyway).
if (document()->styleSheetCollection()->usesRemUnits() && document()->documentElement() == this && localChange != NoChange && currentStyle && newStyle && currentStyle->fontSize() != newStyle->fontSize()) {
// Cached RenderStyles may depend on the re units.
if (StyleResolver* styleResolver = document()->styleResolverIfExists())
styleResolver->invalidateMatchedPropertiesCache();
change = Force;
}
if (change != Force) {
if (styleChangeType() >= FullStyleChange)
change = Force;
else
change = localChange;
}
}
StyleResolverParentPusher parentPusher(this);
// FIXME: This does not care about sibling combinators. Will be necessary in XBL2 world.
if (ElementShadow* shadow = this->shadow()) {
if (change >= Inherit || shadow->childNeedsStyleRecalc() || shadow->needsStyleRecalc()) {
parentPusher.push();
shadow->recalcStyle(change);
}
}
updatePseudoElement(BEFORE, change);
// FIXME: This check is good enough for :hover + foo, but it is not good enough for :hover + foo + bar.
// For now we will just worry about the common case, since it's a lot trickier to get the second case right
// without doing way too much re-resolution.
bool forceCheckOfNextElementSibling = false;
bool forceCheckOfAnyElementSibling = false;
for (Node *n = firstChild(); n; n = n->nextSibling()) {
if (n->isTextNode()) {
toText(n)->recalcTextStyle(change);
continue;
}
if (!n->isElementNode())
continue;
Element* element = toElement(n);
bool childRulesChanged = element->needsStyleRecalc() && element->styleChangeType() == FullStyleChange;
if ((forceCheckOfNextElementSibling || forceCheckOfAnyElementSibling))
element->setNeedsStyleRecalc();
if (change >= Inherit || element->childNeedsStyleRecalc() || element->needsStyleRecalc()) {
parentPusher.push();
element->recalcStyle(change);
}
forceCheckOfNextElementSibling = childRulesChanged && hasDirectAdjacentRules;
forceCheckOfAnyElementSibling = forceCheckOfAnyElementSibling || (childRulesChanged && hasIndirectAdjacentRules);
}
updatePseudoElement(AFTER, change);
clearNeedsStyleRecalc();
clearChildNeedsStyleRecalc();
if (hasCustomStyleCallbacks())
didRecalcStyle(change);
}
ElementShadow* Element::shadow() const
{
return hasRareData() ? elementRareData()->shadow() : 0;
}
ElementShadow* Element::ensureShadow()
{
return ensureElementRareData()->ensureShadow();
}
void Element::didAffectSelector(AffectedSelectorMask)
{
setNeedsStyleRecalc();
}
PassRefPtr<ShadowRoot> Element::createShadowRoot(ExceptionCode& ec)
{
if (alwaysCreateUserAgentShadowRoot())
ensureUserAgentShadowRoot();
#if ENABLE(SHADOW_DOM)
if (RuntimeEnabledFeatures::authorShadowDOMForAnyElementEnabled())
return ensureShadow()->addShadowRoot(this, ShadowRoot::AuthorShadowRoot);
#endif
// Since some elements recreates shadow root dynamically, multiple shadow
// subtrees won't work well in that element. Until they are fixed, we disable
// adding author shadow root for them.
if (!areAuthorShadowsAllowed()) {
ec = HIERARCHY_REQUEST_ERR;
return 0;
}
return ensureShadow()->addShadowRoot(this, ShadowRoot::AuthorShadowRoot);
}
ShadowRoot* Element::authorShadowRoot() const
{
ElementShadow* elementShadow = shadow();
if (!elementShadow)
return 0;
ShadowRoot* shadowRoot = elementShadow->shadowRoot();
if (shadowRoot->type() == ShadowRoot::AuthorShadowRoot)
return shadowRoot;
return 0;
}
ShadowRoot* Element::userAgentShadowRoot() const
{
if (ElementShadow* elementShadow = shadow()) {
if (ShadowRoot* shadowRoot = elementShadow->shadowRoot()) {
ASSERT(shadowRoot->type() == ShadowRoot::UserAgentShadowRoot);
return shadowRoot;
}
}
return 0;
}
ShadowRoot* Element::ensureUserAgentShadowRoot()
{
ShadowRoot* shadowRoot = userAgentShadowRoot();
if (!shadowRoot) {
shadowRoot = ensureShadow()->addShadowRoot(this, ShadowRoot::UserAgentShadowRoot);
didAddUserAgentShadowRoot(shadowRoot);
}
return shadowRoot;
}
const AtomicString& Element::shadowPseudoId() const
{
return pseudo();
}
bool Element::childTypeAllowed(NodeType type) const
{
switch (type) {
case ELEMENT_NODE:
case TEXT_NODE:
case COMMENT_NODE:
case PROCESSING_INSTRUCTION_NODE:
case CDATA_SECTION_NODE:
case ENTITY_REFERENCE_NODE:
return true;
default:
break;
}
return false;
}
static void checkForEmptyStyleChange(Element* element, RenderStyle* style)
{
if (!style && !element->styleAffectedByEmpty())
return;
if (!style || (element->styleAffectedByEmpty() && (!style->emptyState() || element->hasChildNodes())))
element->setNeedsStyleRecalc();
}
static void checkForSiblingStyleChanges(Element* e, RenderStyle* style, bool finishedParsingCallback,
Node* beforeChange, Node* afterChange, int childCountDelta)
{
// :empty selector.
checkForEmptyStyleChange(e, style);
if (!style || (e->needsStyleRecalc() && e->childrenAffectedByPositionalRules()))
return;
// :first-child. In the parser callback case, we don't have to check anything, since we were right the first time.
// In the DOM case, we only need to do something if |afterChange| is not 0.
// |afterChange| is 0 in the parser case, so it works out that we'll skip this block.
if (e->childrenAffectedByFirstChildRules() && afterChange) {
// Find our new first child.
Node* newFirstChild = 0;
for (newFirstChild = e->firstChild(); newFirstChild && !newFirstChild->isElementNode(); newFirstChild = newFirstChild->nextSibling()) {};
// Find the first element node following |afterChange|
Node* firstElementAfterInsertion = 0;
for (firstElementAfterInsertion = afterChange;
firstElementAfterInsertion && !firstElementAfterInsertion->isElementNode();
firstElementAfterInsertion = firstElementAfterInsertion->nextSibling()) {};
// This is the insert/append case.
if (newFirstChild != firstElementAfterInsertion && firstElementAfterInsertion && firstElementAfterInsertion->attached() &&
firstElementAfterInsertion->renderStyle() && firstElementAfterInsertion->renderStyle()->firstChildState())
firstElementAfterInsertion->setNeedsStyleRecalc();
// We also have to handle node removal.
if (childCountDelta < 0 && newFirstChild == firstElementAfterInsertion && newFirstChild && (!newFirstChild->renderStyle() || !newFirstChild->renderStyle()->firstChildState()))
newFirstChild->setNeedsStyleRecalc();
}
// :last-child. In the parser callback case, we don't have to check anything, since we were right the first time.
// In the DOM case, we only need to do something if |afterChange| is not 0.
if (e->childrenAffectedByLastChildRules() && beforeChange) {
// Find our new last child.
Node* newLastChild = 0;
for (newLastChild = e->lastChild(); newLastChild && !newLastChild->isElementNode(); newLastChild = newLastChild->previousSibling()) {};
// Find the last element node going backwards from |beforeChange|
Node* lastElementBeforeInsertion = 0;
for (lastElementBeforeInsertion = beforeChange;
lastElementBeforeInsertion && !lastElementBeforeInsertion->isElementNode();
lastElementBeforeInsertion = lastElementBeforeInsertion->previousSibling()) {};
if (newLastChild != lastElementBeforeInsertion && lastElementBeforeInsertion && lastElementBeforeInsertion->attached() &&
lastElementBeforeInsertion->renderStyle() && lastElementBeforeInsertion->renderStyle()->lastChildState())
lastElementBeforeInsertion->setNeedsStyleRecalc();
// We also have to handle node removal. The parser callback case is similar to node removal as well in that we need to change the last child
// to match now.
if ((childCountDelta < 0 || finishedParsingCallback) && newLastChild == lastElementBeforeInsertion && newLastChild && (!newLastChild->renderStyle() || !newLastChild->renderStyle()->lastChildState()))
newLastChild->setNeedsStyleRecalc();
}
// The + selector. We need to invalidate the first element following the insertion point. It is the only possible element
// that could be affected by this DOM change.
if (e->childrenAffectedByDirectAdjacentRules() && afterChange) {
Node* firstElementAfterInsertion = 0;
for (firstElementAfterInsertion = afterChange;
firstElementAfterInsertion && !firstElementAfterInsertion->isElementNode();
firstElementAfterInsertion = firstElementAfterInsertion->nextSibling()) {};
if (firstElementAfterInsertion && firstElementAfterInsertion->attached())
firstElementAfterInsertion->setNeedsStyleRecalc();
}
// Forward positional selectors include the ~ selector, nth-child, nth-of-type, first-of-type and only-of-type.
// Backward positional selectors include nth-last-child, nth-last-of-type, last-of-type and only-of-type.
// We have to invalidate everything following the insertion point in the forward case, and everything before the insertion point in the
// backward case.
// |afterChange| is 0 in the parser callback case, so we won't do any work for the forward case if we don't have to.
// For performance reasons we just mark the parent node as changed, since we don't want to make childrenChanged O(n^2) by crawling all our kids
// here. recalcStyle will then force a walk of the children when it sees that this has happened.
if ((e->childrenAffectedByForwardPositionalRules() && afterChange)
|| (e->childrenAffectedByBackwardPositionalRules() && beforeChange))
e->setNeedsStyleRecalc();
}
void Element::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
ContainerNode::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
if (changedByParser)
checkForEmptyStyleChange(this, renderStyle());
else
checkForSiblingStyleChanges(this, renderStyle(), false, beforeChange, afterChange, childCountDelta);
if (ElementShadow * shadow = this->shadow())
shadow->invalidateDistribution();
}
void Element::removeAllEventListeners()
{
ContainerNode::removeAllEventListeners();
if (ElementShadow* shadow = this->shadow())
shadow->removeAllEventListeners();
}
void Element::beginParsingChildren()
{
clearIsParsingChildrenFinished();
StyleResolver* styleResolver = document()->styleResolverIfExists();
if (styleResolver && attached())
styleResolver->pushParentElement(this);
}
void Element::finishParsingChildren()
{
ContainerNode::finishParsingChildren();
setIsParsingChildrenFinished();
checkForSiblingStyleChanges(this, renderStyle(), true, lastChild(), 0, 0);
if (StyleResolver* styleResolver = document()->styleResolverIfExists())
styleResolver->popParentElement(this);
}
#ifndef NDEBUG
void Element::formatForDebugger(char* buffer, unsigned length) const
{
StringBuilder result;
String s;
result.append(nodeName());
s = getIdAttribute();
if (s.length() > 0) {
if (result.length() > 0)
result.appendLiteral("; ");
result.appendLiteral("id=");
result.append(s);
}
s = getAttribute(classAttr);
if (s.length() > 0) {
if (result.length() > 0)
result.appendLiteral("; ");
result.appendLiteral("class=");
result.append(s);
}
strncpy(buffer, result.toString().utf8().data(), length - 1);
}
#endif
const Vector<RefPtr<Attr> >& Element::attrNodeList()
{
ASSERT(hasSyntheticAttrChildNodes());
return *attrNodeListForElement(this);
}
PassRefPtr<Attr> Element::setAttributeNode(Attr* attrNode, ExceptionCode& ec)
{
if (!attrNode) {
ec = TYPE_MISMATCH_ERR;
return 0;
}
RefPtr<Attr> oldAttrNode = attrIfExists(attrNode->qualifiedName());
if (oldAttrNode.get() == attrNode)
return attrNode; // This Attr is already attached to the element.
// INUSE_ATTRIBUTE_ERR: Raised if node is an Attr that is already an attribute of another Element object.
// The DOM user must explicitly clone Attr nodes to re-use them in other elements.
if (attrNode->ownerElement()) {
ec = INUSE_ATTRIBUTE_ERR;
return 0;
}
synchronizeAllAttributes();
UniqueElementData* elementData = ensureUniqueElementData();
unsigned index = elementData->getAttributeItemIndexForAttributeNode(attrNode);
if (index != ElementData::attributeNotFound) {
if (oldAttrNode)
detachAttrNodeFromElementWithValue(oldAttrNode.get(), elementData->attributeItem(index)->value());
else
oldAttrNode = Attr::create(document(), attrNode->qualifiedName(), elementData->attributeItem(index)->value());
}
setAttributeInternal(index, attrNode->qualifiedName(), attrNode->value(), NotInSynchronizationOfLazyAttribute);
attrNode->attachToElement(this);
treeScope()->adoptIfNeeded(attrNode);
ensureAttrNodeListForElement(this)->append(attrNode);
return oldAttrNode.release();
}
PassRefPtr<Attr> Element::setAttributeNodeNS(Attr* attr, ExceptionCode& ec)
{
return setAttributeNode(attr, ec);
}
PassRefPtr<Attr> Element::removeAttributeNode(Attr* attr, ExceptionCode& ec)
{
if (!attr) {
ec = TYPE_MISMATCH_ERR;
return 0;
}
if (attr->ownerElement() != this) {
ec = NOT_FOUND_ERR;
return 0;
}
ASSERT(document() == attr->document());
synchronizeAttribute(attr->qualifiedName());
unsigned index = elementData()->getAttributeItemIndexForAttributeNode(attr);
if (index == ElementData::attributeNotFound) {
ec = NOT_FOUND_ERR;
return 0;
}
RefPtr<Attr> attrNode = attr;
detachAttrNodeFromElementWithValue(attr, elementData()->attributeItem(index)->value());
removeAttributeInternal(index, NotInSynchronizationOfLazyAttribute);
return attrNode.release();
}
bool Element::parseAttributeName(QualifiedName& out, const AtomicString& namespaceURI, const AtomicString& qualifiedName, ExceptionCode& ec)
{
String prefix, localName;
if (!Document::parseQualifiedName(qualifiedName, prefix, localName, ec))
return false;
ASSERT(!ec);
QualifiedName qName(prefix, localName, namespaceURI);
if (!Document::hasValidNamespaceForAttributes(qName)) {
ec = NAMESPACE_ERR;
return false;
}
out = qName;
return true;
}
void Element::setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value, ExceptionCode& ec)
{
QualifiedName parsedName = anyName;
if (!parseAttributeName(parsedName, namespaceURI, qualifiedName, ec))
return;
setAttribute(parsedName, value);
}
void Element::removeAttributeInternal(unsigned index, SynchronizationOfLazyAttribute inSynchronizationOfLazyAttribute)
{
ASSERT_WITH_SECURITY_IMPLICATION(index < attributeCount());
UniqueElementData* elementData = ensureUniqueElementData();
QualifiedName name = elementData->attributeItem(index)->name();
AtomicString valueBeingRemoved = elementData->attributeItem(index)->value();
if (!inSynchronizationOfLazyAttribute) {
if (!valueBeingRemoved.isNull())
willModifyAttribute(name, valueBeingRemoved, nullAtom);
}
if (RefPtr<Attr> attrNode = attrIfExists(name))
detachAttrNodeFromElementWithValue(attrNode.get(), elementData->attributeItem(index)->value());
elementData->removeAttribute(index);
if (!inSynchronizationOfLazyAttribute)
didRemoveAttribute(name);
}
void Element::addAttributeInternal(const QualifiedName& name, const AtomicString& value, SynchronizationOfLazyAttribute inSynchronizationOfLazyAttribute)
{
if (!inSynchronizationOfLazyAttribute)
willModifyAttribute(name, nullAtom, value);
ensureUniqueElementData()->addAttribute(name, value);
if (!inSynchronizationOfLazyAttribute)
didAddAttribute(name, value);
}
void Element::removeAttribute(const AtomicString& name)
{
if (!elementData())
return;
AtomicString localName = shouldIgnoreAttributeCase(this) ? name.lower() : name;
unsigned index = elementData()->getAttributeItemIndex(localName, false);
if (index == ElementData::attributeNotFound) {
if (UNLIKELY(localName == styleAttr) && elementData()->m_styleAttributeIsDirty && isStyledElement())
static_cast<StyledElement*>(this)->removeAllInlineStyleProperties();
return;
}
removeAttributeInternal(index, NotInSynchronizationOfLazyAttribute);
}
void Element::removeAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName)
{
removeAttribute(QualifiedName(nullAtom, localName, namespaceURI));
}
PassRefPtr<Attr> Element::getAttributeNode(const AtomicString& localName)
{
if (!elementData())
return 0;
synchronizeAttribute(localName);
const Attribute* attribute = elementData()->getAttributeItem(localName, shouldIgnoreAttributeCase(this));
if (!attribute)
return 0;
return ensureAttr(attribute->name());
}
PassRefPtr<Attr> Element::getAttributeNodeNS(const AtomicString& namespaceURI, const AtomicString& localName)
{
if (!elementData())
return 0;
QualifiedName qName(nullAtom, localName, namespaceURI);
synchronizeAttribute(qName);
const Attribute* attribute = elementData()->getAttributeItem(qName);
if (!attribute)
return 0;
return ensureAttr(attribute->name());
}
bool Element::hasAttribute(const AtomicString& localName) const
{
if (!elementData())
return false;
synchronizeAttribute(localName);
return elementData()->getAttributeItem(shouldIgnoreAttributeCase(this) ? localName.lower() : localName, false);
}
bool Element::hasAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const
{
if (!elementData())
return false;
QualifiedName qName(nullAtom, localName, namespaceURI);
synchronizeAttribute(qName);
return elementData()->getAttributeItem(qName);
}
CSSStyleDeclaration *Element::style()
{
return 0;
}
void Element::focus(bool restorePreviousSelection, FocusDirection direction)
{
if (!inDocument())
return;
Document* doc = document();
if (doc->focusedElement() == this)
return;
// If the stylesheets have already been loaded we can reliably check isFocusable.
// If not, we continue and set the focused node on the focus controller below so
// that it can be updated soon after attach.
if (doc->haveStylesheetsLoaded()) {
doc->updateLayoutIgnorePendingStylesheets();
if (!isFocusable())
return;
}
if (!supportsFocus())
return;
RefPtr<Node> protect;
if (Page* page = doc->page()) {
// Focus and change event handlers can cause us to lose our last ref.
// If a focus event handler changes the focus to a different node it
// does not make sense to continue and update appearence.
protect = this;
if (!page->focusController()->setFocusedElement(this, doc->frame(), direction))
return;
}
// Setting the focused node above might have invalidated the layout due to scripts.
doc->updateLayoutIgnorePendingStylesheets();
if (!isFocusable()) {
ensureElementRareData()->setNeedsFocusAppearanceUpdateSoonAfterAttach(true);
return;
}
cancelFocusAppearanceUpdate();
updateFocusAppearance(restorePreviousSelection);
}
void Element::updateFocusAppearance(bool /*restorePreviousSelection*/)
{
if (isRootEditableElement()) {
Frame* frame = document()->frame();
if (!frame)
return;
// When focusing an editable element in an iframe, don't reset the selection if it already contains a selection.
if (this == frame->selection()->rootEditableElement())
return;
// FIXME: We should restore the previous selection if there is one.
VisibleSelection newSelection = VisibleSelection(firstPositionInOrBeforeNode(this), DOWNSTREAM);
if (frame->selection()->shouldChangeSelection(newSelection)) {
frame->selection()->setSelection(newSelection);
frame->selection()->revealSelection();
}
} else if (renderer() && !renderer()->isWidget())
renderer()->scrollRectToVisible(boundingBox());
}
void Element::blur()
{
cancelFocusAppearanceUpdate();
Document* doc = document();
if (treeScope()->focusedElement() == this) {
if (doc->frame())
doc->frame()->page()->focusController()->setFocusedElement(0, doc->frame());
else
doc->setFocusedElement(0);
}
}
void Element::dispatchFocusInEvent(const AtomicString& eventType, PassRefPtr<Element> oldFocusedElement)
{
ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden());
ASSERT(eventType == eventNames().focusinEvent || eventType == eventNames().DOMFocusInEvent);
dispatchScopedEventDispatchMediator(FocusInEventDispatchMediator::create(FocusEvent::create(eventType, true, false, document()->defaultView(), 0, oldFocusedElement)));
}
void Element::dispatchFocusOutEvent(const AtomicString& eventType, PassRefPtr<Element> newFocusedElement)
{
ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden());
ASSERT(eventType == eventNames().focusoutEvent || eventType == eventNames().DOMFocusOutEvent);
dispatchScopedEventDispatchMediator(FocusOutEventDispatchMediator::create(FocusEvent::create(eventType, true, false, document()->defaultView(), 0, newFocusedElement)));
}
void Element::dispatchFocusEvent(PassRefPtr<Element> oldFocusedElement, FocusDirection)
{
if (document()->page())
document()->page()->chrome().client()->elementDidFocus(this);
RefPtr<FocusEvent> event = FocusEvent::create(eventNames().focusEvent, false, false, document()->defaultView(), 0, oldFocusedElement);
EventDispatcher::dispatchEvent(this, FocusEventDispatchMediator::create(event.release()));
}
void Element::dispatchBlurEvent(PassRefPtr<Element> newFocusedElement)
{
if (document()->page())
document()->page()->chrome().client()->elementDidBlur(this);
RefPtr<FocusEvent> event = FocusEvent::create(eventNames().blurEvent, false, false, document()->defaultView(), 0, newFocusedElement);
EventDispatcher::dispatchEvent(this, BlurEventDispatchMediator::create(event.release()));
}
String Element::innerText()
{
// We need to update layout, since plainText uses line boxes in the render tree.
document()->updateLayoutIgnorePendingStylesheets();
if (!renderer())
return textContent(true);
return plainText(rangeOfContents(const_cast<Element*>(this)).get());
}
String Element::outerText()
{
// Getting outerText is the same as getting innerText, only
// setting is different. You would think this should get the plain
// text for the outer range, but this is wrong, <br> for instance
// would return different values for inner and outer text by such
// a rule, but it doesn't in WinIE, and we want to match that.
return innerText();
}
String Element::title() const
{
return String();
}
const AtomicString& Element::pseudo() const
{
return getAttribute(pseudoAttr);
}
void Element::setPseudo(const AtomicString& value)
{
setAttribute(pseudoAttr, value);
}
LayoutSize Element::minimumSizeForResizing() const
{
return hasRareData() ? elementRareData()->minimumSizeForResizing() : defaultMinimumSizeForResizing();
}
void Element::setMinimumSizeForResizing(const LayoutSize& size)
{
if (!hasRareData() && size == defaultMinimumSizeForResizing())
return;
ensureElementRareData()->setMinimumSizeForResizing(size);
}
RenderStyle* Element::computedStyle(PseudoId pseudoElementSpecifier)
{
if (PseudoElement* element = pseudoElement(pseudoElementSpecifier))
return element->computedStyle();
// FIXME: Find and use the renderer from the pseudo element instead of the actual element so that the 'length'
// properties, which are only known by the renderer because it did the layout, will be correct and so that the
// values returned for the ":selection" pseudo-element will be correct.
if (RenderStyle* usedStyle = renderStyle()) {
if (pseudoElementSpecifier) {
RenderStyle* cachedPseudoStyle = usedStyle->getCachedPseudoStyle(pseudoElementSpecifier);
return cachedPseudoStyle ? cachedPseudoStyle : usedStyle;
} else
return usedStyle;
}
if (!attached())
// FIXME: Try to do better than this. Ensure that styleForElement() works for elements that are not in the
// document tree and figure out when to destroy the computed style for such elements.
return 0;
ElementRareData* data = ensureElementRareData();
if (!data->computedStyle())
data->setComputedStyle(document()->styleForElementIgnoringPendingStylesheets(this));
return pseudoElementSpecifier ? data->computedStyle()->getCachedPseudoStyle(pseudoElementSpecifier) : data->computedStyle();
}
void Element::setStyleAffectedByEmpty()
{
ensureElementRareData()->setStyleAffectedByEmpty(true);
}
void Element::setChildrenAffectedByHover(bool value)
{
if (value || hasRareData())
ensureElementRareData()->setChildrenAffectedByHover(value);
}
void Element::setChildrenAffectedByActive(bool value)
{
if (value || hasRareData())
ensureElementRareData()->setChildrenAffectedByActive(value);
}
void Element::setChildrenAffectedByDrag(bool value)
{
if (value || hasRareData())
ensureElementRareData()->setChildrenAffectedByDrag(value);
}
void Element::setChildrenAffectedByFirstChildRules()
{
ensureElementRareData()->setChildrenAffectedByFirstChildRules(true);
}
void Element::setChildrenAffectedByLastChildRules()
{
ensureElementRareData()->setChildrenAffectedByLastChildRules(true);
}
void Element::setChildrenAffectedByDirectAdjacentRules()
{
ensureElementRareData()->setChildrenAffectedByDirectAdjacentRules(true);
}
void Element::setChildrenAffectedByForwardPositionalRules()
{
ensureElementRareData()->setChildrenAffectedByForwardPositionalRules(true);
}
void Element::setChildrenAffectedByBackwardPositionalRules()
{
ensureElementRareData()->setChildrenAffectedByBackwardPositionalRules(true);
}
void Element::setChildIndex(unsigned index)
{
ElementRareData* rareData = ensureElementRareData();
if (RenderStyle* style = renderStyle())
style->setUnique();
rareData->setChildIndex(index);
}
bool Element::hasFlagsSetDuringStylingOfChildren() const
{
if (!hasRareData())
return false;
return rareDataChildrenAffectedByHover()
|| rareDataChildrenAffectedByActive()
|| rareDataChildrenAffectedByDrag()
|| rareDataChildrenAffectedByFirstChildRules()
|| rareDataChildrenAffectedByLastChildRules()
|| rareDataChildrenAffectedByDirectAdjacentRules()
|| rareDataChildrenAffectedByForwardPositionalRules()
|| rareDataChildrenAffectedByBackwardPositionalRules();
}
bool Element::rareDataStyleAffectedByEmpty() const
{
ASSERT(hasRareData());
return elementRareData()->styleAffectedByEmpty();
}
bool Element::rareDataChildrenAffectedByHover() const
{
ASSERT(hasRareData());
return elementRareData()->childrenAffectedByHover();
}
bool Element::rareDataChildrenAffectedByActive() const
{
ASSERT(hasRareData());
return elementRareData()->childrenAffectedByActive();
}
bool Element::rareDataChildrenAffectedByDrag() const
{
ASSERT(hasRareData());
return elementRareData()->childrenAffectedByDrag();
}
bool Element::rareDataChildrenAffectedByFirstChildRules() const
{
ASSERT(hasRareData());
return elementRareData()->childrenAffectedByFirstChildRules();
}
bool Element::rareDataChildrenAffectedByLastChildRules() const
{
ASSERT(hasRareData());
return elementRareData()->childrenAffectedByLastChildRules();
}
bool Element::rareDataChildrenAffectedByDirectAdjacentRules() const
{
ASSERT(hasRareData());
return elementRareData()->childrenAffectedByDirectAdjacentRules();
}
bool Element::rareDataChildrenAffectedByForwardPositionalRules() const
{
ASSERT(hasRareData());
return elementRareData()->childrenAffectedByForwardPositionalRules();
}
bool Element::rareDataChildrenAffectedByBackwardPositionalRules() const
{
ASSERT(hasRareData());
return elementRareData()->childrenAffectedByBackwardPositionalRules();
}
unsigned Element::rareDataChildIndex() const
{
ASSERT(hasRareData());
return elementRareData()->childIndex();
}
void Element::setIsInCanvasSubtree(bool isInCanvasSubtree)
{
ensureElementRareData()->setIsInCanvasSubtree(isInCanvasSubtree);
}
bool Element::isInCanvasSubtree() const
{
return hasRareData() && elementRareData()->isInCanvasSubtree();
}
void Element::setIsInsideRegion(bool value)
{
if (value == isInsideRegion())
return;
ensureElementRareData()->setIsInsideRegion(value);
}
bool Element::isInsideRegion() const
{
return hasRareData() ? elementRareData()->isInsideRegion() : false;
}
void Element::setRegionOversetState(RegionOversetState state)
{
ensureElementRareData()->setRegionOversetState(state);
}
RegionOversetState Element::regionOversetState() const
{
return hasRareData() ? elementRareData()->regionOversetState() : RegionUndefined;
}
AtomicString Element::computeInheritedLanguage() const
{
const Node* n = this;
AtomicString value;
// The language property is inherited, so we iterate over the parents to find the first language.
do {
if (n->isElementNode()) {
if (const ElementData* elementData = toElement(n)->elementData()) {
// Spec: xml:lang takes precedence -- http://www.w3.org/TR/xhtml1/#C_7
if (const Attribute* attribute = elementData->getAttributeItem(XMLNames::langAttr))
value = attribute->value();
else if (const Attribute* attribute = elementData->getAttributeItem(HTMLNames::langAttr))
value = attribute->value();
}
} else if (n->isDocumentNode()) {
// checking the MIME content-language
value = toDocument(n)->contentLanguage();
}
n = n->parentNode();
} while (n && value.isNull());
return value;
}
Locale& Element::locale() const
{
return document()->getCachedLocale(computeInheritedLanguage());
}
void Element::cancelFocusAppearanceUpdate()
{
if (hasRareData())
elementRareData()->setNeedsFocusAppearanceUpdateSoonAfterAttach(false);
if (document()->focusedElement() == this)
document()->cancelFocusAppearanceUpdate();
}
void Element::normalizeAttributes()
{
if (!hasAttributes())
return;
for (unsigned i = 0; i < attributeCount(); ++i) {
if (RefPtr<Attr> attr = attrIfExists(attributeItem(i)->name()))
attr->normalize();
}
}
void Element::updatePseudoElement(PseudoId pseudoId, StyleChange change)
{
PseudoElement* existing = pseudoElement(pseudoId);
if (existing) {
// PseudoElement styles hang off their parent element's style so if we needed
// a style recalc we should Force one on the pseudo.
existing->recalcStyle(needsStyleRecalc() ? Force : change);
// Wait until our parent is not displayed or pseudoElementRendererIsNeeded
// is false, otherwise we could continously create and destroy PseudoElements
// when RenderObject::isChildAllowed on our parent returns false for the
// PseudoElement's renderer for each style recalc.
if (!renderer() || !pseudoElementRendererIsNeeded(renderer()->getCachedPseudoStyle(pseudoId)))
setPseudoElement(pseudoId, 0);
} else if (RefPtr<PseudoElement> element = createPseudoElementIfNeeded(pseudoId)) {
element->attach();
setPseudoElement(pseudoId, element.release());
}
}
PassRefPtr<PseudoElement> Element::createPseudoElementIfNeeded(PseudoId pseudoId)
{
if (!document()->styleSheetCollection()->usesBeforeAfterRules())
return 0;
if (!renderer() || !renderer()->canHaveGeneratedChildren())
return 0;
if (isPseudoElement())
return 0;
if (!pseudoElementRendererIsNeeded(renderer()->getCachedPseudoStyle(pseudoId)))
return 0;
return PseudoElement::create(this, pseudoId);
}
bool Element::hasPseudoElements() const
{
return hasRareData() && elementRareData()->hasPseudoElements();
}
PseudoElement* Element::pseudoElement(PseudoId pseudoId) const
{
return hasRareData() ? elementRareData()->pseudoElement(pseudoId) : 0;
}
void Element::setPseudoElement(PseudoId pseudoId, PassRefPtr<PseudoElement> element)
{
ensureElementRareData()->setPseudoElement(pseudoId, element);
resetNeedsShadowTreeWalker();
}
RenderObject* Element::pseudoElementRenderer(PseudoId pseudoId) const
{
if (PseudoElement* element = pseudoElement(pseudoId))
return element->renderer();
return 0;
}
// ElementTraversal API
Element* Element::firstElementChild() const
{
return ElementTraversal::firstWithin(this);
}
Element* Element::lastElementChild() const
{
Node* n = lastChild();
while (n && !n->isElementNode())
n = n->previousSibling();
return toElement(n);
}
unsigned Element::childElementCount() const
{
unsigned count = 0;
Node* n = firstChild();
while (n) {
count += n->isElementNode();
n = n->nextSibling();
}
return count;
}
bool Element::matchesReadOnlyPseudoClass() const
{
return false;
}
bool Element::matchesReadWritePseudoClass() const
{
return false;
}
bool Element::webkitMatchesSelector(const String& selector, ExceptionCode& ec)
{
if (selector.isEmpty()) {
ec = SYNTAX_ERR;
return false;
}
SelectorQuery* selectorQuery = document()->selectorQueryCache()->add(selector, document(), ec);
if (!selectorQuery)
return false;
return selectorQuery->matches(this);
}
bool Element::shouldAppearIndeterminate() const
{
return false;
}
DOMTokenList* Element::classList()
{
ElementRareData* data = ensureElementRareData();
if (!data->classList())
data->setClassList(ClassList::create(this));
return data->classList();
}
DOMStringMap* Element::dataset()
{
ElementRareData* data = ensureElementRareData();
if (!data->dataset())
data->setDataset(DatasetDOMStringMap::create(this));
return data->dataset();
}
KURL Element::getURLAttribute(const QualifiedName& name) const
{
#if !ASSERT_DISABLED
if (elementData()) {
if (const Attribute* attribute = getAttributeItem(name))
ASSERT(isURLAttribute(*attribute));
}
#endif
return document()->completeURL(stripLeadingAndTrailingHTMLSpaces(getAttribute(name)));
}
KURL Element::getNonEmptyURLAttribute(const QualifiedName& name) const
{
#if !ASSERT_DISABLED
if (elementData()) {
if (const Attribute* attribute = getAttributeItem(name))
ASSERT(isURLAttribute(*attribute));
}
#endif
String value = stripLeadingAndTrailingHTMLSpaces(getAttribute(name));
if (value.isEmpty())
return KURL();
return document()->completeURL(value);
}
int Element::getIntegralAttribute(const QualifiedName& attributeName) const
{
return getAttribute(attributeName).string().toInt();
}
void Element::setIntegralAttribute(const QualifiedName& attributeName, int value)
{
// FIXME: Need an AtomicString version of String::number.
setAttribute(attributeName, String::number(value));
}
unsigned Element::getUnsignedIntegralAttribute(const QualifiedName& attributeName) const
{
return getAttribute(attributeName).string().toUInt();
}
void Element::setUnsignedIntegralAttribute(const QualifiedName& attributeName, unsigned value)
{
// FIXME: Need an AtomicString version of String::number.
setAttribute(attributeName, String::number(value));
}
#if ENABLE(INDIE_UI)
void Element::setUIActions(const AtomicString& actions)
{
setAttribute(uiactionsAttr, actions);
}
const AtomicString& Element::UIActions() const
{
return getAttribute(uiactionsAttr);
}
#endif
#if ENABLE(SVG)
bool Element::childShouldCreateRenderer(const NodeRenderingContext& childContext) const
{
// Only create renderers for SVG elements whose parents are SVG elements, or for proper <svg xmlns="svgNS"> subdocuments.
if (childContext.node()->isSVGElement())
return childContext.node()->hasTagName(SVGNames::svgTag) || isSVGElement();
return ContainerNode::childShouldCreateRenderer(childContext);
}
#endif
#if ENABLE(FULLSCREEN_API)
void Element::webkitRequestFullscreen()
{
document()->requestFullScreenForElement(this, ALLOW_KEYBOARD_INPUT, Document::EnforceIFrameAllowFullScreenRequirement);
}
void Element::webkitRequestFullScreen(unsigned short flags)
{
document()->requestFullScreenForElement(this, (flags | LEGACY_MOZILLA_REQUEST), Document::EnforceIFrameAllowFullScreenRequirement);
}
bool Element::containsFullScreenElement() const
{
return hasRareData() && elementRareData()->containsFullScreenElement();
}
void Element::setContainsFullScreenElement(bool flag)
{
ensureElementRareData()->setContainsFullScreenElement(flag);
setNeedsStyleRecalc(SyntheticStyleChange);
}
static Element* parentCrossingFrameBoundaries(Element* element)
{
ASSERT(element);
return element->parentElement() ? element->parentElement() : element->document()->ownerElement();
}
void Element::setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(bool flag)
{
Element* element = this;
while ((element = parentCrossingFrameBoundaries(element)))
element->setContainsFullScreenElement(flag);
}
#endif
#if ENABLE(DIALOG_ELEMENT)
bool Element::isInTopLayer() const
{
return hasRareData() && elementRareData()->isInTopLayer();
}
void Element::setIsInTopLayer(bool inTopLayer)
{
if (isInTopLayer() == inTopLayer)
return;
ensureElementRareData()->setIsInTopLayer(inTopLayer);
// We must ensure a reattach occurs so the renderer is inserted in the correct sibling order under RenderView according to its
// top layer position, or in its usual place if not in the top layer.
reattachIfAttached();
}
#endif
#if ENABLE(POINTER_LOCK)
void Element::webkitRequestPointerLock()
{
if (document()->page())
document()->page()->pointerLockController()->requestPointerLock(this);
}
#endif
SpellcheckAttributeState Element::spellcheckAttributeState() const
{
const AtomicString& value = getAttribute(HTMLNames::spellcheckAttr);
if (value == nullAtom)
return SpellcheckAttributeDefault;
if (equalIgnoringCase(value, "true") || equalIgnoringCase(value, ""))
return SpellcheckAttributeTrue;
if (equalIgnoringCase(value, "false"))
return SpellcheckAttributeFalse;
return SpellcheckAttributeDefault;
}
bool Element::isSpellCheckingEnabled() const
{
for (const Element* element = this; element; element = element->parentOrShadowHostElement()) {
switch (element->spellcheckAttributeState()) {
case SpellcheckAttributeTrue:
return true;
case SpellcheckAttributeFalse:
return false;
case SpellcheckAttributeDefault:
break;
}
}
return true;
}
RenderRegion* Element::renderRegion() const
{
if (renderer() && renderer()->isRenderRegion())
return toRenderRegion(renderer());
return 0;
}
#if ENABLE(CSS_REGIONS)
bool Element::shouldMoveToFlowThread(RenderStyle* styleToUse) const
{
ASSERT(styleToUse);
#if ENABLE(FULLSCREEN_API)
if (document()->webkitIsFullScreen() && document()->webkitCurrentFullScreenElement() == this)
return false;
#endif
if (isInShadowTree())
return false;
if (styleToUse->flowThread().isEmpty())
return false;
return !isRegisteredWithNamedFlow();
}
const AtomicString& Element::webkitRegionOverset() const
{
document()->updateLayoutIgnorePendingStylesheets();
DEFINE_STATIC_LOCAL(AtomicString, undefinedState, ("undefined", AtomicString::ConstructFromLiteral));
if (!document()->cssRegionsEnabled() || !renderRegion())
return undefinedState;
switch (renderRegion()->regionOversetState()) {
case RegionFit: {
DEFINE_STATIC_LOCAL(AtomicString, fitState, ("fit", AtomicString::ConstructFromLiteral));
return fitState;
}
case RegionEmpty: {
DEFINE_STATIC_LOCAL(AtomicString, emptyState, ("empty", AtomicString::ConstructFromLiteral));
return emptyState;
}
case RegionOverset: {
DEFINE_STATIC_LOCAL(AtomicString, overflowState, ("overset", AtomicString::ConstructFromLiteral));
return overflowState;
}
case RegionUndefined:
return undefinedState;
}
ASSERT_NOT_REACHED();
return undefinedState;
}
Vector<RefPtr<Range> > Element::webkitGetRegionFlowRanges() const
{
document()->updateLayoutIgnorePendingStylesheets();
Vector<RefPtr<Range> > rangeObjects;
if (document()->cssRegionsEnabled() && renderer() && renderer()->isRenderRegion()) {
RenderRegion* region = toRenderRegion(renderer());
if (region->isValid())
region->getRanges(rangeObjects);
}
return rangeObjects;
}
#endif
#ifndef NDEBUG
bool Element::fastAttributeLookupAllowed(const QualifiedName& name) const
{
if (name == HTMLNames::styleAttr)
return false;
#if ENABLE(SVG)
if (isSVGElement())
return !static_cast<const SVGElement*>(this)->isAnimatableAttribute(name);
#endif
return true;
}
#endif
#ifdef DUMP_NODE_STATISTICS
bool Element::hasNamedNodeMap() const
{
return hasRareData() && elementRareData()->attributeMap();
}
#endif
inline void Element::updateName(const AtomicString& oldName, const AtomicString& newName)
{
if (!isInTreeScope())
return;
if (oldName == newName)
return;
updateNameForTreeScope(treeScope(), oldName, newName);
if (!inDocument())
return;
Document* htmlDocument = document();
if (!htmlDocument->isHTMLDocument())
return;
updateNameForDocument(toHTMLDocument(htmlDocument), oldName, newName);
}
void Element::updateNameForTreeScope(TreeScope* scope, const AtomicString& oldName, const AtomicString& newName)
{
ASSERT(isInTreeScope());
ASSERT(oldName != newName);
if (!oldName.isEmpty())
scope->removeElementByName(oldName, this);
if (!newName.isEmpty())
scope->addElementByName(newName, this);
}
void Element::updateNameForDocument(HTMLDocument* document, const AtomicString& oldName, const AtomicString& newName)
{
ASSERT(inDocument());
ASSERT(oldName != newName);
if (WindowNameCollection::nodeMatchesIfNameAttributeMatch(this)) {
const AtomicString& id = WindowNameCollection::nodeMatchesIfIdAttributeMatch(this) ? getIdAttribute() : nullAtom;
if (!oldName.isEmpty() && oldName != id)
document->windowNamedItemMap().remove(oldName.impl(), this);
if (!newName.isEmpty() && newName != id)
document->windowNamedItemMap().add(newName.impl(), this);
}
if (DocumentNameCollection::nodeMatchesIfNameAttributeMatch(this)) {
const AtomicString& id = DocumentNameCollection::nodeMatchesIfIdAttributeMatch(this) ? getIdAttribute() : nullAtom;
if (!oldName.isEmpty() && oldName != id)
document->documentNamedItemMap().remove(oldName.impl(), this);
if (!newName.isEmpty() && newName != id)
document->documentNamedItemMap().add(newName.impl(), this);
}
}
inline void Element::updateId(const AtomicString& oldId, const AtomicString& newId)
{
if (!isInTreeScope())
return;
if (oldId == newId)
return;
updateIdForTreeScope(treeScope(), oldId, newId);
if (!inDocument())
return;
Document* htmlDocument = document();
if (!htmlDocument->isHTMLDocument())
return;
updateIdForDocument(toHTMLDocument(htmlDocument), oldId, newId, UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute);
}
void Element::updateIdForTreeScope(TreeScope* scope, const AtomicString& oldId, const AtomicString& newId)
{
ASSERT(isInTreeScope());
ASSERT(oldId != newId);
if (!oldId.isEmpty())
scope->removeElementById(oldId, this);
if (!newId.isEmpty())
scope->addElementById(newId, this);
}
void Element::updateIdForDocument(HTMLDocument* document, const AtomicString& oldId, const AtomicString& newId, HTMLDocumentNamedItemMapsUpdatingCondition condition)
{
ASSERT(inDocument());
ASSERT(oldId != newId);
if (WindowNameCollection::nodeMatchesIfIdAttributeMatch(this)) {
const AtomicString& name = condition == UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute && WindowNameCollection::nodeMatchesIfNameAttributeMatch(this) ? getNameAttribute() : nullAtom;
if (!oldId.isEmpty() && oldId != name)
document->windowNamedItemMap().remove(oldId.impl(), this);
if (!newId.isEmpty() && newId != name)
document->windowNamedItemMap().add(newId.impl(), this);
}
if (DocumentNameCollection::nodeMatchesIfIdAttributeMatch(this)) {
const AtomicString& name = condition == UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute && DocumentNameCollection::nodeMatchesIfNameAttributeMatch(this) ? getNameAttribute() : nullAtom;
if (!oldId.isEmpty() && oldId != name)
document->documentNamedItemMap().remove(oldId.impl(), this);
if (!newId.isEmpty() && newId != name)
document->documentNamedItemMap().add(newId.impl(), this);
}
}
void Element::updateLabel(TreeScope* scope, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue)
{
ASSERT(hasTagName(labelTag));
if (!inDocument())
return;
if (oldForAttributeValue == newForAttributeValue)
return;
if (!oldForAttributeValue.isEmpty())
scope->removeLabel(oldForAttributeValue, toHTMLLabelElement(this));
if (!newForAttributeValue.isEmpty())
scope->addLabel(newForAttributeValue, toHTMLLabelElement(this));
}
void Element::willModifyAttribute(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& newValue)
{
if (isIdAttributeName(name))
updateId(oldValue, newValue);
else if (name == HTMLNames::nameAttr)
updateName(oldValue, newValue);
else if (name == HTMLNames::forAttr && hasTagName(labelTag)) {
TreeScope* scope = treeScope();
if (scope->shouldCacheLabelsByForAttribute())
updateLabel(scope, oldValue, newValue);
}
if (oldValue != newValue) {
if (attached() && document()->styleResolverIfExists() && document()->styleResolverIfExists()->hasSelectorForAttribute(name.localName()))
setNeedsStyleRecalc();
}
if (OwnPtr<MutationObserverInterestGroup> recipients = MutationObserverInterestGroup::createForAttributesMutation(this, name))
recipients->enqueueMutationRecord(MutationRecord::createAttributes(this, name, oldValue));
#if ENABLE(INSPECTOR)
InspectorInstrumentation::willModifyDOMAttr(document(), this, oldValue, newValue);
#endif
}
void Element::didAddAttribute(const QualifiedName& name, const AtomicString& value)
{
attributeChanged(name, value);
InspectorInstrumentation::didModifyDOMAttr(document(), this, name.localName(), value);
dispatchSubtreeModifiedEvent();
}
void Element::didModifyAttribute(const QualifiedName& name, const AtomicString& value)
{
attributeChanged(name, value);
InspectorInstrumentation::didModifyDOMAttr(document(), this, name.localName(), value);
// Do not dispatch a DOMSubtreeModified event here; see bug 81141.
}
void Element::didRemoveAttribute(const QualifiedName& name)
{
attributeChanged(name, nullAtom);
InspectorInstrumentation::didRemoveDOMAttr(document(), this, name.localName());
dispatchSubtreeModifiedEvent();
}
PassRefPtr<HTMLCollection> Element::ensureCachedHTMLCollection(CollectionType type)
{
if (HTMLCollection* collection = cachedHTMLCollection(type))
return collection;
RefPtr<HTMLCollection> collection;
if (type == TableRows) {
ASSERT(hasTagName(tableTag));
return ensureRareData()->ensureNodeLists()->addCacheWithAtomicName<HTMLTableRowsCollection>(this, type);
} else if (type == SelectOptions) {
ASSERT(hasTagName(selectTag));
return ensureRareData()->ensureNodeLists()->addCacheWithAtomicName<HTMLOptionsCollection>(this, type);
} else if (type == FormControls) {
ASSERT(hasTagName(formTag) || hasTagName(fieldsetTag));
return ensureRareData()->ensureNodeLists()->addCacheWithAtomicName<HTMLFormControlsCollection>(this, type);
#if ENABLE(MICRODATA)
} else if (type == ItemProperties) {
return ensureRareData()->ensureNodeLists()->addCacheWithAtomicName<HTMLPropertiesCollection>(this, type);
#endif
}
return ensureRareData()->ensureNodeLists()->addCacheWithAtomicName<HTMLCollection>(this, type);
}
HTMLCollection* Element::cachedHTMLCollection(CollectionType type)
{
return hasRareData() && rareData()->nodeLists() ? rareData()->nodeLists()->cacheWithAtomicName<HTMLCollection>(type) : 0;
}
IntSize Element::savedLayerScrollOffset() const
{
return hasRareData() ? elementRareData()->savedLayerScrollOffset() : IntSize();
}
void Element::setSavedLayerScrollOffset(const IntSize& size)
{
if (size.isZero() && !hasRareData())
return;
ensureElementRareData()->setSavedLayerScrollOffset(size);
}
PassRefPtr<Attr> Element::attrIfExists(const QualifiedName& name)
{
if (AttrNodeList* attrNodeList = attrNodeListForElement(this))
return findAttrNodeInList(attrNodeList, name);
return 0;
}
PassRefPtr<Attr> Element::ensureAttr(const QualifiedName& name)
{
AttrNodeList* attrNodeList = ensureAttrNodeListForElement(this);
RefPtr<Attr> attrNode = findAttrNodeInList(attrNodeList, name);
if (!attrNode) {
attrNode = Attr::create(this, name);
treeScope()->adoptIfNeeded(attrNode.get());
attrNodeList->append(attrNode);
}
return attrNode.release();
}
void Element::detachAttrNodeFromElementWithValue(Attr* attrNode, const AtomicString& value)
{
ASSERT(hasSyntheticAttrChildNodes());
attrNode->detachFromElementWithValue(value);
AttrNodeList* attrNodeList = attrNodeListForElement(this);
for (unsigned i = 0; i < attrNodeList->size(); ++i) {
if (attrNodeList->at(i)->qualifiedName() == attrNode->qualifiedName()) {
attrNodeList->remove(i);
if (attrNodeList->isEmpty())
removeAttrNodeListForElement(this);
return;
}
}
ASSERT_NOT_REACHED();
}
void Element::detachAllAttrNodesFromElement()
{
AttrNodeList* attrNodeList = attrNodeListForElement(this);
ASSERT(attrNodeList);
for (unsigned i = 0; i < attributeCount(); ++i) {
const Attribute* attribute = attributeItem(i);
if (RefPtr<Attr> attrNode = findAttrNodeInList(attrNodeList, attribute->name()))
attrNode->detachFromElementWithValue(attribute->value());
}
removeAttrNodeListForElement(this);
}
bool Element::willRecalcStyle(StyleChange)
{
ASSERT(hasCustomStyleCallbacks());
return true;
}
void Element::didRecalcStyle(StyleChange)
{
ASSERT(hasCustomStyleCallbacks());
}
PassRefPtr<RenderStyle> Element::customStyleForRenderer()
{
ASSERT(hasCustomStyleCallbacks());
return 0;
}
void Element::cloneAttributesFromElement(const Element& other)
{
if (hasSyntheticAttrChildNodes())
detachAllAttrNodesFromElement();
other.synchronizeAllAttributes();
if (!other.m_elementData) {
m_elementData.clear();
return;
}
// We can't update window and document's named item maps since the presence of image and object elements depend on other attributes and children.
// Fortunately, those named item maps are only updated when this element is in the document, which should never be the case.
ASSERT(!inDocument());
const AtomicString& oldID = getIdAttribute();
const AtomicString& newID = other.getIdAttribute();
if (!oldID.isNull() || !newID.isNull())
updateId(oldID, newID);
const AtomicString& oldName = getNameAttribute();
const AtomicString& newName = other.getNameAttribute();
if (!oldName.isNull() || !newName.isNull())
updateName(oldName, newName);
// If 'other' has a mutable ElementData, convert it to an immutable one so we can share it between both elements.
// We can only do this if there is no CSSOM wrapper for other's inline style, and there are no presentation attributes.
if (other.m_elementData->isUnique()
&& !other.m_elementData->presentationAttributeStyle()
&& (!other.m_elementData->inlineStyle() || !other.m_elementData->inlineStyle()->hasCSSOMWrapper()))
const_cast<Element&>(other).m_elementData = static_cast<const UniqueElementData*>(other.m_elementData.get())->makeShareableCopy();
if (!other.m_elementData->isUnique())
m_elementData = other.m_elementData;
else
m_elementData = other.m_elementData->makeUniqueCopy();
for (unsigned i = 0; i < m_elementData->length(); ++i) {
const Attribute* attribute = const_cast<const ElementData*>(m_elementData.get())->attributeItem(i);
attributeChangedFromParserOrByCloning(attribute->name(), attribute->value(), ModifiedByCloning);
}
}
void Element::cloneDataFromElement(const Element& other)
{
cloneAttributesFromElement(other);
copyNonAttributePropertiesFromElement(other);
}
void Element::createUniqueElementData()
{
if (!m_elementData)
m_elementData = UniqueElementData::create();
else {
ASSERT(!m_elementData->isUnique());
m_elementData = static_cast<ShareableElementData*>(m_elementData.get())->makeUniqueCopy();
}
}
#if ENABLE(SVG)
bool Element::hasPendingResources() const
{
return hasRareData() && elementRareData()->hasPendingResources();
}
void Element::setHasPendingResources()
{
ensureElementRareData()->setHasPendingResources(true);
}
void Element::clearHasPendingResources()
{
ensureElementRareData()->setHasPendingResources(false);
}
#endif
void ElementData::deref()
{
if (!derefBase())
return;
if (m_isUnique)
delete static_cast<UniqueElementData*>(this);
else
delete static_cast<ShareableElementData*>(this);
}
ElementData::ElementData()
: m_isUnique(true)
, m_arraySize(0)
, m_hasNameAttribute(false)
, m_presentationAttributeStyleIsDirty(false)
, m_styleAttributeIsDirty(false)
#if ENABLE(SVG)
, m_animatedSVGAttributesAreDirty(false)
#endif
{
}
ElementData::ElementData(unsigned arraySize)
: m_isUnique(false)
, m_arraySize(arraySize)
, m_hasNameAttribute(false)
, m_presentationAttributeStyleIsDirty(false)
, m_styleAttributeIsDirty(false)
#if ENABLE(SVG)
, m_animatedSVGAttributesAreDirty(false)
#endif
{
}
struct SameSizeAsElementData : public RefCounted<SameSizeAsElementData> {
unsigned bitfield;
void* refPtrs[3];
};
COMPILE_ASSERT(sizeof(ElementData) == sizeof(SameSizeAsElementData), element_attribute_data_should_stay_small);
static size_t sizeForShareableElementDataWithAttributeCount(unsigned count)
{
return sizeof(ShareableElementData) + sizeof(Attribute) * count;
}
PassRefPtr<ShareableElementData> ShareableElementData::createWithAttributes(const Vector<Attribute>& attributes)
{
void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(attributes.size()));
return adoptRef(new (NotNull, slot) ShareableElementData(attributes));
}
PassRefPtr<UniqueElementData> UniqueElementData::create()
{
return adoptRef(new UniqueElementData);
}
ShareableElementData::ShareableElementData(const Vector<Attribute>& attributes)
: ElementData(attributes.size())
{
for (unsigned i = 0; i < m_arraySize; ++i)
new (NotNull, &m_attributeArray[i]) Attribute(attributes[i]);
}
ShareableElementData::~ShareableElementData()
{
for (unsigned i = 0; i < m_arraySize; ++i)
m_attributeArray[i].~Attribute();
}
ShareableElementData::ShareableElementData(const UniqueElementData& other)
: ElementData(other, false)
{
ASSERT(!other.m_presentationAttributeStyle);
if (other.m_inlineStyle) {
ASSERT(!other.m_inlineStyle->hasCSSOMWrapper());
m_inlineStyle = other.m_inlineStyle->immutableCopyIfNeeded();
}
for (unsigned i = 0; i < m_arraySize; ++i)
new (NotNull, &m_attributeArray[i]) Attribute(other.m_attributeVector.at(i));
}
ElementData::ElementData(const ElementData& other, bool isUnique)
: m_isUnique(isUnique)
, m_arraySize(isUnique ? 0 : other.length())
, m_hasNameAttribute(other.m_hasNameAttribute)
, m_presentationAttributeStyleIsDirty(other.m_presentationAttributeStyleIsDirty)
, m_styleAttributeIsDirty(other.m_styleAttributeIsDirty)
#if ENABLE(SVG)
, m_animatedSVGAttributesAreDirty(other.m_animatedSVGAttributesAreDirty)
#endif
, m_classNames(other.m_classNames)
, m_idForStyleResolution(other.m_idForStyleResolution)
{
// NOTE: The inline style is copied by the subclass copy constructor since we don't know what to do with it here.
}
UniqueElementData::UniqueElementData()
{
}
UniqueElementData::UniqueElementData(const UniqueElementData& other)
: ElementData(other, true)
, m_presentationAttributeStyle(other.m_presentationAttributeStyle)
, m_attributeVector(other.m_attributeVector)
{
m_inlineStyle = other.m_inlineStyle ? other.m_inlineStyle->mutableCopy() : 0;
}
UniqueElementData::UniqueElementData(const ShareableElementData& other)
: ElementData(other, true)
{
// An ShareableElementData should never have a mutable inline StylePropertySet attached.
ASSERT(!other.m_inlineStyle || !other.m_inlineStyle->isMutable());
m_inlineStyle = other.m_inlineStyle;
m_attributeVector.reserveCapacity(other.length());
for (unsigned i = 0; i < other.length(); ++i)
m_attributeVector.uncheckedAppend(other.m_attributeArray[i]);
}
PassRefPtr<UniqueElementData> ElementData::makeUniqueCopy() const
{
if (isUnique())
return adoptRef(new UniqueElementData(static_cast<const UniqueElementData&>(*this)));
return adoptRef(new UniqueElementData(static_cast<const ShareableElementData&>(*this)));
}
PassRefPtr<ShareableElementData> UniqueElementData::makeShareableCopy() const
{
void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(m_attributeVector.size()));
return adoptRef(new (NotNull, slot) ShareableElementData(*this));
}
void UniqueElementData::addAttribute(const QualifiedName& attributeName, const AtomicString& value)
{
m_attributeVector.append(Attribute(attributeName, value));
}
void UniqueElementData::removeAttribute(unsigned index)
{
ASSERT_WITH_SECURITY_IMPLICATION(index < length());
m_attributeVector.remove(index);
}
bool ElementData::isEquivalent(const ElementData* other) const
{
if (!other)
return isEmpty();
unsigned len = length();
if (len != other->length())
return false;
for (unsigned i = 0; i < len; i++) {
const Attribute* attribute = attributeItem(i);
const Attribute* otherAttr = other->getAttributeItem(attribute->name());
if (!otherAttr || attribute->value() != otherAttr->value())
return false;
}
return true;
}
unsigned ElementData::getAttributeItemIndexSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const
{
// Continue to checking case-insensitively and/or full namespaced names if necessary:
for (unsigned i = 0; i < length(); ++i) {
const Attribute* attribute = attributeItem(i);
if (!attribute->name().hasPrefix()) {
if (shouldIgnoreAttributeCase && equalIgnoringCase(name, attribute->localName()))
return i;
} else {
// FIXME: Would be faster to do this comparison without calling toString, which
// generates a temporary string by concatenation. But this branch is only reached
// if the attribute name has a prefix, which is rare in HTML.
if (equalPossiblyIgnoringCase(name, attribute->name().toString(), shouldIgnoreAttributeCase))
return i;
}
}
return attributeNotFound;
}
unsigned ElementData::getAttributeItemIndexForAttributeNode(const Attr* attr) const
{
ASSERT(attr);
const Attribute* attributes = attributeBase();
unsigned count = length();
for (unsigned i = 0; i < count; ++i) {
if (attributes[i].name() == attr->qualifiedName())
return i;
}
return attributeNotFound;
}
Attribute* UniqueElementData::getAttributeItem(const QualifiedName& name)
{
unsigned count = length();
for (unsigned i = 0; i < count; ++i) {
if (m_attributeVector.at(i).name().matches(name))
return &m_attributeVector.at(i);
}
return 0;
}
Attribute* UniqueElementData::attributeItem(unsigned index)
{
ASSERT_WITH_SECURITY_IMPLICATION(index < length());
return &m_attributeVector.at(index);
}
} // namespace WebCore
|