| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 ASSERT(m_mode == SelectorChecker::CollectingStyleRules); | 71 ASSERT(m_mode == SelectorChecker::CollectingStyleRules); |
| 72 return m_styleRuleList.release(); | 72 return m_styleRuleList.release(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 PassRefPtrWillBeRawPtr<CSSRuleList> ElementRuleCollector::matchedCSSRuleList() | 75 PassRefPtrWillBeRawPtr<CSSRuleList> ElementRuleCollector::matchedCSSRuleList() |
| 76 { | 76 { |
| 77 ASSERT(m_mode == SelectorChecker::CollectingCSSRules); | 77 ASSERT(m_mode == SelectorChecker::CollectingCSSRules); |
| 78 return m_cssRuleList.release(); | 78 return m_cssRuleList.release(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 inline void ElementRuleCollector::addMatchedRule(const RuleData* rule, unsigned
specificity, CascadeScope cascadeScope, CascadeOrder cascadeOrder, unsigned styl
eSheetIndex, const CSSStyleSheet* parentStyleSheet) | 81 inline void ElementRuleCollector::addMatchedRule(const RuleData* rule, unsigned
specificity, CascadeOrder cascadeOrder, unsigned styleSheetIndex, const CSSStyle
Sheet* parentStyleSheet) |
| 82 { | 82 { |
| 83 if (!m_matchedRules) | 83 if (!m_matchedRules) |
| 84 m_matchedRules = adoptPtrWillBeNoop(new WillBeHeapVector<MatchedRule, 32
>); | 84 m_matchedRules = adoptPtrWillBeNoop(new WillBeHeapVector<MatchedRule, 32
>); |
| 85 m_matchedRules->append(MatchedRule(rule, specificity, cascadeScope, cascadeO
rder, styleSheetIndex, parentStyleSheet)); | 85 m_matchedRules->append(MatchedRule(rule, specificity, cascadeOrder, styleShe
etIndex, parentStyleSheet)); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void ElementRuleCollector::clearMatchedRules() | 88 void ElementRuleCollector::clearMatchedRules() |
| 89 { | 89 { |
| 90 if (!m_matchedRules) | 90 if (!m_matchedRules) |
| 91 return; | 91 return; |
| 92 m_matchedRules->clear(); | 92 m_matchedRules->clear(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 inline StyleRuleList* ElementRuleCollector::ensureStyleRuleList() | 95 inline StyleRuleList* ElementRuleCollector::ensureStyleRuleList() |
| (...skipping 30 matching lines...) Expand all Loading... |
| 126 return true; | 126 return true; |
| 127 // c) the rules comes from a scoped style sheet within the same tree scope | 127 // c) the rules comes from a scoped style sheet within the same tree scope |
| 128 if (!scopingNode || element->treeScope() == scopingNode->treeScope()) | 128 if (!scopingNode || element->treeScope() == scopingNode->treeScope()) |
| 129 return true; | 129 return true; |
| 130 // d) the rules comes from a scoped style sheet within an active shadow root
whose host is the given element | 130 // d) the rules comes from a scoped style sheet within an active shadow root
whose host is the given element |
| 131 if (SelectorChecker::isHostInItsShadowTree(*element, scopingNode)) | 131 if (SelectorChecker::isHostInItsShadowTree(*element, scopingNode)) |
| 132 return true; | 132 return true; |
| 133 return false; | 133 return false; |
| 134 } | 134 } |
| 135 | 135 |
| 136 void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest
, RuleRange& ruleRange, SelectorChecker::ContextFlags contextFlags, CascadeScope
cascadeScope, CascadeOrder cascadeOrder, bool matchingTreeBoundaryRules) | 136 void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest
, RuleRange& ruleRange, SelectorChecker::ContextFlags contextFlags, CascadeOrder
cascadeOrder, bool matchingTreeBoundaryRules) |
| 137 { | 137 { |
| 138 ASSERT(matchRequest.ruleSet); | 138 ASSERT(matchRequest.ruleSet); |
| 139 ASSERT(m_context.element()); | 139 ASSERT(m_context.element()); |
| 140 | 140 |
| 141 Element& element = *m_context.element(); | 141 Element& element = *m_context.element(); |
| 142 const AtomicString& pseudoId = element.shadowPseudoId(); | 142 const AtomicString& pseudoId = element.shadowPseudoId(); |
| 143 if (!pseudoId.isEmpty()) { | 143 if (!pseudoId.isEmpty()) { |
| 144 ASSERT(element.isStyledElement()); | 144 ASSERT(element.isStyledElement()); |
| 145 collectMatchingRulesForList(matchRequest.ruleSet->shadowPseudoElementRul
es(pseudoId), contextFlags, ignoreCascadeScope, cascadeOrder, matchRequest, rule
Range); | 145 collectMatchingRulesForList(matchRequest.ruleSet->shadowPseudoElementRul
es(pseudoId), contextFlags, cascadeOrder, matchRequest, ruleRange); |
| 146 } | 146 } |
| 147 | 147 |
| 148 if (element.isVTTElement()) | 148 if (element.isVTTElement()) |
| 149 collectMatchingRulesForList(matchRequest.ruleSet->cuePseudoRules(), cont
extFlags, cascadeScope, cascadeOrder, matchRequest, ruleRange); | 149 collectMatchingRulesForList(matchRequest.ruleSet->cuePseudoRules(), cont
extFlags, cascadeOrder, matchRequest, ruleRange); |
| 150 // Check whether other types of rules are applicable in the current tree sco
pe. Criteria for this: | 150 // Check whether other types of rules are applicable in the current tree sco
pe. Criteria for this: |
| 151 // a) it's a UA rule | 151 // a) it's a UA rule |
| 152 // b) the rules comes from a scoped style sheet within the same tree scope | 152 // b) the rules comes from a scoped style sheet within the same tree scope |
| 153 // c) the rules comes from a scoped style sheet within an active shadow root
whose host is the given element | 153 // c) the rules comes from a scoped style sheet within an active shadow root
whose host is the given element |
| 154 // d) the rules can cross boundaries | 154 // d) the rules can cross boundaries |
| 155 // b)-e) is checked in rulesApplicableInCurrentTreeScope. | 155 // b)-e) is checked in rulesApplicableInCurrentTreeScope. |
| 156 if (!m_matchingUARules && !rulesApplicableInCurrentTreeScope(&element, match
Request.scope, matchingTreeBoundaryRules)) | 156 if (!m_matchingUARules && !rulesApplicableInCurrentTreeScope(&element, match
Request.scope, matchingTreeBoundaryRules)) |
| 157 return; | 157 return; |
| 158 | 158 |
| 159 // We need to collect the rules for id, class, tag, and everything else into
a buffer and | 159 // We need to collect the rules for id, class, tag, and everything else into
a buffer and |
| 160 // then sort the buffer. | 160 // then sort the buffer. |
| 161 if (element.hasID()) | 161 if (element.hasID()) |
| 162 collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForS
tyleResolution()), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleR
ange); | 162 collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForS
tyleResolution()), contextFlags, cascadeOrder, matchRequest, ruleRange); |
| 163 if (element.isStyledElement() && element.hasClass()) { | 163 if (element.isStyledElement() && element.hasClass()) { |
| 164 for (size_t i = 0; i < element.classNames().size(); ++i) | 164 for (size_t i = 0; i < element.classNames().size(); ++i) |
| 165 collectMatchingRulesForList(matchRequest.ruleSet->classRules(element
.classNames()[i]), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleR
ange); | 165 collectMatchingRulesForList(matchRequest.ruleSet->classRules(element
.classNames()[i]), contextFlags, cascadeOrder, matchRequest, ruleRange); |
| 166 } | 166 } |
| 167 | 167 |
| 168 if (element.isLink()) | 168 if (element.isLink()) |
| 169 collectMatchingRulesForList(matchRequest.ruleSet->linkPseudoClassRules()
, contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleRange); | 169 collectMatchingRulesForList(matchRequest.ruleSet->linkPseudoClassRules()
, contextFlags, cascadeOrder, matchRequest, ruleRange); |
| 170 if (SelectorChecker::matchesFocusPseudoClass(element)) | 170 if (SelectorChecker::matchesFocusPseudoClass(element)) |
| 171 collectMatchingRulesForList(matchRequest.ruleSet->focusPseudoClassRules(
), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleRange); | 171 collectMatchingRulesForList(matchRequest.ruleSet->focusPseudoClassRules(
), contextFlags, cascadeOrder, matchRequest, ruleRange); |
| 172 collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName
()), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleRange); | 172 collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName
()), contextFlags, cascadeOrder, matchRequest, ruleRange); |
| 173 collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), contextF
lags, cascadeScope, cascadeOrder, matchRequest, ruleRange); | 173 collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), contextF
lags, cascadeOrder, matchRequest, ruleRange); |
| 174 } | 174 } |
| 175 | 175 |
| 176 CSSRuleList* ElementRuleCollector::nestedRuleList(CSSRule* rule) | 176 CSSRuleList* ElementRuleCollector::nestedRuleList(CSSRule* rule) |
| 177 { | 177 { |
| 178 switch (rule->type()) { | 178 switch (rule->type()) { |
| 179 case CSSRule::MEDIA_RULE: | 179 case CSSRule::MEDIA_RULE: |
| 180 return toCSSMediaRule(rule)->cssRules(); | 180 return toCSSMediaRule(rule)->cssRules(); |
| 181 case CSSRule::KEYFRAMES_RULE: | 181 case CSSRule::KEYFRAMES_RULE: |
| 182 return toCSSKeyframesRule(rule)->cssRules(); | 182 return toCSSKeyframesRule(rule)->cssRules(); |
| 183 case CSSRule::SUPPORTS_RULE: | 183 case CSSRule::SUPPORTS_RULE: |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 context.isUARule = m_matchingUARules; | 266 context.isUARule = m_matchingUARules; |
| 267 context.contextFlags = contextFlags; | 267 context.contextFlags = contextFlags; |
| 268 SelectorChecker::Match match = selectorChecker.match(context, DOMSiblingTrav
ersalStrategy(), result); | 268 SelectorChecker::Match match = selectorChecker.match(context, DOMSiblingTrav
ersalStrategy(), result); |
| 269 if (match != SelectorChecker::SelectorMatches) | 269 if (match != SelectorChecker::SelectorMatches) |
| 270 return false; | 270 return false; |
| 271 if (m_pseudoStyleRequest.pseudoId != NOPSEUDO && m_pseudoStyleRequest.pseudo
Id != result->dynamicPseudo) | 271 if (m_pseudoStyleRequest.pseudoId != NOPSEUDO && m_pseudoStyleRequest.pseudo
Id != result->dynamicPseudo) |
| 272 return false; | 272 return false; |
| 273 return true; | 273 return true; |
| 274 } | 274 } |
| 275 | 275 |
| 276 void ElementRuleCollector::collectRuleIfMatches(const RuleData& ruleData, Select
orChecker::ContextFlags contextFlags, CascadeScope cascadeScope, CascadeOrder ca
scadeOrder, const MatchRequest& matchRequest, RuleRange& ruleRange) | 276 void ElementRuleCollector::collectRuleIfMatches(const RuleData& ruleData, Select
orChecker::ContextFlags contextFlags, CascadeOrder cascadeOrder, const MatchRequ
est& matchRequest, RuleRange& ruleRange) |
| 277 { | 277 { |
| 278 if (m_canUseFastReject && m_selectorFilter.fastRejectSelector<RuleData::maxi
mumIdentifierCount>(ruleData.descendantSelectorIdentifierHashes())) | 278 if (m_canUseFastReject && m_selectorFilter.fastRejectSelector<RuleData::maxi
mumIdentifierCount>(ruleData.descendantSelectorIdentifierHashes())) |
| 279 return; | 279 return; |
| 280 | 280 |
| 281 StyleRule* rule = ruleData.rule(); | 281 StyleRule* rule = ruleData.rule(); |
| 282 SelectorChecker::MatchResult result; | 282 SelectorChecker::MatchResult result; |
| 283 if (ruleMatches(ruleData, matchRequest.scope, contextFlags, &result)) { | 283 if (ruleMatches(ruleData, matchRequest.scope, contextFlags, &result)) { |
| 284 // If the rule has no properties to apply, then ignore it in the non-deb
ug mode. | 284 // If the rule has no properties to apply, then ignore it in the non-deb
ug mode. |
| 285 const StylePropertySet& properties = rule->properties(); | 285 const StylePropertySet& properties = rule->properties(); |
| 286 if (properties.isEmpty() && !matchRequest.includeEmptyRules) | 286 if (properties.isEmpty() && !matchRequest.includeEmptyRules) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 298 // FIXME: Matching should not modify the style directly. | 298 // FIXME: Matching should not modify the style directly. |
| 299 if (m_style && dynamicPseudo < FIRST_INTERNAL_PSEUDOID) | 299 if (m_style && dynamicPseudo < FIRST_INTERNAL_PSEUDOID) |
| 300 m_style->setHasPseudoStyle(dynamicPseudo); | 300 m_style->setHasPseudoStyle(dynamicPseudo); |
| 301 } else { | 301 } else { |
| 302 // Update our first/last rule indices in the matched rules array. | 302 // Update our first/last rule indices in the matched rules array. |
| 303 ++ruleRange.lastRuleIndex; | 303 ++ruleRange.lastRuleIndex; |
| 304 if (ruleRange.firstRuleIndex == -1) | 304 if (ruleRange.firstRuleIndex == -1) |
| 305 ruleRange.firstRuleIndex = ruleRange.lastRuleIndex; | 305 ruleRange.firstRuleIndex = ruleRange.lastRuleIndex; |
| 306 | 306 |
| 307 // Add this rule to our list of matched rules. | 307 // Add this rule to our list of matched rules. |
| 308 addMatchedRule(&ruleData, result.specificity, cascadeScope, cascadeO
rder, matchRequest.styleSheetIndex, matchRequest.styleSheet); | 308 addMatchedRule(&ruleData, result.specificity, cascadeOrder, matchReq
uest.styleSheetIndex, matchRequest.styleSheet); |
| 309 return; | 309 return; |
| 310 } | 310 } |
| 311 } | 311 } |
| 312 } | 312 } |
| 313 | 313 |
| 314 static inline bool compareRules(const MatchedRule& matchedRule1, const MatchedRu
le& matchedRule2) | 314 static inline bool compareRules(const MatchedRule& matchedRule1, const MatchedRu
le& matchedRule2) |
| 315 { | 315 { |
| 316 if (matchedRule1.cascadeScope() != matchedRule2.cascadeScope()) | |
| 317 return matchedRule1.cascadeScope() > matchedRule2.cascadeScope(); | |
| 318 | |
| 319 unsigned specificity1 = matchedRule1.specificity(); | 316 unsigned specificity1 = matchedRule1.specificity(); |
| 320 unsigned specificity2 = matchedRule2.specificity(); | 317 unsigned specificity2 = matchedRule2.specificity(); |
| 321 if (specificity1 != specificity2) | 318 if (specificity1 != specificity2) |
| 322 return specificity1 < specificity2; | 319 return specificity1 < specificity2; |
| 323 | 320 |
| 324 return matchedRule1.position() < matchedRule2.position(); | 321 return matchedRule1.position() < matchedRule2.position(); |
| 325 } | 322 } |
| 326 | 323 |
| 327 void ElementRuleCollector::sortMatchedRules() | 324 void ElementRuleCollector::sortMatchedRules() |
| 328 { | 325 { |
| 329 ASSERT(m_matchedRules); | 326 ASSERT(m_matchedRules); |
| 330 std::sort(m_matchedRules->begin(), m_matchedRules->end(), compareRules); | 327 std::sort(m_matchedRules->begin(), m_matchedRules->end(), compareRules); |
| 331 } | 328 } |
| 332 | 329 |
| 333 bool ElementRuleCollector::hasAnyMatchingRules(RuleSet* ruleSet) | 330 bool ElementRuleCollector::hasAnyMatchingRules(RuleSet* ruleSet) |
| 334 { | 331 { |
| 335 clearMatchedRules(); | 332 clearMatchedRules(); |
| 336 | 333 |
| 337 m_mode = SelectorChecker::SharingRules; | 334 m_mode = SelectorChecker::SharingRules; |
| 338 // To check whether a given RuleSet has any rule matching a given element, | 335 // To check whether a given RuleSet has any rule matching a given element, |
| 339 // should not see the element's treescope. Because RuleSet has no | 336 // should not see the element's treescope. Because RuleSet has no |
| 340 // information about "scope". | 337 // information about "scope". |
| 341 int firstRuleIndex = -1, lastRuleIndex = -1; | 338 int firstRuleIndex = -1, lastRuleIndex = -1; |
| 342 RuleRange ruleRange(firstRuleIndex, lastRuleIndex); | 339 RuleRange ruleRange(firstRuleIndex, lastRuleIndex); |
| 343 // FIXME: Verify whether it's ok to ignore CascadeScope here. | |
| 344 collectMatchingRules(MatchRequest(ruleSet), ruleRange, SelectorChecker::Defa
ultBehavior); | 340 collectMatchingRules(MatchRequest(ruleSet), ruleRange, SelectorChecker::Defa
ultBehavior); |
| 345 | 341 |
| 346 return m_matchedRules && !m_matchedRules->isEmpty(); | 342 return m_matchedRules && !m_matchedRules->isEmpty(); |
| 347 } | 343 } |
| 348 | 344 |
| 349 } // namespace blink | 345 } // namespace blink |
| OLD | NEW |