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 invalidate(*documentElement, recursionData); |
25 document.clearChildNeedsStyleInvalidation(); | 26 document.clearChildNeedsStyleInvalidation(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 return; | 80 return; |
80 } | 81 } |
81 m_invalidationSets.append(&invalidationSet); | 82 m_invalidationSets.append(&invalidationSet); |
82 m_invalidateCustomPseudo = invalidationSet.customPseudoInvalid(); | 83 m_invalidateCustomPseudo = invalidationSet.customPseudoInvalid(); |
83 } | 84 } |
84 | 85 |
85 bool StyleInvalidator::RecursionData::matchesCurrentInvalidationSets(Element& el
ement) | 86 bool StyleInvalidator::RecursionData::matchesCurrentInvalidationSets(Element& el
ement) |
86 { | 87 { |
87 ASSERT(!m_wholeSubtreeInvalid); | 88 ASSERT(!m_wholeSubtreeInvalid); |
88 | 89 |
89 if (m_invalidateCustomPseudo && element.shadowPseudoId() != nullAtom) | 90 if (m_invalidateCustomPseudo && element.shadowPseudoId() != nullAtom) { |
| 91 TRACE_STYLE_INVALIDATOR_INVALIDATION(element, InvalidateCustomPseudo); |
90 return true; | 92 return true; |
| 93 } |
91 | 94 |
92 for (InvalidationSets::iterator it = m_invalidationSets.begin(); it != m_inv
alidationSets.end(); ++it) { | 95 for (InvalidationSets::iterator it = m_invalidationSets.begin(); it != m_inv
alidationSets.end(); ++it) { |
93 if ((*it)->invalidatesElement(element)) | 96 if ((*it)->invalidatesElement(element)) |
94 return true; | 97 return true; |
95 } | 98 } |
96 | 99 |
97 return false; | 100 return false; |
98 } | 101 } |
99 | 102 |
100 bool StyleInvalidator::checkInvalidationSetsAgainstElement(Element& element, Sty
leInvalidator::RecursionData& recursionData) | 103 bool StyleInvalidator::checkInvalidationSetsAgainstElement(Element& element, Sty
leInvalidator::RecursionData& recursionData) |
101 { | 104 { |
102 if (element.styleChangeType() >= SubtreeStyleChange || recursionData.wholeSu
btreeInvalid()) { | 105 if (element.styleChangeType() >= SubtreeStyleChange || recursionData.wholeSu
btreeInvalid()) { |
103 recursionData.setWholeSubtreeInvalid(); | 106 recursionData.setWholeSubtreeInvalid(); |
104 return false; | 107 return false; |
105 } | 108 } |
106 if (element.needsStyleInvalidation()) { | 109 if (element.needsStyleInvalidation()) { |
107 if (InvalidationList* invalidationList = m_pendingInvalidationMap.get(&e
lement)) { | 110 if (InvalidationList* invalidationList = m_pendingInvalidationMap.get(&e
lement)) { |
108 for (InvalidationList::const_iterator it = invalidationList->begin()
; it != invalidationList->end(); ++it) | 111 for (InvalidationList::const_iterator it = invalidationList->begin()
; it != invalidationList->end(); ++it) |
109 recursionData.pushInvalidationSet(**it); | 112 recursionData.pushInvalidationSet(**it); |
110 // FIXME: It's really only necessary to clone the render style for t
his element, not full style recalc. | 113 // FIXME: It's really only necessary to clone the render style for t
his element, not full style recalc. |
| 114 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.in
validationTracking"), |
| 115 "StyleInvalidatorInvalidationTracking", |
| 116 "data", InspectorStyleInvalidatorInvalidateEvent::invalidationLi
st(element, *invalidationList)); |
111 return true; | 117 return true; |
112 } | 118 } |
113 } | 119 } |
| 120 |
114 return recursionData.matchesCurrentInvalidationSets(element); | 121 return recursionData.matchesCurrentInvalidationSets(element); |
115 } | 122 } |
116 | 123 |
117 bool StyleInvalidator::invalidateChildren(Element& element, StyleInvalidator::Re
cursionData& recursionData) | 124 bool StyleInvalidator::invalidateChildren(Element& element, StyleInvalidator::Re
cursionData& recursionData) |
118 { | 125 { |
119 bool someChildrenNeedStyleRecalc = false; | 126 bool someChildrenNeedStyleRecalc = false; |
120 for (ShadowRoot* root = element.youngestShadowRoot(); root; root = root->old
erShadowRoot()) { | 127 for (ShadowRoot* root = element.youngestShadowRoot(); root; root = root->old
erShadowRoot()) { |
121 if (!recursionData.treeBoundaryCrossing() && !root->childNeedsStyleInval
idation() && !root->needsStyleInvalidation()) | 128 if (!recursionData.treeBoundaryCrossing() && !root->childNeedsStyleInval
idation() && !root->needsStyleInvalidation()) |
122 continue; | 129 continue; |
123 for (Element* child = ElementTraversal::firstChild(*root); child; child
= ElementTraversal::nextSibling(*child)) { | 130 for (Element* child = ElementTraversal::firstChild(*root); child; child
= ElementTraversal::nextSibling(*child)) { |
(...skipping 17 matching lines...) Expand all Loading... |
141 bool thisElementNeedsStyleRecalc = checkInvalidationSetsAgainstElement(eleme
nt, recursionData); | 148 bool thisElementNeedsStyleRecalc = checkInvalidationSetsAgainstElement(eleme
nt, recursionData); |
142 | 149 |
143 bool someChildrenNeedStyleRecalc = false; | 150 bool someChildrenNeedStyleRecalc = false; |
144 if (recursionData.hasInvalidationSets() || element.childNeedsStyleInvalidati
on()) | 151 if (recursionData.hasInvalidationSets() || element.childNeedsStyleInvalidati
on()) |
145 someChildrenNeedStyleRecalc = invalidateChildren(element, recursionData)
; | 152 someChildrenNeedStyleRecalc = invalidateChildren(element, recursionData)
; |
146 | 153 |
147 if (thisElementNeedsStyleRecalc) { | 154 if (thisElementNeedsStyleRecalc) { |
148 element.setNeedsStyleRecalc(recursionData.wholeSubtreeInvalid() ? Subtre
eStyleChange : LocalStyleChange, StyleChangeReasonForTracing::create(StyleChange
Reason::StyleInvalidator)); | 155 element.setNeedsStyleRecalc(recursionData.wholeSubtreeInvalid() ? Subtre
eStyleChange : LocalStyleChange, StyleChangeReasonForTracing::create(StyleChange
Reason::StyleInvalidator)); |
149 } else if (recursionData.hasInvalidationSets() && someChildrenNeedStyleRecal
c) { | 156 } else if (recursionData.hasInvalidationSets() && someChildrenNeedStyleRecal
c) { |
150 // Clone the RenderStyle in order to preserve correct style sharing, if
possible. Otherwise recalc style. | 157 // Clone the RenderStyle in order to preserve correct style sharing, if
possible. Otherwise recalc style. |
151 if (RenderObject* renderer = element.renderer()) | 158 if (RenderObject* renderer = element.renderer()) { |
152 renderer->setStyleInternal(RenderStyle::clone(renderer->style())); | 159 renderer->setStyleInternal(RenderStyle::clone(renderer->style())); |
153 else | 160 } else { |
| 161 TRACE_STYLE_INVALIDATOR_INVALIDATION(element, PreventStyleSharingFor
Parent); |
154 element.setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTr
acing::create(StyleChangeReason::StyleInvalidator)); | 162 element.setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTr
acing::create(StyleChangeReason::StyleInvalidator)); |
| 163 } |
155 } | 164 } |
156 | 165 |
157 element.clearChildNeedsStyleInvalidation(); | 166 element.clearChildNeedsStyleInvalidation(); |
158 element.clearNeedsStyleInvalidation(); | 167 element.clearNeedsStyleInvalidation(); |
159 | 168 |
160 return thisElementNeedsStyleRecalc; | 169 return thisElementNeedsStyleRecalc; |
161 } | 170 } |
162 | 171 |
163 void StyleInvalidator::trace(Visitor* visitor) | 172 void StyleInvalidator::trace(Visitor* visitor) |
164 { | 173 { |
165 #if ENABLE(OILPAN) | 174 #if ENABLE(OILPAN) |
166 visitor->trace(m_pendingInvalidationMap); | 175 visitor->trace(m_pendingInvalidationMap); |
167 #endif | 176 #endif |
168 } | 177 } |
169 | 178 |
170 } // namespace blink | 179 } // namespace blink |
OLD | NEW |