| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/css/invalidation/DescendantInvalidationSet.h" | 32 #include "core/css/invalidation/InvalidationSet.h" |
| 33 | 33 |
| 34 #include "core/css/resolver/StyleResolver.h" | 34 #include "core/css/resolver/StyleResolver.h" |
| 35 #include "core/dom/Element.h" | 35 #include "core/dom/Element.h" |
| 36 #include "core/inspector/InspectorTraceEvents.h" | 36 #include "core/inspector/InspectorTraceEvents.h" |
| 37 #include "platform/TracedValue.h" | 37 #include "platform/TracedValue.h" |
| 38 #include "wtf/Compiler.h" | 38 #include "wtf/Compiler.h" |
| 39 #include "wtf/text/StringBuilder.h" | 39 #include "wtf/text/StringBuilder.h" |
| 40 | 40 |
| 41 namespace blink { | 41 namespace blink { |
| 42 | 42 |
| 43 static const unsigned char* s_tracingEnabled = nullptr; | 43 static const unsigned char* s_tracingEnabled = nullptr; |
| 44 | 44 |
| 45 #define TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(element, re
ason, invalidationSet, singleSelectorPart) \ | 45 #define TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(element, re
ason, invalidationSet, singleSelectorPart) \ |
| 46 if (UNLIKELY(*s_tracingEnabled)) \ | 46 if (UNLIKELY(*s_tracingEnabled)) \ |
| 47 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART(element, reason, inval
idationSet, singleSelectorPart); | 47 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART(element, reason, inval
idationSet, singleSelectorPart); |
| 48 | 48 |
| 49 void DescendantInvalidationSet::cacheTracingFlag() | 49 void InvalidationSet::cacheTracingFlag() |
| 50 { | 50 { |
| 51 s_tracingEnabled = TRACE_EVENT_API_GET_CATEGORY_ENABLED(TRACE_DISABLED_BY_DE
FAULT("devtools.timeline.invalidationTracking")); | 51 s_tracingEnabled = TRACE_EVENT_API_GET_CATEGORY_ENABLED(TRACE_DISABLED_BY_DE
FAULT("devtools.timeline.invalidationTracking")); |
| 52 } | 52 } |
| 53 | 53 |
| 54 DescendantInvalidationSet::DescendantInvalidationSet() | 54 InvalidationSet::InvalidationSet() |
| 55 : m_allDescendantsMightBeInvalid(false) | 55 : m_maxDirectAdjacentSelectors(1) |
| 56 , m_appliesDirectly(false) |
| 57 , m_allDescendantsMightBeInvalid(false) |
| 56 , m_customPseudoInvalid(false) | 58 , m_customPseudoInvalid(false) |
| 57 , m_treeBoundaryCrossing(false) | 59 , m_treeBoundaryCrossing(false) |
| 58 , m_insertionPointCrossing(false) | 60 , m_insertionPointCrossing(false) |
| 59 { | 61 { |
| 60 } | 62 } |
| 61 | 63 |
| 62 bool DescendantInvalidationSet::invalidatesElement(Element& element) const | 64 bool InvalidationSet::invalidatesElement(Element& element) const |
| 63 { | 65 { |
| 64 if (m_allDescendantsMightBeInvalid) | 66 if (m_allDescendantsMightBeInvalid) |
| 65 return true; | 67 return true; |
| 66 | 68 |
| 67 if (m_tagNames && m_tagNames->contains(element.tagQName().localName())) { | 69 if (m_tagNames && m_tagNames->contains(element.tagQName().localName())) { |
| 68 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(element, In
validationSetMatchedTagName, *this, element.tagQName().localName()); | 70 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(element, In
validationSetMatchedTagName, *this, element.tagQName().localName()); |
| 69 return true; | 71 return true; |
| 70 } | 72 } |
| 71 | 73 |
| 72 if (element.hasID() && m_ids && m_ids->contains(element.idForStyleResolution
())) { | 74 if (element.hasID() && m_ids && m_ids->contains(element.idForStyleResolution
())) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 89 if (element.hasAttribute(attribute)) { | 91 if (element.hasAttribute(attribute)) { |
| 90 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(ele
ment, InvalidationSetMatchedAttribute, *this, attribute); | 92 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(ele
ment, InvalidationSetMatchedAttribute, *this, attribute); |
| 91 return true; | 93 return true; |
| 92 } | 94 } |
| 93 } | 95 } |
| 94 } | 96 } |
| 95 | 97 |
| 96 return false; | 98 return false; |
| 97 } | 99 } |
| 98 | 100 |
| 99 void DescendantInvalidationSet::combine(const DescendantInvalidationSet& other) | 101 void InvalidationSet::combine(const InvalidationSet& other) |
| 100 { | 102 { |
| 103 m_maxDirectAdjacentSelectors = std::max(m_maxDirectAdjacentSelectors, other.
m_maxDirectAdjacentSelectors); |
| 104 |
| 105 if (other.descendants()) |
| 106 ensureInvalidationSet().combine(*other.descendants()); |
| 107 |
| 108 if (other.appliesDirectly()) |
| 109 setAppliesDirectly(); |
| 110 |
| 101 // No longer bother combining data structures, since the whole subtree is de
emed invalid. | 111 // No longer bother combining data structures, since the whole subtree is de
emed invalid. |
| 102 if (wholeSubtreeInvalid()) | 112 if (wholeSubtreeInvalid()) |
| 103 return; | 113 return; |
| 104 | 114 |
| 105 if (other.wholeSubtreeInvalid()) { | 115 if (other.wholeSubtreeInvalid()) { |
| 106 setWholeSubtreeInvalid(); | 116 setWholeSubtreeInvalid(); |
| 107 return; | 117 return; |
| 108 } | 118 } |
| 109 | 119 |
| 110 if (other.customPseudoInvalid()) | 120 if (other.customPseudoInvalid()) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 130 for (const auto& tagName : *other.m_tagNames) | 140 for (const auto& tagName : *other.m_tagNames) |
| 131 addTagName(tagName); | 141 addTagName(tagName); |
| 132 } | 142 } |
| 133 | 143 |
| 134 if (other.m_attributes) { | 144 if (other.m_attributes) { |
| 135 for (const auto& attribute : *other.m_attributes) | 145 for (const auto& attribute : *other.m_attributes) |
| 136 addAttribute(attribute); | 146 addAttribute(attribute); |
| 137 } | 147 } |
| 138 } | 148 } |
| 139 | 149 |
| 140 WillBeHeapHashSet<AtomicString>& DescendantInvalidationSet::ensureClassSet() | 150 WillBeHeapHashSet<AtomicString>& InvalidationSet::ensureClassSet() |
| 141 { | 151 { |
| 142 if (!m_classes) | 152 if (!m_classes) |
| 143 m_classes = adoptPtrWillBeNoop(new WillBeHeapHashSet<AtomicString>); | 153 m_classes = adoptPtrWillBeNoop(new WillBeHeapHashSet<AtomicString>); |
| 144 return *m_classes; | 154 return *m_classes; |
| 145 } | 155 } |
| 146 | 156 |
| 147 WillBeHeapHashSet<AtomicString>& DescendantInvalidationSet::ensureIdSet() | 157 WillBeHeapHashSet<AtomicString>& InvalidationSet::ensureIdSet() |
| 148 { | 158 { |
| 149 if (!m_ids) | 159 if (!m_ids) |
| 150 m_ids = adoptPtrWillBeNoop(new WillBeHeapHashSet<AtomicString>); | 160 m_ids = adoptPtrWillBeNoop(new WillBeHeapHashSet<AtomicString>); |
| 151 return *m_ids; | 161 return *m_ids; |
| 152 } | 162 } |
| 153 | 163 |
| 154 WillBeHeapHashSet<AtomicString>& DescendantInvalidationSet::ensureTagNameSet() | 164 WillBeHeapHashSet<AtomicString>& InvalidationSet::ensureTagNameSet() |
| 155 { | 165 { |
| 156 if (!m_tagNames) | 166 if (!m_tagNames) |
| 157 m_tagNames = adoptPtrWillBeNoop(new WillBeHeapHashSet<AtomicString>); | 167 m_tagNames = adoptPtrWillBeNoop(new WillBeHeapHashSet<AtomicString>); |
| 158 return *m_tagNames; | 168 return *m_tagNames; |
| 159 } | 169 } |
| 160 | 170 |
| 161 WillBeHeapHashSet<AtomicString>& DescendantInvalidationSet::ensureAttributeSet() | 171 WillBeHeapHashSet<AtomicString>& InvalidationSet::ensureAttributeSet() |
| 162 { | 172 { |
| 163 if (!m_attributes) | 173 if (!m_attributes) |
| 164 m_attributes = adoptPtrWillBeNoop(new WillBeHeapHashSet<AtomicString>); | 174 m_attributes = adoptPtrWillBeNoop(new WillBeHeapHashSet<AtomicString>); |
| 165 return *m_attributes; | 175 return *m_attributes; |
| 166 } | 176 } |
| 167 | 177 |
| 168 void DescendantInvalidationSet::addClass(const AtomicString& className) | 178 InvalidationSet& InvalidationSet::ensureInvalidationSet() |
| 179 { |
| 180 if (!m_descendantInvalidationSet) |
| 181 m_descendantInvalidationSet = InvalidationSet::create(); |
| 182 |
| 183 return *m_descendantInvalidationSet; |
| 184 } |
| 185 |
| 186 void InvalidationSet::addClass(const AtomicString& className) |
| 169 { | 187 { |
| 170 if (wholeSubtreeInvalid()) | 188 if (wholeSubtreeInvalid()) |
| 171 return; | 189 return; |
| 172 ensureClassSet().add(className); | 190 ensureClassSet().add(className); |
| 173 } | 191 } |
| 174 | 192 |
| 175 void DescendantInvalidationSet::addId(const AtomicString& id) | 193 void InvalidationSet::addId(const AtomicString& id) |
| 176 { | 194 { |
| 177 if (wholeSubtreeInvalid()) | 195 if (wholeSubtreeInvalid()) |
| 178 return; | 196 return; |
| 179 ensureIdSet().add(id); | 197 ensureIdSet().add(id); |
| 180 } | 198 } |
| 181 | 199 |
| 182 void DescendantInvalidationSet::addTagName(const AtomicString& tagName) | 200 void InvalidationSet::addTagName(const AtomicString& tagName) |
| 183 { | 201 { |
| 184 if (wholeSubtreeInvalid()) | 202 if (wholeSubtreeInvalid()) |
| 185 return; | 203 return; |
| 186 ensureTagNameSet().add(tagName); | 204 ensureTagNameSet().add(tagName); |
| 187 } | 205 } |
| 188 | 206 |
| 189 void DescendantInvalidationSet::addAttribute(const AtomicString& attribute) | 207 void InvalidationSet::addAttribute(const AtomicString& attribute) |
| 190 { | 208 { |
| 191 if (wholeSubtreeInvalid()) | 209 if (wholeSubtreeInvalid()) |
| 192 return; | 210 return; |
| 193 ensureAttributeSet().add(attribute); | 211 ensureAttributeSet().add(attribute); |
| 194 } | 212 } |
| 195 | 213 |
| 196 void DescendantInvalidationSet::setWholeSubtreeInvalid() | 214 void InvalidationSet::setWholeSubtreeInvalid() |
| 197 { | 215 { |
| 198 if (m_allDescendantsMightBeInvalid) | 216 if (m_allDescendantsMightBeInvalid) |
| 199 return; | 217 return; |
| 200 | 218 |
| 201 m_allDescendantsMightBeInvalid = true; | 219 m_allDescendantsMightBeInvalid = true; |
| 202 m_customPseudoInvalid = false; | 220 m_customPseudoInvalid = false; |
| 203 m_treeBoundaryCrossing = false; | 221 m_treeBoundaryCrossing = false; |
| 204 m_insertionPointCrossing = false; | 222 m_insertionPointCrossing = false; |
| 205 m_classes = nullptr; | 223 m_classes = nullptr; |
| 206 m_ids = nullptr; | 224 m_ids = nullptr; |
| 207 m_tagNames = nullptr; | 225 m_tagNames = nullptr; |
| 208 m_attributes = nullptr; | 226 m_attributes = nullptr; |
| 209 } | 227 } |
| 210 | 228 |
| 211 DEFINE_TRACE(DescendantInvalidationSet) | 229 DEFINE_TRACE(InvalidationSet) |
| 212 { | 230 { |
| 213 #if ENABLE(OILPAN) | 231 #if ENABLE(OILPAN) |
| 214 visitor->trace(m_classes); | 232 visitor->trace(m_classes); |
| 215 visitor->trace(m_ids); | 233 visitor->trace(m_ids); |
| 216 visitor->trace(m_tagNames); | 234 visitor->trace(m_tagNames); |
| 217 visitor->trace(m_attributes); | 235 visitor->trace(m_attributes); |
| 236 visitor->trace(m_descendantInvalidationSet); |
| 218 #endif | 237 #endif |
| 219 } | 238 } |
| 220 | 239 |
| 221 void DescendantInvalidationSet::toTracedValue(TracedValue* value) const | 240 void InvalidationSet::toTracedValue(TracedValue* value) const |
| 222 { | 241 { |
| 223 value->beginDictionary(); | 242 value->beginDictionary(); |
| 224 | 243 |
| 225 value->setString("id", descendantInvalidationSetToIdString(*this)); | 244 value->setString("id", descendantInvalidationSetToIdString(*this)); |
| 226 | 245 |
| 227 if (m_allDescendantsMightBeInvalid) | 246 if (m_allDescendantsMightBeInvalid) |
| 228 value->setBoolean("allDescendantsMightBeInvalid", true); | 247 value->setBoolean("allDescendantsMightBeInvalid", true); |
| 229 if (m_customPseudoInvalid) | 248 if (m_customPseudoInvalid) |
| 230 value->setBoolean("customPseudoInvalid", true); | 249 value->setBoolean("customPseudoInvalid", true); |
| 231 if (m_treeBoundaryCrossing) | 250 if (m_treeBoundaryCrossing) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 258 value->beginArray("attributes"); | 277 value->beginArray("attributes"); |
| 259 for (const auto& attribute : *m_attributes) | 278 for (const auto& attribute : *m_attributes) |
| 260 value->pushString(attribute); | 279 value->pushString(attribute); |
| 261 value->endArray(); | 280 value->endArray(); |
| 262 } | 281 } |
| 263 | 282 |
| 264 value->endDictionary(); | 283 value->endDictionary(); |
| 265 } | 284 } |
| 266 | 285 |
| 267 #ifndef NDEBUG | 286 #ifndef NDEBUG |
| 268 void DescendantInvalidationSet::show() const | 287 void InvalidationSet::show() const |
| 269 { | 288 { |
| 270 RefPtr<TracedValue> value = TracedValue::create(); | 289 RefPtr<TracedValue> value = TracedValue::create(); |
| 271 value->beginArray("DescendantInvalidationSet"); | 290 value->beginArray("InvalidationSet"); |
| 272 toTracedValue(value.get()); | 291 toTracedValue(value.get()); |
| 273 value->endArray(); | 292 value->endArray(); |
| 274 fprintf(stderr, "%s\n", value->asTraceFormat().ascii().data()); | 293 fprintf(stderr, "%s\n", value->asTraceFormat().ascii().data()); |
| 275 } | 294 } |
| 276 #endif // NDEBUG | 295 #endif // NDEBUG |
| 277 | 296 |
| 278 } // namespace blink | 297 } // namespace blink |
| OLD | NEW |