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, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
14 * | 14 * |
15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
19 * | 19 * |
20 */ | 20 */ |
21 | 21 |
22 #ifndef RuleFeature_h | 22 #ifndef RuleFeature_h |
23 #define RuleFeature_h | 23 #define RuleFeature_h |
24 | 24 |
| 25 #include "core/css/CSSSelector.h" |
25 #include "core/css/invalidation/DescendantInvalidationSet.h" | 26 #include "core/css/invalidation/DescendantInvalidationSet.h" |
26 #include "core/css/invalidation/StyleInvalidator.h" | 27 #include "core/css/invalidation/StyleInvalidator.h" |
27 #include "wtf/Forward.h" | 28 #include "wtf/Forward.h" |
28 #include "wtf/HashSet.h" | 29 #include "wtf/HashSet.h" |
29 #include "wtf/text/AtomicStringHash.h" | 30 #include "wtf/text/AtomicStringHash.h" |
30 | 31 |
31 namespace WebCore { | 32 namespace WebCore { |
32 | 33 |
33 class CSSSelector; | |
34 class CSSSelectorList; | 34 class CSSSelectorList; |
35 class Document; | 35 class Document; |
36 class Node; | 36 class Node; |
37 class QualifiedName; | 37 class QualifiedName; |
38 class RuleData; | 38 class RuleData; |
39 class ShadowRoot; | 39 class ShadowRoot; |
40 class SpaceSplitString; | 40 class SpaceSplitString; |
41 class StyleRule; | 41 class StyleRule; |
42 | 42 |
43 struct RuleFeature { | 43 struct RuleFeature { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 return m_classInvalidationSets.contains(classValue); | 80 return m_classInvalidationSets.contains(classValue); |
81 } | 81 } |
82 | 82 |
83 inline bool hasSelectorForId(const AtomicString& idValue) const | 83 inline bool hasSelectorForId(const AtomicString& idValue) const |
84 { | 84 { |
85 return m_idInvalidationSets.contains(idValue); | 85 return m_idInvalidationSets.contains(idValue); |
86 } | 86 } |
87 | 87 |
88 void scheduleStyleInvalidationForClassChange(const SpaceSplitString& changed
Classes, Element&); | 88 void scheduleStyleInvalidationForClassChange(const SpaceSplitString& changed
Classes, Element&); |
89 void scheduleStyleInvalidationForClassChange(const SpaceSplitString& oldClas
ses, const SpaceSplitString& newClasses, Element&); | 89 void scheduleStyleInvalidationForClassChange(const SpaceSplitString& oldClas
ses, const SpaceSplitString& newClasses, Element&); |
90 | |
91 void scheduleStyleInvalidationForAttributeChange(const QualifiedName& attrib
uteName, Element&); | 90 void scheduleStyleInvalidationForAttributeChange(const QualifiedName& attrib
uteName, Element&); |
92 | |
93 void scheduleStyleInvalidationForIdChange(const AtomicString& oldId, const A
tomicString& newId, Element&); | 91 void scheduleStyleInvalidationForIdChange(const AtomicString& oldId, const A
tomicString& newId, Element&); |
| 92 void scheduleStyleInvalidationForPseudoChange(CSSSelector::PseudoType, Eleme
nt&); |
94 | 93 |
95 bool hasIdsInSelectors() const | 94 bool hasIdsInSelectors() const |
96 { | 95 { |
97 return m_idInvalidationSets.size() > 0; | 96 return m_idInvalidationSets.size() > 0; |
98 } | 97 } |
99 | 98 |
100 // Marks the given attribute name as "appearing in a selector". Used for | 99 // Marks the given attribute name as "appearing in a selector". Used for |
101 // CSS properties such as content: ... attr(...) ... | 100 // CSS properties such as content: ... attr(...) ... |
102 // FIXME: record these internally to this class instead calls from StyleReso
lver to here. | 101 // FIXME: record these internally to this class instead calls from StyleReso
lver to here. |
103 void addContentAttr(const AtomicString& attributeName); | 102 void addContentAttr(const AtomicString& attributeName); |
104 | 103 |
105 StyleInvalidator& styleInvalidator(); | 104 StyleInvalidator& styleInvalidator(); |
106 | 105 |
107 Vector<RuleFeature> siblingRules; | 106 Vector<RuleFeature> siblingRules; |
108 Vector<RuleFeature> uncommonAttributeRules; | 107 Vector<RuleFeature> uncommonAttributeRules; |
109 | 108 |
110 private: | 109 private: |
111 typedef HashMap<AtomicString, RefPtr<DescendantInvalidationSet> > Invalidati
onSetMap; | 110 typedef HashMap<AtomicString, RefPtr<DescendantInvalidationSet> > Invalidati
onSetMap; |
| 111 typedef HashMap<CSSSelector::PseudoType, RefPtr<DescendantInvalidationSet>,
WTF::IntHash<unsigned>, WTF::UnsignedWithZeroKeyHashTraits<unsigned> > PseudoTyp
eInvalidationSetMap; |
112 | 112 |
113 struct FeatureMetadata { | 113 struct FeatureMetadata { |
114 FeatureMetadata() | 114 FeatureMetadata() |
115 : usesFirstLineRules(false) | 115 : usesFirstLineRules(false) |
116 , foundSiblingSelector(false) | 116 , foundSiblingSelector(false) |
117 , maxDirectAdjacentSelectors(0) | 117 , maxDirectAdjacentSelectors(0) |
118 { } | 118 { } |
119 void add(const FeatureMetadata& other); | 119 void add(const FeatureMetadata& other); |
120 void clear(); | 120 void clear(); |
121 | 121 |
122 bool usesFirstLineRules; | 122 bool usesFirstLineRules; |
123 bool foundSiblingSelector; | 123 bool foundSiblingSelector; |
124 unsigned maxDirectAdjacentSelectors; | 124 unsigned maxDirectAdjacentSelectors; |
125 }; | 125 }; |
126 | 126 |
127 enum InvalidationSetMode { | 127 enum InvalidationSetMode { |
128 AddFeatures, | 128 AddFeatures, |
129 UseLocalStyleChange, | 129 UseLocalStyleChange, |
130 UseSubtreeStyleChange | 130 UseSubtreeStyleChange |
131 }; | 131 }; |
132 | 132 |
133 static InvalidationSetMode invalidationSetModeForSelector(const CSSSelector&
); | 133 static InvalidationSetMode invalidationSetModeForSelector(const CSSSelector&
); |
134 | 134 |
135 void collectFeaturesFromSelector(const CSSSelector&, FeatureMetadata&, Inval
idationSetMode); | 135 void collectFeaturesFromSelector(const CSSSelector&, FeatureMetadata&, Inval
idationSetMode, bool seenCombinator); |
136 void collectFeaturesFromSelectorList(const CSSSelectorList*, FeatureMetadata
&, InvalidationSetMode); | 136 void collectFeaturesFromSelectorList(const CSSSelectorList*, FeatureMetadata
&, InvalidationSetMode, bool seenCombinator); |
137 | 137 |
138 DescendantInvalidationSet& ensureClassInvalidationSet(const AtomicString& cl
assName); | 138 DescendantInvalidationSet& ensureClassInvalidationSet(const AtomicString& cl
assName); |
139 DescendantInvalidationSet& ensureAttributeInvalidationSet(const AtomicString
& attributeName); | 139 DescendantInvalidationSet& ensureAttributeInvalidationSet(const AtomicString
& attributeName); |
140 DescendantInvalidationSet& ensureIdInvalidationSet(const AtomicString& attri
buteName); | 140 DescendantInvalidationSet& ensureIdInvalidationSet(const AtomicString& attri
buteName); |
141 DescendantInvalidationSet* invalidationSetForSelector(const CSSSelector&); | 141 DescendantInvalidationSet& ensurePseudoInvalidationSet(CSSSelector::PseudoTy
pe); |
| 142 DescendantInvalidationSet* invalidationSetForSelector(const CSSSelector&, bo
ol seenCombinator); |
142 | 143 |
143 InvalidationSetMode updateInvalidationSets(const CSSSelector&); | 144 InvalidationSetMode updateInvalidationSets(const CSSSelector&); |
144 | 145 |
145 struct InvalidationSetFeatures { | 146 struct InvalidationSetFeatures { |
146 InvalidationSetFeatures() : customPseudoElement(false) { } | 147 InvalidationSetFeatures() : customPseudoElement(false) { } |
147 Vector<AtomicString> classes; | 148 Vector<AtomicString> classes; |
148 Vector<AtomicString> attributes; | 149 Vector<AtomicString> attributes; |
149 AtomicString id; | 150 AtomicString id; |
150 AtomicString tagName; | 151 AtomicString tagName; |
151 bool customPseudoElement; | 152 bool customPseudoElement; |
152 }; | 153 }; |
153 | 154 |
154 static void extractInvalidationSetFeature(const CSSSelector&, InvalidationSe
tFeatures&); | 155 static void extractInvalidationSetFeature(const CSSSelector&, InvalidationSe
tFeatures&); |
155 const CSSSelector* extractInvalidationSetFeatures(const CSSSelector&, Invali
dationSetFeatures&); | 156 const CSSSelector* extractInvalidationSetFeatures(const CSSSelector&, Invali
dationSetFeatures&); |
156 void addFeaturesToInvalidationSets(const CSSSelector&, const InvalidationSet
Features&, bool wholeSubtree); | 157 void addFeaturesToInvalidationSets(const CSSSelector&, const InvalidationSet
Features&, bool wholeSubtree); |
157 | 158 |
158 void addClassToInvalidationSet(const AtomicString& className, Element&); | 159 void addClassToInvalidationSet(const AtomicString& className, Element&); |
159 | 160 |
160 FeatureMetadata m_metadata; | 161 FeatureMetadata m_metadata; |
161 InvalidationSetMap m_classInvalidationSets; | 162 InvalidationSetMap m_classInvalidationSets; |
162 InvalidationSetMap m_attributeInvalidationSets; | 163 InvalidationSetMap m_attributeInvalidationSets; |
163 InvalidationSetMap m_idInvalidationSets; | 164 InvalidationSetMap m_idInvalidationSets; |
| 165 PseudoTypeInvalidationSetMap m_pseudoInvalidationSets; |
164 bool m_targetedStyleRecalcEnabled; | 166 bool m_targetedStyleRecalcEnabled; |
165 StyleInvalidator m_styleInvalidator; | 167 StyleInvalidator m_styleInvalidator; |
166 }; | 168 }; |
167 | 169 |
168 | 170 |
169 } // namespace WebCore | 171 } // namespace WebCore |
170 | 172 |
171 #endif // RuleFeature_h | 173 #endif // RuleFeature_h |
OLD | NEW |