From a0ba49a50ac80417c9cff3fc4f6cc17ed003f928 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 11 Apr 2022 20:48:50 +0200 Subject: [PATCH] LibWeb: Support CSSStyleDeclaration.getPropertyPriority() --- .../Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp | 12 ++++++++++++ Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h | 1 + .../Libraries/LibWeb/CSS/CSSStyleDeclaration.idl | 1 + 3 files changed, 14 insertions(+) diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp index d9807168c8..e8f094d52d 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp @@ -177,6 +177,18 @@ String CSSStyleDeclaration::get_property_value(StringView property_name) const return maybe_property->value->to_string(); } +// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-getpropertypriority +String CSSStyleDeclaration::get_property_priority(StringView property_name) const +{ + auto property_id = property_id_from_string(property_name); + if (property_id == CSS::PropertyID::Invalid) + return {}; + auto maybe_property = property(property_id); + if (!maybe_property.has_value()) + return {}; + return maybe_property->important == Important::Yes ? "important" : ""; +} + DOM::ExceptionOr CSSStyleDeclaration::set_property(StringView property_name, StringView css_text, StringView priority) { auto property_id = property_id_from_string(property_name); diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h index 0e43db3eaf..0da22ce5b5 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h @@ -45,6 +45,7 @@ public: DOM::ExceptionOr remove_property(StringView property_name); String get_property_value(StringView property) const; + String get_property_priority(StringView property) const; String css_text() const; void set_css_text(StringView); diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.idl b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.idl index 867d3bd1ed..c94c7ac1f3 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.idl +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.idl @@ -5,6 +5,7 @@ interface CSSStyleDeclaration { CSSOMString item(unsigned long index); CSSOMString getPropertyValue(CSSOMString property); + CSSOMString getPropertyPriority(CSSOMString property); [CEReactions] undefined setProperty(CSSOMString property, [LegacyNullToEmptyString] CSSOMString value, [LegacyNullToEmptyString] optional CSSOMString priority = ""); [CEReactions] CSSOMString removeProperty(CSSOMString property);