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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 SelectorPreMatch collectFeaturesFromRuleData(const RuleData&); | 73 SelectorPreMatch collectFeaturesFromRuleData(const RuleData&); |
74 | 74 |
75 bool usesSiblingRules() const { return !siblingRules.isEmpty(); } | 75 bool usesSiblingRules() const { return !siblingRules.isEmpty(); } |
76 bool usesFirstLineRules() const { return m_metadata.usesFirstLineRules; } | 76 bool usesFirstLineRules() const { return m_metadata.usesFirstLineRules; } |
77 bool usesWindowInactiveSelector() const { return m_metadata.usesWindowInacti
veSelector; } | 77 bool usesWindowInactiveSelector() const { return m_metadata.usesWindowInacti
veSelector; } |
78 | 78 |
79 unsigned maxDirectAdjacentSelectors() const { return m_metadata.maxDirectAdj
acentSelectors; } | 79 unsigned maxDirectAdjacentSelectors() const { return m_metadata.maxDirectAdj
acentSelectors; } |
80 | 80 |
81 bool hasSelectorForAttribute(const AtomicString& attributeName) const | 81 bool hasSelectorForAttribute(const AtomicString& attributeName) const |
82 { | 82 { |
83 ASSERT(!attributeName.isEmpty()); | 83 DCHECK(!attributeName.isEmpty()); |
84 return m_attributeInvalidationSets.contains(attributeName); | 84 return m_attributeInvalidationSets.contains(attributeName); |
85 } | 85 } |
86 | 86 |
87 bool hasSelectorForClass(const AtomicString& classValue) const | 87 bool hasSelectorForClass(const AtomicString& classValue) const |
88 { | 88 { |
89 ASSERT(!classValue.isEmpty()); | 89 DCHECK(!classValue.isEmpty()); |
90 return m_classInvalidationSets.contains(classValue); | 90 return m_classInvalidationSets.contains(classValue); |
91 } | 91 } |
92 | 92 |
93 bool hasSelectorForId(const AtomicString& idValue) const { return m_idInvali
dationSets.contains(idValue); } | 93 bool hasSelectorForId(const AtomicString& idValue) const { return m_idInvali
dationSets.contains(idValue); } |
94 | 94 |
95 // Collect descendant and sibling invalidation sets. | 95 // Collect descendant and sibling invalidation sets. |
96 void collectInvalidationSetsForClass(InvalidationLists&, Element&, const Ato
micString& className) const; | 96 void collectInvalidationSetsForClass(InvalidationLists&, Element&, const Ato
micString& className) const; |
97 void collectInvalidationSetsForId(InvalidationLists&, Element&, const Atomic
String& id) const; | 97 void collectInvalidationSetsForId(InvalidationLists&, Element&, const Atomic
String& id) const; |
98 void collectInvalidationSetsForAttribute(InvalidationLists&, Element&, const
QualifiedName& attributeName) const; | 98 void collectInvalidationSetsForAttribute(InvalidationLists&, Element&, const
QualifiedName& attributeName) const; |
99 void collectInvalidationSetsForPseudoClass(InvalidationLists&, Element&, CSS
Selector::PseudoType) const; | 99 void collectInvalidationSetsForPseudoClass(InvalidationLists&, Element&, CSS
Selector::PseudoType) const; |
(...skipping 10 matching lines...) Expand all Loading... |
110 } | 110 } |
111 | 111 |
112 DECLARE_TRACE(); | 112 DECLARE_TRACE(); |
113 | 113 |
114 HeapVector<RuleFeature> siblingRules; | 114 HeapVector<RuleFeature> siblingRules; |
115 HeapVector<RuleFeature> uncommonAttributeRules; | 115 HeapVector<RuleFeature> uncommonAttributeRules; |
116 | 116 |
117 bool isAlive() const { return m_isAlive; } | 117 bool isAlive() const { return m_isAlive; } |
118 | 118 |
119 protected: | 119 protected: |
120 InvalidationSet* invalidationSetForSelector(const CSSSelector&, Invalidation
Type); | 120 InvalidationSet* invalidationSetForSimpleSelector(const CSSSelector&, Invali
dationType); |
121 | 121 |
122 private: | 122 private: |
123 // Each map entry is either a DescendantInvalidationSet or SiblingInvalidati
onSet. | 123 // Each map entry is either a DescendantInvalidationSet or SiblingInvalidati
onSet. |
124 // When both are needed, we store the SiblingInvalidationSet, and use it to
hold the DescendantInvalidationSet. | 124 // When both are needed, we store the SiblingInvalidationSet, and use it to
hold the DescendantInvalidationSet. |
125 using InvalidationSetMap = HashMap<AtomicString, RefPtr<InvalidationSet>>; | 125 using InvalidationSetMap = HashMap<AtomicString, RefPtr<InvalidationSet>>; |
126 using PseudoTypeInvalidationSetMap = HashMap<CSSSelector::PseudoType, RefPtr
<InvalidationSet>, WTF::IntHash<unsigned>, WTF::UnsignedWithZeroKeyHashTraits<un
signed>>; | 126 using PseudoTypeInvalidationSetMap = HashMap<CSSSelector::PseudoType, RefPtr
<InvalidationSet>, WTF::IntHash<unsigned>, WTF::UnsignedWithZeroKeyHashTraits<un
signed>>; |
127 | 127 |
128 struct FeatureMetadata { | 128 struct FeatureMetadata { |
129 DISALLOW_NEW(); | 129 DISALLOW_NEW(); |
130 void add(const FeatureMetadata& other); | 130 void add(const FeatureMetadata& other); |
(...skipping 14 matching lines...) Expand all Loading... |
145 InvalidationSet& ensurePseudoInvalidationSet(CSSSelector::PseudoType, Invali
dationType); | 145 InvalidationSet& ensurePseudoInvalidationSet(CSSSelector::PseudoType, Invali
dationType); |
146 SiblingInvalidationSet& ensureUniversalSiblingInvalidationSet(); | 146 SiblingInvalidationSet& ensureUniversalSiblingInvalidationSet(); |
147 DescendantInvalidationSet& ensureNthInvalidationSet(); | 147 DescendantInvalidationSet& ensureNthInvalidationSet(); |
148 | 148 |
149 void updateInvalidationSets(const RuleData&); | 149 void updateInvalidationSets(const RuleData&); |
150 void updateInvalidationSetsForContentAttribute(const RuleData&); | 150 void updateInvalidationSetsForContentAttribute(const RuleData&); |
151 | 151 |
152 struct InvalidationSetFeatures { | 152 struct InvalidationSetFeatures { |
153 DISALLOW_NEW(); | 153 DISALLOW_NEW(); |
154 | 154 |
| 155 void add(const InvalidationSetFeatures& other); |
| 156 bool hasFeatures() const; |
| 157 |
155 Vector<AtomicString> classes; | 158 Vector<AtomicString> classes; |
156 Vector<AtomicString> attributes; | 159 Vector<AtomicString> attributes; |
157 Vector<AtomicString> ids; | 160 Vector<AtomicString> ids; |
158 Vector<AtomicString> tagNames; | 161 Vector<AtomicString> tagNames; |
159 unsigned maxDirectAdjacentSelectors = UINT_MAX; | 162 unsigned maxDirectAdjacentSelectors = 0; |
160 bool customPseudoElement = false; | 163 bool customPseudoElement = false; |
161 bool hasBeforeOrAfter = false; | 164 bool hasBeforeOrAfter = false; |
162 bool treeBoundaryCrossing = false; | 165 bool treeBoundaryCrossing = false; |
163 bool adjacent = false; | |
164 bool insertionPointCrossing = false; | 166 bool insertionPointCrossing = false; |
165 bool forceSubtree = false; | 167 bool forceSubtree = false; |
166 bool contentPseudoCrossing = false; | 168 bool contentPseudoCrossing = false; |
167 bool invalidatesSlotted = false; | 169 bool invalidatesSlotted = false; |
168 bool hasNthPseudo = false; | 170 bool hasNthPseudo = false; |
169 }; | 171 }; |
170 | 172 |
171 static bool extractInvalidationSetFeature(const CSSSelector&, InvalidationSe
tFeatures&); | 173 static void extractInvalidationSetFeature(const CSSSelector&, InvalidationSe
tFeatures&); |
172 | 174 |
173 enum UseFeaturesType { UseFeatures, ForceSubtree }; | 175 enum UseFeaturesType { UseFeatures, ForceSubtree }; |
174 | 176 |
175 enum PositionType { Subject, Ancestor }; | 177 enum PositionType { Subject, Ancestor }; |
176 std::pair<const CSSSelector*, UseFeaturesType> extractInvalidationSetFeature
s(const CSSSelector&, InvalidationSetFeatures&, PositionType, CSSSelector::Pseud
oType = CSSSelector::PseudoUnknown); | 178 |
| 179 void extractInvalidationSetFeaturesFromSimpleSelector(const CSSSelector&, In
validationSetFeatures&); |
| 180 const CSSSelector* extractInvalidationSetFeaturesFromCompound(const CSSSelec
tor&, InvalidationSetFeatures&, PositionType, CSSSelector::PseudoType = CSSSelec
tor::PseudoUnknown); |
| 181 const CSSSelector* extractInvalidationSetFeaturesFromSelectorList(const CSSS
elector&, InvalidationSetFeatures&, PositionType); |
| 182 void updateFeaturesFromCombinator(const CSSSelector&, |
| 183 const CSSSelector* lastCompoundSelectorInAdjacentChain, |
| 184 InvalidationSetFeatures& lastCompoundInAdjacentChainFeatures, |
| 185 InvalidationSetFeatures*& siblingFeatures, |
| 186 InvalidationSetFeatures& descendantFeatures); |
177 | 187 |
178 void addFeaturesToInvalidationSet(InvalidationSet&, const InvalidationSetFea
tures&); | 188 void addFeaturesToInvalidationSet(InvalidationSet&, const InvalidationSetFea
tures&); |
179 void addFeaturesToInvalidationSets(const CSSSelector*, InvalidationSetFeatur
es* siblingFeatures, InvalidationSetFeatures& descendantFeatures); | 189 void addFeaturesToInvalidationSets(const CSSSelector&, InvalidationSetFeatur
es& descendantFeatures); |
| 190 const CSSSelector* addFeaturesToInvalidationSetsForCompoundSelector(const CS
SSelector&, InvalidationSetFeatures* siblingFeatures, InvalidationSetFeatures& d
escendantFeatures); |
| 191 void addFeaturesToInvalidationSetsForSimpleSelector(const CSSSelector&, Inva
lidationSetFeatures* siblingFeatures, InvalidationSetFeatures& descendantFeature
s); |
| 192 void addFeaturesToInvalidationSetsForSelectorList(const CSSSelector&, Invali
dationSetFeatures* siblingFeatures, InvalidationSetFeatures& descendantFeatures)
; |
180 void addFeaturesToUniversalSiblingInvalidationSet(const InvalidationSetFeatu
res& siblingFeatures, const InvalidationSetFeatures& descendantFeatures); | 193 void addFeaturesToUniversalSiblingInvalidationSet(const InvalidationSetFeatu
res& siblingFeatures, const InvalidationSetFeatures& descendantFeatures); |
181 | 194 |
182 void addClassToInvalidationSet(const AtomicString& className, Element&); | 195 void addClassToInvalidationSet(const AtomicString& className, Element&); |
183 | 196 |
184 FeatureMetadata m_metadata; | 197 FeatureMetadata m_metadata; |
185 InvalidationSetMap m_classInvalidationSets; | 198 InvalidationSetMap m_classInvalidationSets; |
186 InvalidationSetMap m_attributeInvalidationSets; | 199 InvalidationSetMap m_attributeInvalidationSets; |
187 InvalidationSetMap m_idInvalidationSets; | 200 InvalidationSetMap m_idInvalidationSets; |
188 PseudoTypeInvalidationSetMap m_pseudoInvalidationSets; | 201 PseudoTypeInvalidationSetMap m_pseudoInvalidationSets; |
189 RefPtr<SiblingInvalidationSet> m_universalSiblingInvalidationSet; | 202 RefPtr<SiblingInvalidationSet> m_universalSiblingInvalidationSet; |
190 RefPtr<DescendantInvalidationSet> m_nthInvalidationSet; | 203 RefPtr<DescendantInvalidationSet> m_nthInvalidationSet; |
191 | 204 |
192 // If true, the RuleFeatureSet is alive and can be used. | 205 // If true, the RuleFeatureSet is alive and can be used. |
193 unsigned m_isAlive : 1; | 206 unsigned m_isAlive : 1; |
194 | 207 |
195 friend class RuleFeatureSetTest; | 208 friend class RuleFeatureSetTest; |
196 }; | 209 }; |
197 | 210 |
198 } // namespace blink | 211 } // namespace blink |
199 | 212 |
200 #endif // RuleFeature_h | 213 #endif // RuleFeature_h |
OLD | NEW |