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

Unified Diff: Source/core/css/resolver/ScopedStyleResolver.cpp

Issue 23567016: Have ScopedStyleResolver deal with ContainerNode references, not pointers (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 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/css/resolver/ScopedStyleResolver.h ('k') | Source/core/css/resolver/StyleResolver.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/resolver/ScopedStyleResolver.cpp
diff --git a/Source/core/css/resolver/ScopedStyleResolver.cpp b/Source/core/css/resolver/ScopedStyleResolver.cpp
index 53c76a3b7236141a25b8844b33c0e6340f1f1326..71a446fa012a5f660b9cae2e23456f266b51ed6c 100644
--- a/Source/core/css/resolver/ScopedStyleResolver.cpp
+++ b/Source/core/css/resolver/ScopedStyleResolver.cpp
@@ -41,9 +41,8 @@
namespace WebCore {
-ScopedStyleResolver* ScopedStyleTree::ensureScopedStyleResolver(const ContainerNode* scopingNode)
+ScopedStyleResolver* ScopedStyleTree::ensureScopedStyleResolver(const ContainerNode& scopingNode)
{
- ASSERT(scopingNode);
bool isNewEntry;
ScopedStyleResolver* scopedStyleResolver = addScopedStyleResolver(scopingNode, isNewEntry);
if (isNewEntry)
@@ -51,24 +50,24 @@ ScopedStyleResolver* ScopedStyleTree::ensureScopedStyleResolver(const ContainerN
return scopedStyleResolver;
}
-ScopedStyleResolver* ScopedStyleTree::scopedStyleResolverFor(const ContainerNode* scopingNode)
+ScopedStyleResolver* ScopedStyleTree::scopedStyleResolverFor(const ContainerNode& scopingNode)
{
- if (!scopingNode->hasScopedHTMLStyleChild()
- && !(scopingNode->isElementNode() && toElement(scopingNode)->shadow())
- && !scopingNode->isDocumentNode()
- && !scopingNode->isShadowRoot())
+ if (!scopingNode.hasScopedHTMLStyleChild()
+ && !(scopingNode.isElementNode() && toElement(scopingNode).shadow())
+ && !scopingNode.isDocumentNode()
+ && !scopingNode.isShadowRoot())
return 0;
- HashMap<const ContainerNode*, OwnPtr<ScopedStyleResolver> >::iterator it = m_authorStyles.find(scopingNode);
+ HashMap<const ContainerNode*, OwnPtr<ScopedStyleResolver> >::iterator it = m_authorStyles.find(&scopingNode);
return it != m_authorStyles.end() ? it->value.get() : 0;
}
-ScopedStyleResolver* ScopedStyleTree::addScopedStyleResolver(const ContainerNode* scopingNode, bool& isNewEntry)
+ScopedStyleResolver* ScopedStyleTree::addScopedStyleResolver(const ContainerNode& scopingNode, bool& isNewEntry)
{
- HashMap<const ContainerNode*, OwnPtr<ScopedStyleResolver> >::AddResult addResult = m_authorStyles.add(scopingNode, nullptr);
+ HashMap<const ContainerNode*, OwnPtr<ScopedStyleResolver> >::AddResult addResult = m_authorStyles.add(&scopingNode, nullptr);
if (addResult.isNewEntry) {
addResult.iterator->value = ScopedStyleResolver::create(scopingNode);
- if (!scopingNode || scopingNode->isDocumentNode())
+ if (scopingNode.isDocumentNode())
m_scopedResolverForDocument = addResult.iterator->value.get();
}
isNewEntry = addResult.isNewEntry;
@@ -78,21 +77,20 @@ ScopedStyleResolver* ScopedStyleTree::addScopedStyleResolver(const ContainerNode
void ScopedStyleTree::setupScopedStylesTree(ScopedStyleResolver* target)
{
ASSERT(target);
- ASSERT(target->scopingNode());
- const ContainerNode* scopingNode = target->scopingNode();
+ const ContainerNode& scopingNode = target->scopingNode();
// Since StyleResolver creates RuleSets according to styles' document
// order, a parent of the given ScopedRuleData has been already
// prepared.
- for (const ContainerNode* node = scopingNode->parentOrShadowHostNode(); node; node = node->parentOrShadowHostNode()) {
- if (ScopedStyleResolver* scopedResolver = scopedStyleResolverFor(node)) {
+ for (const ContainerNode* node = scopingNode.parentOrShadowHostNode(); node; node = node->parentOrShadowHostNode()) {
+ if (ScopedStyleResolver* scopedResolver = scopedStyleResolverFor(*node)) {
target->setParent(scopedResolver);
break;
}
if (node->isDocumentNode()) {
bool dummy;
- ScopedStyleResolver* scopedResolver = addScopedStyleResolver(node, dummy);
+ ScopedStyleResolver* scopedResolver = addScopedStyleResolver(*node, dummy);
target->setParent(scopedResolver);
setupScopedStylesTree(scopedResolver);
break;
@@ -106,7 +104,7 @@ void ScopedStyleTree::setupScopedStylesTree(ScopedStyleResolver* target)
for (HashMap<const ContainerNode*, OwnPtr<ScopedStyleResolver> >::iterator it = m_authorStyles.begin(); it != m_authorStyles.end(); ++it) {
if (it->value == target)
continue;
- if (it->value->parent() == target->parent() && scopingNode->containsIncludingShadowDOM(it->key))
+ if (it->value->parent() == target->parent() && scopingNode.containsIncludingShadowDOM(it->key))
it->value->setParent(target);
}
}
@@ -133,7 +131,7 @@ void ScopedStyleTree::collectScopedResolversForHostedShadowTrees(const Element*
// Adding scoped resolver for active shadow roots for shadow host styling.
for (ShadowRoot* shadowRoot = shadow->youngestShadowRoot(); shadowRoot; shadowRoot = shadowRoot->olderShadowRoot()) {
if (shadowRoot->hasScopedHTMLStyleChild()) {
- if (ScopedStyleResolver* resolver = scopedStyleResolverFor(shadowRoot))
+ if (ScopedStyleResolver* resolver = scopedStyleResolverFor(*shadowRoot))
resolvers.append(resolver);
}
if (!shadowRoot->containsShadowElements())
@@ -156,7 +154,7 @@ void ScopedStyleTree::resolveScopedKeyframesRules(const Element* element, Vector
inline ScopedStyleResolver* ScopedStyleTree::enclosingScopedStyleResolverFor(const ContainerNode* scopingNode)
{
for (; scopingNode; scopingNode = scopingNode->parentOrShadowHostNode()) {
- if (ScopedStyleResolver* scopedStyleResolver = scopedStyleResolverFor(scopingNode))
+ if (ScopedStyleResolver* scopedStyleResolver = scopedStyleResolverFor(*scopingNode))
return scopedStyleResolver;
}
return 0;
@@ -168,30 +166,30 @@ void ScopedStyleTree::resolveStyleCache(const ContainerNode* scopingNode)
m_cache.nodeForScopedStyles = scopingNode;
}
-void ScopedStyleTree::pushStyleCache(const ContainerNode* scopingNode, const ContainerNode* parent)
+void ScopedStyleTree::pushStyleCache(const ContainerNode& scopingNode, const ContainerNode* parent)
{
if (m_authorStyles.isEmpty())
return;
if (!cacheIsValid(parent)) {
- resolveStyleCache(scopingNode);
+ resolveStyleCache(&scopingNode);
return;
}
ScopedStyleResolver* scopedResolver = scopedStyleResolverFor(scopingNode);
if (scopedResolver)
m_cache.scopedResolver = scopedResolver;
- m_cache.nodeForScopedStyles = scopingNode;
+ m_cache.nodeForScopedStyles = &scopingNode;
}
-void ScopedStyleTree::popStyleCache(const ContainerNode* scopingNode)
+void ScopedStyleTree::popStyleCache(const ContainerNode& scopingNode)
{
- if (!cacheIsValid(scopingNode))
+ if (!cacheIsValid(&scopingNode))
return;
- if (m_cache.scopedResolver && m_cache.scopedResolver->scopingNode() == scopingNode)
+ if (m_cache.scopedResolver && &m_cache.scopedResolver->scopingNode() == &scopingNode)
m_cache.scopedResolver = m_cache.scopedResolver->parent();
- m_cache.nodeForScopedStyles = scopingNode->parentOrShadowHostNode();
+ m_cache.nodeForScopedStyles = scopingNode.parentOrShadowHostNode();
}
void ScopedStyleTree::collectFeaturesTo(RuleFeatureSet& features)
@@ -214,7 +212,7 @@ void ScopedStyleTree::remove(const ContainerNode* scopingNode)
if (!scopingNode || scopingNode->isDocumentNode())
return;
- ScopedStyleResolver* resolverRemoved = scopedStyleResolverFor(scopingNode);
+ ScopedStyleResolver* resolverRemoved = scopedStyleResolverFor(*scopingNode);
if (!resolverRemoved)
return;
@@ -251,7 +249,7 @@ void ScopedStyleResolver::addRulesFromSheet(StyleSheetContents* sheet, const Med
{
if (!m_authorStyle)
m_authorStyle = RuleSet::create();
- m_authorStyle->addRulesFromSheet(sheet, medium, resolver, m_scopingNode);
+ m_authorStyle->addRulesFromSheet(sheet, medium, resolver, &m_scopingNode);
}
inline RuleSet* ScopedStyleResolver::ensureAtHostRuleSetFor(const ShadowRoot* shadowRoot)
@@ -357,10 +355,10 @@ void ScopedStyleResolver::matchHostRules(ElementRuleCollector& collector, bool i
// FIXME: Determine tree position.
CascadeScope cascadeScope = ignoreCascadeScope;
- if (m_atHostRules.isEmpty() || !m_scopingNode->isElementNode())
+ if (m_atHostRules.isEmpty() || !m_scopingNode.isElementNode())
return;
- ElementShadow* shadow = toElement(m_scopingNode)->shadow();
+ ElementShadow* shadow = toElement(m_scopingNode).shadow();
if (!shadow)
return;
@@ -383,7 +381,7 @@ void ScopedStyleResolver::matchHostRules(ElementRuleCollector& collector, bool i
collector.setBehaviorAtBoundary(static_cast<SelectorChecker::BehaviorAtBoundary>(SelectorChecker::DoesNotCrossBoundary | SelectorChecker::ScopeContainsLastMatchedElement));
for (; shadowRoot; shadowRoot = shadowRoot->youngerShadowRoot()) {
if (RuleSet* ruleSet = atHostRuleSetFor(shadowRoot))
- collector.collectMatchingRules(MatchRequest(ruleSet, includeEmptyRules, m_scopingNode), ruleRange, cascadeScope);
+ collector.collectMatchingRules(MatchRequest(ruleSet, includeEmptyRules, &m_scopingNode), ruleRange, cascadeScope);
}
collector.sortAndTransferMatchedRules();
@@ -402,14 +400,14 @@ void ScopedStyleResolver::collectMatchingAuthorRules(ElementRuleCollector& colle
if (!m_authorStyle)
return;
- const ContainerNode* scopingNode = m_scopingNode;
+ const ContainerNode* scopingNode = &m_scopingNode;
unsigned behaviorAtBoundary = SelectorChecker::DoesNotCrossBoundary;
if (!applyAuthorStyles)
behaviorAtBoundary |= SelectorChecker::ScopeContainsLastMatchedElement;
- if (m_scopingNode->isShadowRoot()) {
- scopingNode = toShadowRoot(m_scopingNode)->host();
+ if (m_scopingNode.isShadowRoot()) {
+ scopingNode = toShadowRoot(m_scopingNode).host();
behaviorAtBoundary |= SelectorChecker::ScopeIsShadowHost;
}
@@ -423,7 +421,7 @@ void ScopedStyleResolver::collectMatchingAuthorRules(ElementRuleCollector& colle
void ScopedStyleResolver::matchPageRules(PageRuleCollector& collector)
{
// Only consider the global author RuleSet for @page rules, as per the HTML5 spec.
- ASSERT(m_scopingNode->isDocumentNode());
+ ASSERT(m_scopingNode.isDocumentNode());
collector.matchPageRules(m_authorStyle.get());
}
« no previous file with comments | « Source/core/css/resolver/ScopedStyleResolver.h ('k') | Source/core/css/resolver/StyleResolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698