From 3bab4fbae9633d0ec7c6fc97cb6c7be166601ca0 Mon Sep 17 00:00:00 2001 From: MacDue Date: Sun, 31 Mar 2024 14:54:00 +0100 Subject: [PATCH] LibWeb: Stub out `SVGTransformList` --- Userland/Libraries/LibWeb/CMakeLists.txt | 1 + .../Libraries/LibWeb/SVG/SVGTransformList.cpp | 56 +++++++++++++++++++ .../Libraries/LibWeb/SVG/SVGTransformList.h | 38 +++++++++++++ .../Libraries/LibWeb/SVG/SVGTransformList.idl | 21 +++++++ Userland/Libraries/LibWeb/idl_files.cmake | 1 + 5 files changed, 117 insertions(+) create mode 100644 Userland/Libraries/LibWeb/SVG/SVGTransformList.cpp create mode 100644 Userland/Libraries/LibWeb/SVG/SVGTransformList.h create mode 100644 Userland/Libraries/LibWeb/SVG/SVGTransformList.idl diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 24a65967211..38000188006 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -623,6 +623,7 @@ set(SOURCES SVG/SVGTextPositioningElement.cpp SVG/SVGTitleElement.cpp SVG/SVGTransform.cpp + SVG/SVGTransformList.cpp SVG/SVGTSpanElement.cpp SVG/SVGUseElement.cpp SVG/TagNames.cpp diff --git a/Userland/Libraries/LibWeb/SVG/SVGTransformList.cpp b/Userland/Libraries/LibWeb/SVG/SVGTransformList.cpp new file mode 100644 index 00000000000..246bdde0988 --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGTransformList.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024, MacDue + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +namespace Web::SVG { + +JS_DEFINE_ALLOCATOR(SVGTransformList); + +JS::NonnullGCPtr SVGTransformList::create(JS::Realm& realm) +{ + return realm.heap().allocate(realm, realm); +} + +SVGTransformList::~SVGTransformList() = default; + +SVGTransformList::SVGTransformList(JS::Realm& realm) + : PlatformObject(realm) {}; + +// https://svgwg.org/svg2-draft/single-page.html#types-__svg__SVGNameList__getItem +WebIDL::ExceptionOr> SVGTransformList::get_item(WebIDL::UnsignedLong index) +{ + // 1. If index is greater than or equal to the length of the list, then throw an IndexSizeError. + if (index >= m_transforms.size()) + return WebIDL::IndexSizeError::create(realm(), "SVGTransformList index out of bounds"_fly_string); + // 2. Return the element in the list at position index. + return m_transforms.at(index); +} + +// https://svgwg.org/svg2-draft/single-page.html#types-__svg__SVGNameList__appendItem +JS::NonnullGCPtr SVGTransformList::append_item(JS::NonnullGCPtr new_item) +{ + // FIXME: This does not implement the steps from the specification. + m_transforms.append(new_item); + return new_item; +} + +void SVGTransformList::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGTransformList); +} + +void SVGTransformList::visit_edges(Cell::Visitor& visitor) +{ + Base::visit_edges(visitor); + for (auto transform : m_transforms) + transform->visit_edges(visitor); +} + +} diff --git a/Userland/Libraries/LibWeb/SVG/SVGTransformList.h b/Userland/Libraries/LibWeb/SVG/SVGTransformList.h new file mode 100644 index 00000000000..e4f2b213161 --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGTransformList.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024, MacDue + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include + +namespace Web::SVG { + +// https://svgwg.org/svg2-draft/single-page.html#coords-InterfaceSVGTransformList +class SVGTransformList final : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(SVGTransformList, Bindings::PlatformObject); + JS_DECLARE_ALLOCATOR(SVGTransformList); + +public: + [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm& realm); + virtual ~SVGTransformList() override; + + WebIDL::ExceptionOr> get_item(WebIDL::UnsignedLong index); + + JS::NonnullGCPtr append_item(JS::NonnullGCPtr new_item); + +private: + SVGTransformList(JS::Realm& realm); + + virtual void initialize(JS::Realm& realm) override; + virtual void visit_edges(Cell::Visitor& visitor) override; + + Vector> m_transforms; +}; + +} diff --git a/Userland/Libraries/LibWeb/SVG/SVGTransformList.idl b/Userland/Libraries/LibWeb/SVG/SVGTransformList.idl new file mode 100644 index 00000000000..0bfdda1d3c0 --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGTransformList.idl @@ -0,0 +1,21 @@ +#import + +// https://svgwg.org/svg2-draft/single-page.html#coords-InterfaceSVGTransformList +[Exposed=Window] +interface SVGTransformList { + // FIXME: readonly attribute unsigned long length; + // FIXME: readonly attribute unsigned long numberOfItems; + + // FIXME: undefined clear(); + // FIXME: SVGTransform initialize(SVGTransform newItem); + getter SVGTransform getItem(unsigned long index); + // FIXME: SVGTransform insertItemBefore(SVGTransform newItem, unsigned long index); + // FIXME: SVGTransform replaceItem(SVGTransform newItem, unsigned long index); + // FIXME: SVGTransform removeItem(unsigned long index); + SVGTransform appendItem(SVGTransform newItem); + // FIXME: setter undefined (unsigned long index, SVGTransform newItem); + + // Additional methods not common to other list interfaces. + // FIXME: SVGTransform createSVGTransformFromMatrix(optional DOMMatrix2DInit matrix = {}); + // FIXME: SVGTransform? consolidate(); +}; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 6e930a8c8ed..2fc8e6420ae 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -270,6 +270,7 @@ libweb_js_bindings(SVG/SVGTextPathElement) libweb_js_bindings(SVG/SVGTextPositioningElement) libweb_js_bindings(SVG/SVGTitleElement) libweb_js_bindings(SVG/SVGTransform) +libweb_js_bindings(SVG/SVGTransformList) libweb_js_bindings(SVG/SVGTSpanElement) libweb_js_bindings(SVG/SVGUseElement) libweb_js_bindings(Selection/Selection)