Chromium Code Reviews| 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 15 matching lines...) Expand all Loading... | |
| 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/DescendantInvalidationSet.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" | |
| 37 #include "platform/TracedValue.h" | |
| 38 #include "wtf/Compiler.h" | |
| 39 #include "wtf/text/StringBuilder.h" | |
| 36 | 40 |
| 37 namespace blink { | 41 namespace blink { |
| 38 | 42 |
| 43 static const unsigned char* s_tracingEnabled = nullptr; | |
| 44 | |
| 45 #define TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(element, re ason, singleSelectorPart) \ | |
| 46 if (UNLIKELY(*s_tracingEnabled)) \ | |
| 47 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART(element, reason, singl eSelectorPart); | |
| 48 | |
| 49 void DescendantInvalidationSet::cacheTracingFlag() | |
| 50 { | |
| 51 s_tracingEnabled = TRACE_EVENT_API_GET_CATEGORY_ENABLED(TRACE_DISABLED_BY_DE FAULT("devtools.timeline.invalidationTracking")); | |
| 52 } | |
| 53 | |
| 39 DescendantInvalidationSet::DescendantInvalidationSet() | 54 DescendantInvalidationSet::DescendantInvalidationSet() |
| 40 : m_allDescendantsMightBeInvalid(false) | 55 : m_allDescendantsMightBeInvalid(false) |
| 41 , m_customPseudoInvalid(false) | 56 , m_customPseudoInvalid(false) |
| 42 , m_treeBoundaryCrossing(false) | 57 , m_treeBoundaryCrossing(false) |
| 43 { | 58 { |
| 44 } | 59 } |
| 45 | 60 |
| 46 bool DescendantInvalidationSet::invalidatesElement(Element& element) const | 61 bool DescendantInvalidationSet::invalidatesElement(Element& element) const |
| 47 { | 62 { |
| 48 if (m_allDescendantsMightBeInvalid) | 63 if (m_allDescendantsMightBeInvalid) |
| 49 return true; | 64 return true; |
| 50 | 65 |
| 51 if (m_tagNames && m_tagNames->contains(element.tagQName().localName())) | 66 if (m_tagNames && m_tagNames->contains(element.tagQName().localName())) { |
| 67 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(element, In validationSetMatchedTagName, element.tagQName().localName()); | |
| 52 return true; | 68 return true; |
| 69 } | |
| 53 | 70 |
| 54 if (element.hasID() && m_ids && m_ids->contains(element.idForStyleResolution ())) | 71 if (element.hasID() && m_ids && m_ids->contains(element.idForStyleResolution ())) { |
| 72 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(element, In validationSetMatchedId, element.idForStyleResolution()); | |
| 55 return true; | 73 return true; |
| 74 } | |
| 56 | 75 |
| 57 if (element.hasClass() && m_classes) { | 76 if (element.hasClass() && m_classes) { |
| 58 const SpaceSplitString& classNames = element.classNames(); | 77 const SpaceSplitString& classNames = element.classNames(); |
| 59 for (const auto& className : *m_classes) { | 78 for (const auto& className : *m_classes) { |
| 60 if (classNames.contains(className)) | 79 if (classNames.contains(className)) { |
| 80 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(ele ment, InvalidationSetMatchedClass, className); | |
| 61 return true; | 81 return true; |
| 82 } | |
| 62 } | 83 } |
| 63 } | 84 } |
| 64 | 85 |
| 65 if (element.hasAttributes() && m_attributes) { | 86 if (element.hasAttributes() && m_attributes) { |
| 66 for (const auto& attribute : *m_attributes) { | 87 for (const auto& attribute : *m_attributes) { |
| 67 if (element.hasAttribute(attribute)) | 88 if (element.hasAttribute(attribute)) { |
| 89 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(ele ment, InvalidationSetMatchedAttribute, attribute); | |
| 68 return true; | 90 return true; |
| 91 } | |
| 69 } | 92 } |
| 70 } | 93 } |
| 71 | 94 |
| 72 return false; | 95 return false; |
| 73 } | 96 } |
| 74 | 97 |
| 75 void DescendantInvalidationSet::combine(const DescendantInvalidationSet& other) | 98 void DescendantInvalidationSet::combine(const DescendantInvalidationSet& other) |
| 76 { | 99 { |
| 77 // No longer bother combining data structures, since the whole subtree is de emed invalid. | 100 // No longer bother combining data structures, since the whole subtree is de emed invalid. |
| 78 if (wholeSubtreeInvalid()) | 101 if (wholeSubtreeInvalid()) |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 void DescendantInvalidationSet::trace(Visitor* visitor) | 205 void DescendantInvalidationSet::trace(Visitor* visitor) |
| 183 { | 206 { |
| 184 #if ENABLE(OILPAN) | 207 #if ENABLE(OILPAN) |
| 185 visitor->trace(m_classes); | 208 visitor->trace(m_classes); |
| 186 visitor->trace(m_ids); | 209 visitor->trace(m_ids); |
| 187 visitor->trace(m_tagNames); | 210 visitor->trace(m_tagNames); |
| 188 visitor->trace(m_attributes); | 211 visitor->trace(m_attributes); |
| 189 #endif | 212 #endif |
| 190 } | 213 } |
| 191 | 214 |
| 215 void DescendantInvalidationSet::toTracedValue(TracedValue* value) const | |
| 216 { | |
| 217 value->beginDictionary(); | |
| 218 | |
| 219 if (m_allDescendantsMightBeInvalid) | |
| 220 value->setBoolean("allDescendantsMightBeInvalid", true); | |
| 221 if (m_customPseudoInvalid) | |
| 222 value->setBoolean("customPseudoInvalid", true); | |
| 223 if (m_treeBoundaryCrossing) | |
| 224 value->setBoolean("treeBoundaryCrossing", true); | |
| 225 | |
| 226 if (m_ids) { | |
| 227 value->beginArray("ids"); | |
| 228 for (const auto& id : *m_ids) | |
| 229 value->pushString(id); | |
| 230 value->endArray(); | |
| 231 } | |
| 232 | |
| 233 if (m_classes) { | |
| 234 value->beginArray("classes"); | |
| 235 for (const auto& className : *m_classes) | |
| 236 value->pushString(className); | |
| 237 value->endArray(); | |
| 238 } | |
| 239 | |
| 240 if (m_tagNames) { | |
| 241 value->beginArray("tagNames"); | |
| 242 for (const auto& tagName : *m_tagNames) | |
| 243 value->pushString(tagName); | |
| 244 value->endArray(); | |
| 245 } | |
| 246 | |
| 247 if (m_attributes) { | |
| 248 value->beginArray("ids"); | |
|
tasak
2014/10/14 04:35:53
Nit: attributes?
kouhei (in TOK)
2014/10/14 04:42:49
Indeed. Thanks for the catch!
| |
| 249 for (const auto& attribute : *m_attributes) | |
| 250 value->pushString(attribute); | |
| 251 value->endArray(); | |
| 252 } | |
| 253 | |
| 254 value->endDictionary(); | |
| 255 } | |
| 256 | |
| 192 #ifndef NDEBUG | 257 #ifndef NDEBUG |
| 193 void DescendantInvalidationSet::show() const | 258 void DescendantInvalidationSet::show() const |
| 194 { | 259 { |
| 195 fprintf(stderr, "DescendantInvalidationSet { "); | 260 RefPtr<TracedValue> value = TracedValue::create(); |
| 196 if (m_allDescendantsMightBeInvalid) | 261 toTracedValue(value.get()); |
| 197 fprintf(stderr, "* "); | 262 fprintf(stderr, "%s\n", value->asTraceFormat().ascii().data()); |
| 198 if (m_customPseudoInvalid) | |
| 199 fprintf(stderr, "::custom "); | |
| 200 if (m_treeBoundaryCrossing) | |
| 201 fprintf(stderr, "::shadow/deep/ "); | |
| 202 if (m_ids) { | |
| 203 for (const auto& id : *m_ids) | |
| 204 fprintf(stderr, "#%s ", id.ascii().data()); | |
| 205 } | |
| 206 if (m_classes) { | |
| 207 for (const auto& className : *m_classes) | |
| 208 fprintf(stderr, ".%s ", className.ascii().data()); | |
| 209 } | |
| 210 if (m_tagNames) { | |
| 211 for (const auto& tagName : *m_tagNames) | |
| 212 fprintf(stderr, "<%s> ", tagName.ascii().data()); | |
| 213 } | |
| 214 if (m_attributes) { | |
| 215 for (const auto& attribute : *m_attributes) | |
| 216 fprintf(stderr, "[%s] ", attribute.ascii().data()); | |
| 217 } | |
| 218 fprintf(stderr, "}\n"); | |
| 219 } | 263 } |
| 220 #endif // NDEBUG | 264 #endif // NDEBUG |
| 221 | 265 |
| 222 } // namespace blink | 266 } // namespace blink |
| OLD | NEW |