OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All r
ights reserved. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All r
ights reserved. |
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 if (!tagName.isEmpty()) | 115 if (!tagName.isEmpty()) |
116 invalidationSet.addTagName(tagName); | 116 invalidationSet.addTagName(tagName); |
117 for (HashSet<AtomicString>::const_iterator it = classes.begin(); it
!= classes.end(); ++it) { | 117 for (HashSet<AtomicString>::const_iterator it = classes.begin(); it
!= classes.end(); ++it) { |
118 invalidationSet.addClass(*it); | 118 invalidationSet.addClass(*it); |
119 } | 119 } |
120 } | 120 } |
121 } | 121 } |
122 return true; | 122 return true; |
123 } | 123 } |
124 | 124 |
| 125 void RuleFeatureSet::addAttributeInASelector(const AtomicString& attributeName) |
| 126 { |
| 127 m_metadata.attrsInRules.add(attributeName); |
| 128 } |
| 129 |
| 130 |
125 void RuleFeatureSet::collectFeaturesFromRuleData(const RuleData& ruleData) | 131 void RuleFeatureSet::collectFeaturesFromRuleData(const RuleData& ruleData) |
126 { | 132 { |
127 bool foundSiblingSelector = false; | |
128 unsigned maxDirectAdjacentSelectors = 0; | |
129 for (const CSSSelector* selector = ruleData.selector(); selector; selector =
selector->tagHistory()) { | |
130 collectFeaturesFromSelector(selector); | |
131 | 133 |
132 if (const CSSSelectorList* selectorList = selector->selectorList()) { | 134 FeatureMetadata metadata; |
133 for (const CSSSelector* subSelector = selectorList->first(); subSele
ctor; subSelector = CSSSelectorList::next(subSelector)) { | 135 collectFeaturesFromSelector(ruleData.selector(), metadata); |
134 // FIXME: Shouldn't this be checking subSelector->isSiblingSelec
tor()? | 136 m_metadata.add(metadata); |
135 if (!foundSiblingSelector && selector->isSiblingSelector()) | |
136 foundSiblingSelector = true; | |
137 if (subSelector->isDirectAdjacentSelector()) | |
138 maxDirectAdjacentSelectors++; | |
139 collectFeaturesFromSelector(subSelector); | |
140 } | |
141 } else { | |
142 if (!foundSiblingSelector && selector->isSiblingSelector()) | |
143 foundSiblingSelector = true; | |
144 if (selector->isDirectAdjacentSelector()) | |
145 maxDirectAdjacentSelectors++; | |
146 } | |
147 } | |
148 if (RuntimeEnabledFeatures::targetedStyleRecalcEnabled()) { | 137 if (RuntimeEnabledFeatures::targetedStyleRecalcEnabled()) { |
149 bool selectorUsesClassInvalidationSet = updateClassInvalidationSets(rule
Data.selector()); | 138 bool selectorUsesClassInvalidationSet = updateClassInvalidationSets(rule
Data.selector()); |
150 if (!selectorUsesClassInvalidationSet) { | 139 if (!selectorUsesClassInvalidationSet) { |
151 for (HashSet<AtomicString>::const_iterator it = classesInRules.begin
(); it != classesInRules.end(); ++it) { | 140 for (HashSet<AtomicString>::const_iterator it = metadata.classesInRu
les.begin(); it != metadata.classesInRules.end(); ++it) { |
152 DescendantInvalidationSet& invalidationSet = ensureClassInvalida
tionSet(*it); | 141 DescendantInvalidationSet& invalidationSet = ensureClassInvalida
tionSet(*it); |
153 invalidationSet.setWholeSubtreeInvalid(); | 142 invalidationSet.setWholeSubtreeInvalid(); |
154 } | 143 } |
155 } | 144 } |
156 } | 145 } |
157 setMaxDirectAdjacentSelectors(maxDirectAdjacentSelectors); | 146 if (metadata.foundSiblingSelector) |
158 if (foundSiblingSelector) | |
159 siblingRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(
), ruleData.hasDocumentSecurityOrigin())); | 147 siblingRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(
), ruleData.hasDocumentSecurityOrigin())); |
160 if (ruleData.containsUncommonAttributeSelector()) | 148 if (ruleData.containsUncommonAttributeSelector()) |
161 uncommonAttributeRules.append(RuleFeature(ruleData.rule(), ruleData.sele
ctorIndex(), ruleData.hasDocumentSecurityOrigin())); | 149 uncommonAttributeRules.append(RuleFeature(ruleData.rule(), ruleData.sele
ctorIndex(), ruleData.hasDocumentSecurityOrigin())); |
162 } | 150 } |
163 | 151 |
164 DescendantInvalidationSet& RuleFeatureSet::ensureClassInvalidationSet(const Atom
icString& className) | 152 DescendantInvalidationSet& RuleFeatureSet::ensureClassInvalidationSet(const Atom
icString& className) |
165 { | 153 { |
166 InvalidationSetMap::AddResult addResult = m_classInvalidationSets.add(classN
ame, 0); | 154 InvalidationSetMap::AddResult addResult = m_classInvalidationSets.add(classN
ame, 0); |
167 if (addResult.isNewEntry) | 155 if (addResult.isNewEntry) |
168 addResult.iterator->value = DescendantInvalidationSet::create(); | 156 addResult.iterator->value = DescendantInvalidationSet::create(); |
169 return *addResult.iterator->value; | 157 return *addResult.iterator->value; |
170 } | 158 } |
171 | 159 |
172 void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector* selector) | 160 void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector* selector) |
173 { | 161 { |
174 if (selector->m_match == CSSSelector::Id) | 162 collectFeaturesFromSelector(selector, m_metadata); |
175 idsInRules.add(selector->value()); | 163 } |
176 else if (selector->m_match == CSSSelector::Class) | 164 |
177 classesInRules.add(selector->value()); | 165 void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector* selector, Ru
leFeatureSet::FeatureMetadata& metadata) |
178 else if (selector->isAttributeSelector()) | 166 { |
179 attrsInRules.add(selector->attribute().localName()); | 167 for (; selector; selector = selector->tagHistory()) { |
180 switch (selector->pseudoType()) { | 168 if (selector->m_match == CSSSelector::Id) |
181 case CSSSelector::PseudoFirstLine: | 169 metadata.idsInRules.add(selector->value()); |
182 m_usesFirstLineRules = true; | 170 else if (selector->m_match == CSSSelector::Class) |
183 break; | 171 metadata.classesInRules.add(selector->value()); |
184 case CSSSelector::PseudoHost: | 172 else if (selector->isAttributeSelector()) |
185 collectFeaturesFromSelectorList(selector->selectorList()); | 173 metadata.attrsInRules.add(selector->attribute().localName()); |
186 break; | 174 |
187 default: | 175 if (selector->pseudoType() == CSSSelector::PseudoFirstLine) |
188 break; | 176 metadata.usesFirstLineRules = true; |
| 177 if (selector->isDirectAdjacentSelector()) |
| 178 metadata.maxDirectAdjacentSelectors++; |
| 179 if (selector->isSiblingSelector()) |
| 180 metadata.foundSiblingSelector = true; |
| 181 |
| 182 collectFeaturesFromSelectorList(selector->selectorList(), metadata); |
189 } | 183 } |
190 } | 184 } |
191 | 185 |
192 void RuleFeatureSet::collectFeaturesFromSelectorList(const CSSSelectorList* sele
ctorList) | 186 void RuleFeatureSet::collectFeaturesFromSelectorList(const CSSSelectorList* sele
ctorList, RuleFeatureSet::FeatureMetadata& metadata) |
193 { | 187 { |
194 if (!selectorList) | 188 if (!selectorList) |
195 return; | 189 return; |
196 | 190 |
197 for (const CSSSelector* selector = selectorList->first(); selector; selector
= CSSSelectorList::next(selector)) { | 191 for (const CSSSelector* selector = selectorList->first(); selector; selector
= CSSSelectorList::next(selector)) { |
198 for (const CSSSelector* subSelector = selector; subSelector; subSelector
= subSelector->tagHistory()) | 192 for (const CSSSelector* subSelector = selector; subSelector; subSelector
= subSelector->tagHistory()) |
199 collectFeaturesFromSelector(subSelector); | 193 collectFeaturesFromSelector(subSelector, metadata); |
200 } | 194 } |
201 } | 195 } |
202 | 196 |
203 void RuleFeatureSet::add(const RuleFeatureSet& other) | 197 void RuleFeatureSet::FeatureMetadata::add(const FeatureMetadata& other) |
204 { | 198 { |
205 for (InvalidationSetMap::const_iterator it = other.m_classInvalidationSets.b
egin(); it != other.m_classInvalidationSets.end(); ++it) { | 199 usesFirstLineRules = usesFirstLineRules || other.usesFirstLineRules; |
206 ensureClassInvalidationSet(it->key).combine(*it->value); | 200 maxDirectAdjacentSelectors = std::max(maxDirectAdjacentSelectors, other.maxD
irectAdjacentSelectors); |
207 } | |
208 | 201 |
209 HashSet<AtomicString>::const_iterator end = other.idsInRules.end(); | 202 HashSet<AtomicString>::const_iterator end = other.idsInRules.end(); |
210 for (HashSet<AtomicString>::const_iterator it = other.idsInRules.begin(); it
!= end; ++it) | 203 for (HashSet<AtomicString>::const_iterator it = other.idsInRules.begin(); it
!= end; ++it) |
211 idsInRules.add(*it); | 204 idsInRules.add(*it); |
212 end = other.classesInRules.end(); | 205 end = other.classesInRules.end(); |
213 for (HashSet<AtomicString>::const_iterator it = other.classesInRules.begin()
; it != end; ++it) | 206 for (HashSet<AtomicString>::const_iterator it = other.classesInRules.begin()
; it != end; ++it) |
214 classesInRules.add(*it); | 207 classesInRules.add(*it); |
215 end = other.attrsInRules.end(); | 208 end = other.attrsInRules.end(); |
216 for (HashSet<AtomicString>::const_iterator it = other.attrsInRules.begin();
it != end; ++it) | 209 for (HashSet<AtomicString>::const_iterator it = other.attrsInRules.begin();
it != end; ++it) |
217 attrsInRules.add(*it); | 210 attrsInRules.add(*it); |
| 211 } |
| 212 |
| 213 void RuleFeatureSet::FeatureMetadata::clear() |
| 214 { |
| 215 |
| 216 idsInRules.clear(); |
| 217 classesInRules.clear(); |
| 218 attrsInRules.clear(); |
| 219 usesFirstLineRules = false; |
| 220 foundSiblingSelector = false; |
| 221 maxDirectAdjacentSelectors = 0; |
| 222 } |
| 223 |
| 224 void RuleFeatureSet::add(const RuleFeatureSet& other) |
| 225 { |
| 226 for (InvalidationSetMap::const_iterator it = other.m_classInvalidationSets.b
egin(); it != other.m_classInvalidationSets.end(); ++it) { |
| 227 ensureClassInvalidationSet(it->key).combine(*it->value); |
| 228 } |
| 229 |
| 230 m_metadata.add(other.m_metadata); |
| 231 |
218 siblingRules.append(other.siblingRules); | 232 siblingRules.append(other.siblingRules); |
219 uncommonAttributeRules.append(other.uncommonAttributeRules); | 233 uncommonAttributeRules.append(other.uncommonAttributeRules); |
220 m_usesFirstLineRules = m_usesFirstLineRules || other.m_usesFirstLineRules; | |
221 m_maxDirectAdjacentSelectors = std::max(m_maxDirectAdjacentSelectors, other.
maxDirectAdjacentSelectors()); | |
222 } | 234 } |
223 | 235 |
224 void RuleFeatureSet::clear() | 236 void RuleFeatureSet::clear() |
225 { | 237 { |
226 idsInRules.clear(); | 238 m_metadata.clear(); |
227 classesInRules.clear(); | |
228 attrsInRules.clear(); | |
229 siblingRules.clear(); | 239 siblingRules.clear(); |
230 uncommonAttributeRules.clear(); | 240 uncommonAttributeRules.clear(); |
231 m_usesFirstLineRules = false; | |
232 m_maxDirectAdjacentSelectors = 0; | |
233 } | 241 } |
234 | 242 |
235 } // namespace WebCore | 243 } // namespace WebCore |
OLD | NEW |