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

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: Put behind PartialLayout runtime flag 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 1741
1742 if (Element* oe = ownerElement()) 1742 if (Element* oe = ownerElement())
1743 oe->document().updateLayout(); 1743 oe->document().updateLayout();
1744 1744
1745 updateStyleIfNeeded(); 1745 updateStyleIfNeeded();
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) {
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 }
1789
1763 // FIXME: This is a bad idea and needs to be removed eventually. 1790 // FIXME: This is a bad idea and needs to be removed eventually.
1764 // Other browsers load stylesheets before they continue parsing the web page. 1791 // 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 1792 // 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 1793 // stylesheets are loaded. Doing a layout ignoring the pending stylesheets
1767 // lets us get reasonable answers. The long term solution to this problem is 1794 // lets us get reasonable answers. The long term solution to this problem is
1768 // to instead suspend JavaScript execution. 1795 // to instead suspend JavaScript execution.
1769 void Document::updateLayoutIgnorePendingStylesheets() 1796 void Document::updateLayoutIgnorePendingStylesheets()
1770 { 1797 {
1771 bool oldIgnore = m_ignorePendingStylesheets; 1798 TemporaryChange<bool> ignorePendingStylesheets(m_ignorePendingStylesheets, m _ignorePendingStylesheets);
esprehn 2013/09/03 18:15:36 This TemporaryChange should be inside recalcStyleF
pdr. 2013/09/03 21:37:35 Done.
1799 recalcStyleForLayoutIgnoringPendingStylesheets();
1800 updateLayout();
1801 }
1772 1802
1773 if (!haveStylesheetsLoaded()) { 1803 void Document::partialUpdateLayoutIgnorePendingStylesheets(Node* stopLayoutAtNod e)
1774 m_ignorePendingStylesheets = true; 1804 {
1775 // FIXME: We are willing to attempt to suppress painting with outdated s tyle info only once. Our assumption is that it would be 1805 if (!RuntimeEnabledFeatures::partialLayoutEnabled())
1776 // dangerous to try to stop it a second time, after page content has alr eady been loaded and displayed 1806 updateLayoutIgnorePendingStylesheets();
esprehn 2013/09/03 18:15:36 You need to early return, otherwise your code stil
pdr. 2013/09/03 21:37:35 :( Stupid mistake on my part; good catch.
1777 // with accurate style information. (Our suppression involves blanking the whole page at the 1807
1778 // moment. If it were more refined, we might be able to do something be tter.) 1808 TemporaryChange<bool> ignorePendingStylesheets(m_ignorePendingStylesheets, m _ignorePendingStylesheets);
1779 // It's worth noting though that this entire method is a hack, since wha t we really want to do is 1809 recalcStyleForLayoutIgnoringPendingStylesheets();
1780 // suspend JS instead of doing a layout with inaccurate information. 1810
1781 HTMLElement* bodyElement = body(); 1811 if (stopLayoutAtNode) {
1782 if (bodyElement && !bodyElement->renderer() && m_pendingSheetLayout == N oLayoutWithPendingSheets) { 1812 bool canPartialLayout = true;
1783 m_pendingSheetLayout = DidLayoutWithPendingSheets; 1813 RenderObject* renderer = stopLayoutAtNode->renderer();
1784 styleResolverChanged(RecalcStyleImmediately); 1814 while (renderer) {
1785 } else if (m_hasNodesWithPlaceholderStyle) 1815 if (!renderer->supportsPartialLayout()) {
1786 // If new nodes have been added or style recalc has been done with s tyle sheets still pending, some nodes 1816 canPartialLayout = false;
1787 // may not have had their real style calculated yet. Normally this g ets cleaned when style sheets arrive 1817 break;
1788 // but here we need up-to-date style immediately. 1818 }
1789 recalcStyle(Force); 1819 renderer = renderer->parent();
1820 }
1821 if (canPartialLayout)
1822 view()->partialLayout().setStopAtRenderer(stopLayoutAtNode->renderer ());
1790 } 1823 }
1791 1824
1792 updateLayout(); 1825 updateLayout();
1793 1826
1794 m_ignorePendingStylesheets = oldIgnore; 1827 view()->partialLayout().reset();
esprehn 2013/09/03 18:15:36 I think this needs to be inside FrameView::layout(
pdr. 2013/09/03 21:37:35 I don't think we need to run the post layout tasks
1795 } 1828 }
1796 1829
1797 PassRefPtr<RenderStyle> Document::styleForElementIgnoringPendingStylesheets(Elem ent* element) 1830 PassRefPtr<RenderStyle> Document::styleForElementIgnoringPendingStylesheets(Elem ent* element)
1798 { 1831 {
1799 ASSERT_ARG(element, &element->document() == this); 1832 ASSERT_ARG(element, &element->document() == this);
1800 TemporaryChange<bool> ignoreStyleSheets(m_ignorePendingStylesheets, true); 1833 TemporaryChange<bool> ignoreStyleSheets(m_ignorePendingStylesheets, true);
1801 return styleResolver()->styleForElement(element, element->parentNode() ? ele ment->parentNode()->computedStyle() : 0); 1834 return styleResolver()->styleForElement(element, element->parentNode() ? ele ment->parentNode()->computedStyle() : 0);
1802 } 1835 }
1803 1836
1804 PassRefPtr<RenderStyle> Document::styleForPage(int pageIndex) 1837 PassRefPtr<RenderStyle> Document::styleForPage(int pageIndex)
(...skipping 3489 matching lines...) Expand 10 before | Expand all | Expand 10 after
5294 { 5327 {
5295 return DocumentLifecycleNotifier::create(this); 5328 return DocumentLifecycleNotifier::create(this);
5296 } 5329 }
5297 5330
5298 DocumentLifecycleNotifier* Document::lifecycleNotifier() 5331 DocumentLifecycleNotifier* Document::lifecycleNotifier()
5299 { 5332 {
5300 return static_cast<DocumentLifecycleNotifier*>(ScriptExecutionContext::lifec ycleNotifier()); 5333 return static_cast<DocumentLifecycleNotifier*>(ScriptExecutionContext::lifec ycleNotifier());
5301 } 5334 }
5302 5335
5303 } // namespace WebCore 5336 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698