Chromium Code Reviews| 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 |
| 21 static const unsigned char* s_tracingEnabled = nullptr; | |
| 22 | |
| 20 void StyleInvalidator::invalidate(Document& document) | 23 void StyleInvalidator::invalidate(Document& document) |
| 21 { | 24 { |
| 22 RecursionData recursionData; | 25 RecursionData recursionData; |
| 23 if (Element* documentElement = document.documentElement()) | 26 if (Element* documentElement = document.documentElement()) |
| 24 invalidate(*documentElement, recursionData); | 27 invalidate(*documentElement, recursionData); |
| 25 document.clearChildNeedsStyleInvalidation(); | 28 document.clearChildNeedsStyleInvalidation(); |
| 26 document.clearNeedsStyleInvalidation(); | 29 document.clearNeedsStyleInvalidation(); |
| 27 clearPendingInvalidations(); | 30 clearPendingInvalidations(); |
| 28 } | 31 } |
| 29 | 32 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 54 { | 57 { |
| 55 if (node.isElementNode() && node.needsStyleInvalidation()) | 58 if (node.isElementNode() && node.needsStyleInvalidation()) |
| 56 m_pendingInvalidationMap.remove(toElement(&node)); | 59 m_pendingInvalidationMap.remove(toElement(&node)); |
| 57 } | 60 } |
| 58 | 61 |
| 59 void StyleInvalidator::clearPendingInvalidations() | 62 void StyleInvalidator::clearPendingInvalidations() |
| 60 { | 63 { |
| 61 m_pendingInvalidationMap.clear(); | 64 m_pendingInvalidationMap.clear(); |
| 62 } | 65 } |
| 63 | 66 |
| 67 void StyleInvalidator::init() | |
| 68 { | |
| 69 s_tracingEnabled = TRACE_EVENT_API_GET_CATEGORY_ENABLED(TRACE_DISABLED_BY_DE FAULT("devtools.timeline.invalidationTracking")); | |
| 70 } | |
| 71 | |
| 64 StyleInvalidator::StyleInvalidator() | 72 StyleInvalidator::StyleInvalidator() |
| 65 { | 73 { |
| 66 } | 74 } |
| 67 | 75 |
| 68 StyleInvalidator::~StyleInvalidator() | 76 StyleInvalidator::~StyleInvalidator() |
| 69 { | 77 { |
| 70 } | 78 } |
| 71 | 79 |
| 72 void StyleInvalidator::RecursionData::pushInvalidationSet(const DescendantInvali dationSet& invalidationSet) | 80 void StyleInvalidator::RecursionData::pushInvalidationSet(const DescendantInvali dationSet& invalidationSet) |
| 73 { | 81 { |
| 74 ASSERT(!m_wholeSubtreeInvalid); | 82 ASSERT(!m_wholeSubtreeInvalid); |
| 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 |
| 85 bool StyleInvalidator::RecursionData::matchesCurrentInvalidationSets(Element& el ement) | 93 ALWAYS_INLINE bool StyleInvalidator::RecursionData::matchesCurrentInvalidationSe ts(Element& element) |
| 86 { | 94 { |
| 87 ASSERT(!m_wholeSubtreeInvalid); | 95 ASSERT(!m_wholeSubtreeInvalid); |
| 88 | 96 |
| 89 if (m_invalidateCustomPseudo && element.shadowPseudoId() != nullAtom) | 97 if (m_invalidateCustomPseudo && element.shadowPseudoId() != nullAtom) { |
| 98 if (UNLIKELY(*s_tracingEnabled)) | |
|
pdr.
2014/10/14 01:36:47
Can you break this unlikely out into a macro using
kouhei (in TOK)
2014/10/14 02:02:10
Done.
| |
| 99 TRACE_STYLE_INVALIDATOR_INVALIDATION(element, InvalidateCustomPseudo ); | |
| 90 return true; | 100 return true; |
| 101 } | |
| 91 | 102 |
| 92 for (const auto& invalidationSet : m_invalidationSets) { | 103 for (const auto& invalidationSet : m_invalidationSets) { |
| 93 if (invalidationSet->invalidatesElement(element)) | 104 if (invalidationSet->invalidatesElement(element)) |
| 94 return true; | 105 return true; |
| 95 } | 106 } |
| 96 | 107 |
| 97 return false; | 108 return false; |
| 98 } | 109 } |
| 99 | 110 |
| 100 bool StyleInvalidator::checkInvalidationSetsAgainstElement(Element& element, Sty leInvalidator::RecursionData& recursionData) | 111 ALWAYS_INLINE bool StyleInvalidator::checkInvalidationSetsAgainstElement(Element & element, StyleInvalidator::RecursionData& recursionData) |
| 101 { | 112 { |
| 102 if (element.styleChangeType() >= SubtreeStyleChange || recursionData.wholeSu btreeInvalid()) { | 113 if (element.styleChangeType() >= SubtreeStyleChange || recursionData.wholeSu btreeInvalid()) { |
| 103 recursionData.setWholeSubtreeInvalid(); | 114 recursionData.setWholeSubtreeInvalid(); |
| 104 return false; | 115 return false; |
| 105 } | 116 } |
| 106 if (element.needsStyleInvalidation()) { | 117 if (element.needsStyleInvalidation()) { |
| 107 if (InvalidationList* invalidationList = m_pendingInvalidationMap.get(&e lement)) { | 118 if (InvalidationList* invalidationList = m_pendingInvalidationMap.get(&e lement)) { |
| 108 for (const auto& invalidationSet : *invalidationList) | 119 for (const auto& invalidationSet : *invalidationList) |
| 109 recursionData.pushInvalidationSet(*invalidationSet); | 120 recursionData.pushInvalidationSet(*invalidationSet); |
| 110 // FIXME: It's really only necessary to clone the render style for t his element, not full style recalc. | 121 // FIXME: It's really only necessary to clone the render style for t his element, not full style recalc. |
| 122 if (UNLIKELY(*s_tracingEnabled)) { | |
| 123 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timelin e.invalidationTracking"), | |
| 124 "StyleInvalidatorInvalidationTracking", | |
| 125 "data", InspectorStyleInvalidatorInvalidateEvent::invalidati onList(element, *invalidationList)); | |
| 126 } | |
| 111 return true; | 127 return true; |
| 112 } | 128 } |
| 113 } | 129 } |
| 130 | |
| 114 return recursionData.matchesCurrentInvalidationSets(element); | 131 return recursionData.matchesCurrentInvalidationSets(element); |
| 115 } | 132 } |
| 116 | 133 |
| 117 bool StyleInvalidator::invalidateChildren(Element& element, StyleInvalidator::Re cursionData& recursionData) | 134 bool StyleInvalidator::invalidateChildren(Element& element, StyleInvalidator::Re cursionData& recursionData) |
| 118 { | 135 { |
| 119 bool someChildrenNeedStyleRecalc = false; | 136 bool someChildrenNeedStyleRecalc = false; |
| 120 for (ShadowRoot* root = element.youngestShadowRoot(); root; root = root->old erShadowRoot()) { | 137 for (ShadowRoot* root = element.youngestShadowRoot(); root; root = root->old erShadowRoot()) { |
| 121 if (!recursionData.treeBoundaryCrossing() && !root->childNeedsStyleInval idation() && !root->needsStyleInvalidation()) | 138 if (!recursionData.treeBoundaryCrossing() && !root->childNeedsStyleInval idation() && !root->needsStyleInvalidation()) |
| 122 continue; | 139 continue; |
| 123 for (Element* child = ElementTraversal::firstChild(*root); child; child = ElementTraversal::nextSibling(*child)) { | 140 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); | 158 bool thisElementNeedsStyleRecalc = checkInvalidationSetsAgainstElement(eleme nt, recursionData); |
| 142 | 159 |
| 143 bool someChildrenNeedStyleRecalc = false; | 160 bool someChildrenNeedStyleRecalc = false; |
| 144 if (recursionData.hasInvalidationSets() || element.childNeedsStyleInvalidati on()) | 161 if (recursionData.hasInvalidationSets() || element.childNeedsStyleInvalidati on()) |
| 145 someChildrenNeedStyleRecalc = invalidateChildren(element, recursionData) ; | 162 someChildrenNeedStyleRecalc = invalidateChildren(element, recursionData) ; |
| 146 | 163 |
| 147 if (thisElementNeedsStyleRecalc) { | 164 if (thisElementNeedsStyleRecalc) { |
| 148 element.setNeedsStyleRecalc(recursionData.wholeSubtreeInvalid() ? Subtre eStyleChange : LocalStyleChange, StyleChangeReasonForTracing::create(StyleChange Reason::StyleInvalidator)); | 165 element.setNeedsStyleRecalc(recursionData.wholeSubtreeInvalid() ? Subtre eStyleChange : LocalStyleChange, StyleChangeReasonForTracing::create(StyleChange Reason::StyleInvalidator)); |
| 149 } else if (recursionData.hasInvalidationSets() && someChildrenNeedStyleRecal c) { | 166 } else if (recursionData.hasInvalidationSets() && someChildrenNeedStyleRecal c) { |
| 150 // Clone the RenderStyle in order to preserve correct style sharing, if possible. Otherwise recalc style. | 167 // Clone the RenderStyle in order to preserve correct style sharing, if possible. Otherwise recalc style. |
| 151 if (RenderObject* renderer = element.renderer()) | 168 if (RenderObject* renderer = element.renderer()) { |
| 152 renderer->setStyleInternal(RenderStyle::clone(renderer->style())); | 169 renderer->setStyleInternal(RenderStyle::clone(renderer->style())); |
| 153 else | 170 } else { |
| 171 if (UNLIKELY(*s_tracingEnabled)) | |
| 172 TRACE_STYLE_INVALIDATOR_INVALIDATION(element, PreventStyleSharin gForParent); | |
| 154 element.setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTr acing::create(StyleChangeReason::StyleInvalidator)); | 173 element.setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTr acing::create(StyleChangeReason::StyleInvalidator)); |
| 174 } | |
| 155 } | 175 } |
| 156 | 176 |
| 157 element.clearChildNeedsStyleInvalidation(); | 177 element.clearChildNeedsStyleInvalidation(); |
| 158 element.clearNeedsStyleInvalidation(); | 178 element.clearNeedsStyleInvalidation(); |
| 159 | 179 |
| 160 return thisElementNeedsStyleRecalc; | 180 return thisElementNeedsStyleRecalc; |
| 161 } | 181 } |
| 162 | 182 |
| 163 void StyleInvalidator::trace(Visitor* visitor) | 183 void StyleInvalidator::trace(Visitor* visitor) |
| 164 { | 184 { |
| 165 #if ENABLE(OILPAN) | 185 #if ENABLE(OILPAN) |
| 166 visitor->trace(m_pendingInvalidationMap); | 186 visitor->trace(m_pendingInvalidationMap); |
| 167 #endif | 187 #endif |
| 168 } | 188 } |
| 169 | 189 |
| 170 } // namespace blink | 190 } // namespace blink |
| OLD | NEW |