From 41c172c6630463b3822c90a309d98234f26b7ce7 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Wed, 20 Nov 2024 18:11:47 +0100 Subject: [PATCH] LibWeb: Allow custom properties in getPropertyPriority() --- Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp | 6 ++++++ .../expected/css/CSSStyleDeclaration-custom-properties.txt | 1 + .../input/css/CSSStyleDeclaration-custom-properties.html | 1 + 3 files changed, 8 insertions(+) diff --git a/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp b/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp index 82dbd566eae..fef865c27f3 100644 --- a/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp @@ -318,6 +318,12 @@ StringView CSSStyleDeclaration::get_property_priority(StringView property_name) auto property_id = property_id_from_string(property_name); if (!property_id.has_value()) return {}; + if (property_id.value() == PropertyID::Custom) { + auto maybe_custom_property = custom_property(FlyString::from_utf8_without_validation(property_name.bytes())); + if (!maybe_custom_property.has_value()) + return {}; + return maybe_custom_property.value().important == Important::Yes ? "important"sv : ""sv; + } auto maybe_property = property(property_id.value()); if (!maybe_property.has_value()) return {}; diff --git a/Tests/LibWeb/Text/expected/css/CSSStyleDeclaration-custom-properties.txt b/Tests/LibWeb/Text/expected/css/CSSStyleDeclaration-custom-properties.txt index dde24163aa6..2c1e1baa910 100644 --- a/Tests/LibWeb/Text/expected/css/CSSStyleDeclaration-custom-properties.txt +++ b/Tests/LibWeb/Text/expected/css/CSSStyleDeclaration-custom-properties.txt @@ -1,3 +1,4 @@ style.getPropertyValue(--redcolor)=red +style.getPropertyPriority(--redcolor)= rgb(255, 0, 0) rgba(0, 0, 0, 0) diff --git a/Tests/LibWeb/Text/input/css/CSSStyleDeclaration-custom-properties.html b/Tests/LibWeb/Text/input/css/CSSStyleDeclaration-custom-properties.html index 929250da074..178d731bc29 100644 --- a/Tests/LibWeb/Text/input/css/CSSStyleDeclaration-custom-properties.html +++ b/Tests/LibWeb/Text/input/css/CSSStyleDeclaration-custom-properties.html @@ -6,6 +6,7 @@ const div = document.createElement('div'); div.style.setProperty("--redcolor", "red"); println(`style.getPropertyValue(--redcolor)=${div.style.getPropertyValue("--redcolor")}`); + println(`style.getPropertyPriority(--redcolor)=${div.style.getPropertyPriority("--redcolor")}`); const nested = document.createElement('div'); nested.style["backgroundColor"] = "var(--redcolor)";