From a2c9ab9c9ac938e54eee338813ac850aa84fe1e0 Mon Sep 17 00:00:00 2001 From: Callum Law Date: Thu, 21 Aug 2025 16:38:17 +1200 Subject: [PATCH] LibWeb: Return `AbstractElement` from `element_to_inherit_style_from` No functional changes. --- Libraries/LibWeb/CSS/StyleComputer.cpp | 5 +++-- Libraries/LibWeb/DOM/AbstractElement.cpp | 9 +++++++-- Libraries/LibWeb/DOM/AbstractElement.h | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index b447809d809..50d054be9a6 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -3119,9 +3119,10 @@ NonnullRefPtr StyleComputer::compute_value_of_custom_property( // Unset is the same as inherit for inherited properties, and by default all custom properties are inherited. // FIXME: Support non-inherited registered custom properties. if (value->is_inherit() || value->is_unset()) { - if (!abstract_element.element_to_inherit_style_from()) + auto element_to_inherit_style_from = abstract_element.element_to_inherit_style_from(); + if (!element_to_inherit_style_from.has_value()) return document.custom_property_initial_value(name); - auto inherited_value = DOM::AbstractElement { const_cast(*abstract_element.element_to_inherit_style_from()) }.get_custom_property(name); + auto inherited_value = element_to_inherit_style_from->get_custom_property(name); if (!inherited_value) return document.custom_property_initial_value(name); return inherited_value.release_nonnull(); diff --git a/Libraries/LibWeb/DOM/AbstractElement.cpp b/Libraries/LibWeb/DOM/AbstractElement.cpp index f07fb274c70..e66ba5015ba 100644 --- a/Libraries/LibWeb/DOM/AbstractElement.cpp +++ b/Libraries/LibWeb/DOM/AbstractElement.cpp @@ -40,9 +40,14 @@ GC::Ptr AbstractElement::parent_element() const return m_element->parent_element(); } -GC::Ptr AbstractElement::element_to_inherit_style_from() const +Optional AbstractElement::element_to_inherit_style_from() const { - return m_element->element_to_inherit_style_from(m_pseudo_element); + GC::Ptr element = m_element->element_to_inherit_style_from(m_pseudo_element); + + if (!element) + return OptionalNone {}; + + return AbstractElement { const_cast(*element) }; } Optional AbstractElement::walk_layout_tree(WalkMethod walk_method) diff --git a/Libraries/LibWeb/DOM/AbstractElement.h b/Libraries/LibWeb/DOM/AbstractElement.h index af44dab2579..5cc885ff50b 100644 --- a/Libraries/LibWeb/DOM/AbstractElement.h +++ b/Libraries/LibWeb/DOM/AbstractElement.h @@ -27,7 +27,7 @@ public: GC::Ptr layout_node() const { return const_cast(this)->layout_node(); } GC::Ptr parent_element() const; - GC::Ptr element_to_inherit_style_from() const; + Optional element_to_inherit_style_from() const; Optional previous_in_tree_order() { return walk_layout_tree(WalkMethod::Previous); } Optional previous_sibling_in_tree_order() { return walk_layout_tree(WalkMethod::PreviousSibling); } bool is_before(AbstractElement const&) const;