Index: Source/core/dom/StyleEngine.cpp |
diff --git a/Source/core/dom/StyleEngine.cpp b/Source/core/dom/StyleEngine.cpp |
index 98b9051247b78f3aa9e738fb350c63447ae399e8..de290da44a22fb58e0154f6877522361aafc696b 100644 |
--- a/Source/core/dom/StyleEngine.cpp |
+++ b/Source/core/dom/StyleEngine.cpp |
@@ -103,9 +103,7 @@ void StyleEngine::detachFromDocument() |
m_fontSelector.clear(); |
m_resolver.clear(); |
m_styleSheetCollectionMap.clear(); |
- for (const auto& resolver : m_scopedStyleResolvers) |
- const_cast<TreeScope&>(resolver->treeScope()).clearScopedStyleResolver(); |
- m_scopedStyleResolvers.clear(); |
+ m_activeTreeScopes.clear(); |
} |
#endif |
@@ -396,8 +394,12 @@ void StyleEngine::updateActiveStyleSheets(StyleResolverUpdateMode updateMode) |
ShadowTreeStyleSheetCollection* collection = static_cast<ShadowTreeStyleSheetCollection*>(styleSheetCollectionFor(*treeScope)); |
ASSERT(collection); |
collection->updateActiveStyleSheets(this, updateMode); |
- if (!collection->hasStyleSheetCandidateNodes()) |
+ if (!collection->hasStyleSheetCandidateNodes()) { |
treeScopesRemoved.add(treeScope); |
+ // When removing TreeScope from ActiveTreeScopes, |
+ // its resolver should be destroyed by invoking resetAuthorStyle. |
+ ASSERT(!treeScope->scopedStyleResolver()); |
+ } |
} |
m_activeTreeScopes.removeAll(treeScopesRemoved); |
} |
@@ -433,8 +435,6 @@ const WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet> > StyleEngine::activeSt |
void StyleEngine::didRemoveShadowRoot(ShadowRoot* shadowRoot) |
{ |
- if (shadowRoot->scopedStyleResolver()) |
- removeScopedStyleResolver(shadowRoot->scopedStyleResolver()); |
m_styleSheetCollectionMap.remove(shadowRoot); |
} |
@@ -462,8 +462,9 @@ void StyleEngine::createResolver() |
ASSERT(document().frame()); |
m_resolver = adoptPtrWillBeNoop(new StyleResolver(*m_document)); |
- addScopedStyleResolver(&m_document->ensureScopedStyleResolver()); |
+ // A scoped style resolver for document will be created during |
+ // appendActiveAuthorStyleSheets if needed. |
appendActiveAuthorStyleSheets(); |
combineCSSFeatureFlags(m_resolver->ensureUpdatedRuleFeatureSet()); |
} |
@@ -473,9 +474,9 @@ void StyleEngine::clearResolver() |
ASSERT(!document().inStyleRecalc()); |
ASSERT(isMaster() || !m_resolver); |
- for (const auto& resolver: m_scopedStyleResolvers) |
- const_cast<TreeScope&>(resolver->treeScope()).clearScopedStyleResolver(); |
- m_scopedStyleResolvers.clear(); |
+ document().clearScopedStyleResolver(); |
+ for (auto& treeScope: m_activeTreeScopes) |
+ treeScope->clearScopedStyleResolver(); |
if (m_resolver) |
document().updateStyleInvalidationIfNeeded(); |
@@ -642,8 +643,12 @@ void StyleEngine::removeSheet(StyleSheetContents* contents) |
void StyleEngine::collectScopedStyleFeaturesTo(RuleFeatureSet& features) const |
{ |
HashSet<const StyleSheetContents*> visitedSharedStyleSheetContents; |
- for (const auto& resolver : m_scopedStyleResolvers) |
- resolver->collectFeaturesTo(features, visitedSharedStyleSheetContents); |
+ if (document().scopedStyleResolver()) |
+ document().scopedStyleResolver()->collectFeaturesTo(features, visitedSharedStyleSheetContents); |
+ for (auto& treeScope: m_activeTreeScopes) { |
+ ASSERT(treeScope->scopedStyleResolver()); |
+ treeScope->scopedStyleResolver()->collectFeaturesTo(features, visitedSharedStyleSheetContents); |
+ } |
} |
void StyleEngine::fontsNeedUpdate(CSSFontSelector*) |
@@ -664,7 +669,6 @@ void StyleEngine::trace(Visitor* visitor) |
visitor->trace(m_authorStyleSheets); |
visitor->trace(m_documentStyleSheetCollection); |
visitor->trace(m_styleSheetCollectionMap); |
- visitor->trace(m_scopedStyleResolvers); |
visitor->trace(m_resolver); |
visitor->trace(m_fontSelector); |
visitor->trace(m_textToSheetCache); |