| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 29 */ | |
| 30 | |
| 31 #include "config.h" | |
| 32 #include "core/css/invalidation/DescendantInvalidationSet.h" | |
| 33 | |
| 34 #include "core/css/resolver/StyleResolver.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" | |
| 40 | |
| 41 namespace blink { | |
| 42 | |
| 43 static const unsigned char* s_tracingEnabled = nullptr; | |
| 44 | |
| 45 #define TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(element, re
ason, invalidationSet, singleSelectorPart) \ | |
| 46 if (UNLIKELY(*s_tracingEnabled)) \ | |
| 47 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART(element, reason, inval
idationSet, singleSelectorPart); | |
| 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 | |
| 54 DescendantInvalidationSet::DescendantInvalidationSet() | |
| 55 : m_allDescendantsMightBeInvalid(false) | |
| 56 , m_customPseudoInvalid(false) | |
| 57 , m_treeBoundaryCrossing(false) | |
| 58 , m_insertionPointCrossing(false) | |
| 59 { | |
| 60 } | |
| 61 | |
| 62 bool DescendantInvalidationSet::invalidatesElement(Element& element) const | |
| 63 { | |
| 64 if (m_allDescendantsMightBeInvalid) | |
| 65 return true; | |
| 66 | |
| 67 if (m_tagNames && m_tagNames->contains(element.tagQName().localName())) { | |
| 68 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(element, In
validationSetMatchedTagName, *this, element.tagQName().localName()); | |
| 69 return true; | |
| 70 } | |
| 71 | |
| 72 if (element.hasID() && m_ids && m_ids->contains(element.idForStyleResolution
())) { | |
| 73 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(element, In
validationSetMatchedId, *this, element.idForStyleResolution()); | |
| 74 return true; | |
| 75 } | |
| 76 | |
| 77 if (element.hasClass() && m_classes) { | |
| 78 const SpaceSplitString& classNames = element.classNames(); | |
| 79 for (const auto& className : *m_classes) { | |
| 80 if (classNames.contains(className)) { | |
| 81 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(ele
ment, InvalidationSetMatchedClass, *this, className); | |
| 82 return true; | |
| 83 } | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 if (element.hasAttributes() && m_attributes) { | |
| 88 for (const auto& attribute : *m_attributes) { | |
| 89 if (element.hasAttribute(attribute)) { | |
| 90 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(ele
ment, InvalidationSetMatchedAttribute, *this, attribute); | |
| 91 return true; | |
| 92 } | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 return false; | |
| 97 } | |
| 98 | |
| 99 void DescendantInvalidationSet::combine(const DescendantInvalidationSet& other) | |
| 100 { | |
| 101 // No longer bother combining data structures, since the whole subtree is de
emed invalid. | |
| 102 if (wholeSubtreeInvalid()) | |
| 103 return; | |
| 104 | |
| 105 if (other.wholeSubtreeInvalid()) { | |
| 106 setWholeSubtreeInvalid(); | |
| 107 return; | |
| 108 } | |
| 109 | |
| 110 if (other.customPseudoInvalid()) | |
| 111 setCustomPseudoInvalid(); | |
| 112 | |
| 113 if (other.treeBoundaryCrossing()) | |
| 114 setTreeBoundaryCrossing(); | |
| 115 | |
| 116 if (other.insertionPointCrossing()) | |
| 117 setInsertionPointCrossing(); | |
| 118 | |
| 119 if (other.m_classes) { | |
| 120 for (const auto& className : *other.m_classes) | |
| 121 addClass(className); | |
| 122 } | |
| 123 | |
| 124 if (other.m_ids) { | |
| 125 for (const auto& id : *other.m_ids) | |
| 126 addId(id); | |
| 127 } | |
| 128 | |
| 129 if (other.m_tagNames) { | |
| 130 for (const auto& tagName : *other.m_tagNames) | |
| 131 addTagName(tagName); | |
| 132 } | |
| 133 | |
| 134 if (other.m_attributes) { | |
| 135 for (const auto& attribute : *other.m_attributes) | |
| 136 addAttribute(attribute); | |
| 137 } | |
| 138 } | |
| 139 | |
| 140 WillBeHeapHashSet<AtomicString>& DescendantInvalidationSet::ensureClassSet() | |
| 141 { | |
| 142 if (!m_classes) | |
| 143 m_classes = adoptPtrWillBeNoop(new WillBeHeapHashSet<AtomicString>); | |
| 144 return *m_classes; | |
| 145 } | |
| 146 | |
| 147 WillBeHeapHashSet<AtomicString>& DescendantInvalidationSet::ensureIdSet() | |
| 148 { | |
| 149 if (!m_ids) | |
| 150 m_ids = adoptPtrWillBeNoop(new WillBeHeapHashSet<AtomicString>); | |
| 151 return *m_ids; | |
| 152 } | |
| 153 | |
| 154 WillBeHeapHashSet<AtomicString>& DescendantInvalidationSet::ensureTagNameSet() | |
| 155 { | |
| 156 if (!m_tagNames) | |
| 157 m_tagNames = adoptPtrWillBeNoop(new WillBeHeapHashSet<AtomicString>); | |
| 158 return *m_tagNames; | |
| 159 } | |
| 160 | |
| 161 WillBeHeapHashSet<AtomicString>& DescendantInvalidationSet::ensureAttributeSet() | |
| 162 { | |
| 163 if (!m_attributes) | |
| 164 m_attributes = adoptPtrWillBeNoop(new WillBeHeapHashSet<AtomicString>); | |
| 165 return *m_attributes; | |
| 166 } | |
| 167 | |
| 168 void DescendantInvalidationSet::addClass(const AtomicString& className) | |
| 169 { | |
| 170 if (wholeSubtreeInvalid()) | |
| 171 return; | |
| 172 ensureClassSet().add(className); | |
| 173 } | |
| 174 | |
| 175 void DescendantInvalidationSet::addId(const AtomicString& id) | |
| 176 { | |
| 177 if (wholeSubtreeInvalid()) | |
| 178 return; | |
| 179 ensureIdSet().add(id); | |
| 180 } | |
| 181 | |
| 182 void DescendantInvalidationSet::addTagName(const AtomicString& tagName) | |
| 183 { | |
| 184 if (wholeSubtreeInvalid()) | |
| 185 return; | |
| 186 ensureTagNameSet().add(tagName); | |
| 187 } | |
| 188 | |
| 189 void DescendantInvalidationSet::addAttribute(const AtomicString& attribute) | |
| 190 { | |
| 191 if (wholeSubtreeInvalid()) | |
| 192 return; | |
| 193 ensureAttributeSet().add(attribute); | |
| 194 } | |
| 195 | |
| 196 void DescendantInvalidationSet::setWholeSubtreeInvalid() | |
| 197 { | |
| 198 if (m_allDescendantsMightBeInvalid) | |
| 199 return; | |
| 200 | |
| 201 m_allDescendantsMightBeInvalid = true; | |
| 202 m_customPseudoInvalid = false; | |
| 203 m_treeBoundaryCrossing = false; | |
| 204 m_insertionPointCrossing = false; | |
| 205 m_classes = nullptr; | |
| 206 m_ids = nullptr; | |
| 207 m_tagNames = nullptr; | |
| 208 m_attributes = nullptr; | |
| 209 } | |
| 210 | |
| 211 DEFINE_TRACE(DescendantInvalidationSet) | |
| 212 { | |
| 213 #if ENABLE(OILPAN) | |
| 214 visitor->trace(m_classes); | |
| 215 visitor->trace(m_ids); | |
| 216 visitor->trace(m_tagNames); | |
| 217 visitor->trace(m_attributes); | |
| 218 #endif | |
| 219 } | |
| 220 | |
| 221 void DescendantInvalidationSet::toTracedValue(TracedValue* value) const | |
| 222 { | |
| 223 value->beginDictionary(); | |
| 224 | |
| 225 value->setString("id", descendantInvalidationSetToIdString(*this)); | |
| 226 | |
| 227 if (m_allDescendantsMightBeInvalid) | |
| 228 value->setBoolean("allDescendantsMightBeInvalid", true); | |
| 229 if (m_customPseudoInvalid) | |
| 230 value->setBoolean("customPseudoInvalid", true); | |
| 231 if (m_treeBoundaryCrossing) | |
| 232 value->setBoolean("treeBoundaryCrossing", true); | |
| 233 if (m_insertionPointCrossing) | |
| 234 value->setBoolean("insertionPointCrossing", true); | |
| 235 | |
| 236 if (m_ids) { | |
| 237 value->beginArray("ids"); | |
| 238 for (const auto& id : *m_ids) | |
| 239 value->pushString(id); | |
| 240 value->endArray(); | |
| 241 } | |
| 242 | |
| 243 if (m_classes) { | |
| 244 value->beginArray("classes"); | |
| 245 for (const auto& className : *m_classes) | |
| 246 value->pushString(className); | |
| 247 value->endArray(); | |
| 248 } | |
| 249 | |
| 250 if (m_tagNames) { | |
| 251 value->beginArray("tagNames"); | |
| 252 for (const auto& tagName : *m_tagNames) | |
| 253 value->pushString(tagName); | |
| 254 value->endArray(); | |
| 255 } | |
| 256 | |
| 257 if (m_attributes) { | |
| 258 value->beginArray("attributes"); | |
| 259 for (const auto& attribute : *m_attributes) | |
| 260 value->pushString(attribute); | |
| 261 value->endArray(); | |
| 262 } | |
| 263 | |
| 264 value->endDictionary(); | |
| 265 } | |
| 266 | |
| 267 #ifndef NDEBUG | |
| 268 void DescendantInvalidationSet::show() const | |
| 269 { | |
| 270 RefPtr<TracedValue> value = TracedValue::create(); | |
| 271 value->beginArray("DescendantInvalidationSet"); | |
| 272 toTracedValue(value.get()); | |
| 273 value->endArray(); | |
| 274 fprintf(stderr, "%s\n", value->asTraceFormat().ascii().data()); | |
| 275 } | |
| 276 #endif // NDEBUG | |
| 277 | |
| 278 } // namespace blink | |
| OLD | NEW |