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 3 // found in the LICENSE file. 4 5 #ifndef StyleInvalidator_h 6 #define StyleInvalidator_h 7 8 #include "platform/heap/Handle.h" 9 10 namespace blink { 11 12 class DescendantInvalidationSet; 13 class Document; 14 class Element; 15 16 class StyleInvalidator { 17 DISALLOW_ALLOCATION(); 18 public: 19 StyleInvalidator(); 20 ~StyleInvalidator(); 21 void invalidate(Document&); 22 void scheduleInvalidation(PassRefPtrWillBeRawPtr<DescendantInvalidationSet>, Element&); 23 24 // Clears all style invalidation state for the passed node. 25 void clearInvalidation(Node&); 26 27 void clearPendingInvalidations(); 28 29 void trace(Visitor*); 30 31 private: 32 struct RecursionData { RecursionDataRecursionData33 RecursionData() 34 : m_invalidateCustomPseudo(false) 35 , m_wholeSubtreeInvalid(false) 36 , m_treeBoundaryCrossing(false) 37 { } 38 39 void pushInvalidationSet(const DescendantInvalidationSet&); 40 bool matchesCurrentInvalidationSets(Element&); hasInvalidationSetsRecursionData41 bool hasInvalidationSets() const { return !wholeSubtreeInvalid() && m_invalidationSets.size(); } 42 wholeSubtreeInvalidRecursionData43 bool wholeSubtreeInvalid() const { return m_wholeSubtreeInvalid; } setWholeSubtreeInvalidRecursionData44 void setWholeSubtreeInvalid() { m_wholeSubtreeInvalid = true; } 45 treeBoundaryCrossingRecursionData46 bool treeBoundaryCrossing() const { return m_treeBoundaryCrossing; } 47 48 typedef Vector<const DescendantInvalidationSet*, 16> InvalidationSets; 49 InvalidationSets m_invalidationSets; 50 bool m_invalidateCustomPseudo; 51 bool m_wholeSubtreeInvalid; 52 bool m_treeBoundaryCrossing; 53 }; 54 55 bool invalidate(Element&, RecursionData&); 56 bool invalidateChildren(Element&, RecursionData&); 57 bool checkInvalidationSetsAgainstElement(Element&, RecursionData&); 58 59 class RecursionCheckpoint { 60 public: RecursionCheckpoint(RecursionData * data)61 RecursionCheckpoint(RecursionData* data) 62 : m_prevInvalidationSetsSize(data->m_invalidationSets.size()) 63 , m_prevInvalidateCustomPseudo(data->m_invalidateCustomPseudo) 64 , m_prevWholeSubtreeInvalid(data->m_wholeSubtreeInvalid) 65 , m_treeBoundaryCrossing(data->m_treeBoundaryCrossing) 66 , m_data(data) 67 { } ~RecursionCheckpoint()68 ~RecursionCheckpoint() 69 { 70 m_data->m_invalidationSets.remove(m_prevInvalidationSetsSize, m_data->m_invalidationSets.size() - m_prevInvalidationSetsSize); 71 m_data->m_invalidateCustomPseudo = m_prevInvalidateCustomPseudo; 72 m_data->m_wholeSubtreeInvalid = m_prevWholeSubtreeInvalid; 73 m_data->m_treeBoundaryCrossing = m_treeBoundaryCrossing; 74 } 75 76 private: 77 int m_prevInvalidationSetsSize; 78 bool m_prevInvalidateCustomPseudo; 79 bool m_prevWholeSubtreeInvalid; 80 bool m_treeBoundaryCrossing; 81 RecursionData* m_data; 82 }; 83 84 typedef WillBeHeapVector<RefPtrWillBeMember<DescendantInvalidationSet> > InvalidationList; 85 typedef WillBeHeapHashMap<RawPtrWillBeMember<Element>, OwnPtrWillBeMember<InvalidationList> > PendingInvalidationMap; 86 87 InvalidationList& ensurePendingInvalidationList(Element&); 88 89 PendingInvalidationMap m_pendingInvalidationMap; 90 }; 91 92 } // namespace blink 93 94 #endif // StyleInvalidator_h 95