OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. | 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 namespace blink { | 33 namespace blink { |
34 | 34 |
35 class CSSStyleSheet; | 35 class CSSStyleSheet; |
36 class CSSRuleList; | 36 class CSSRuleList; |
37 class RuleData; | 37 class RuleData; |
38 class RuleSet; | 38 class RuleSet; |
39 class SelectorFilter; | 39 class SelectorFilter; |
40 class StaticCSSRuleList; | 40 class StaticCSSRuleList; |
41 | 41 |
42 typedef unsigned CascadeScope; | |
43 typedef unsigned CascadeOrder; | 42 typedef unsigned CascadeOrder; |
44 | 43 |
45 const CascadeScope ignoreCascadeScope = 0; | |
46 const CascadeOrder ignoreCascadeOrder = 0; | 44 const CascadeOrder ignoreCascadeOrder = 0; |
47 | 45 |
48 class MatchedRule { | 46 class MatchedRule { |
49 ALLOW_ONLY_INLINE_ALLOCATION(); | 47 ALLOW_ONLY_INLINE_ALLOCATION(); |
50 public: | 48 public: |
51 MatchedRule(const RuleData* ruleData, unsigned specificity, CascadeScope cas
cadeScope, CascadeOrder cascadeOrder, unsigned styleSheetIndex, const CSSStyleSh
eet* parentStyleSheet) | 49 MatchedRule(const RuleData* ruleData, unsigned specificity, CascadeOrder cas
cadeOrder, unsigned styleSheetIndex, const CSSStyleSheet* parentStyleSheet) |
52 : m_ruleData(ruleData) | 50 : m_ruleData(ruleData) |
53 , m_specificity(specificity) | 51 , m_specificity(specificity) |
54 , m_cascadeScope(cascadeScope) | |
55 , m_parentStyleSheet(parentStyleSheet) | 52 , m_parentStyleSheet(parentStyleSheet) |
56 { | 53 { |
57 ASSERT(m_ruleData); | 54 ASSERT(m_ruleData); |
58 static const unsigned BitsForPositionInRuleData = 18; | 55 static const unsigned BitsForPositionInRuleData = 18; |
59 static const unsigned BitsForStyleSheetIndex = 32; | 56 static const unsigned BitsForStyleSheetIndex = 32; |
60 m_position = ((uint64_t)cascadeOrder << (BitsForStyleSheetIndex + BitsFo
rPositionInRuleData)) + ((uint64_t)styleSheetIndex << BitsForPositionInRuleData)
+ m_ruleData->position(); | 57 m_position = ((uint64_t)cascadeOrder << (BitsForStyleSheetIndex + BitsFo
rPositionInRuleData)) + ((uint64_t)styleSheetIndex << BitsForPositionInRuleData)
+ m_ruleData->position(); |
61 } | 58 } |
62 | 59 |
63 const RuleData* ruleData() const { return m_ruleData; } | 60 const RuleData* ruleData() const { return m_ruleData; } |
64 uint32_t cascadeScope() const { return m_cascadeScope; } | |
65 uint64_t position() const { return m_position; } | 61 uint64_t position() const { return m_position; } |
66 unsigned specificity() const { return ruleData()->specificity() + m_specific
ity; } | 62 unsigned specificity() const { return ruleData()->specificity() + m_specific
ity; } |
67 const CSSStyleSheet* parentStyleSheet() const { return m_parentStyleSheet; } | 63 const CSSStyleSheet* parentStyleSheet() const { return m_parentStyleSheet; } |
68 void trace(Visitor* visitor) | 64 void trace(Visitor* visitor) |
69 { | 65 { |
70 visitor->trace(m_parentStyleSheet); | 66 visitor->trace(m_parentStyleSheet); |
71 } | 67 } |
72 | 68 |
73 private: | 69 private: |
74 // FIXME: Oilpan: RuleData is in the oilpan heap and this pointer | 70 // FIXME: Oilpan: RuleData is in the oilpan heap and this pointer |
75 // really should be traced. However, RuleData objects are | 71 // really should be traced. However, RuleData objects are |
76 // allocated inside larger TerminatedArray objects and we cannot | 72 // allocated inside larger TerminatedArray objects and we cannot |
77 // trace a raw rule data pointer at this point. | 73 // trace a raw rule data pointer at this point. |
78 const RuleData* m_ruleData; | 74 const RuleData* m_ruleData; |
79 unsigned m_specificity; | 75 unsigned m_specificity; |
80 CascadeScope m_cascadeScope; | |
81 uint64_t m_position; | 76 uint64_t m_position; |
82 RawPtrWillBeMember<const CSSStyleSheet> m_parentStyleSheet; | 77 RawPtrWillBeMember<const CSSStyleSheet> m_parentStyleSheet; |
83 }; | 78 }; |
84 | 79 |
85 } // namespace blink | 80 } // namespace blink |
86 | 81 |
87 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::MatchedRule); | 82 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::MatchedRule); |
88 | 83 |
89 namespace blink { | 84 namespace blink { |
90 | 85 |
(...skipping 27 matching lines...) Expand all Loading... |
118 void setPseudoStyleRequest(const PseudoStyleRequest& request) { m_pseudoStyl
eRequest = request; } | 113 void setPseudoStyleRequest(const PseudoStyleRequest& request) { m_pseudoStyl
eRequest = request; } |
119 void setSameOriginOnly(bool f) { m_sameOriginOnly = f; } | 114 void setSameOriginOnly(bool f) { m_sameOriginOnly = f; } |
120 | 115 |
121 void setMatchingUARules(bool matchingUARules) { m_matchingUARules = matching
UARules; } | 116 void setMatchingUARules(bool matchingUARules) { m_matchingUARules = matching
UARules; } |
122 bool hasAnyMatchingRules(RuleSet*); | 117 bool hasAnyMatchingRules(RuleSet*); |
123 | 118 |
124 MatchResult& matchedResult(); | 119 MatchResult& matchedResult(); |
125 PassRefPtrWillBeRawPtr<StyleRuleList> matchedStyleRuleList(); | 120 PassRefPtrWillBeRawPtr<StyleRuleList> matchedStyleRuleList(); |
126 PassRefPtrWillBeRawPtr<CSSRuleList> matchedCSSRuleList(); | 121 PassRefPtrWillBeRawPtr<CSSRuleList> matchedCSSRuleList(); |
127 | 122 |
128 void collectMatchingRules(const MatchRequest&, RuleRange&, SelectorChecker::
ContextFlags = SelectorChecker::DefaultBehavior, CascadeScope = ignoreCascadeSco
pe, CascadeOrder = ignoreCascadeOrder); | 123 void collectMatchingRules(const MatchRequest&, RuleRange&, SelectorChecker::
ContextFlags = SelectorChecker::DefaultBehavior, CascadeOrder = ignoreCascadeOrd
er); |
129 void sortAndTransferMatchedRules(); | 124 void sortAndTransferMatchedRules(); |
130 void clearMatchedRules(); | 125 void clearMatchedRules(); |
131 void addElementStyleProperties(const StylePropertySet*, bool isCacheable = t
rue); | 126 void addElementStyleProperties(const StylePropertySet*, bool isCacheable = t
rue); |
132 | 127 |
133 private: | 128 private: |
134 void collectRuleIfMatches(const RuleData&, SelectorChecker::ContextFlags, Ca
scadeScope, CascadeOrder, const MatchRequest&, RuleRange&); | 129 void collectRuleIfMatches(const RuleData&, SelectorChecker::ContextFlags, Ca
scadeOrder, const MatchRequest&, RuleRange&); |
135 | 130 |
136 template<typename RuleDataListType> | 131 template<typename RuleDataListType> |
137 void collectMatchingRulesForList(const RuleDataListType* rules, SelectorChec
ker::ContextFlags contextFlags, CascadeScope cascadeScope, CascadeOrder cascadeO
rder, const MatchRequest& matchRequest, RuleRange& ruleRange) | 132 void collectMatchingRulesForList(const RuleDataListType* rules, SelectorChec
ker::ContextFlags contextFlags, CascadeOrder cascadeOrder, const MatchRequest& m
atchRequest, RuleRange& ruleRange) |
138 { | 133 { |
139 if (!rules) | 134 if (!rules) |
140 return; | 135 return; |
141 | 136 |
142 for (typename RuleDataListType::const_iterator it = rules->begin(), end
= rules->end(); it != end; ++it) | 137 for (typename RuleDataListType::const_iterator it = rules->begin(), end
= rules->end(); it != end; ++it) |
143 collectRuleIfMatches(*it, contextFlags, cascadeScope, cascadeOrder,
matchRequest, ruleRange); | 138 collectRuleIfMatches(*it, contextFlags, cascadeOrder, matchRequest,
ruleRange); |
144 } | 139 } |
145 | 140 |
146 bool ruleMatches(const RuleData&, const ContainerNode* scope, SelectorChecke
r::ContextFlags, SelectorChecker::MatchResult*); | 141 bool ruleMatches(const RuleData&, const ContainerNode* scope, SelectorChecke
r::ContextFlags, SelectorChecker::MatchResult*); |
147 | 142 |
148 CSSRuleList* nestedRuleList(CSSRule*); | 143 CSSRuleList* nestedRuleList(CSSRule*); |
149 template<class CSSRuleCollection> | 144 template<class CSSRuleCollection> |
150 CSSRule* findStyleRule(CSSRuleCollection*, StyleRule*); | 145 CSSRule* findStyleRule(CSSRuleCollection*, StyleRule*); |
151 void appendCSSOMWrapperForRule(CSSStyleSheet*, StyleRule*); | 146 void appendCSSOMWrapperForRule(CSSStyleSheet*, StyleRule*); |
152 | 147 |
153 void sortMatchedRules(); | 148 void sortMatchedRules(); |
154 void addMatchedRule(const RuleData*, unsigned specificity, CascadeScope, Cas
cadeOrder, unsigned styleSheetIndex, const CSSStyleSheet* parentStyleSheet); | 149 void addMatchedRule(const RuleData*, unsigned specificity, CascadeOrder, uns
igned styleSheetIndex, const CSSStyleSheet* parentStyleSheet); |
155 | 150 |
156 StaticCSSRuleList* ensureRuleList(); | 151 StaticCSSRuleList* ensureRuleList(); |
157 StyleRuleList* ensureStyleRuleList(); | 152 StyleRuleList* ensureStyleRuleList(); |
158 | 153 |
159 private: | 154 private: |
160 const ElementResolveContext& m_context; | 155 const ElementResolveContext& m_context; |
161 const SelectorFilter& m_selectorFilter; | 156 const SelectorFilter& m_selectorFilter; |
162 RefPtr<RenderStyle> m_style; // FIXME: This can be mutated during matching! | 157 RefPtr<RenderStyle> m_style; // FIXME: This can be mutated during matching! |
163 | 158 |
164 PseudoStyleRequest m_pseudoStyleRequest; | 159 PseudoStyleRequest m_pseudoStyleRequest; |
165 SelectorChecker::Mode m_mode; | 160 SelectorChecker::Mode m_mode; |
166 bool m_canUseFastReject; | 161 bool m_canUseFastReject; |
167 bool m_sameOriginOnly; | 162 bool m_sameOriginOnly; |
168 bool m_matchingUARules; | 163 bool m_matchingUARules; |
169 | 164 |
170 OwnPtrWillBeMember<WillBeHeapVector<MatchedRule, 32> > m_matchedRules; | 165 OwnPtrWillBeMember<WillBeHeapVector<MatchedRule, 32> > m_matchedRules; |
171 | 166 |
172 // Output. | 167 // Output. |
173 RefPtrWillBeMember<StaticCSSRuleList> m_cssRuleList; | 168 RefPtrWillBeMember<StaticCSSRuleList> m_cssRuleList; |
174 RefPtrWillBeMember<StyleRuleList> m_styleRuleList; | 169 RefPtrWillBeMember<StyleRuleList> m_styleRuleList; |
175 MatchResult m_result; | 170 MatchResult m_result; |
176 }; | 171 }; |
177 | 172 |
178 } // namespace blink | 173 } // namespace blink |
179 | 174 |
180 #endif // ElementRuleCollector_h | 175 #endif // ElementRuleCollector_h |
OLD | NEW |