| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 ElementRuleCollector::~ElementRuleCollector() | 50 ElementRuleCollector::~ElementRuleCollector() |
| 51 { | 51 { |
| 52 } | 52 } |
| 53 | 53 |
| 54 MatchResult& ElementRuleCollector::matchedResult() | 54 MatchResult& ElementRuleCollector::matchedResult() |
| 55 { | 55 { |
| 56 return m_result; | 56 return m_result; |
| 57 } | 57 } |
| 58 | 58 |
| 59 inline void ElementRuleCollector::addMatchedRule(const RuleData* rule, CascadeSc
ope cascadeScope, CascadeOrder cascadeOrder, unsigned styleSheetIndex, const CSS
StyleSheet* parentStyleSheet) | 59 inline void ElementRuleCollector::addMatchedRule(const RuleData* rule, CascadeOr
der cascadeOrder, unsigned styleSheetIndex, const CSSStyleSheet* parentStyleShee
t) |
| 60 { | 60 { |
| 61 if (!m_matchedRules) | 61 if (!m_matchedRules) |
| 62 m_matchedRules = adoptPtr(new Vector<MatchedRule, 32>); | 62 m_matchedRules = adoptPtr(new Vector<MatchedRule, 32>); |
| 63 m_matchedRules->append(MatchedRule(rule, cascadeScope, cascadeOrder, styleSh
eetIndex, parentStyleSheet)); | 63 m_matchedRules->append(MatchedRule(rule, cascadeOrder, styleSheetIndex, pare
ntStyleSheet)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void ElementRuleCollector::clearMatchedRules() | 66 void ElementRuleCollector::clearMatchedRules() |
| 67 { | 67 { |
| 68 if (!m_matchedRules) | 68 if (!m_matchedRules) |
| 69 return; | 69 return; |
| 70 m_matchedRules->clear(); | 70 m_matchedRules->clear(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void ElementRuleCollector::addElementStyleProperties(const StylePropertySet* pro
pertySet, bool isCacheable) | 73 void ElementRuleCollector::addElementStyleProperties(const StylePropertySet* pro
pertySet, bool isCacheable) |
| 74 { | 74 { |
| 75 if (!propertySet) | 75 if (!propertySet) |
| 76 return; | 76 return; |
| 77 m_result.ranges.lastAuthorRule = m_result.matchedProperties.size(); | 77 m_result.ranges.lastAuthorRule = m_result.matchedProperties.size(); |
| 78 if (m_result.ranges.firstAuthorRule == -1) | 78 if (m_result.ranges.firstAuthorRule == -1) |
| 79 m_result.ranges.firstAuthorRule = m_result.ranges.lastAuthorRule; | 79 m_result.ranges.firstAuthorRule = m_result.ranges.lastAuthorRule; |
| 80 m_result.addMatchedProperties(propertySet); | 80 m_result.addMatchedProperties(propertySet); |
| 81 if (!isCacheable) | 81 if (!isCacheable) |
| 82 m_result.isCacheable = false; | 82 m_result.isCacheable = false; |
| 83 } | 83 } |
| 84 | 84 |
| 85 static bool rulesApplicableInCurrentTreeScope(const Element* element, const Cont
ainerNode* scopingNode) | 85 static bool rulesApplicableInCurrentTreeScope(const Element* element, const Cont
ainerNode* scopingNode) |
| 86 { | 86 { |
| 87 TreeScope& treeScope = element->treeScope(); | 87 TreeScope& treeScope = element->treeScope(); |
| 88 return !scopingNode || | 88 return !scopingNode || |
| 89 treeScope == scopingNode->treeScope() || | 89 treeScope == scopingNode->treeScope() || |
| 90 SelectorChecker::isHostInItsShadowTree(*element, scopingNode); | 90 SelectorChecker::isHostInItsShadowTree(*element, scopingNode); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest
, RuleRange& ruleRange, CascadeScope cascadeScope, CascadeOrder cascadeOrder) | 93 void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest
, RuleRange& ruleRange, CascadeOrder cascadeOrder) |
| 94 { | 94 { |
| 95 ASSERT(matchRequest.ruleSet); | 95 ASSERT(matchRequest.ruleSet); |
| 96 ASSERT(m_context.element()); | 96 ASSERT(m_context.element()); |
| 97 | 97 |
| 98 Element& element = *m_context.element(); | 98 Element& element = *m_context.element(); |
| 99 | 99 |
| 100 if (!m_matchingUARules && !rulesApplicableInCurrentTreeScope(&element, match
Request.scope)) | 100 if (!m_matchingUARules && !rulesApplicableInCurrentTreeScope(&element, match
Request.scope)) |
| 101 return; | 101 return; |
| 102 | 102 |
| 103 // We need to collect the rules for id, class, tag, and everything else into
a buffer and | 103 // We need to collect the rules for id, class, tag, and everything else into
a buffer and |
| 104 // then sort the buffer. | 104 // then sort the buffer. |
| 105 if (element.hasID()) | 105 if (element.hasID()) |
| 106 collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForS
tyleResolution()), cascadeScope, cascadeOrder, matchRequest, ruleRange); | 106 collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForS
tyleResolution()), cascadeOrder, matchRequest, ruleRange); |
| 107 if (element.isStyledElement() && element.hasClass()) { | 107 if (element.isStyledElement() && element.hasClass()) { |
| 108 for (size_t i = 0; i < element.classNames().size(); ++i) | 108 for (size_t i = 0; i < element.classNames().size(); ++i) |
| 109 collectMatchingRulesForList(matchRequest.ruleSet->classRules(element
.classNames()[i]), cascadeScope, cascadeOrder, matchRequest, ruleRange); | 109 collectMatchingRulesForList(matchRequest.ruleSet->classRules(element
.classNames()[i]), cascadeOrder, matchRequest, ruleRange); |
| 110 } | 110 } |
| 111 | 111 |
| 112 collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName
()), cascadeScope, cascadeOrder, matchRequest, ruleRange); | 112 collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName
()), cascadeOrder, matchRequest, ruleRange); |
| 113 collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), cascadeS
cope, cascadeOrder, matchRequest, ruleRange); | 113 collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), cascadeO
rder, matchRequest, ruleRange); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void ElementRuleCollector::sortAndTransferMatchedRules() | 116 void ElementRuleCollector::sortAndTransferMatchedRules() |
| 117 { | 117 { |
| 118 if (!m_matchedRules || m_matchedRules->isEmpty()) | 118 if (!m_matchedRules || m_matchedRules->isEmpty()) |
| 119 return; | 119 return; |
| 120 | 120 |
| 121 sortMatchedRules(); | 121 sortMatchedRules(); |
| 122 | 122 |
| 123 Vector<MatchedRule, 32>& matchedRules = *m_matchedRules; | 123 Vector<MatchedRule, 32>& matchedRules = *m_matchedRules; |
| 124 | 124 |
| 125 // Now transfer the set of matched rules over to our list of declarations. | 125 // Now transfer the set of matched rules over to our list of declarations. |
| 126 for (unsigned i = 0; i < matchedRules.size(); i++) { | 126 for (unsigned i = 0; i < matchedRules.size(); i++) { |
| 127 const RuleData* ruleData = matchedRules[i].ruleData(); | 127 const RuleData* ruleData = matchedRules[i].ruleData(); |
| 128 m_result.addMatchedProperties(&ruleData->rule()->properties()); | 128 m_result.addMatchedProperties(&ruleData->rule()->properties()); |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 inline bool ElementRuleCollector::ruleMatches(const RuleData& ruleData, const Co
ntainerNode* scope) | 132 inline bool ElementRuleCollector::ruleMatches(const RuleData& ruleData, const Co
ntainerNode* scope) |
| 133 { | 133 { |
| 134 SelectorChecker selectorChecker(m_context.element()->document(), m_mode); | 134 SelectorChecker selectorChecker(m_context.element()->document(), m_mode); |
| 135 SelectorChecker::SelectorCheckingContext context(ruleData.selector(), m_cont
ext.element()); | 135 SelectorChecker::SelectorCheckingContext context(ruleData.selector(), m_cont
ext.element()); |
| 136 context.elementStyle = m_style.get(); | 136 context.elementStyle = m_style.get(); |
| 137 context.scope = scope; | 137 context.scope = scope; |
| 138 return selectorChecker.match(context); | 138 return selectorChecker.match(context); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void ElementRuleCollector::collectRuleIfMatches(const RuleData& ruleData, Cascad
eScope cascadeScope, CascadeOrder cascadeOrder, const MatchRequest& matchRequest
, RuleRange& ruleRange) | 141 void ElementRuleCollector::collectRuleIfMatches(const RuleData& ruleData, Cascad
eOrder cascadeOrder, const MatchRequest& matchRequest, RuleRange& ruleRange) |
| 142 { | 142 { |
| 143 StyleRule* rule = ruleData.rule(); | 143 StyleRule* rule = ruleData.rule(); |
| 144 if (ruleMatches(ruleData, matchRequest.scope)) { | 144 if (ruleMatches(ruleData, matchRequest.scope)) { |
| 145 // If the rule has no properties to apply, then ignore it in the non-deb
ug mode. | 145 // If the rule has no properties to apply, then ignore it in the non-deb
ug mode. |
| 146 const StylePropertySet& properties = rule->properties(); | 146 const StylePropertySet& properties = rule->properties(); |
| 147 if (properties.isEmpty()) | 147 if (properties.isEmpty()) |
| 148 return; | 148 return; |
| 149 | 149 |
| 150 // Update our first/last rule indices in the matched rules array. | 150 // Update our first/last rule indices in the matched rules array. |
| 151 ++ruleRange.lastRuleIndex; | 151 ++ruleRange.lastRuleIndex; |
| 152 if (ruleRange.firstRuleIndex == -1) | 152 if (ruleRange.firstRuleIndex == -1) |
| 153 ruleRange.firstRuleIndex = ruleRange.lastRuleIndex; | 153 ruleRange.firstRuleIndex = ruleRange.lastRuleIndex; |
| 154 | 154 |
| 155 // Add this rule to our list of matched rules. | 155 // Add this rule to our list of matched rules. |
| 156 addMatchedRule(&ruleData, cascadeScope, cascadeOrder, matchRequest.style
SheetIndex, matchRequest.styleSheet); | 156 addMatchedRule(&ruleData, cascadeOrder, matchRequest.styleSheetIndex, ma
tchRequest.styleSheet); |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 static inline bool compareRules(const MatchedRule& matchedRule1, const MatchedRu
le& matchedRule2) | 160 static inline bool compareRules(const MatchedRule& matchedRule1, const MatchedRu
le& matchedRule2) |
| 161 { | 161 { |
| 162 if (matchedRule1.cascadeScope() != matchedRule2.cascadeScope()) | |
| 163 return matchedRule1.cascadeScope() > matchedRule2.cascadeScope(); | |
| 164 | |
| 165 return matchedRule1.position() < matchedRule2.position(); | 162 return matchedRule1.position() < matchedRule2.position(); |
| 166 } | 163 } |
| 167 | 164 |
| 168 void ElementRuleCollector::sortMatchedRules() | 165 void ElementRuleCollector::sortMatchedRules() |
| 169 { | 166 { |
| 170 ASSERT(m_matchedRules); | 167 ASSERT(m_matchedRules); |
| 171 std::sort(m_matchedRules->begin(), m_matchedRules->end(), compareRules); | 168 std::sort(m_matchedRules->begin(), m_matchedRules->end(), compareRules); |
| 172 } | 169 } |
| 173 | 170 |
| 174 } // namespace blink | 171 } // namespace blink |
| OLD | NEW |