OLD | NEW |
1 | 1 |
2 // Copyright 2014 The Chromium Authors. All rights reserved. | 2 // Copyright 2014 The Chromium Authors. All rights reserved. |
3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
5 | 5 |
6 #include "config.h" | 6 #include "config.h" |
7 | 7 |
8 #include "core/css/invalidation/StyleInvalidator.h" | 8 #include "core/css/invalidation/StyleInvalidator.h" |
9 | 9 |
10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
11 #include "core/dom/Element.h" | 11 #include "core/dom/Element.h" |
12 #include "core/dom/ElementTraversal.h" | 12 #include "core/dom/ElementTraversal.h" |
13 #include "core/dom/shadow/ElementShadow.h" | 13 #include "core/dom/shadow/ElementShadow.h" |
14 #include "core/dom/shadow/ShadowRoot.h" | 14 #include "core/dom/shadow/ShadowRoot.h" |
15 #include "core/rendering/RenderObject.h" | 15 #include "core/rendering/RenderObject.h" |
16 | 16 |
17 namespace WebCore { | 17 namespace WebCore { |
18 | 18 |
19 void StyleInvalidator::invalidate() | 19 void StyleInvalidator::invalidate(Document& document) |
20 { | 20 { |
21 if (Element* documentElement = m_document.documentElement()) | 21 if (Element* documentElement = document.documentElement()) |
22 invalidate(*documentElement); | 22 invalidate(*documentElement); |
23 m_document.clearChildNeedsStyleInvalidation(); | 23 document.clearChildNeedsStyleInvalidation(); |
24 m_document.clearNeedsStyleInvalidation(); | 24 document.clearNeedsStyleInvalidation(); |
| 25 clearPendingInvalidations(); |
| 26 } |
| 27 |
| 28 void StyleInvalidator::scheduleInvalidation(PassRefPtr<DescendantInvalidationSet
> invalidationSet, Element& element) |
| 29 { |
| 30 ensurePendingInvalidationList(element).append(invalidationSet); |
| 31 element.setNeedsStyleInvalidation(); |
| 32 } |
| 33 |
| 34 StyleInvalidator::InvalidationList& StyleInvalidator::ensurePendingInvalidationL
ist(Element& element) |
| 35 { |
| 36 PendingInvalidationMap::AddResult addResult = m_pendingInvalidationMap.add(&
element, nullptr); |
| 37 if (addResult.isNewEntry) |
| 38 addResult.storedValue->value = adoptPtr(new InvalidationList); |
| 39 return *addResult.storedValue->value; |
| 40 } |
| 41 |
| 42 void StyleInvalidator::clearInvalidation(Node& node) |
| 43 { |
| 44 node.clearChildNeedsStyleInvalidation(); |
| 45 node.clearNeedsStyleInvalidation(); |
| 46 if (node.isElementNode()) |
| 47 m_pendingInvalidationMap.remove(toElement(&node)); |
| 48 } |
| 49 |
| 50 void StyleInvalidator::clearPendingInvalidations() |
| 51 { |
25 m_pendingInvalidationMap.clear(); | 52 m_pendingInvalidationMap.clear(); |
26 } | 53 } |
27 | 54 |
28 StyleInvalidator::StyleInvalidator(Document& document) | 55 StyleInvalidator::StyleInvalidator() |
29 : m_document(document) | |
30 , m_pendingInvalidationMap(document.styleResolver()->ruleFeatureSet().pendin
gInvalidationMap()) | |
31 { } | 56 { } |
32 | 57 |
33 void StyleInvalidator::RecursionData::pushInvalidationSet(const DescendantInvali
dationSet& invalidationSet) | 58 void StyleInvalidator::RecursionData::pushInvalidationSet(const DescendantInvali
dationSet& invalidationSet) |
34 { | 59 { |
35 invalidationSet.getClasses(m_invalidationClasses); | 60 invalidationSet.getClasses(m_invalidationClasses); |
36 invalidationSet.getAttributes(m_invalidationAttributes); | 61 invalidationSet.getAttributes(m_invalidationAttributes); |
37 m_foundInvalidationSet = true; | 62 m_foundInvalidationSet = true; |
38 } | 63 } |
39 | 64 |
40 bool StyleInvalidator::RecursionData::matchesCurrentInvalidationSets(Element& el
ement) | 65 bool StyleInvalidator::RecursionData::matchesCurrentInvalidationSets(Element& el
ement) |
(...skipping 12 matching lines...) Expand all Loading... |
53 } | 78 } |
54 } | 79 } |
55 | 80 |
56 return false; | 81 return false; |
57 } | 82 } |
58 | 83 |
59 bool StyleInvalidator::checkInvalidationSetsAgainstElement(Element& element) | 84 bool StyleInvalidator::checkInvalidationSetsAgainstElement(Element& element) |
60 { | 85 { |
61 bool thisElementNeedsStyleRecalc = false; | 86 bool thisElementNeedsStyleRecalc = false; |
62 if (element.needsStyleInvalidation()) { | 87 if (element.needsStyleInvalidation()) { |
63 if (RuleFeatureSet::InvalidationList* invalidationList = m_pendingInvali
dationMap.get(&element)) { | 88 if (InvalidationList* invalidationList = m_pendingInvalidationMap.get(&e
lement)) { |
64 // FIXME: it's really only necessary to clone the render style for t
his element, not full style recalc. | 89 // FIXME: it's really only necessary to clone the render style for t
his element, not full style recalc. |
65 thisElementNeedsStyleRecalc = true; | 90 thisElementNeedsStyleRecalc = true; |
66 for (RuleFeatureSet::InvalidationList::const_iterator it = invalidat
ionList->begin(); it != invalidationList->end(); ++it) { | 91 for (InvalidationList::const_iterator it = invalidationList->begin()
; it != invalidationList->end(); ++it) { |
67 m_recursionData.pushInvalidationSet(**it); | 92 m_recursionData.pushInvalidationSet(**it); |
68 if ((*it)->wholeSubtreeInvalid()) { | 93 if ((*it)->wholeSubtreeInvalid()) { |
69 element.setNeedsStyleRecalc(SubtreeStyleChange); | 94 element.setNeedsStyleRecalc(SubtreeStyleChange); |
70 // Even though we have set needsStyleRecalc on the whole sub
tree, we need to keep walking over the subtree | 95 // Even though we have set needsStyleRecalc on the whole sub
tree, we need to keep walking over the subtree |
71 // in order to clear the invalidation dirty bits on all elem
ents. | 96 // in order to clear the invalidation dirty bits on all elem
ents. |
72 // FIXME: we can optimize this by having a dedicated functio
n that just traverses the tree and removes the dirty bits, | 97 // FIXME: we can optimize this by having a dedicated functio
n that just traverses the tree and removes the dirty bits, |
73 // without checking classes etc. | 98 // without checking classes etc. |
74 break; | 99 break; |
75 } | 100 } |
76 } | 101 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 } | 148 } |
124 } | 149 } |
125 | 150 |
126 element.clearChildNeedsStyleInvalidation(); | 151 element.clearChildNeedsStyleInvalidation(); |
127 element.clearNeedsStyleInvalidation(); | 152 element.clearNeedsStyleInvalidation(); |
128 | 153 |
129 return thisElementNeedsStyleRecalc; | 154 return thisElementNeedsStyleRecalc; |
130 } | 155 } |
131 | 156 |
132 } // namespace WebCore | 157 } // namespace WebCore |
OLD | NEW |