IdChangeInvalidation.cpp [plain text]
#include "config.h"
#include "IdChangeInvalidation.h"
#include "DocumentRuleSets.h"
#include "ElementChildIterator.h"
#include "ShadowRoot.h"
#include "StyleResolver.h"
#include "StyleScope.h"
namespace WebCore {
namespace Style {
static bool mayBeAffectedByHostRules(const Element& element, const AtomicString& changedId)
{
auto* shadowRoot = element.shadowRoot();
if (!shadowRoot)
return false;
auto& shadowRuleSets = shadowRoot->styleScope().resolver().ruleSets();
if (shadowRuleSets.authorStyle().hostPseudoClassRules().isEmpty())
return false;
return shadowRuleSets.features().idsInRules.contains(changedId.impl());
}
static bool mayBeAffectedBySlottedRules(const Element& element, const AtomicString& changedId)
{
for (auto* shadowRoot : assignedShadowRootsIfSlotted(element)) {
auto& ruleSets = shadowRoot->styleScope().resolver().ruleSets();
if (ruleSets.authorStyle().slottedPseudoElementRules().isEmpty())
continue;
if (ruleSets.features().idsInRules.contains(changedId.impl()))
return true;
}
return false;
}
void IdChangeInvalidation::invalidateStyle(const AtomicString& changedId)
{
if (changedId.isEmpty())
return;
auto& ruleSets = m_element.styleResolver().ruleSets();
bool mayAffectStyle = ruleSets.features().idsInRules.contains(changedId.impl())
|| mayBeAffectedByHostRules(m_element, changedId)
|| mayBeAffectedBySlottedRules(m_element, changedId);
if (!mayAffectStyle)
return;
if (m_element.shadowRoot() && ruleSets.authorStyle().hasShadowPseudoElementRules()) {
m_element.invalidateStyleForSubtree();
return;
}
m_element.invalidateStyle();
bool mayAffectDescendantStyle = ruleSets.features().idsMatchingAncestorsInRules.contains(changedId.impl());
if (mayAffectDescendantStyle)
m_element.invalidateStyleForSubtree();
else
m_element.invalidateStyle();
}
}
}