From b3c4b4fd971034517bd79e947b932a024f6b2965 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 7 Dec 2024 01:10:11 +0100 Subject: [PATCH] LibWeb: Serialize resolved CSS values in dedicated serialization mode This doesn't actually do anything differently yet, but it will in the very next commit. --- Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp | 10 +++++++--- Libraries/LibWeb/CSS/CSSStyleDeclaration.h | 3 +++ Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h | 2 ++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp b/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp index 29e0c5576fc..8012796cd3d 100644 --- a/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp @@ -271,7 +271,9 @@ String CSSStyleDeclaration::get_property_value(StringView property_name) const 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 maybe_custom_property.value().value->to_string(Web::CSS::CSSStyleValue::SerializationMode::Normal); + return maybe_custom_property.value().value->to_string( + computed_flag() ? Web::CSS::CSSStyleValue::SerializationMode::ResolvedValue + : Web::CSS::CSSStyleValue::SerializationMode::Normal); } return {}; } @@ -302,7 +304,7 @@ String CSSStyleDeclaration::get_property_value(StringView property_name) const // 3. If important flags of all declarations in list are same, then return the serialization of list. // NOTE: Currently we implement property-specific shorthand serialization in ShorthandStyleValue::to_string(). - return ShorthandStyleValue::create(property_id.value(), longhand_ids, list)->to_string(CSSStyleValue::SerializationMode::Normal); + return ShorthandStyleValue::create(property_id.value(), longhand_ids, list)->to_string(computed_flag() ? CSSStyleValue::SerializationMode::ResolvedValue : CSSStyleValue::SerializationMode::Normal); // 4. Return the empty string. // NOTE: This is handled by the loop. @@ -311,7 +313,9 @@ String CSSStyleDeclaration::get_property_value(StringView property_name) const auto maybe_property = property(property_id.value()); if (!maybe_property.has_value()) return {}; - return maybe_property->value->to_string(Web::CSS::CSSStyleValue::SerializationMode::Normal); + return maybe_property->value->to_string( + computed_flag() ? Web::CSS::CSSStyleValue::SerializationMode::ResolvedValue + : Web::CSS::CSSStyleValue::SerializationMode::Normal); } // https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-getpropertypriority diff --git a/Libraries/LibWeb/CSS/CSSStyleDeclaration.h b/Libraries/LibWeb/CSS/CSSStyleDeclaration.h index be6b6765f81..251f2a4263c 100644 --- a/Libraries/LibWeb/CSS/CSSStyleDeclaration.h +++ b/Libraries/LibWeb/CSS/CSSStyleDeclaration.h @@ -50,6 +50,9 @@ public: virtual GC::Ptr parent_rule() const; + // https://drafts.csswg.org/cssom/#cssstyledeclaration-computed-flag + [[nodiscard]] virtual bool computed_flag() const { return false; } + protected: explicit CSSStyleDeclaration(JS::Realm&); diff --git a/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h b/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h index 459965d090d..beb40f92cf2 100644 --- a/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h +++ b/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h @@ -38,6 +38,8 @@ private: virtual void visit_edges(Cell::Visitor&) override; + virtual bool computed_flag() const override { return true; } + RefPtr style_value_for_property(Layout::NodeWithStyle const&, PropertyID) const; GC::Ref m_element;