LibWeb: Implement SVGLengthList

This commit is contained in:
Jelle Raaijmakers 2025-11-19 13:03:48 +01:00 committed by Andreas Kling
parent 832e953c67
commit 797e6dd4eb
Notes: github-actions[bot] 2025-11-20 22:16:40 +00:00
11 changed files with 126 additions and 18 deletions

View file

@ -0,0 +1,49 @@
/*
* Copyright (c) 2025, Jelle Raaijmakers <jelle@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/SVGLengthListPrototype.h>
#include <LibWeb/SVG/SVGLengthList.h>
namespace Web::SVG {
GC_DEFINE_ALLOCATOR(SVGLengthList);
GC::Ref<SVGLengthList> SVGLengthList::create(JS::Realm& realm, Vector<GC::Ref<SVGLength>> items, ReadOnlyList read_only)
{
return realm.create<SVGLengthList>(realm, move(items), read_only);
}
GC::Ref<SVGLengthList> SVGLengthList::create(JS::Realm& realm, ReadOnlyList read_only)
{
return realm.create<SVGLengthList>(realm, read_only);
}
SVGLengthList::SVGLengthList(JS::Realm& realm, Vector<GC::Ref<SVGLength>> items, ReadOnlyList read_only)
: Bindings::PlatformObject(realm)
, SVGList(realm, move(items), read_only)
{
}
SVGLengthList::SVGLengthList(JS::Realm& realm, ReadOnlyList read_only)
: Bindings::PlatformObject(realm)
, SVGList(realm, read_only)
{
}
void SVGLengthList::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGLengthList);
Base::initialize(realm);
}
void SVGLengthList::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
SVGList::visit_edges(visitor);
}
}

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2025, Jelle Raaijmakers <jelle@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/SVG/SVGLength.h>
#include <LibWeb/SVG/SVGList.h>
namespace Web::SVG {
// https://svgwg.org/svg2-draft/types.html#InterfaceSVGLengthList
class SVGLengthList final
: public Bindings::PlatformObject
, public SVGList<GC::Ref<SVGLength>> {
WEB_PLATFORM_OBJECT(SVGLengthList, Bindings::PlatformObject);
GC_DECLARE_ALLOCATOR(SVGLengthList);
public:
[[nodiscard]] static GC::Ref<SVGLengthList> create(JS::Realm& realm, Vector<GC::Ref<SVGLength>>, ReadOnlyList);
[[nodiscard]] static GC::Ref<SVGLengthList> create(JS::Realm& realm, ReadOnlyList);
virtual ~SVGLengthList() override = default;
private:
SVGLengthList(JS::Realm&, Vector<GC::Ref<SVGLength>>, ReadOnlyList);
SVGLengthList(JS::Realm&, ReadOnlyList);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Visitor&) override;
};
}

View file

@ -0,0 +1,18 @@
#import <SVG/SVGLength.idl>
// https://svgwg.org/svg2-draft/types.html#InterfaceSVGLengthList
[Exposed=Window]
interface SVGLengthList {
readonly attribute unsigned long length;
readonly attribute unsigned long numberOfItems;
undefined clear();
SVGLength initialize(SVGLength newItem);
getter SVGLength getItem(unsigned long index);
SVGLength insertItemBefore(SVGLength newItem, unsigned long index);
SVGLength replaceItem(SVGLength newItem, unsigned long index);
SVGLength removeItem(unsigned long index);
SVGLength appendItem(SVGLength newItem);
setter undefined (unsigned long index, SVGLength newItem);
};

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/SVG/SVGLength.h>
#include <LibWeb/SVG/SVGList.h>
#include <LibWeb/SVG/SVGNumber.h>
#include <LibWeb/SVG/SVGTransform.h>
@ -204,6 +205,7 @@ WebIDL::ExceptionOr<T> SVGList<T>::append_item(T new_item)
return new_item;
}
template class SVGList<GC::Ref<SVGLength>>;
template class SVGList<GC::Ref<SVGNumber>>;
template class SVGList<GC::Ref<SVGTransform>>;

View file

@ -8,7 +8,6 @@
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/SVGTransformListPrototype.h>
#include <LibWeb/SVG/SVGTransformList.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::SVG {