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

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

Issue 18601002: Add infrastructure for partial layouts (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address reviewer comments. Add PartialLayoutState and PartialLayoutDisabler Created 7 years, 3 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 1730 matching lines...) Expand 10 before | Expand all | Expand 10 after
1741 oe->document()->updateLayout(); 1741 oe->document()->updateLayout();
1742 1742
1743 updateStyleIfNeeded(); 1743 updateStyleIfNeeded();
1744 1744
1745 StackStats::LayoutCheckPoint layoutCheckPoint; 1745 StackStats::LayoutCheckPoint layoutCheckPoint;
1746 1746
1747 // Only do a layout if changes have occurred that make it necessary. 1747 // Only do a layout if changes have occurred that make it necessary.
1748 if (frameView && renderer() && (frameView->layoutPending() || renderer()->ne edsLayout())) 1748 if (frameView && renderer() && (frameView->layoutPending() || renderer()->ne edsLayout()))
1749 frameView->layout(); 1749 frameView->layout();
1750 1750
1751 if (frameView)
1752 frameView->partialLayout().reset();
1753
1751 setNeedsFocusedElementCheck(); 1754 setNeedsFocusedElementCheck();
1752 } 1755 }
1753 1756
1754 void Document::setNeedsFocusedElementCheck() 1757 void Document::setNeedsFocusedElementCheck()
1755 { 1758 {
1756 // FIXME: Using a Task doesn't look a good idea. 1759 // FIXME: Using a Task doesn't look a good idea.
1757 if (!m_focusedElement || m_didPostCheckFocusedElementTask) 1760 if (!m_focusedElement || m_didPostCheckFocusedElementTask)
1758 return; 1761 return;
1759 postTask(CheckFocusedElementTask::create()); 1762 postTask(CheckFocusedElementTask::create());
1760 m_didPostCheckFocusedElementTask = true; 1763 m_didPostCheckFocusedElementTask = true;
1761 } 1764 }
1762 1765
1766 void Document::recalcStyleForLayoutIgnoringPendingStylesheets()
1767 {
1768 if (!haveStylesheetsLoaded()) {
1769 m_ignorePendingStylesheets = true;
1770 // FIXME: We are willing to attempt to suppress painting with outdated s tyle info only once.
1771 // Our assumption is that it would be dangerous to try to stop it a seco nd time, after page
1772 // content has already been loaded and displayed with accurate style inf ormation. (Our
1773 // suppression involves blanking the whole page at the moment. If it wer e more refined, we
1774 // might be able to do something better.) It's worth noting though that this entire method
1775 // is a hack, since what we really want to do is suspend JS instead of d oing a layout with
1776 // inaccurate information.
1777 HTMLElement* bodyElement = body();
1778 if (bodyElement && !bodyElement->renderer() && m_pendingSheetLayout == N oLayoutWithPendingSheets) {
1779 m_pendingSheetLayout = DidLayoutWithPendingSheets;
1780 styleResolverChanged(RecalcStyleImmediately);
1781 } else if (m_hasNodesWithPlaceholderStyle)
ojan 2013/08/27 01:33:41 Nit: moar curly braces plz.
1782 // If new nodes have been added or style recalc has been done with s tyle sheets still
1783 // pending, some nodes may not have had their real style calculated yet. Normally this
1784 // gets cleaned when style sheets arrive but here we need up-to-date style immediately.
1785 recalcStyle(Force);
1786 }
1787 }
1788
1763 // FIXME: This is a bad idea and needs to be removed eventually. 1789 // FIXME: This is a bad idea and needs to be removed eventually.
1764 // Other browsers load stylesheets before they continue parsing the web page. 1790 // Other browsers load stylesheets before they continue parsing the web page.
1765 // Since we don't, we can run JavaScript code that needs answers before the 1791 // Since we don't, we can run JavaScript code that needs answers before the
1766 // stylesheets are loaded. Doing a layout ignoring the pending stylesheets 1792 // stylesheets are loaded. Doing a layout ignoring the pending stylesheets
1767 // lets us get reasonable answers. The long term solution to this problem is 1793 // lets us get reasonable answers. The long term solution to this problem is
1768 // to instead suspend JavaScript execution. 1794 // to instead suspend JavaScript execution.
1769 void Document::updateLayoutIgnorePendingStylesheets() 1795 void Document::updateLayoutIgnorePendingStylesheets()
1770 { 1796 {
1771 bool oldIgnore = m_ignorePendingStylesheets; 1797 TemporaryChange<bool> ignorePendingStylesheets(m_ignorePendingStylesheets, m _ignorePendingStylesheets);
1798 recalcStyleForLayoutIgnoringPendingStylesheets();
1799 updateLayout();
1800 }
1772 1801
1773 if (!haveStylesheetsLoaded()) { 1802 void Document::partialUpdateLayoutIgnorePendingStylesheets(Node* stopLayoutAtNod e)
1774 m_ignorePendingStylesheets = true; 1803 {
1775 // FIXME: We are willing to attempt to suppress painting with outdated s tyle info only once. Our assumption is that it would be 1804 TemporaryChange<bool> ignorePendingStylesheets(m_ignorePendingStylesheets, m _ignorePendingStylesheets);
1776 // dangerous to try to stop it a second time, after page content has alr eady been loaded and displayed 1805 recalcStyleForLayoutIgnoringPendingStylesheets();
1777 // with accurate style information. (Our suppression involves blanking the whole page at the 1806
1778 // moment. If it were more refined, we might be able to do something be tter.) 1807 if (stopLayoutAtNode) {
1779 // It's worth noting though that this entire method is a hack, since wha t we really want to do is 1808 bool canPartialLayout = true;
1780 // suspend JS instead of doing a layout with inaccurate information. 1809 RenderObject* renderer = stopLayoutAtNode->renderer();
1781 HTMLElement* bodyElement = body(); 1810 while (renderer) {
1782 if (bodyElement && !bodyElement->renderer() && m_pendingSheetLayout == N oLayoutWithPendingSheets) { 1811 if (!renderer->supportsPartialLayout()) {
1783 m_pendingSheetLayout = DidLayoutWithPendingSheets; 1812 canPartialLayout = false;
1784 styleResolverChanged(RecalcStyleImmediately); 1813 break;
1785 } else if (m_hasNodesWithPlaceholderStyle) 1814 }
1786 // If new nodes have been added or style recalc has been done with s tyle sheets still pending, some nodes 1815 renderer = renderer->parent();
1787 // may not have had their real style calculated yet. Normally this g ets cleaned when style sheets arrive 1816 }
1788 // but here we need up-to-date style immediately. 1817 if (canPartialLayout)
1789 recalcStyle(Force); 1818 view()->partialLayout().setStopAtRenderer(stopLayoutAtNode->renderer ());
1790 } 1819 }
1791 1820
1792 updateLayout(); 1821 updateLayout();
1793 1822
1794 m_ignorePendingStylesheets = oldIgnore; 1823 view()->partialLayout().reset();
1795 } 1824 }
1796 1825
1797 PassRefPtr<RenderStyle> Document::styleForElementIgnoringPendingStylesheets(Elem ent* element) 1826 PassRefPtr<RenderStyle> Document::styleForElementIgnoringPendingStylesheets(Elem ent* element)
1798 { 1827 {
1799 ASSERT_ARG(element, element->document() == this); 1828 ASSERT_ARG(element, element->document() == this);
1800 TemporaryChange<bool> ignoreStyleSheets(m_ignorePendingStylesheets, true); 1829 TemporaryChange<bool> ignoreStyleSheets(m_ignorePendingStylesheets, true);
1801 return styleResolver()->styleForElement(element, element->parentNode() ? ele ment->parentNode()->computedStyle() : 0); 1830 return styleResolver()->styleForElement(element, element->parentNode() ? ele ment->parentNode()->computedStyle() : 0);
1802 } 1831 }
1803 1832
1804 PassRefPtr<RenderStyle> Document::styleForPage(int pageIndex) 1833 PassRefPtr<RenderStyle> Document::styleForPage(int pageIndex)
(...skipping 3439 matching lines...) Expand 10 before | Expand all | Expand 10 after
5244 { 5273 {
5245 return DocumentLifecycleNotifier::create(this); 5274 return DocumentLifecycleNotifier::create(this);
5246 } 5275 }
5247 5276
5248 DocumentLifecycleNotifier* Document::lifecycleNotifier() 5277 DocumentLifecycleNotifier* Document::lifecycleNotifier()
5249 { 5278 {
5250 return static_cast<DocumentLifecycleNotifier*>(ScriptExecutionContext::lifec ycleNotifier()); 5279 return static_cast<DocumentLifecycleNotifier*>(ScriptExecutionContext::lifec ycleNotifier());
5251 } 5280 }
5252 5281
5253 } // namespace WebCore 5282 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698