Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: Source/core/css/RuleFeature.cpp

Issue 220123004: Add support for element ids in TargetedStyleRecalc (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix comment. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 102 }
103 } 103 }
104 104
105 // This method is somewhat conservative in what it accepts. 105 // This method is somewhat conservative in what it accepts.
106 RuleFeatureSet::InvalidationSetMode RuleFeatureSet::supportsClassDescendantInval idation(const CSSSelector& selector) 106 RuleFeatureSet::InvalidationSetMode RuleFeatureSet::supportsClassDescendantInval idation(const CSSSelector& selector)
107 { 107 {
108 bool foundDescendantRelation = false; 108 bool foundDescendantRelation = false;
109 bool foundIdent = false; 109 bool foundIdent = false;
110 for (const CSSSelector* component = &selector; component; component = compon ent->tagHistory()) { 110 for (const CSSSelector* component = &selector; component; component = compon ent->tagHistory()) {
111 111
112 // FIXME: next up: Tag and Id. 112 // FIXME: next up: Tag.
113 if (component->m_match == CSSSelector::Class || component->isAttributeSe lector()) { 113 if (component->m_match == CSSSelector::Class || component->m_match == CS SSelector::Id || component->isAttributeSelector()) {
114 if (!foundDescendantRelation) 114 if (!foundDescendantRelation)
115 foundIdent = true; 115 foundIdent = true;
116 } else if (component->pseudoType() == CSSSelector::PseudoHost || compone nt->pseudoType() == CSSSelector::PseudoAny) { 116 } else if (component->pseudoType() == CSSSelector::PseudoHost || compone nt->pseudoType() == CSSSelector::PseudoAny) {
117 if (const CSSSelectorList* selectorList = component->selectorList()) { 117 if (const CSSSelectorList* selectorList = component->selectorList()) {
118 for (const CSSSelector* selector = selectorList->first(); select or; selector = CSSSelectorList::next(*selector)) { 118 for (const CSSSelector* selector = selectorList->first(); select or; selector = CSSSelectorList::next(*selector)) {
119 InvalidationSetMode hostMode = supportsClassDescendantInvali dation(*selector); 119 InvalidationSetMode hostMode = supportsClassDescendantInvali dation(*selector);
120 if (hostMode == UseSubtreeStyleChange) 120 if (hostMode == UseSubtreeStyleChange)
121 return foundDescendantRelation ? UseLocalStyleChange : U seSubtreeStyleChange; 121 return foundDescendantRelation ? UseLocalStyleChange : U seSubtreeStyleChange;
122 if (hostMode == AddFeatures) 122 if (hostMode == AddFeatures)
123 foundIdent = true; 123 foundIdent = true;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 : m_targetedStyleRecalcEnabled(RuntimeEnabledFeatures::targetedStyleRecalcEn abled()) 158 : m_targetedStyleRecalcEnabled(RuntimeEnabledFeatures::targetedStyleRecalcEn abled())
159 { 159 {
160 } 160 }
161 161
162 DescendantInvalidationSet* RuleFeatureSet::invalidationSetForSelector(const CSSS elector& selector) 162 DescendantInvalidationSet* RuleFeatureSet::invalidationSetForSelector(const CSSS elector& selector)
163 { 163 {
164 if (selector.m_match == CSSSelector::Class) 164 if (selector.m_match == CSSSelector::Class)
165 return &ensureClassInvalidationSet(selector.value()); 165 return &ensureClassInvalidationSet(selector.value());
166 if (selector.isAttributeSelector()) 166 if (selector.isAttributeSelector())
167 return &ensureAttributeInvalidationSet(selector.attribute().localName()) ; 167 return &ensureAttributeInvalidationSet(selector.attribute().localName()) ;
168 if (selector.m_match == CSSSelector::Id)
169 return &ensureIdInvalidationSet(selector.value());
168 return 0; 170 return 0;
169 } 171 }
170 172
171 RuleFeatureSet::InvalidationSetMode RuleFeatureSet::updateInvalidationSets(const CSSSelector& selector) 173 RuleFeatureSet::InvalidationSetMode RuleFeatureSet::updateInvalidationSets(const CSSSelector& selector)
172 { 174 {
173 InvalidationSetMode mode = supportsClassDescendantInvalidation(selector); 175 InvalidationSetMode mode = supportsClassDescendantInvalidation(selector);
174 if (mode != AddFeatures) 176 if (mode != AddFeatures)
175 return mode; 177 return mode;
176 178
177 InvalidationSetFeatures features; 179 InvalidationSetFeatures features;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 return *addResult.storedValue->value; 257 return *addResult.storedValue->value;
256 } 258 }
257 259
258 DescendantInvalidationSet& RuleFeatureSet::ensureAttributeInvalidationSet(const AtomicString& attributeName) 260 DescendantInvalidationSet& RuleFeatureSet::ensureAttributeInvalidationSet(const AtomicString& attributeName)
259 { 261 {
260 InvalidationSetMap::AddResult addResult = m_attributeInvalidationSets.add(at tributeName, nullptr); 262 InvalidationSetMap::AddResult addResult = m_attributeInvalidationSets.add(at tributeName, nullptr);
261 if (addResult.isNewEntry) 263 if (addResult.isNewEntry)
262 addResult.storedValue->value = DescendantInvalidationSet::create(); 264 addResult.storedValue->value = DescendantInvalidationSet::create();
263 return *addResult.storedValue->value; 265 return *addResult.storedValue->value;
264 } 266 }
267
268 DescendantInvalidationSet& RuleFeatureSet::ensureIdInvalidationSet(const AtomicS tring& id)
269 {
270 InvalidationSetMap::AddResult addResult = m_idInvalidationSets.add(id, nullp tr);
271 if (addResult.isNewEntry)
272 addResult.storedValue->value = DescendantInvalidationSet::create();
273 return *addResult.storedValue->value;
274 }
275
265 void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector& selector) 276 void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector& selector)
266 { 277 {
267 collectFeaturesFromSelector(selector, m_metadata, UseSubtreeStyleChange); 278 collectFeaturesFromSelector(selector, m_metadata, UseSubtreeStyleChange);
268 } 279 }
269 280
270 void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector& selector, Ru leFeatureSet::FeatureMetadata& metadata, InvalidationSetMode mode) 281 void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector& selector, Ru leFeatureSet::FeatureMetadata& metadata, InvalidationSetMode mode)
271 { 282 {
272 unsigned maxDirectAdjacentSelectors = 0; 283 unsigned maxDirectAdjacentSelectors = 0;
273 284
274 for (const CSSSelector* current = &selector; current; current = current->tag History()) { 285 for (const CSSSelector* current = &selector; current; current = current->tag History()) {
275 if (current->m_match == CSSSelector::Id) { 286 if (mode != AddFeatures && (current->m_match == CSSSelector::Class || cu rrent->m_match == CSSSelector::Id || current->isAttributeSelector())) {
276 metadata.idsInRules.add(current->value());
277 } else if (mode != AddFeatures && (current->m_match == CSSSelector::Clas s || current->isAttributeSelector())) {
278 DescendantInvalidationSet* invalidationSet = invalidationSetForSelec tor(*current); 287 DescendantInvalidationSet* invalidationSet = invalidationSetForSelec tor(*current);
279 ASSERT(invalidationSet); 288 ASSERT(invalidationSet);
280 if (mode == UseSubtreeStyleChange) 289 if (mode == UseSubtreeStyleChange)
281 invalidationSet->setWholeSubtreeInvalid(); 290 invalidationSet->setWholeSubtreeInvalid();
282 } 291 }
283 if (current->pseudoType() == CSSSelector::PseudoFirstLine) 292 if (current->pseudoType() == CSSSelector::PseudoFirstLine)
284 metadata.usesFirstLineRules = true; 293 metadata.usesFirstLineRules = true;
285 if (current->isDirectAdjacentSelector()) { 294 if (current->isDirectAdjacentSelector()) {
286 maxDirectAdjacentSelectors++; 295 maxDirectAdjacentSelectors++;
287 } else if (maxDirectAdjacentSelectors) { 296 } else if (maxDirectAdjacentSelectors) {
(...skipping 19 matching lines...) Expand all
307 return; 316 return;
308 317
309 for (const CSSSelector* selector = selectorList->first(); selector; selector = CSSSelectorList::next(*selector)) 318 for (const CSSSelector* selector = selectorList->first(); selector; selector = CSSSelectorList::next(*selector))
310 collectFeaturesFromSelector(*selector, metadata, mode); 319 collectFeaturesFromSelector(*selector, metadata, mode);
311 } 320 }
312 321
313 void RuleFeatureSet::FeatureMetadata::add(const FeatureMetadata& other) 322 void RuleFeatureSet::FeatureMetadata::add(const FeatureMetadata& other)
314 { 323 {
315 usesFirstLineRules = usesFirstLineRules || other.usesFirstLineRules; 324 usesFirstLineRules = usesFirstLineRules || other.usesFirstLineRules;
316 maxDirectAdjacentSelectors = std::max(maxDirectAdjacentSelectors, other.maxD irectAdjacentSelectors); 325 maxDirectAdjacentSelectors = std::max(maxDirectAdjacentSelectors, other.maxD irectAdjacentSelectors);
317
318 HashSet<AtomicString>::const_iterator end = other.idsInRules.end();
319 for (HashSet<AtomicString>::const_iterator it = other.idsInRules.begin(); it != end; ++it)
320 idsInRules.add(*it);
321 } 326 }
322 327
323 void RuleFeatureSet::FeatureMetadata::clear() 328 void RuleFeatureSet::FeatureMetadata::clear()
324 { 329 {
325 idsInRules.clear();
326 usesFirstLineRules = false; 330 usesFirstLineRules = false;
327 foundSiblingSelector = false; 331 foundSiblingSelector = false;
328 maxDirectAdjacentSelectors = 0; 332 maxDirectAdjacentSelectors = 0;
329 } 333 }
330 334
331 void RuleFeatureSet::add(const RuleFeatureSet& other) 335 void RuleFeatureSet::add(const RuleFeatureSet& other)
332 { 336 {
333 for (InvalidationSetMap::const_iterator it = other.m_classInvalidationSets.b egin(); it != other.m_classInvalidationSets.end(); ++it) 337 for (InvalidationSetMap::const_iterator it = other.m_classInvalidationSets.b egin(); it != other.m_classInvalidationSets.end(); ++it)
334 ensureClassInvalidationSet(it->key).combine(*it->value); 338 ensureClassInvalidationSet(it->key).combine(*it->value);
335 for (InvalidationSetMap::const_iterator it = other.m_attributeInvalidationSe ts.begin(); it != other.m_attributeInvalidationSets.end(); ++it) 339 for (InvalidationSetMap::const_iterator it = other.m_attributeInvalidationSe ts.begin(); it != other.m_attributeInvalidationSets.end(); ++it)
336 ensureAttributeInvalidationSet(it->key).combine(*it->value); 340 ensureAttributeInvalidationSet(it->key).combine(*it->value);
341 for (InvalidationSetMap::const_iterator it = other.m_idInvalidationSets.begi n(); it != other.m_idInvalidationSets.end(); ++it)
342 ensureIdInvalidationSet(it->key).combine(*it->value);
337 343
338 m_metadata.add(other.m_metadata); 344 m_metadata.add(other.m_metadata);
339 345
340 siblingRules.appendVector(other.siblingRules); 346 siblingRules.appendVector(other.siblingRules);
341 uncommonAttributeRules.appendVector(other.uncommonAttributeRules); 347 uncommonAttributeRules.appendVector(other.uncommonAttributeRules);
342 } 348 }
343 349
344 void RuleFeatureSet::clear() 350 void RuleFeatureSet::clear()
345 { 351 {
346 siblingRules.clear(); 352 siblingRules.clear();
347 uncommonAttributeRules.clear(); 353 uncommonAttributeRules.clear();
348 m_metadata.clear(); 354 m_metadata.clear();
349 m_classInvalidationSets.clear(); 355 m_classInvalidationSets.clear();
350 m_attributeInvalidationSets.clear(); 356 m_attributeInvalidationSets.clear();
357 m_idInvalidationSets.clear();
351 m_styleInvalidator.clearPendingInvalidations(); 358 m_styleInvalidator.clearPendingInvalidations();
352 } 359 }
353 360
354 void RuleFeatureSet::scheduleStyleInvalidationForClassChange(const SpaceSplitStr ing& changedClasses, Element& element) 361 void RuleFeatureSet::scheduleStyleInvalidationForClassChange(const SpaceSplitStr ing& changedClasses, Element& element)
355 { 362 {
356 unsigned changedSize = changedClasses.size(); 363 unsigned changedSize = changedClasses.size();
357 for (unsigned i = 0; i < changedSize; ++i) { 364 for (unsigned i = 0; i < changedSize; ++i) {
358 addClassToInvalidationSet(changedClasses[i], element); 365 addClassToInvalidationSet(changedClasses[i], element);
359 } 366 }
360 } 367 }
(...skipping 30 matching lines...) Expand all
391 addClassToInvalidationSet(oldClasses[i], element); 398 addClassToInvalidationSet(oldClasses[i], element);
392 } 399 }
393 } 400 }
394 401
395 void RuleFeatureSet::scheduleStyleInvalidationForAttributeChange(const Qualified Name& attributeName, Element& element) 402 void RuleFeatureSet::scheduleStyleInvalidationForAttributeChange(const Qualified Name& attributeName, Element& element)
396 { 403 {
397 if (RefPtr<DescendantInvalidationSet> invalidationSet = m_attributeInvalidat ionSets.get(attributeName.localName())) 404 if (RefPtr<DescendantInvalidationSet> invalidationSet = m_attributeInvalidat ionSets.get(attributeName.localName()))
398 m_styleInvalidator.scheduleInvalidation(invalidationSet, element); 405 m_styleInvalidator.scheduleInvalidation(invalidationSet, element);
399 } 406 }
400 407
408 void RuleFeatureSet::scheduleStyleInvalidationForIdChange(const AtomicString& ol dId, const AtomicString& newId, Element& element)
409 {
410 if (!oldId.isEmpty()) {
411 if (RefPtr<DescendantInvalidationSet> invalidationSet = m_idInvalidation Sets.get(oldId))
412 m_styleInvalidator.scheduleInvalidation(invalidationSet, element);
413 }
414 if (!newId.isEmpty()) {
415 if (RefPtr<DescendantInvalidationSet> invalidationSet = m_idInvalidation Sets.get(newId))
416 m_styleInvalidator.scheduleInvalidation(invalidationSet, element);
417 }
418 }
419
401 void RuleFeatureSet::addClassToInvalidationSet(const AtomicString& className, El ement& element) 420 void RuleFeatureSet::addClassToInvalidationSet(const AtomicString& className, El ement& element)
402 { 421 {
403 if (RefPtr<DescendantInvalidationSet> invalidationSet = m_classInvalidationS ets.get(className)) 422 if (RefPtr<DescendantInvalidationSet> invalidationSet = m_classInvalidationS ets.get(className))
404 m_styleInvalidator.scheduleInvalidation(invalidationSet, element); 423 m_styleInvalidator.scheduleInvalidation(invalidationSet, element);
405 } 424 }
406 425
407 StyleInvalidator& RuleFeatureSet::styleInvalidator() 426 StyleInvalidator& RuleFeatureSet::styleInvalidator()
408 { 427 {
409 return m_styleInvalidator; 428 return m_styleInvalidator;
410 } 429 }
411 430
412 } // namespace WebCore 431 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698