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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 context.scrollbarPart = m_pseudoStyleRequest.scrollbarPart; | 199 context.scrollbarPart = m_pseudoStyleRequest.scrollbarPart; |
200 context.behaviorAtBoundary = m_behaviorAtBoundary; | 200 context.behaviorAtBoundary = m_behaviorAtBoundary; |
201 SelectorChecker::Match match = selectorChecker.match(context, dynamicPseudo, DOMSiblingTraversalStrategy()); | 201 SelectorChecker::Match match = selectorChecker.match(context, dynamicPseudo, DOMSiblingTraversalStrategy()); |
202 if (match != SelectorChecker::SelectorMatches) | 202 if (match != SelectorChecker::SelectorMatches) |
203 return false; | 203 return false; |
204 if (m_pseudoStyleRequest.pseudoId != NOPSEUDO && m_pseudoStyleRequest.pseudo Id != dynamicPseudo) | 204 if (m_pseudoStyleRequest.pseudoId != NOPSEUDO && m_pseudoStyleRequest.pseudo Id != dynamicPseudo) |
205 return false; | 205 return false; |
206 return true; | 206 return true; |
207 } | 207 } |
208 | 208 |
209 void ElementRuleCollector::collectRuleIfMatches(const RuleData& ruleData, const MatchRequest& matchRequest, StyleResolver::RuleRange& ruleRange) | |
210 { | |
211 if (m_canUseFastReject && m_selectorFilter.fastRejectSelector<RuleData::maxi mumIdentifierCount>(ruleData.descendantSelectorIdentifierHashes())) | |
212 return; | |
213 | |
214 StyleRule* rule = ruleData.rule(); | |
215 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willMatchR ule(document(), rule, m_inspectorCSSOMWrappers, document()->styleSheetCollection ()); | |
216 PseudoId dynamicPseudo = NOPSEUDO; | |
217 if (ruleMatches(ruleData, matchRequest.scope, dynamicPseudo)) { | |
218 // If the rule has no properties to apply, then ignore it in the non-deb ug mode. | |
219 const StylePropertySet* properties = rule->properties(); | |
220 if (!properties || (properties->isEmpty() && !matchRequest.includeEmptyR ules)) { | |
221 InspectorInstrumentation::didMatchRule(cookie, false); | |
222 return; | |
223 } | |
224 // FIXME: Exposing the non-standard getMatchedCSSRules API to web is the only reason this is needed. | |
225 if (m_sameOriginOnly && !ruleData.hasDocumentSecurityOrigin()) { | |
226 InspectorInstrumentation::didMatchRule(cookie, false); | |
227 return; | |
228 } | |
229 // If we're matching normal rules, set a pseudo bit if | |
230 // we really just matched a pseudo-element. | |
231 if (dynamicPseudo != NOPSEUDO && m_pseudoStyleRequest.pseudoId == NOPSEU DO) { | |
232 if (m_mode == SelectorChecker::CollectingRules) { | |
233 InspectorInstrumentation::didMatchRule(cookie, false); | |
234 return; | |
235 } | |
236 if (dynamicPseudo < FIRST_INTERNAL_PSEUDOID) | |
237 m_state.style()->setHasPseudoStyle(dynamicPseudo); | |
238 } else { | |
239 // Update our first/last rule indices in the matched rules array. | |
240 ++ruleRange.lastRuleIndex; | |
241 if (ruleRange.firstRuleIndex == -1) | |
242 ruleRange.firstRuleIndex = ruleRange.lastRuleIndex; | |
243 | |
244 // Add this rule to our list of matched rules. | |
245 addMatchedRule(&ruleData); | |
246 InspectorInstrumentation::didMatchRule(cookie, true); | |
247 return; | |
248 } | |
249 } | |
250 InspectorInstrumentation::didMatchRule(cookie, false); | |
251 } | |
252 | |
253 void ElementRuleCollector::collectMatchingRulesForList(const RuleData* rules, co nst MatchRequest& matchRequest, StyleResolver::RuleRange& ruleRange) | |
254 { | |
255 if (!rules) | |
256 return; | |
257 while (!rules->isLastInArray()) | |
258 collectRuleIfMatches(*rules++, matchRequest, ruleRange); | |
esprehn
2013/06/26 00:37:33
you could maybe do/while {} but I don't know if th
abarth-chromium
2013/06/26 00:57:00
Yeah, I tried a few permutations of this loop, and
| |
259 collectRuleIfMatches(*rules++, matchRequest, ruleRange); | |
esprehn
2013/06/26 00:37:33
No reason to increment here.
abarth-chromium
2013/06/26 00:57:00
Done.
| |
260 } | |
261 | |
209 void ElementRuleCollector::collectMatchingRulesForList(const Vector<RuleData>* r ules, const MatchRequest& matchRequest, StyleResolver::RuleRange& ruleRange) | 262 void ElementRuleCollector::collectMatchingRulesForList(const Vector<RuleData>* r ules, const MatchRequest& matchRequest, StyleResolver::RuleRange& ruleRange) |
210 { | 263 { |
211 if (!rules) | 264 if (!rules) |
212 return; | 265 return; |
213 | |
214 const StyleResolverState& state = m_state; | |
215 | |
216 unsigned size = rules->size(); | 266 unsigned size = rules->size(); |
217 for (unsigned i = 0; i < size; ++i) { | 267 for (unsigned i = 0; i < size; ++i) |
218 const RuleData& ruleData = rules->at(i); | 268 collectRuleIfMatches(rules->at(i), matchRequest, ruleRange); |
219 if (m_canUseFastReject && m_selectorFilter.fastRejectSelector<RuleData:: maximumIdentifierCount>(ruleData.descendantSelectorIdentifierHashes())) | |
220 continue; | |
221 | |
222 StyleRule* rule = ruleData.rule(); | |
223 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willMa tchRule(document(), rule, m_inspectorCSSOMWrappers, document()->styleSheetCollec tion()); | |
224 PseudoId dynamicPseudo = NOPSEUDO; | |
225 if (ruleMatches(ruleData, matchRequest.scope, dynamicPseudo)) { | |
226 // If the rule has no properties to apply, then ignore it in the non -debug mode. | |
227 const StylePropertySet* properties = rule->properties(); | |
228 if (!properties || (properties->isEmpty() && !matchRequest.includeEm ptyRules)) { | |
229 InspectorInstrumentation::didMatchRule(cookie, false); | |
230 continue; | |
231 } | |
232 // FIXME: Exposing the non-standard getMatchedCSSRules API to web is the only reason this is needed. | |
233 if (m_sameOriginOnly && !ruleData.hasDocumentSecurityOrigin()) { | |
234 InspectorInstrumentation::didMatchRule(cookie, false); | |
235 continue; | |
236 } | |
237 // If we're matching normal rules, set a pseudo bit if | |
238 // we really just matched a pseudo-element. | |
239 if (dynamicPseudo != NOPSEUDO && m_pseudoStyleRequest.pseudoId == NO PSEUDO) { | |
240 if (m_mode == SelectorChecker::CollectingRules) { | |
241 InspectorInstrumentation::didMatchRule(cookie, false); | |
242 continue; | |
243 } | |
244 if (dynamicPseudo < FIRST_INTERNAL_PSEUDOID) | |
245 state.style()->setHasPseudoStyle(dynamicPseudo); | |
246 } else { | |
247 // Update our first/last rule indices in the matched rules array . | |
248 ++ruleRange.lastRuleIndex; | |
249 if (ruleRange.firstRuleIndex == -1) | |
250 ruleRange.firstRuleIndex = ruleRange.lastRuleIndex; | |
251 | |
252 // Add this rule to our list of matched rules. | |
253 addMatchedRule(&ruleData); | |
254 InspectorInstrumentation::didMatchRule(cookie, true); | |
255 continue; | |
256 } | |
257 } | |
258 InspectorInstrumentation::didMatchRule(cookie, false); | |
259 } | |
260 } | 269 } |
261 | 270 |
262 static inline bool compareRules(const RuleData* r1, const RuleData* r2) | 271 static inline bool compareRules(const RuleData* r1, const RuleData* r2) |
263 { | 272 { |
264 unsigned specificity1 = r1->specificity(); | 273 unsigned specificity1 = r1->specificity(); |
265 unsigned specificity2 = r2->specificity(); | 274 unsigned specificity2 = r2->specificity(); |
266 return (specificity1 == specificity2) ? r1->position() < r2->position() : sp ecificity1 < specificity2; | 275 return (specificity1 == specificity2) ? r1->position() < r2->position() : sp ecificity1 < specificity2; |
267 } | 276 } |
268 | 277 |
269 void ElementRuleCollector::sortMatchedRules() | 278 void ElementRuleCollector::sortMatchedRules() |
(...skipping 12 matching lines...) Expand all Loading... | |
282 // information about "scope". | 291 // information about "scope". |
283 m_behaviorAtBoundary = SelectorChecker::StaysWithinTreeScope; | 292 m_behaviorAtBoundary = SelectorChecker::StaysWithinTreeScope; |
284 int firstRuleIndex = -1, lastRuleIndex = -1; | 293 int firstRuleIndex = -1, lastRuleIndex = -1; |
285 StyleResolver::RuleRange ruleRange(firstRuleIndex, lastRuleIndex); | 294 StyleResolver::RuleRange ruleRange(firstRuleIndex, lastRuleIndex); |
286 collectMatchingRules(MatchRequest(ruleSet), ruleRange); | 295 collectMatchingRules(MatchRequest(ruleSet), ruleRange); |
287 | 296 |
288 return m_matchedRules && !m_matchedRules->isEmpty(); | 297 return m_matchedRules && !m_matchedRules->isEmpty(); |
289 } | 298 } |
290 | 299 |
291 } // namespace WebCore | 300 } // namespace WebCore |
OLD | NEW |