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
|
/*
* Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
* 1999 Lars Knoll <knoll@kde.org>
* 1999 Antti Koivisto <koivisto@kde.org>
* 2000 Dirk Mueller <mueller@kde.org>
* Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
* (C) 2006 Graham Dennis (graham.dennis@gmail.com)
* (C) 2006 Alexey Proskuryakov (ap@nypop.com)
* Copyright (C) 2009 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "FrameView.h"
#include "AXObjectCache.h"
#include "CSSStyleSelector.h"
#include "CachedResourceLoader.h"
#include "Chrome.h"
#include "ChromeClient.h"
#include "DocumentMarkerController.h"
#include "EventHandler.h"
#include "FloatRect.h"
#include "FocusController.h"
#include "Frame.h"
#include "FrameActionScheduler.h"
#include "FrameLoader.h"
#include "FrameLoaderClient.h"
#include "FrameTree.h"
#include "GraphicsContext.h"
#include "HTMLDocument.h"
#include "HTMLFrameElement.h"
#include "HTMLFrameSetElement.h"
#include "HTMLNames.h"
#include "HTMLPlugInImageElement.h"
#include "InspectorInstrumentation.h"
#include "OverflowEvent.h"
#include "RenderEmbeddedObject.h"
#include "RenderFullScreen.h"
#include "RenderLayer.h"
#include "RenderPart.h"
#include "RenderScrollbar.h"
#include "RenderScrollbarPart.h"
#include "RenderTheme.h"
#include "RenderView.h"
#include "ScrollAnimator.h"
#include "Settings.h"
#include "TextResourceDecoder.h"
#include <wtf/CurrentTime.h>
#if USE(ACCELERATED_COMPOSITING)
#include "RenderLayerCompositor.h"
#endif
#if ENABLE(SVG)
#include "SVGDocument.h"
#include "SVGLocatable.h"
#include "SVGNames.h"
#include "SVGPreserveAspectRatio.h"
#include "SVGSVGElement.h"
#include "SVGViewElement.h"
#include "SVGViewSpec.h"
#endif
#if ENABLE(TILED_BACKING_STORE)
#include "TiledBackingStore.h"
#endif
namespace WebCore {
using namespace HTMLNames;
double FrameView::sCurrentPaintTimeStamp = 0.0;
// REPAINT_THROTTLING now chooses default values for throttling parameters.
// Should be removed when applications start using runtime configuration.
#if ENABLE(REPAINT_THROTTLING)
// Normal delay
double FrameView::s_deferredRepaintDelay = 0.025;
// Negative value would mean that first few repaints happen without a delay
double FrameView::s_initialDeferredRepaintDelayDuringLoading = 0;
// The delay grows on each repaint to this maximum value
double FrameView::s_maxDeferredRepaintDelayDuringLoading = 2.5;
// On each repaint the delay increses by this amount
double FrameView::s_deferredRepaintDelayIncrementDuringLoading = 0.5;
#else
// FIXME: Repaint throttling could be good to have on all platform.
// The balance between CPU use and repaint frequency will need some tuning for desktop.
// More hooks may be needed to reset the delay on things like GIF and CSS animations.
double FrameView::s_deferredRepaintDelay = 0;
double FrameView::s_initialDeferredRepaintDelayDuringLoading = 0;
double FrameView::s_maxDeferredRepaintDelayDuringLoading = 0;
double FrameView::s_deferredRepaintDelayIncrementDuringLoading = 0;
#endif
// The maximum number of updateWidgets iterations that should be done before returning.
static const unsigned maxUpdateWidgetsIterations = 2;
FrameView::FrameView(Frame* frame)
: m_frame(frame)
, m_canHaveScrollbars(true)
, m_slowRepaintObjectCount(0)
, m_fixedObjectCount(0)
, m_layoutTimer(this, &FrameView::layoutTimerFired)
, m_layoutRoot(0)
, m_hasPendingPostLayoutTasks(false)
, m_inSynchronousPostLayout(false)
, m_postLayoutTasksTimer(this, &FrameView::postLayoutTimerFired)
, m_isTransparent(false)
, m_baseBackgroundColor(Color::white)
, m_mediaType("screen")
, m_actionScheduler(adoptPtr(new FrameActionScheduler))
, m_overflowStatusDirty(true)
, m_viewportRenderer(0)
, m_wasScrolledByUser(false)
, m_inProgrammaticScroll(false)
, m_deferredRepaintTimer(this, &FrameView::deferredRepaintTimerFired)
, m_shouldUpdateWhileOffscreen(true)
, m_deferSetNeedsLayouts(0)
, m_setNeedsLayoutWasDeferred(false)
, m_scrollCorner(0)
{
init();
if (m_frame) {
if (Page* page = m_frame->page()) {
m_page = page;
m_page->addScrollableArea(this);
if (m_frame == m_page->mainFrame()) {
ScrollableArea::setVerticalScrollElasticity(ScrollElasticityAllowed);
ScrollableArea::setHorizontalScrollElasticity(ScrollElasticityAllowed);
}
}
}
}
PassRefPtr<FrameView> FrameView::create(Frame* frame)
{
RefPtr<FrameView> view = adoptRef(new FrameView(frame));
view->show();
return view.release();
}
PassRefPtr<FrameView> FrameView::create(Frame* frame, const IntSize& initialSize)
{
RefPtr<FrameView> view = adoptRef(new FrameView(frame));
view->Widget::setFrameRect(IntRect(view->pos(), initialSize));
view->setInitialBoundsSize(initialSize);
view->show();
return view.release();
}
FrameView::~FrameView()
{
if (m_hasPendingPostLayoutTasks) {
m_postLayoutTasksTimer.stop();
m_actionScheduler->clear();
}
if (AXObjectCache::accessibilityEnabled() && axObjectCache())
axObjectCache()->remove(this);
resetScrollbars();
// Custom scrollbars should already be destroyed at this point
ASSERT(!horizontalScrollbar() || !horizontalScrollbar()->isCustomScrollbar());
ASSERT(!verticalScrollbar() || !verticalScrollbar()->isCustomScrollbar());
setHasHorizontalScrollbar(false); // Remove native scrollbars now before we lose the connection to the HostWindow.
setHasVerticalScrollbar(false);
ASSERT(!m_scrollCorner);
ASSERT(m_actionScheduler->isEmpty());
if (m_page)
m_page->removeScrollableArea(this);
if (m_frame) {
ASSERT(m_frame->view() != this || !m_frame->contentRenderer());
RenderPart* renderer = m_frame->ownerRenderer();
if (renderer && renderer->widget() == this)
renderer->setWidget(0);
}
}
void FrameView::reset()
{
m_useSlowRepaints = false;
m_isOverlapped = false;
m_contentIsOpaque = false;
m_borderX = 30;
m_borderY = 30;
m_layoutTimer.stop();
m_layoutRoot = 0;
m_delayedLayout = false;
m_doFullRepaint = true;
m_layoutSchedulingEnabled = true;
m_inLayout = false;
m_inSynchronousPostLayout = false;
m_hasPendingPostLayoutTasks = false;
m_layoutCount = 0;
m_nestedLayoutCount = 0;
m_postLayoutTasksTimer.stop();
m_firstLayout = true;
m_firstLayoutCallbackPending = false;
m_wasScrolledByUser = false;
m_lastLayoutSize = IntSize();
m_lastZoomFactor = 1.0f;
m_deferringRepaints = 0;
m_repaintCount = 0;
m_repaintRects.clear();
m_deferredRepaintDelay = s_initialDeferredRepaintDelayDuringLoading;
m_deferredRepaintTimer.stop();
m_lastPaintTime = 0;
m_paintBehavior = PaintBehaviorNormal;
m_isPainting = false;
m_isVisuallyNonEmpty = false;
m_firstVisuallyNonEmptyLayoutCallbackPending = true;
m_maintainScrollPositionAnchor = 0;
}
bool FrameView::isFrameView() const
{
return true;
}
void FrameView::clearFrame()
{
m_frame = 0;
}
void FrameView::resetScrollbars()
{
// Reset the document's scrollbars back to our defaults before we yield the floor.
m_firstLayout = true;
setScrollbarsSuppressed(true);
if (m_canHaveScrollbars)
setScrollbarModes(ScrollbarAuto, ScrollbarAuto);
else
setScrollbarModes(ScrollbarAlwaysOff, ScrollbarAlwaysOff);
setScrollbarsSuppressed(false);
}
void FrameView::resetScrollbarsAndClearContentsSize()
{
resetScrollbars();
setScrollbarsSuppressed(true);
setContentsSize(IntSize());
setScrollbarsSuppressed(false);
}
void FrameView::init()
{
reset();
m_margins = IntSize(-1, -1); // undefined
m_size = IntSize();
// Propagate the marginwidth/height and scrolling modes to the view.
Element* ownerElement = m_frame ? m_frame->ownerElement() : 0;
if (ownerElement && (ownerElement->hasTagName(frameTag) || ownerElement->hasTagName(iframeTag))) {
HTMLFrameElement* frameElt = static_cast<HTMLFrameElement*>(ownerElement);
if (frameElt->scrollingMode() == ScrollbarAlwaysOff)
setCanHaveScrollbars(false);
int marginWidth = frameElt->marginWidth();
int marginHeight = frameElt->marginHeight();
if (marginWidth != -1)
setMarginWidth(marginWidth);
if (marginHeight != -1)
setMarginHeight(marginHeight);
}
}
void FrameView::detachCustomScrollbars()
{
if (!m_frame)
return;
Scrollbar* horizontalBar = horizontalScrollbar();
if (horizontalBar && horizontalBar->isCustomScrollbar())
setHasHorizontalScrollbar(false);
Scrollbar* verticalBar = verticalScrollbar();
if (verticalBar && verticalBar->isCustomScrollbar())
setHasVerticalScrollbar(false);
if (m_scrollCorner) {
m_scrollCorner->destroy();
m_scrollCorner = 0;
}
}
ScrollbarOverlayStyle FrameView::recommendedScrollbarOverlayStyle() const
{
Color bgColor = m_frame->getDocumentBackgroundColor();
if (!bgColor.isValid())
return ScrollbarOverlayStyleDefault;
// Reduce the background color from RGB to a lightness value
// and determine which scrollbar style to use based on a lightness
// heuristic.
double hue, saturation, lightness;
bgColor.getHSL(hue, saturation, lightness);
if (lightness > .5)
return ScrollbarOverlayStyleDefault;
return ScrollbarOverlayStyleLight;
}
void FrameView::clear()
{
setCanBlitOnScroll(true);
reset();
if (m_frame) {
if (RenderPart* renderer = m_frame->ownerRenderer())
renderer->viewCleared();
}
setScrollbarsSuppressed(true);
}
bool FrameView::didFirstLayout() const
{
return !m_firstLayout;
}
void FrameView::invalidateRect(const IntRect& rect)
{
if (!parent()) {
if (hostWindow())
hostWindow()->invalidateContentsAndWindow(rect, false /*immediate*/);
return;
}
if (!m_frame)
return;
RenderPart* renderer = m_frame->ownerRenderer();
if (!renderer)
return;
IntRect repaintRect = rect;
repaintRect.move(renderer->borderLeft() + renderer->paddingLeft(),
renderer->borderTop() + renderer->paddingTop());
renderer->repaintRectangle(repaintRect);
}
void FrameView::setFrameRect(const IntRect& newRect)
{
IntRect oldRect = frameRect();
if (newRect == oldRect)
return;
ScrollView::setFrameRect(newRect);
#if USE(ACCELERATED_COMPOSITING)
if (RenderView* root = m_frame->contentRenderer()) {
if (root->usesCompositing())
root->compositor()->frameViewDidChangeSize();
}
#endif
}
#if ENABLE(REQUEST_ANIMATION_FRAME)
void FrameView::scheduleAnimation()
{
if (hostWindow())
hostWindow()->scheduleAnimation();
}
#endif
void FrameView::setMarginWidth(int w)
{
// make it update the rendering area when set
m_margins.setWidth(w);
}
void FrameView::setMarginHeight(int h)
{
// make it update the rendering area when set
m_margins.setHeight(h);
}
bool FrameView::avoidScrollbarCreation() const
{
ASSERT(m_frame);
// with frame flattening no subframe can have scrollbars
// but we also cannot turn scrollbars of as we determine
// our flattening policy using that.
if (!m_frame->ownerElement())
return false;
if (!m_frame->settings() || m_frame->settings()->frameFlatteningEnabled())
return true;
return false;
}
void FrameView::setCanHaveScrollbars(bool canHaveScrollbars)
{
m_canHaveScrollbars = canHaveScrollbars;
ScrollView::setCanHaveScrollbars(canHaveScrollbars);
}
void FrameView::updateCanHaveScrollbars()
{
ScrollbarMode hMode;
ScrollbarMode vMode;
scrollbarModes(hMode, vMode);
if (hMode == ScrollbarAlwaysOff && vMode == ScrollbarAlwaysOff)
setCanHaveScrollbars(false);
else
setCanHaveScrollbars(true);
}
PassRefPtr<Scrollbar> FrameView::createScrollbar(ScrollbarOrientation orientation)
{
// FIXME: We need to update the scrollbar dynamically as documents change (or as doc elements and bodies get discovered that have custom styles).
Document* doc = m_frame->document();
// Try the <body> element first as a scrollbar source.
Element* body = doc ? doc->body() : 0;
if (body && body->renderer() && body->renderer()->style()->hasPseudoStyle(SCROLLBAR))
return RenderScrollbar::createCustomScrollbar(this, orientation, body->renderer()->enclosingBox());
// If the <body> didn't have a custom style, then the root element might.
Element* docElement = doc ? doc->documentElement() : 0;
if (docElement && docElement->renderer() && docElement->renderer()->style()->hasPseudoStyle(SCROLLBAR))
return RenderScrollbar::createCustomScrollbar(this, orientation, docElement->renderBox());
// If we have an owning iframe/frame element, then it can set the custom scrollbar also.
RenderPart* frameRenderer = m_frame->ownerRenderer();
if (frameRenderer && frameRenderer->style()->hasPseudoStyle(SCROLLBAR))
return RenderScrollbar::createCustomScrollbar(this, orientation, 0, m_frame.get());
// Nobody set a custom style, so we just use a native scrollbar.
return ScrollView::createScrollbar(orientation);
}
void FrameView::setContentsSize(const IntSize& size)
{
if (size == contentsSize())
return;
m_deferSetNeedsLayouts++;
ScrollView::setContentsSize(size);
scrollAnimator()->contentsResized();
Page* page = frame() ? frame()->page() : 0;
if (!page)
return;
page->chrome()->contentsSizeChanged(frame(), size); //notify only
m_deferSetNeedsLayouts--;
if (!m_deferSetNeedsLayouts)
m_setNeedsLayoutWasDeferred = false; // FIXME: Find a way to make the deferred layout actually happen.
}
void FrameView::adjustViewSize()
{
ASSERT(m_frame->view() == this);
RenderView* root = m_frame->contentRenderer();
if (!root)
return;
IntSize size = IntSize(root->docWidth(), root->docHeight());
ScrollView::setScrollOrigin(IntPoint(-root->docLeft(), -root->docTop()), !m_frame->document()->printing(), size == contentsSize());
setContentsSize(size);
}
void FrameView::applyOverflowToViewport(RenderObject* o, ScrollbarMode& hMode, ScrollbarMode& vMode)
{
// Handle the overflow:hidden/scroll case for the body/html elements. WinIE treats
// overflow:hidden and overflow:scroll on <body> as applying to the document's
// scrollbars. The CSS2.1 draft states that HTML UAs should use the <html> or <body> element and XML/XHTML UAs should
// use the root element.
switch (o->style()->overflowX()) {
case OHIDDEN:
hMode = ScrollbarAlwaysOff;
break;
case OSCROLL:
hMode = ScrollbarAlwaysOn;
break;
case OAUTO:
hMode = ScrollbarAuto;
break;
default:
// Don't set it at all.
;
}
switch (o->style()->overflowY()) {
case OHIDDEN:
vMode = ScrollbarAlwaysOff;
break;
case OSCROLL:
vMode = ScrollbarAlwaysOn;
break;
case OAUTO:
vMode = ScrollbarAuto;
break;
default:
// Don't set it at all.
;
}
m_viewportRenderer = o;
}
void FrameView::calculateScrollbarModesForLayout(ScrollbarMode& hMode, ScrollbarMode& vMode)
{
m_viewportRenderer = 0;
const HTMLFrameOwnerElement* owner = m_frame->ownerElement();
if (owner && (owner->scrollingMode() == ScrollbarAlwaysOff)) {
hMode = ScrollbarAlwaysOff;
vMode = ScrollbarAlwaysOff;
return;
}
if (m_canHaveScrollbars) {
hMode = ScrollbarAuto;
vMode = ScrollbarAuto;
} else {
hMode = ScrollbarAlwaysOff;
vMode = ScrollbarAlwaysOff;
}
if (!m_layoutRoot) {
Document* document = m_frame->document();
Node* documentElement = document->documentElement();
RenderObject* rootRenderer = documentElement ? documentElement->renderer() : 0;
Node* body = document->body();
if (body && body->renderer()) {
if (body->hasTagName(framesetTag) && m_frame->settings() && !m_frame->settings()->frameFlatteningEnabled()) {
vMode = ScrollbarAlwaysOff;
hMode = ScrollbarAlwaysOff;
} else if (body->hasTagName(bodyTag)) {
// It's sufficient to just check the X overflow,
// since it's illegal to have visible in only one direction.
RenderObject* o = rootRenderer->style()->overflowX() == OVISIBLE && document->documentElement()->hasTagName(htmlTag) ? body->renderer() : rootRenderer;
applyOverflowToViewport(o, hMode, vMode);
}
} else if (rootRenderer) {
#if ENABLE(SVG)
if (!documentElement->isSVGElement())
applyOverflowToViewport(rootRenderer, hMode, vMode);
#else
applyOverflowToViewport(rootRenderer, hMode, vMode);
#endif
}
}
}
#if ENABLE(FULLSCREEN_API) && USE(ACCELERATED_COMPOSITING)
static bool isDocumentRunningFullScreenAnimation(Document* document)
{
return document->webkitIsFullScreen() && document->fullScreenRenderer() && document->fullScreenRenderer()->isAnimating();
}
#endif
#if USE(ACCELERATED_COMPOSITING)
void FrameView::updateCompositingLayers()
{
RenderView* view = m_frame->contentRenderer();
if (!view)
return;
// This call will make sure the cached hasAcceleratedCompositing is updated from the pref
view->compositor()->cacheAcceleratedCompositingFlags();
view->compositor()->updateCompositingLayers(CompositingUpdateAfterLayoutOrStyleChange);
#if ENABLE(FULLSCREEN_API)
Document* document = m_frame->document();
if (isDocumentRunningFullScreenAnimation(document))
view->compositor()->updateCompositingLayers(CompositingUpdateAfterLayoutOrStyleChange, document->fullScreenRenderer()->layer());
#endif
}
GraphicsLayer* FrameView::layerForHorizontalScrollbar() const
{
RenderView* view = m_frame->contentRenderer();
if (!view)
return 0;
return view->compositor()->layerForHorizontalScrollbar();
}
GraphicsLayer* FrameView::layerForVerticalScrollbar() const
{
RenderView* view = m_frame->contentRenderer();
if (!view)
return 0;
return view->compositor()->layerForVerticalScrollbar();
}
GraphicsLayer* FrameView::layerForScrollCorner() const
{
RenderView* view = m_frame->contentRenderer();
if (!view)
return 0;
return view->compositor()->layerForScrollCorner();
}
bool FrameView::syncCompositingStateForThisFrame()
{
ASSERT(m_frame->view() == this);
RenderView* view = m_frame->contentRenderer();
if (!view)
return true; // We don't want to keep trying to update layers if we have no renderer.
// If we sync compositing layers when a layout is pending, we may cause painting of compositing
// layer content to occur before layout has happened, which will cause paintContents() to bail.
if (needsLayout())
return false;
if (GraphicsLayer* graphicsLayer = view->compositor()->layerForHorizontalScrollbar())
graphicsLayer->syncCompositingStateForThisLayerOnly();
if (GraphicsLayer* graphicsLayer = view->compositor()->layerForVerticalScrollbar())
graphicsLayer->syncCompositingStateForThisLayerOnly();
if (GraphicsLayer* graphicsLayer = view->compositor()->layerForScrollCorner())
graphicsLayer->syncCompositingStateForThisLayerOnly();
view->compositor()->flushPendingLayerChanges();
#if ENABLE(FULLSCREEN_API)
// The fullScreenRenderer's graphicsLayer has been re-parented, and the above recursive syncCompositingState
// call will not cause the subtree under it to repaint. Explicitly call the syncCompositingState on
// the fullScreenRenderer's graphicsLayer here:
Document* document = m_frame->document();
if (isDocumentRunningFullScreenAnimation(document)) {
RenderLayerBacking* backing = document->fullScreenRenderer()->layer()->backing();
if (GraphicsLayer* fullScreenLayer = backing->graphicsLayer())
fullScreenLayer->syncCompositingState();
}
#endif
return true;
}
void FrameView::setNeedsOneShotDrawingSynchronization()
{
Page* page = frame() ? frame()->page() : 0;
if (page)
page->chrome()->client()->setNeedsOneShotDrawingSynchronization();
}
#endif // USE(ACCELERATED_COMPOSITING)
bool FrameView::hasCompositedContent() const
{
#if USE(ACCELERATED_COMPOSITING)
if (RenderView* view = m_frame->contentRenderer())
return view->compositor()->inCompositingMode();
#endif
return false;
}
bool FrameView::hasCompositedContentIncludingDescendants() const
{
#if USE(ACCELERATED_COMPOSITING)
for (Frame* frame = m_frame.get(); frame; frame = frame->tree()->traverseNext(m_frame.get())) {
RenderView* renderView = frame->contentRenderer();
RenderLayerCompositor* compositor = renderView ? renderView->compositor() : 0;
if (compositor) {
if (compositor->inCompositingMode())
return true;
if (!RenderLayerCompositor::allowsIndependentlyCompositedFrames(this))
break;
}
}
#endif
return false;
}
bool FrameView::hasCompositingAncestor() const
{
#if USE(ACCELERATED_COMPOSITING)
for (Frame* frame = m_frame->tree()->parent(); frame; frame = frame->tree()->parent()) {
if (FrameView* view = frame->view()) {
if (view->hasCompositedContent())
return true;
}
}
#endif
return false;
}
// Sometimes (for plug-ins) we need to eagerly go into compositing mode.
void FrameView::enterCompositingMode()
{
#if USE(ACCELERATED_COMPOSITING)
if (RenderView* view = m_frame->contentRenderer()) {
view->compositor()->enableCompositingMode();
if (!needsLayout())
view->compositor()->scheduleCompositingLayerUpdate();
}
#endif
}
bool FrameView::isEnclosedInCompositingLayer() const
{
#if USE(ACCELERATED_COMPOSITING)
RenderObject* frameOwnerRenderer = m_frame->ownerRenderer();
if (frameOwnerRenderer && frameOwnerRenderer->containerForRepaint())
return true;
if (FrameView* parentView = parentFrameView())
return parentView->isEnclosedInCompositingLayer();
#endif
return false;
}
bool FrameView::syncCompositingStateIncludingSubframes()
{
#if USE(ACCELERATED_COMPOSITING)
bool allFramesSynced = syncCompositingStateForThisFrame();
for (Frame* child = m_frame->tree()->firstChild(); child; child = child->tree()->traverseNext(m_frame.get())) {
bool synced = child->view()->syncCompositingStateForThisFrame();
allFramesSynced &= synced;
}
return allFramesSynced;
#else // USE(ACCELERATED_COMPOSITING)
return true;
#endif
}
bool FrameView::isSoftwareRenderable() const
{
#if USE(ACCELERATED_COMPOSITING)
RenderView* view = m_frame->contentRenderer();
if (!view)
return true;
return !view->compositor()->has3DContent();
#else
return true;
#endif
}
void FrameView::didMoveOnscreen()
{
RenderView* view = m_frame->contentRenderer();
if (view)
view->didMoveOnscreen();
scrollAnimator()->contentAreaDidShow();
}
void FrameView::willMoveOffscreen()
{
RenderView* view = m_frame->contentRenderer();
if (view)
view->willMoveOffscreen();
scrollAnimator()->contentAreaDidHide();
}
RenderObject* FrameView::layoutRoot(bool onlyDuringLayout) const
{
return onlyDuringLayout && layoutPending() ? 0 : m_layoutRoot;
}
void FrameView::layout(bool allowSubtree)
{
if (m_inLayout)
return;
bool inSubframeLayoutWithFrameFlattening = parent() && m_frame->settings() && m_frame->settings()->frameFlatteningEnabled();
if (inSubframeLayoutWithFrameFlattening) {
if (parent()->isFrameView()) {
FrameView* parentView = static_cast<FrameView*>(parent());
if (!parentView->m_nestedLayoutCount) {
while (parentView->parent() && parentView->parent()->isFrameView())
parentView = static_cast<FrameView*>(parentView->parent());
parentView->layout(allowSubtree);
return;
}
}
}
m_layoutTimer.stop();
m_delayedLayout = false;
m_setNeedsLayoutWasDeferred = false;
// Protect the view from being deleted during layout (in recalcStyle)
RefPtr<FrameView> protector(this);
if (!m_frame) {
// FIXME: Do we need to set m_size.width here?
// FIXME: Should we set m_size.height here too?
m_size.setWidth(layoutWidth());
return;
}
// we shouldn't enter layout() while painting
ASSERT(!isPainting());
if (isPainting())
return;
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willLayout(m_frame.get());
if (!allowSubtree && m_layoutRoot) {
m_layoutRoot->markContainingBlocksForLayout(false);
m_layoutRoot = 0;
}
ASSERT(m_frame->view() == this);
Document* document = m_frame->document();
m_layoutSchedulingEnabled = false;
if (!m_nestedLayoutCount && !m_inSynchronousPostLayout && m_hasPendingPostLayoutTasks && !inSubframeLayoutWithFrameFlattening) {
// This is a new top-level layout. If there are any remaining tasks from the previous
// layout, finish them now.
m_inSynchronousPostLayout = true;
m_postLayoutTasksTimer.stop();
performPostLayoutTasks();
m_inSynchronousPostLayout = false;
}
// Viewport-dependent media queries may cause us to need completely different style information.
// Check that here.
if (document->styleSelector()->affectedByViewportChange())
document->styleSelectorChanged(RecalcStyleImmediately);
// Always ensure our style info is up-to-date. This can happen in situations where
// the layout beats any sort of style recalc update that needs to occur.
document->updateStyleIfNeeded();
bool subtree = m_layoutRoot;
// If there is only one ref to this view left, then its going to be destroyed as soon as we exit,
// so there's no point to continuing to layout
if (protector->hasOneRef())
return;
RenderObject* root = subtree ? m_layoutRoot : document->renderer();
if (!root) {
// FIXME: Do we need to set m_size here?
m_layoutSchedulingEnabled = true;
return;
}
m_nestedLayoutCount++;
if (!m_layoutRoot) {
Document* document = m_frame->document();
Node* documentElement = document->documentElement();
RenderObject* rootRenderer = documentElement ? documentElement->renderer() : 0;
Node* body = document->body();
if (body && body->renderer()) {
if (body->hasTagName(framesetTag) && m_frame->settings() && !m_frame->settings()->frameFlatteningEnabled()) {
body->renderer()->setChildNeedsLayout(true);
} else if (body->hasTagName(bodyTag)) {
if (!m_firstLayout && m_size.height() != layoutHeight() && body->renderer()->enclosingBox()->stretchesToViewport())
body->renderer()->setChildNeedsLayout(true);
}
} else if (rootRenderer) {
#if ENABLE(SVG)
if (documentElement->isSVGElement()) {
if (!m_firstLayout && (m_size.width() != layoutWidth() || m_size.height() != layoutHeight()))
rootRenderer->setChildNeedsLayout(true);
}
#endif
}
#ifdef INSTRUMENT_LAYOUT_SCHEDULING
if (m_firstLayout && !m_frame->ownerElement())
printf("Elapsed time before first layout: %d\n", document->elapsedTime());
#endif
}
ScrollbarMode hMode;
ScrollbarMode vMode;
calculateScrollbarModesForLayout(hMode, vMode);
m_doFullRepaint = !subtree && (m_firstLayout || toRenderView(root)->printing());
if (!subtree) {
// Now set our scrollbar state for the layout.
ScrollbarMode currentHMode = horizontalScrollbarMode();
ScrollbarMode currentVMode = verticalScrollbarMode();
if (m_firstLayout || (hMode != currentHMode || vMode != currentVMode)) {
if (m_firstLayout) {
setScrollbarsSuppressed(true);
m_firstLayout = false;
m_firstLayoutCallbackPending = true;
m_lastLayoutSize = IntSize(width(), height());
m_lastZoomFactor = root->style()->zoom();
// Set the initial vMode to AlwaysOn if we're auto.
if (vMode == ScrollbarAuto)
setVerticalScrollbarMode(ScrollbarAlwaysOn); // This causes a vertical scrollbar to appear.
// Set the initial hMode to AlwaysOff if we're auto.
if (hMode == ScrollbarAuto)
setHorizontalScrollbarMode(ScrollbarAlwaysOff); // This causes a horizontal scrollbar to disappear.
setScrollbarModes(hMode, vMode);
setScrollbarsSuppressed(false, true);
} else
setScrollbarModes(hMode, vMode);
}
IntSize oldSize = m_size;
m_size = IntSize(layoutWidth(), layoutHeight());
if (oldSize != m_size) {
m_doFullRepaint = true;
if (!m_firstLayout) {
RenderBox* rootRenderer = document->documentElement() ? document->documentElement()->renderBox() : 0;
RenderBox* bodyRenderer = rootRenderer && document->body() ? document->body()->renderBox() : 0;
if (bodyRenderer && bodyRenderer->stretchesToViewport())
bodyRenderer->setChildNeedsLayout(true);
else if (rootRenderer && rootRenderer->stretchesToViewport())
rootRenderer->setChildNeedsLayout(true);
}
}
}
RenderLayer* layer = root->enclosingLayer();
m_actionScheduler->pause();
bool disableLayoutState = false;
if (subtree) {
RenderView* view = root->view();
disableLayoutState = view->shouldDisableLayoutStateForSubtree(root);
view->pushLayoutState(root);
if (disableLayoutState)
view->disableLayoutState();
}
m_inLayout = true;
beginDeferredRepaints();
root->layout();
endDeferredRepaints();
m_inLayout = false;
if (subtree) {
RenderView* view = root->view();
view->popLayoutState(root);
if (disableLayoutState)
view->enableLayoutState();
}
m_layoutRoot = 0;
m_layoutSchedulingEnabled = true;
if (!subtree && !toRenderView(root)->printing())
adjustViewSize();
// Now update the positions of all layers.
beginDeferredRepaints();
IntPoint cachedOffset;
if (m_doFullRepaint)
root->view()->repaint(); // FIXME: This isn't really right, since the RenderView doesn't fully encompass the visibleContentRect(). It just happens
// to work out most of the time, since first layouts and printing don't have you scrolled anywhere.
layer->updateLayerPositions((m_doFullRepaint ? 0 : RenderLayer::CheckForRepaint)
| RenderLayer::IsCompositingUpdateRoot
| RenderLayer::UpdateCompositingLayers,
subtree ? 0 : &cachedOffset);
endDeferredRepaints();
#if USE(ACCELERATED_COMPOSITING)
updateCompositingLayers();
#endif
m_layoutCount++;
#if PLATFORM(MAC) || PLATFORM(CHROMIUM)
if (AXObjectCache::accessibilityEnabled())
root->document()->axObjectCache()->postNotification(root, AXObjectCache::AXLayoutComplete, true);
#endif
#if ENABLE(DASHBOARD_SUPPORT)
updateDashboardRegions();
#endif
ASSERT(!root->needsLayout());
updateCanBlitOnScrollRecursively();
if (document->hasListenerType(Document::OVERFLOWCHANGED_LISTENER))
updateOverflowStatus(layoutWidth() < contentsWidth(),
layoutHeight() < contentsHeight());
if (!m_hasPendingPostLayoutTasks) {
if (!m_inSynchronousPostLayout) {
if (inSubframeLayoutWithFrameFlattening)
m_frame->contentRenderer()->updateWidgetPositions();
else {
m_inSynchronousPostLayout = true;
// Calls resumeScheduledEvents()
performPostLayoutTasks();
m_inSynchronousPostLayout = false;
}
}
if (!m_hasPendingPostLayoutTasks && (needsLayout() || m_inSynchronousPostLayout || inSubframeLayoutWithFrameFlattening)) {
// If we need layout or are already in a synchronous call to postLayoutTasks(),
// defer widget updates and event dispatch until after we return. postLayoutTasks()
// can make us need to update again, and we can get stuck in a nasty cycle unless
// we call it through the timer here.
m_hasPendingPostLayoutTasks = true;
m_postLayoutTasksTimer.startOneShot(0);
if (needsLayout()) {
m_actionScheduler->pause();
layout();
}
}
} else {
m_actionScheduler->resume();
}
InspectorInstrumentation::didLayout(cookie);
m_nestedLayoutCount--;
}
void FrameView::addWidgetToUpdate(RenderEmbeddedObject* object)
{
if (!m_widgetUpdateSet)
m_widgetUpdateSet = adoptPtr(new RenderEmbeddedObjectSet);
m_widgetUpdateSet->add(object);
}
void FrameView::removeWidgetToUpdate(RenderEmbeddedObject* object)
{
if (!m_widgetUpdateSet)
return;
m_widgetUpdateSet->remove(object);
}
void FrameView::setMediaType(const String& mediaType)
{
m_mediaType = mediaType;
}
String FrameView::mediaType() const
{
// See if we have an override type.
String overrideType = m_frame->loader()->client()->overrideMediaType();
if (!overrideType.isNull())
return overrideType;
return m_mediaType;
}
void FrameView::adjustMediaTypeForPrinting(bool printing)
{
if (printing) {
if (m_mediaTypeWhenNotPrinting.isNull())
m_mediaTypeWhenNotPrinting = mediaType();
setMediaType("print");
} else {
if (!m_mediaTypeWhenNotPrinting.isNull())
setMediaType(m_mediaTypeWhenNotPrinting);
m_mediaTypeWhenNotPrinting = String();
}
}
bool FrameView::useSlowRepaints() const
{
if (m_useSlowRepaints || m_slowRepaintObjectCount > 0 || (platformWidget() && m_fixedObjectCount > 0) || m_isOverlapped || !m_contentIsOpaque)
return true;
if (FrameView* parentView = parentFrameView())
return parentView->useSlowRepaints();
return false;
}
bool FrameView::useSlowRepaintsIfNotOverlapped() const
{
if (m_useSlowRepaints || m_slowRepaintObjectCount > 0 || (platformWidget() && m_fixedObjectCount > 0) || !m_contentIsOpaque)
return true;
if (FrameView* parentView = parentFrameView())
return parentView->useSlowRepaintsIfNotOverlapped();
return false;
}
void FrameView::updateCanBlitOnScrollRecursively()
{
for (Frame* frame = m_frame.get(); frame; frame = frame->tree()->traverseNext(m_frame.get())) {
if (FrameView* view = frame->view())
view->setCanBlitOnScroll(!view->useSlowRepaints());
}
}
void FrameView::setUseSlowRepaints()
{
m_useSlowRepaints = true;
updateCanBlitOnScrollRecursively();
}
void FrameView::addSlowRepaintObject()
{
if (!m_slowRepaintObjectCount)
updateCanBlitOnScrollRecursively();
m_slowRepaintObjectCount++;
}
void FrameView::removeSlowRepaintObject()
{
ASSERT(m_slowRepaintObjectCount > 0);
m_slowRepaintObjectCount--;
if (!m_slowRepaintObjectCount)
updateCanBlitOnScrollRecursively();
}
void FrameView::addFixedObject()
{
if (!m_fixedObjectCount && platformWidget())
updateCanBlitOnScrollRecursively();
++m_fixedObjectCount;
}
void FrameView::removeFixedObject()
{
ASSERT(m_fixedObjectCount > 0);
--m_fixedObjectCount;
if (!m_fixedObjectCount)
updateCanBlitOnScrollRecursively();
}
int FrameView::scrollXForFixedPosition() const
{
int visibleContentWidth = visibleContentRect().width();
int maxX = contentsWidth() - visibleContentWidth;
if (maxX == 0)
return 0;
int x = scrollX();
if (!ScrollView::scrollOrigin().x()) {
if (x < 0)
x = 0;
else if (x > maxX)
x = maxX;
} else {
if (x > 0)
x = 0;
else if (x < -maxX)
x = -maxX;
}
if (!m_frame)
return x;
float pageScaleFactor = m_frame->pageScaleFactor();
// When the page is scaled, the scaled "viewport" with respect to which fixed object are positioned
// doesn't move as fast as the content view, so that when the content is scrolled all the way to the
// end, the bottom of the scaled "viewport" touches the bottom of the real viewport.
float dragFactor = (contentsWidth() - visibleContentWidth * pageScaleFactor) / maxX;
return x * dragFactor / pageScaleFactor;
}
int FrameView::scrollYForFixedPosition() const
{
int visibleContentHeight = visibleContentRect().height();
int maxY = contentsHeight() - visibleContentHeight;
if (maxY == 0)
return 0;
int y = scrollY();
if (!ScrollView::scrollOrigin().y()) {
if (y < 0)
y = 0;
else if (y > maxY)
y = maxY;
} else {
if (y > 0)
y = 0;
else if (y < -maxY)
y = -maxY;
}
if (!m_frame)
return y;
float pageScaleFactor = m_frame->pageScaleFactor();
float dragFactor = (contentsHeight() - visibleContentHeight * pageScaleFactor) / maxY;
return y * dragFactor / pageScaleFactor;
}
IntSize FrameView::scrollOffsetForFixedPosition() const
{
return IntSize(scrollXForFixedPosition(), scrollYForFixedPosition());
}
IntPoint FrameView::currentMousePosition() const
{
return m_frame ? m_frame->eventHandler()->currentMousePosition() : IntPoint();
}
bool FrameView::scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect)
{
const size_t fixedObjectThreshold = 5;
RenderBlock::PositionedObjectsListHashSet* positionedObjects = 0;
if (RenderView* root = m_frame->contentRenderer())
positionedObjects = root->positionedObjects();
if (!positionedObjects || positionedObjects->isEmpty()) {
hostWindow()->scroll(scrollDelta, rectToScroll, clipRect);
return true;
}
// Get the rects of the fixed objects visible in the rectToScroll
Vector<IntRect, fixedObjectThreshold> subRectToUpdate;
bool updateInvalidatedSubRect = true;
RenderBlock::PositionedObjectsListHashSet::const_iterator end = positionedObjects->end();
for (RenderBlock::PositionedObjectsListHashSet::const_iterator it = positionedObjects->begin(); it != end; ++it) {
RenderBox* renderBox = *it;
if (renderBox->style()->position() != FixedPosition)
continue;
IntRect updateRect = renderBox->layer()->repaintRectIncludingDescendants();
updateRect = contentsToWindow(updateRect);
if (clipsRepaints())
updateRect.intersect(rectToScroll);
if (!updateRect.isEmpty()) {
if (subRectToUpdate.size() >= fixedObjectThreshold) {
updateInvalidatedSubRect = false;
break;
}
subRectToUpdate.append(updateRect);
}
}
// Scroll the view
if (updateInvalidatedSubRect) {
// 1) scroll
hostWindow()->scroll(scrollDelta, rectToScroll, clipRect);
// 2) update the area of fixed objects that has been invalidated
size_t fixObjectsCount = subRectToUpdate.size();
for (size_t i = 0; i < fixObjectsCount; ++i) {
IntRect updateRect = subRectToUpdate[i];
IntRect scrolledRect = updateRect;
scrolledRect.move(scrollDelta);
updateRect.unite(scrolledRect);
if (clipsRepaints())
updateRect.intersect(rectToScroll);
hostWindow()->invalidateContentsAndWindow(updateRect, false);
}
return true;
}
// the number of fixed objects exceed the threshold, we cannot use the fast path
return false;
}
void FrameView::scrollContentsSlowPath(const IntRect& updateRect)
{
#if USE(ACCELERATED_COMPOSITING)
if (RenderPart* frameRenderer = m_frame->ownerRenderer()) {
if (frameRenderer->containerForRepaint()) {
IntRect rect(frameRenderer->borderLeft() + frameRenderer->paddingLeft(),
frameRenderer->borderTop() + frameRenderer->paddingTop(),
visibleWidth(), visibleHeight());
frameRenderer->repaintRectangle(rect);
return;
}
}
#endif
ScrollView::scrollContentsSlowPath(updateRect);
}
// Note that this gets called at painting time.
void FrameView::setIsOverlapped(bool isOverlapped)
{
if (isOverlapped == m_isOverlapped)
return;
m_isOverlapped = isOverlapped;
updateCanBlitOnScrollRecursively();
#if USE(ACCELERATED_COMPOSITING)
if (hasCompositedContentIncludingDescendants()) {
// Overlap can affect compositing tests, so if it changes, we need to trigger
// a layer update in the parent document.
if (Frame* parentFrame = m_frame->tree()->parent()) {
if (RenderView* parentView = parentFrame->contentRenderer()) {
RenderLayerCompositor* compositor = parentView->compositor();
compositor->setCompositingLayersNeedRebuild();
compositor->scheduleCompositingLayerUpdate();
}
}
if (RenderLayerCompositor::allowsIndependentlyCompositedFrames(this)) {
// We also need to trigger reevaluation for this and all descendant frames,
// since a frame uses compositing if any ancestor is compositing.
for (Frame* frame = m_frame.get(); frame; frame = frame->tree()->traverseNext(m_frame.get())) {
if (RenderView* view = frame->contentRenderer()) {
RenderLayerCompositor* compositor = view->compositor();
compositor->setCompositingLayersNeedRebuild();
compositor->scheduleCompositingLayerUpdate();
}
}
}
}
#endif
}
bool FrameView::isOverlappedIncludingAncestors() const
{
if (isOverlapped())
return true;
if (FrameView* parentView = parentFrameView()) {
if (parentView->isOverlapped())
return true;
}
return false;
}
void FrameView::setContentIsOpaque(bool contentIsOpaque)
{
if (contentIsOpaque == m_contentIsOpaque)
return;
m_contentIsOpaque = contentIsOpaque;
updateCanBlitOnScrollRecursively();
}
void FrameView::restoreScrollbar()
{
setScrollbarsSuppressed(false);
}
bool FrameView::scrollToFragment(const KURL& url)
{
// If our URL has no ref, then we have no place we need to jump to.
// OTOH If CSS target was set previously, we want to set it to 0, recalc
// and possibly repaint because :target pseudo class may have been
// set (see bug 11321).
if (!url.hasFragmentIdentifier() && !m_frame->document()->cssTarget())
return false;
String fragmentIdentifier = url.fragmentIdentifier();
if (scrollToAnchor(fragmentIdentifier))
return true;
// Try again after decoding the ref, based on the document's encoding.
if (TextResourceDecoder* decoder = m_frame->document()->decoder())
return scrollToAnchor(decodeURLEscapeSequences(fragmentIdentifier, decoder->encoding()));
return false;
}
bool FrameView::scrollToAnchor(const String& name)
{
ASSERT(m_frame->document());
if (!m_frame->document()->haveStylesheetsLoaded()) {
m_frame->document()->setGotoAnchorNeededAfterStylesheetsLoad(true);
return false;
}
m_frame->document()->setGotoAnchorNeededAfterStylesheetsLoad(false);
Element* anchorNode = m_frame->document()->findAnchor(name);
#if ENABLE(SVG)
if (m_frame->document()->isSVGDocument()) {
if (name.startsWith("xpointer(")) {
// We need to parse the xpointer reference here
} else if (name.startsWith("svgView(")) {
RefPtr<SVGSVGElement> svg = static_cast<SVGDocument*>(m_frame->document())->rootElement();
if (!svg->currentView()->parseViewSpec(name))
return false;
svg->setUseCurrentView(true);
} else {
if (anchorNode && anchorNode->hasTagName(SVGNames::viewTag)) {
RefPtr<SVGViewElement> viewElement = anchorNode->hasTagName(SVGNames::viewTag) ? static_cast<SVGViewElement*>(anchorNode) : 0;
if (viewElement.get()) {
SVGElement* element = SVGLocatable::nearestViewportElement(viewElement.get());
if (element->hasTagName(SVGNames::svgTag)) {
RefPtr<SVGSVGElement> svg = static_cast<SVGSVGElement*>(element);
svg->inheritViewAttributes(viewElement.get());
}
}
}
}
// FIXME: need to decide which <svg> to focus on, and zoom to that one
// FIXME: need to actually "highlight" the viewTarget(s)
}
#endif
m_frame->document()->setCSSTarget(anchorNode); // Setting to null will clear the current target.
// Implement the rule that "" and "top" both mean top of page as in other browsers.
if (!anchorNode && !(name.isEmpty() || equalIgnoringCase(name, "top")))
return false;
maintainScrollPositionAtAnchor(anchorNode ? static_cast<Node*>(anchorNode) : m_frame->document());
return true;
}
void FrameView::maintainScrollPositionAtAnchor(Node* anchorNode)
{
m_maintainScrollPositionAnchor = anchorNode;
if (!m_maintainScrollPositionAnchor)
return;
// We need to update the layout before scrolling, otherwise we could
// really mess things up if an anchor scroll comes at a bad moment.
m_frame->document()->updateStyleIfNeeded();
// Only do a layout if changes have occurred that make it necessary.
if (m_frame->contentRenderer() && m_frame->contentRenderer()->needsLayout())
layout();
else
scrollToAnchor();
}
void FrameView::setScrollPosition(const IntPoint& scrollPoint)
{
bool wasInProgrammaticScroll = m_inProgrammaticScroll;
m_inProgrammaticScroll = true;
m_maintainScrollPositionAnchor = 0;
ScrollView::setScrollPosition(scrollPoint);
m_inProgrammaticScroll = wasInProgrammaticScroll;
}
void FrameView::scrollPositionChangedViaPlatformWidget()
{
repaintFixedElementsAfterScrolling();
scrollPositionChanged();
}
void FrameView::scrollPositionChanged()
{
frame()->eventHandler()->sendScrollEvent();
#if USE(ACCELERATED_COMPOSITING)
if (RenderView* root = m_frame->contentRenderer()) {
if (root->usesCompositing())
root->compositor()->frameViewDidScroll(scrollPosition());
}
#endif
}
void FrameView::repaintFixedElementsAfterScrolling()
{
// For fixed position elements, update widget positions and compositing layers after scrolling,
// but only if we're not inside of layout.
if (!m_nestedLayoutCount && hasFixedObjects()) {
if (RenderView* root = m_frame->contentRenderer()) {
root->updateWidgetPositions();
root->layer()->updateRepaintRectsAfterScroll();
#if USE(ACCELERATED_COMPOSITING)
root->compositor()->updateCompositingLayers(CompositingUpdateOnScroll);
#endif
}
}
}
HostWindow* FrameView::hostWindow() const
{
Page* page = frame() ? frame()->page() : 0;
if (!page)
return 0;
return page->chrome();
}
const unsigned cRepaintRectUnionThreshold = 25;
void FrameView::repaintContentRectangle(const IntRect& r, bool immediate)
{
ASSERT(!m_frame->ownerElement());
double delay = m_deferringRepaints ? 0 : adjustedDeferredRepaintDelay();
if ((m_deferringRepaints || m_deferredRepaintTimer.isActive() || delay) && !immediate) {
IntRect paintRect = r;
if (clipsRepaints() && !paintsEntireContents())
paintRect.intersect(visibleContentRect());
if (paintRect.isEmpty())
return;
if (m_repaintCount == cRepaintRectUnionThreshold) {
IntRect unionedRect;
for (unsigned i = 0; i < cRepaintRectUnionThreshold; ++i)
unionedRect.unite(m_repaintRects[i]);
m_repaintRects.clear();
m_repaintRects.append(unionedRect);
}
if (m_repaintCount < cRepaintRectUnionThreshold)
m_repaintRects.append(paintRect);
else
m_repaintRects[0].unite(paintRect);
m_repaintCount++;
if (!m_deferringRepaints && !m_deferredRepaintTimer.isActive())
m_deferredRepaintTimer.startOneShot(delay);
return;
}
if (!shouldUpdate(immediate))
return;
#if ENABLE(TILED_BACKING_STORE)
if (frame()->tiledBackingStore()) {
frame()->tiledBackingStore()->invalidate(r);
return;
}
#endif
ScrollView::repaintContentRectangle(r, immediate);
}
void FrameView::contentsResized()
{
scrollAnimator()->contentsResized();
setNeedsLayout();
}
void FrameView::visibleContentsResized()
{
// We check to make sure the view is attached to a frame() as this method can
// be triggered before the view is attached by Frame::createView(...) setting
// various values such as setScrollBarModes(...) for example. An ASSERT is
// triggered when a view is layout before being attached to a frame().
if (!frame()->view())
return;
if (needsLayout())
layout();
#if USE(ACCELERATED_COMPOSITING)
if (RenderView* root = m_frame->contentRenderer()) {
if (root->usesCompositing())
root->compositor()->frameViewDidChangeSize();
}
#endif
}
void FrameView::beginDeferredRepaints()
{
Page* page = m_frame->page();
if (page->mainFrame() != m_frame)
return page->mainFrame()->view()->beginDeferredRepaints();
m_deferringRepaints++;
}
void FrameView::endDeferredRepaints()
{
Page* page = m_frame->page();
if (page->mainFrame() != m_frame)
return page->mainFrame()->view()->endDeferredRepaints();
ASSERT(m_deferringRepaints > 0);
if (--m_deferringRepaints)
return;
if (m_deferredRepaintTimer.isActive())
return;
if (double delay = adjustedDeferredRepaintDelay()) {
m_deferredRepaintTimer.startOneShot(delay);
return;
}
doDeferredRepaints();
}
void FrameView::checkStopDelayingDeferredRepaints()
{
if (!m_deferredRepaintTimer.isActive())
return;
Document* document = m_frame->document();
if (document && (document->parsing() || document->cachedResourceLoader()->requestCount()))
return;
m_deferredRepaintTimer.stop();
doDeferredRepaints();
}
void FrameView::doDeferredRepaints()
{
ASSERT(!m_deferringRepaints);
if (!shouldUpdate()) {
m_repaintRects.clear();
m_repaintCount = 0;
return;
}
unsigned size = m_repaintRects.size();
for (unsigned i = 0; i < size; i++) {
#if ENABLE(TILED_BACKING_STORE)
if (frame()->tiledBackingStore()) {
frame()->tiledBackingStore()->invalidate(m_repaintRects[i]);
continue;
}
#endif
ScrollView::repaintContentRectangle(m_repaintRects[i], false);
}
m_repaintRects.clear();
m_repaintCount = 0;
updateDeferredRepaintDelay();
}
void FrameView::updateDeferredRepaintDelay()
{
Document* document = m_frame->document();
if (!document || (!document->parsing() && !document->cachedResourceLoader()->requestCount())) {
m_deferredRepaintDelay = s_deferredRepaintDelay;
return;
}
if (m_deferredRepaintDelay < s_maxDeferredRepaintDelayDuringLoading) {
m_deferredRepaintDelay += s_deferredRepaintDelayIncrementDuringLoading;
if (m_deferredRepaintDelay > s_maxDeferredRepaintDelayDuringLoading)
m_deferredRepaintDelay = s_maxDeferredRepaintDelayDuringLoading;
}
}
void FrameView::resetDeferredRepaintDelay()
{
m_deferredRepaintDelay = 0;
if (m_deferredRepaintTimer.isActive()) {
m_deferredRepaintTimer.stop();
if (!m_deferringRepaints)
doDeferredRepaints();
}
}
double FrameView::adjustedDeferredRepaintDelay() const
{
ASSERT(!m_deferringRepaints);
if (!m_deferredRepaintDelay)
return 0;
double timeSinceLastPaint = currentTime() - m_lastPaintTime;
return max(0., m_deferredRepaintDelay - timeSinceLastPaint);
}
void FrameView::deferredRepaintTimerFired(Timer<FrameView>*)
{
doDeferredRepaints();
}
void FrameView::layoutTimerFired(Timer<FrameView>*)
{
#ifdef INSTRUMENT_LAYOUT_SCHEDULING
if (!m_frame->document()->ownerElement())
printf("Layout timer fired at %d\n", m_frame->document()->elapsedTime());
#endif
layout();
}
void FrameView::scheduleRelayout()
{
// FIXME: We should assert the page is not in the page cache, but that is causing
// too many false assertions. See <rdar://problem/7218118>.
ASSERT(m_frame->view() == this);
if (m_layoutRoot) {
m_layoutRoot->markContainingBlocksForLayout(false);
m_layoutRoot = 0;
}
if (!m_layoutSchedulingEnabled)
return;
if (!needsLayout())
return;
if (!m_frame->document()->shouldScheduleLayout())
return;
// When frame flattening is enabled, the contents of the frame affects layout of the parent frames.
// Also invalidate parent frame starting from the owner element of this frame.
if (m_frame->settings() && m_frame->settings()->frameFlatteningEnabled() && m_frame->ownerRenderer()) {
if (m_frame->ownerElement()->hasTagName(iframeTag) || m_frame->ownerElement()->hasTagName(frameTag))
m_frame->ownerRenderer()->setNeedsLayout(true, true);
}
int delay = m_frame->document()->minimumLayoutDelay();
if (m_layoutTimer.isActive() && m_delayedLayout && !delay)
unscheduleRelayout();
if (m_layoutTimer.isActive())
return;
m_delayedLayout = delay != 0;
#ifdef INSTRUMENT_LAYOUT_SCHEDULING
if (!m_frame->document()->ownerElement())
printf("Scheduling layout for %d\n", delay);
#endif
m_layoutTimer.startOneShot(delay * 0.001);
}
static bool isObjectAncestorContainerOf(RenderObject* ancestor, RenderObject* descendant)
{
for (RenderObject* r = descendant; r; r = r->container()) {
if (r == ancestor)
return true;
}
return false;
}
void FrameView::scheduleRelayoutOfSubtree(RenderObject* relayoutRoot)
{
ASSERT(m_frame->view() == this);
if (m_frame->contentRenderer() && m_frame->contentRenderer()->needsLayout()) {
if (relayoutRoot)
relayoutRoot->markContainingBlocksForLayout(false);
return;
}
if (layoutPending() || !m_layoutSchedulingEnabled) {
if (m_layoutRoot != relayoutRoot) {
if (isObjectAncestorContainerOf(m_layoutRoot, relayoutRoot)) {
// Keep the current root
relayoutRoot->markContainingBlocksForLayout(false, m_layoutRoot);
ASSERT(!m_layoutRoot->container() || !m_layoutRoot->container()->needsLayout());
} else if (m_layoutRoot && isObjectAncestorContainerOf(relayoutRoot, m_layoutRoot)) {
// Re-root at relayoutRoot
m_layoutRoot->markContainingBlocksForLayout(false, relayoutRoot);
m_layoutRoot = relayoutRoot;
ASSERT(!m_layoutRoot->container() || !m_layoutRoot->container()->needsLayout());
} else {
// Just do a full relayout
if (m_layoutRoot)
m_layoutRoot->markContainingBlocksForLayout(false);
m_layoutRoot = 0;
relayoutRoot->markContainingBlocksForLayout(false);
}
}
} else if (m_layoutSchedulingEnabled) {
int delay = m_frame->document()->minimumLayoutDelay();
m_layoutRoot = relayoutRoot;
ASSERT(!m_layoutRoot->container() || !m_layoutRoot->container()->needsLayout());
m_delayedLayout = delay != 0;
m_layoutTimer.startOneShot(delay * 0.001);
}
}
bool FrameView::layoutPending() const
{
return m_layoutTimer.isActive();
}
bool FrameView::needsLayout() const
{
// This can return true in cases where the document does not have a body yet.
// Document::shouldScheduleLayout takes care of preventing us from scheduling
// layout in that case.
if (!m_frame)
return false;
RenderView* root = m_frame->contentRenderer();
return layoutPending()
|| (root && root->needsLayout())
|| m_layoutRoot
|| (m_deferSetNeedsLayouts && m_setNeedsLayoutWasDeferred);
}
void FrameView::setNeedsLayout()
{
if (m_deferSetNeedsLayouts) {
m_setNeedsLayoutWasDeferred = true;
return;
}
RenderView* root = m_frame->contentRenderer();
if (root)
root->setNeedsLayout(true);
}
void FrameView::unscheduleRelayout()
{
m_postLayoutTasksTimer.stop();
if (!m_layoutTimer.isActive())
return;
#ifdef INSTRUMENT_LAYOUT_SCHEDULING
if (!m_frame->document()->ownerElement())
printf("Layout timer unscheduled at %d\n", m_frame->document()->elapsedTime());
#endif
m_layoutTimer.stop();
m_delayedLayout = false;
}
#if ENABLE(REQUEST_ANIMATION_FRAME)
void FrameView::serviceScriptedAnimations(DOMTimeStamp time)
{
for (Frame* frame = m_frame.get(); frame; frame = frame->tree()->traverseNext())
frame->document()->serviceScriptedAnimations(time);
}
#endif
bool FrameView::isTransparent() const
{
return m_isTransparent;
}
void FrameView::setTransparent(bool isTransparent)
{
m_isTransparent = isTransparent;
}
Color FrameView::baseBackgroundColor() const
{
return m_baseBackgroundColor;
}
void FrameView::setBaseBackgroundColor(const Color& backgroundColor)
{
if (!backgroundColor.isValid())
m_baseBackgroundColor = Color::white;
else
m_baseBackgroundColor = backgroundColor;
}
void FrameView::updateBackgroundRecursively(const Color& backgroundColor, bool transparent)
{
for (Frame* frame = m_frame.get(); frame; frame = frame->tree()->traverseNext(m_frame.get())) {
if (FrameView* view = frame->view()) {
view->setTransparent(transparent);
view->setBaseBackgroundColor(backgroundColor);
}
}
}
bool FrameView::shouldUpdateWhileOffscreen() const
{
return m_shouldUpdateWhileOffscreen;
}
void FrameView::setShouldUpdateWhileOffscreen(bool shouldUpdateWhileOffscreen)
{
m_shouldUpdateWhileOffscreen = shouldUpdateWhileOffscreen;
}
bool FrameView::shouldUpdate(bool immediateRequested) const
{
if (!immediateRequested && isOffscreen() && !shouldUpdateWhileOffscreen())
return false;
return true;
}
void FrameView::scheduleEvent(PassRefPtr<Event> event, PassRefPtr<Node> eventTarget)
{
m_actionScheduler->scheduleEvent(event, eventTarget);
}
void FrameView::pauseScheduledEvents()
{
m_actionScheduler->pause();
}
void FrameView::resumeScheduledEvents()
{
m_actionScheduler->resume();
}
void FrameView::scrollToAnchor()
{
RefPtr<Node> anchorNode = m_maintainScrollPositionAnchor;
if (!anchorNode)
return;
if (!anchorNode->renderer())
return;
IntRect rect;
if (anchorNode != m_frame->document())
rect = anchorNode->getRect();
// Scroll nested layers and frames to reveal the anchor.
// Align to the top and to the closest side (this matches other browsers).
anchorNode->renderer()->enclosingLayer()->scrollRectToVisible(rect, true, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignTopAlways);
if (AXObjectCache::accessibilityEnabled())
m_frame->document()->axObjectCache()->handleScrolledToAnchor(anchorNode.get());
// scrollRectToVisible can call into setScrollPosition(), which resets m_maintainScrollPositionAnchor.
m_maintainScrollPositionAnchor = anchorNode;
}
void FrameView::updateWidget(RenderEmbeddedObject* object)
{
ASSERT(!object->node() || object->node()->isElementNode());
Element* ownerElement = static_cast<Element*>(object->node());
// The object may have already been destroyed (thus node cleared),
// but FrameView holds a manual ref, so it won't have been deleted.
ASSERT(m_widgetUpdateSet->contains(object));
if (!ownerElement)
return;
// No need to update if it's already crashed or known to be missing.
if (object->pluginCrashedOrWasMissing())
return;
// FIXME: This could turn into a real virtual dispatch if we defined
// updateWidget(bool) on HTMLElement.
if (ownerElement->hasTagName(objectTag) || ownerElement->hasTagName(embedTag))
static_cast<HTMLPlugInImageElement*>(ownerElement)->updateWidget(CreateAnyWidgetType);
// FIXME: It is not clear that Media elements need or want this updateWidget() call.
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
else if (ownerElement->isMediaElement())
static_cast<HTMLMediaElement*>(ownerElement)->updateWidget(CreateAnyWidgetType);
#endif
else
ASSERT_NOT_REACHED();
// Caution: it's possible the object was destroyed again, since loading a
// plugin may run any arbitrary javascript.
object->updateWidgetPosition();
}
bool FrameView::updateWidgets()
{
if (m_nestedLayoutCount > 1 || !m_widgetUpdateSet || m_widgetUpdateSet->isEmpty())
return true;
size_t size = m_widgetUpdateSet->size();
Vector<RenderEmbeddedObject*> objects;
objects.reserveCapacity(size);
RenderEmbeddedObjectSet::const_iterator end = m_widgetUpdateSet->end();
for (RenderEmbeddedObjectSet::const_iterator it = m_widgetUpdateSet->begin(); it != end; ++it) {
objects.uncheckedAppend(*it);
(*it)->ref();
}
for (size_t i = 0; i < size; ++i) {
RenderEmbeddedObject* object = objects[i];
updateWidget(object);
m_widgetUpdateSet->remove(object);
}
RenderArena* arena = m_frame->document()->renderArena();
for (size_t i = 0; i < size; ++i)
objects[i]->deref(arena);
return m_widgetUpdateSet->isEmpty();
}
void FrameView::flushAnyPendingPostLayoutTasks()
{
if (!m_hasPendingPostLayoutTasks)
return;
m_postLayoutTasksTimer.stop();
performPostLayoutTasks();
}
void FrameView::performPostLayoutTasks()
{
m_hasPendingPostLayoutTasks = false;
m_frame->selection()->setCaretRectNeedsUpdate();
m_frame->selection()->updateAppearance();
if (m_nestedLayoutCount <= 1) {
if (m_firstLayoutCallbackPending) {
m_firstLayoutCallbackPending = false;
m_frame->loader()->didFirstLayout();
}
if (m_isVisuallyNonEmpty && m_firstVisuallyNonEmptyLayoutCallbackPending) {
m_firstVisuallyNonEmptyLayoutCallbackPending = false;
m_frame->loader()->didFirstVisuallyNonEmptyLayout();
}
}
RenderView* root = m_frame->contentRenderer();
root->updateWidgetPositions();
for (unsigned i = 0; i < maxUpdateWidgetsIterations; i++) {
if (updateWidgets())
break;
}
scrollToAnchor();
m_actionScheduler->resume();
if (!root->printing()) {
IntSize currentSize = IntSize(width(), height());
float currentZoomFactor = root->style()->zoom();
bool resized = !m_firstLayout && (currentSize != m_lastLayoutSize || currentZoomFactor != m_lastZoomFactor);
m_lastLayoutSize = currentSize;
m_lastZoomFactor = currentZoomFactor;
if (resized)
m_frame->eventHandler()->sendResizeEvent();
}
}
void FrameView::postLayoutTimerFired(Timer<FrameView>*)
{
performPostLayoutTasks();
}
void FrameView::updateOverflowStatus(bool horizontalOverflow, bool verticalOverflow)
{
if (!m_viewportRenderer)
return;
if (m_overflowStatusDirty) {
m_horizontalOverflow = horizontalOverflow;
m_verticalOverflow = verticalOverflow;
m_overflowStatusDirty = false;
return;
}
bool horizontalOverflowChanged = (m_horizontalOverflow != horizontalOverflow);
bool verticalOverflowChanged = (m_verticalOverflow != verticalOverflow);
if (horizontalOverflowChanged || verticalOverflowChanged) {
m_horizontalOverflow = horizontalOverflow;
m_verticalOverflow = verticalOverflow;
m_actionScheduler->scheduleEvent(OverflowEvent::create(horizontalOverflowChanged, horizontalOverflow,
verticalOverflowChanged, verticalOverflow),
m_viewportRenderer->node());
}
}
IntRect FrameView::windowClipRect(bool clipToContents) const
{
ASSERT(m_frame->view() == this);
if (paintsEntireContents())
return IntRect(IntPoint(0, 0), contentsSize());
// Set our clip rect to be our contents.
IntRect clipRect = contentsToWindow(visibleContentRect(!clipToContents));
if (!m_frame || !m_frame->ownerElement())
return clipRect;
// Take our owner element and get the clip rect from the enclosing layer.
Element* elt = m_frame->ownerElement();
// The renderer can sometimes be null when style="display:none" interacts
// with external content and plugins.
RenderLayer* layer = elt->renderer() ? elt->renderer()->enclosingLayer() : 0;
if (!layer)
return clipRect;
FrameView* parentView = elt->document()->view();
clipRect.intersect(parentView->windowClipRectForLayer(layer, true));
return clipRect;
}
IntRect FrameView::windowClipRectForLayer(const RenderLayer* layer, bool clipToLayerContents) const
{
// If we have no layer, just return our window clip rect.
if (!layer)
return windowClipRect();
// Apply the clip from the layer.
IntRect clipRect;
if (clipToLayerContents)
clipRect = layer->childrenClipRect();
else
clipRect = layer->selfClipRect();
clipRect = contentsToWindow(clipRect);
return intersection(clipRect, windowClipRect());
}
bool FrameView::isActive() const
{
Page* page = frame()->page();
return page && page->focusController()->isActive();
}
void FrameView::scrollTo(const IntSize& newOffset)
{
IntSize offset = scrollOffset();
ScrollView::scrollTo(newOffset);
if (offset != scrollOffset())
scrollPositionChanged();
frame()->loader()->client()->didChangeScrollOffset();
}
void FrameView::invalidateScrollbarRect(Scrollbar* scrollbar, const IntRect& rect)
{
// Add in our offset within the FrameView.
IntRect dirtyRect = rect;
dirtyRect.move(scrollbar->x(), scrollbar->y());
invalidateRect(dirtyRect);
}
void FrameView::getTickmarks(Vector<IntRect>& tickmarks) const
{
tickmarks = frame()->document()->markers()->renderedRectsForMarkers(DocumentMarker::TextMatch);
}
IntRect FrameView::windowResizerRect() const
{
Page* page = frame() ? frame()->page() : 0;
if (!page)
return IntRect();
return page->chrome()->windowResizerRect();
}
void FrameView::didCompleteRubberBand(const IntSize& initialOverhang) const
{
Page* page = m_frame->page();
if (!page)
return;
if (page->mainFrame() != m_frame)
return;
return page->chrome()->client()->didCompleteRubberBandForMainFrame(initialOverhang);
}
void FrameView::scrollbarStyleChanged()
{
Page* page = m_frame->page();
if (!page)
return;
page->setNeedsRecalcStyleInAllFrames();
}
void FrameView::setVisibleScrollerThumbRect(const IntRect& scrollerThumb)
{
Page* page = m_frame->page();
if (!page)
return;
if (page->mainFrame() != m_frame)
return;
return page->chrome()->client()->notifyScrollerThumbIsVisibleInRect(scrollerThumb);
}
bool FrameView::shouldSuspendScrollAnimations() const
{
return m_frame->loader()->state() != FrameStateComplete;
}
void FrameView::notifyPageThatContentAreaWillPaint() const
{
Page* page = m_frame->page();
const HashSet<ScrollableArea*>* scrollableAreas = page->scrollableAreaSet();
if (!scrollableAreas)
return;
HashSet<ScrollableArea*>::const_iterator end = scrollableAreas->end();
for (HashSet<ScrollableArea*>::const_iterator it = scrollableAreas->begin(); it != end; ++it)
(*it)->scrollAnimator()->contentAreaWillPaint();
}
#if ENABLE(DASHBOARD_SUPPORT)
void FrameView::updateDashboardRegions()
{
Document* document = m_frame->document();
if (!document->hasDashboardRegions())
return;
Vector<DashboardRegionValue> newRegions;
document->renderBox()->collectDashboardRegions(newRegions);
if (newRegions == document->dashboardRegions())
return;
document->setDashboardRegions(newRegions);
Page* page = m_frame->page();
if (!page)
return;
page->chrome()->client()->dashboardRegionsChanged();
}
#endif
void FrameView::updateScrollCorner()
{
RenderObject* renderer = 0;
RefPtr<RenderStyle> cornerStyle;
if (!scrollCornerRect().isEmpty()) {
// Try the <body> element first as a scroll corner source.
Document* doc = m_frame->document();
Element* body = doc ? doc->body() : 0;
if (body && body->renderer()) {
renderer = body->renderer();
cornerStyle = renderer->getUncachedPseudoStyle(SCROLLBAR_CORNER, renderer->style());
}
if (!cornerStyle) {
// If the <body> didn't have a custom style, then the root element might.
Element* docElement = doc ? doc->documentElement() : 0;
if (docElement && docElement->renderer()) {
renderer = docElement->renderer();
cornerStyle = renderer->getUncachedPseudoStyle(SCROLLBAR_CORNER, renderer->style());
}
}
if (!cornerStyle) {
// If we have an owning iframe/frame element, then it can set the custom scrollbar also.
if (RenderPart* renderer = m_frame->ownerRenderer())
cornerStyle = renderer->getUncachedPseudoStyle(SCROLLBAR_CORNER, renderer->style());
}
}
if (cornerStyle) {
if (!m_scrollCorner)
m_scrollCorner = new (renderer->renderArena()) RenderScrollbarPart(renderer->document());
m_scrollCorner->setStyle(cornerStyle.release());
invalidateScrollCorner();
} else if (m_scrollCorner) {
m_scrollCorner->destroy();
m_scrollCorner = 0;
}
ScrollView::updateScrollCorner();
}
void FrameView::paintScrollCorner(GraphicsContext* context, const IntRect& cornerRect)
{
if (context->updatingControlTints()) {
updateScrollCorner();
return;
}
if (m_scrollCorner) {
m_scrollCorner->paintIntoRect(context, cornerRect.x(), cornerRect.y(), cornerRect);
return;
}
ScrollView::paintScrollCorner(context, cornerRect);
}
bool FrameView::hasCustomScrollbars() const
{
const HashSet<RefPtr<Widget> >* viewChildren = children();
HashSet<RefPtr<Widget> >::const_iterator end = viewChildren->end();
for (HashSet<RefPtr<Widget> >::const_iterator current = viewChildren->begin(); current != end; ++current) {
Widget* widget = current->get();
if (widget->isFrameView()) {
if (static_cast<FrameView*>(widget)->hasCustomScrollbars())
return true;
} else if (widget->isScrollbar()) {
Scrollbar* scrollbar = static_cast<Scrollbar*>(widget);
if (scrollbar->isCustomScrollbar())
return true;
}
}
return false;
}
void FrameView::clearOwningRendererForCustomScrollbars(RenderBox* box)
{
const HashSet<RefPtr<Widget> >* viewChildren = children();
HashSet<RefPtr<Widget> >::const_iterator end = viewChildren->end();
for (HashSet<RefPtr<Widget> >::const_iterator current = viewChildren->begin(); current != end; ++current) {
Widget* widget = current->get();
if (widget->isScrollbar()) {
Scrollbar* scrollbar = static_cast<Scrollbar*>(widget);
if (scrollbar->isCustomScrollbar()) {
RenderScrollbar* customScrollbar = toRenderScrollbar(scrollbar);
if (customScrollbar->owningRenderer() == box)
customScrollbar->clearOwningRenderer();
}
}
}
}
FrameView* FrameView::parentFrameView() const
{
if (Widget* parentView = parent()) {
if (parentView->isFrameView())
return static_cast<FrameView*>(parentView);
}
return 0;
}
void FrameView::updateControlTints()
{
// This is called when control tints are changed from aqua/graphite to clear and vice versa.
// We do a "fake" paint, and when the theme gets a paint call, it can then do an invalidate.
// This is only done if the theme supports control tinting. It's up to the theme and platform
// to define when controls get the tint and to call this function when that changes.
// Optimize the common case where we bring a window to the front while it's still empty.
if (!m_frame || m_frame->document()->url().isEmpty())
return;
if ((m_frame->contentRenderer() && m_frame->contentRenderer()->theme()->supportsControlTints()) || hasCustomScrollbars()) {
if (needsLayout())
layout();
PlatformGraphicsContext* const noContext = 0;
GraphicsContext context(noContext);
context.setUpdatingControlTints(true);
if (platformWidget())
paintContents(&context, visibleContentRect());
else
paint(&context, frameRect());
}
}
bool FrameView::wasScrolledByUser() const
{
return m_wasScrolledByUser;
}
void FrameView::setWasScrolledByUser(bool wasScrolledByUser)
{
if (m_inProgrammaticScroll)
return;
m_maintainScrollPositionAnchor = 0;
m_wasScrolledByUser = wasScrolledByUser;
}
void FrameView::paintContents(GraphicsContext* p, const IntRect& rect)
{
if (!frame())
return;
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willPaint(m_frame.get(), rect);
Document* document = m_frame->document();
#ifndef NDEBUG
bool fillWithRed;
if (document->printing())
fillWithRed = false; // Printing, don't fill with red (can't remember why).
else if (m_frame->ownerElement())
fillWithRed = false; // Subframe, don't fill with red.
else if (isTransparent())
fillWithRed = false; // Transparent, don't fill with red.
else if (m_paintBehavior & PaintBehaviorSelectionOnly)
fillWithRed = false; // Selections are transparent, don't fill with red.
else if (m_nodeToDraw)
fillWithRed = false; // Element images are transparent, don't fill with red.
else
fillWithRed = true;
if (fillWithRed)
p->fillRect(rect, Color(0xFF, 0, 0), ColorSpaceDeviceRGB);
#endif
bool isTopLevelPainter = !sCurrentPaintTimeStamp;
if (isTopLevelPainter)
sCurrentPaintTimeStamp = currentTime();
RenderView* contentRenderer = frame()->contentRenderer();
if (!contentRenderer) {
LOG_ERROR("called FrameView::paint with nil renderer");
return;
}
ASSERT(!needsLayout());
if (needsLayout())
return;
#if USE(ACCELERATED_COMPOSITING)
if (!p->paintingDisabled())
syncCompositingStateForThisFrame();
#endif
PaintBehavior oldPaintBehavior = m_paintBehavior;
if (FrameView* parentView = parentFrameView()) {
if (parentView->paintBehavior() & PaintBehaviorFlattenCompositingLayers)
m_paintBehavior |= PaintBehaviorFlattenCompositingLayers;
}
if (m_paintBehavior == PaintBehaviorNormal)
document->markers()->invalidateRenderedRectsForMarkersInRect(rect);
if (document->printing())
m_paintBehavior |= PaintBehaviorFlattenCompositingLayers;
bool flatteningPaint = m_paintBehavior & PaintBehaviorFlattenCompositingLayers;
bool isRootFrame = !m_frame->ownerElement();
if (flatteningPaint && isRootFrame)
notifyWidgetsInAllFrames(WillPaintFlattened);
ASSERT(!m_isPainting);
m_isPainting = true;
// m_nodeToDraw is used to draw only one element (and its descendants)
RenderObject* eltRenderer = m_nodeToDraw ? m_nodeToDraw->renderer() : 0;
RenderLayer* rootLayer = contentRenderer->layer();
rootLayer->paint(p, rect, m_paintBehavior, eltRenderer);
if (rootLayer->containsDirtyOverlayScrollbars())
rootLayer->paintOverlayScrollbars(p, rect, m_paintBehavior, eltRenderer);
m_isPainting = false;
if (flatteningPaint && isRootFrame)
notifyWidgetsInAllFrames(DidPaintFlattened);
m_paintBehavior = oldPaintBehavior;
m_lastPaintTime = currentTime();
#if ENABLE(DASHBOARD_SUPPORT)
// Regions may have changed as a result of the visibility/z-index of element changing.
if (document->dashboardRegionsDirty())
updateDashboardRegions();
#endif
if (isTopLevelPainter)
sCurrentPaintTimeStamp = 0;
InspectorInstrumentation::didPaint(cookie);
}
void FrameView::setPaintBehavior(PaintBehavior behavior)
{
m_paintBehavior = behavior;
}
PaintBehavior FrameView::paintBehavior() const
{
return m_paintBehavior;
}
bool FrameView::isPainting() const
{
return m_isPainting;
}
void FrameView::setNodeToDraw(Node* node)
{
m_nodeToDraw = node;
}
void FrameView::paintOverhangAreas(GraphicsContext* context, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect)
{
if (context->paintingDisabled())
return;
if (m_frame->document()->printing())
return;
Page* page = m_frame->page();
if (page->mainFrame() == m_frame) {
if (page->chrome()->client()->paintCustomOverhangArea(context, horizontalOverhangArea, verticalOverhangArea, dirtyRect))
return;
}
return ScrollView::paintOverhangAreas(context, horizontalOverhangArea, verticalOverhangArea, dirtyRect);
}
void FrameView::updateLayoutAndStyleIfNeededRecursive()
{
// We have to crawl our entire tree looking for any FrameViews that need
// layout and make sure they are up to date.
// Mac actually tests for intersection with the dirty region and tries not to
// update layout for frames that are outside the dirty region. Not only does this seem
// pointless (since those frames will have set a zero timer to layout anyway), but
// it is also incorrect, since if two frames overlap, the first could be excluded from the dirty
// region but then become included later by the second frame adding rects to the dirty region
// when it lays out.
m_frame->document()->updateStyleIfNeeded();
if (needsLayout())
layout();
const HashSet<RefPtr<Widget> >* viewChildren = children();
HashSet<RefPtr<Widget> >::const_iterator end = viewChildren->end();
for (HashSet<RefPtr<Widget> >::const_iterator current = viewChildren->begin(); current != end; ++current) {
Widget* widget = (*current).get();
if (widget->isFrameView())
static_cast<FrameView*>(widget)->updateLayoutAndStyleIfNeededRecursive();
}
// updateLayoutAndStyleIfNeededRecursive is called when we need to make sure style and layout are up-to-date before
// painting, so we need to flush out any deferred repaints too.
flushDeferredRepaints();
}
void FrameView::flushDeferredRepaints()
{
if (!m_deferredRepaintTimer.isActive())
return;
m_deferredRepaintTimer.stop();
doDeferredRepaints();
}
void FrameView::forceLayout(bool allowSubtree)
{
layout(allowSubtree);
}
void FrameView::forceLayoutForPagination(const FloatSize& pageSize, float maximumShrinkFactor, Frame::AdjustViewSizeOrNot shouldAdjustViewSize)
{
// Dumping externalRepresentation(m_frame->renderer()).ascii() is a good trick to see
// the state of things before and after the layout
RenderView *root = toRenderView(m_frame->document()->renderer());
if (root) {
float pageLogicalWidth = root->style()->isHorizontalWritingMode() ? pageSize.width() : pageSize.height();
float pageLogicalHeight = root->style()->isHorizontalWritingMode() ? pageSize.height() : pageSize.width();
int flooredPageLogicalWidth = static_cast<int>(pageLogicalWidth);
root->setLogicalWidth(flooredPageLogicalWidth);
root->setPageLogicalHeight(pageLogicalHeight);
root->setNeedsLayoutAndPrefWidthsRecalc();
forceLayout();
// If we don't fit in the given page width, we'll lay out again. If we don't fit in the
// page width when shrunk, we will lay out at maximum shrink and clip extra content.
// FIXME: We are assuming a shrink-to-fit printing implementation. A cropping
// implementation should not do this!
int docLogicalWidth = root->style()->isHorizontalWritingMode() ? root->docWidth() : root->docHeight();
if (docLogicalWidth > pageLogicalWidth) {
flooredPageLogicalWidth = std::min<int>(docLogicalWidth, pageLogicalWidth * maximumShrinkFactor);
if (pageLogicalHeight)
root->setPageLogicalHeight(flooredPageLogicalWidth / pageSize.width() * pageSize.height());
root->setLogicalWidth(flooredPageLogicalWidth);
root->setNeedsLayoutAndPrefWidthsRecalc();
forceLayout();
int docLogicalHeight = root->style()->isHorizontalWritingMode() ? root->docHeight() : root->docWidth();
int docLogicalTop = root->style()->isHorizontalWritingMode() ? root->docTop() : root->docLeft();
int docLogicalRight = root->style()->isHorizontalWritingMode() ? root->docRight() : root->docBottom();
int clippedLogicalLeft = 0;
if (!root->style()->isLeftToRightDirection())
clippedLogicalLeft = docLogicalRight - flooredPageLogicalWidth;
IntRect overflow(clippedLogicalLeft, docLogicalTop, flooredPageLogicalWidth, docLogicalHeight);
if (!root->style()->isHorizontalWritingMode())
overflow = overflow.transposedRect();
root->clearLayoutOverflow();
root->addLayoutOverflow(overflow); // This is how we clip in case we overflow again.
}
}
if (shouldAdjustViewSize)
adjustViewSize();
}
void FrameView::adjustPageHeightDeprecated(float *newBottom, float oldTop, float oldBottom, float /*bottomLimit*/)
{
RenderView* root = m_frame->contentRenderer();
if (root) {
// Use a context with painting disabled.
GraphicsContext context((PlatformGraphicsContext*)0);
root->setTruncatedAt((int)floorf(oldBottom));
IntRect dirtyRect(0, (int)floorf(oldTop), root->maxXLayoutOverflow(), (int)ceilf(oldBottom - oldTop));
root->setPrintRect(dirtyRect);
root->layer()->paint(&context, dirtyRect);
*newBottom = root->bestTruncatedAt();
if (*newBottom == 0)
*newBottom = oldBottom;
root->setPrintRect(IntRect());
} else
*newBottom = oldBottom;
}
IntRect FrameView::convertFromRenderer(const RenderObject* renderer, const IntRect& rendererRect) const
{
IntRect rect = renderer->localToAbsoluteQuad(FloatRect(rendererRect)).enclosingBoundingBox();
// Convert from page ("absolute") to FrameView coordinates.
rect.move(-scrollX(), -scrollY());
return rect;
}
IntRect FrameView::convertToRenderer(const RenderObject* renderer, const IntRect& viewRect) const
{
IntRect rect = viewRect;
// Convert from FrameView coords into page ("absolute") coordinates.
rect.move(scrollX(), scrollY());
// FIXME: we don't have a way to map an absolute rect down to a local quad, so just
// move the rect for now.
rect.setLocation(roundedIntPoint(renderer->absoluteToLocal(rect.location(), false, true /* use transforms */)));
return rect;
}
IntPoint FrameView::convertFromRenderer(const RenderObject* renderer, const IntPoint& rendererPoint) const
{
IntPoint point = roundedIntPoint(renderer->localToAbsolute(rendererPoint, false, true /* use transforms */));
// Convert from page ("absolute") to FrameView coordinates.
point.move(-scrollX(), -scrollY());
return point;
}
IntPoint FrameView::convertToRenderer(const RenderObject* renderer, const IntPoint& viewPoint) const
{
IntPoint point = viewPoint;
// Convert from FrameView coords into page ("absolute") coordinates.
point += IntSize(scrollX(), scrollY());
return roundedIntPoint(renderer->absoluteToLocal(point, false, true /* use transforms */));
}
IntRect FrameView::convertToContainingView(const IntRect& localRect) const
{
if (const ScrollView* parentScrollView = parent()) {
if (parentScrollView->isFrameView()) {
const FrameView* parentView = static_cast<const FrameView*>(parentScrollView);
// Get our renderer in the parent view
RenderPart* renderer = m_frame->ownerRenderer();
if (!renderer)
return localRect;
IntRect rect(localRect);
// Add borders and padding??
rect.move(renderer->borderLeft() + renderer->paddingLeft(),
renderer->borderTop() + renderer->paddingTop());
return parentView->convertFromRenderer(renderer, rect);
}
return Widget::convertToContainingView(localRect);
}
return localRect;
}
IntRect FrameView::convertFromContainingView(const IntRect& parentRect) const
{
if (const ScrollView* parentScrollView = parent()) {
if (parentScrollView->isFrameView()) {
const FrameView* parentView = static_cast<const FrameView*>(parentScrollView);
// Get our renderer in the parent view
RenderPart* renderer = m_frame->ownerRenderer();
if (!renderer)
return parentRect;
IntRect rect = parentView->convertToRenderer(renderer, parentRect);
// Subtract borders and padding
rect.move(-renderer->borderLeft() - renderer->paddingLeft(),
-renderer->borderTop() - renderer->paddingTop());
return rect;
}
return Widget::convertFromContainingView(parentRect);
}
return parentRect;
}
IntPoint FrameView::convertToContainingView(const IntPoint& localPoint) const
{
if (const ScrollView* parentScrollView = parent()) {
if (parentScrollView->isFrameView()) {
const FrameView* parentView = static_cast<const FrameView*>(parentScrollView);
// Get our renderer in the parent view
RenderPart* renderer = m_frame->ownerRenderer();
if (!renderer)
return localPoint;
IntPoint point(localPoint);
// Add borders and padding
point.move(renderer->borderLeft() + renderer->paddingLeft(),
renderer->borderTop() + renderer->paddingTop());
return parentView->convertFromRenderer(renderer, point);
}
return Widget::convertToContainingView(localPoint);
}
return localPoint;
}
IntPoint FrameView::convertFromContainingView(const IntPoint& parentPoint) const
{
if (const ScrollView* parentScrollView = parent()) {
if (parentScrollView->isFrameView()) {
const FrameView* parentView = static_cast<const FrameView*>(parentScrollView);
// Get our renderer in the parent view
RenderPart* renderer = m_frame->ownerRenderer();
if (!renderer)
return parentPoint;
IntPoint point = parentView->convertToRenderer(renderer, parentPoint);
// Subtract borders and padding
point.move(-renderer->borderLeft() - renderer->paddingLeft(),
-renderer->borderTop() - renderer->paddingTop());
return point;
}
return Widget::convertFromContainingView(parentPoint);
}
return parentPoint;
}
// Normal delay
void FrameView::setRepaintThrottlingDeferredRepaintDelay(double p)
{
s_deferredRepaintDelay = p;
}
// Negative value would mean that first few repaints happen without a delay
void FrameView::setRepaintThrottlingnInitialDeferredRepaintDelayDuringLoading(double p)
{
s_initialDeferredRepaintDelayDuringLoading = p;
}
// The delay grows on each repaint to this maximum value
void FrameView::setRepaintThrottlingMaxDeferredRepaintDelayDuringLoading(double p)
{
s_maxDeferredRepaintDelayDuringLoading = p;
}
// On each repaint the delay increases by this amount
void FrameView::setRepaintThrottlingDeferredRepaintDelayIncrementDuringLoading(double p)
{
s_deferredRepaintDelayIncrementDuringLoading = p;
}
bool FrameView::isVerticalDocument() const
{
if (!m_frame)
return true;
Document* doc = m_frame->document();
if (!doc)
return true;
RenderObject* renderView = doc->renderer();
if (!renderView)
return true;
return renderView->style()->isHorizontalWritingMode();
}
bool FrameView::isFlippedDocument() const
{
if (!m_frame)
return false;
Document* doc = m_frame->document();
if (!doc)
return false;
RenderObject* renderView = doc->renderer();
if (!renderView)
return false;
return renderView->style()->isFlippedBlocksWritingMode();
}
void FrameView::notifyWidgetsInAllFrames(WidgetNotification notification)
{
for (Frame* frame = m_frame.get(); frame; frame = frame->tree()->traverseNext(m_frame.get())) {
if (RenderView* root = frame->contentRenderer())
root->notifyWidgets(notification);
}
}
AXObjectCache* FrameView::axObjectCache() const
{
if (frame() && frame()->document() && frame()->document()->axObjectCacheExists())
return frame()->document()->axObjectCache();
return 0;
}
} // namespace WebCore
|