mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
LibWeb: Add method to get style scope from layout node
This commit is contained in:
Notes:
github-actions[bot]
2026-04-15 10:09:21 +00:00
Author: https://github.com/Calme1709 Commit: https://github.com/LadybirdBrowser/ladybird/commit/fedd1f8d55f Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8815 Reviewed-by: https://github.com/AtkinsSJ ✅
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user