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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 { | 65 { |
66 if (!m_matchedRules) | 66 if (!m_matchedRules) |
67 return; | 67 return; |
68 m_matchedRules->clear(); | 68 m_matchedRules->clear(); |
69 } | 69 } |
70 | 70 |
71 void ElementRuleCollector::addElementStyleProperties(const StylePropertySet* pro
pertySet, bool isCacheable) | 71 void ElementRuleCollector::addElementStyleProperties(const StylePropertySet* pro
pertySet, bool isCacheable) |
72 { | 72 { |
73 if (!propertySet) | 73 if (!propertySet) |
74 return; | 74 return; |
75 m_result.ranges.lastAuthorRule = m_result.matchedProperties.size(); | |
76 if (m_result.ranges.firstAuthorRule == -1) | |
77 m_result.ranges.firstAuthorRule = m_result.ranges.lastAuthorRule; | |
78 m_result.addMatchedProperties(propertySet); | 75 m_result.addMatchedProperties(propertySet); |
79 if (!isCacheable) | 76 if (!isCacheable) |
80 m_result.isCacheable = false; | 77 m_result.isCacheable = false; |
81 } | 78 } |
82 | 79 |
83 void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest
, RuleRange& ruleRange, CascadeOrder cascadeOrder) | 80 void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest
, CascadeOrder cascadeOrder) |
84 { | 81 { |
85 ASSERT(matchRequest.ruleSet); | 82 ASSERT(matchRequest.ruleSet); |
86 ASSERT(m_context.element()); | 83 ASSERT(m_context.element()); |
87 | 84 |
88 Element& element = *m_context.element(); | 85 Element& element = *m_context.element(); |
89 | 86 |
90 // We need to collect the rules for id, class, tag, and everything else into
a buffer and | 87 // We need to collect the rules for id, class, tag, and everything else into
a buffer and |
91 // then sort the buffer. | 88 // then sort the buffer. |
92 if (element.hasID()) | 89 if (element.hasID()) |
93 collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForS
tyleResolution()), cascadeOrder, matchRequest, ruleRange); | 90 collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForS
tyleResolution()), cascadeOrder, matchRequest); |
94 if (element.isStyledElement() && element.hasClass()) { | 91 if (element.isStyledElement() && element.hasClass()) { |
95 for (size_t i = 0; i < element.classNames().size(); ++i) | 92 for (size_t i = 0; i < element.classNames().size(); ++i) |
96 collectMatchingRulesForList(matchRequest.ruleSet->classRules(element
.classNames()[i]), cascadeOrder, matchRequest, ruleRange); | 93 collectMatchingRulesForList(matchRequest.ruleSet->classRules(element
.classNames()[i]), cascadeOrder, matchRequest); |
97 } | 94 } |
98 | 95 |
99 collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName
()), cascadeOrder, matchRequest, ruleRange); | 96 collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName
()), cascadeOrder, matchRequest); |
100 collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), cascadeO
rder, matchRequest, ruleRange); | 97 collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), cascadeO
rder, matchRequest); |
101 } | 98 } |
102 | 99 |
103 void ElementRuleCollector::collectMatchingHostRules(const MatchRequest& matchReq
uest, RuleRange& ruleRange, CascadeOrder cascadeOrder) | 100 void ElementRuleCollector::collectMatchingHostRules(const MatchRequest& matchReq
uest, CascadeOrder cascadeOrder) |
104 { | 101 { |
105 collectMatchingRulesForList(matchRequest.ruleSet->hostRules(), cascadeOrder,
matchRequest, ruleRange); | 102 collectMatchingRulesForList(matchRequest.ruleSet->hostRules(), cascadeOrder,
matchRequest); |
106 } | 103 } |
107 | 104 |
108 void ElementRuleCollector::sortAndTransferMatchedRules() | 105 void ElementRuleCollector::sortAndTransferMatchedRules() |
109 { | 106 { |
110 if (!m_matchedRules || m_matchedRules->isEmpty()) | 107 if (!m_matchedRules || m_matchedRules->isEmpty()) |
111 return; | 108 return; |
112 | 109 |
113 sortMatchedRules(); | 110 sortMatchedRules(); |
114 | 111 |
115 Vector<MatchedRule, 32>& matchedRules = *m_matchedRules; | 112 Vector<MatchedRule, 32>& matchedRules = *m_matchedRules; |
(...skipping 18 matching lines...) Expand all Loading... |
134 | 131 |
135 if (checker.matchedHoverSelector()) | 132 if (checker.matchedHoverSelector()) |
136 m_style->setAffectedByHover(); | 133 m_style->setAffectedByHover(); |
137 | 134 |
138 if (checker.matchedActiveSelector()) | 135 if (checker.matchedActiveSelector()) |
139 m_style->setAffectedByActive(); | 136 m_style->setAffectedByActive(); |
140 | 137 |
141 return matched; | 138 return matched; |
142 } | 139 } |
143 | 140 |
144 void ElementRuleCollector::collectRuleIfMatches(const RuleData& ruleData, Cascad
eOrder cascadeOrder, const MatchRequest& matchRequest, RuleRange& ruleRange) | 141 void ElementRuleCollector::collectRuleIfMatches(const RuleData& ruleData, Cascad
eOrder cascadeOrder, const MatchRequest& matchRequest) |
145 { | 142 { |
146 StyleRule* rule = ruleData.rule(); | 143 StyleRule* rule = ruleData.rule(); |
147 if (ruleMatches(ruleData)) { | 144 if (ruleMatches(ruleData)) { |
148 // 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. |
149 const StylePropertySet& properties = rule->properties(); | 146 const StylePropertySet& properties = rule->properties(); |
150 if (properties.isEmpty()) | 147 if (properties.isEmpty()) |
151 return; | 148 return; |
152 | 149 |
153 // Update our first/last rule indices in the matched rules array. | |
154 ++ruleRange.lastRuleIndex; | |
155 if (ruleRange.firstRuleIndex == -1) | |
156 ruleRange.firstRuleIndex = ruleRange.lastRuleIndex; | |
157 | |
158 // Add this rule to our list of matched rules. | 150 // Add this rule to our list of matched rules. |
159 addMatchedRule(&ruleData, cascadeOrder, matchRequest.styleSheetIndex, ma
tchRequest.styleSheet); | 151 addMatchedRule(&ruleData, cascadeOrder, matchRequest.styleSheetIndex, ma
tchRequest.styleSheet); |
160 } | 152 } |
161 } | 153 } |
162 | 154 |
163 static inline bool compareRules(const MatchedRule& matchedRule1, const MatchedRu
le& matchedRule2) | 155 static inline bool compareRules(const MatchedRule& matchedRule1, const MatchedRu
le& matchedRule2) |
164 { | 156 { |
165 return matchedRule1.position() < matchedRule2.position(); | 157 return matchedRule1.position() < matchedRule2.position(); |
166 } | 158 } |
167 | 159 |
168 void ElementRuleCollector::sortMatchedRules() | 160 void ElementRuleCollector::sortMatchedRules() |
169 { | 161 { |
170 ASSERT(m_matchedRules); | 162 ASSERT(m_matchedRules); |
171 std::sort(m_matchedRules->begin(), m_matchedRules->end(), compareRules); | 163 std::sort(m_matchedRules->begin(), m_matchedRules->end(), compareRules); |
172 } | 164 } |
173 | 165 |
174 } // namespace blink | 166 } // namespace blink |
OLD | NEW |