Procházet zdrojové kódy

LibWeb: Implement DOMPoint/DOMPointReadOnly.fromPoint()

Sam Atkins před 2 roky
rodič
revize
ab19c5fab8

+ 8 - 0
Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp

@@ -1,5 +1,6 @@
 /*
 /*
  * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
  *
  *
  * SPDX-License-Identifier: BSD-2-Clause
  * 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"));
     set_prototype(&Bindings::cached_web_prototype(realm, "DOMPoint"));
 }
 }
 
 
+// https://drafts.fxtf.org/geometry/#dom-dompoint-frompoint
+JS::NonnullGCPtr<DOMPoint> 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;
 DOMPoint::~DOMPoint() = default;
 
 
 }
 }

+ 3 - 0
Userland/Libraries/LibWeb/Geometry/DOMPoint.h

@@ -1,5 +1,6 @@
 /*
 /*
  * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
  *
  *
  * SPDX-License-Identifier: BSD-2-Clause
  * SPDX-License-Identifier: BSD-2-Clause
  */
  */
@@ -17,6 +18,8 @@ class DOMPoint final : public DOMPointReadOnly {
 public:
 public:
     static JS::NonnullGCPtr<DOMPoint> construct_impl(JS::Realm&, double x = 0, double y = 0, double z = 0, double w = 1);
     static JS::NonnullGCPtr<DOMPoint> construct_impl(JS::Realm&, double x = 0, double y = 0, double z = 0, double w = 1);
 
 
+    static JS::NonnullGCPtr<DOMPoint> from_point(JS::VM&, DOMPointInit const&);
+
     virtual ~DOMPoint() override;
     virtual ~DOMPoint() override;
 
 
     double x() const { return m_x; }
     double x() const { return m_x; }

+ 1 - 1
Userland/Libraries/LibWeb/Geometry/DOMPoint.idl

@@ -6,7 +6,7 @@ interface DOMPoint : DOMPointReadOnly {
     constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
     constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
                 optional unrestricted double z = 0, optional unrestricted double w = 1);
                 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 x;
     inherit attribute unrestricted double y;
     inherit attribute unrestricted double y;

+ 8 - 0
Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp

@@ -1,5 +1,6 @@
 /*
 /*
  * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
  *
  *
  * SPDX-License-Identifier: BSD-2-Clause
  * 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"));
     set_prototype(&Bindings::cached_web_prototype(realm, "DOMPointReadOnly"));
 }
 }
 
 
+// https://drafts.fxtf.org/geometry/#dom-dompointreadonly-frompoint
+JS::NonnullGCPtr<DOMPointReadOnly> 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;
 DOMPointReadOnly::~DOMPointReadOnly() = default;
 
 
 }
 }

+ 10 - 0
Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h

@@ -1,5 +1,6 @@
 /*
 /*
  * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
  *
  *
  * SPDX-License-Identifier: BSD-2-Clause
  * SPDX-License-Identifier: BSD-2-Clause
  */
  */
@@ -12,6 +13,13 @@
 
 
 namespace Web::Geometry {
 namespace Web::Geometry {
 
 
+struct DOMPointInit {
+    double x { 0 };
+    double y { 0 };
+    double z { 0 };
+    double w { 1 };
+};
+
 // https://drafts.fxtf.org/geometry/#dompointreadonly
 // https://drafts.fxtf.org/geometry/#dompointreadonly
 class DOMPointReadOnly : public Bindings::PlatformObject {
 class DOMPointReadOnly : public Bindings::PlatformObject {
     WEB_PLATFORM_OBJECT(DOMPointReadOnly, Bindings::PlatformObject);
     WEB_PLATFORM_OBJECT(DOMPointReadOnly, Bindings::PlatformObject);
@@ -19,6 +27,8 @@ class DOMPointReadOnly : public Bindings::PlatformObject {
 public:
 public:
     static JS::NonnullGCPtr<DOMPointReadOnly> construct_impl(JS::Realm&, double x = 0, double y = 0, double z = 0, double w = 1);
     static JS::NonnullGCPtr<DOMPointReadOnly> construct_impl(JS::Realm&, double x = 0, double y = 0, double z = 0, double w = 1);
 
 
+    static JS::NonnullGCPtr<DOMPointReadOnly> from_point(JS::VM&, DOMPointInit const&);
+
     virtual ~DOMPointReadOnly() override;
     virtual ~DOMPointReadOnly() override;
 
 
     double x() const { return m_x; }
     double x() const { return m_x; }

+ 8 - 1
Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.idl

@@ -4,7 +4,7 @@ interface DOMPointReadOnly {
     constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
     constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
                 optional unrestricted double z = 0, optional unrestricted double w = 1);
                 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 x;
     readonly attribute unrestricted double y;
     readonly attribute unrestricted double y;
@@ -15,3 +15,10 @@ interface DOMPointReadOnly {
 
 
     // FIXME: [Default] object toJSON();
     // FIXME: [Default] object toJSON();
 };
 };
+
+dictionary DOMPointInit {
+    unrestricted double x = 0;
+    unrestricted double y = 0;
+    unrestricted double z = 0;
+    unrestricted double w = 1;
+};