diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 5b021d25a1..c8ec1861e0 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -135,6 +135,8 @@ set(SOURCES FileAPI/Blob.cpp FileAPI/File.cpp FontCache.cpp + Geometry/DOMPoint.cpp + Geometry/DOMPointReadOnly.cpp Geometry/DOMRectList.cpp HTML/AttributeNames.cpp HTML/BrowsingContext.cpp diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 3ac0532c63..0bc45acf27 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -451,8 +451,6 @@ namespace Web::Bindings { class BlobWrapper; class CryptoWrapper; class DOMExceptionWrapper; -class DOMPointWrapper; -class DOMPointReadOnlyWrapper; class DOMRectListWrapper; class DOMRectReadOnlyWrapper; class DOMRectWrapper; diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp b/Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp new file mode 100644 index 0000000000..5b6ee78cd9 --- /dev/null +++ b/Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2022, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Web::Geometry { + +JS::NonnullGCPtr DOMPoint::create_with_global_object(HTML::Window& window, double x, double y, double z, double w) +{ + return *window.heap().allocate(window.realm(), window, x, y, z, w); +} + +DOMPoint::DOMPoint(HTML::Window& window, double x, double y, double z, double w) + : DOMPointReadOnly(window, x, y, z, w) +{ + set_prototype(&window.cached_web_prototype("DOMPoint")); +} + +DOMPoint::~DOMPoint() = default; + +} diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPoint.h b/Userland/Libraries/LibWeb/Geometry/DOMPoint.h index ccea076ebb..cf0b8e3956 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMPoint.h +++ b/Userland/Libraries/LibWeb/Geometry/DOMPoint.h @@ -12,18 +12,12 @@ namespace Web::Geometry { // https://drafts.fxtf.org/geometry/#DOMPoint class DOMPoint final : public DOMPointReadOnly { + WEB_PLATFORM_OBJECT(DOMPoint, DOMPointReadOnly); + public: - using WrapperType = Bindings::DOMPointWrapper; + static JS::NonnullGCPtr create_with_global_object(HTML::Window&, double x = 0, double y = 0, double z = 0, double w = 0); - static NonnullRefPtr create_with_global_object(HTML::Window&, double x = 0, double y = 0, double z = 0, double w = 0) - { - return DOMPoint::create(x, y, z, w); - } - - static NonnullRefPtr create(double x = 0, double y = 0, double z = 0, double w = 0) - { - return adopt_ref(*new DOMPoint(x, y, z, w)); - } + virtual ~DOMPoint() override; double x() const { return m_x; } double y() const { return m_y; } @@ -36,9 +30,9 @@ public: void set_w(double w) { m_w = w; } private: - DOMPoint(float x, float y, float z, float w) - : DOMPointReadOnly(x, y, z, w) - { - } + DOMPoint(HTML::Window&, double x, double y, double z, double w); }; + } + +WRAPPER_HACK(DOMPoint, Web::Geometry) diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp new file mode 100644 index 0000000000..aefd2d4cdb --- /dev/null +++ b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Web::Geometry { + +JS::NonnullGCPtr DOMPointReadOnly::create_with_global_object(HTML::Window& window, double x, double y, double z, double w) +{ + return *window.heap().allocate(window.realm(), window, x, y, z, w); +} + +DOMPointReadOnly::DOMPointReadOnly(HTML::Window& window, double x, double y, double z, double w) + : PlatformObject(window.realm()) + , m_x(x) + , m_y(y) + , m_z(z) + , m_w(w) +{ + set_prototype(&window.cached_web_prototype("DOMPointReadOnly")); +} + +DOMPointReadOnly::~DOMPointReadOnly() = default; + +} diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h index b9587058ae..47b5aba7f8 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h +++ b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h @@ -6,29 +6,20 @@ #pragma once -#include #include -#include +#include #include namespace Web::Geometry { // https://drafts.fxtf.org/geometry/#dompointreadonly -class DOMPointReadOnly - : public RefCounted - , public Bindings::Wrappable { +class DOMPointReadOnly : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(DOMPointReadOnly, Bindings::PlatformObject); + public: - using WrapperType = Bindings::DOMPointReadOnlyWrapper; + static JS::NonnullGCPtr create_with_global_object(HTML::Window&, double x = 0, double y = 0, double z = 0, double w = 0); - static NonnullRefPtr create_with_global_object(HTML::Window&, double x = 0, double y = 0, double z = 0, double w = 0) - { - return DOMPointReadOnly::create(x, y, z, w); - } - - static NonnullRefPtr create(double x = 0, double y = 0, double z = 0, double w = 0) - { - return adopt_ref(*new DOMPointReadOnly(x, y, z, w)); - } + virtual ~DOMPointReadOnly() override; double x() const { return m_x; } double y() const { return m_y; } @@ -36,13 +27,7 @@ public: double w() const { return m_w; } protected: - DOMPointReadOnly(double x, double y, double z, double w) - : m_x(x) - , m_y(y) - , m_z(z) - , m_w(w) - { - } + DOMPointReadOnly(HTML::Window&, double x, double y, double z, double w); double m_x; double m_y; @@ -51,3 +36,5 @@ protected: }; } + +WRAPPER_HACK(DOMPointReadOnly, Web::Geometry) diff --git a/Userland/Libraries/LibWeb/SVG/SVGGeometryElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGGeometryElement.cpp index 1fe2677c43..8485f50883 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGGeometryElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGGeometryElement.cpp @@ -26,10 +26,10 @@ float SVGGeometryElement::get_total_length() return 0; } -NonnullRefPtr SVGGeometryElement::get_point_at_length(float distance) +JS::NonnullGCPtr SVGGeometryElement::get_point_at_length(float distance) { (void)distance; - return Geometry::DOMPoint::create(0, 0, 0, 0); + return Geometry::DOMPoint::create_with_global_object(window(), 0, 0, 0, 0); } } diff --git a/Userland/Libraries/LibWeb/SVG/SVGGeometryElement.h b/Userland/Libraries/LibWeb/SVG/SVGGeometryElement.h index f72ef382fe..92e2d206ce 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGGeometryElement.h +++ b/Userland/Libraries/LibWeb/SVG/SVGGeometryElement.h @@ -21,7 +21,7 @@ public: virtual Gfx::Path& get_path() = 0; float get_total_length(); - NonnullRefPtr get_point_at_length(float distance); + JS::NonnullGCPtr get_point_at_length(float distance); protected: SVGGeometryElement(DOM::Document& document, DOM::QualifiedName qualified_name); diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 223c62c0a7..702abe154a 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -56,8 +56,8 @@ libweb_js_wrapper(Encoding/TextEncoder) libweb_js_wrapper(Fetch/Headers ITERABLE) libweb_js_wrapper(FileAPI/Blob) libweb_js_wrapper(FileAPI/File) -libweb_js_wrapper(Geometry/DOMPoint) -libweb_js_wrapper(Geometry/DOMPointReadOnly) +libweb_js_wrapper(Geometry/DOMPoint NO_INSTANCE) +libweb_js_wrapper(Geometry/DOMPointReadOnly NO_INSTANCE) libweb_js_wrapper(Geometry/DOMRect) libweb_js_wrapper(Geometry/DOMRectList) libweb_js_wrapper(Geometry/DOMRectReadOnly)