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

Unified Diff: sky/engine/core/css/RuleFeature.cpp

Issue 712173002: Remove StyleInvalidator machinery. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/engine/core/css/RuleFeature.h ('k') | sky/engine/core/css/invalidation/DescendantInvalidationSet.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/engine/core/css/RuleFeature.cpp
diff --git a/sky/engine/core/css/RuleFeature.cpp b/sky/engine/core/css/RuleFeature.cpp
index e6f52da38065f9ffdb02ef3fb33a6c3eec57c454..ce5a216313716ac29c58ad649622c96ce51fdfe8 100644
--- a/sky/engine/core/css/RuleFeature.cpp
+++ b/sky/engine/core/css/RuleFeature.cpp
@@ -33,122 +33,13 @@
#include "core/css/CSSSelectorList.h"
#include "core/css/RuleSet.h"
#include "core/css/StyleRule.h"
-#include "core/css/invalidation/DescendantInvalidationSet.h"
#include "core/dom/Element.h"
#include "core/dom/Node.h"
-#include "platform/RuntimeEnabledFeatures.h"
#include "wtf/BitVector.h"
namespace blink {
-static bool isSkippableComponentForInvalidation(const CSSSelector& selector)
-{
- if (selector.match() == CSSSelector::Tag) {
- ASSERT(selector.tagQName().localName() == starAtom);
- return true;
- }
- if (selector.match() == CSSSelector::PseudoElement)
- return false;
- if (selector.match() != CSSSelector::PseudoClass)
- return false;
- switch (selector.pseudoType()) {
- case CSSSelector::PseudoHover:
- case CSSSelector::PseudoFocus:
- case CSSSelector::PseudoActive:
- case CSSSelector::PseudoLang:
- case CSSSelector::PseudoUnresolved:
- return true;
- default:
- return false;
- }
-}
-
-RuleFeature::RuleFeature(StyleRule* rule, unsigned selectorIndex)
- : rule(rule)
- , selectorIndex(selectorIndex)
-{
-}
-
-void RuleFeature::trace(Visitor* visitor)
-{
- visitor->trace(rule);
-}
-
-// This method is somewhat conservative in what it accepts.
-RuleFeatureSet::InvalidationSetMode RuleFeatureSet::invalidationSetModeForSelector(const CSSSelector& selector)
-{
- bool foundCombinator = false;
- bool foundIdent = false;
- for (const CSSSelector* component = &selector; component; component = component->tagHistory()) {
-
- if (component->match() == CSSSelector::Class || component->match() == CSSSelector::Id
- || (component->match() == CSSSelector::Tag && component->tagQName().localName() != starAtom)
- || component->isAttributeSelector() || component->isCustomPseudoElement()) {
- if (!foundCombinator) {
- // We have found an invalidation set feature in the rightmost compound selector.
- foundIdent = true;
- }
- } else if (component->pseudoType() == CSSSelector::PseudoHost) {
- if (const CSSSelectorList* selectorList = component->selectorList()) {
- // Features inside :not() are not added to the feature set, so consider it a universal selector.
- bool foundUniversal = false;
- for (const CSSSelector* selector = selectorList->first(); selector; selector = CSSSelectorList::next(*selector)) {
- // Find the invalidation set mode for each of the selectors in the selector list
- // of a :not(), :host(), etc. For instance, ".x :-webkit-any(.a, .b)" yields an
- // AddFeatures mode for both ".a" and ".b". ":-webkit-any(.a, *)" yields AddFeatures
- // for ".a", but UseSubtreeStyleChange for "*". One sub-selector without invalidation
- // set features is sufficient to cause the selector to be a universal selector as far
- // the invalidation set is concerned.
- InvalidationSetMode subSelectorMode = invalidationSetModeForSelector(*selector);
-
- // The sub-selector contained something unskippable, fall back to whole subtree
- // recalcs in collectFeaturesFromSelector. subSelectorMode will return
- // UseSubtreeStyleChange since there are no combinators inside the selector list,
- // so translate it to UseLocalStyleChange if a combinator has been seen in the
- // outer context.
- //
- // FIXME: Is UseSubtreeStyleChange ever needed as input to collectFeaturesFromSelector?
- // That is, are there any selectors for which we need to use SubtreeStyleChange for
- // changing features when present in the rightmost compound selector?
- if (subSelectorMode == UseSubtreeStyleChange)
- return foundCombinator ? UseLocalStyleChange : UseSubtreeStyleChange;
-
- // We found no features in the sub-selector, only skippable ones (foundIdent was
- // false at the end of this method). That is a universal selector as far as the
- // invalidation set is concerned.
- if (subSelectorMode == UseLocalStyleChange)
- foundUniversal = true;
- }
- if (!foundUniversal && !foundCombinator) {
- // All sub-selectors contained invalidation set features and
- // we are in the rightmost compound selector.
- foundIdent = true;
- }
- }
- } else if (!isSkippableComponentForInvalidation(*component)) {
- return foundCombinator ? UseLocalStyleChange : UseSubtreeStyleChange;
- }
- foundCombinator = true;
- }
- return foundIdent ? AddFeatures : UseLocalStyleChange;
-}
-
-void RuleFeatureSet::extractInvalidationSetFeature(const CSSSelector& selector, InvalidationSetFeatures& features)
-{
- if (selector.match() == CSSSelector::Tag)
- features.tagName = selector.tagQName().localName();
- else if (selector.match() == CSSSelector::Id)
- features.id = selector.value();
- else if (selector.match() == CSSSelector::Class)
- features.classes.append(selector.value());
- else if (selector.isAttributeSelector())
- features.attributes.append(selector.attribute().localName());
- else if (selector.isCustomPseudoElement())
- features.customPseudoElement = true;
-}
-
RuleFeatureSet::RuleFeatureSet()
- : m_targetedStyleRecalcEnabled(RuntimeEnabledFeatures::targetedStyleRecalcEnabled())
{
}
@@ -156,183 +47,49 @@ RuleFeatureSet::~RuleFeatureSet()
{
}
-DescendantInvalidationSet* RuleFeatureSet::invalidationSetForSelector(const CSSSelector& selector)
+void RuleFeatureSet::addSelectorFeatures(const CSSSelector& selector)
{
if (selector.match() == CSSSelector::Class)
- return &ensureClassInvalidationSet(selector.value());
- if (selector.isAttributeSelector())
- return &ensureAttributeInvalidationSet(selector.attribute().localName());
- if (selector.match() == CSSSelector::Id)
- return &ensureIdInvalidationSet(selector.value());
- if (selector.match() == CSSSelector::PseudoClass) {
- CSSSelector::PseudoType pseudo = selector.pseudoType();
- if (pseudo == CSSSelector::PseudoHover || pseudo == CSSSelector::PseudoActive || pseudo == CSSSelector::PseudoFocus)
- return &ensurePseudoInvalidationSet(pseudo);
- }
- return 0;
-}
-
-// Given a selector, update the descendant invalidation sets for the features found
-// in the selector. The first step is to extract the features from the rightmost
-// compound selector (extractInvalidationSetFeatures). Secondly, those features will be
-// added to the invalidation sets for the features found in the other compound selectors
-// (addFeaturesToInvalidationSets).
-
-RuleFeatureSet::InvalidationSetMode RuleFeatureSet::updateInvalidationSets(const CSSSelector& selector)
-{
- InvalidationSetMode mode = invalidationSetModeForSelector(selector);
- if (mode != AddFeatures)
- return mode;
-
- InvalidationSetFeatures features;
- if (const CSSSelector* current = extractInvalidationSetFeatures(selector, features, false))
- addFeaturesToInvalidationSets(*current, features);
- return AddFeatures;
-}
-
-const CSSSelector* RuleFeatureSet::extractInvalidationSetFeatures(const CSSSelector& selector, InvalidationSetFeatures& features, bool negated)
-{
- for (const CSSSelector* current = &selector; current; current = current->tagHistory()) {
- if (!negated)
- extractInvalidationSetFeature(*current, features);
- // Initialize the entry in the invalidation set map, if supported.
- invalidationSetForSelector(*current);
- if (current->pseudoType() == CSSSelector::PseudoHost) {
- if (const CSSSelectorList* selectorList = current->selectorList()) {
- for (const CSSSelector* selector = selectorList->first(); selector; selector = CSSSelectorList::next(*selector))
- extractInvalidationSetFeatures(*selector, features, false);
- }
- }
- }
- return 0;
-}
-
-// Add features extracted from the rightmost compound selector to descendant invalidation
-// sets for features found in other compound selectors.
-//
-// As we encounter a descendant type of combinator, the features only need to be checked
-// against descendants in the same subtree only. Hence wholeSubtree is reset to false.
-
-void RuleFeatureSet::addFeaturesToInvalidationSets(const CSSSelector& selector, InvalidationSetFeatures& features)
-{
- for (const CSSSelector* current = &selector; current; current = current->tagHistory()) {
- if (DescendantInvalidationSet* invalidationSet = invalidationSetForSelector(*current)) {
- if (features.treeBoundaryCrossing)
- invalidationSet->setTreeBoundaryCrossing();
- if (features.wholeSubtree) {
- invalidationSet->setWholeSubtreeInvalid();
- } else {
- if (!features.id.isEmpty())
- invalidationSet->addId(features.id);
- if (!features.tagName.isEmpty())
- invalidationSet->addTagName(features.tagName);
- for (Vector<AtomicString>::const_iterator it = features.classes.begin(); it != features.classes.end(); ++it)
- invalidationSet->addClass(*it);
- for (Vector<AtomicString>::const_iterator it = features.attributes.begin(); it != features.attributes.end(); ++it)
- invalidationSet->addAttribute(*it);
- if (features.customPseudoElement)
- invalidationSet->setCustomPseudoInvalid();
- }
- } else {
- if (current->pseudoType() == CSSSelector::PseudoHost)
- features.treeBoundaryCrossing = true;
- if (const CSSSelectorList* selectorList = current->selectorList()) {
- ASSERT(current->pseudoType() == CSSSelector::PseudoHost);
- for (const CSSSelector* selector = selectorList->first(); selector; selector = CSSSelectorList::next(*selector))
- addFeaturesToInvalidationSets(*selector, features);
- }
- }
- }
-}
-
-void RuleFeatureSet::addContentAttr(const AtomicString& attributeName)
-{
- DescendantInvalidationSet& invalidationSet = ensureAttributeInvalidationSet(attributeName);
- invalidationSet.setWholeSubtreeInvalid();
+ m_classNames.add(selector.value());
+ else if (selector.match() == CSSSelector::Id)
+ m_idNames.add(selector.value());
+ else if (selector.isAttributeSelector())
+ m_attributeNames.add(selector.attribute().localName());
}
void RuleFeatureSet::collectFeaturesFromRuleData(const RuleData& ruleData)
{
- InvalidationSetMode mode = UseSubtreeStyleChange;
- if (m_targetedStyleRecalcEnabled)
- mode = updateInvalidationSets(ruleData.selector());
-
- collectFeaturesFromSelector(ruleData.selector(), mode);
+ collectFeaturesFromSelector(ruleData.selector());
if (ruleData.containsAttributeSelector())
attributeRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex()));
}
-DescendantInvalidationSet& RuleFeatureSet::ensureClassInvalidationSet(const AtomicString& className)
-{
- InvalidationSetMap::AddResult addResult = m_classInvalidationSets.add(className, nullptr);
- if (addResult.isNewEntry)
- addResult.storedValue->value = DescendantInvalidationSet::create();
- return *addResult.storedValue->value;
-}
-
-DescendantInvalidationSet& RuleFeatureSet::ensureAttributeInvalidationSet(const AtomicString& attributeName)
-{
- InvalidationSetMap::AddResult addResult = m_attributeInvalidationSets.add(attributeName, nullptr);
- if (addResult.isNewEntry)
- addResult.storedValue->value = DescendantInvalidationSet::create();
- return *addResult.storedValue->value;
-}
-
-DescendantInvalidationSet& RuleFeatureSet::ensureIdInvalidationSet(const AtomicString& id)
-{
- InvalidationSetMap::AddResult addResult = m_idInvalidationSets.add(id, nullptr);
- if (addResult.isNewEntry)
- addResult.storedValue->value = DescendantInvalidationSet::create();
- return *addResult.storedValue->value;
-}
-
-DescendantInvalidationSet& RuleFeatureSet::ensurePseudoInvalidationSet(CSSSelector::PseudoType pseudoType)
-{
- PseudoTypeInvalidationSetMap::AddResult addResult = m_pseudoInvalidationSets.add(pseudoType, nullptr);
- if (addResult.isNewEntry)
- addResult.storedValue->value = DescendantInvalidationSet::create();
- return *addResult.storedValue->value;
-}
-
void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector& selector)
{
- collectFeaturesFromSelector(selector, UseSubtreeStyleChange);
-}
-
-void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector& selector, InvalidationSetMode mode)
-{
- for (const CSSSelector* current = &selector; current; current = current->tagHistory()) {
- if (mode != AddFeatures) {
- if (DescendantInvalidationSet* invalidationSet = invalidationSetForSelector(*current)) {
- if (mode == UseSubtreeStyleChange)
- invalidationSet->setWholeSubtreeInvalid();
- }
- }
+ addSelectorFeatures(selector);
- collectFeaturesFromSelectorList(current->selectorList(), mode);
- }
+ for (const CSSSelector* current = &selector; current; current = current->tagHistory())
+ collectFeaturesFromSelectorList(current->selectorList());
}
-void RuleFeatureSet::collectFeaturesFromSelectorList(const CSSSelectorList* selectorList, InvalidationSetMode mode)
+void RuleFeatureSet::collectFeaturesFromSelectorList(const CSSSelectorList* selectorList)
{
if (!selectorList)
return;
for (const CSSSelector* selector = selectorList->first(); selector; selector = CSSSelectorList::next(*selector))
- collectFeaturesFromSelector(*selector, mode);
+ collectFeaturesFromSelector(*selector);
}
void RuleFeatureSet::add(const RuleFeatureSet& other)
{
- for (InvalidationSetMap::const_iterator it = other.m_classInvalidationSets.begin(); it != other.m_classInvalidationSets.end(); ++it)
- ensureClassInvalidationSet(it->key).combine(*it->value);
- for (InvalidationSetMap::const_iterator it = other.m_attributeInvalidationSets.begin(); it != other.m_attributeInvalidationSets.end(); ++it)
- ensureAttributeInvalidationSet(it->key).combine(*it->value);
- for (InvalidationSetMap::const_iterator it = other.m_idInvalidationSets.begin(); it != other.m_idInvalidationSets.end(); ++it)
- ensureIdInvalidationSet(it->key).combine(*it->value);
- for (PseudoTypeInvalidationSetMap::const_iterator it = other.m_pseudoInvalidationSets.begin(); it != other.m_pseudoInvalidationSets.end(); ++it)
- ensurePseudoInvalidationSet(static_cast<CSSSelector::PseudoType>(it->key)).combine(*it->value);
+ for (HashSet<AtomicString>::const_iterator it = other.m_classNames.begin(); it != other.m_classNames.end(); ++it)
+ m_classNames.add(*it);
+ for (HashSet<AtomicString>::const_iterator it = other.m_attributeNames.begin(); it != other.m_attributeNames.end(); ++it)
+ m_attributeNames.add(*it);
+ for (HashSet<AtomicString>::const_iterator it = other.m_idNames.begin(); it != other.m_idNames.end(); ++it)
+ m_idNames.add(*it);
attributeRules.appendVector(other.attributeRules);
}
@@ -340,20 +97,16 @@ void RuleFeatureSet::add(const RuleFeatureSet& other)
void RuleFeatureSet::clear()
{
attributeRules.clear();
- m_classInvalidationSets.clear();
- m_attributeInvalidationSets.clear();
- m_idInvalidationSets.clear();
- // We cannot clear m_styleInvalidator here, because the style invalidator might not
- // have been evaluated yet. If not yet, in StyleInvalidator, there exists some element
- // who has needsStyleInvlidation but does not have any invalidation list.
- // This makes Blink not to recalc style correctly. crbug.com/344729.
+ m_classNames.clear();
+ m_attributeNames.clear();
+ m_idNames.clear();
}
void RuleFeatureSet::scheduleStyleInvalidationForClassChange(const SpaceSplitString& changedClasses, Element& element)
{
unsigned changedSize = changedClasses.size();
for (unsigned i = 0; i < changedSize; ++i) {
- addClassToInvalidationSet(changedClasses[i], element);
+ scheduleStyleInvalidationForClassChange(changedClasses[i], element);
}
}
@@ -381,63 +134,39 @@ void RuleFeatureSet::scheduleStyleInvalidationForClassChange(const SpaceSplitStr
}
// Class was added.
if (!found)
- addClassToInvalidationSet(newClasses[i], element);
+ scheduleStyleInvalidationForClassChange(newClasses[i], element);
}
for (unsigned i = 0; i < oldClasses.size(); ++i) {
if (remainingClassBits.quickGet(i))
continue;
// Class was removed.
- addClassToInvalidationSet(oldClasses[i], element);
+ scheduleStyleInvalidationForClassChange(oldClasses[i], element);
}
}
void RuleFeatureSet::scheduleStyleInvalidationForAttributeChange(const QualifiedName& attributeName, Element& element)
{
-
- if (RefPtr<DescendantInvalidationSet> invalidationSet = m_attributeInvalidationSets.get(attributeName.localName()))
- m_styleInvalidator.scheduleInvalidation(invalidationSet, element);
+ if (m_attributeNames.contains(attributeName.localName()))
+ element.setNeedsStyleRecalc(LocalStyleChange);
}
void RuleFeatureSet::scheduleStyleInvalidationForIdChange(const AtomicString& oldId, const AtomicString& newId, Element& element)
{
if (!oldId.isEmpty()) {
- if (RefPtr<DescendantInvalidationSet> invalidationSet = m_idInvalidationSets.get(oldId))
- m_styleInvalidator.scheduleInvalidation(invalidationSet, element);
+ if (m_idNames.contains(oldId))
+ element.setNeedsStyleRecalc(LocalStyleChange);
}
if (!newId.isEmpty()) {
- if (RefPtr<DescendantInvalidationSet> invalidationSet = m_idInvalidationSets.get(newId))
- m_styleInvalidator.scheduleInvalidation(invalidationSet, element);
+ if (m_idNames.contains(newId))
+ element.setNeedsStyleRecalc(LocalStyleChange);
}
}
-void RuleFeatureSet::scheduleStyleInvalidationForPseudoChange(CSSSelector::PseudoType pseudo, Element& element)
-{
- if (RefPtr<DescendantInvalidationSet> invalidationSet = m_pseudoInvalidationSets.get(pseudo))
- m_styleInvalidator.scheduleInvalidation(invalidationSet, element);
-}
-
-void RuleFeatureSet::addClassToInvalidationSet(const AtomicString& className, Element& element)
-{
- if (RefPtr<DescendantInvalidationSet> invalidationSet = m_classInvalidationSets.get(className))
- m_styleInvalidator.scheduleInvalidation(invalidationSet, element);
-}
-
-StyleInvalidator& RuleFeatureSet::styleInvalidator()
-{
- return m_styleInvalidator;
-}
-
-void RuleFeatureSet::trace(Visitor* visitor)
+void RuleFeatureSet::scheduleStyleInvalidationForClassChange(const AtomicString& className, Element& element)
{
-#if ENABLE(OILPAN)
- visitor->trace(attributeRules);
- visitor->trace(m_classInvalidationSets);
- visitor->trace(m_attributeInvalidationSets);
- visitor->trace(m_idInvalidationSets);
- visitor->trace(m_pseudoInvalidationSets);
- visitor->trace(m_styleInvalidator);
-#endif
+ if (m_classNames.contains(className))
+ element.setNeedsStyleRecalc(LocalStyleChange);
}
} // namespace blink
« no previous file with comments | « sky/engine/core/css/RuleFeature.h ('k') | sky/engine/core/css/invalidation/DescendantInvalidationSet.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698