diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt index f2606377fa9..2bf2855ad97 100644 --- a/Libraries/LibWeb/CMakeLists.txt +++ b/Libraries/LibWeb/CMakeLists.txt @@ -110,6 +110,7 @@ set(SOURCES CSS/CSSFontFaceDescriptors.cpp CSS/CSSFontFaceRule.cpp CSS/CSSGroupingRule.cpp + CSS/CSSImageValue.cpp CSS/CSSImportRule.cpp CSS/CSSKeyframeRule.cpp CSS/CSSKeyframesRule.cpp @@ -206,6 +207,7 @@ set(SOURCES CSS/StyleSheet.cpp CSS/StyleSheetIdentifier.cpp CSS/StyleSheetList.cpp + CSS/StyleValues/AbstractImageStyleValue.cpp CSS/StyleValues/AnchorStyleValue.cpp CSS/StyleValues/AnchorSizeStyleValue.cpp CSS/StyleValues/AngleStyleValue.cpp diff --git a/Libraries/LibWeb/CSS/CSSImageValue.cpp b/Libraries/LibWeb/CSS/CSSImageValue.cpp new file mode 100644 index 00000000000..3a9db429de2 --- /dev/null +++ b/Libraries/LibWeb/CSS/CSSImageValue.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2025, Sam Atkins + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "CSSImageValue.h" +#include +#include + +namespace Web::CSS { + +GC_DEFINE_ALLOCATOR(CSSImageValue); + +GC::Ref CSSImageValue::create(JS::Realm& realm, String constructed_from_string) +{ + return realm.create(realm, move(constructed_from_string)); +} + +CSSImageValue::CSSImageValue(JS::Realm& realm, String constructed_from_string) + : CSSStyleValue(realm) + , m_constructed_from_string(move(constructed_from_string)) +{ +} + +void CSSImageValue::initialize(JS::Realm& realm) +{ + WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSImageValue); + Base::initialize(realm); +} + +// https://drafts.css-houdini.org/css-typed-om-1/#stylevalue-serialization +String CSSImageValue::to_string() const +{ + // AD-HOC: The spec doesn't say how to serialize this, as it's intentionally a black box. + // We just serialize the source string that was used to construct this. + return m_constructed_from_string; +} + +} diff --git a/Libraries/LibWeb/CSS/CSSImageValue.h b/Libraries/LibWeb/CSS/CSSImageValue.h new file mode 100644 index 00000000000..29e95cd2346 --- /dev/null +++ b/Libraries/LibWeb/CSS/CSSImageValue.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025, Sam Atkins + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::CSS { + +// https://drafts.css-houdini.org/css-typed-om-1/#cssimagevalue +class CSSImageValue final : public CSSStyleValue { + WEB_PLATFORM_OBJECT(CSSImageValue, CSSStyleValue); + GC_DECLARE_ALLOCATOR(CSSImageValue); + +public: + [[nodiscard]] static GC::Ref create(JS::Realm&, String constructed_from_string); + + virtual ~CSSImageValue() override = default; + + virtual String to_string() const override; + +private: + explicit CSSImageValue(JS::Realm&, String constructed_from_string); + + virtual void initialize(JS::Realm&) override; + + String m_constructed_from_string; +}; + +} diff --git a/Libraries/LibWeb/CSS/CSSImageValue.idl b/Libraries/LibWeb/CSS/CSSImageValue.idl new file mode 100644 index 00000000000..fd50c8c5cee --- /dev/null +++ b/Libraries/LibWeb/CSS/CSSImageValue.idl @@ -0,0 +1,6 @@ +#import + +// https://drafts.css-houdini.org/css-typed-om-1/#cssimagevalue +[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] +interface CSSImageValue : CSSStyleValue { +}; diff --git a/Libraries/LibWeb/CSS/StyleValues/AbstractImageStyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/AbstractImageStyleValue.cpp new file mode 100644 index 00000000000..9e9db41eedf --- /dev/null +++ b/Libraries/LibWeb/CSS/StyleValues/AbstractImageStyleValue.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025, Sam Atkins + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "AbstractImageStyleValue.h" +#include + +namespace Web::CSS { + +// https://drafts.css-houdini.org/css-typed-om-1/#reify-stylevalue +GC::Ref AbstractImageStyleValue::reify(JS::Realm& realm, String const&) const +{ + // AD-HOC: There's no spec description of how to reify as a CSSImageValue. + return CSSImageValue::create(realm, to_string(SerializationMode::Normal)); +} + +} diff --git a/Libraries/LibWeb/CSS/StyleValues/AbstractImageStyleValue.h b/Libraries/LibWeb/CSS/StyleValues/AbstractImageStyleValue.h index d2856e07b87..632e0b0a3ae 100644 --- a/Libraries/LibWeb/CSS/StyleValues/AbstractImageStyleValue.h +++ b/Libraries/LibWeb/CSS/StyleValues/AbstractImageStyleValue.h @@ -40,6 +40,8 @@ public: virtual void paint(DisplayListRecordingContext& context, DevicePixelRect const& dest_rect, ImageRendering) const = 0; virtual Optional color_if_single_pixel_bitmap() const { return {}; } + + virtual GC::Ref reify(JS::Realm&, String const& associated_property) const override; }; // And now, some gradient related things. Maybe these should live somewhere else. diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h index 0b96c9e3bd6..659250d37c1 100644 --- a/Libraries/LibWeb/Forward.h +++ b/Libraries/LibWeb/Forward.h @@ -235,6 +235,7 @@ class CSSDescriptors; class CSSFontFaceDescriptors; class CSSFontFaceRule; class CSSGroupingRule; +class CSSImageValue; class CSSImportRule; class CSSKeyframeRule; class CSSKeyframesRule; diff --git a/Libraries/LibWeb/idl_files.cmake b/Libraries/LibWeb/idl_files.cmake index c40bd9bb0d4..68da1e5f80f 100644 --- a/Libraries/LibWeb/idl_files.cmake +++ b/Libraries/LibWeb/idl_files.cmake @@ -29,6 +29,7 @@ libweb_js_bindings(CSS/CSSCounterStyleRule) libweb_js_bindings(CSS/CSSFontFaceDescriptors) libweb_js_bindings(CSS/CSSFontFaceRule) libweb_js_bindings(CSS/CSSGroupingRule) +libweb_js_bindings(CSS/CSSImageValue) libweb_js_bindings(CSS/CSSImportRule) libweb_js_bindings(CSS/CSSKeyframeRule) libweb_js_bindings(CSS/CSSKeyframesRule) diff --git a/Tests/LibWeb/Text/expected/all-window-properties.txt b/Tests/LibWeb/Text/expected/all-window-properties.txt index b436751380a..115d2716150 100644 --- a/Tests/LibWeb/Text/expected/all-window-properties.txt +++ b/Tests/LibWeb/Text/expected/all-window-properties.txt @@ -42,6 +42,7 @@ CSSCounterStyleRule CSSFontFaceDescriptors CSSFontFaceRule CSSGroupingRule +CSSImageValue CSSImportRule CSSKeyframeRule CSSKeyframesRule diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/stylevalue-normalization/normalize-image.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/stylevalue-normalization/normalize-image.txt index e52cf2744dc..e1e6870f455 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/stylevalue-normalization/normalize-image.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/stylevalue-normalization/normalize-image.txt @@ -2,7 +2,7 @@ Harness status: OK Found 3 tests -3 Fail -Fail Normalizing a valid returns a CSSImageValue -Fail Normalizing a bad returns a CSSImageValue -Fail Normalizing a returns a CSSImageValue \ No newline at end of file +3 Pass +Pass Normalizing a valid returns a CSSImageValue +Pass Normalizing a bad returns a CSSImageValue +Pass Normalizing a returns a CSSImageValue \ No newline at end of file