| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
| 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
| 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc.
All rights reserved. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc.
All rights reserved. |
| 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
| 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
| 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
| 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 if ((behaviorAtBoundary & SelectorChecker::BoundaryBehaviorMask) == Selector
Checker::CrossesBoundary) | 134 if ((behaviorAtBoundary & SelectorChecker::BoundaryBehaviorMask) == Selector
Checker::CrossesBoundary) |
| 135 return true; | 135 return true; |
| 136 return false; | 136 return false; |
| 137 } | 137 } |
| 138 | 138 |
| 139 void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest
, RuleRange& ruleRange, SelectorChecker::BehaviorAtBoundary behaviorAtBoundary,
CascadeScope cascadeScope, CascadeOrder cascadeOrder) | 139 void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest
, RuleRange& ruleRange, SelectorChecker::BehaviorAtBoundary behaviorAtBoundary,
CascadeScope cascadeScope, CascadeOrder cascadeOrder) |
| 140 { | 140 { |
| 141 ASSERT(matchRequest.ruleSet); | 141 ASSERT(matchRequest.ruleSet); |
| 142 ASSERT(m_context.element()); | 142 ASSERT(m_context.element()); |
| 143 | 143 |
| 144 Element* element = m_context.element(); | 144 Element& element = *m_context.element(); |
| 145 const AtomicString& pseudoId = element->shadowPseudoId(); | 145 const AtomicString& pseudoId = element.shadowPseudoId(); |
| 146 if (!pseudoId.isEmpty()) { | 146 if (!pseudoId.isEmpty()) { |
| 147 ASSERT(element->isStyledElement()); | 147 ASSERT(element.isStyledElement()); |
| 148 collectMatchingRulesForList(matchRequest.ruleSet->shadowPseudoElementRul
es(pseudoId.impl()), behaviorAtBoundary, ignoreCascadeScope, cascadeOrder, match
Request, ruleRange); | 148 collectMatchingRulesForList(matchRequest.ruleSet->shadowPseudoElementRul
es(pseudoId.impl()), behaviorAtBoundary, ignoreCascadeScope, cascadeOrder, match
Request, ruleRange); |
| 149 } | 149 } |
| 150 | 150 |
| 151 if (element->isWebVTTElement()) | 151 if (element.isWebVTTElement()) |
| 152 collectMatchingRulesForList(matchRequest.ruleSet->cuePseudoRules(), beha
viorAtBoundary, cascadeScope, cascadeOrder, matchRequest, ruleRange); | 152 collectMatchingRulesForList(matchRequest.ruleSet->cuePseudoRules(), beha
viorAtBoundary, cascadeScope, cascadeOrder, matchRequest, ruleRange); |
| 153 // Check whether other types of rules are applicable in the current tree sco
pe. Criteria for this: | 153 // Check whether other types of rules are applicable in the current tree sco
pe. Criteria for this: |
| 154 // a) it's a UA rule | 154 // a) it's a UA rule |
| 155 // b) the tree scope allows author rules | 155 // b) the tree scope allows author rules |
| 156 // c) the rules comes from a scoped style sheet within the same tree scope | 156 // c) the rules comes from a scoped style sheet within the same tree scope |
| 157 // d) the rules comes from a scoped style sheet within an active shadow root
whose host is the given element | 157 // d) the rules comes from a scoped style sheet within an active shadow root
whose host is the given element |
| 158 // e) the rules can cross boundaries | 158 // e) the rules can cross boundaries |
| 159 // b)-e) is checked in rulesApplicableInCurrentTreeScope. | 159 // b)-e) is checked in rulesApplicableInCurrentTreeScope. |
| 160 if (!m_matchingUARules && !rulesApplicableInCurrentTreeScope(element, matchR
equest.scope, behaviorAtBoundary, matchRequest.elementApplyAuthorStyles)) | 160 if (!m_matchingUARules && !rulesApplicableInCurrentTreeScope(&element, match
Request.scope, behaviorAtBoundary, matchRequest.elementApplyAuthorStyles)) |
| 161 return; | 161 return; |
| 162 | 162 |
| 163 // We need to collect the rules for id, class, tag, and everything else into
a buffer and | 163 // We need to collect the rules for id, class, tag, and everything else into
a buffer and |
| 164 // then sort the buffer. | 164 // then sort the buffer. |
| 165 if (element->hasID()) | 165 if (element.hasID()) |
| 166 collectMatchingRulesForList(matchRequest.ruleSet->idRules(element->idFor
StyleResolution().impl()), behaviorAtBoundary, cascadeScope, cascadeOrder, match
Request, ruleRange); | 166 collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForS
tyleResolution().impl()), behaviorAtBoundary, cascadeScope, cascadeOrder, matchR
equest, ruleRange); |
| 167 if (element->isStyledElement() && element->hasClass()) { | 167 if (element.isStyledElement() && element.hasClass()) { |
| 168 for (size_t i = 0; i < element->classNames().size(); ++i) | 168 for (size_t i = 0; i < element.classNames().size(); ++i) |
| 169 collectMatchingRulesForList(matchRequest.ruleSet->classRules(element
->classNames()[i].impl()), behaviorAtBoundary, cascadeScope, cascadeOrder, match
Request, ruleRange); | 169 collectMatchingRulesForList(matchRequest.ruleSet->classRules(element
.classNames()[i].impl()), behaviorAtBoundary, cascadeScope, cascadeOrder, matchR
equest, ruleRange); |
| 170 } | 170 } |
| 171 | 171 |
| 172 if (element->isLink()) | 172 if (element.isLink()) |
| 173 collectMatchingRulesForList(matchRequest.ruleSet->linkPseudoClassRules()
, behaviorAtBoundary, cascadeScope, cascadeOrder, matchRequest, ruleRange); | 173 collectMatchingRulesForList(matchRequest.ruleSet->linkPseudoClassRules()
, behaviorAtBoundary, cascadeScope, cascadeOrder, matchRequest, ruleRange); |
| 174 if (SelectorChecker::matchesFocusPseudoClass(element)) | 174 if (SelectorChecker::matchesFocusPseudoClass(element)) |
| 175 collectMatchingRulesForList(matchRequest.ruleSet->focusPseudoClassRules(
), behaviorAtBoundary, cascadeScope, cascadeOrder, matchRequest, ruleRange); | 175 collectMatchingRulesForList(matchRequest.ruleSet->focusPseudoClassRules(
), behaviorAtBoundary, cascadeScope, cascadeOrder, matchRequest, ruleRange); |
| 176 collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element->localNam
e().impl()), behaviorAtBoundary, cascadeScope, cascadeOrder, matchRequest, ruleR
ange); | 176 collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName
().impl()), behaviorAtBoundary, cascadeScope, cascadeOrder, matchRequest, ruleRa
nge); |
| 177 collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), behavior
AtBoundary, cascadeScope, cascadeOrder, matchRequest, ruleRange); | 177 collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), behavior
AtBoundary, cascadeScope, cascadeOrder, matchRequest, ruleRange); |
| 178 } | 178 } |
| 179 | 179 |
| 180 void ElementRuleCollector::collectMatchingRulesForRegion(const MatchRequest& mat
chRequest, RuleRange& ruleRange, SelectorChecker::BehaviorAtBoundary behaviorAtB
oundary, CascadeScope cascadeScope, CascadeOrder cascadeOrder) | 180 void ElementRuleCollector::collectMatchingRulesForRegion(const MatchRequest& mat
chRequest, RuleRange& ruleRange, SelectorChecker::BehaviorAtBoundary behaviorAtB
oundary, CascadeScope cascadeScope, CascadeOrder cascadeOrder) |
| 181 { | 181 { |
| 182 if (!m_regionForStyling) | 182 if (!m_regionForStyling) |
| 183 return; | 183 return; |
| 184 | 184 |
| 185 unsigned size = matchRequest.ruleSet->m_regionSelectorsAndRuleSets.size(); | 185 unsigned size = matchRequest.ruleSet->m_regionSelectorsAndRuleSets.size(); |
| 186 for (unsigned i = 0; i < size; ++i) { | 186 for (unsigned i = 0; i < size; ++i) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 { | 259 { |
| 260 // They can't match because the fast path uses a pool of tag/class/ids, coll
ected from | 260 // They can't match because the fast path uses a pool of tag/class/ids, coll
ected from |
| 261 // elements in that tree and those will never match the host, since it's in
a different pool. | 261 // elements in that tree and those will never match the host, since it's in
a different pool. |
| 262 // So when adding scoped rules to RuleSet, RuleCanUseFastCheckSelector is no
t used. | 262 // So when adding scoped rules to RuleSet, RuleCanUseFastCheckSelector is no
t used. |
| 263 if (ruleData.hasFastCheckableSelector()) { | 263 if (ruleData.hasFastCheckableSelector()) { |
| 264 // We know this selector does not include any pseudo elements. | 264 // We know this selector does not include any pseudo elements. |
| 265 if (m_pseudoStyleRequest.pseudoId != NOPSEUDO) | 265 if (m_pseudoStyleRequest.pseudoId != NOPSEUDO) |
| 266 return false; | 266 return false; |
| 267 // We know a sufficiently simple single part selector matches simply bec
ause we found it from the rule hash. | 267 // We know a sufficiently simple single part selector matches simply bec
ause we found it from the rule hash. |
| 268 // This is limited to HTML only so we don't need to check the namespace. | 268 // This is limited to HTML only so we don't need to check the namespace. |
| 269 ASSERT(m_context.element()); |
| 269 if (ruleData.hasRightmostSelectorMatchingHTMLBasedOnRuleHash() && m_cont
ext.element()->isHTMLElement()) { | 270 if (ruleData.hasRightmostSelectorMatchingHTMLBasedOnRuleHash() && m_cont
ext.element()->isHTMLElement()) { |
| 270 if (!ruleData.hasMultipartSelector()) | 271 if (!ruleData.hasMultipartSelector()) |
| 271 return true; | 272 return true; |
| 272 } | 273 } |
| 273 if (ruleData.selector()->m_match == CSSSelector::Tag && !SelectorChecker
::tagMatches(m_context.element(), ruleData.selector()->tagQName())) | 274 if (ruleData.selector()->m_match == CSSSelector::Tag && !SelectorChecker
::tagMatches(*m_context.element(), ruleData.selector()->tagQName())) |
| 274 return false; | 275 return false; |
| 275 SelectorCheckerFastPath selectorCheckerFastPath(ruleData.selector(), m_c
ontext.element()); | 276 SelectorCheckerFastPath selectorCheckerFastPath(ruleData.selector(), *m_
context.element()); |
| 276 if (!selectorCheckerFastPath.matchesRightmostAttributeSelector()) | 277 if (!selectorCheckerFastPath.matchesRightmostAttributeSelector()) |
| 277 return false; | 278 return false; |
| 278 | 279 |
| 279 return selectorCheckerFastPath.matches(); | 280 return selectorCheckerFastPath.matches(); |
| 280 } | 281 } |
| 281 | 282 |
| 282 // Slow path. | 283 // Slow path. |
| 283 SelectorChecker selectorChecker(m_context.element()->document(), m_mode); | 284 SelectorChecker selectorChecker(m_context.element()->document(), m_mode); |
| 284 SelectorChecker::SelectorCheckingContext context(ruleData.selector(), m_cont
ext.element(), SelectorChecker::VisitedMatchEnabled); | 285 SelectorChecker::SelectorCheckingContext context(ruleData.selector(), m_cont
ext.element(), SelectorChecker::VisitedMatchEnabled); |
| 285 context.elementStyle = m_style.get(); | 286 context.elementStyle = m_style.get(); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 // information about "scope". | 376 // information about "scope". |
| 376 int firstRuleIndex = -1, lastRuleIndex = -1; | 377 int firstRuleIndex = -1, lastRuleIndex = -1; |
| 377 RuleRange ruleRange(firstRuleIndex, lastRuleIndex); | 378 RuleRange ruleRange(firstRuleIndex, lastRuleIndex); |
| 378 // FIXME: Verify whether it's ok to ignore CascadeScope here. | 379 // FIXME: Verify whether it's ok to ignore CascadeScope here. |
| 379 collectMatchingRules(MatchRequest(ruleSet), ruleRange, SelectorChecker::Stay
sWithinTreeScope); | 380 collectMatchingRules(MatchRequest(ruleSet), ruleRange, SelectorChecker::Stay
sWithinTreeScope); |
| 380 | 381 |
| 381 return m_matchedRules && !m_matchedRules->isEmpty(); | 382 return m_matchedRules && !m_matchedRules->isEmpty(); |
| 382 } | 383 } |
| 383 | 384 |
| 384 } // namespace WebCore | 385 } // namespace WebCore |
| OLD | NEW |