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 11 matching lines...) Expand all Loading... |
22 #ifndef RuleFeature_h | 22 #ifndef RuleFeature_h |
23 #define RuleFeature_h | 23 #define RuleFeature_h |
24 | 24 |
25 #include "core/css/analyzer/DescendantInvalidationSet.h" | 25 #include "core/css/analyzer/DescendantInvalidationSet.h" |
26 #include "wtf/Forward.h" | 26 #include "wtf/Forward.h" |
27 #include "wtf/HashSet.h" | 27 #include "wtf/HashSet.h" |
28 #include "wtf/text/AtomicStringHash.h" | 28 #include "wtf/text/AtomicStringHash.h" |
29 | 29 |
30 namespace WebCore { | 30 namespace WebCore { |
31 | 31 |
| 32 class CSSSelector; |
| 33 class CSSSelectorList; |
32 class Document; | 34 class Document; |
33 class Node; | 35 class Node; |
| 36 class QualifiedName; |
| 37 class RuleData; |
34 class ShadowRoot; | 38 class ShadowRoot; |
| 39 class SpaceSplitString; |
35 class StyleRule; | 40 class StyleRule; |
36 class CSSSelector; | |
37 class CSSSelectorList; | |
38 class RuleData; | |
39 class SpaceSplitString; | |
40 | 41 |
41 struct RuleFeature { | 42 struct RuleFeature { |
42 RuleFeature(StyleRule* rule, unsigned selectorIndex, bool hasDocumentSecurit
yOrigin) | 43 RuleFeature(StyleRule* rule, unsigned selectorIndex, bool hasDocumentSecurit
yOrigin) |
43 : rule(rule) | 44 : rule(rule) |
44 , selectorIndex(selectorIndex) | 45 , selectorIndex(selectorIndex) |
45 , hasDocumentSecurityOrigin(hasDocumentSecurityOrigin) | 46 , hasDocumentSecurityOrigin(hasDocumentSecurityOrigin) |
46 { | 47 { |
47 } | 48 } |
48 StyleRule* rule; | 49 StyleRule* rule; |
49 unsigned selectorIndex; | 50 unsigned selectorIndex; |
(...skipping 12 matching lines...) Expand all Loading... |
62 | 63 |
63 bool usesSiblingRules() const { return !siblingRules.isEmpty(); } | 64 bool usesSiblingRules() const { return !siblingRules.isEmpty(); } |
64 bool usesFirstLineRules() const { return m_metadata.usesFirstLineRules; } | 65 bool usesFirstLineRules() const { return m_metadata.usesFirstLineRules; } |
65 | 66 |
66 unsigned maxDirectAdjacentSelectors() const { return m_metadata.maxDirectAdj
acentSelectors; } | 67 unsigned maxDirectAdjacentSelectors() const { return m_metadata.maxDirectAdj
acentSelectors; } |
67 void setMaxDirectAdjacentSelectors(unsigned value) { m_metadata.maxDirectAd
jacentSelectors = std::max(value, m_metadata.maxDirectAdjacentSelectors); } | 68 void setMaxDirectAdjacentSelectors(unsigned value) { m_metadata.maxDirectAd
jacentSelectors = std::max(value, m_metadata.maxDirectAdjacentSelectors); } |
68 | 69 |
69 inline bool hasSelectorForAttribute(const AtomicString& attributeName) const | 70 inline bool hasSelectorForAttribute(const AtomicString& attributeName) const |
70 { | 71 { |
71 ASSERT(!attributeName.isEmpty()); | 72 ASSERT(!attributeName.isEmpty()); |
72 return m_metadata.attrsInRules.contains(attributeName); | 73 return m_attributeInvalidationSets.get(attributeName); |
73 } | 74 } |
74 | 75 |
75 inline bool hasSelectorForClass(const AtomicString& classValue) const | 76 inline bool hasSelectorForClass(const AtomicString& classValue) const |
76 { | 77 { |
77 ASSERT(!classValue.isEmpty()); | 78 ASSERT(!classValue.isEmpty()); |
78 return m_classInvalidationSets.get(classValue); | 79 return m_classInvalidationSets.get(classValue); |
79 } | 80 } |
80 | 81 |
81 inline bool hasSelectorForId(const AtomicString& idValue) const | 82 inline bool hasSelectorForId(const AtomicString& idValue) const |
82 { | 83 { |
83 return m_metadata.idsInRules.contains(idValue); | 84 return m_metadata.idsInRules.contains(idValue); |
84 } | 85 } |
85 | 86 |
86 void scheduleStyleInvalidationForClassChange(const SpaceSplitString& changed
Classes, Element*); | 87 void scheduleStyleInvalidationForClassChange(const SpaceSplitString& changed
Classes, Element*); |
87 void scheduleStyleInvalidationForClassChange(const SpaceSplitString& oldClas
ses, const SpaceSplitString& newClasses, Element*); | 88 void scheduleStyleInvalidationForClassChange(const SpaceSplitString& oldClas
ses, const SpaceSplitString& newClasses, Element*); |
88 | 89 |
| 90 void scheduleStyleInvalidationForAttributeChange(const QualifiedName& attrib
uteName, Element*); |
| 91 |
89 // Clears all style invalidation state for the passed node. | 92 // Clears all style invalidation state for the passed node. |
90 void clearStyleInvalidation(Node*); | 93 void clearStyleInvalidation(Node*); |
91 | 94 |
92 int hasIdsInSelectors() const | 95 int hasIdsInSelectors() const |
93 { | 96 { |
94 return m_metadata.idsInRules.size() > 0; | 97 return m_metadata.idsInRules.size() > 0; |
95 } | 98 } |
96 | 99 |
97 // Marks the given attribute name as "appearing in a selector". Used for | 100 // Marks the given attribute name as "appearing in a selector". Used for |
98 // CSS properties such as content: ... attr(...) ... | 101 // CSS properties such as content: ... attr(...) ... |
99 void addAttributeInASelector(const AtomicString& attributeName); | 102 // FIXME: record these internally to this class instead calls from StyleReso
lver to here. |
| 103 void addAttributeFromAContentAttrValue(const AtomicString& attributeName); |
100 | 104 |
101 Vector<RuleFeature> siblingRules; | 105 Vector<RuleFeature> siblingRules; |
102 Vector<RuleFeature> uncommonAttributeRules; | 106 Vector<RuleFeature> uncommonAttributeRules; |
103 | 107 |
104 typedef Vector<RefPtr<DescendantInvalidationSet> > InvalidationList; | 108 typedef Vector<RefPtr<DescendantInvalidationSet> > InvalidationList; |
105 typedef HashMap<Element*, OwnPtr<InvalidationList> > PendingInvalidationMap; | 109 typedef HashMap<Element*, OwnPtr<InvalidationList> > PendingInvalidationMap; |
106 | 110 |
107 PendingInvalidationMap& pendingInvalidationMap(); | 111 PendingInvalidationMap& pendingInvalidationMap(); |
108 | 112 |
109 private: | 113 private: |
110 typedef HashMap<AtomicString, RefPtr<DescendantInvalidationSet> > Invalidati
onSetMap; | 114 typedef HashMap<AtomicString, RefPtr<DescendantInvalidationSet> > Invalidati
onSetMap; |
111 | 115 |
112 struct FeatureMetadata { | 116 struct FeatureMetadata { |
113 FeatureMetadata() | 117 FeatureMetadata() |
114 : usesFirstLineRules(false) | 118 : usesFirstLineRules(false) |
115 , foundSiblingSelector(false) | 119 , foundSiblingSelector(false) |
116 , maxDirectAdjacentSelectors(0) | 120 , maxDirectAdjacentSelectors(0) |
117 { } | 121 { } |
118 void add(const FeatureMetadata& other); | 122 void add(const FeatureMetadata& other); |
119 void clear(); | 123 void clear(); |
120 | 124 |
121 bool usesFirstLineRules; | 125 bool usesFirstLineRules; |
122 bool foundSiblingSelector; | 126 bool foundSiblingSelector; |
123 unsigned maxDirectAdjacentSelectors; | 127 unsigned maxDirectAdjacentSelectors; |
124 HashSet<AtomicString> idsInRules; | 128 HashSet<AtomicString> idsInRules; |
125 HashSet<AtomicString> attrsInRules; | |
126 }; | 129 }; |
127 | 130 |
128 enum InvalidationSetMode { | 131 enum InvalidationSetMode { |
129 AddFeatures, | 132 AddFeatures, |
130 UseLocalStyleChange, | 133 UseLocalStyleChange, |
131 UseSubtreeStyleChange | 134 UseSubtreeStyleChange |
132 }; | 135 }; |
133 | 136 |
134 static InvalidationSetMode supportsClassDescendantInvalidation(const CSSSele
ctor&); | 137 static InvalidationSetMode supportsClassDescendantInvalidation(const CSSSele
ctor&); |
135 | 138 |
136 void collectFeaturesFromSelector(const CSSSelector&, FeatureMetadata&, Inval
idationSetMode); | 139 void collectFeaturesFromSelector(const CSSSelector&, FeatureMetadata&, Inval
idationSetMode); |
137 void collectFeaturesFromSelectorList(const CSSSelectorList*, FeatureMetadata
&, InvalidationSetMode); | 140 void collectFeaturesFromSelectorList(const CSSSelectorList*, FeatureMetadata
&, InvalidationSetMode); |
138 | 141 |
139 DescendantInvalidationSet& ensureClassInvalidationSet(const AtomicString& cl
assName); | 142 DescendantInvalidationSet& ensureClassInvalidationSet(const AtomicString& cl
assName); |
140 InvalidationSetMode updateClassInvalidationSets(const CSSSelector&); | 143 DescendantInvalidationSet& ensureAttributeInvalidationSet(const AtomicString
& className); |
| 144 DescendantInvalidationSet* invalidationSetForSelector(const CSSSelector&); |
| 145 |
| 146 InvalidationSetMode updateInvalidationSets(const CSSSelector&); |
141 | 147 |
142 void addClassToInvalidationSet(const AtomicString& className, Element*); | 148 void addClassToInvalidationSet(const AtomicString& className, Element*); |
143 | 149 |
144 InvalidationList& ensurePendingInvalidationList(Element*); | 150 InvalidationList& ensurePendingInvalidationList(Element*); |
145 | 151 |
146 FeatureMetadata m_metadata; | 152 FeatureMetadata m_metadata; |
147 InvalidationSetMap m_classInvalidationSets; | 153 InvalidationSetMap m_classInvalidationSets; |
| 154 InvalidationSetMap m_attributeInvalidationSets; |
| 155 |
148 PendingInvalidationMap m_pendingInvalidationMap; | 156 PendingInvalidationMap m_pendingInvalidationMap; |
149 | 157 |
150 bool m_targetedStyleRecalcEnabled; | 158 bool m_targetedStyleRecalcEnabled; |
151 }; | 159 }; |
152 | 160 |
153 | 161 |
154 } // namespace WebCore | 162 } // namespace WebCore |
155 | 163 |
156 #endif // RuleFeature_h | 164 #endif // RuleFeature_h |
OLD | NEW |