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/inspector/InspectorTraceEvents.h" |
16 #include "core/rendering/RenderObject.h" | 17 #include "core/rendering/RenderObject.h" |
17 | 18 |
18 namespace blink { | 19 namespace blink { |
19 | 20 |
20 void StyleInvalidator::invalidate(Document& document) | 21 void StyleInvalidator::invalidate(Document& document) |
21 { | 22 { |
22 RecursionData recursionData; | 23 RecursionData recursionData; |
23 if (Element* documentElement = document.documentElement()) | 24 if (Element* documentElement = document.documentElement()) { |
24 invalidate(*documentElement, recursionData); | 25 bool isTracingEnabled; |
| 26 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("devtools.t
imeline.invalidationTracking"), &isTracingEnabled); |
| 27 |
| 28 if (isTracingEnabled) |
| 29 invalidate<StyleInvalidationTracingEnabled>(*documentElement, recurs
ionData); |
| 30 else |
| 31 invalidate<StyleInvalidationTracingDisabled>(*documentElement, recur
sionData); |
| 32 } |
25 document.clearChildNeedsStyleInvalidation(); | 33 document.clearChildNeedsStyleInvalidation(); |
26 document.clearNeedsStyleInvalidation(); | 34 document.clearNeedsStyleInvalidation(); |
27 clearPendingInvalidations(); | 35 clearPendingInvalidations(); |
28 } | 36 } |
29 | 37 |
30 void StyleInvalidator::scheduleInvalidation(PassRefPtrWillBeRawPtr<DescendantInv
alidationSet> invalidationSet, Element& element) | 38 void StyleInvalidator::scheduleInvalidation(PassRefPtrWillBeRawPtr<DescendantInv
alidationSet> invalidationSet, Element& element) |
31 { | 39 { |
32 ASSERT(element.inActiveDocument()); | 40 ASSERT(element.inActiveDocument()); |
33 ASSERT(element.styleChangeType() < SubtreeStyleChange); | 41 ASSERT(element.styleChangeType() < SubtreeStyleChange); |
34 InvalidationList& list = ensurePendingInvalidationList(element); | 42 InvalidationList& list = ensurePendingInvalidationList(element); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 if (invalidationSet.treeBoundaryCrossing()) | 83 if (invalidationSet.treeBoundaryCrossing()) |
76 m_treeBoundaryCrossing = true; | 84 m_treeBoundaryCrossing = true; |
77 if (invalidationSet.wholeSubtreeInvalid()) { | 85 if (invalidationSet.wholeSubtreeInvalid()) { |
78 m_wholeSubtreeInvalid = true; | 86 m_wholeSubtreeInvalid = true; |
79 return; | 87 return; |
80 } | 88 } |
81 m_invalidationSets.append(&invalidationSet); | 89 m_invalidationSets.append(&invalidationSet); |
82 m_invalidateCustomPseudo = invalidationSet.customPseudoInvalid(); | 90 m_invalidateCustomPseudo = invalidationSet.customPseudoInvalid(); |
83 } | 91 } |
84 | 92 |
| 93 template <StyleInvalidationTracingEnabledFlag styleInvalidationTracingEnabled> |
85 bool StyleInvalidator::RecursionData::matchesCurrentInvalidationSets(Element& el
ement) | 94 bool StyleInvalidator::RecursionData::matchesCurrentInvalidationSets(Element& el
ement) |
86 { | 95 { |
87 ASSERT(!m_wholeSubtreeInvalid); | 96 ASSERT(!m_wholeSubtreeInvalid); |
88 | 97 |
89 if (m_invalidateCustomPseudo && element.shadowPseudoId() != nullAtom) | 98 if (m_invalidateCustomPseudo && element.shadowPseudoId() != nullAtom) { |
| 99 if (styleInvalidationTracingEnabled == StyleInvalidationTracingEnabled) |
| 100 TRACE_STYLE_INVALIDATOR_INVALIDATION(element, InvalidateCustomPseudo
); |
| 101 |
90 return true; | 102 return true; |
| 103 } |
91 | 104 |
92 for (InvalidationSets::iterator it = m_invalidationSets.begin(); it != m_inv
alidationSets.end(); ++it) { | 105 for (InvalidationSets::iterator it = m_invalidationSets.begin(); it != m_inv
alidationSets.end(); ++it) { |
93 if ((*it)->invalidatesElement(element)) | 106 if ((*it)->invalidatesElement<styleInvalidationTracingEnabled>(element)) |
94 return true; | 107 return true; |
95 } | 108 } |
96 | 109 |
97 return false; | 110 return false; |
98 } | 111 } |
99 | 112 |
| 113 template <StyleInvalidationTracingEnabledFlag styleInvalidationTracingEnabled> |
100 bool StyleInvalidator::checkInvalidationSetsAgainstElement(Element& element, Sty
leInvalidator::RecursionData& recursionData) | 114 bool StyleInvalidator::checkInvalidationSetsAgainstElement(Element& element, Sty
leInvalidator::RecursionData& recursionData) |
101 { | 115 { |
102 if (element.styleChangeType() >= SubtreeStyleChange || recursionData.wholeSu
btreeInvalid()) { | 116 if (element.styleChangeType() >= SubtreeStyleChange || recursionData.wholeSu
btreeInvalid()) { |
103 recursionData.setWholeSubtreeInvalid(); | 117 recursionData.setWholeSubtreeInvalid(); |
104 return false; | 118 return false; |
105 } | 119 } |
106 if (element.needsStyleInvalidation()) { | 120 if (element.needsStyleInvalidation()) { |
107 if (InvalidationList* invalidationList = m_pendingInvalidationMap.get(&e
lement)) { | 121 if (InvalidationList* invalidationList = m_pendingInvalidationMap.get(&e
lement)) { |
108 for (InvalidationList::const_iterator it = invalidationList->begin()
; it != invalidationList->end(); ++it) | 122 for (InvalidationList::const_iterator it = invalidationList->begin()
; it != invalidationList->end(); ++it) |
109 recursionData.pushInvalidationSet(**it); | 123 recursionData.pushInvalidationSet(**it); |
110 // FIXME: It's really only necessary to clone the render style for t
his element, not full style recalc. | 124 // FIXME: It's really only necessary to clone the render style for t
his element, not full style recalc. |
| 125 if (styleInvalidationTracingEnabled == StyleInvalidationTracingEnabl
ed) { |
| 126 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timelin
e.invalidationTracking"), |
| 127 "StyleInvalidatorInvalidationTracking", |
| 128 "data", InspectorStyleInvalidatorInvalidateEvent::invalidati
onList(element, *invalidationList)); |
| 129 } |
111 return true; | 130 return true; |
112 } | 131 } |
113 } | 132 } |
114 return recursionData.matchesCurrentInvalidationSets(element); | 133 |
| 134 return recursionData.matchesCurrentInvalidationSets<styleInvalidationTracing
Enabled>(element); |
115 } | 135 } |
116 | 136 |
| 137 template <StyleInvalidationTracingEnabledFlag styleInvalidationTracingEnabled> |
117 bool StyleInvalidator::invalidateChildren(Element& element, StyleInvalidator::Re
cursionData& recursionData) | 138 bool StyleInvalidator::invalidateChildren(Element& element, StyleInvalidator::Re
cursionData& recursionData) |
118 { | 139 { |
119 bool someChildrenNeedStyleRecalc = false; | 140 bool someChildrenNeedStyleRecalc = false; |
120 for (ShadowRoot* root = element.youngestShadowRoot(); root; root = root->old
erShadowRoot()) { | 141 for (ShadowRoot* root = element.youngestShadowRoot(); root; root = root->old
erShadowRoot()) { |
121 if (!recursionData.treeBoundaryCrossing() && !root->childNeedsStyleInval
idation() && !root->needsStyleInvalidation()) | 142 if (!recursionData.treeBoundaryCrossing() && !root->childNeedsStyleInval
idation() && !root->needsStyleInvalidation()) |
122 continue; | 143 continue; |
123 for (Element* child = ElementTraversal::firstChild(*root); child; child
= ElementTraversal::nextSibling(*child)) { | 144 for (Element* child = ElementTraversal::firstChild(*root); child; child
= ElementTraversal::nextSibling(*child)) { |
124 bool childRecalced = invalidate(*child, recursionData); | 145 bool childRecalced = invalidate<styleInvalidationTracingEnabled>(*ch
ild, recursionData); |
125 someChildrenNeedStyleRecalc = someChildrenNeedStyleRecalc || childRe
calced; | 146 someChildrenNeedStyleRecalc = someChildrenNeedStyleRecalc || childRe
calced; |
126 } | 147 } |
127 root->clearChildNeedsStyleInvalidation(); | 148 root->clearChildNeedsStyleInvalidation(); |
128 root->clearNeedsStyleInvalidation(); | 149 root->clearNeedsStyleInvalidation(); |
129 } | 150 } |
130 for (Element* child = ElementTraversal::firstChild(element); child; child =
ElementTraversal::nextSibling(*child)) { | 151 for (Element* child = ElementTraversal::firstChild(element); child; child =
ElementTraversal::nextSibling(*child)) { |
131 bool childRecalced = invalidate(*child, recursionData); | 152 bool childRecalced = invalidate<styleInvalidationTracingEnabled>(*child,
recursionData); |
132 someChildrenNeedStyleRecalc = someChildrenNeedStyleRecalc || childRecalc
ed; | 153 someChildrenNeedStyleRecalc = someChildrenNeedStyleRecalc || childRecalc
ed; |
133 } | 154 } |
134 return someChildrenNeedStyleRecalc; | 155 return someChildrenNeedStyleRecalc; |
135 } | 156 } |
136 | 157 |
| 158 template <StyleInvalidationTracingEnabledFlag styleInvalidationTracingEnabled> |
137 bool StyleInvalidator::invalidate(Element& element, StyleInvalidator::RecursionD
ata& recursionData) | 159 bool StyleInvalidator::invalidate(Element& element, StyleInvalidator::RecursionD
ata& recursionData) |
138 { | 160 { |
139 RecursionCheckpoint checkpoint(&recursionData); | 161 RecursionCheckpoint checkpoint(&recursionData); |
140 | 162 |
141 bool thisElementNeedsStyleRecalc = checkInvalidationSetsAgainstElement(eleme
nt, recursionData); | 163 bool thisElementNeedsStyleRecalc = checkInvalidationSetsAgainstElement<style
InvalidationTracingEnabled>(element, recursionData); |
142 | 164 |
143 bool someChildrenNeedStyleRecalc = false; | 165 bool someChildrenNeedStyleRecalc = false; |
144 if (recursionData.hasInvalidationSets() || element.childNeedsStyleInvalidati
on()) | 166 if (recursionData.hasInvalidationSets() || element.childNeedsStyleInvalidati
on()) |
145 someChildrenNeedStyleRecalc = invalidateChildren(element, recursionData)
; | 167 someChildrenNeedStyleRecalc = invalidateChildren<styleInvalidationTracin
gEnabled>(element, recursionData); |
146 | 168 |
147 if (thisElementNeedsStyleRecalc) { | 169 if (thisElementNeedsStyleRecalc) { |
148 element.setNeedsStyleRecalc(recursionData.wholeSubtreeInvalid() ? Subtre
eStyleChange : LocalStyleChange, StyleChangeReasonForTracing::create(StyleChange
Reason::StyleInvalidator)); | 170 element.setNeedsStyleRecalc(recursionData.wholeSubtreeInvalid() ? Subtre
eStyleChange : LocalStyleChange, StyleChangeReasonForTracing::create(StyleChange
Reason::StyleInvalidator)); |
149 } else if (recursionData.hasInvalidationSets() && someChildrenNeedStyleRecal
c) { | 171 } else if (recursionData.hasInvalidationSets() && someChildrenNeedStyleRecal
c) { |
150 // Clone the RenderStyle in order to preserve correct style sharing, if
possible. Otherwise recalc style. | 172 // Clone the RenderStyle in order to preserve correct style sharing, if
possible. Otherwise recalc style. |
151 if (RenderObject* renderer = element.renderer()) | 173 if (RenderObject* renderer = element.renderer()) { |
152 renderer->setStyleInternal(RenderStyle::clone(renderer->style())); | 174 renderer->setStyleInternal(RenderStyle::clone(renderer->style())); |
153 else | 175 } else { |
| 176 if (styleInvalidationTracingEnabled == StyleInvalidationTracingEnabl
ed) |
| 177 TRACE_STYLE_INVALIDATOR_INVALIDATION(element, PreventStyleSharin
gForParent); |
154 element.setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTr
acing::create(StyleChangeReason::StyleInvalidator)); | 178 element.setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTr
acing::create(StyleChangeReason::StyleInvalidator)); |
| 179 } |
155 } | 180 } |
156 | 181 |
157 element.clearChildNeedsStyleInvalidation(); | 182 element.clearChildNeedsStyleInvalidation(); |
158 element.clearNeedsStyleInvalidation(); | 183 element.clearNeedsStyleInvalidation(); |
159 | 184 |
160 return thisElementNeedsStyleRecalc; | 185 return thisElementNeedsStyleRecalc; |
161 } | 186 } |
162 | 187 |
163 void StyleInvalidator::trace(Visitor* visitor) | 188 void StyleInvalidator::trace(Visitor* visitor) |
164 { | 189 { |
165 #if ENABLE(OILPAN) | 190 #if ENABLE(OILPAN) |
166 visitor->trace(m_pendingInvalidationMap); | 191 visitor->trace(m_pendingInvalidationMap); |
167 #endif | 192 #endif |
168 } | 193 } |
169 | 194 |
170 } // namespace blink | 195 } // namespace blink |
OLD | NEW |