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
This commit is contained in:
Elliott Sprehn 2015-01-07 11:57:32 -08:00
parent 9629178ee6
commit 8fc2d586cb
5 changed files with 19 additions and 27 deletions

View File

@ -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)

View File

@ -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<typename RuleDataListType>
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);

View File

@ -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))

View File

@ -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> element;
RawPtr<const ContainerNode> scope;
RenderStyle* elementStyle;
ContextFlags contextFlags;
};
bool match(const SelectorCheckingContext&) const;

View File

@ -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<SelectorChecker::ContextFlags>(contextFlags), cascadeScope, cascadeOrder);
collector.collectMatchingRules(matchRequest, ruleRange, cascadeScope, cascadeOrder);
}
}