From 8fc2d586cb3128bd98778b558b80ce348b79221c Mon Sep 17 00:00:00 2001 From: Elliott Sprehn Date: Wed, 7 Jan 2015 11:57:32 -0800 Subject: [PATCH] Remove SelectorChecker::ContextFlags. We don't need the flags, we can just use an explicit check for :host(). R=ojan@chromium.org Review URL: https://codereview.chromium.org/838863002 --- engine/core/css/ElementRuleCollector.cpp | 17 ++++++++--------- engine/core/css/ElementRuleCollector.h | 10 +++++----- engine/core/css/SelectorChecker.cpp | 8 +++++--- engine/core/css/SelectorChecker.h | 7 ------- .../core/css/resolver/ScopedStyleResolver.cpp | 4 +--- 5 files changed, 19 insertions(+), 27 deletions(-) diff --git a/engine/core/css/ElementRuleCollector.cpp b/engine/core/css/ElementRuleCollector.cpp index 18fa5a573dc..c5297a38300 100644 --- a/engine/core/css/ElementRuleCollector.cpp +++ b/engine/core/css/ElementRuleCollector.cpp @@ -90,7 +90,7 @@ static bool rulesApplicableInCurrentTreeScope(const Element* element, const Cont SelectorChecker::isHostInItsShadowTree(*element, scopingNode); } -void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest, RuleRange& ruleRange, SelectorChecker::ContextFlags contextFlags, CascadeScope cascadeScope, CascadeOrder cascadeOrder) +void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest, RuleRange& ruleRange, CascadeScope cascadeScope, CascadeOrder cascadeOrder) { ASSERT(matchRequest.ruleSet); ASSERT(m_context.element()); @@ -103,14 +103,14 @@ void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest // We need to collect the rules for id, class, tag, and everything else into a buffer and // then sort the buffer. if (element.hasID()) - collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForStyleResolution()), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleRange); + collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForStyleResolution()), cascadeScope, cascadeOrder, matchRequest, ruleRange); if (element.isStyledElement() && element.hasClass()) { for (size_t i = 0; i < element.classNames().size(); ++i) - collectMatchingRulesForList(matchRequest.ruleSet->classRules(element.classNames()[i]), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleRange); + collectMatchingRulesForList(matchRequest.ruleSet->classRules(element.classNames()[i]), cascadeScope, cascadeOrder, matchRequest, ruleRange); } - collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName()), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleRange); - collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleRange); + collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName()), cascadeScope, cascadeOrder, matchRequest, ruleRange); + collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), cascadeScope, cascadeOrder, matchRequest, ruleRange); } void ElementRuleCollector::sortAndTransferMatchedRules() @@ -129,20 +129,19 @@ void ElementRuleCollector::sortAndTransferMatchedRules() } } -inline bool ElementRuleCollector::ruleMatches(const RuleData& ruleData, const ContainerNode* scope, SelectorChecker::ContextFlags contextFlags) +inline bool ElementRuleCollector::ruleMatches(const RuleData& ruleData, const ContainerNode* scope) { SelectorChecker selectorChecker(m_context.element()->document(), m_mode); SelectorChecker::SelectorCheckingContext context(ruleData.selector(), m_context.element()); context.elementStyle = m_style.get(); context.scope = scope; - context.contextFlags = contextFlags; return selectorChecker.match(context); } -void ElementRuleCollector::collectRuleIfMatches(const RuleData& ruleData, SelectorChecker::ContextFlags contextFlags, CascadeScope cascadeScope, CascadeOrder cascadeOrder, const MatchRequest& matchRequest, RuleRange& ruleRange) +void ElementRuleCollector::collectRuleIfMatches(const RuleData& ruleData, CascadeScope cascadeScope, CascadeOrder cascadeOrder, const MatchRequest& matchRequest, RuleRange& ruleRange) { StyleRule* rule = ruleData.rule(); - if (ruleMatches(ruleData, matchRequest.scope, contextFlags)) { + if (ruleMatches(ruleData, matchRequest.scope)) { // If the rule has no properties to apply, then ignore it in the non-debug mode. const StylePropertySet& properties = rule->properties(); if (properties.isEmpty() && !matchRequest.includeEmptyRules) diff --git a/engine/core/css/ElementRuleCollector.h b/engine/core/css/ElementRuleCollector.h index 363b7c9dbbf..5d811987be5 100644 --- a/engine/core/css/ElementRuleCollector.h +++ b/engine/core/css/ElementRuleCollector.h @@ -103,25 +103,25 @@ public: MatchResult& matchedResult(); - void collectMatchingRules(const MatchRequest&, RuleRange&, SelectorChecker::ContextFlags = SelectorChecker::DefaultBehavior, CascadeScope = ignoreCascadeScope, CascadeOrder = ignoreCascadeOrder); + void collectMatchingRules(const MatchRequest&, RuleRange&, CascadeScope = ignoreCascadeScope, CascadeOrder = ignoreCascadeOrder); void sortAndTransferMatchedRules(); void clearMatchedRules(); void addElementStyleProperties(const StylePropertySet*, bool isCacheable = true); private: - void collectRuleIfMatches(const RuleData&, SelectorChecker::ContextFlags, CascadeScope, CascadeOrder, const MatchRequest&, RuleRange&); + void collectRuleIfMatches(const RuleData&, CascadeScope, CascadeOrder, const MatchRequest&, RuleRange&); template - void collectMatchingRulesForList(const RuleDataListType* rules, SelectorChecker::ContextFlags contextFlags, CascadeScope cascadeScope, CascadeOrder cascadeOrder, const MatchRequest& matchRequest, RuleRange& ruleRange) + void collectMatchingRulesForList(const RuleDataListType* rules, CascadeScope cascadeScope, CascadeOrder cascadeOrder, const MatchRequest& matchRequest, RuleRange& ruleRange) { if (!rules) return; for (typename RuleDataListType::const_iterator it = rules->begin(), end = rules->end(); it != end; ++it) - collectRuleIfMatches(*it, contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleRange); + collectRuleIfMatches(*it, cascadeScope, cascadeOrder, matchRequest, ruleRange); } - bool ruleMatches(const RuleData&, const ContainerNode* scope, SelectorChecker::ContextFlags); + bool ruleMatches(const RuleData&, const ContainerNode* scope); void sortMatchedRules(); void addMatchedRule(const RuleData*, CascadeScope, CascadeOrder, unsigned styleSheetIndex, const CSSStyleSheet* parentStyleSheet); diff --git a/engine/core/css/SelectorChecker.cpp b/engine/core/css/SelectorChecker.cpp index 487c662deaf..92959f4ec7c 100644 --- a/engine/core/css/SelectorChecker.cpp +++ b/engine/core/css/SelectorChecker.cpp @@ -64,8 +64,7 @@ bool SelectorChecker::match(const SelectorCheckingContext& context) const // FIXME(sky): Get rid of SelectorCheckingContext. SelectorCheckingContext matchContext(context); - bool isShadowHost = isHostInItsShadowTree(*context.element, context.scope) - && !(context.contextFlags & TreatShadowHostAsNormalScope); + bool isShadowHost = isHostInItsShadowTree(*context.element, context.scope); while (true) { const CSSSelector& selector = *matchContext.selector; @@ -287,7 +286,10 @@ bool SelectorChecker::checkPseudoClass(const SelectorCheckingContext& context) c return true; SelectorCheckingContext subContext(context); - subContext.contextFlags = TreatShadowHostAsNormalScope; + + // Treat the inside of :host() rules as if they were defined in the + // same scope as the host. + subContext.scope = &context.element->treeScope().rootNode(); for (subContext.selector = selector.selectorList()->first(); subContext.selector; subContext.selector = CSSSelectorList::next(*subContext.selector)) { if (match(subContext)) diff --git a/engine/core/css/SelectorChecker.h b/engine/core/css/SelectorChecker.h index bd003c6dd26..e9b28f5740c 100644 --- a/engine/core/css/SelectorChecker.h +++ b/engine/core/css/SelectorChecker.h @@ -43,11 +43,6 @@ class SelectorChecker { public: enum Mode { ResolvingStyle = 0, QueryingRules, SharingRules }; explicit SelectorChecker(Document&, Mode); - enum ContextFlags { - // FIXME: Revmoe DefaultBehavior. - DefaultBehavior = 0, - TreatShadowHostAsNormalScope = 1, - }; struct SelectorCheckingContext { STACK_ALLOCATED(); @@ -58,7 +53,6 @@ public: , element(element) , scope(nullptr) , elementStyle(0) - , contextFlags(DefaultBehavior) { } @@ -66,7 +60,6 @@ public: RawPtr element; RawPtr scope; RenderStyle* elementStyle; - ContextFlags contextFlags; }; bool match(const SelectorCheckingContext&) const; diff --git a/engine/core/css/resolver/ScopedStyleResolver.cpp b/engine/core/css/resolver/ScopedStyleResolver.cpp index 73edabb4bef..08de8f870e8 100644 --- a/engine/core/css/resolver/ScopedStyleResolver.cpp +++ b/engine/core/css/resolver/ScopedStyleResolver.cpp @@ -78,12 +78,10 @@ const StyleRuleKeyframes* ScopedStyleResolver::keyframeStylesForAnimation(String void ScopedStyleResolver::collectMatchingAuthorRules(ElementRuleCollector& collector, bool includeEmptyRules, CascadeScope cascadeScope, CascadeOrder cascadeOrder) { - unsigned contextFlags = SelectorChecker::DefaultBehavior; - RuleRange ruleRange = collector.matchedResult().ranges.authorRuleRange(); for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) { MatchRequest matchRequest(&m_authorStyleSheets[i]->contents()->ruleSet(), includeEmptyRules, &m_scope->rootNode(), m_authorStyleSheets[i], i); - collector.collectMatchingRules(matchRequest, ruleRange, static_cast(contextFlags), cascadeScope, cascadeOrder); + collector.collectMatchingRules(matchRequest, ruleRange, cascadeScope, cascadeOrder); } }