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/CoreExport.h" | 25 #include "core/CoreExport.h" |
26 #include "core/css/CSSSelector.h" | 26 #include "core/css/CSSSelector.h" |
27 #include "core/css/invalidation/InvalidationSet.h" | 27 #include "core/css/invalidation/InvalidationData.h" |
28 #include "wtf/Forward.h" | 28 #include "wtf/Forward.h" |
29 #include "wtf/HashSet.h" | 29 #include "wtf/HashSet.h" |
30 #include "wtf/text/AtomicStringHash.h" | 30 #include "wtf/text/AtomicStringHash.h" |
31 | 31 |
32 namespace blink { | 32 namespace blink { |
33 | 33 |
34 struct InvalidationLists; | |
34 class QualifiedName; | 35 class QualifiedName; |
35 class RuleData; | 36 class RuleData; |
36 class SpaceSplitString; | 37 class SpaceSplitString; |
37 class StyleRule; | 38 class StyleRule; |
38 | 39 |
39 struct RuleFeature { | 40 struct RuleFeature { |
40 ALLOW_ONLY_INLINE_ALLOCATION(); | 41 ALLOW_ONLY_INLINE_ALLOCATION(); |
41 public: | 42 public: |
42 RuleFeature(StyleRule*, unsigned selectorIndex, bool hasDocumentSecurityOrig in); | 43 RuleFeature(StyleRule*, unsigned selectorIndex, bool hasDocumentSecurityOrig in); |
43 | 44 |
44 DECLARE_TRACE(); | 45 DECLARE_TRACE(); |
45 | 46 |
46 RawPtrWillBeMember<StyleRule> rule; | 47 RawPtrWillBeMember<StyleRule> rule; |
47 unsigned selectorIndex; | 48 unsigned selectorIndex; |
48 bool hasDocumentSecurityOrigin; | 49 bool hasDocumentSecurityOrigin; |
49 }; | 50 }; |
50 | 51 |
51 using InvalidationSetVector = WillBeHeapVector<RefPtrWillBeMember<InvalidationSe t>, 8>; | |
52 | |
53 class CORE_EXPORT RuleFeatureSet { | 52 class CORE_EXPORT RuleFeatureSet { |
54 DISALLOW_ALLOCATION(); | 53 DISALLOW_ALLOCATION(); |
55 public: | 54 public: |
56 RuleFeatureSet(); | 55 RuleFeatureSet(); |
57 ~RuleFeatureSet(); | 56 ~RuleFeatureSet(); |
58 | 57 |
59 void add(const RuleFeatureSet&); | 58 void add(const RuleFeatureSet&); |
60 void clear(); | 59 void clear(); |
61 | 60 |
62 void collectFeaturesFromRuleData(const RuleData&); | 61 void collectFeaturesFromRuleData(const RuleData&); |
63 | 62 |
64 bool usesSiblingRules() const { return !siblingRules.isEmpty(); } | 63 bool usesSiblingRules() const { return !siblingRules.isEmpty(); } |
65 bool usesFirstLineRules() const { return m_metadata.usesFirstLineRules; } | 64 bool usesFirstLineRules() const { return m_metadata.usesFirstLineRules; } |
66 bool usesWindowInactiveSelector() const { return m_metadata.usesWindowInacti veSelector; } | 65 bool usesWindowInactiveSelector() const { return m_metadata.usesWindowInacti veSelector; } |
67 | 66 |
68 unsigned maxDirectAdjacentSelectors() const { return m_metadata.maxDirectAdj acentSelectors; } | 67 unsigned maxDirectAdjacentSelectors() const { return m_metadata.maxDirectAdj acentSelectors; } |
69 void setMaxDirectAdjacentSelectors(unsigned value) { m_metadata.maxDirectAd jacentSelectors = std::max(value, m_metadata.maxDirectAdjacentSelectors); } | |
70 | 68 |
71 bool hasSelectorForAttribute(const AtomicString& attributeName) const | 69 bool hasSelectorForAttribute(const AtomicString& attributeName) const |
72 { | 70 { |
73 ASSERT(!attributeName.isEmpty()); | 71 ASSERT(!attributeName.isEmpty()); |
74 return m_attributeInvalidationSets.contains(attributeName); | 72 return m_attributeInvalidationSets.contains(attributeName); |
75 } | 73 } |
76 | 74 |
77 bool hasSelectorForClass(const AtomicString& classValue) const | 75 bool hasSelectorForClass(const AtomicString& classValue) const |
78 { | 76 { |
79 ASSERT(!classValue.isEmpty()); | 77 ASSERT(!classValue.isEmpty()); |
80 return m_classInvalidationSets.contains(classValue); | 78 return m_classInvalidationSets.contains(classValue); |
81 } | 79 } |
82 | 80 |
83 bool hasSelectorForId(const AtomicString& idValue) const { return m_idInvali dationSets.contains(idValue); } | 81 bool hasSelectorForId(const AtomicString& idValue) const { return m_idInvali dationSets.contains(idValue); } |
84 | 82 |
85 void collectInvalidationSetsForClass(InvalidationSetVector&, Element&, const AtomicString& className) const; | 83 // Collect descendant and sibling invalidation sets. |
86 void collectInvalidationSetsForId(InvalidationSetVector&, Element&, const At omicString& id) const; | 84 void collectInvalidationSetsForClass(InvalidationLists&, Element&, const Ato micString& className) const; |
87 void collectInvalidationSetsForAttribute(InvalidationSetVector&, Element&, c onst QualifiedName& attributeName) const; | 85 void collectInvalidationSetsForId(InvalidationLists&, Element&, const Atomic String& id) const; |
88 void collectInvalidationSetsForPseudoClass(InvalidationSetVector&, Element&, CSSSelector::PseudoType) const; | 86 void collectInvalidationSetsForAttribute(InvalidationLists&, Element&, const QualifiedName& attributeName) const; |
87 void collectInvalidationSetsForPseudoClass(InvalidationLists&, Element&, CSS Selector::PseudoType) const; | |
89 | 88 |
90 bool hasIdsInSelectors() const | 89 bool hasIdsInSelectors() const |
91 { | 90 { |
92 return m_idInvalidationSets.size() > 0; | 91 return m_idInvalidationSets.size() > 0; |
93 } | 92 } |
94 | 93 |
95 DECLARE_TRACE(); | 94 DECLARE_TRACE(); |
96 | 95 |
97 WillBeHeapVector<RuleFeature> siblingRules; | 96 WillBeHeapVector<RuleFeature> siblingRules; |
98 WillBeHeapVector<RuleFeature> uncommonAttributeRules; | 97 WillBeHeapVector<RuleFeature> uncommonAttributeRules; |
99 | 98 |
100 protected: | 99 protected: |
101 InvalidationSet* invalidationSetForSelector(const CSSSelector&); | 100 InvalidationSet* invalidationSetForSelector(const CSSSelector&, Invalidation Type); |
102 | 101 |
103 private: | 102 private: |
104 using InvalidationSetMap = WillBeHeapHashMap<AtomicString, RefPtrWillBeMembe r<InvalidationSet>>; | 103 using InvalidationSetMap = WillBeHeapHashMap<AtomicString, RefPtrWillBeMembe r<InvalidationData>>; |
105 using PseudoTypeInvalidationSetMap = WillBeHeapHashMap<CSSSelector::PseudoTy pe, RefPtrWillBeMember<InvalidationSet>, WTF::IntHash<unsigned>, WTF::UnsignedWi thZeroKeyHashTraits<unsigned>>; | 104 using PseudoTypeInvalidationSetMap = WillBeHeapHashMap<CSSSelector::PseudoTy pe, RefPtrWillBeMember<InvalidationData>, WTF::IntHash<unsigned>, WTF::UnsignedW ithZeroKeyHashTraits<unsigned>>; |
106 | 105 |
107 struct FeatureMetadata { | 106 struct FeatureMetadata { |
108 DISALLOW_ALLOCATION(); | 107 DISALLOW_ALLOCATION(); |
109 FeatureMetadata() | 108 FeatureMetadata() |
110 : usesFirstLineRules(false) | 109 : usesFirstLineRules(false) |
111 , usesWindowInactiveSelector(false) | 110 , usesWindowInactiveSelector(false) |
112 , foundSiblingSelector(false) | 111 , foundSiblingSelector(false) |
113 , maxDirectAdjacentSelectors(0) | 112 , maxDirectAdjacentSelectors(0) |
114 { } | 113 { } |
115 void add(const FeatureMetadata& other); | 114 void add(const FeatureMetadata& other); |
116 void clear(); | 115 void clear(); |
117 | 116 |
118 bool usesFirstLineRules; | 117 bool usesFirstLineRules; |
119 bool usesWindowInactiveSelector; | 118 bool usesWindowInactiveSelector; |
120 bool foundSiblingSelector; | 119 bool foundSiblingSelector; |
121 unsigned maxDirectAdjacentSelectors; | 120 unsigned maxDirectAdjacentSelectors; |
122 }; | 121 }; |
123 | 122 |
124 void collectFeaturesFromSelector(const CSSSelector&, FeatureMetadata&); | 123 void collectFeaturesFromSelector(const CSSSelector&, FeatureMetadata&); |
125 | 124 |
126 InvalidationSet& ensureClassInvalidationSet(const AtomicString& className); | 125 template<class Map> |
127 InvalidationSet& ensureAttributeInvalidationSet(const AtomicString& attribut eName); | 126 static InvalidationData& ensureInvalidationData(Map&, const typename Map::Ke yType&); |
128 InvalidationSet& ensureIdInvalidationSet(const AtomicString& attributeName); | 127 |
129 InvalidationSet& ensurePseudoInvalidationSet(CSSSelector::PseudoType); | 128 InvalidationData& ensureClassInvalidationData(const AtomicString& className) { return ensureInvalidationData(m_classInvalidationSets, className); } |
129 InvalidationData& ensureAttributeInvalidationData(const AtomicString& attrib uteName) { return ensureInvalidationData(m_attributeInvalidationSets, attributeN ame); } | |
130 InvalidationData& ensureIdInvalidationData(const AtomicString& id) { return ensureInvalidationData(m_idInvalidationSets, id); } | |
131 InvalidationData& ensurePseudoInvalidationData(CSSSelector::PseudoType pseud oType) { return ensureInvalidationData(m_pseudoInvalidationSets, pseudoType); } | |
132 | |
133 InvalidationSet& ensureClassInvalidationSet(const AtomicString& className, I nvalidationType type) { return ensureClassInvalidationData(className).ensureInva lidationSet(type); } | |
134 InvalidationSet& ensureAttributeInvalidationSet(const AtomicString& attribut eName, InvalidationType type) { return ensureAttributeInvalidationData(attribute Name).ensureInvalidationSet(type); } | |
135 InvalidationSet& ensureIdInvalidationSet(const AtomicString& id, Invalidatio nType type) { return ensureIdInvalidationData(id).ensureInvalidationSet(type); } | |
136 InvalidationSet& ensurePseudoInvalidationSet(CSSSelector::PseudoType pseudoT ype, InvalidationType type) { return ensurePseudoInvalidationData(pseudoType).en sureInvalidationSet(type); } | |
130 | 137 |
131 void updateInvalidationSets(const RuleData&); | 138 void updateInvalidationSets(const RuleData&); |
132 void updateInvalidationSetsForContentAttribute(const RuleData&); | 139 void updateInvalidationSetsForContentAttribute(const RuleData&); |
133 | 140 |
134 struct InvalidationSetFeatures { | 141 struct InvalidationSetFeatures { |
135 DISALLOW_ALLOCATION(); | 142 DISALLOW_ALLOCATION(); |
136 InvalidationSetFeatures() | 143 InvalidationSetFeatures() |
137 : customPseudoElement(false) | 144 : maxDirectAdjacentSelectors(std::numeric_limits<unsigned>::max()) |
145 , customPseudoElement(false) | |
138 , hasBeforeOrAfter(false) | 146 , hasBeforeOrAfter(false) |
139 , treeBoundaryCrossing(false) | 147 , treeBoundaryCrossing(false) |
140 , adjacent(false) | 148 , adjacent(false) |
141 , insertionPointCrossing(false) | 149 , insertionPointCrossing(false) |
142 , forceSubtree(false) | 150 , forceSubtree(false) |
143 { } | 151 { } |
144 | 152 |
145 bool useSubtreeInvalidation() const { return forceSubtree || adjacent; } | |
146 | |
147 Vector<AtomicString> classes; | 153 Vector<AtomicString> classes; |
148 Vector<AtomicString> attributes; | 154 Vector<AtomicString> attributes; |
149 AtomicString id; | 155 AtomicString id; |
150 AtomicString tagName; | 156 AtomicString tagName; |
157 unsigned maxDirectAdjacentSelectors; | |
151 bool customPseudoElement; | 158 bool customPseudoElement; |
152 bool hasBeforeOrAfter; | 159 bool hasBeforeOrAfter; |
153 bool treeBoundaryCrossing; | 160 bool treeBoundaryCrossing; |
154 bool adjacent; | 161 bool adjacent; |
155 bool insertionPointCrossing; | 162 bool insertionPointCrossing; |
156 bool forceSubtree; | 163 bool forceSubtree; |
157 }; | 164 }; |
158 | 165 |
159 static bool extractInvalidationSetFeature(const CSSSelector&, InvalidationSe tFeatures&); | 166 static bool extractInvalidationSetFeature(const CSSSelector&, InvalidationSe tFeatures&); |
160 | 167 |
161 enum UseFeaturesType { UseFeatures, ForceSubtree }; | 168 enum UseFeaturesType { UseFeatures, ForceSubtree }; |
162 | 169 |
163 std::pair<const CSSSelector*, UseFeaturesType> extractInvalidationSetFeature s(const CSSSelector&, InvalidationSetFeatures&, bool negated); | 170 std::pair<const CSSSelector*, UseFeaturesType> extractInvalidationSetFeature s(const CSSSelector&, InvalidationSetFeatures&, bool negated); |
164 | 171 |
165 void addFeaturesToInvalidationSet(InvalidationSet&, const InvalidationSetFea tures&); | 172 void addFeaturesToInvalidationSet(InvalidationSet&, const InvalidationSetFea tures&); |
166 void addFeaturesToInvalidationSets(const CSSSelector&, InvalidationSetFeatur es&); | 173 void addFeaturesToInvalidationSets(const CSSSelector*, InvalidationSetFeatur es*, InvalidationSetFeatures&); |
rune
2015/10/02 13:17:58
You should name the two InvalidationSetFeatures pa
Eric Willigers
2015/10/14 00:25:40
Done.
| |
167 | 174 |
168 void addClassToInvalidationSet(const AtomicString& className, Element&); | 175 void addClassToInvalidationSet(const AtomicString& className, Element&); |
169 | 176 |
170 FeatureMetadata m_metadata; | 177 FeatureMetadata m_metadata; |
171 InvalidationSetMap m_classInvalidationSets; | 178 InvalidationSetMap m_classInvalidationSets; |
172 InvalidationSetMap m_attributeInvalidationSets; | 179 InvalidationSetMap m_attributeInvalidationSets; |
173 InvalidationSetMap m_idInvalidationSets; | 180 InvalidationSetMap m_idInvalidationSets; |
174 PseudoTypeInvalidationSetMap m_pseudoInvalidationSets; | 181 PseudoTypeInvalidationSetMap m_pseudoInvalidationSets; |
182 | |
183 friend class RuleFeatureSetTest; | |
175 }; | 184 }; |
176 | 185 |
186 template<class Map> | |
187 InvalidationData& RuleFeatureSet::ensureInvalidationData(Map& map, const typenam e Map::KeyType& key) | |
rune
2015/10/02 13:17:58
This method does not need to be a member of RuleFe
Eric Willigers
2015/10/14 00:25:40
Done.
| |
188 { | |
189 typename Map::AddResult addResult = map.add(key, nullptr); | |
190 if (addResult.isNewEntry) | |
191 addResult.storedValue->value = InvalidationData::create(); | |
192 return *addResult.storedValue->value; | |
193 } | |
194 | |
177 } // namespace blink | 195 } // namespace blink |
178 | 196 |
179 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::RuleFeature); | 197 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::RuleFeature); |
180 | 198 |
181 #endif // RuleFeature_h | 199 #endif // RuleFeature_h |
OLD | NEW |