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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 if (!propertySet) | 111 if (!propertySet) |
112 return; | 112 return; |
113 m_result.ranges.lastAuthorRule = m_result.matchedProperties.size(); | 113 m_result.ranges.lastAuthorRule = m_result.matchedProperties.size(); |
114 if (m_result.ranges.firstAuthorRule == -1) | 114 if (m_result.ranges.firstAuthorRule == -1) |
115 m_result.ranges.firstAuthorRule = m_result.ranges.lastAuthorRule; | 115 m_result.ranges.firstAuthorRule = m_result.ranges.lastAuthorRule; |
116 m_result.addMatchedProperties(propertySet); | 116 m_result.addMatchedProperties(propertySet); |
117 if (!isCacheable) | 117 if (!isCacheable) |
118 m_result.isCacheable = false; | 118 m_result.isCacheable = false; |
119 } | 119 } |
120 | 120 |
121 static bool rulesApplicableInCurrentTreeScope(const Element* element, const Cont
ainerNode* scopingNode, SelectorChecker::BehaviorAtBoundary behaviorAtBoundary,
bool elementApplyAuthorStyles) | 121 static bool rulesApplicableInCurrentTreeScope(const Element* element, const Cont
ainerNode* scopingNode, bool elementApplyAuthorStyles) |
122 { | 122 { |
123 TreeScope& treeScope = element->treeScope(); | 123 TreeScope& treeScope = element->treeScope(); |
124 | 124 |
125 // [skipped, because already checked] a) it's a UA rule | 125 // [skipped, because already checked] a) it's a UA rule |
126 // b) element is allowed to apply author rules | 126 // b) element is allowed to apply author rules |
127 if (elementApplyAuthorStyles) | 127 if (elementApplyAuthorStyles) |
128 return true; | 128 return true; |
129 // c) the rules comes from a scoped style sheet within the same tree scope | 129 // c) the rules comes from a scoped style sheet within the same tree scope |
130 if (!scopingNode || treeScope == scopingNode->treeScope()) | 130 if (!scopingNode || treeScope == scopingNode->treeScope()) |
131 return true; | 131 return true; |
132 // d) the rules comes from a scoped style sheet within an active shadow root
whose host is the given element | 132 // d) the rules comes from a scoped style sheet within an active shadow root
whose host is the given element |
133 if (SelectorChecker::isHostInItsShadowTree(*element, behaviorAtBoundary, sco
pingNode)) | 133 if (SelectorChecker::isHostInItsShadowTree(*element, scopingNode)) |
134 return true; | 134 return true; |
135 return false; | 135 return false; |
136 } | 136 } |
137 | 137 |
138 void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest
, RuleRange& ruleRange, SelectorChecker::BehaviorAtBoundary behaviorAtBoundary,
CascadeScope cascadeScope, CascadeOrder cascadeOrder) | 138 void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest
, RuleRange& ruleRange, SelectorChecker::ContextFlags contextFlags, CascadeScope
cascadeScope, CascadeOrder cascadeOrder) |
139 { | 139 { |
140 ASSERT(matchRequest.ruleSet); | 140 ASSERT(matchRequest.ruleSet); |
141 ASSERT(m_context.element()); | 141 ASSERT(m_context.element()); |
142 | 142 |
143 Element& element = *m_context.element(); | 143 Element& element = *m_context.element(); |
144 const AtomicString& pseudoId = element.shadowPseudoId(); | 144 const AtomicString& pseudoId = element.shadowPseudoId(); |
145 if (!pseudoId.isEmpty()) { | 145 if (!pseudoId.isEmpty()) { |
146 ASSERT(element.isStyledElement()); | 146 ASSERT(element.isStyledElement()); |
147 collectMatchingRulesForList(matchRequest.ruleSet->shadowPseudoElementRul
es(pseudoId), behaviorAtBoundary, ignoreCascadeScope, cascadeOrder, matchRequest
, ruleRange); | 147 collectMatchingRulesForList(matchRequest.ruleSet->shadowPseudoElementRul
es(pseudoId), contextFlags, ignoreCascadeScope, cascadeOrder, matchRequest, rule
Range); |
148 } | 148 } |
149 | 149 |
150 if (element.isVTTElement()) | 150 if (element.isVTTElement()) |
151 collectMatchingRulesForList(matchRequest.ruleSet->cuePseudoRules(), beha
viorAtBoundary, cascadeScope, cascadeOrder, matchRequest, ruleRange); | 151 collectMatchingRulesForList(matchRequest.ruleSet->cuePseudoRules(), cont
extFlags, cascadeScope, cascadeOrder, matchRequest, ruleRange); |
152 // Check whether other types of rules are applicable in the current tree sco
pe. Criteria for this: | 152 // Check whether other types of rules are applicable in the current tree sco
pe. Criteria for this: |
153 // a) it's a UA rule | 153 // a) it's a UA rule |
154 // b) the tree scope allows author rules | 154 // b) the tree scope allows author rules |
155 // c) the rules comes from a scoped style sheet within the same tree scope | 155 // c) the rules comes from a scoped style sheet within the same tree scope |
156 // d) the rules comes from a scoped style sheet within an active shadow root
whose host is the given element | 156 // d) the rules comes from a scoped style sheet within an active shadow root
whose host is the given element |
157 // e) the rules can cross boundaries | 157 // e) the rules can cross boundaries |
158 // b)-e) is checked in rulesApplicableInCurrentTreeScope. | 158 // b)-e) is checked in rulesApplicableInCurrentTreeScope. |
159 if (!m_matchingUARules && !rulesApplicableInCurrentTreeScope(&element, match
Request.scope, behaviorAtBoundary, matchRequest.elementApplyAuthorStyles)) | 159 if (!m_matchingUARules && !rulesApplicableInCurrentTreeScope(&element, match
Request.scope, matchRequest.elementApplyAuthorStyles)) |
160 return; | 160 return; |
161 | 161 |
162 // We need to collect the rules for id, class, tag, and everything else into
a buffer and | 162 // We need to collect the rules for id, class, tag, and everything else into
a buffer and |
163 // then sort the buffer. | 163 // then sort the buffer. |
164 if (element.hasID()) | 164 if (element.hasID()) |
165 collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForS
tyleResolution()), behaviorAtBoundary, cascadeScope, cascadeOrder, matchRequest,
ruleRange); | 165 collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForS
tyleResolution()), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleR
ange); |
166 if (element.isStyledElement() && element.hasClass()) { | 166 if (element.isStyledElement() && element.hasClass()) { |
167 for (size_t i = 0; i < element.classNames().size(); ++i) | 167 for (size_t i = 0; i < element.classNames().size(); ++i) |
168 collectMatchingRulesForList(matchRequest.ruleSet->classRules(element
.classNames()[i]), behaviorAtBoundary, cascadeScope, cascadeOrder, matchRequest,
ruleRange); | 168 collectMatchingRulesForList(matchRequest.ruleSet->classRules(element
.classNames()[i]), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleR
ange); |
169 } | 169 } |
170 | 170 |
171 if (element.isLink()) | 171 if (element.isLink()) |
172 collectMatchingRulesForList(matchRequest.ruleSet->linkPseudoClassRules()
, behaviorAtBoundary, cascadeScope, cascadeOrder, matchRequest, ruleRange); | 172 collectMatchingRulesForList(matchRequest.ruleSet->linkPseudoClassRules()
, contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleRange); |
173 if (SelectorChecker::matchesFocusPseudoClass(element)) | 173 if (SelectorChecker::matchesFocusPseudoClass(element)) |
174 collectMatchingRulesForList(matchRequest.ruleSet->focusPseudoClassRules(
), behaviorAtBoundary, cascadeScope, cascadeOrder, matchRequest, ruleRange); | 174 collectMatchingRulesForList(matchRequest.ruleSet->focusPseudoClassRules(
), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleRange); |
175 collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName
()), behaviorAtBoundary, cascadeScope, cascadeOrder, matchRequest, ruleRange); | 175 collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName
()), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleRange); |
176 collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), behavior
AtBoundary, cascadeScope, cascadeOrder, matchRequest, ruleRange); | 176 collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), contextF
lags, cascadeScope, cascadeOrder, matchRequest, ruleRange); |
177 } | 177 } |
178 | 178 |
179 CSSRuleList* ElementRuleCollector::nestedRuleList(CSSRule* rule) | 179 CSSRuleList* ElementRuleCollector::nestedRuleList(CSSRule* rule) |
180 { | 180 { |
181 switch (rule->type()) { | 181 switch (rule->type()) { |
182 case CSSRule::MEDIA_RULE: | 182 case CSSRule::MEDIA_RULE: |
183 return toCSSMediaRule(rule)->cssRules(); | 183 return toCSSMediaRule(rule)->cssRules(); |
184 case CSSRule::KEYFRAMES_RULE: | 184 case CSSRule::KEYFRAMES_RULE: |
185 return toCSSKeyframesRule(rule)->cssRules(); | 185 return toCSSKeyframesRule(rule)->cssRules(); |
186 case CSSRule::SUPPORTS_RULE: | 186 case CSSRule::SUPPORTS_RULE: |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 // Now transfer the set of matched rules over to our list of declarations. | 250 // Now transfer the set of matched rules over to our list of declarations. |
251 for (unsigned i = 0; i < matchedRules.size(); i++) { | 251 for (unsigned i = 0; i < matchedRules.size(); i++) { |
252 // FIXME: Matching should not modify the style directly. | 252 // FIXME: Matching should not modify the style directly. |
253 const RuleData* ruleData = matchedRules[i].ruleData(); | 253 const RuleData* ruleData = matchedRules[i].ruleData(); |
254 if (m_style && ruleData->containsUncommonAttributeSelector()) | 254 if (m_style && ruleData->containsUncommonAttributeSelector()) |
255 m_style->setUnique(); | 255 m_style->setUnique(); |
256 m_result.addMatchedProperties(&ruleData->rule()->properties(), ruleData-
>rule(), ruleData->linkMatchType(), ruleData->propertyWhitelistType(m_matchingUA
Rules)); | 256 m_result.addMatchedProperties(&ruleData->rule()->properties(), ruleData-
>rule(), ruleData->linkMatchType(), ruleData->propertyWhitelistType(m_matchingUA
Rules)); |
257 } | 257 } |
258 } | 258 } |
259 | 259 |
260 inline bool ElementRuleCollector::ruleMatches(const RuleData& ruleData, const Co
ntainerNode* scope, SelectorChecker::BehaviorAtBoundary behaviorAtBoundary, Sele
ctorChecker::MatchResult* result) | 260 inline bool ElementRuleCollector::ruleMatches(const RuleData& ruleData, const Co
ntainerNode* scope, SelectorChecker::ContextFlags contextFlags, SelectorChecker:
:MatchResult* result) |
261 { | 261 { |
262 SelectorChecker selectorChecker(m_context.element()->document(), m_mode); | 262 SelectorChecker selectorChecker(m_context.element()->document(), m_mode); |
263 SelectorChecker::SelectorCheckingContext context(ruleData.selector(), m_cont
ext.element(), SelectorChecker::VisitedMatchEnabled); | 263 SelectorChecker::SelectorCheckingContext context(ruleData.selector(), m_cont
ext.element(), SelectorChecker::VisitedMatchEnabled); |
264 context.elementStyle = m_style.get(); | 264 context.elementStyle = m_style.get(); |
265 context.scope = scope; | 265 context.scope = scope; |
266 context.pseudoId = m_pseudoStyleRequest.pseudoId; | 266 context.pseudoId = m_pseudoStyleRequest.pseudoId; |
267 context.scrollbar = m_pseudoStyleRequest.scrollbar; | 267 context.scrollbar = m_pseudoStyleRequest.scrollbar; |
268 context.scrollbarPart = m_pseudoStyleRequest.scrollbarPart; | 268 context.scrollbarPart = m_pseudoStyleRequest.scrollbarPart; |
269 context.behaviorAtBoundary = behaviorAtBoundary; | 269 context.contextFlags = contextFlags; |
270 SelectorChecker::Match match = selectorChecker.match(context, DOMSiblingTrav
ersalStrategy(), result); | 270 SelectorChecker::Match match = selectorChecker.match(context, DOMSiblingTrav
ersalStrategy(), result); |
271 if (match != SelectorChecker::SelectorMatches) | 271 if (match != SelectorChecker::SelectorMatches) |
272 return false; | 272 return false; |
273 if (m_pseudoStyleRequest.pseudoId != NOPSEUDO && m_pseudoStyleRequest.pseudo
Id != result->dynamicPseudo) | 273 if (m_pseudoStyleRequest.pseudoId != NOPSEUDO && m_pseudoStyleRequest.pseudo
Id != result->dynamicPseudo) |
274 return false; | 274 return false; |
275 return true; | 275 return true; |
276 } | 276 } |
277 | 277 |
278 void ElementRuleCollector::collectRuleIfMatches(const RuleData& ruleData, Select
orChecker::BehaviorAtBoundary behaviorAtBoundary, CascadeScope cascadeScope, Cas
cadeOrder cascadeOrder, const MatchRequest& matchRequest, RuleRange& ruleRange) | 278 void ElementRuleCollector::collectRuleIfMatches(const RuleData& ruleData, Select
orChecker::ContextFlags contextFlags, CascadeScope cascadeScope, CascadeOrder ca
scadeOrder, const MatchRequest& matchRequest, RuleRange& ruleRange) |
279 { | 279 { |
280 if (m_canUseFastReject && m_selectorFilter.fastRejectSelector<RuleData::maxi
mumIdentifierCount>(ruleData.descendantSelectorIdentifierHashes())) | 280 if (m_canUseFastReject && m_selectorFilter.fastRejectSelector<RuleData::maxi
mumIdentifierCount>(ruleData.descendantSelectorIdentifierHashes())) |
281 return; | 281 return; |
282 | 282 |
283 StyleRule* rule = ruleData.rule(); | 283 StyleRule* rule = ruleData.rule(); |
284 SelectorChecker::MatchResult result; | 284 SelectorChecker::MatchResult result; |
285 if (ruleMatches(ruleData, matchRequest.scope, behaviorAtBoundary, &result))
{ | 285 if (ruleMatches(ruleData, matchRequest.scope, contextFlags, &result)) { |
286 // If the rule has no properties to apply, then ignore it in the non-deb
ug mode. | 286 // If the rule has no properties to apply, then ignore it in the non-deb
ug mode. |
287 const StylePropertySet& properties = rule->properties(); | 287 const StylePropertySet& properties = rule->properties(); |
288 if (properties.isEmpty() && !matchRequest.includeEmptyRules) | 288 if (properties.isEmpty() && !matchRequest.includeEmptyRules) |
289 return; | 289 return; |
290 // FIXME: Exposing the non-standard getMatchedCSSRules API to web is the
only reason this is needed. | 290 // FIXME: Exposing the non-standard getMatchedCSSRules API to web is the
only reason this is needed. |
291 if (m_sameOriginOnly && !ruleData.hasDocumentSecurityOrigin()) | 291 if (m_sameOriginOnly && !ruleData.hasDocumentSecurityOrigin()) |
292 return; | 292 return; |
293 | 293 |
294 PseudoId dynamicPseudo = result.dynamicPseudo; | 294 PseudoId dynamicPseudo = result.dynamicPseudo; |
295 // If we're matching normal rules, set a pseudo bit if | 295 // If we're matching normal rules, set a pseudo bit if |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 { | 336 { |
337 clearMatchedRules(); | 337 clearMatchedRules(); |
338 | 338 |
339 m_mode = SelectorChecker::SharingRules; | 339 m_mode = SelectorChecker::SharingRules; |
340 // To check whether a given RuleSet has any rule matching a given element, | 340 // To check whether a given RuleSet has any rule matching a given element, |
341 // should not see the element's treescope. Because RuleSet has no | 341 // should not see the element's treescope. Because RuleSet has no |
342 // information about "scope". | 342 // information about "scope". |
343 int firstRuleIndex = -1, lastRuleIndex = -1; | 343 int firstRuleIndex = -1, lastRuleIndex = -1; |
344 RuleRange ruleRange(firstRuleIndex, lastRuleIndex); | 344 RuleRange ruleRange(firstRuleIndex, lastRuleIndex); |
345 // FIXME: Verify whether it's ok to ignore CascadeScope here. | 345 // FIXME: Verify whether it's ok to ignore CascadeScope here. |
346 collectMatchingRules(MatchRequest(ruleSet), ruleRange, SelectorChecker::Stay
sWithinTreeScope); | 346 collectMatchingRules(MatchRequest(ruleSet), ruleRange, SelectorChecker::Defa
ultBehavior); |
347 | 347 |
348 return m_matchedRules && !m_matchedRules->isEmpty(); | 348 return m_matchedRules && !m_matchedRules->isEmpty(); |
349 } | 349 } |
350 | 350 |
351 } // namespace WebCore | 351 } // namespace WebCore |
OLD | NEW |