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; | 231 WillBeHeapVector<MatchedRule, 32>& matchedRules = m_matchedRules; |
rune
2014/12/12 07:10:35
Is it really necessary to have a new reference her
sof
2014/12/12 07:13:23
Yes, we can simplify this away now. Will do.
| |
236 if (m_mode == SelectorChecker::CollectingStyleRules) { | 232 if (m_mode == SelectorChecker::CollectingStyleRules) { |
237 for (unsigned i = 0; i < matchedRules.size(); ++i) | 233 for (unsigned i = 0; i < matchedRules.size(); ++i) |
238 ensureStyleRuleList()->m_list.append(matchedRules[i].ruleData()->rul e()); | 234 ensureStyleRuleList()->m_list.append(matchedRules[i].ruleData()->rul e()); |
239 return; | 235 return; |
240 } | 236 } |
241 | 237 |
242 if (m_mode == SelectorChecker::CollectingCSSRules) { | 238 if (m_mode == SelectorChecker::CollectingCSSRules) { |
243 for (unsigned i = 0; i < matchedRules.size(); ++i) | 239 for (unsigned i = 0; i < matchedRules.size(); ++i) |
244 appendCSSOMWrapperForRule(const_cast<CSSStyleSheet*>(matchedRules[i] .parentStyleSheet()), matchedRules[i].ruleData()->rule()); | 240 appendCSSOMWrapperForRule(const_cast<CSSStyleSheet*>(matchedRules[i] .parentStyleSheet()), matchedRules[i].ruleData()->rule()); |
245 return; | 241 return; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 unsigned specificity1 = matchedRule1.specificity(); | 319 unsigned specificity1 = matchedRule1.specificity(); |
324 unsigned specificity2 = matchedRule2.specificity(); | 320 unsigned specificity2 = matchedRule2.specificity(); |
325 if (specificity1 != specificity2) | 321 if (specificity1 != specificity2) |
326 return specificity1 < specificity2; | 322 return specificity1 < specificity2; |
327 | 323 |
328 return matchedRule1.position() < matchedRule2.position(); | 324 return matchedRule1.position() < matchedRule2.position(); |
329 } | 325 } |
330 | 326 |
331 void ElementRuleCollector::sortMatchedRules() | 327 void ElementRuleCollector::sortMatchedRules() |
332 { | 328 { |
333 ASSERT(m_matchedRules); | 329 std::sort(m_matchedRules.begin(), m_matchedRules.end(), compareRules); |
334 std::sort(m_matchedRules->begin(), m_matchedRules->end(), compareRules); | |
335 } | 330 } |
336 | 331 |
337 bool ElementRuleCollector::hasAnyMatchingRules(RuleSet* ruleSet) | 332 bool ElementRuleCollector::hasAnyMatchingRules(RuleSet* ruleSet) |
338 { | 333 { |
339 clearMatchedRules(); | 334 clearMatchedRules(); |
340 | 335 |
341 m_mode = SelectorChecker::SharingRules; | 336 m_mode = SelectorChecker::SharingRules; |
342 // To check whether a given RuleSet has any rule matching a given element, | 337 // 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 | 338 // should not see the element's treescope. Because RuleSet has no |
344 // information about "scope". | 339 // information about "scope". |
345 int firstRuleIndex = -1, lastRuleIndex = -1; | 340 int firstRuleIndex = -1, lastRuleIndex = -1; |
346 RuleRange ruleRange(firstRuleIndex, lastRuleIndex); | 341 RuleRange ruleRange(firstRuleIndex, lastRuleIndex); |
347 // FIXME: Verify whether it's ok to ignore CascadeScope here. | 342 // FIXME: Verify whether it's ok to ignore CascadeScope here. |
348 collectMatchingRules(MatchRequest(ruleSet), ruleRange); | 343 collectMatchingRules(MatchRequest(ruleSet), ruleRange); |
349 | 344 |
350 return m_matchedRules && !m_matchedRules->isEmpty(); | 345 return !m_matchedRules.isEmpty(); |
351 } | 346 } |
352 | 347 |
353 } // namespace blink | 348 } // namespace blink |
OLD | NEW |