| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef StyleInvalidator_h | 5 #ifndef StyleInvalidator_h |
| 6 #define StyleInvalidator_h | 6 #define StyleInvalidator_h |
| 7 | 7 |
| 8 #include "core/css/invalidation/PendingInvalidations.h" |
| 8 #include "platform/heap/Handle.h" | 9 #include "platform/heap/Handle.h" |
| 9 #include "wtf/Noncopyable.h" | 10 #include "wtf/Noncopyable.h" |
| 10 | 11 |
| 11 namespace blink { | 12 namespace blink { |
| 12 | 13 |
| 13 class InvalidationSet; | |
| 14 class Document; | 14 class Document; |
| 15 class Element; | 15 class Element; |
| 16 class InvalidationSet; |
| 17 |
| 16 | 18 |
| 17 class StyleInvalidator { | 19 class StyleInvalidator { |
| 18 DISALLOW_ALLOCATION(); | 20 DISALLOW_ALLOCATION(); |
| 19 WTF_MAKE_NONCOPYABLE(StyleInvalidator); | 21 WTF_MAKE_NONCOPYABLE(StyleInvalidator); |
| 20 public: | 22 public: |
| 21 StyleInvalidator(); | 23 StyleInvalidator(); |
| 22 ~StyleInvalidator(); | 24 ~StyleInvalidator(); |
| 23 void invalidate(Document&); | 25 void invalidate(Document&); |
| 24 void scheduleInvalidation(PassRefPtrWillBeRawPtr<InvalidationSet>, Element&)
; | 26 void scheduleInvalidationSetsForElement(const InvalidationLists&, Element&); |
| 25 void clearInvalidation(Element&); | 27 void clearInvalidation(Element&); |
| 26 | 28 |
| 27 void clearPendingInvalidations(); | |
| 28 | |
| 29 DECLARE_TRACE(); | 29 DECLARE_TRACE(); |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 struct RecursionData { | 32 struct RecursionData { |
| 33 RecursionData() | 33 RecursionData() |
| 34 : m_invalidateCustomPseudo(false) | 34 : m_invalidateCustomPseudo(false) |
| 35 , m_wholeSubtreeInvalid(false) | 35 , m_wholeSubtreeInvalid(false) |
| 36 , m_treeBoundaryCrossing(false) | 36 , m_treeBoundaryCrossing(false) |
| 37 , m_insertionPointCrossing(false) | 37 , m_insertionPointCrossing(false) |
| 38 { } | 38 { } |
| 39 | 39 |
| 40 void pushInvalidationSet(const InvalidationSet&); | 40 void pushInvalidationSet(const InvalidationSet&); |
| 41 bool matchesCurrentInvalidationSets(Element&); | 41 bool matchesCurrentInvalidationSets(Element&) const; |
| 42 bool hasInvalidationSets() const { return !wholeSubtreeInvalid() && m_in
validationSets.size(); } | 42 bool hasInvalidationSets() const { return !wholeSubtreeInvalid() && m_in
validationSets.size(); } |
| 43 | 43 |
| 44 bool wholeSubtreeInvalid() const { return m_wholeSubtreeInvalid; } | 44 bool wholeSubtreeInvalid() const { return m_wholeSubtreeInvalid; } |
| 45 void setWholeSubtreeInvalid() { m_wholeSubtreeInvalid = true; } | 45 void setWholeSubtreeInvalid() { m_wholeSubtreeInvalid = true; } |
| 46 | 46 |
| 47 bool treeBoundaryCrossing() const { return m_treeBoundaryCrossing; } | 47 bool treeBoundaryCrossing() const { return m_treeBoundaryCrossing; } |
| 48 bool insertionPointCrossing() const { return m_insertionPointCrossing; } | 48 bool insertionPointCrossing() const { return m_insertionPointCrossing; } |
| 49 | 49 |
| 50 using InvalidationSets = Vector<const InvalidationSet*, 16>; | 50 using InvalidationSets = Vector<const InvalidationSet*, 16>; |
| 51 InvalidationSets m_invalidationSets; | 51 InvalidationSets m_invalidationSets; |
| 52 bool m_invalidateCustomPseudo; | 52 bool m_invalidateCustomPseudo; |
| 53 bool m_wholeSubtreeInvalid; | 53 bool m_wholeSubtreeInvalid; |
| 54 bool m_treeBoundaryCrossing; | 54 bool m_treeBoundaryCrossing; |
| 55 bool m_insertionPointCrossing; | 55 bool m_insertionPointCrossing; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 bool invalidate(Element&, RecursionData&); | 58 class SiblingData { |
| 59 STACK_ALLOCATED(); |
| 60 public: |
| 61 SiblingData() |
| 62 : m_elementIndex(0) |
| 63 { } |
| 64 |
| 65 void pushInvalidationSet(const InvalidationSet&); |
| 66 bool matchCurrentInvalidationSets(Element&, RecursionData&); |
| 67 |
| 68 void advance() { m_elementIndex++; } |
| 69 |
| 70 private: |
| 71 struct Entry { |
| 72 ALLOW_ONLY_INLINE_ALLOCATION(); |
| 73 Entry(const InvalidationSet* invalidationSet, unsigned invalidationL
imit) |
| 74 : m_invalidationSet(invalidationSet) |
| 75 , m_invalidationLimit(invalidationLimit) |
| 76 {} |
| 77 |
| 78 RawPtrWillBeMember<const InvalidationSet> m_invalidationSet; |
| 79 unsigned m_invalidationLimit; |
| 80 }; |
| 81 |
| 82 Vector<Entry, 16> m_invalidationEntries; |
| 83 unsigned m_elementIndex; |
| 84 }; |
| 85 |
| 86 bool invalidate(Element&, RecursionData&, SiblingData&); |
| 59 bool invalidateChildren(Element&, RecursionData&); | 87 bool invalidateChildren(Element&, RecursionData&); |
| 60 bool checkInvalidationSetsAgainstElement(Element&, RecursionData&); | 88 bool checkInvalidationSetsAgainstElement(Element&, RecursionData&, SiblingDa
ta&); |
| 61 | 89 |
| 62 class RecursionCheckpoint { | 90 class RecursionCheckpoint { |
| 63 public: | 91 public: |
| 64 RecursionCheckpoint(RecursionData* data) | 92 RecursionCheckpoint(RecursionData* data) |
| 65 : m_prevInvalidationSetsSize(data->m_invalidationSets.size()) | 93 : m_prevInvalidationSetsSize(data->m_invalidationSets.size()) |
| 66 , m_prevInvalidateCustomPseudo(data->m_invalidateCustomPseudo) | 94 , m_prevInvalidateCustomPseudo(data->m_invalidateCustomPseudo) |
| 67 , m_prevWholeSubtreeInvalid(data->m_wholeSubtreeInvalid) | 95 , m_prevWholeSubtreeInvalid(data->m_wholeSubtreeInvalid) |
| 68 , m_treeBoundaryCrossing(data->m_treeBoundaryCrossing) | 96 , m_treeBoundaryCrossing(data->m_treeBoundaryCrossing) |
| 69 , m_insertionPointCrossing(data->m_insertionPointCrossing) | 97 , m_insertionPointCrossing(data->m_insertionPointCrossing) |
| 70 , m_data(data) | 98 , m_data(data) |
| 71 { } | 99 { } |
| 72 ~RecursionCheckpoint() | 100 ~RecursionCheckpoint() |
| 73 { | 101 { |
| 74 m_data->m_invalidationSets.remove(m_prevInvalidationSetsSize, m_data
->m_invalidationSets.size() - m_prevInvalidationSetsSize); | 102 m_data->m_invalidationSets.remove(m_prevInvalidationSetsSize, m_data
->m_invalidationSets.size() - m_prevInvalidationSetsSize); |
| 75 m_data->m_invalidateCustomPseudo = m_prevInvalidateCustomPseudo; | 103 m_data->m_invalidateCustomPseudo = m_prevInvalidateCustomPseudo; |
| 76 m_data->m_wholeSubtreeInvalid = m_prevWholeSubtreeInvalid; | 104 m_data->m_wholeSubtreeInvalid = m_prevWholeSubtreeInvalid; |
| 77 m_data->m_treeBoundaryCrossing = m_treeBoundaryCrossing; | 105 m_data->m_treeBoundaryCrossing = m_treeBoundaryCrossing; |
| 78 m_data->m_insertionPointCrossing = m_insertionPointCrossing; | 106 m_data->m_insertionPointCrossing = m_insertionPointCrossing; |
| 79 } | 107 } |
| 80 | 108 |
| 81 private: | 109 private: |
| 82 int m_prevInvalidationSetsSize; | 110 int m_prevInvalidationSetsSize; |
| 83 bool m_prevInvalidateCustomPseudo; | 111 bool m_prevInvalidateCustomPseudo; |
| 84 bool m_prevWholeSubtreeInvalid; | 112 bool m_prevWholeSubtreeInvalid; |
| 85 bool m_treeBoundaryCrossing; | 113 bool m_treeBoundaryCrossing; |
| 86 bool m_insertionPointCrossing; | 114 bool m_insertionPointCrossing; |
| 87 RecursionData* m_data; | 115 RecursionData* m_data; |
| 88 }; | 116 }; |
| 89 | 117 |
| 90 using InvalidationList = WillBeHeapVector<RefPtrWillBeMember<InvalidationSet
>>; | 118 using PendingInvalidationMap = WillBeHeapHashMap<RawPtrWillBeMember<Element>
, RefPtrWillBeMember<PendingInvalidations>>; |
| 91 using PendingInvalidationMap = WillBeHeapHashMap<RawPtrWillBeMember<Element>
, OwnPtrWillBeMember<InvalidationList>>; | |
| 92 | 119 |
| 93 InvalidationList& ensurePendingInvalidationList(Element&); | 120 PendingInvalidations& ensurePendingInvalidations(Element&); |
| 94 | 121 |
| 95 PendingInvalidationMap m_pendingInvalidationMap; | 122 PendingInvalidationMap m_pendingInvalidationMap; |
| 96 }; | 123 }; |
| 97 | 124 |
| 98 } // namespace blink | 125 } // namespace blink |
| 99 | 126 |
| 100 #endif // StyleInvalidator_h | 127 #endif // StyleInvalidator_h |
| OLD | NEW |