diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp b/Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp index b05be1517a..c6fd9c84a6 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp +++ b/Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2022, Andreas Kling + * Copyright (c) 2022, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -20,6 +21,13 @@ DOMPoint::DOMPoint(JS::Realm& realm, double x, double y, double z, double w) set_prototype(&Bindings::cached_web_prototype(realm, "DOMPoint")); } +// https://drafts.fxtf.org/geometry/#dom-dompoint-frompoint +JS::NonnullGCPtr DOMPoint::from_point(JS::VM& vm, DOMPointInit const& other) +{ + // The fromPoint(other) static method on DOMPoint must create a DOMPoint from the dictionary other. + return construct_impl(*vm.current_realm(), other.x, other.y, other.z, other.w); +} + DOMPoint::~DOMPoint() = default; } diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPoint.h b/Userland/Libraries/LibWeb/Geometry/DOMPoint.h index cec9c3ffc3..c758d2784c 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMPoint.h +++ b/Userland/Libraries/LibWeb/Geometry/DOMPoint.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Andreas Kling + * Copyright (c) 2022, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -17,6 +18,8 @@ class DOMPoint final : public DOMPointReadOnly { public: static JS::NonnullGCPtr construct_impl(JS::Realm&, double x = 0, double y = 0, double z = 0, double w = 1); + static JS::NonnullGCPtr from_point(JS::VM&, DOMPointInit const&); + virtual ~DOMPoint() override; double x() const { return m_x; } diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPoint.idl b/Userland/Libraries/LibWeb/Geometry/DOMPoint.idl index 1a030782d5..99378ec9bf 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMPoint.idl +++ b/Userland/Libraries/LibWeb/Geometry/DOMPoint.idl @@ -6,7 +6,7 @@ interface DOMPoint : DOMPointReadOnly { constructor(optional unrestricted double x = 0, optional unrestricted double y = 0, optional unrestricted double z = 0, optional unrestricted double w = 1); - // FIXME: [NewObject] static DOMPoint fromPoint(optional DOMPointInit other = {}); + [NewObject] static DOMPoint fromPoint(optional DOMPointInit other = {}); inherit attribute unrestricted double x; inherit attribute unrestricted double y; diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp index 7844540012..7258beabd2 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp +++ b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2022, Andreas Kling + * Copyright (c) 2022, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -24,6 +25,13 @@ DOMPointReadOnly::DOMPointReadOnly(JS::Realm& realm, double x, double y, double set_prototype(&Bindings::cached_web_prototype(realm, "DOMPointReadOnly")); } +// https://drafts.fxtf.org/geometry/#dom-dompointreadonly-frompoint +JS::NonnullGCPtr DOMPointReadOnly::from_point(JS::VM& vm, DOMPointInit const& other) +{ + // The fromPoint(other) static method on DOMPointReadOnly must create a DOMPointReadOnly from the dictionary other. + return construct_impl(*vm.current_realm(), other.x, other.y, other.z, other.w); +} + DOMPointReadOnly::~DOMPointReadOnly() = default; } diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h index 276c0ce399..aadc16f202 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h +++ b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2022, Andreas Kling + * Copyright (c) 2022, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -12,6 +13,13 @@ namespace Web::Geometry { +struct DOMPointInit { + double x { 0 }; + double y { 0 }; + double z { 0 }; + double w { 1 }; +}; + // https://drafts.fxtf.org/geometry/#dompointreadonly class DOMPointReadOnly : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(DOMPointReadOnly, Bindings::PlatformObject); @@ -19,6 +27,8 @@ class DOMPointReadOnly : public Bindings::PlatformObject { public: static JS::NonnullGCPtr construct_impl(JS::Realm&, double x = 0, double y = 0, double z = 0, double w = 1); + static JS::NonnullGCPtr from_point(JS::VM&, DOMPointInit const&); + virtual ~DOMPointReadOnly() override; double x() const { return m_x; } diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.idl b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.idl index 5adc08851f..75053bb44e 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.idl +++ b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.idl @@ -4,7 +4,7 @@ interface DOMPointReadOnly { constructor(optional unrestricted double x = 0, optional unrestricted double y = 0, optional unrestricted double z = 0, optional unrestricted double w = 1); - // FIXME: [NewObject] static DOMPointReadOnly fromPoint(optional DOMPointInit other = {}); + [NewObject] static DOMPointReadOnly fromPoint(optional DOMPointInit other = {}); readonly attribute unrestricted double x; readonly attribute unrestricted double y; @@ -15,3 +15,10 @@ interface DOMPointReadOnly { // FIXME: [Default] object toJSON(); }; + +dictionary DOMPointInit { + unrestricted double x = 0; + unrestricted double y = 0; + unrestricted double z = 0; + unrestricted double w = 1; +};