OLD | NEW |
1 | 1 |
2 // Copyright 2014 The Chromium Authors. All rights reserved. | 2 // Copyright 2014 The Chromium Authors. All rights reserved. |
3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
5 | 5 |
6 #include "config.h" | 6 #include "config.h" |
7 | 7 |
8 #include "core/css/invalidation/StyleInvalidator.h" | 8 #include "core/css/invalidation/StyleInvalidator.h" |
9 | 9 |
10 #include "core/css/invalidation/DescendantInvalidationSet.h" | 10 #include "core/css/invalidation/DescendantInvalidationSet.h" |
11 #include "core/dom/Document.h" | 11 #include "core/dom/Document.h" |
12 #include "core/dom/Element.h" | 12 #include "core/dom/Element.h" |
13 #include "core/dom/ElementTraversal.h" | 13 #include "core/dom/ElementTraversal.h" |
14 #include "core/dom/shadow/ElementShadow.h" | 14 #include "core/dom/shadow/ElementShadow.h" |
15 #include "core/dom/shadow/ShadowRoot.h" | 15 #include "core/dom/shadow/ShadowRoot.h" |
16 #include "core/rendering/RenderObject.h" | 16 #include "core/rendering/RenderObject.h" |
17 | 17 |
18 namespace blink { | 18 namespace blink { |
19 | 19 |
20 void StyleInvalidator::invalidate(Document& document) | 20 void StyleInvalidator::invalidate(Document& document) |
21 { | 21 { |
| 22 RecursionData recursionData; |
22 if (Element* documentElement = document.documentElement()) | 23 if (Element* documentElement = document.documentElement()) |
23 invalidate(*documentElement); | 24 invalidate(*documentElement, recursionData); |
24 document.clearChildNeedsStyleInvalidation(); | 25 document.clearChildNeedsStyleInvalidation(); |
25 document.clearNeedsStyleInvalidation(); | 26 document.clearNeedsStyleInvalidation(); |
26 clearPendingInvalidations(); | 27 clearPendingInvalidations(); |
27 } | 28 } |
28 | 29 |
29 void StyleInvalidator::scheduleInvalidation(PassRefPtrWillBeRawPtr<DescendantInv
alidationSet> invalidationSet, Element& element) | 30 void StyleInvalidator::scheduleInvalidation(PassRefPtrWillBeRawPtr<DescendantInv
alidationSet> invalidationSet, Element& element) |
30 { | 31 { |
31 ASSERT(element.inActiveDocument()); | 32 ASSERT(element.inActiveDocument()); |
32 ASSERT(element.styleChangeType() < SubtreeStyleChange); | 33 ASSERT(element.styleChangeType() < SubtreeStyleChange); |
33 InvalidationList& list = ensurePendingInvalidationList(element); | 34 InvalidationList& list = ensurePendingInvalidationList(element); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 return true; | 90 return true; |
90 | 91 |
91 for (InvalidationSets::iterator it = m_invalidationSets.begin(); it != m_inv
alidationSets.end(); ++it) { | 92 for (InvalidationSets::iterator it = m_invalidationSets.begin(); it != m_inv
alidationSets.end(); ++it) { |
92 if ((*it)->invalidatesElement(element)) | 93 if ((*it)->invalidatesElement(element)) |
93 return true; | 94 return true; |
94 } | 95 } |
95 | 96 |
96 return false; | 97 return false; |
97 } | 98 } |
98 | 99 |
99 bool StyleInvalidator::checkInvalidationSetsAgainstElement(Element& element) | 100 bool StyleInvalidator::checkInvalidationSetsAgainstElement(Element& element, Sty
leInvalidator::RecursionData& recursionData) |
100 { | 101 { |
101 if (element.styleChangeType() >= SubtreeStyleChange || m_recursionData.whole
SubtreeInvalid()) { | 102 if (element.styleChangeType() >= SubtreeStyleChange || recursionData.wholeSu
btreeInvalid()) { |
102 m_recursionData.setWholeSubtreeInvalid(); | 103 recursionData.setWholeSubtreeInvalid(); |
103 return false; | 104 return false; |
104 } | 105 } |
105 if (element.needsStyleInvalidation()) { | 106 if (element.needsStyleInvalidation()) { |
106 if (InvalidationList* invalidationList = m_pendingInvalidationMap.get(&e
lement)) { | 107 if (InvalidationList* invalidationList = m_pendingInvalidationMap.get(&e
lement)) { |
107 for (InvalidationList::const_iterator it = invalidationList->begin()
; it != invalidationList->end(); ++it) | 108 for (InvalidationList::const_iterator it = invalidationList->begin()
; it != invalidationList->end(); ++it) |
108 m_recursionData.pushInvalidationSet(**it); | 109 recursionData.pushInvalidationSet(**it); |
109 // FIXME: It's really only necessary to clone the render style for t
his element, not full style recalc. | 110 // FIXME: It's really only necessary to clone the render style for t
his element, not full style recalc. |
110 return true; | 111 return true; |
111 } | 112 } |
112 } | 113 } |
113 return m_recursionData.matchesCurrentInvalidationSets(element); | 114 return recursionData.matchesCurrentInvalidationSets(element); |
114 } | 115 } |
115 | 116 |
116 bool StyleInvalidator::invalidateChildren(Element& element) | 117 bool StyleInvalidator::invalidateChildren(Element& element, StyleInvalidator::Re
cursionData& recursionData) |
117 { | 118 { |
118 bool someChildrenNeedStyleRecalc = false; | 119 bool someChildrenNeedStyleRecalc = false; |
119 for (ShadowRoot* root = element.youngestShadowRoot(); root; root = root->old
erShadowRoot()) { | 120 for (ShadowRoot* root = element.youngestShadowRoot(); root; root = root->old
erShadowRoot()) { |
120 if (!m_recursionData.treeBoundaryCrossing() && !root->childNeedsStyleInv
alidation() && !root->needsStyleInvalidation()) | 121 if (!recursionData.treeBoundaryCrossing() && !root->childNeedsStyleInval
idation() && !root->needsStyleInvalidation()) |
121 continue; | 122 continue; |
122 for (Element* child = ElementTraversal::firstChild(*root); child; child
= ElementTraversal::nextSibling(*child)) { | 123 for (Element* child = ElementTraversal::firstChild(*root); child; child
= ElementTraversal::nextSibling(*child)) { |
123 bool childRecalced = invalidate(*child); | 124 bool childRecalced = invalidate(*child, recursionData); |
124 someChildrenNeedStyleRecalc = someChildrenNeedStyleRecalc || childRe
calced; | 125 someChildrenNeedStyleRecalc = someChildrenNeedStyleRecalc || childRe
calced; |
125 } | 126 } |
126 root->clearChildNeedsStyleInvalidation(); | 127 root->clearChildNeedsStyleInvalidation(); |
127 root->clearNeedsStyleInvalidation(); | 128 root->clearNeedsStyleInvalidation(); |
128 } | 129 } |
129 for (Element* child = ElementTraversal::firstChild(element); child; child =
ElementTraversal::nextSibling(*child)) { | 130 for (Element* child = ElementTraversal::firstChild(element); child; child =
ElementTraversal::nextSibling(*child)) { |
130 bool childRecalced = invalidate(*child); | 131 bool childRecalced = invalidate(*child, recursionData); |
131 someChildrenNeedStyleRecalc = someChildrenNeedStyleRecalc || childRecalc
ed; | 132 someChildrenNeedStyleRecalc = someChildrenNeedStyleRecalc || childRecalc
ed; |
132 } | 133 } |
133 return someChildrenNeedStyleRecalc; | 134 return someChildrenNeedStyleRecalc; |
134 } | 135 } |
135 | 136 |
136 bool StyleInvalidator::invalidate(Element& element) | 137 bool StyleInvalidator::invalidate(Element& element, StyleInvalidator::RecursionD
ata& recursionData) |
137 { | 138 { |
138 RecursionCheckpoint checkpoint(&m_recursionData); | 139 RecursionCheckpoint checkpoint(&recursionData); |
139 | 140 |
140 bool thisElementNeedsStyleRecalc = checkInvalidationSetsAgainstElement(eleme
nt); | 141 bool thisElementNeedsStyleRecalc = checkInvalidationSetsAgainstElement(eleme
nt, recursionData); |
141 | 142 |
142 bool someChildrenNeedStyleRecalc = false; | 143 bool someChildrenNeedStyleRecalc = false; |
143 if (m_recursionData.hasInvalidationSets() || element.childNeedsStyleInvalida
tion()) | 144 if (recursionData.hasInvalidationSets() || element.childNeedsStyleInvalidati
on()) |
144 someChildrenNeedStyleRecalc = invalidateChildren(element); | 145 someChildrenNeedStyleRecalc = invalidateChildren(element, recursionData)
; |
145 | 146 |
146 if (thisElementNeedsStyleRecalc) { | 147 if (thisElementNeedsStyleRecalc) { |
147 element.setNeedsStyleRecalc(m_recursionData.wholeSubtreeInvalid() ? Subt
reeStyleChange : LocalStyleChange); | 148 element.setNeedsStyleRecalc(recursionData.wholeSubtreeInvalid() ? Subtre
eStyleChange : LocalStyleChange); |
148 } else if (m_recursionData.hasInvalidationSets() && someChildrenNeedStyleRec
alc) { | 149 } else if (recursionData.hasInvalidationSets() && someChildrenNeedStyleRecal
c) { |
149 // Clone the RenderStyle in order to preserve correct style sharing, if
possible. Otherwise recalc style. | 150 // Clone the RenderStyle in order to preserve correct style sharing, if
possible. Otherwise recalc style. |
150 if (RenderObject* renderer = element.renderer()) | 151 if (RenderObject* renderer = element.renderer()) |
151 renderer->setStyleInternal(RenderStyle::clone(renderer->style())); | 152 renderer->setStyleInternal(RenderStyle::clone(renderer->style())); |
152 else | 153 else |
153 element.setNeedsStyleRecalc(LocalStyleChange); | 154 element.setNeedsStyleRecalc(LocalStyleChange); |
154 } | 155 } |
155 | 156 |
156 element.clearChildNeedsStyleInvalidation(); | 157 element.clearChildNeedsStyleInvalidation(); |
157 element.clearNeedsStyleInvalidation(); | 158 element.clearNeedsStyleInvalidation(); |
158 | 159 |
159 return thisElementNeedsStyleRecalc; | 160 return thisElementNeedsStyleRecalc; |
160 } | 161 } |
161 | 162 |
162 void StyleInvalidator::trace(Visitor* visitor) | 163 void StyleInvalidator::trace(Visitor* visitor) |
163 { | 164 { |
164 #if ENABLE(OILPAN) | 165 #if ENABLE(OILPAN) |
165 visitor->trace(m_pendingInvalidationMap); | 166 visitor->trace(m_pendingInvalidationMap); |
166 #endif | 167 #endif |
167 } | 168 } |
168 | 169 |
169 } // namespace blink | 170 } // namespace blink |
OLD | NEW |