Chromium Code Reviews| 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 m_pendingInvalidationMap.clear(); | 25 clear(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 StyleInvalidator::StyleInvalidator(Document& document) | 28 void StyleInvalidator::scheduleInvalidation(PassRefPtr<DescendantInvalidationSet > invalidationSet, Element* element) |
| 29 : m_document(document) | 29 { |
| 30 , m_pendingInvalidationMap(document.styleResolver()->ruleFeatureSet().pendin gInvalidationMap()) | 30 ensurePendingInvalidationList(element).append(invalidationSet); |
| 31 element->setNeedsStyleInvalidation(); | |
| 32 } | |
| 33 | |
| 34 StyleInvalidator::InvalidationList& StyleInvalidator::ensurePendingInvalidationL ist(Element* element) | |
|
esprehn
2014/03/31 18:20:39
by reference
chrishtr
2014/03/31 19:22:59
Done.
| |
| 35 { | |
| 36 PendingInvalidationMap::AddResult addResult = m_pendingInvalidationMap.add(e lement, nullptr); | |
| 37 if (addResult.isNewEntry) | |
| 38 addResult.storedValue->value = adoptPtr(new InvalidationList); | |
| 39 return *addResult.storedValue->value; | |
| 40 } | |
| 41 | |
| 42 void StyleInvalidator::clearStyleInvalidation(Node* node) | |
| 43 { | |
| 44 node->clearChildNeedsStyleInvalidation(); | |
| 45 node->clearNeedsStyleInvalidation(); | |
| 46 if (node->isElementNode()) | |
| 47 m_pendingInvalidationMap.remove(toElement(node)); | |
| 48 } | |
| 49 | |
| 50 void StyleInvalidator::clear() | |
| 51 { | |
| 52 m_pendingInvalidationMap.clear(); | |
| 53 m_recursionData.clear(); | |
|
esprehn
2014/03/31 18:20:39
How is it possible to have recursion data at this
chrishtr
2014/03/31 19:22:59
It should not be possible. Removed.
| |
| 54 } | |
| 55 | |
| 56 void StyleInvalidator::RecursionData::clear(); | |
| 57 { | |
| 58 m_invalidationClasses.clear(); | |
| 59 m_invalidationAttributes.clear(); | |
| 60 m_foundInvalidationSet = false; | |
| 61 } | |
| 62 | |
| 63 StyleInvalidator::RecursionData::RecursionData() | |
| 64 { | |
| 65 clear(); | |
| 66 } | |
| 67 | |
| 68 StyleInvalidator::StyleInvalidator() | |
| 31 { } | 69 { } |
| 32 | 70 |
| 33 void StyleInvalidator::RecursionData::pushInvalidationSet(const DescendantInvali dationSet& invalidationSet) | 71 void StyleInvalidator::RecursionData::pushInvalidationSet(const DescendantInvali dationSet& invalidationSet) |
| 34 { | 72 { |
| 35 invalidationSet.getClasses(m_invalidationClasses); | 73 invalidationSet.getClasses(m_invalidationClasses); |
| 36 invalidationSet.getAttributes(m_invalidationAttributes); | 74 invalidationSet.getAttributes(m_invalidationAttributes); |
| 37 m_foundInvalidationSet = true; | 75 m_foundInvalidationSet = true; |
| 38 } | 76 } |
| 39 | 77 |
| 40 bool StyleInvalidator::RecursionData::matchesCurrentInvalidationSets(Element& el ement) | 78 bool StyleInvalidator::RecursionData::matchesCurrentInvalidationSets(Element& el ement) |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 53 } | 91 } |
| 54 } | 92 } |
| 55 | 93 |
| 56 return false; | 94 return false; |
| 57 } | 95 } |
| 58 | 96 |
| 59 bool StyleInvalidator::checkInvalidationSetsAgainstElement(Element& element) | 97 bool StyleInvalidator::checkInvalidationSetsAgainstElement(Element& element) |
| 60 { | 98 { |
| 61 bool thisElementNeedsStyleRecalc = false; | 99 bool thisElementNeedsStyleRecalc = false; |
| 62 if (element.needsStyleInvalidation()) { | 100 if (element.needsStyleInvalidation()) { |
| 63 if (RuleFeatureSet::InvalidationList* invalidationList = m_pendingInvali dationMap.get(&element)) { | 101 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. | 102 // FIXME: it's really only necessary to clone the render style for t his element, not full style recalc. |
| 65 thisElementNeedsStyleRecalc = true; | 103 thisElementNeedsStyleRecalc = true; |
| 66 for (RuleFeatureSet::InvalidationList::const_iterator it = invalidat ionList->begin(); it != invalidationList->end(); ++it) { | 104 for (InvalidationList::const_iterator it = invalidationList->begin() ; it != invalidationList->end(); ++it) { |
| 67 m_recursionData.pushInvalidationSet(**it); | 105 m_recursionData.pushInvalidationSet(**it); |
| 68 if ((*it)->wholeSubtreeInvalid()) { | 106 if ((*it)->wholeSubtreeInvalid()) { |
| 69 element.setNeedsStyleRecalc(SubtreeStyleChange); | 107 element.setNeedsStyleRecalc(SubtreeStyleChange); |
| 70 // Even though we have set needsStyleRecalc on the whole sub tree, we need to keep walking over the subtree | 108 // 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. | 109 // 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, | 110 // 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. | 111 // without checking classes etc. |
| 74 break; | 112 break; |
| 75 } | 113 } |
| 76 } | 114 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 } | 161 } |
| 124 } | 162 } |
| 125 | 163 |
| 126 element.clearChildNeedsStyleInvalidation(); | 164 element.clearChildNeedsStyleInvalidation(); |
| 127 element.clearNeedsStyleInvalidation(); | 165 element.clearNeedsStyleInvalidation(); |
| 128 | 166 |
| 129 return thisElementNeedsStyleRecalc; | 167 return thisElementNeedsStyleRecalc; |
| 130 } | 168 } |
| 131 | 169 |
| 132 } // namespace WebCore | 170 } // namespace WebCore |
| OLD | NEW |