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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } | 74 } |
75 | 75 |
76 PassRefPtrWillBeRawPtr<CSSRuleList> ElementRuleCollector::matchedCSSRuleList() | 76 PassRefPtrWillBeRawPtr<CSSRuleList> ElementRuleCollector::matchedCSSRuleList() |
77 { | 77 { |
78 ASSERT(m_mode == SelectorChecker::CollectingCSSRules); | 78 ASSERT(m_mode == SelectorChecker::CollectingCSSRules); |
79 return m_cssRuleList.release(); | 79 return m_cssRuleList.release(); |
80 } | 80 } |
81 | 81 |
82 inline void ElementRuleCollector::addMatchedRule(const RuleData* rule, unsigned
specificity, CascadeScope cascadeScope, CascadeOrder cascadeOrder, unsigned styl
eSheetIndex, const CSSStyleSheet* parentStyleSheet) | 82 inline void ElementRuleCollector::addMatchedRule(const RuleData* rule, unsigned
specificity, CascadeScope cascadeScope, CascadeOrder cascadeOrder, unsigned styl
eSheetIndex, const CSSStyleSheet* parentStyleSheet) |
83 { | 83 { |
84 if (!m_matchedRules) | 84 m_matchedRules.append(MatchedRule(rule, specificity, cascadeScope, cascadeOr
der, styleSheetIndex, parentStyleSheet)); |
85 m_matchedRules = adoptPtrWillBeNoop(new WillBeHeapVector<MatchedRule, 32
>); | |
86 m_matchedRules->append(MatchedRule(rule, specificity, cascadeScope, cascadeO
rder, styleSheetIndex, parentStyleSheet)); | |
87 } | 85 } |
88 | 86 |
89 void ElementRuleCollector::clearMatchedRules() | 87 void ElementRuleCollector::clearMatchedRules() |
90 { | 88 { |
91 if (!m_matchedRules) | 89 m_matchedRules.clear(); |
92 return; | |
93 m_matchedRules->clear(); | |
94 } | 90 } |
95 | 91 |
96 inline StyleRuleList* ElementRuleCollector::ensureStyleRuleList() | 92 inline StyleRuleList* ElementRuleCollector::ensureStyleRuleList() |
97 { | 93 { |
98 if (!m_styleRuleList) | 94 if (!m_styleRuleList) |
99 m_styleRuleList = StyleRuleList::create(); | 95 m_styleRuleList = StyleRuleList::create(); |
100 return m_styleRuleList.get(); | 96 return m_styleRuleList.get(); |
101 } | 97 } |
102 | 98 |
103 inline StaticCSSRuleList* ElementRuleCollector::ensureRuleList() | 99 inline StaticCSSRuleList* ElementRuleCollector::ensureRuleList() |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 if (parentStyleSheet) | 216 if (parentStyleSheet) |
221 cssRule = findStyleRule(parentStyleSheet, rule); | 217 cssRule = findStyleRule(parentStyleSheet, rule); |
222 else | 218 else |
223 cssRule = rule->createCSSOMWrapper(); | 219 cssRule = rule->createCSSOMWrapper(); |
224 ASSERT(!parentStyleSheet || cssRule); | 220 ASSERT(!parentStyleSheet || cssRule); |
225 ensureRuleList()->rules().append(cssRule); | 221 ensureRuleList()->rules().append(cssRule); |
226 } | 222 } |
227 | 223 |
228 void ElementRuleCollector::sortAndTransferMatchedRules() | 224 void ElementRuleCollector::sortAndTransferMatchedRules() |
229 { | 225 { |
230 if (!m_matchedRules || m_matchedRules->isEmpty()) | 226 if (m_matchedRules.isEmpty()) |
231 return; | 227 return; |
232 | 228 |
233 sortMatchedRules(); | 229 sortMatchedRules(); |
234 | 230 |
235 WillBeHeapVector<MatchedRule, 32>& matchedRules = *m_matchedRules; | |
236 if (m_mode == SelectorChecker::CollectingStyleRules) { | 231 if (m_mode == SelectorChecker::CollectingStyleRules) { |
237 for (unsigned i = 0; i < matchedRules.size(); ++i) | 232 for (unsigned i = 0; i < m_matchedRules.size(); ++i) |
238 ensureStyleRuleList()->m_list.append(matchedRules[i].ruleData()->rul
e()); | 233 ensureStyleRuleList()->m_list.append(m_matchedRules[i].ruleData()->r
ule()); |
239 return; | 234 return; |
240 } | 235 } |
241 | 236 |
242 if (m_mode == SelectorChecker::CollectingCSSRules) { | 237 if (m_mode == SelectorChecker::CollectingCSSRules) { |
243 for (unsigned i = 0; i < matchedRules.size(); ++i) | 238 for (unsigned i = 0; i < m_matchedRules.size(); ++i) |
244 appendCSSOMWrapperForRule(const_cast<CSSStyleSheet*>(matchedRules[i]
.parentStyleSheet()), matchedRules[i].ruleData()->rule()); | 239 appendCSSOMWrapperForRule(const_cast<CSSStyleSheet*>(m_matchedRules[
i].parentStyleSheet()), m_matchedRules[i].ruleData()->rule()); |
245 return; | 240 return; |
246 } | 241 } |
247 | 242 |
248 // Now transfer the set of matched rules over to our list of declarations. | 243 // Now transfer the set of matched rules over to our list of declarations. |
249 for (unsigned i = 0; i < matchedRules.size(); i++) { | 244 for (unsigned i = 0; i < m_matchedRules.size(); i++) { |
250 // FIXME: Matching should not modify the style directly. | 245 // FIXME: Matching should not modify the style directly. |
251 const RuleData* ruleData = matchedRules[i].ruleData(); | 246 const RuleData* ruleData = m_matchedRules[i].ruleData(); |
252 if (m_style && ruleData->containsUncommonAttributeSelector()) | 247 if (m_style && ruleData->containsUncommonAttributeSelector()) |
253 m_style->setUnique(); | 248 m_style->setUnique(); |
254 m_result.addMatchedProperties(&ruleData->rule()->properties(), ruleData-
>linkMatchType(), ruleData->propertyWhitelistType(m_matchingUARules)); | 249 m_result.addMatchedProperties(&ruleData->rule()->properties(), ruleData-
>linkMatchType(), ruleData->propertyWhitelistType(m_matchingUARules)); |
255 } | 250 } |
256 } | 251 } |
257 | 252 |
258 inline bool ElementRuleCollector::ruleMatches(const RuleData& ruleData, const Co
ntainerNode* scope, SelectorChecker::MatchResult* result) | 253 inline bool ElementRuleCollector::ruleMatches(const RuleData& ruleData, const Co
ntainerNode* scope, SelectorChecker::MatchResult* result) |
259 { | 254 { |
260 SelectorChecker selectorChecker(m_context.element()->document(), m_mode); | 255 SelectorChecker selectorChecker(m_context.element()->document(), m_mode); |
261 SelectorChecker::SelectorCheckingContext context(ruleData.selector(), m_cont
ext.element(), SelectorChecker::VisitedMatchEnabled); | 256 SelectorChecker::SelectorCheckingContext context(ruleData.selector(), m_cont
ext.element(), SelectorChecker::VisitedMatchEnabled); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 unsigned specificity1 = matchedRule1.specificity(); | 318 unsigned specificity1 = matchedRule1.specificity(); |
324 unsigned specificity2 = matchedRule2.specificity(); | 319 unsigned specificity2 = matchedRule2.specificity(); |
325 if (specificity1 != specificity2) | 320 if (specificity1 != specificity2) |
326 return specificity1 < specificity2; | 321 return specificity1 < specificity2; |
327 | 322 |
328 return matchedRule1.position() < matchedRule2.position(); | 323 return matchedRule1.position() < matchedRule2.position(); |
329 } | 324 } |
330 | 325 |
331 void ElementRuleCollector::sortMatchedRules() | 326 void ElementRuleCollector::sortMatchedRules() |
332 { | 327 { |
333 ASSERT(m_matchedRules); | 328 std::sort(m_matchedRules.begin(), m_matchedRules.end(), compareRules); |
334 std::sort(m_matchedRules->begin(), m_matchedRules->end(), compareRules); | |
335 } | 329 } |
336 | 330 |
337 bool ElementRuleCollector::hasAnyMatchingRules(RuleSet* ruleSet) | 331 bool ElementRuleCollector::hasAnyMatchingRules(RuleSet* ruleSet) |
338 { | 332 { |
339 clearMatchedRules(); | 333 clearMatchedRules(); |
340 | 334 |
341 m_mode = SelectorChecker::SharingRules; | 335 m_mode = SelectorChecker::SharingRules; |
342 // To check whether a given RuleSet has any rule matching a given element, | 336 // To check whether a given RuleSet has any rule matching a given element, |
343 // should not see the element's treescope. Because RuleSet has no | 337 // should not see the element's treescope. Because RuleSet has no |
344 // information about "scope". | 338 // information about "scope". |
345 int firstRuleIndex = -1, lastRuleIndex = -1; | 339 int firstRuleIndex = -1, lastRuleIndex = -1; |
346 RuleRange ruleRange(firstRuleIndex, lastRuleIndex); | 340 RuleRange ruleRange(firstRuleIndex, lastRuleIndex); |
347 // FIXME: Verify whether it's ok to ignore CascadeScope here. | 341 // FIXME: Verify whether it's ok to ignore CascadeScope here. |
348 collectMatchingRules(MatchRequest(ruleSet), ruleRange); | 342 collectMatchingRules(MatchRequest(ruleSet), ruleRange); |
349 | 343 |
350 return m_matchedRules && !m_matchedRules->isEmpty(); | 344 return !m_matchedRules.isEmpty(); |
351 } | 345 } |
352 | 346 |
353 } // namespace blink | 347 } // namespace blink |
OLD | NEW |