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

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

Issue 143873016: Implement style invalidation tree walk for targeted style recalc upon class change. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Addressed comments. 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/Element.cpp » ('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 1510 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 { 1521 {
1522 if (!root) { 1522 if (!root) {
1523 exceptionState.throwDOMException(NotSupportedError, "The provided node i s invalid."); 1523 exceptionState.throwDOMException(NotSupportedError, "The provided node i s invalid.");
1524 return 0; 1524 return 0;
1525 } 1525 }
1526 return TreeWalker::create(root, whatToShow, filter); 1526 return TreeWalker::create(root, whatToShow, filter);
1527 } 1527 }
1528 1528
1529 bool Document::shouldCallRecalcStyleForDocument() 1529 bool Document::shouldCallRecalcStyleForDocument()
1530 { 1530 {
1531 return needsStyleRecalc() || childNeedsStyleRecalc() || childNeedsDistributi onRecalc() || !m_useElementsNeedingUpdate.isEmpty(); 1531 return needsStyleRecalc() || childNeedsStyleRecalc() || childNeedsDistributi onRecalc() || !m_useElementsNeedingUpdate.isEmpty() || childNeedsStyleInvalidati on();
1532 } 1532 }
1533 1533
1534 void Document::scheduleStyleRecalc() 1534 void Document::scheduleStyleRecalc()
1535 { 1535 {
1536 if (!isActive()) 1536 if (!isActive())
1537 return; 1537 return;
1538 1538
1539 if (m_styleRecalcTimer.isActive() || !shouldScheduleLayout()) 1539 if (m_styleRecalcTimer.isActive() || !shouldScheduleLayout())
1540 return; 1540 return;
1541 1541
(...skipping 21 matching lines...) Expand all
1563 } 1563 }
1564 1564
1565 void Document::updateDistributionIfNeeded() 1565 void Document::updateDistributionIfNeeded()
1566 { 1566 {
1567 if (!childNeedsDistributionRecalc()) 1567 if (!childNeedsDistributionRecalc())
1568 return; 1568 return;
1569 TRACE_EVENT0("webkit", "Document::recalcDistribution"); 1569 TRACE_EVENT0("webkit", "Document::recalcDistribution");
1570 recalcDistribution(); 1570 recalcDistribution();
1571 } 1571 }
1572 1572
1573 void Document::updateStyleInvalidationIfNeeded()
1574 {
1575 if (!childNeedsStyleInvalidation())
1576 return;
1577 TRACE_EVENT0("webkit", "Document::computeNeedsStyleRecalcState");
1578 if (!styleResolver()) {
1579 clearChildNeedsStyleInvalidation();
ojan 2014/01/29 00:50:07 I think we still need to do the style invalidation
chrishtr 2014/01/29 01:56:42 The style invalidation data structure lives in the
ojan 2014/01/29 02:00:25 I see. Yeah, it seems like we have to block turnin
chrishtr 2014/01/29 02:02:32 Yes. My plan is to try to land the change that rem
1580 return;
1581 }
1582
1583 // FIXME: the style resolver can be deleted at present. Either resolve
1584 // crbug.com/335964 or move the invalidation data elsewhere.
ojan 2014/01/29 00:50:07 You can use use ensureStyleResolver(). I don't see
chrishtr 2014/01/29 01:56:42 See above.
1585 styleResolver()->ensureRuleFeatureSet().computeStyleInvalidation(*this);
1586 }
1587
1573 void Document::updateDistributionForNodeIfNeeded(Node* node) 1588 void Document::updateDistributionForNodeIfNeeded(Node* node)
1574 { 1589 {
1575 if (node->inDocument()) { 1590 if (node->inDocument()) {
1576 updateDistributionIfNeeded(); 1591 updateDistributionIfNeeded();
1577 return; 1592 return;
1578 } 1593 }
1579 Node* root = node; 1594 Node* root = node;
1580 while (Node* host = root->shadowHost()) 1595 while (Node* host = root->shadowHost())
1581 root = host; 1596 root = host;
1582 while (Node* ancestor = root->parentOrShadowHostNode()) 1597 while (Node* ancestor = root->parentOrShadowHostNode())
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 body->setNeedsStyleRecalc(); 1666 body->setNeedsStyleRecalc();
1652 } 1667 }
1653 } 1668 }
1654 1669
1655 if (RenderStyle* style = documentElement()->renderStyle()) { 1670 if (RenderStyle* style = documentElement()->renderStyle()) {
1656 if (style->direction() != rootDirection || style->writingMode() != rootW ritingMode) 1671 if (style->direction() != rootDirection || style->writingMode() != rootW ritingMode)
1657 documentElement()->setNeedsStyleRecalc(); 1672 documentElement()->setNeedsStyleRecalc();
1658 } 1673 }
1659 } 1674 }
1660 1675
1676 // FIXME: need a better name than recalcStyle. It's performing style invalidatio n, style recalc, and distribution.
1661 void Document::recalcStyle(StyleRecalcChange change) 1677 void Document::recalcStyle(StyleRecalcChange change)
1662 { 1678 {
1663 // we should not enter style recalc while painting 1679 // we should not enter style recalc while painting
1664 RELEASE_ASSERT(!view() || !view()->isPainting()); 1680 RELEASE_ASSERT(!view() || !view()->isPainting());
1665 1681
1666 // FIXME: We should never enter here without a FrameView or with an inactive document. 1682 // FIXME: We should never enter here without a FrameView or with an inactive document.
1667 if (!isActive() || !view()) 1683 if (!isActive() || !view())
1668 return; 1684 return;
1669 1685
1670 if (m_inStyleRecalc) 1686 if (m_inStyleRecalc)
1671 return; 1687 return;
1672 1688
1673 TRACE_EVENT0("webkit", "Document::recalcStyle"); 1689 TRACE_EVENT0("webkit", "Document::recalcStyle");
1674 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "RecalcStyle"); 1690 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "RecalcStyle");
1675 1691
1676 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willRecalc ulateStyle(this); 1692 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willRecalc ulateStyle(this);
1677 1693
1678 updateDistributionIfNeeded(); 1694 updateDistributionIfNeeded();
1679 updateUseShadowTrees(); 1695 updateUseShadowTrees();
1696 updateStyleInvalidationIfNeeded();
1680 1697
1681 if (m_evaluateMediaQueriesOnStyleRecalc) { 1698 if (m_evaluateMediaQueriesOnStyleRecalc) {
1682 m_evaluateMediaQueriesOnStyleRecalc = false; 1699 m_evaluateMediaQueriesOnStyleRecalc = false;
1683 evaluateMediaQueryList(); 1700 evaluateMediaQueryList();
1684 } 1701 }
1685 1702
1686 // FIXME: We should update style on our ancestor chain before proceeding 1703 // FIXME: We should update style on our ancestor chain before proceeding
1687 // however doing so currently causes several tests to crash, as Frame::setDo cument calls Document::attach 1704 // however doing so currently causes several tests to crash, as Frame::setDo cument calls Document::attach
1688 // before setting the DOMWindow on the Frame, or the SecurityOrigin on the d ocument. The attach, in turn 1705 // before setting the DOMWindow on the Frame, or the SecurityOrigin on the d ocument. The attach, in turn
1689 // resolves style (here) and then when we resolve style on the parent chain, we may end up 1706 // resolves style (here) and then when we resolve style on the parent chain, we may end up
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1772 void Document::updateStyleForNodeIfNeeded(Node* node) 1789 void Document::updateStyleForNodeIfNeeded(Node* node)
1773 { 1790 {
1774 if (!shouldCallRecalcStyleForDocument()) 1791 if (!shouldCallRecalcStyleForDocument())
1775 return; 1792 return;
1776 1793
1777 // At this point, we know that we need to recalc some style on the document in order to fully update styles. 1794 // At this point, we know that we need to recalc some style on the document in order to fully update styles.
1778 // However, style on 'node' only needs to be recalculated if a global recomp utation is needed, or a node on 1795 // However, style on 'node' only needs to be recalculated if a global recomp utation is needed, or a node on
1779 // the path from 'node' to the root needs style recalc. 1796 // the path from 'node' to the root needs style recalc.
1780 1797
1781 // Global needed. 1798 // Global needed.
1782 bool needsRecalc = needsStyleRecalc() || childNeedsDistributionRecalc() || ! m_useElementsNeedingUpdate.isEmpty(); 1799 bool needsRecalc = needsStyleRecalc() || childNeedsDistributionRecalc() || ! m_useElementsNeedingUpdate.isEmpty() || childNeedsStyleInvalidation();
1783 1800
1784 // On the path. 1801 // On the path.
1785 for (Node* ancestor = node; ancestor && !needsRecalc; ancestor = ancestor->p arentOrShadowHostNode()) 1802 for (Node* ancestor = node; ancestor && !needsRecalc; ancestor = ancestor->p arentOrShadowHostNode())
1786 needsRecalc = ancestor->needsStyleRecalc(); 1803 needsRecalc = ancestor->needsStyleRecalc();
1787 if (needsRecalc) 1804 if (needsRecalc)
1788 updateStyleIfNeeded(); 1805 updateStyleIfNeeded();
1789 } 1806 }
1790 1807
1791 void Document::updateLayout() 1808 void Document::updateLayout()
1792 { 1809 {
(...skipping 3526 matching lines...) Expand 10 before | Expand all | Expand 10 after
5319 if (!page->focusController().isActive() || !page->focusController().isFocuse d()) 5336 if (!page->focusController().isActive() || !page->focusController().isFocuse d())
5320 return false; 5337 return false;
5321 if (Frame* focusedFrame = page->focusController().focusedFrame()) { 5338 if (Frame* focusedFrame = page->focusController().focusedFrame()) {
5322 if (focusedFrame->tree().isDescendantOf(frame())) 5339 if (focusedFrame->tree().isDescendantOf(frame()))
5323 return true; 5340 return true;
5324 } 5341 }
5325 return false; 5342 return false;
5326 } 5343 }
5327 5344
5328 } // namespace WebCore 5345 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/dom/Element.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698