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

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: 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
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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 , m_containsValidityStyleRules(false) 458 , m_containsValidityStyleRules(false)
459 , m_updateFocusAppearanceRestoresSelection(false) 459 , m_updateFocusAppearanceRestoresSelection(false)
460 , m_containsPlugins(false) 460 , m_containsPlugins(false)
461 , m_ignoreDestructiveWriteCount(0) 461 , m_ignoreDestructiveWriteCount(0)
462 , m_titleSetExplicitly(false) 462 , m_titleSetExplicitly(false)
463 , m_markers(adoptPtr(new DocumentMarkerController)) 463 , m_markers(adoptPtr(new DocumentMarkerController))
464 , m_updateFocusAppearanceTimer(this, &Document::updateFocusAppearanceTimerFi red) 464 , m_updateFocusAppearanceTimer(this, &Document::updateFocusAppearanceTimerFi red)
465 , m_cssTarget(0) 465 , m_cssTarget(0)
466 , m_loadEventProgress(LoadEventNotRun) 466 , m_loadEventProgress(LoadEventNotRun)
467 , m_startTime(currentTime()) 467 , m_startTime(currentTime())
468 , m_overMinimumLayoutThreshold(false)
ojan 2014/02/06 05:11:39 Should probably remove this in a separate pre-patc
abarth-chromium 2014/02/06 05:31:15 Yep!
469 , m_scriptRunner(ScriptRunner::create(this)) 468 , m_scriptRunner(ScriptRunner::create(this))
470 , m_xmlVersion("1.0") 469 , m_xmlVersion("1.0")
471 , m_xmlStandalone(StandaloneUnspecified) 470 , m_xmlStandalone(StandaloneUnspecified)
472 , m_hasXMLDeclaration(0) 471 , m_hasXMLDeclaration(0)
473 , m_designMode(inherit) 472 , m_designMode(inherit)
474 , m_hasAnnotatedRegions(false) 473 , m_hasAnnotatedRegions(false)
475 , m_annotatedRegionsDirty(false) 474 , m_annotatedRegionsDirty(false)
476 , m_useSecureKeyboardEntryWhenActive(false) 475 , m_useSecureKeyboardEntryWhenActive(false)
477 , m_documentClasses(documentClasses) 476 , m_documentClasses(documentClasses)
478 , m_isViewSource(false) 477 , m_isViewSource(false)
(...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after
1572 return 0; 1571 return 0;
1573 } 1572 }
1574 return TreeWalker::create(root, whatToShow, filter); 1573 return TreeWalker::create(root, whatToShow, filter);
1575 } 1574 }
1576 1575
1577 bool Document::shouldCallRecalcStyleForDocument() 1576 bool Document::shouldCallRecalcStyleForDocument()
1578 { 1577 {
1579 return needsStyleRecalc() || childNeedsStyleRecalc() || childNeedsDistributi onRecalc() || !m_useElementsNeedingUpdate.isEmpty() || childNeedsStyleInvalidati on(); 1578 return needsStyleRecalc() || childNeedsStyleRecalc() || childNeedsDistributi onRecalc() || !m_useElementsNeedingUpdate.isEmpty() || childNeedsStyleInvalidati on();
1580 } 1579 }
1581 1580
1581 bool Document::shouldScheduleStyleRecalc()
1582 {
1583 if (!isActive())
1584 return false;
1585 if (hasPendingStyleRecalc())
1586 return false;
1587 if (inStyleRecalc())
1588 return false;
1589 // InPreLayout will recalc style itself. There's no reason to schedule anoth er recalc.
1590 if (m_lifecycle.state() == DocumentLifecycle::InPreLayout)
1591 return false;
1592 return true;
1593 }
1594
1582 void Document::scheduleStyleRecalc() 1595 void Document::scheduleStyleRecalc()
1583 { 1596 {
1584 if (hasPendingStyleRecalc() || !isActive() || inStyleRecalc() || !shouldSche duleLayout()) 1597 if (!shouldScheduleStyleRecalc() || !shouldScheduleLayout())
1585 return; 1598 return;
1586 1599
1587 ASSERT(shouldCallRecalcStyleForDocument()); 1600 ASSERT(shouldCallRecalcStyleForDocument());
1588 1601
1589 view()->scheduleAnimation(); 1602 view()->scheduleAnimation();
1590 m_lifecycle.rewindTo(DocumentLifecycle::StyleRecalcPending); 1603 m_lifecycle.rewindTo(DocumentLifecycle::StyleRecalcPending);
1591 1604
1592 InspectorInstrumentation::didScheduleStyleRecalculation(this); 1605 InspectorInstrumentation::didScheduleStyleRecalculation(this);
1593 } 1606 }
1594 1607
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1792 if (m_styleEngine->hasResolver()) { 1805 if (m_styleEngine->hasResolver()) {
1793 // Pseudo element removal and similar may only work with these flags still set. Reset them after the style recalc. 1806 // Pseudo element removal and similar may only work with these flags still set. Reset them after the style recalc.
1794 StyleResolver& resolver = m_styleEngine->ensureResolver(); 1807 StyleResolver& resolver = m_styleEngine->ensureResolver();
1795 m_styleEngine->resetCSSFeatureFlags(resolver.ensureRuleFeatureSet()) ; 1808 m_styleEngine->resetCSSFeatureFlags(resolver.ensureRuleFeatureSet()) ;
1796 resolver.clearStyleSharingList(); 1809 resolver.clearStyleSharingList();
1797 } 1810 }
1798 1811
1799 ASSERT(!needsStyleRecalc()); 1812 ASSERT(!needsStyleRecalc());
1800 ASSERT(!childNeedsStyleRecalc()); 1813 ASSERT(!childNeedsStyleRecalc());
1801 ASSERT(inStyleRecalc()); 1814 ASSERT(inStyleRecalc());
1802 m_lifecycle.advanceTo(DocumentLifecycle::Clean); 1815 m_lifecycle.advanceTo(DocumentLifecycle::StyleClean);
1803 } 1816 }
1804 1817
1805 InspectorInstrumentation::didRecalculateStyle(cookie); 1818 InspectorInstrumentation::didRecalculateStyle(cookie);
1806 1819
1807 // As a result of the style recalculation, the currently hovered element mig ht have been 1820 // As a result of the style recalculation, the currently hovered element mig ht have been
1808 // detached (for example, by setting display:none in the :hover style), sche dule another mouseMove event 1821 // detached (for example, by setting display:none in the :hover style), sche dule another mouseMove event
1809 // to check if any other elements ended up under the mouse pointer due to re -layout. 1822 // to check if any other elements ended up under the mouse pointer due to re -layout.
1810 if (hoverNode() && !hoverNode()->renderer() && frame()) 1823 if (hoverNode() && !hoverNode()->renderer() && frame())
1811 frame()->eventHandler().dispatchFakeMouseMoveEventSoon(); 1824 frame()->eventHandler().dispatchFakeMouseMoveEventSoon();
1812 } 1825 }
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
2064 2077
2065 m_renderView = new RenderView(this); 2078 m_renderView = new RenderView(this);
2066 setRenderer(m_renderView); 2079 setRenderer(m_renderView);
2067 2080
2068 m_renderView->setIsInWindow(true); 2081 m_renderView->setIsInWindow(true);
2069 m_renderView->setStyle(StyleResolver::styleForDocument(*this)); 2082 m_renderView->setStyle(StyleResolver::styleForDocument(*this));
2070 view()->updateCompositingLayersAfterStyleChange(); 2083 view()->updateCompositingLayersAfterStyleChange();
2071 2084
2072 ContainerNode::attach(context); 2085 ContainerNode::attach(context);
2073 2086
2074 m_lifecycle.advanceTo(DocumentLifecycle::Clean); 2087 m_lifecycle.advanceTo(DocumentLifecycle::LayoutClean);
2075 } 2088 }
2076 2089
2077 void Document::detach(const AttachContext& context) 2090 void Document::detach(const AttachContext& context)
2078 { 2091 {
2079 ASSERT(isActive()); 2092 ASSERT(isActive());
2080 m_lifecycle.advanceTo(DocumentLifecycle::Stopping); 2093 m_lifecycle.advanceTo(DocumentLifecycle::Stopping);
2081 2094
2082 if (page()) 2095 if (page())
2083 page()->documentDetached(this); 2096 page()->documentDetached(this);
2084 2097
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
2447 } 2460 }
2448 2461
2449 // Make sure both the initial layout and reflow happen after the onload 2462 // Make sure both the initial layout and reflow happen after the onload
2450 // fires. This will improve onload scores, and other browsers do it. 2463 // fires. This will improve onload scores, and other browsers do it.
2451 // If they wanna cheat, we can too. -dwh 2464 // If they wanna cheat, we can too. -dwh
2452 2465
2453 if (frame()->navigationScheduler().locationChangePending() && elapsedTime() < cLayoutScheduleThreshold) { 2466 if (frame()->navigationScheduler().locationChangePending() && elapsedTime() < cLayoutScheduleThreshold) {
2454 // Just bail out. Before or during the onload we were shifted to another page. 2467 // Just bail out. Before or during the onload we were shifted to another page.
2455 // The old i-Bench suite does this. When this happens don't bother paint ing or laying out. 2468 // The old i-Bench suite does this. When this happens don't bother paint ing or laying out.
2456 m_loadEventProgress = LoadEventCompleted; 2469 m_loadEventProgress = LoadEventCompleted;
2457 view()->unscheduleRelayout();
2458 return; 2470 return;
2459 } 2471 }
2460 2472
2461 // We used to force a synchronous display and flush here. This really isn't 2473 // We used to force a synchronous display and flush here. This really isn't
2462 // necessary and can in fact be actively harmful if pages are loading at a r ate of > 60fps 2474 // necessary and can in fact be actively harmful if pages are loading at a r ate of > 60fps
2463 // (if your platform is syncing flushes and limiting them to 60fps). 2475 // (if your platform is syncing flushes and limiting them to 60fps).
2464 m_overMinimumLayoutThreshold = true;
2465 if (!ownerElement() || (ownerElement()->renderer() && !ownerElement()->rende rer()->needsLayout())) { 2476 if (!ownerElement() || (ownerElement()->renderer() && !ownerElement()->rende rer()->needsLayout())) {
2466 updateStyleIfNeeded(); 2477 updateStyleIfNeeded();
2467 2478
2468 // Always do a layout after loading if needed. 2479 // Always do a layout after loading if needed.
2469 if (view() && renderView() && (!renderView()->firstChild() || renderView ()->needsLayout())) 2480 if (view() && renderView() && (!renderView()->firstChild() || renderView ()->needsLayout()))
2470 view()->layout(); 2481 view()->layout();
2471 } 2482 }
2472 2483
2473 m_loadEventProgress = LoadEventCompleted; 2484 m_loadEventProgress = LoadEventCompleted;
2474 2485
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
2600 // 2611 //
2601 // (a) Only schedule a layout once the stylesheets are loaded. 2612 // (a) Only schedule a layout once the stylesheets are loaded.
2602 // (b) Only schedule layout once we have a body element. 2613 // (b) Only schedule layout once we have a body element.
2603 2614
2604 return (haveStylesheetsLoaded() && body()) 2615 return (haveStylesheetsLoaded() && body())
2605 || (documentElement() && !documentElement()->hasTagName(htmlTag)); 2616 || (documentElement() && !documentElement()->hasTagName(htmlTag));
2606 } 2617 }
2607 2618
2608 bool Document::shouldParserYieldAgressivelyBeforeScriptExecution() 2619 bool Document::shouldParserYieldAgressivelyBeforeScriptExecution()
2609 { 2620 {
2610 return view() && view()->layoutPending() && !minimumLayoutDelay(); 2621 return view() && view()->layoutPending();
2611 }
2612
2613 int Document::minimumLayoutDelay()
2614 {
2615 if (m_overMinimumLayoutThreshold)
2616 return 0;
2617
2618 int elapsed = elapsedTime();
2619 m_overMinimumLayoutThreshold = elapsed > cLayoutScheduleThreshold;
2620
2621 // We'll want to schedule the timer to fire at the minimum layout threshold.
2622 return max(0, cLayoutScheduleThreshold - elapsed);
2623 } 2622 }
2624 2623
2625 int Document::elapsedTime() const 2624 int Document::elapsedTime() const
2626 { 2625 {
2627 return static_cast<int>((currentTime() - m_startTime) * 1000); 2626 return static_cast<int>((currentTime() - m_startTime) * 1000);
2628 } 2627 }
2629 2628
2630 void Document::write(const SegmentedString& text, Document* ownerDocument) 2629 void Document::write(const SegmentedString& text, Document* ownerDocument)
2631 { 2630 {
2632 NestingLevelIncrementer nestingLevelIncrementer(m_writeRecursionDepth); 2631 NestingLevelIncrementer nestingLevelIncrementer(m_writeRecursionDepth);
(...skipping 2806 matching lines...) Expand 10 before | Expand all | Expand 10 after
5439 void Document::defaultEventHandler(Event* event) 5438 void Document::defaultEventHandler(Event* event)
5440 { 5439 {
5441 if (frame() && frame()->remotePlatformLayer()) { 5440 if (frame() && frame()->remotePlatformLayer()) {
5442 frame()->chromeClient().forwardInputEvent(this, event); 5441 frame()->chromeClient().forwardInputEvent(this, event);
5443 return; 5442 return;
5444 } 5443 }
5445 Node::defaultEventHandler(event); 5444 Node::defaultEventHandler(event);
5446 } 5445 }
5447 5446
5448 } // namespace WebCore 5447 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698