diff --git a/engine/core/animation/css/CSSAnimations.cpp b/engine/core/animation/css/CSSAnimations.cpp index 1d542471644..997f5bb2d3e 100644 --- a/engine/core/animation/css/CSSAnimations.cpp +++ b/engine/core/animation/css/CSSAnimations.cpp @@ -196,9 +196,6 @@ static void resolveKeyframes(StyleResolver* resolver, Element* element, const El const StyleRuleKeyframes* CSSAnimations::matchScopedKeyframesRule(StyleResolver* resolver, const Element* element, const StringImpl* animationName) { // FIXME: This is all implementation detail of style resolver, CSSAnimations shouldn't be reaching into any of it. - if (resolver->document().styleEngine()->hasOnlyScopedResolverForDocument()) - return element->document().scopedStyleResolver()->keyframeStylesForAnimation(animationName); - Vector, 8> stack; resolver->styleTreeResolveScopedKeyframesRules(element, stack); if (stack.isEmpty()) diff --git a/engine/core/css/resolver/ScopedStyleResolver.cpp b/engine/core/css/resolver/ScopedStyleResolver.cpp index 0872d349414..6769ef6e78a 100644 --- a/engine/core/css/resolver/ScopedStyleResolver.cpp +++ b/engine/core/css/resolver/ScopedStyleResolver.cpp @@ -39,6 +39,11 @@ namespace blink { +ScopedStyleResolver::ScopedStyleResolver(TreeScope& scope) + : m_scope(scope) +{ +} + void ScopedStyleResolver::addRulesFromSheet(CSSStyleSheet* cssSheet, StyleResolver* resolver) { m_authorStyleSheets.append(cssSheet); diff --git a/engine/core/css/resolver/ScopedStyleResolver.h b/engine/core/css/resolver/ScopedStyleResolver.h index f12de44beb7..48c10585e33 100644 --- a/engine/core/css/resolver/ScopedStyleResolver.h +++ b/engine/core/css/resolver/ScopedStyleResolver.h @@ -62,13 +62,9 @@ public: void resetAuthorStyle(); private: - explicit ScopedStyleResolver(TreeScope& scope) - : m_scope(scope) - { - } + explicit ScopedStyleResolver(TreeScope&); RawPtr m_scope; - Vector > m_authorStyleSheets; typedef HashMap > KeyframesRuleMap; diff --git a/engine/core/css/resolver/StyleResolver.cpp b/engine/core/css/resolver/StyleResolver.cpp index 144b45c9462..fa9e93ba79a 100644 --- a/engine/core/css/resolver/StyleResolver.cpp +++ b/engine/core/css/resolver/StyleResolver.cpp @@ -167,8 +167,7 @@ void StyleResolver::appendCSSStyleSheet(CSSStyleSheet* cssSheet) return; TreeScope& treeScope = ownerNode->treeScope(); - ScopedStyleResolver& resolver = treeScope.ensureScopedStyleResolver(); - document().styleEngine()->addScopedStyleResolver(&resolver); + ScopedStyleResolver& resolver = treeScope.scopedStyleResolver(); resolver.addRulesFromSheet(cssSheet, this); } @@ -208,8 +207,7 @@ void StyleResolver::resetRuleFeatures() void StyleResolver::processScopedRules(const RuleSet& authorRules, CSSStyleSheet* parentStyleSheet, unsigned parentIndex, ContainerNode& scope) { const Vector > keyframesRules = authorRules.keyframesRules(); - ScopedStyleResolver* resolver = &scope.treeScope().ensureScopedStyleResolver(); - document().styleEngine()->addScopedStyleResolver(resolver); + ScopedStyleResolver* resolver = &scope.treeScope().scopedStyleResolver(); for (unsigned i = 0; i < keyframesRules.size(); ++i) resolver->addKeyframeStyle(keyframesRules[i]); @@ -225,18 +223,8 @@ void StyleResolver::processScopedRules(const RuleSet& authorRules, CSSStyleSheet void StyleResolver::resetAuthorStyle(TreeScope& treeScope) { - ScopedStyleResolver* resolver = treeScope.scopedStyleResolver(); - if (!resolver) - return; - - resolver->resetAuthorStyle(); + treeScope.scopedStyleResolver().resetAuthorStyle(); resetRuleFeatures(); - if (treeScope.rootNode().isDocumentNode()) - return; - - // resolver is going to be freed below. - document().styleEngine()->removeScopedStyleResolver(resolver); - treeScope.clearScopedStyleResolver(); } void StyleResolver::collectFeatures() @@ -322,15 +310,9 @@ void StyleResolver::matchAuthorRules(Element* element, ElementRuleCollector& col collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult().matchedProperties.size() - 1; bool applyAuthorStyles = applyAuthorStylesOf(element); - if (document().styleEngine()->hasOnlyScopedResolverForDocument()) { - document().scopedStyleResolver()->collectMatchingAuthorRules(collector, includeEmptyRules, applyAuthorStyles, ignoreCascadeScope); - collector.sortAndTransferMatchedRules(); - return; - } Vector, 8> resolvers; - if (ScopedStyleResolver* resolver = element->treeScope().scopedStyleResolver()) - resolvers.append(resolver); + resolvers.append(&element->treeScope().scopedStyleResolver()); Vector, 8> resolversInShadowTree; collectScopedResolversForHostedShadowTrees(element, resolversInShadowTree); @@ -630,20 +612,15 @@ void StyleResolver::collectScopedResolversForHostedShadowTrees(const Element* el return; // Adding scoped resolver for active shadow roots for shadow host styling. - if (ShadowRoot* shadowRoot = shadow->shadowRoot()) { - if (ScopedStyleResolver* resolver = shadowRoot->scopedStyleResolver()) - resolvers.append(resolver); - } + if (ShadowRoot* shadowRoot = shadow->shadowRoot()) + resolvers.append(&shadowRoot->scopedStyleResolver()); } void StyleResolver::styleTreeResolveScopedKeyframesRules(const Element* element, Vector, 8>& resolvers) { // Add resolvers for shadow roots hosted by the given element. collectScopedResolversForHostedShadowTrees(element, resolvers); - - // Add resolvers while walking up DOM tree from the given element. - if (ScopedStyleResolver* resolver = element->treeScope().scopedStyleResolver()) - resolvers.append(resolver); + resolvers.append(&element->treeScope().scopedStyleResolver()); } template diff --git a/engine/core/dom/StyleEngine.cpp b/engine/core/dom/StyleEngine.cpp index b0fc8b8fbca..293b81d3fd3 100644 --- a/engine/core/dom/StyleEngine.cpp +++ b/engine/core/dom/StyleEngine.cpp @@ -33,6 +33,7 @@ #include "sky/engine/core/css/FontFaceCache.h" #include "sky/engine/core/css/StyleSheetContents.h" #include "sky/engine/core/dom/Element.h" +#include "sky/engine/core/dom/ElementTraversal.h" #include "sky/engine/core/dom/StyleSheetCollection.h" #include "sky/engine/core/dom/shadow/ShadowRoot.h" #include "sky/engine/core/frame/Settings.h" @@ -73,9 +74,6 @@ void StyleEngine::detachFromDocument() m_fontSelector.clear(); m_resolver.clear(); m_styleSheetCollectionMap.clear(); - for (ScopedStyleResolverSet::iterator it = m_scopedStyleResolvers.begin(); it != m_scopedStyleResolvers.end(); ++it) - const_cast((*it)->treeScope()).clearScopedStyleResolver(); - m_scopedStyleResolvers.clear(); } const Vector>& StyleEngine::activeAuthorStyleSheetsFor(TreeScope& treeScope) @@ -178,8 +176,6 @@ void StyleEngine::updateActiveStyleSheets() void StyleEngine::didRemoveShadowRoot(ShadowRoot* shadowRoot) { - if (shadowRoot->scopedStyleResolver()) - removeScopedStyleResolver(shadowRoot->scopedStyleResolver()); m_styleSheetCollectionMap.remove(shadowRoot); } @@ -205,7 +201,6 @@ void StyleEngine::createResolver() ASSERT(m_document->frame()); m_resolver = adoptPtr(new StyleResolver(*m_document)); - addScopedStyleResolver(&m_document->ensureScopedStyleResolver()); appendActiveAuthorStyleSheets(); } @@ -213,10 +208,6 @@ void StyleEngine::createResolver() void StyleEngine::clearResolver() { ASSERT(!m_document->inStyleRecalc()); - - for (ScopedStyleResolverSet::iterator it = m_scopedStyleResolvers.begin(); it != m_scopedStyleResolvers.end(); ++it) - const_cast((*it)->treeScope()).clearScopedStyleResolver(); - m_scopedStyleResolvers.clear(); m_resolver.clear(); } @@ -317,11 +308,21 @@ void StyleEngine::removeSheet(StyleSheetContents* contents) m_sheetToTextCache.remove(contents); } +// TODO(esprehn): This walks the entire document to collect features, instead +// we should store features per scope and get rid of the global set. +static void collectFeatures(TreeScope& scope, RuleFeatureSet& features, HashSet visitedSharedStyleSheetContents) +{ + scope.scopedStyleResolver().collectFeaturesTo(features, visitedSharedStyleSheetContents); + for (Element* element = ElementTraversal::firstWithin(scope.rootNode()); element; element = ElementTraversal::next(*element, &scope.rootNode())) { + if (ShadowRoot* root = element->shadowRoot()) + collectFeatures(*root, features, visitedSharedStyleSheetContents); + } +} + void StyleEngine::collectScopedStyleFeaturesTo(RuleFeatureSet& features) const { HashSet visitedSharedStyleSheetContents; - for (ScopedStyleResolverSet::iterator it = m_scopedStyleResolvers.begin(); it != m_scopedStyleResolvers.end(); ++it) - (*it)->collectFeaturesTo(features, visitedSharedStyleSheetContents); + collectFeatures(*m_document, features, visitedSharedStyleSheetContents); } void StyleEngine::fontsNeedUpdate(CSSFontSelector*) diff --git a/engine/core/dom/StyleEngine.h b/engine/core/dom/StyleEngine.h index 9d8e89114fb..c41840cebc2 100644 --- a/engine/core/dom/StyleEngine.h +++ b/engine/core/dom/StyleEngine.h @@ -117,9 +117,6 @@ public: PassRefPtr createSheet(Element*, const String& text); void removeSheet(StyleSheetContents*); - void addScopedStyleResolver(const ScopedStyleResolver* resolver) { m_scopedStyleResolvers.add(resolver); } - void removeScopedStyleResolver(const ScopedStyleResolver* resolver) { m_scopedStyleResolvers.remove(resolver); } - bool hasOnlyScopedResolverForDocument() const { return m_scopedStyleResolvers.size() == 1; } void collectScopedStyleFeaturesTo(RuleFeatureSet&) const; private: @@ -153,8 +150,6 @@ private: typedef HashMap, OwnPtr > StyleSheetCollectionMap; StyleSheetCollectionMap m_styleSheetCollectionMap; - typedef HashSet > ScopedStyleResolverSet; - ScopedStyleResolverSet m_scopedStyleResolvers; typedef ListHashSet TreeScopeSet; TreeScopeSet m_dirtyTreeScopes; diff --git a/engine/core/dom/TreeScope.cpp b/engine/core/dom/TreeScope.cpp index d38bd66bacb..3af09ff1d2f 100644 --- a/engine/core/dom/TreeScope.cpp +++ b/engine/core/dom/TreeScope.cpp @@ -54,9 +54,8 @@ TreeScope::TreeScope(ContainerNode& rootNode, Document& document) : m_rootNode(&rootNode) , m_document(&document) , m_parentTreeScope(&document) -#if !ENABLE(OILPAN) + , m_scopedStyleResolver(ScopedStyleResolver::create(*this)) , m_guardRefCount(0) -#endif { ASSERT(rootNode != document); #if !ENABLE(OILPAN) @@ -69,16 +68,14 @@ TreeScope::TreeScope(Document& document) : m_rootNode(document) , m_document(&document) , m_parentTreeScope(nullptr) -#if !ENABLE(OILPAN) + , m_scopedStyleResolver(ScopedStyleResolver::create(*this)) , m_guardRefCount(0) -#endif { m_rootNode->setTreeScope(this); } TreeScope::~TreeScope() { -#if !ENABLE(OILPAN) ASSERT(!m_guardRefCount); m_rootNode->setTreeScope(0); @@ -89,7 +86,6 @@ TreeScope::~TreeScope() if (m_parentTreeScope) m_parentTreeScope->guardDeref(); -#endif } bool TreeScope::isInclusiveOlderSiblingShadowRootOrAncestorTreeScopeOf(const TreeScope& scope) const @@ -129,19 +125,6 @@ void TreeScope::setParentTreeScope(TreeScope& newParentScope) setDocument(newParentScope.document()); } -ScopedStyleResolver& TreeScope::ensureScopedStyleResolver() -{ - RELEASE_ASSERT(this); - if (!m_scopedStyleResolver) - m_scopedStyleResolver = ScopedStyleResolver::create(*this); - return *m_scopedStyleResolver; -} - -void TreeScope::clearScopedStyleResolver() -{ - m_scopedStyleResolver.clear(); -} - Element* TreeScope::getElementById(const AtomicString& elementId) const { if (elementId.isEmpty()) diff --git a/engine/core/dom/TreeScope.h b/engine/core/dom/TreeScope.h index cd8691bae1b..93adc1b448b 100644 --- a/engine/core/dom/TreeScope.h +++ b/engine/core/dom/TreeScope.h @@ -113,9 +113,7 @@ public: Element* getElementByAccessKey(const String& key) const; - ScopedStyleResolver* scopedStyleResolver() const { return m_scopedStyleResolver.get(); } - ScopedStyleResolver& ensureScopedStyleResolver(); - void clearScopedStyleResolver(); + ScopedStyleResolver& scopedStyleResolver() const { return *m_scopedStyleResolver; } protected: TreeScope(ContainerNode&, Document&); @@ -156,17 +154,15 @@ private: RawPtr m_document; RawPtr m_parentTreeScope; -#if !ENABLE(OILPAN) - int m_guardRefCount; -#endif + OwnPtr m_scopedStyleResolver; OwnPtr m_elementsById; OwnPtr m_imageMapsByName; OwnPtr m_labelsByForAttribute; - OwnPtr m_scopedStyleResolver; - mutable RefPtr m_selection; + + int m_guardRefCount; }; DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(TreeScope)