Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(519)

Side by Side Diff: Source/core/dom/Document.cpp

Issue 156413002: [WIP] Move layout states into the DocumentLifecycle state machine (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: uber patch Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/dom/DocumentLifecycle.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 , m_containsValidityStyleRules(false) 428 , m_containsValidityStyleRules(false)
429 , m_updateFocusAppearanceRestoresSelection(false) 429 , m_updateFocusAppearanceRestoresSelection(false)
430 , m_containsPlugins(false) 430 , m_containsPlugins(false)
431 , m_ignoreDestructiveWriteCount(0) 431 , m_ignoreDestructiveWriteCount(0)
432 , m_titleSetExplicitly(false) 432 , m_titleSetExplicitly(false)
433 , m_markers(adoptPtr(new DocumentMarkerController)) 433 , m_markers(adoptPtr(new DocumentMarkerController))
434 , m_updateFocusAppearanceTimer(this, &Document::updateFocusAppearanceTimerFi red) 434 , m_updateFocusAppearanceTimer(this, &Document::updateFocusAppearanceTimerFi red)
435 , m_cssTarget(0) 435 , m_cssTarget(0)
436 , m_loadEventProgress(LoadEventNotRun) 436 , m_loadEventProgress(LoadEventNotRun)
437 , m_startTime(currentTime()) 437 , m_startTime(currentTime())
438 , m_overMinimumLayoutThreshold(false)
439 , m_scriptRunner(ScriptRunner::create(this)) 438 , m_scriptRunner(ScriptRunner::create(this))
440 , m_xmlVersion("1.0") 439 , m_xmlVersion("1.0")
441 , m_xmlStandalone(StandaloneUnspecified) 440 , m_xmlStandalone(StandaloneUnspecified)
442 , m_hasXMLDeclaration(0) 441 , m_hasXMLDeclaration(0)
443 , m_designMode(inherit) 442 , m_designMode(inherit)
444 , m_hasAnnotatedRegions(false) 443 , m_hasAnnotatedRegions(false)
445 , m_annotatedRegionsDirty(false) 444 , m_annotatedRegionsDirty(false)
446 , m_useSecureKeyboardEntryWhenActive(false) 445 , m_useSecureKeyboardEntryWhenActive(false)
447 , m_documentClasses(documentClasses) 446 , m_documentClasses(documentClasses)
448 , m_isViewSource(false) 447 , m_isViewSource(false)
(...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 return 0; 1541 return 0;
1543 } 1542 }
1544 return TreeWalker::create(root, whatToShow, filter); 1543 return TreeWalker::create(root, whatToShow, filter);
1545 } 1544 }
1546 1545
1547 bool Document::shouldCallRecalcStyleForDocument() 1546 bool Document::shouldCallRecalcStyleForDocument()
1548 { 1547 {
1549 return needsStyleRecalc() || childNeedsStyleRecalc() || childNeedsDistributi onRecalc() || !m_useElementsNeedingUpdate.isEmpty() || childNeedsStyleInvalidati on(); 1548 return needsStyleRecalc() || childNeedsStyleRecalc() || childNeedsDistributi onRecalc() || !m_useElementsNeedingUpdate.isEmpty() || childNeedsStyleInvalidati on();
1550 } 1549 }
1551 1550
1551 bool Document::shouldScheduleStyleRecalc()
1552 {
1553 if (!isActive())
1554 return false;
1555 if (hasPendingStyleRecalc())
1556 return false;
1557 if (inStyleRecalc())
1558 return false;
1559 // InPreLayout will recalc style itself. There's no reason to schedule anoth er recalc.
1560 if (m_lifecycle.state() == DocumentLifecycle::InPreLayout)
1561 return false;
1562 return true;
1563 }
1564
1552 void Document::scheduleStyleRecalc() 1565 void Document::scheduleStyleRecalc()
1553 { 1566 {
1554 if (hasPendingStyleRecalc() || !isActive() || inStyleRecalc() || !shouldSche duleLayout()) 1567 if (!shouldScheduleStyleRecalc() || !shouldScheduleLayout())
1555 return; 1568 return;
1556 1569
1557 ASSERT(shouldCallRecalcStyleForDocument()); 1570 ASSERT(shouldCallRecalcStyleForDocument());
1558 1571
1559 view()->scheduleAnimation(); 1572 view()->scheduleAnimation();
1560 m_lifecycle.rewindTo(DocumentLifecycle::StyleRecalcPending); 1573 m_lifecycle.rewindTo(DocumentLifecycle::StyleRecalcPending);
1561 1574
1562 InspectorInstrumentation::didScheduleStyleRecalculation(this); 1575 InspectorInstrumentation::didScheduleStyleRecalculation(this);
1563 } 1576 }
1564 1577
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1762 if (m_styleEngine->hasResolver()) { 1775 if (m_styleEngine->hasResolver()) {
1763 // Pseudo element removal and similar may only work with these flags still set. Reset them after the style recalc. 1776 // Pseudo element removal and similar may only work with these flags still set. Reset them after the style recalc.
1764 StyleResolver& resolver = m_styleEngine->ensureResolver(); 1777 StyleResolver& resolver = m_styleEngine->ensureResolver();
1765 m_styleEngine->resetCSSFeatureFlags(resolver.ensureRuleFeatureSet()) ; 1778 m_styleEngine->resetCSSFeatureFlags(resolver.ensureRuleFeatureSet()) ;
1766 resolver.clearStyleSharingList(); 1779 resolver.clearStyleSharingList();
1767 } 1780 }
1768 1781
1769 ASSERT(!needsStyleRecalc()); 1782 ASSERT(!needsStyleRecalc());
1770 ASSERT(!childNeedsStyleRecalc()); 1783 ASSERT(!childNeedsStyleRecalc());
1771 ASSERT(inStyleRecalc()); 1784 ASSERT(inStyleRecalc());
1772 m_lifecycle.advanceTo(DocumentLifecycle::Clean); 1785 m_lifecycle.advanceTo(DocumentLifecycle::StyleClean);
1773 } 1786 }
1774 1787
1775 InspectorInstrumentation::didRecalculateStyle(cookie); 1788 InspectorInstrumentation::didRecalculateStyle(cookie);
1776 1789
1777 // As a result of the style recalculation, the currently hovered element mig ht have been 1790 // As a result of the style recalculation, the currently hovered element mig ht have been
1778 // detached (for example, by setting display:none in the :hover style), sche dule another mouseMove event 1791 // detached (for example, by setting display:none in the :hover style), sche dule another mouseMove event
1779 // to check if any other elements ended up under the mouse pointer due to re -layout. 1792 // to check if any other elements ended up under the mouse pointer due to re -layout.
1780 if (hoverNode() && !hoverNode()->renderer() && frame()) 1793 if (hoverNode() && !hoverNode()->renderer() && frame())
1781 frame()->eventHandler().dispatchFakeMouseMoveEventSoon(); 1794 frame()->eventHandler().dispatchFakeMouseMoveEventSoon();
1782 1795
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
2042 2055
2043 m_renderView = new RenderView(this); 2056 m_renderView = new RenderView(this);
2044 setRenderer(m_renderView); 2057 setRenderer(m_renderView);
2045 2058
2046 m_renderView->setIsInWindow(true); 2059 m_renderView->setIsInWindow(true);
2047 m_renderView->setStyle(StyleResolver::styleForDocument(*this)); 2060 m_renderView->setStyle(StyleResolver::styleForDocument(*this));
2048 view()->updateCompositingLayersAfterStyleChange(); 2061 view()->updateCompositingLayersAfterStyleChange();
2049 2062
2050 ContainerNode::attach(context); 2063 ContainerNode::attach(context);
2051 2064
2052 m_lifecycle.advanceTo(DocumentLifecycle::Clean); 2065 m_lifecycle.advanceTo(DocumentLifecycle::LayoutClean);
2053 } 2066 }
2054 2067
2055 void Document::detach(const AttachContext& context) 2068 void Document::detach(const AttachContext& context)
2056 { 2069 {
2057 ASSERT(isActive()); 2070 ASSERT(isActive());
2058 m_lifecycle.advanceTo(DocumentLifecycle::Stopping); 2071 m_lifecycle.advanceTo(DocumentLifecycle::Stopping);
2059 2072
2060 if (page()) 2073 if (page())
2061 page()->documentDetached(this); 2074 page()->documentDetached(this);
2062 2075
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
2425 } 2438 }
2426 2439
2427 // Make sure both the initial layout and reflow happen after the onload 2440 // Make sure both the initial layout and reflow happen after the onload
2428 // fires. This will improve onload scores, and other browsers do it. 2441 // fires. This will improve onload scores, and other browsers do it.
2429 // If they wanna cheat, we can too. -dwh 2442 // If they wanna cheat, we can too. -dwh
2430 2443
2431 if (frame()->navigationScheduler().locationChangePending() && elapsedTime() < cLayoutScheduleThreshold) { 2444 if (frame()->navigationScheduler().locationChangePending() && elapsedTime() < cLayoutScheduleThreshold) {
2432 // Just bail out. Before or during the onload we were shifted to another page. 2445 // Just bail out. Before or during the onload we were shifted to another page.
2433 // The old i-Bench suite does this. When this happens don't bother paint ing or laying out. 2446 // The old i-Bench suite does this. When this happens don't bother paint ing or laying out.
2434 m_loadEventProgress = LoadEventCompleted; 2447 m_loadEventProgress = LoadEventCompleted;
2435 view()->unscheduleRelayout();
2436 return; 2448 return;
2437 } 2449 }
2438 2450
2439 // We used to force a synchronous display and flush here. This really isn't 2451 // We used to force a synchronous display and flush here. This really isn't
2440 // necessary and can in fact be actively harmful if pages are loading at a r ate of > 60fps 2452 // necessary and can in fact be actively harmful if pages are loading at a r ate of > 60fps
2441 // (if your platform is syncing flushes and limiting them to 60fps). 2453 // (if your platform is syncing flushes and limiting them to 60fps).
2442 m_overMinimumLayoutThreshold = true;
2443 if (!ownerElement() || (ownerElement()->renderer() && !ownerElement()->rende rer()->needsLayout())) { 2454 if (!ownerElement() || (ownerElement()->renderer() && !ownerElement()->rende rer()->needsLayout())) {
2444 updateStyleIfNeeded(); 2455 updateStyleIfNeeded();
2445 2456
2446 // Always do a layout after loading if needed. 2457 // Always do a layout after loading if needed.
2447 if (view() && renderView() && (!renderView()->firstChild() || renderView ()->needsLayout())) 2458 if (view() && renderView() && (!renderView()->firstChild() || renderView ()->needsLayout()))
2448 view()->layout(); 2459 view()->layout();
2449 } 2460 }
2450 2461
2451 m_loadEventProgress = LoadEventCompleted; 2462 m_loadEventProgress = LoadEventCompleted;
2452 2463
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
2578 // 2589 //
2579 // (a) Only schedule a layout once the stylesheets are loaded. 2590 // (a) Only schedule a layout once the stylesheets are loaded.
2580 // (b) Only schedule layout once we have a body element. 2591 // (b) Only schedule layout once we have a body element.
2581 2592
2582 return (haveStylesheetsLoaded() && body()) 2593 return (haveStylesheetsLoaded() && body())
2583 || (documentElement() && !documentElement()->hasTagName(htmlTag)); 2594 || (documentElement() && !documentElement()->hasTagName(htmlTag));
2584 } 2595 }
2585 2596
2586 bool Document::shouldParserYieldAgressivelyBeforeScriptExecution() 2597 bool Document::shouldParserYieldAgressivelyBeforeScriptExecution()
2587 { 2598 {
2588 return view() && view()->layoutPending() && !minimumLayoutDelay(); 2599 return view() && view()->layoutPending();
2589 }
2590
2591 int Document::minimumLayoutDelay()
2592 {
2593 if (m_overMinimumLayoutThreshold)
2594 return 0;
2595
2596 int elapsed = elapsedTime();
2597 m_overMinimumLayoutThreshold = elapsed > cLayoutScheduleThreshold;
2598
2599 // We'll want to schedule the timer to fire at the minimum layout threshold.
2600 return max(0, cLayoutScheduleThreshold - elapsed);
2601 } 2600 }
2602 2601
2603 int Document::elapsedTime() const 2602 int Document::elapsedTime() const
2604 { 2603 {
2605 return static_cast<int>((currentTime() - m_startTime) * 1000); 2604 return static_cast<int>((currentTime() - m_startTime) * 1000);
2606 } 2605 }
2607 2606
2608 void Document::write(const SegmentedString& text, Document* ownerDocument) 2607 void Document::write(const SegmentedString& text, Document* ownerDocument)
2609 { 2608 {
2610 NestingLevelIncrementer nestingLevelIncrementer(m_writeRecursionDepth); 2609 NestingLevelIncrementer nestingLevelIncrementer(m_writeRecursionDepth);
(...skipping 2808 matching lines...) Expand 10 before | Expand all | Expand 10 after
5419 void Document::defaultEventHandler(Event* event) 5418 void Document::defaultEventHandler(Event* event)
5420 { 5419 {
5421 if (frame() && frame()->remotePlatformLayer()) { 5420 if (frame() && frame()->remotePlatformLayer()) {
5422 frame()->chromeClient().forwardInputEvent(this, event); 5421 frame()->chromeClient().forwardInputEvent(this, event);
5423 return; 5422 return;
5424 } 5423 }
5425 Node::defaultEventHandler(event); 5424 Node::defaultEventHandler(event);
5426 } 5425 }
5427 5426
5428 } // namespace WebCore 5427 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/dom/DocumentLifecycle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698