| 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 // FIXME: Remove CascadeScope, it doesn't do anything now. | |
| 43 typedef unsigned CascadeScope; | |
| 44 typedef unsigned CascadeOrder; | 42 typedef unsigned CascadeOrder; |
| 45 | 43 |
| 46 const CascadeScope ignoreCascadeScope = 0; | |
| 47 const CascadeOrder ignoreCascadeOrder = 0; | 44 const CascadeOrder ignoreCascadeOrder = 0; |
| 48 | 45 |
| 49 class MatchedRule { | 46 class MatchedRule { |
| 50 ALLOW_ONLY_INLINE_ALLOCATION(); | 47 ALLOW_ONLY_INLINE_ALLOCATION(); |
| 51 public: | 48 public: |
| 52 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) |
| 53 : m_ruleData(ruleData) | 50 : m_ruleData(ruleData) |
| 54 , m_specificity(specificity) | 51 , m_specificity(specificity) |
| 55 , m_cascadeScope(cascadeScope) | |
| 56 , m_parentStyleSheet(parentStyleSheet) | 52 , m_parentStyleSheet(parentStyleSheet) |
| 57 { | 53 { |
| 58 ASSERT(m_ruleData); | 54 ASSERT(m_ruleData); |
| 59 static const unsigned BitsForPositionInRuleData = 18; | 55 static const unsigned BitsForPositionInRuleData = 18; |
| 60 static const unsigned BitsForStyleSheetIndex = 32; | 56 static const unsigned BitsForStyleSheetIndex = 32; |
| 61 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(); |
| 62 } | 58 } |
| 63 | 59 |
| 64 const RuleData* ruleData() const { return m_ruleData; } | 60 const RuleData* ruleData() const { return m_ruleData; } |
| 65 uint32_t cascadeScope() const { return m_cascadeScope; } | |
| 66 uint64_t position() const { return m_position; } | 61 uint64_t position() const { return m_position; } |
| 67 unsigned specificity() const { return ruleData()->specificity() + m_specific
ity; } | 62 unsigned specificity() const { return ruleData()->specificity() + m_specific
ity; } |
| 68 const CSSStyleSheet* parentStyleSheet() const { return m_parentStyleSheet; } | 63 const CSSStyleSheet* parentStyleSheet() const { return m_parentStyleSheet; } |
| 69 void trace(Visitor* visitor) | 64 void trace(Visitor* visitor) |
| 70 { | 65 { |
| 71 visitor->trace(m_parentStyleSheet); | 66 visitor->trace(m_parentStyleSheet); |
| 72 } | 67 } |
| 73 | 68 |
| 74 private: | 69 private: |
| 75 // FIXME: Oilpan: RuleData is in the oilpan heap and this pointer | 70 // FIXME: Oilpan: RuleData is in the oilpan heap and this pointer |
| 76 // really should be traced. However, RuleData objects are | 71 // really should be traced. However, RuleData objects are |
| 77 // allocated inside larger TerminatedArray objects and we cannot | 72 // allocated inside larger TerminatedArray objects and we cannot |
| 78 // trace a raw rule data pointer at this point. | 73 // trace a raw rule data pointer at this point. |
| 79 const RuleData* m_ruleData; | 74 const RuleData* m_ruleData; |
| 80 unsigned m_specificity; | 75 unsigned m_specificity; |
| 81 CascadeScope m_cascadeScope; | |
| 82 uint64_t m_position; | 76 uint64_t m_position; |
| 83 RawPtrWillBeMember<const CSSStyleSheet> m_parentStyleSheet; | 77 RawPtrWillBeMember<const CSSStyleSheet> m_parentStyleSheet; |
| 84 }; | 78 }; |
| 85 | 79 |
| 86 } // namespace blink | 80 } // namespace blink |
| 87 | 81 |
| 88 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::MatchedRule); | 82 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::MatchedRule); |
| 89 | 83 |
| 90 namespace blink { | 84 namespace blink { |
| 91 | 85 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 119 void setPseudoStyleRequest(const PseudoStyleRequest& request) { m_pseudoStyl
eRequest = request; } | 113 void setPseudoStyleRequest(const PseudoStyleRequest& request) { m_pseudoStyl
eRequest = request; } |
| 120 void setSameOriginOnly(bool f) { m_sameOriginOnly = f; } | 114 void setSameOriginOnly(bool f) { m_sameOriginOnly = f; } |
| 121 | 115 |
| 122 void setMatchingUARules(bool matchingUARules) { m_matchingUARules = matching
UARules; } | 116 void setMatchingUARules(bool matchingUARules) { m_matchingUARules = matching
UARules; } |
| 123 bool hasAnyMatchingRules(RuleSet*); | 117 bool hasAnyMatchingRules(RuleSet*); |
| 124 | 118 |
| 125 MatchResult& matchedResult(); | 119 MatchResult& matchedResult(); |
| 126 PassRefPtrWillBeRawPtr<StyleRuleList> matchedStyleRuleList(); | 120 PassRefPtrWillBeRawPtr<StyleRuleList> matchedStyleRuleList(); |
| 127 PassRefPtrWillBeRawPtr<CSSRuleList> matchedCSSRuleList(); | 121 PassRefPtrWillBeRawPtr<CSSRuleList> matchedCSSRuleList(); |
| 128 | 122 |
| 129 void collectMatchingRules(const MatchRequest&, RuleRange&, SelectorChecker::
ContextFlags = SelectorChecker::DefaultBehavior, CascadeScope = ignoreCascadeSco
pe, CascadeOrder = ignoreCascadeOrder, bool matchingTreeBoundaryRules = false); | 123 void collectMatchingRules(const MatchRequest&, RuleRange&, SelectorChecker::
ContextFlags = SelectorChecker::DefaultBehavior, CascadeOrder = ignoreCascadeOrd
er, bool matchingTreeBoundaryRules = false); |
| 130 void sortAndTransferMatchedRules(); | 124 void sortAndTransferMatchedRules(); |
| 131 void clearMatchedRules(); | 125 void clearMatchedRules(); |
| 132 void addElementStyleProperties(const StylePropertySet*, bool isCacheable = t
rue); | 126 void addElementStyleProperties(const StylePropertySet*, bool isCacheable = t
rue); |
| 133 | 127 |
| 134 private: | 128 private: |
| 135 void collectRuleIfMatches(const RuleData&, SelectorChecker::ContextFlags, Ca
scadeScope, CascadeOrder, const MatchRequest&, RuleRange&); | 129 void collectRuleIfMatches(const RuleData&, SelectorChecker::ContextFlags, Ca
scadeOrder, const MatchRequest&, RuleRange&); |
| 136 | 130 |
| 137 template<typename RuleDataListType> | 131 template<typename RuleDataListType> |
| 138 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) |
| 139 { | 133 { |
| 140 if (!rules) | 134 if (!rules) |
| 141 return; | 135 return; |
| 142 | 136 |
| 143 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) |
| 144 collectRuleIfMatches(*it, contextFlags, cascadeScope, cascadeOrder,
matchRequest, ruleRange); | 138 collectRuleIfMatches(*it, contextFlags, cascadeOrder, matchRequest,
ruleRange); |
| 145 } | 139 } |
| 146 | 140 |
| 147 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*); |
| 148 | 142 |
| 149 CSSRuleList* nestedRuleList(CSSRule*); | 143 CSSRuleList* nestedRuleList(CSSRule*); |
| 150 template<class CSSRuleCollection> | 144 template<class CSSRuleCollection> |
| 151 CSSRule* findStyleRule(CSSRuleCollection*, StyleRule*); | 145 CSSRule* findStyleRule(CSSRuleCollection*, StyleRule*); |
| 152 void appendCSSOMWrapperForRule(CSSStyleSheet*, StyleRule*); | 146 void appendCSSOMWrapperForRule(CSSStyleSheet*, StyleRule*); |
| 153 | 147 |
| 154 void sortMatchedRules(); | 148 void sortMatchedRules(); |
| 155 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); |
| 156 | 150 |
| 157 StaticCSSRuleList* ensureRuleList(); | 151 StaticCSSRuleList* ensureRuleList(); |
| 158 StyleRuleList* ensureStyleRuleList(); | 152 StyleRuleList* ensureStyleRuleList(); |
| 159 | 153 |
| 160 private: | 154 private: |
| 161 const ElementResolveContext& m_context; | 155 const ElementResolveContext& m_context; |
| 162 const SelectorFilter& m_selectorFilter; | 156 const SelectorFilter& m_selectorFilter; |
| 163 RefPtr<RenderStyle> m_style; // FIXME: This can be mutated during matching! | 157 RefPtr<RenderStyle> m_style; // FIXME: This can be mutated during matching! |
| 164 | 158 |
| 165 PseudoStyleRequest m_pseudoStyleRequest; | 159 PseudoStyleRequest m_pseudoStyleRequest; |
| 166 SelectorChecker::Mode m_mode; | 160 SelectorChecker::Mode m_mode; |
| 167 bool m_canUseFastReject; | 161 bool m_canUseFastReject; |
| 168 bool m_sameOriginOnly; | 162 bool m_sameOriginOnly; |
| 169 bool m_matchingUARules; | 163 bool m_matchingUARules; |
| 170 | 164 |
| 171 OwnPtrWillBeMember<WillBeHeapVector<MatchedRule, 32> > m_matchedRules; | 165 OwnPtrWillBeMember<WillBeHeapVector<MatchedRule, 32> > m_matchedRules; |
| 172 | 166 |
| 173 // Output. | 167 // Output. |
| 174 RefPtrWillBeMember<StaticCSSRuleList> m_cssRuleList; | 168 RefPtrWillBeMember<StaticCSSRuleList> m_cssRuleList; |
| 175 RefPtrWillBeMember<StyleRuleList> m_styleRuleList; | 169 RefPtrWillBeMember<StyleRuleList> m_styleRuleList; |
| 176 MatchResult m_result; | 170 MatchResult m_result; |
| 177 }; | 171 }; |
| 178 | 172 |
| 179 } // namespace blink | 173 } // namespace blink |
| 180 | 174 |
| 181 #endif // ElementRuleCollector_h | 175 #endif // ElementRuleCollector_h |
| OLD | NEW |