mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Remove global set of ScopedStyleResolvers.
Just walk the DOM instead. This will be slower, but I'm going to get rid of the global RuleFeatureSet anyway, so this is just a temporary measure to simplify the system. Removing the set also means removing a bunch of special cases for when the document didn't have any ShadowRoots with styles (which is very unlikely in Sky). R=eseidel@chromium.org Review URL: https://codereview.chromium.org/810893002
This commit is contained in:
parent
a30b0288e2
commit
2a1d0c5abb
@ -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<RawPtr<ScopedStyleResolver>, 8> stack;
|
||||
resolver->styleTreeResolveScopedKeyframesRules(element, stack);
|
||||
if (stack.isEmpty())
|
||||
|
||||
@ -39,6 +39,11 @@
|
||||
|
||||
namespace blink {
|
||||
|
||||
ScopedStyleResolver::ScopedStyleResolver(TreeScope& scope)
|
||||
: m_scope(scope)
|
||||
{
|
||||
}
|
||||
|
||||
void ScopedStyleResolver::addRulesFromSheet(CSSStyleSheet* cssSheet, StyleResolver* resolver)
|
||||
{
|
||||
m_authorStyleSheets.append(cssSheet);
|
||||
|
||||
@ -62,13 +62,9 @@ public:
|
||||
void resetAuthorStyle();
|
||||
|
||||
private:
|
||||
explicit ScopedStyleResolver(TreeScope& scope)
|
||||
: m_scope(scope)
|
||||
{
|
||||
}
|
||||
explicit ScopedStyleResolver(TreeScope&);
|
||||
|
||||
RawPtr<TreeScope> m_scope;
|
||||
|
||||
Vector<RawPtr<CSSStyleSheet> > m_authorStyleSheets;
|
||||
|
||||
typedef HashMap<const StringImpl*, RefPtr<StyleRuleKeyframes> > KeyframesRuleMap;
|
||||
|
||||
@ -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<RawPtr<StyleRuleKeyframes> > 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<RawPtr<ScopedStyleResolver>, 8> resolvers;
|
||||
if (ScopedStyleResolver* resolver = element->treeScope().scopedStyleResolver())
|
||||
resolvers.append(resolver);
|
||||
resolvers.append(&element->treeScope().scopedStyleResolver());
|
||||
|
||||
Vector<RawPtr<ScopedStyleResolver>, 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<RawPtr<ScopedStyleResolver>, 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 <StyleResolver::StyleApplicationPass pass>
|
||||
|
||||
@ -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<TreeScope&>((*it)->treeScope()).clearScopedStyleResolver();
|
||||
m_scopedStyleResolvers.clear();
|
||||
}
|
||||
|
||||
const Vector<RefPtr<CSSStyleSheet>>& 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<TreeScope&>((*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<const StyleSheetContents*> 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<const StyleSheetContents*> 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*)
|
||||
|
||||
@ -117,9 +117,6 @@ public:
|
||||
PassRefPtr<CSSStyleSheet> 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<RawPtr<TreeScope>, OwnPtr<StyleSheetCollection> > StyleSheetCollectionMap;
|
||||
StyleSheetCollectionMap m_styleSheetCollectionMap;
|
||||
typedef HashSet<RawPtr<const ScopedStyleResolver> > ScopedStyleResolverSet;
|
||||
ScopedStyleResolverSet m_scopedStyleResolvers;
|
||||
|
||||
typedef ListHashSet<TreeScope*, 16> TreeScopeSet;
|
||||
TreeScopeSet m_dirtyTreeScopes;
|
||||
|
||||
@ -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())
|
||||
|
||||
@ -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<Document> m_document;
|
||||
RawPtr<TreeScope> m_parentTreeScope;
|
||||
|
||||
#if !ENABLE(OILPAN)
|
||||
int m_guardRefCount;
|
||||
#endif
|
||||
OwnPtr<ScopedStyleResolver> m_scopedStyleResolver;
|
||||
|
||||
OwnPtr<DocumentOrderedMap> m_elementsById;
|
||||
OwnPtr<DocumentOrderedMap> m_imageMapsByName;
|
||||
OwnPtr<DocumentOrderedMap> m_labelsByForAttribute;
|
||||
|
||||
OwnPtr<ScopedStyleResolver> m_scopedStyleResolver;
|
||||
|
||||
mutable RefPtr<DOMSelection> m_selection;
|
||||
|
||||
int m_guardRefCount;
|
||||
};
|
||||
|
||||
DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(TreeScope)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user