Browse Source

LibWeb: Implement CSSStyleDeclaration.getPropertyValue(property)

Andreas Kling 3 years ago
parent
commit
a2f5589d3a

+ 11 - 0
Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp

@@ -91,4 +91,15 @@ bool PropertyOwningCSSStyleDeclaration::set_property(PropertyID property_id, Str
     return true;
     return true;
 }
 }
 
 
+String CSSStyleDeclaration::get_property_value(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->value->to_string();
+}
+
 }
 }

+ 2 - 0
Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h

@@ -34,6 +34,8 @@ public:
     virtual Optional<StyleProperty> property(PropertyID) const = 0;
     virtual Optional<StyleProperty> property(PropertyID) const = 0;
     virtual bool set_property(PropertyID, StringView css_text) = 0;
     virtual bool set_property(PropertyID, StringView css_text) = 0;
 
 
+    String get_property_value(StringView property) const;
+
 protected:
 protected:
     CSSStyleDeclaration() { }
     CSSStyleDeclaration() { }
 };
 };

+ 2 - 0
Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.idl

@@ -4,4 +4,6 @@ interface CSSStyleDeclaration {
     readonly attribute unsigned long length;
     readonly attribute unsigned long length;
     CSSOMString item(unsigned long index);
     CSSOMString item(unsigned long index);
 
 
+    CSSOMString getPropertyValue(CSSOMString property);
+
 };
 };