PseudoClassChangeInvalidation.cpp [plain text]
#include "config.h"
#include "PseudoClassChangeInvalidation.h"
#include "ElementChildIterator.h"
#include "StyleInvalidationFunctions.h"
namespace WebCore {
namespace Style {
void PseudoClassChangeInvalidation::computeInvalidation(CSSSelector::PseudoClassType pseudoClass, InvalidationScope invalidationScope)
{
bool shouldInvalidateCurrent = false;
bool mayAffectStyleInShadowTree = false;
traverseRuleFeatures(m_element, [&] (const RuleFeatureSet& features, bool mayAffectShadowTree) {
if (mayAffectShadowTree && features.pseudoClassRules.contains(pseudoClass))
mayAffectStyleInShadowTree = true;
if (m_element.shadowRoot() && features.pseudoClassesAffectingHost.contains(pseudoClass))
shouldInvalidateCurrent = true;
});
if (mayAffectStyleInShadowTree) {
m_element.invalidateStyleForSubtree();
}
if (shouldInvalidateCurrent)
m_element.invalidateStyle();
auto& ruleSets = m_element.styleResolver().ruleSets();
if (auto* invalidationRuleSets = ruleSets.pseudoClassInvalidationRuleSets(pseudoClass)) {
for (auto& invalidationRuleSet : *invalidationRuleSets) {
auto shouldInvalidate = [&] {
switch (invalidationScope) {
case InvalidationScope::All:
return true;
case InvalidationScope::SelfChildrenAndSiblings:
return invalidationRuleSet.matchElement != MatchElement::Ancestor;
case InvalidationScope::Descendants:
return invalidationRuleSet.matchElement == MatchElement::Ancestor;
}
ASSERT_NOT_REACHED();
return true;
}();
if (!shouldInvalidate)
continue;
Invalidator::addToMatchElementRuleSets(m_matchElementRuleSets, invalidationRuleSet);
}
}
}
void PseudoClassChangeInvalidation::invalidateStyleWithRuleSets()
{
Invalidator::invalidateWithMatchElementRuleSets(m_element, m_matchElementRuleSets);
}
}
}