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

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

Issue 1913833002: Current work-in-progress crbug.com/567021 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More assert fixes Created 4 years, 6 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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 // to the invalidation sets for the features found in the other compound selecto rs 361 // to the invalidation sets for the features found in the other compound selecto rs
362 // (addFeaturesToInvalidationSets). If we find a feature in the right-most compo und 362 // (addFeaturesToInvalidationSets). If we find a feature in the right-most compo und
363 // selector that requires a subtree recalc, we addFeaturesToInvalidationSets for the 363 // selector that requires a subtree recalc, we addFeaturesToInvalidationSets for the
364 // rightmost compound selector as well. 364 // rightmost compound selector as well.
365 365
366 void RuleFeatureSet::updateInvalidationSets(const RuleData& ruleData) 366 void RuleFeatureSet::updateInvalidationSets(const RuleData& ruleData)
367 { 367 {
368 InvalidationSetFeatures features; 368 InvalidationSetFeatures features;
369 auto result = extractInvalidationSetFeatures(ruleData.selector(), features, Subject); 369 auto result = extractInvalidationSetFeatures(ruleData.selector(), features, Subject);
370 370
371 if (result.first) { 371 if (result.second == ForceSubtree) {
372 features.forceSubtree = result.second == ForceSubtree; 372 features.forceSubtree = true;
373 features.containsIdClassAttributeOrTypeInScope = false;
374 }
375
376 if (result.first)
373 addFeaturesToInvalidationSets(result.first, features.adjacent ? &feature s : nullptr, features); 377 addFeaturesToInvalidationSets(result.first, features.adjacent ? &feature s : nullptr, features);
374 } 378
379 if (!features.containsIdClassAttributeOrTypeInScope)
380 m_metadata.needsFullRecalcForRuleSetInvalidation = true;
375 381
376 // If any ::before and ::after rules specify 'content: attr(...)', we 382 // If any ::before and ::after rules specify 'content: attr(...)', we
377 // need to create invalidation sets for those attributes. 383 // need to create invalidation sets for those attributes.
378 if (features.hasBeforeOrAfter) 384 if (features.hasBeforeOrAfter)
379 updateInvalidationSetsForContentAttribute(ruleData); 385 updateInvalidationSetsForContentAttribute(ruleData);
380 } 386 }
381 387
382 void RuleFeatureSet::updateInvalidationSetsForContentAttribute(const RuleData& r uleData) 388 void RuleFeatureSet::updateInvalidationSetsForContentAttribute(const RuleData& r uleData)
383 { 389 {
384 const StylePropertySet& propertySet = ruleData.rule()->properties(); 390 const StylePropertySet& propertySet = ruleData.rule()->properties();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 } 448 }
443 allSubSelectorsHaveFeatures &= result.second == UseFeatures; 449 allSubSelectorsHaveFeatures &= result.second == UseFeatures;
444 } 450 }
445 foundFeatures |= allSubSelectorsHaveFeatures; 451 foundFeatures |= allSubSelectorsHaveFeatures;
446 } 452 }
447 } 453 }
448 454
449 if (current->relation() == CSSSelector::SubSelector) 455 if (current->relation() == CSSSelector::SubSelector)
450 continue; 456 continue;
451 457
452 features.treeBoundaryCrossing = current->isShadowSelector(); 458 features.containsIdClassAttributeOrTypeInScope |= foundFeatures;
459 if (current->isShadowSelector()) {
460 features.treeBoundaryCrossing = true;
461 features.containsIdClassAttributeOrTypeInScope = false;
462 }
453 if (current->relationIsAffectedByPseudoContent()) { 463 if (current->relationIsAffectedByPseudoContent()) {
454 features.contentPseudoCrossing = true; 464 features.contentPseudoCrossing = true;
455 features.insertionPointCrossing = true; 465 features.insertionPointCrossing = true;
466 features.containsIdClassAttributeOrTypeInScope = false;
456 } 467 }
468
457 features.adjacent = current->isAdjacentSelector(); 469 features.adjacent = current->isAdjacentSelector();
458 if (current->relation() == CSSSelector::DirectAdjacent) 470 if (current->relation() == CSSSelector::DirectAdjacent)
459 features.maxDirectAdjacentSelectors = 1; 471 features.maxDirectAdjacentSelectors = 1;
460 return std::make_pair(current->tagHistory(), foundFeatures ? UseFeatures : ForceSubtree); 472 return std::make_pair(current->tagHistory(), foundFeatures ? UseFeatures : ForceSubtree);
461 } 473 }
462 return std::make_pair(nullptr, foundFeatures ? UseFeatures : ForceSubtree); 474 features.containsIdClassAttributeOrTypeInScope |= foundFeatures;
475 return std::make_pair(nullptr, foundFeatures ? UseFeatures : ForceSubtree);
463 } 476 }
464 477
465 // Add features extracted from the rightmost compound selector to descendant inv alidation 478 // Add features extracted from the rightmost compound selector to descendant inv alidation
466 // sets for features found in other compound selectors. 479 // sets for features found in other compound selectors.
467 // 480 //
468 // We use descendant invalidation for descendants, sibling invalidation for sibl ings and their subtrees. 481 // We use descendant invalidation for descendants, sibling invalidation for sibl ings and their subtrees.
469 // 482 //
470 // As we encounter a descendant type of combinator, the features only need to be checked 483 // As we encounter a descendant type of combinator, the features only need to be checked
471 // against descendants in the same subtree only. features.adjacent is set to fal se, and 484 // against descendants in the same subtree only. features.adjacent is set to fal se, and
472 // we start adding features to the descendant invalidation set. 485 // we start adding features to the descendant invalidation set.
(...skipping 29 matching lines...) Expand all
502 void RuleFeatureSet::addFeaturesToInvalidationSets(const CSSSelector* selector, InvalidationSetFeatures* siblingFeatures, InvalidationSetFeatures& descendantFea tures) 515 void RuleFeatureSet::addFeaturesToInvalidationSets(const CSSSelector* selector, InvalidationSetFeatures* siblingFeatures, InvalidationSetFeatures& descendantFea tures)
503 { 516 {
504 const CSSSelector* lastCompoundSelectorInAdjacentChain = selector; 517 const CSSSelector* lastCompoundSelectorInAdjacentChain = selector;
505 518
506 // We set siblingFeatures to &localFeatures if we find a rightmost sibling c ombinator. 519 // We set siblingFeatures to &localFeatures if we find a rightmost sibling c ombinator.
507 InvalidationSetFeatures localFeatures; 520 InvalidationSetFeatures localFeatures;
508 521
509 for (const CSSSelector* current = selector; current; current = current->tagH istory()) { 522 for (const CSSSelector* current = selector; current; current = current->tagH istory()) {
510 InvalidationType type = siblingFeatures ? InvalidateSiblings : Invalidat eDescendants; 523 InvalidationType type = siblingFeatures ? InvalidateSiblings : Invalidat eDescendants;
511 if (InvalidationSet* invalidationSet = invalidationSetForSelector(*curre nt, type)) { 524 if (InvalidationSet* invalidationSet = invalidationSetForSelector(*curre nt, type)) {
525 if (current->match() == CSSSelector::Id || current->match() == CSSSe lector::Class || current->match() >= CSSSelector::FirstAttributeSelectorMatch)
526 descendantFeatures.containsIdClassAttributeOrTypeInScope = true;
512 if (siblingFeatures) { 527 if (siblingFeatures) {
513 SiblingInvalidationSet* siblingInvalidationSet = toSiblingInvali dationSet(invalidationSet); 528 SiblingInvalidationSet* siblingInvalidationSet = toSiblingInvali dationSet(invalidationSet);
514 siblingInvalidationSet->updateMaxDirectAdjacentSelectors(sibling Features->maxDirectAdjacentSelectors); 529 siblingInvalidationSet->updateMaxDirectAdjacentSelectors(sibling Features->maxDirectAdjacentSelectors);
515 530
516 addFeaturesToInvalidationSet(*invalidationSet, *siblingFeatures) ; 531 addFeaturesToInvalidationSet(*invalidationSet, *siblingFeatures) ;
517 if (siblingFeatures == &descendantFeatures) 532 if (siblingFeatures == &descendantFeatures)
518 siblingInvalidationSet->setInvalidatesSelf(); 533 siblingInvalidationSet->setInvalidatesSelf();
519 else 534 else
520 addFeaturesToInvalidationSet(siblingInvalidationSet->ensureS iblingDescendants(), descendantFeatures); 535 addFeaturesToInvalidationSet(siblingInvalidationSet->ensureS iblingDescendants(), descendantFeatures);
521 } else { 536 } else {
522 addFeaturesToInvalidationSet(*invalidationSet, descendantFeature s); 537 addFeaturesToInvalidationSet(*invalidationSet, descendantFeature s);
523 } 538 }
524 } else { 539 } else {
525 if (current->isHostPseudoClass()) 540 if (current->isHostPseudoClass())
526 descendantFeatures.treeBoundaryCrossing = true; 541 descendantFeatures.treeBoundaryCrossing = true;
527 if (current->isInsertionPointCrossing()) 542 if (current->isInsertionPointCrossing())
528 descendantFeatures.insertionPointCrossing = true; 543 descendantFeatures.insertionPointCrossing = true;
529 if (const CSSSelectorList* selectorList = current->selectorList()) { 544 if (const CSSSelectorList* selectorList = current->selectorList()) {
530 ASSERT(supportsInvalidationWithSelectorList(current->getPseudoTy pe())); 545 ASSERT(supportsInvalidationWithSelectorList(current->getPseudoTy pe()));
546 bool didContain = descendantFeatures.containsIdClassAttributeOrT ypeInScope;
531 for (const CSSSelector* subSelector = selectorList->first(); sub Selector; subSelector = CSSSelectorList::next(*subSelector)) 547 for (const CSSSelector* subSelector = selectorList->first(); sub Selector; subSelector = CSSSelectorList::next(*subSelector))
532 addFeaturesToInvalidationSets(subSelector, siblingFeatures, descendantFeatures); 548 addFeaturesToInvalidationSets(subSelector, siblingFeatures, descendantFeatures);
549 if (current->getPseudoType() == CSSSelector::PseudoNot || curren t->getPseudoType() == CSSSelector::PseudoHostContext)
550 descendantFeatures.containsIdClassAttributeOrTypeInScope = d idContain;
551 else
552 descendantFeatures.containsIdClassAttributeOrTypeInScope |= didContain;
533 } 553 }
534 } 554 }
535 555
536 if (current->relation() == CSSSelector::SubSelector) 556 if (current->relation() == CSSSelector::SubSelector)
537 continue; 557 continue;
538 558
539 if (current->relationIsAffectedByPseudoContent() || current->relation() == CSSSelector::ShadowSlot) { 559 if (current->relationIsAffectedByPseudoContent() || current->relation() == CSSSelector::ShadowSlot) {
540 descendantFeatures.insertionPointCrossing = true; 560 descendantFeatures.insertionPointCrossing = true;
541 descendantFeatures.contentPseudoCrossing = true; 561 descendantFeatures.contentPseudoCrossing = true;
562 descendantFeatures.containsIdClassAttributeOrTypeInScope = false;
542 } 563 }
543 if (current->isShadowSelector()) 564 if (current->isShadowSelector()) {
544 descendantFeatures.treeBoundaryCrossing = true; 565 descendantFeatures.treeBoundaryCrossing = true;
566 descendantFeatures.containsIdClassAttributeOrTypeInScope = false;
567 }
545 if (!current->isAdjacentSelector()) { 568 if (!current->isAdjacentSelector()) {
546 lastCompoundSelectorInAdjacentChain = current->tagHistory(); 569 lastCompoundSelectorInAdjacentChain = current->tagHistory();
547 siblingFeatures = nullptr; 570 siblingFeatures = nullptr;
548 continue; 571 continue;
549 } 572 }
550 573
551 if (siblingFeatures) { 574 if (siblingFeatures) {
552 if (siblingFeatures->maxDirectAdjacentSelectors == UINT_MAX) 575 if (siblingFeatures->maxDirectAdjacentSelectors == UINT_MAX)
553 continue; 576 continue;
554 577
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 usesWindowInactiveSelector = usesWindowInactiveSelector || other.usesWindowI nactiveSelector; 685 usesWindowInactiveSelector = usesWindowInactiveSelector || other.usesWindowI nactiveSelector;
663 maxDirectAdjacentSelectors = std::max(maxDirectAdjacentSelectors, other.maxD irectAdjacentSelectors); 686 maxDirectAdjacentSelectors = std::max(maxDirectAdjacentSelectors, other.maxD irectAdjacentSelectors);
664 } 687 }
665 688
666 void RuleFeatureSet::FeatureMetadata::clear() 689 void RuleFeatureSet::FeatureMetadata::clear()
667 { 690 {
668 usesFirstLineRules = false; 691 usesFirstLineRules = false;
669 usesWindowInactiveSelector = false; 692 usesWindowInactiveSelector = false;
670 foundSiblingSelector = false; 693 foundSiblingSelector = false;
671 foundInsertionPointCrossing = false; 694 foundInsertionPointCrossing = false;
695 needsFullRecalcForRuleSetInvalidation = false;
672 maxDirectAdjacentSelectors = 0; 696 maxDirectAdjacentSelectors = 0;
673 } 697 }
674 698
675 void RuleFeatureSet::add(const RuleFeatureSet& other) 699 void RuleFeatureSet::add(const RuleFeatureSet& other)
676 { 700 {
677 for (const auto& entry : other.m_classInvalidationSets) 701 for (const auto& entry : other.m_classInvalidationSets)
678 ensureInvalidationSet(m_classInvalidationSets, entry.key, entry.value->t ype()).combine(*entry.value); 702 ensureInvalidationSet(m_classInvalidationSets, entry.key, entry.value->t ype()).combine(*entry.value);
679 for (const auto& entry : other.m_attributeInvalidationSets) 703 for (const auto& entry : other.m_attributeInvalidationSets)
680 ensureInvalidationSet(m_attributeInvalidationSets, entry.key, entry.valu e->type()).combine(*entry.value); 704 ensureInvalidationSet(m_attributeInvalidationSets, entry.key, entry.valu e->type()).combine(*entry.value);
681 for (const auto& entry : other.m_idInvalidationSets) 705 for (const auto& entry : other.m_idInvalidationSets)
682 ensureInvalidationSet(m_idInvalidationSets, entry.key, entry.value->type ()).combine(*entry.value); 706 ensureInvalidationSet(m_idInvalidationSets, entry.key, entry.value->type ()).combine(*entry.value);
683 for (const auto& entry : other.m_pseudoInvalidationSets) 707 for (const auto& entry : other.m_pseudoInvalidationSets)
684 ensureInvalidationSet(m_pseudoInvalidationSets, static_cast<CSSSelector: :PseudoType>(entry.key), entry.value->type()).combine(*entry.value); 708 ensureInvalidationSet(m_pseudoInvalidationSets, static_cast<CSSSelector: :PseudoType>(entry.key), entry.value->type()).combine(*entry.value);
685 709
686 m_metadata.add(other.m_metadata); 710 m_metadata.add(other.m_metadata);
687 711
688 siblingRules.appendVector(other.siblingRules); 712 siblingRules.appendVector(other.siblingRules);
689 uncommonAttributeRules.appendVector(other.uncommonAttributeRules); 713 uncommonAttributeRules.appendVector(other.uncommonAttributeRules);
714 viewportDependentMediaQueryResults.appendVector(other.viewportDependentMedia QueryResults);
715 deviceDependentMediaQueryResults.appendVector(other.deviceDependentMediaQuer yResults);
690 } 716 }
691 717
692 void RuleFeatureSet::clear() 718 void RuleFeatureSet::clear()
693 { 719 {
694 siblingRules.clear(); 720 siblingRules.clear();
695 uncommonAttributeRules.clear(); 721 uncommonAttributeRules.clear();
696 m_metadata.clear(); 722 m_metadata.clear();
697 m_classInvalidationSets.clear(); 723 m_classInvalidationSets.clear();
698 m_attributeInvalidationSets.clear(); 724 m_attributeInvalidationSets.clear();
699 m_idInvalidationSets.clear(); 725 m_idInvalidationSets.clear();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 if (siblings) { 807 if (siblings) {
782 TRACE_SCHEDULE_STYLE_INVALIDATION(element, *siblings, pseudoChange, pseu do); 808 TRACE_SCHEDULE_STYLE_INVALIDATION(element, *siblings, pseudoChange, pseu do);
783 invalidationLists.siblings.append(siblings); 809 invalidationLists.siblings.append(siblings);
784 } 810 }
785 } 811 }
786 812
787 DEFINE_TRACE(RuleFeatureSet) 813 DEFINE_TRACE(RuleFeatureSet)
788 { 814 {
789 visitor->trace(siblingRules); 815 visitor->trace(siblingRules);
790 visitor->trace(uncommonAttributeRules); 816 visitor->trace(uncommonAttributeRules);
817 visitor->trace(viewportDependentMediaQueryResults);
818 visitor->trace(deviceDependentMediaQueryResults);
791 } 819 }
792 820
793 } // namespace blink 821 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/RuleFeature.h ('k') | third_party/WebKit/Source/core/css/RuleFeatureSetTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698