LibWeb: Add method to get style scope from layout node

This commit is contained in:
Callum Law
2026-04-06 11:19:42 +12:00
committed by Sam Atkins
parent b9e9c4e655
commit fedd1f8d55
Notes: github-actions[bot] 2026-04-15 10:09:21 +00:00
2 changed files with 27 additions and 0 deletions

View File

@@ -23,6 +23,7 @@
#include <LibWeb/CSS/StyleValues/URLStyleValue.h>
#include <LibWeb/CSS/SystemColor.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/Dump.h>
#include <LibWeb/HTML/FormAssociatedElement.h>
#include <LibWeb/HTML/HTMLHtmlElement.h>
@@ -986,6 +987,31 @@ void NodeWithStyle::apply_style(CSS::ComputedProperties const& computed_style)
box_node->propagate_style_along_continuation(computed_style);
}
CSS::StyleScope const& NodeWithStyle::style_scope() const
{
auto resolve_style_scope = [](DOM::Node const& dom_node) -> CSS::StyleScope const& {
auto const& root = dom_node.root();
if (root.is_shadow_root()) {
auto const& shadow_root = static_cast<DOM::ShadowRoot const&>(root);
if (shadow_root.uses_document_style_sheets())
return root.document().style_scope();
return shadow_root.style_scope();
}
return root.document().style_scope();
};
if (auto const* dom_node = this->dom_node())
return resolve_style_scope(*dom_node);
if (is_generated_for_pseudo_element())
return resolve_style_scope(*pseudo_element_generator());
if (auto const* parent = this->parent())
return parent->style_scope();
return document().style_scope();
}
void NodeWithStyle::propagate_non_inherit_values(NodeWithStyle& target_node) const
{
// NOTE: These properties are not inherited, but we still have to propagate them to anonymous wrappers.