mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-21 08:48:57 +00:00
LibWeb/CSS: Implement CSSImageValue and reify images as it
This is specced to be opaque, so there's not much to it.
This commit is contained in:
parent
eb39c0162c
commit
5904694844
Notes:
github-actions[bot]
2025-09-15 07:48:05 +00:00
Author: https://github.com/AtkinsSJ
Commit: 5904694844
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6176
10 changed files with 109 additions and 4 deletions
|
@ -110,6 +110,7 @@ set(SOURCES
|
||||||
CSS/CSSFontFaceDescriptors.cpp
|
CSS/CSSFontFaceDescriptors.cpp
|
||||||
CSS/CSSFontFaceRule.cpp
|
CSS/CSSFontFaceRule.cpp
|
||||||
CSS/CSSGroupingRule.cpp
|
CSS/CSSGroupingRule.cpp
|
||||||
|
CSS/CSSImageValue.cpp
|
||||||
CSS/CSSImportRule.cpp
|
CSS/CSSImportRule.cpp
|
||||||
CSS/CSSKeyframeRule.cpp
|
CSS/CSSKeyframeRule.cpp
|
||||||
CSS/CSSKeyframesRule.cpp
|
CSS/CSSKeyframesRule.cpp
|
||||||
|
@ -206,6 +207,7 @@ set(SOURCES
|
||||||
CSS/StyleSheet.cpp
|
CSS/StyleSheet.cpp
|
||||||
CSS/StyleSheetIdentifier.cpp
|
CSS/StyleSheetIdentifier.cpp
|
||||||
CSS/StyleSheetList.cpp
|
CSS/StyleSheetList.cpp
|
||||||
|
CSS/StyleValues/AbstractImageStyleValue.cpp
|
||||||
CSS/StyleValues/AnchorStyleValue.cpp
|
CSS/StyleValues/AnchorStyleValue.cpp
|
||||||
CSS/StyleValues/AnchorSizeStyleValue.cpp
|
CSS/StyleValues/AnchorSizeStyleValue.cpp
|
||||||
CSS/StyleValues/AngleStyleValue.cpp
|
CSS/StyleValues/AngleStyleValue.cpp
|
||||||
|
|
40
Libraries/LibWeb/CSS/CSSImageValue.cpp
Normal file
40
Libraries/LibWeb/CSS/CSSImageValue.cpp
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "CSSImageValue.h"
|
||||||
|
#include <LibWeb/Bindings/CSSImageValuePrototype.h>
|
||||||
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
|
|
||||||
|
namespace Web::CSS {
|
||||||
|
|
||||||
|
GC_DEFINE_ALLOCATOR(CSSImageValue);
|
||||||
|
|
||||||
|
GC::Ref<CSSImageValue> CSSImageValue::create(JS::Realm& realm, String constructed_from_string)
|
||||||
|
{
|
||||||
|
return realm.create<CSSImageValue>(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
33
Libraries/LibWeb/CSS/CSSImageValue.h
Normal file
33
Libraries/LibWeb/CSS/CSSImageValue.h
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibWeb/CSS/CSSStyleValue.h>
|
||||||
|
|
||||||
|
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<CSSImageValue> 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;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
6
Libraries/LibWeb/CSS/CSSImageValue.idl
Normal file
6
Libraries/LibWeb/CSS/CSSImageValue.idl
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#import <CSS/CSSStyleValue.idl>
|
||||||
|
|
||||||
|
// https://drafts.css-houdini.org/css-typed-om-1/#cssimagevalue
|
||||||
|
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)]
|
||||||
|
interface CSSImageValue : CSSStyleValue {
|
||||||
|
};
|
19
Libraries/LibWeb/CSS/StyleValues/AbstractImageStyleValue.cpp
Normal file
19
Libraries/LibWeb/CSS/StyleValues/AbstractImageStyleValue.cpp
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "AbstractImageStyleValue.h"
|
||||||
|
#include <LibWeb/CSS/CSSImageValue.h>
|
||||||
|
|
||||||
|
namespace Web::CSS {
|
||||||
|
|
||||||
|
// https://drafts.css-houdini.org/css-typed-om-1/#reify-stylevalue
|
||||||
|
GC::Ref<CSSStyleValue> 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -40,6 +40,8 @@ public:
|
||||||
virtual void paint(DisplayListRecordingContext& context, DevicePixelRect const& dest_rect, ImageRendering) const = 0;
|
virtual void paint(DisplayListRecordingContext& context, DevicePixelRect const& dest_rect, ImageRendering) const = 0;
|
||||||
|
|
||||||
virtual Optional<Gfx::Color> color_if_single_pixel_bitmap() const { return {}; }
|
virtual Optional<Gfx::Color> color_if_single_pixel_bitmap() const { return {}; }
|
||||||
|
|
||||||
|
virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, String const& associated_property) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
// And now, some gradient related things. Maybe these should live somewhere else.
|
// And now, some gradient related things. Maybe these should live somewhere else.
|
||||||
|
|
|
@ -235,6 +235,7 @@ class CSSDescriptors;
|
||||||
class CSSFontFaceDescriptors;
|
class CSSFontFaceDescriptors;
|
||||||
class CSSFontFaceRule;
|
class CSSFontFaceRule;
|
||||||
class CSSGroupingRule;
|
class CSSGroupingRule;
|
||||||
|
class CSSImageValue;
|
||||||
class CSSImportRule;
|
class CSSImportRule;
|
||||||
class CSSKeyframeRule;
|
class CSSKeyframeRule;
|
||||||
class CSSKeyframesRule;
|
class CSSKeyframesRule;
|
||||||
|
|
|
@ -29,6 +29,7 @@ libweb_js_bindings(CSS/CSSCounterStyleRule)
|
||||||
libweb_js_bindings(CSS/CSSFontFaceDescriptors)
|
libweb_js_bindings(CSS/CSSFontFaceDescriptors)
|
||||||
libweb_js_bindings(CSS/CSSFontFaceRule)
|
libweb_js_bindings(CSS/CSSFontFaceRule)
|
||||||
libweb_js_bindings(CSS/CSSGroupingRule)
|
libweb_js_bindings(CSS/CSSGroupingRule)
|
||||||
|
libweb_js_bindings(CSS/CSSImageValue)
|
||||||
libweb_js_bindings(CSS/CSSImportRule)
|
libweb_js_bindings(CSS/CSSImportRule)
|
||||||
libweb_js_bindings(CSS/CSSKeyframeRule)
|
libweb_js_bindings(CSS/CSSKeyframeRule)
|
||||||
libweb_js_bindings(CSS/CSSKeyframesRule)
|
libweb_js_bindings(CSS/CSSKeyframesRule)
|
||||||
|
|
|
@ -42,6 +42,7 @@ CSSCounterStyleRule
|
||||||
CSSFontFaceDescriptors
|
CSSFontFaceDescriptors
|
||||||
CSSFontFaceRule
|
CSSFontFaceRule
|
||||||
CSSGroupingRule
|
CSSGroupingRule
|
||||||
|
CSSImageValue
|
||||||
CSSImportRule
|
CSSImportRule
|
||||||
CSSKeyframeRule
|
CSSKeyframeRule
|
||||||
CSSKeyframesRule
|
CSSKeyframesRule
|
||||||
|
|
|
@ -2,7 +2,7 @@ Harness status: OK
|
||||||
|
|
||||||
Found 3 tests
|
Found 3 tests
|
||||||
|
|
||||||
3 Fail
|
3 Pass
|
||||||
Fail Normalizing a valid <url> returns a CSSImageValue
|
Pass Normalizing a valid <url> returns a CSSImageValue
|
||||||
Fail Normalizing a bad <url> returns a CSSImageValue
|
Pass Normalizing a bad <url> returns a CSSImageValue
|
||||||
Fail Normalizing a <gradient> returns a CSSImageValue
|
Pass Normalizing a <gradient> returns a CSSImageValue
|
Loading…
Add table
Add a link
Reference in a new issue