Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(819)

Unified Diff: Source/core/dom/StyleEngine.cpp

Issue 1111643003: Move StyleInvalidator to StyleEngine. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Avoid calling ensureUpdatedRuleFeatureSet multiple times Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/StyleEngine.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/StyleEngine.cpp
diff --git a/Source/core/dom/StyleEngine.cpp b/Source/core/dom/StyleEngine.cpp
index d25247045e79e69558b151b2e439ffa065cc32dc..f36f7be975c14a98770ad05e623a325e2dc7c5f6 100644
--- a/Source/core/dom/StyleEngine.cpp
+++ b/Source/core/dom/StyleEngine.cpp
@@ -694,6 +694,92 @@ void StyleEngine::platformColorsChanged()
document().setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::PlatformColorChange));
}
+void StyleEngine::classChangedForElement(const SpaceSplitString& changedClasses, Element& element)
+{
+ ASSERT(isMaster());
+ InvalidationSetVector invalidationSets;
+ unsigned changedSize = changedClasses.size();
+ RuleFeatureSet& ruleFeatureSet = ensureResolver().ensureUpdatedRuleFeatureSet();
+ for (unsigned i = 0; i < changedSize; ++i)
+ ruleFeatureSet.collectInvalidationSetsForClass(invalidationSets, element, changedClasses[i]);
+ scheduleInvalidationSetsForElement(invalidationSets, element);
+}
+
+void StyleEngine::classChangedForElement(const SpaceSplitString& oldClasses, const SpaceSplitString& newClasses, Element& element)
+{
+ ASSERT(isMaster());
+ InvalidationSetVector invalidationSets;
+ if (!oldClasses.size()) {
+ classChangedForElement(newClasses, element);
+ return;
+ }
+
+ // Class vectors tend to be very short. This is faster than using a hash table.
+ BitVector remainingClassBits;
+ remainingClassBits.ensureSize(oldClasses.size());
+
+ RuleFeatureSet& ruleFeatureSet = ensureResolver().ensureUpdatedRuleFeatureSet();
+
+ for (unsigned i = 0; i < newClasses.size(); ++i) {
+ bool found = false;
+ for (unsigned j = 0; j < oldClasses.size(); ++j) {
+ if (newClasses[i] == oldClasses[j]) {
+ // Mark each class that is still in the newClasses so we can skip doing
+ // an n^2 search below when looking for removals. We can't break from
+ // this loop early since a class can appear more than once.
+ remainingClassBits.quickSet(j);
+ found = true;
+ }
+ }
+ // Class was added.
+ if (!found)
+ ruleFeatureSet.collectInvalidationSetsForClass(invalidationSets, element, newClasses[i]);
+ }
+
+ for (unsigned i = 0; i < oldClasses.size(); ++i) {
+ if (remainingClassBits.quickGet(i))
+ continue;
+ // Class was removed.
+ ruleFeatureSet.collectInvalidationSetsForClass(invalidationSets, element, oldClasses[i]);
+ }
+
+ scheduleInvalidationSetsForElement(invalidationSets, element);
+}
+
+void StyleEngine::attributeChangedForElement(const QualifiedName& attributeName, Element& element)
+{
+ ASSERT(isMaster());
+ InvalidationSetVector invalidationSets;
+ ensureResolver().ensureUpdatedRuleFeatureSet().collectInvalidationSetsForAttribute(invalidationSets, element, attributeName);
+ scheduleInvalidationSetsForElement(invalidationSets, element);
+}
+
+void StyleEngine::idChangedForElement(const AtomicString& oldId, const AtomicString& newId, Element& element)
+{
+ ASSERT(isMaster());
+ InvalidationSetVector invalidationSets;
+ RuleFeatureSet& ruleFeatureSet = ensureResolver().ensureUpdatedRuleFeatureSet();
+ if (!oldId.isEmpty())
+ ruleFeatureSet.collectInvalidationSetsForId(invalidationSets, element, oldId);
+ if (!newId.isEmpty())
+ ruleFeatureSet.collectInvalidationSetsForId(invalidationSets, element, newId);
+ scheduleInvalidationSetsForElement(invalidationSets, element);
+}
+
+void StyleEngine::pseudoStateChangedForElement(CSSSelector::PseudoType pseudoType, Element& element)
+{
+ ASSERT(isMaster());
+ InvalidationSetVector invalidationSets;
+ ensureResolver().ensureUpdatedRuleFeatureSet().collectInvalidationSetsForPseudoClass(invalidationSets, element, pseudoType);
+ scheduleInvalidationSetsForElement(invalidationSets, element);
+}
+
+void StyleEngine::scheduleInvalidationSetsForElement(const InvalidationSetVector& invalidationSets, Element& element)
+{
+ for (auto invalidationSet : invalidationSets)
+ m_styleInvalidator.scheduleInvalidation(invalidationSet, element);
+}
+
DEFINE_TRACE(StyleEngine)
{
#if ENABLE(OILPAN)
@@ -702,6 +788,7 @@ DEFINE_TRACE(StyleEngine)
visitor->trace(m_documentStyleSheetCollection);
visitor->trace(m_styleSheetCollectionMap);
visitor->trace(m_resolver);
+ visitor->trace(m_styleInvalidator);
visitor->trace(m_dirtyTreeScopes);
visitor->trace(m_activeTreeScopes);
visitor->trace(m_fontSelector);
« no previous file with comments | « Source/core/dom/StyleEngine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698