From e4dc7583438164929457c4eb5a5f751a8c791b7d Mon Sep 17 00:00:00 2001 From: rmg-x Date: Thu, 21 Nov 2024 16:11:18 -0600 Subject: [PATCH] LibWeb/CSS: Check for matching custom properties on parent elements Previously, we were only checking the current element and not the parents in `ResolvedCSSStyleDeclaration::custom_property()` which wasn't correct. --- .../LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp | 11 ++++++++++- .../Text/expected/custom-property-from-parent.txt | 1 + .../Text/input/custom-property-from-parent.html | 13 +++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/custom-property-from-parent.txt create mode 100644 Tests/LibWeb/Text/input/custom-property-from-parent.html diff --git a/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index e062224c9a4..156a5f47f60 100644 --- a/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -604,7 +604,16 @@ Optional ResolvedCSSStyleDeclaration::property(PropertyID propert Optional ResolvedCSSStyleDeclaration::custom_property(FlyString const& name) const { const_cast(m_element->document()).update_style(); - return m_element->custom_properties(m_pseudo_element).get(name); + + auto const* element_to_check = m_element.ptr(); + while (element_to_check) { + if (auto property = element_to_check->custom_properties(m_pseudo_element).get(name); property.has_value()) + return *property; + + element_to_check = element_to_check->parent_element(); + } + + return {}; } static WebIDL::ExceptionOr cannot_modify_computed_property_error(JS::Realm& realm) diff --git a/Tests/LibWeb/Text/expected/custom-property-from-parent.txt b/Tests/LibWeb/Text/expected/custom-property-from-parent.txt new file mode 100644 index 00000000000..235dd81b746 --- /dev/null +++ b/Tests/LibWeb/Text/expected/custom-property-from-parent.txt @@ -0,0 +1 @@ +PASS: #19db6e \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/custom-property-from-parent.html b/Tests/LibWeb/Text/input/custom-property-from-parent.html new file mode 100644 index 00000000000..cdbdd9ac451 --- /dev/null +++ b/Tests/LibWeb/Text/input/custom-property-from-parent.html @@ -0,0 +1,13 @@ + + + +