StyleInvalidationFunctions.h [plain text]
#pragma once
#include "HTMLSlotElement.h"
#include "ShadowRoot.h"
#include "StyleResolver.h"
#include "StyleScope.h"
#include "StyleScopeRuleSets.h"
namespace WebCore {
namespace Style {
template <typename TraverseFunction>
inline void traverseRuleFeaturesInShadowTree(Element& element, TraverseFunction&& function)
{
if (!element.shadowRoot())
return;
auto& shadowRuleSets = element.shadowRoot()->styleScope().resolver().ruleSets();
auto& authorStyle = shadowRuleSets.authorStyle();
bool hasHostPseudoClassRulesMatchingInShadowTree = authorStyle.hasHostPseudoClassRulesMatchingInShadowTree();
if (authorStyle.hostPseudoClassRules().isEmpty() && !hasHostPseudoClassRulesMatchingInShadowTree)
return;
function(shadowRuleSets.features(), hasHostPseudoClassRulesMatchingInShadowTree);
}
template <typename TraverseFunction>
inline void traverseRuleFeaturesForSlotted(Element& element, TraverseFunction&& function)
{
auto assignedShadowRoots = assignedShadowRootsIfSlotted(element);
for (auto& assignedShadowRoot : assignedShadowRoots) {
auto& ruleSets = assignedShadowRoot->styleScope().resolver().ruleSets();
if (ruleSets.authorStyle().slottedPseudoElementRules().isEmpty())
continue;
function(ruleSets.features(), false);
}
}
template <typename TraverseFunction>
inline void traverseRuleFeatures(Element& element, TraverseFunction&& function)
{
auto& ruleSets = element.styleResolver().ruleSets();
auto mayAffectShadowTree = [&] {
if (element.shadowRoot() && ruleSets.authorStyle().hasShadowPseudoElementRules())
return true;
if (is<HTMLSlotElement>(element) && !ruleSets.authorStyle().slottedPseudoElementRules().isEmpty())
return true;
return false;
};
function(ruleSets.features(), mayAffectShadowTree());
traverseRuleFeaturesInShadowTree(element, function);
traverseRuleFeaturesForSlotted(element, function);
if (element.isInShadowTree())
Style::Scope::forNode(*element.containingShadowRoot()->host()).resolver();
}
}
}