AttributeChangeInvalidation.cpp [plain text]
#include "config.h"
#include "AttributeChangeInvalidation.h"
#include "ElementIterator.h"
#include "StyleInvalidationFunctions.h"
namespace WebCore {
namespace Style {
static bool mayBeAffectedByAttributeChange(const RuleFeatureSet& features, bool isHTML, const QualifiedName& attributeName)
{
auto& nameSet = isHTML ? features.attributeCanonicalLocalNamesInRules : features.attributeLocalNamesInRules;
return nameSet.contains(attributeName.localName());
}
void AttributeChangeInvalidation::invalidateStyle(const QualifiedName& attributeName, const AtomString& oldValue, const AtomString& newValue)
{
if (newValue == oldValue)
return;
bool isHTML = m_element.isHTMLElement();
bool shouldInvalidateCurrent = false;
bool mayAffectStyleInShadowTree = false;
auto attributeNameForLookups = attributeName.localName().convertToASCIILowercase();
traverseRuleFeatures(m_element, [&] (const RuleFeatureSet& features, bool mayAffectShadowTree) {
if (mayAffectShadowTree && mayBeAffectedByAttributeChange(features, isHTML, attributeName))
mayAffectStyleInShadowTree = true;
if (features.attributesAffectingHost.contains(attributeNameForLookups))
shouldInvalidateCurrent = true;
else if (features.contentAttributeNamesInRules.contains(attributeNameForLookups))
shouldInvalidateCurrent = true;
});
if (mayAffectStyleInShadowTree) {
m_element.invalidateStyleForSubtree();
}
if (shouldInvalidateCurrent)
m_element.invalidateStyle();
auto& ruleSets = m_element.styleResolver().ruleSets();
auto* invalidationRuleSets = ruleSets.attributeInvalidationRuleSets(attributeNameForLookups);
if (!invalidationRuleSets)
return;
for (auto& invalidationRuleSet : *invalidationRuleSets) {
for (auto* selector : invalidationRuleSet.invalidationSelectors) {
bool oldMatches = !oldValue.isNull() && SelectorChecker::attributeSelectorMatches(m_element, attributeName, oldValue, *selector);
bool newMatches = !newValue.isNull() && SelectorChecker::attributeSelectorMatches(m_element, attributeName, newValue, *selector);
if (oldMatches != newMatches) {
Invalidator::addToMatchElementRuleSets(m_matchElementRuleSets, invalidationRuleSet);
break;
}
}
}
}
void AttributeChangeInvalidation::invalidateStyleWithRuleSets()
{
Invalidator::invalidateWithMatchElementRuleSets(m_element, m_matchElementRuleSets);
}
}
}