AttributeChangeInvalidation.cpp [plain text]
#include "config.h"
#include "AttributeChangeInvalidation.h"
#include "ElementIterator.h"
#include "StyleInvalidationFunctions.h"
#include "StyleInvalidator.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 AtomicString& oldValue, const AtomicString& newValue)
{
if (newValue == oldValue)
return;
bool isHTML = m_element.isHTMLElement();
bool mayAffectStyle = false;
bool mayAffectStyleInShadowTree = false;
traverseRuleFeatures(m_element, [&] (const RuleFeatureSet& features, bool mayAffectShadowTree) {
if (!mayBeAffectedByAttributeChange(features, isHTML, attributeName))
return;
mayAffectStyle = true;
if (mayAffectShadowTree)
mayAffectStyleInShadowTree = true;
});
if (!mayAffectStyle)
return;
if (!isHTML) {
m_element.invalidateStyleForSubtree();
return;
}
if (mayAffectStyleInShadowTree) {
m_element.invalidateStyleForSubtree();
return;
}
m_element.invalidateStyle();
if (!childrenOfType<Element>(m_element).first())
return;
auto& ruleSets = m_element.styleResolver().ruleSets();
auto* attributeRules = ruleSets.ancestorAttributeRulesForHTML(attributeName.localName());
if (!attributeRules)
return;
for (auto* selector : attributeRules->attributeSelectors) {
bool oldMatches = oldValue.isNull() ? false : SelectorChecker::attributeSelectorMatches(m_element, attributeName, oldValue, *selector);
bool newMatches = newValue.isNull() ? false : SelectorChecker::attributeSelectorMatches(m_element, attributeName, newValue, *selector);
if (oldMatches != newMatches) {
m_descendantInvalidationRuleSet = attributeRules->ruleSet.get();
return;
}
}
}
void AttributeChangeInvalidation::invalidateDescendants()
{
if (!m_descendantInvalidationRuleSet)
return;
Invalidator invalidator(*m_descendantInvalidationRuleSet);
invalidator.invalidateStyle(m_element);
}
}
}