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

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: Adjust test. 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
« no previous file with comments | « Source/core/css/RuleFeature.h ('k') | Source/core/css/invalidation/DescendantInvalidationSet.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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() || component->isCustomPseudoElement()) { 113 if (component->m_match == CSSSelector::Class || component->m_match == CS SSelector::Id || component->isAttributeSelector() || component->isCustomPseudoEl ement()) {
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 : m_targetedStyleRecalcEnabled(RuntimeEnabledFeatures::targetedStyleRecalcEn abled()) 160 : m_targetedStyleRecalcEnabled(RuntimeEnabledFeatures::targetedStyleRecalcEn abled())
161 { 161 {
162 } 162 }
163 163
164 DescendantInvalidationSet* RuleFeatureSet::invalidationSetForSelector(const CSSS elector& selector) 164 DescendantInvalidationSet* RuleFeatureSet::invalidationSetForSelector(const CSSS elector& selector)
165 { 165 {
166 if (selector.m_match == CSSSelector::Class) 166 if (selector.m_match == CSSSelector::Class)
167 return &ensureClassInvalidationSet(selector.value()); 167 return &ensureClassInvalidationSet(selector.value());
168 if (selector.isAttributeSelector()) 168 if (selector.isAttributeSelector())
169 return &ensureAttributeInvalidationSet(selector.attribute().localName()) ; 169 return &ensureAttributeInvalidationSet(selector.attribute().localName()) ;
170 if (selector.m_match == CSSSelector::Id)
171 return &ensureIdInvalidationSet(selector.value());
170 return 0; 172 return 0;
171 } 173 }
172 174
173 RuleFeatureSet::InvalidationSetMode RuleFeatureSet::updateInvalidationSets(const CSSSelector& selector) 175 RuleFeatureSet::InvalidationSetMode RuleFeatureSet::updateInvalidationSets(const CSSSelector& selector)
174 { 176 {
175 InvalidationSetMode mode = supportsClassDescendantInvalidation(selector); 177 InvalidationSetMode mode = supportsClassDescendantInvalidation(selector);
176 if (mode != AddFeatures) 178 if (mode != AddFeatures)
177 return mode; 179 return mode;
178 180
179 InvalidationSetFeatures features; 181 InvalidationSetFeatures features;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 return *addResult.storedValue->value; 261 return *addResult.storedValue->value;
260 } 262 }
261 263
262 DescendantInvalidationSet& RuleFeatureSet::ensureAttributeInvalidationSet(const AtomicString& attributeName) 264 DescendantInvalidationSet& RuleFeatureSet::ensureAttributeInvalidationSet(const AtomicString& attributeName)
263 { 265 {
264 InvalidationSetMap::AddResult addResult = m_attributeInvalidationSets.add(at tributeName, nullptr); 266 InvalidationSetMap::AddResult addResult = m_attributeInvalidationSets.add(at tributeName, nullptr);
265 if (addResult.isNewEntry) 267 if (addResult.isNewEntry)
266 addResult.storedValue->value = DescendantInvalidationSet::create(); 268 addResult.storedValue->value = DescendantInvalidationSet::create();
267 return *addResult.storedValue->value; 269 return *addResult.storedValue->value;
268 } 270 }
271
272 DescendantInvalidationSet& RuleFeatureSet::ensureIdInvalidationSet(const AtomicS tring& id)
273 {
274 InvalidationSetMap::AddResult addResult = m_idInvalidationSets.add(id, nullp tr);
275 if (addResult.isNewEntry)
276 addResult.storedValue->value = DescendantInvalidationSet::create();
277 return *addResult.storedValue->value;
278 }
279
269 void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector& selector) 280 void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector& selector)
270 { 281 {
271 collectFeaturesFromSelector(selector, m_metadata, UseSubtreeStyleChange); 282 collectFeaturesFromSelector(selector, m_metadata, UseSubtreeStyleChange);
272 } 283 }
273 284
274 void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector& selector, Ru leFeatureSet::FeatureMetadata& metadata, InvalidationSetMode mode) 285 void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector& selector, Ru leFeatureSet::FeatureMetadata& metadata, InvalidationSetMode mode)
275 { 286 {
276 unsigned maxDirectAdjacentSelectors = 0; 287 unsigned maxDirectAdjacentSelectors = 0;
277 288
278 for (const CSSSelector* current = &selector; current; current = current->tag History()) { 289 for (const CSSSelector* current = &selector; current; current = current->tag History()) {
279 if (current->m_match == CSSSelector::Id) { 290 if (mode != AddFeatures && (current->m_match == CSSSelector::Class || cu rrent->m_match == CSSSelector::Id || current->isAttributeSelector())) {
280 metadata.idsInRules.add(current->value());
281 } else if (mode != AddFeatures && (current->m_match == CSSSelector::Clas s || current->isAttributeSelector())) {
282 DescendantInvalidationSet* invalidationSet = invalidationSetForSelec tor(*current); 291 DescendantInvalidationSet* invalidationSet = invalidationSetForSelec tor(*current);
283 ASSERT(invalidationSet); 292 ASSERT(invalidationSet);
284 if (mode == UseSubtreeStyleChange) 293 if (mode == UseSubtreeStyleChange)
285 invalidationSet->setWholeSubtreeInvalid(); 294 invalidationSet->setWholeSubtreeInvalid();
286 } 295 }
287 if (current->pseudoType() == CSSSelector::PseudoFirstLine) 296 if (current->pseudoType() == CSSSelector::PseudoFirstLine)
288 metadata.usesFirstLineRules = true; 297 metadata.usesFirstLineRules = true;
289 if (current->isDirectAdjacentSelector()) { 298 if (current->isDirectAdjacentSelector()) {
290 maxDirectAdjacentSelectors++; 299 maxDirectAdjacentSelectors++;
291 } else if (maxDirectAdjacentSelectors) { 300 } else if (maxDirectAdjacentSelectors) {
(...skipping 19 matching lines...) Expand all
311 return; 320 return;
312 321
313 for (const CSSSelector* selector = selectorList->first(); selector; selector = CSSSelectorList::next(*selector)) 322 for (const CSSSelector* selector = selectorList->first(); selector; selector = CSSSelectorList::next(*selector))
314 collectFeaturesFromSelector(*selector, metadata, mode); 323 collectFeaturesFromSelector(*selector, metadata, mode);
315 } 324 }
316 325
317 void RuleFeatureSet::FeatureMetadata::add(const FeatureMetadata& other) 326 void RuleFeatureSet::FeatureMetadata::add(const FeatureMetadata& other)
318 { 327 {
319 usesFirstLineRules = usesFirstLineRules || other.usesFirstLineRules; 328 usesFirstLineRules = usesFirstLineRules || other.usesFirstLineRules;
320 maxDirectAdjacentSelectors = std::max(maxDirectAdjacentSelectors, other.maxD irectAdjacentSelectors); 329 maxDirectAdjacentSelectors = std::max(maxDirectAdjacentSelectors, other.maxD irectAdjacentSelectors);
321
322 HashSet<AtomicString>::const_iterator end = other.idsInRules.end();
323 for (HashSet<AtomicString>::const_iterator it = other.idsInRules.begin(); it != end; ++it)
324 idsInRules.add(*it);
325 } 330 }
326 331
327 void RuleFeatureSet::FeatureMetadata::clear() 332 void RuleFeatureSet::FeatureMetadata::clear()
328 { 333 {
329 idsInRules.clear();
330 usesFirstLineRules = false; 334 usesFirstLineRules = false;
331 foundSiblingSelector = false; 335 foundSiblingSelector = false;
332 maxDirectAdjacentSelectors = 0; 336 maxDirectAdjacentSelectors = 0;
333 } 337 }
334 338
335 void RuleFeatureSet::add(const RuleFeatureSet& other) 339 void RuleFeatureSet::add(const RuleFeatureSet& other)
336 { 340 {
337 for (InvalidationSetMap::const_iterator it = other.m_classInvalidationSets.b egin(); it != other.m_classInvalidationSets.end(); ++it) 341 for (InvalidationSetMap::const_iterator it = other.m_classInvalidationSets.b egin(); it != other.m_classInvalidationSets.end(); ++it)
338 ensureClassInvalidationSet(it->key).combine(*it->value); 342 ensureClassInvalidationSet(it->key).combine(*it->value);
339 for (InvalidationSetMap::const_iterator it = other.m_attributeInvalidationSe ts.begin(); it != other.m_attributeInvalidationSets.end(); ++it) 343 for (InvalidationSetMap::const_iterator it = other.m_attributeInvalidationSe ts.begin(); it != other.m_attributeInvalidationSets.end(); ++it)
340 ensureAttributeInvalidationSet(it->key).combine(*it->value); 344 ensureAttributeInvalidationSet(it->key).combine(*it->value);
345 for (InvalidationSetMap::const_iterator it = other.m_idInvalidationSets.begi n(); it != other.m_idInvalidationSets.end(); ++it)
346 ensureIdInvalidationSet(it->key).combine(*it->value);
341 347
342 m_metadata.add(other.m_metadata); 348 m_metadata.add(other.m_metadata);
343 349
344 siblingRules.appendVector(other.siblingRules); 350 siblingRules.appendVector(other.siblingRules);
345 uncommonAttributeRules.appendVector(other.uncommonAttributeRules); 351 uncommonAttributeRules.appendVector(other.uncommonAttributeRules);
346 } 352 }
347 353
348 void RuleFeatureSet::clear() 354 void RuleFeatureSet::clear()
349 { 355 {
350 siblingRules.clear(); 356 siblingRules.clear();
351 uncommonAttributeRules.clear(); 357 uncommonAttributeRules.clear();
352 m_metadata.clear(); 358 m_metadata.clear();
353 m_classInvalidationSets.clear(); 359 m_classInvalidationSets.clear();
354 m_attributeInvalidationSets.clear(); 360 m_attributeInvalidationSets.clear();
361 m_idInvalidationSets.clear();
355 m_styleInvalidator.clearPendingInvalidations(); 362 m_styleInvalidator.clearPendingInvalidations();
356 } 363 }
357 364
358 void RuleFeatureSet::scheduleStyleInvalidationForClassChange(const SpaceSplitStr ing& changedClasses, Element& element) 365 void RuleFeatureSet::scheduleStyleInvalidationForClassChange(const SpaceSplitStr ing& changedClasses, Element& element)
359 { 366 {
360 unsigned changedSize = changedClasses.size(); 367 unsigned changedSize = changedClasses.size();
361 for (unsigned i = 0; i < changedSize; ++i) { 368 for (unsigned i = 0; i < changedSize; ++i) {
362 addClassToInvalidationSet(changedClasses[i], element); 369 addClassToInvalidationSet(changedClasses[i], element);
363 } 370 }
364 } 371 }
(...skipping 30 matching lines...) Expand all
395 addClassToInvalidationSet(oldClasses[i], element); 402 addClassToInvalidationSet(oldClasses[i], element);
396 } 403 }
397 } 404 }
398 405
399 void RuleFeatureSet::scheduleStyleInvalidationForAttributeChange(const Qualified Name& attributeName, Element& element) 406 void RuleFeatureSet::scheduleStyleInvalidationForAttributeChange(const Qualified Name& attributeName, Element& element)
400 { 407 {
401 if (RefPtr<DescendantInvalidationSet> invalidationSet = m_attributeInvalidat ionSets.get(attributeName.localName())) 408 if (RefPtr<DescendantInvalidationSet> invalidationSet = m_attributeInvalidat ionSets.get(attributeName.localName()))
402 m_styleInvalidator.scheduleInvalidation(invalidationSet, element); 409 m_styleInvalidator.scheduleInvalidation(invalidationSet, element);
403 } 410 }
404 411
412 void RuleFeatureSet::scheduleStyleInvalidationForIdChange(const AtomicString& ol dId, const AtomicString& newId, Element& element)
413 {
414 if (!oldId.isEmpty()) {
415 if (RefPtr<DescendantInvalidationSet> invalidationSet = m_idInvalidation Sets.get(oldId))
416 m_styleInvalidator.scheduleInvalidation(invalidationSet, element);
417 }
418 if (!newId.isEmpty()) {
419 if (RefPtr<DescendantInvalidationSet> invalidationSet = m_idInvalidation Sets.get(newId))
420 m_styleInvalidator.scheduleInvalidation(invalidationSet, element);
421 }
422 }
423
405 void RuleFeatureSet::addClassToInvalidationSet(const AtomicString& className, El ement& element) 424 void RuleFeatureSet::addClassToInvalidationSet(const AtomicString& className, El ement& element)
406 { 425 {
407 if (RefPtr<DescendantInvalidationSet> invalidationSet = m_classInvalidationS ets.get(className)) 426 if (RefPtr<DescendantInvalidationSet> invalidationSet = m_classInvalidationS ets.get(className))
408 m_styleInvalidator.scheduleInvalidation(invalidationSet, element); 427 m_styleInvalidator.scheduleInvalidation(invalidationSet, element);
409 } 428 }
410 429
411 StyleInvalidator& RuleFeatureSet::styleInvalidator() 430 StyleInvalidator& RuleFeatureSet::styleInvalidator()
412 { 431 {
413 return m_styleInvalidator; 432 return m_styleInvalidator;
414 } 433 }
415 434
416 } // namespace WebCore 435 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/RuleFeature.h ('k') | Source/core/css/invalidation/DescendantInvalidationSet.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698