| 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 14 matching lines...) Expand all Loading... |
| 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 #ifndef InvalidationSet_h | 31 #ifndef InvalidationSet_h |
| 32 #define InvalidationSet_h | 32 #define InvalidationSet_h |
| 33 | 33 |
| 34 #include "core/CoreExport.h" | 34 #include "core/CoreExport.h" |
| 35 #include "wtf/Assertions.h" |
| 35 #include "wtf/Forward.h" | 36 #include "wtf/Forward.h" |
| 36 #include "wtf/HashSet.h" | 37 #include "wtf/HashSet.h" |
| 37 #include "wtf/RefCounted.h" | 38 #include "wtf/RefCounted.h" |
| 38 #include "wtf/RefPtr.h" | 39 #include "wtf/RefPtr.h" |
| 39 #include "wtf/text/AtomicStringHash.h" | 40 #include "wtf/text/AtomicStringHash.h" |
| 40 #include "wtf/text/StringHash.h" | 41 #include "wtf/text/StringHash.h" |
| 41 | 42 |
| 42 namespace blink { | 43 namespace blink { |
| 43 | 44 |
| 45 class DescendantInvalidationSet; |
| 44 class Element; | 46 class Element; |
| 45 class TracedValue; | 47 class TracedValue; |
| 46 | 48 |
| 47 // Tracks data to determine which elements of a DOM subtree need to have style | 49 enum InvalidationType { |
| 48 // recalculated. | 50 InvalidateDescendants, |
| 49 class CORE_EXPORT InvalidationSet final : public RefCounted<InvalidationSet> { | 51 InvalidateSiblings |
| 52 }; |
| 53 |
| 54 // Tracks data to determine which descendants in a DOM subtree, or |
| 55 // siblings and their descendants, need to have style recalculated. |
| 56 class CORE_EXPORT InvalidationSet : public RefCounted<InvalidationSet> { |
| 50 WTF_MAKE_NONCOPYABLE(InvalidationSet); | 57 WTF_MAKE_NONCOPYABLE(InvalidationSet); |
| 51 public: | 58 public: |
| 52 static PassRefPtr<InvalidationSet> create() | 59 virtual ~InvalidationSet() {} |
| 53 { | 60 |
| 54 return adoptRef(new InvalidationSet); | 61 virtual bool isDescendantInvalidationSet() const { return false; } |
| 55 } | 62 virtual bool isSiblingInvalidationSet() const { return false; } |
| 56 | 63 |
| 57 static void cacheTracingFlag(); | 64 static void cacheTracingFlag(); |
| 58 | 65 |
| 59 bool invalidatesElement(Element&) const; | 66 bool invalidatesElement(Element&) const; |
| 60 | 67 |
| 61 void combine(const InvalidationSet& other); | |
| 62 | |
| 63 void addClass(const AtomicString& className); | 68 void addClass(const AtomicString& className); |
| 64 void addId(const AtomicString& id); | 69 void addId(const AtomicString& id); |
| 65 void addTagName(const AtomicString& tagName); | 70 void addTagName(const AtomicString& tagName); |
| 66 void addAttribute(const AtomicString& attributeLocalName); | 71 void addAttribute(const AtomicString& attributeLocalName); |
| 67 | 72 |
| 68 void setWholeSubtreeInvalid(); | 73 void setWholeSubtreeInvalid(); |
| 69 bool wholeSubtreeInvalid() const { return m_allDescendantsMightBeInvalid; } | 74 bool wholeSubtreeInvalid() const { return m_allDescendantsMightBeInvalid; } |
| 70 | 75 |
| 71 void setInvalidatesSelf() { m_invalidatesSelf = true; } | 76 void setInvalidatesSelf() { m_invalidatesSelf = true; } |
| 72 bool invalidatesSelf() const { return m_invalidatesSelf; } | 77 bool invalidatesSelf() const { return m_invalidatesSelf; } |
| 73 | 78 |
| 74 void setTreeBoundaryCrossing() { m_treeBoundaryCrossing = true; } | 79 void setTreeBoundaryCrossing() { m_treeBoundaryCrossing = true; } |
| 75 bool treeBoundaryCrossing() const { return m_treeBoundaryCrossing; } | 80 bool treeBoundaryCrossing() const { return m_treeBoundaryCrossing; } |
| 76 | 81 |
| 77 void setInsertionPointCrossing() { m_insertionPointCrossing = true; } | 82 void setInsertionPointCrossing() { m_insertionPointCrossing = true; } |
| 78 bool insertionPointCrossing() const { return m_insertionPointCrossing; } | 83 bool insertionPointCrossing() const { return m_insertionPointCrossing; } |
| 79 | 84 |
| 80 void setCustomPseudoInvalid() { m_customPseudoInvalid = true; } | 85 void setCustomPseudoInvalid() { m_customPseudoInvalid = true; } |
| 81 bool customPseudoInvalid() const { return m_customPseudoInvalid; } | 86 bool customPseudoInvalid() const { return m_customPseudoInvalid; } |
| 82 | 87 |
| 83 bool isEmpty() const { return !m_classes && !m_ids && !m_tagNames && !m_attr
ibutes && !m_customPseudoInvalid; } | 88 bool isEmpty() const { return !m_classes && !m_ids && !m_tagNames && !m_attr
ibutes && !m_customPseudoInvalid; } |
| 84 | 89 |
| 85 void toTracedValue(TracedValue*) const; | 90 void toTracedValue(TracedValue*) const; |
| 86 | 91 |
| 87 #ifndef NDEBUG | 92 #ifndef NDEBUG |
| 88 void show() const; | 93 void show() const; |
| 89 #endif | 94 #endif |
| 90 | 95 |
| 91 private: | 96 const HashSet<AtomicString>& classSetForTesting() const { ASSERT(m_classes);
return *m_classes; } |
| 97 const HashSet<AtomicString>& idSetForTesting() const { ASSERT(m_ids); return
*m_ids; } |
| 98 const HashSet<AtomicString>& tagNameSetForTesting() const { ASSERT(m_tagName
s); return *m_tagNames; } |
| 99 const HashSet<AtomicString>& attributeSetForTesting() const { ASSERT(m_attri
butes); return *m_attributes; } |
| 100 |
| 101 protected: |
| 92 InvalidationSet(); | 102 InvalidationSet(); |
| 93 | 103 |
| 104 void combine(const InvalidationSet& other); |
| 105 |
| 106 private: |
| 94 HashSet<AtomicString>& ensureClassSet(); | 107 HashSet<AtomicString>& ensureClassSet(); |
| 95 HashSet<AtomicString>& ensureIdSet(); | 108 HashSet<AtomicString>& ensureIdSet(); |
| 96 HashSet<AtomicString>& ensureTagNameSet(); | 109 HashSet<AtomicString>& ensureTagNameSet(); |
| 97 HashSet<AtomicString>& ensureAttributeSet(); | 110 HashSet<AtomicString>& ensureAttributeSet(); |
| 98 | 111 |
| 99 // FIXME: optimize this if it becomes a memory issue. | 112 // FIXME: optimize this if it becomes a memory issue. |
| 100 OwnPtr<HashSet<AtomicString>> m_classes; | 113 OwnPtr<HashSet<AtomicString>> m_classes; |
| 101 OwnPtr<HashSet<AtomicString>> m_ids; | 114 OwnPtr<HashSet<AtomicString>> m_ids; |
| 102 OwnPtr<HashSet<AtomicString>> m_tagNames; | 115 OwnPtr<HashSet<AtomicString>> m_tagNames; |
| 103 OwnPtr<HashSet<AtomicString>> m_attributes; | 116 OwnPtr<HashSet<AtomicString>> m_attributes; |
| 104 | 117 |
| 105 // If true, all descendants might be invalidated, so a full subtree recalc i
s required. | 118 // If true, all descendants might be invalidated, so a full subtree recalc i
s required. |
| 106 unsigned m_allDescendantsMightBeInvalid : 1; | 119 unsigned m_allDescendantsMightBeInvalid : 1; |
| 107 | 120 |
| 108 // If true, the element itself is invalid. | 121 // If true, the element itself is invalid. |
| 109 unsigned m_invalidatesSelf : 1; | 122 unsigned m_invalidatesSelf : 1; |
| 110 | 123 |
| 111 // If true, all descendants which are custom pseudo elements must be invalid
ated. | 124 // If true, all descendants which are custom pseudo elements must be invalid
ated. |
| 112 unsigned m_customPseudoInvalid : 1; | 125 unsigned m_customPseudoInvalid : 1; |
| 113 | 126 |
| 114 // If true, the invalidation must traverse into ShadowRoots with this set. | 127 // If true, the invalidation must traverse into ShadowRoots with this set. |
| 115 unsigned m_treeBoundaryCrossing : 1; | 128 unsigned m_treeBoundaryCrossing : 1; |
| 116 | 129 |
| 117 // If true, insertion point descendants must be invalidated. | 130 // If true, insertion point descendants must be invalidated. |
| 118 unsigned m_insertionPointCrossing : 1; | 131 unsigned m_insertionPointCrossing : 1; |
| 119 }; | 132 }; |
| 120 | 133 |
| 134 class CORE_EXPORT DescendantInvalidationSet final : public InvalidationSet { |
| 135 public: |
| 136 static PassRefPtr<DescendantInvalidationSet> create() |
| 137 { |
| 138 return adoptRef(new DescendantInvalidationSet); |
| 139 } |
| 140 |
| 141 bool isDescendantInvalidationSet() const final { return true; } |
| 142 |
| 143 void combine(const DescendantInvalidationSet& other) |
| 144 { |
| 145 InvalidationSet::combine(other); |
| 146 } |
| 147 |
| 148 private: |
| 149 DescendantInvalidationSet() {} |
| 150 }; |
| 151 |
| 152 class CORE_EXPORT SiblingInvalidationSet final : public InvalidationSet { |
| 153 public: |
| 154 static PassRefPtr<SiblingInvalidationSet> create() |
| 155 { |
| 156 return adoptRef(new SiblingInvalidationSet); |
| 157 } |
| 158 |
| 159 bool isSiblingInvalidationSet() const final { return true; } |
| 160 |
| 161 void combine(const SiblingInvalidationSet& other); |
| 162 |
| 163 DescendantInvalidationSet& descendants() { return *m_descendantInvalidationS
et; } |
| 164 const DescendantInvalidationSet& descendants() const { return *m_descendantI
nvalidationSet; } |
| 165 |
| 166 unsigned maxDirectAdjacentSelectors() const { return m_maxDirectAdjacentSele
ctors; } |
| 167 void updateMaxDirectAdjacentSelectors(unsigned value) { m_maxDirectAdjacentS
electors = std::max(value, m_maxDirectAdjacentSelectors); } |
| 168 |
| 169 private: |
| 170 SiblingInvalidationSet(); |
| 171 |
| 172 // Indicates the maximum possible number of siblings affected. |
| 173 unsigned m_maxDirectAdjacentSelectors; |
| 174 |
| 175 // Indicates the descendants of siblings. |
| 176 RefPtr<DescendantInvalidationSet> m_descendantInvalidationSet; |
| 177 }; |
| 178 |
| 179 using InvalidationSetVector = Vector<RefPtr<InvalidationSet>>; |
| 180 |
| 181 struct InvalidationLists { |
| 182 InvalidationSetVector descendants; |
| 183 InvalidationSetVector siblings; |
| 184 }; |
| 185 |
| 186 DEFINE_TYPE_CASTS(DescendantInvalidationSet, InvalidationSet, value, value->isDe
scendantInvalidationSet(), value.isDescendantInvalidationSet()); |
| 187 DEFINE_TYPE_CASTS(SiblingInvalidationSet, InvalidationSet, value, value->isSibli
ngInvalidationSet(), value.isSiblingInvalidationSet()); |
| 188 |
| 121 } // namespace blink | 189 } // namespace blink |
| 122 | 190 |
| 123 #endif // InvalidationSet_h | 191 #endif // InvalidationSet_h |
| OLD | NEW |