LibWeb/CSS: Implement CSSTransformComponent

This is a base type for the various transform functions.

CSSMatrixComponent's to_string() can throw exceptions, so to_string() is
implemented that way. https://github.com/w3c/fxtf-drafts/issues/611

+9 WPT subtests.
This commit is contained in:
Sam Atkins 2025-09-12 16:32:58 +01:00
commit 8e86bf2dd0
Notes: github-actions[bot] 2025-09-24 11:29:53 +00:00
9 changed files with 95 additions and 11 deletions

View file

@ -142,6 +142,7 @@ set(SOURCES
CSS/CSSStyleSheet.cpp
CSS/CSSStyleValue.cpp
CSS/CSSSupportsRule.cpp
CSS/CSSTransformComponent.cpp
CSS/CSSTransition.cpp
CSS/CSSUnitValue.cpp
CSS/CSSUnparsedValue.cpp

View file

@ -0,0 +1,29 @@
/*
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "CSSTransformComponent.h"
#include <LibWeb/Bindings/CSSTransformComponentPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
namespace Web::CSS {
GC_DEFINE_ALLOCATOR(CSSTransformComponent);
CSSTransformComponent::CSSTransformComponent(JS::Realm& realm, Is2D is_2d)
: Bindings::PlatformObject(realm)
, m_is_2d(is_2d == Is2D::Yes)
{
}
CSSTransformComponent::~CSSTransformComponent() = default;
void CSSTransformComponent::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSTransformComponent);
Base::initialize(realm);
}
}

View file

@ -0,0 +1,41 @@
/*
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Bindings/PlatformObject.h>
namespace Web::CSS {
// https://drafts.css-houdini.org/css-typed-om-1/#csstransformcomponent
class CSSTransformComponent : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(CSSTransformComponent, Bindings::PlatformObject);
GC_DECLARE_ALLOCATOR(CSSTransformComponent);
public:
enum class Is2D : u8 {
No,
Yes,
};
virtual void initialize(JS::Realm&) override;
virtual ~CSSTransformComponent() override;
virtual WebIDL::ExceptionOr<Utf16String> to_string() const = 0;
bool is_2d() const { return m_is_2d; }
virtual void set_is_2d(bool value) { m_is_2d = value; }
virtual WebIDL::ExceptionOr<GC::Ref<Geometry::DOMMatrix>> to_matrix() const = 0;
protected:
explicit CSSTransformComponent(JS::Realm&, Is2D is_2d);
private:
bool m_is_2d;
};
}

View file

@ -0,0 +1,9 @@
#import <Geometry/DOMMatrix.idl>
// https://drafts.css-houdini.org/css-typed-om-1/#csstransformcomponent
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)]
interface CSSTransformComponent {
stringifier;
[ImplementedAs=is_2d] attribute boolean is2D;
DOMMatrix toMatrix();
};

View file

@ -267,6 +267,7 @@ class CSSStyleRule;
class CSSStyleSheet;
class CSSStyleValue;
class CSSSupportsRule;
class CSSTransformComponent;
class CSSUnitValue;
class CSSUnparsedValue;
class CSSVariableReferenceValue;

View file

@ -62,6 +62,7 @@ libweb_js_bindings(CSS/CSSStyleRule)
libweb_js_bindings(CSS/CSSStyleSheet)
libweb_js_bindings(CSS/CSSStyleValue)
libweb_js_bindings(CSS/CSSSupportsRule)
libweb_js_bindings(CSS/CSSTransformComponent)
libweb_js_bindings(CSS/CSSTransition)
libweb_js_bindings(CSS/CSSUnitValue)
libweb_js_bindings(CSS/CSSUnparsedValue)

View file

@ -58,6 +58,7 @@ static bool is_platform_object(Type const& type)
"CSSNumericArray"sv,
"CSSNumericValue"sv,
"CSSStyleValue"sv,
"CSSTransformComponent"sv,
"CSSUnitValue"sv,
"CSSUnparsedValue"sv,
"CSSVariableReferenceValue"sv,

View file

@ -74,6 +74,7 @@ CSSStyleRule
CSSStyleSheet
CSSStyleValue
CSSSupportsRule
CSSTransformComponent
CSSTransition
CSSUnitValue
CSSUnparsedValue

View file

@ -2,8 +2,8 @@ Harness status: OK
Found 545 tests
287 Pass
258 Fail
296 Pass
249 Fail
Pass idl_test setup
Pass idl_test validation
Pass Partial interface Element: original interface defined
@ -267,15 +267,15 @@ Pass CSSStyleValue interface: transformValue must inherit property "parse(USVStr
Pass CSSStyleValue interface: calling parse(USVString, USVString) on transformValue with too few arguments must throw TypeError
Pass CSSStyleValue interface: transformValue must inherit property "parseAll(USVString, USVString)" with the proper type
Pass CSSStyleValue interface: calling parseAll(USVString, USVString) on transformValue with too few arguments must throw TypeError
Fail CSSTransformComponent interface: existence and properties of interface object
Fail CSSTransformComponent interface object length
Fail CSSTransformComponent interface object name
Fail CSSTransformComponent interface: existence and properties of interface prototype object
Fail CSSTransformComponent interface: existence and properties of interface prototype object's "constructor" property
Fail CSSTransformComponent interface: existence and properties of interface prototype object's @@unscopables property
Fail CSSTransformComponent interface: stringifier
Fail CSSTransformComponent interface: attribute is2D
Fail CSSTransformComponent interface: operation toMatrix()
Pass CSSTransformComponent interface: existence and properties of interface object
Pass CSSTransformComponent interface object length
Pass CSSTransformComponent interface object name
Pass CSSTransformComponent interface: existence and properties of interface prototype object
Pass CSSTransformComponent interface: existence and properties of interface prototype object's "constructor" property
Pass CSSTransformComponent interface: existence and properties of interface prototype object's @@unscopables property
Pass CSSTransformComponent interface: stringifier
Pass CSSTransformComponent interface: attribute is2D
Pass CSSTransformComponent interface: operation toMatrix()
Fail CSSTranslate interface: existence and properties of interface object
Fail CSSTranslate interface object length
Fail CSSTranslate interface object name