summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kaster <akaster@serenityos.org>2022-09-25 18:03:02 -0600
committerLinus Groh <mail@linusgroh.de>2022-10-01 21:05:32 +0100
commit62a8c26b73e874005c94969da9605fb9fd421b3c (patch)
treed50c0011291472bcbf849fef09f743e344a6b493
parentf0c5f77f99801441db1d8e99c14dae2ab1357b47 (diff)
downloadserenity-62a8c26b73e874005c94969da9605fb9fd421b3c.zip
LibWeb: Remove unecessary dependence on Window from Geometry classes
These classes only needed Window to get at its realm. Pass a realm directly to construct Geometry classes.
-rw-r--r--Userland/Libraries/LibWeb/DOM/Element.cpp8
-rw-r--r--Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp14
-rw-r--r--Userland/Libraries/LibWeb/Geometry/DOMPoint.h3
-rw-r--r--Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp12
-rw-r--r--Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h4
-rw-r--r--Userland/Libraries/LibWeb/Geometry/DOMRect.cpp16
-rw-r--r--Userland/Libraries/LibWeb/Geometry/DOMRect.h6
-rw-r--r--Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp10
-rw-r--r--Userland/Libraries/LibWeb/Geometry/DOMRectList.h4
-rw-r--r--Userland/Libraries/LibWeb/Geometry/DOMRectReadOnly.cpp12
-rw-r--r--Userland/Libraries/LibWeb/Geometry/DOMRectReadOnly.h4
11 files changed, 50 insertions, 43 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp
index df17923d9e..863d33d35d 100644
--- a/Userland/Libraries/LibWeb/DOM/Element.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Element.cpp
@@ -587,12 +587,12 @@ JS::NonnullGCPtr<Geometry::DOMRect> Element::get_bounding_client_rect() const
// FIXME: Support inline layout nodes as well.
auto* paint_box = this->paint_box();
if (!paint_box)
- return Geometry::DOMRect::create_with_global_object(window(), 0, 0, 0, 0);
+ return Geometry::DOMRect::construct_impl(realm(), 0, 0, 0, 0);
VERIFY(document().browsing_context());
auto viewport_offset = document().browsing_context()->viewport_scroll_offset();
- return Geometry::DOMRect::create(window(), paint_box->absolute_rect().translated(-viewport_offset.x(), -viewport_offset.y()));
+ return Geometry::DOMRect::create(realm(), paint_box->absolute_rect().translated(-viewport_offset.x(), -viewport_offset.y()));
}
// https://drafts.csswg.org/cssom-view/#dom-element-getclientrects
@@ -602,7 +602,7 @@ JS::NonnullGCPtr<Geometry::DOMRectList> Element::get_client_rects() const
// 1. If the element on which it was invoked does not have an associated layout box return an empty DOMRectList object and stop this algorithm.
if (!layout_node() || !layout_node()->is_box())
- return Geometry::DOMRectList::create(window(), move(rects));
+ return Geometry::DOMRectList::create(realm(), move(rects));
// FIXME: 2. If the element has an associated SVG layout box return a DOMRectList object containing a single DOMRect object that describes
// the bounding box of the element as defined by the SVG specification, applying the transforms that apply to the element and its ancestors.
@@ -616,7 +616,7 @@ JS::NonnullGCPtr<Geometry::DOMRectList> Element::get_client_rects() const
auto bounding_rect = get_bounding_client_rect();
rects.append(*bounding_rect);
- return Geometry::DOMRectList::create(window(), move(rects));
+ return Geometry::DOMRectList::create(realm(), move(rects));
}
int Element::client_top() const
diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp b/Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp
index 5b6ee78cd9..57d57cd903 100644
--- a/Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp
+++ b/Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp
@@ -4,20 +4,26 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Geometry/DOMPoint.h>
#include <LibWeb/HTML/Window.h>
namespace Web::Geometry {
+JS::NonnullGCPtr<DOMPoint> DOMPoint::construct_impl(JS::Realm& realm, double x, double y, double z, double w)
+{
+ return *realm.heap().allocate<DOMPoint>(realm, realm, x, y, z, w);
+}
+
JS::NonnullGCPtr<DOMPoint> DOMPoint::create_with_global_object(HTML::Window& window, double x, double y, double z, double w)
{
- return *window.heap().allocate<DOMPoint>(window.realm(), window, x, y, z, w);
+ return construct_impl(window.realm(), x, y, z, w);
}
-DOMPoint::DOMPoint(HTML::Window& window, double x, double y, double z, double w)
- : DOMPointReadOnly(window, x, y, z, w)
+DOMPoint::DOMPoint(JS::Realm& realm, double x, double y, double z, double w)
+ : DOMPointReadOnly(realm, x, y, z, w)
{
- set_prototype(&window.cached_web_prototype("DOMPoint"));
+ set_prototype(&Bindings::cached_web_prototype(realm, "DOMPoint"));
}
DOMPoint::~DOMPoint() = default;
diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPoint.h b/Userland/Libraries/LibWeb/Geometry/DOMPoint.h
index ef0ce1ba67..b4ade6d2dd 100644
--- a/Userland/Libraries/LibWeb/Geometry/DOMPoint.h
+++ b/Userland/Libraries/LibWeb/Geometry/DOMPoint.h
@@ -15,6 +15,7 @@ class DOMPoint final : public DOMPointReadOnly {
WEB_PLATFORM_OBJECT(DOMPoint, DOMPointReadOnly);
public:
+ static JS::NonnullGCPtr<DOMPoint> construct_impl(JS::Realm&, double x = 0, double y = 0, double z = 0, double w = 0);
static JS::NonnullGCPtr<DOMPoint> create_with_global_object(HTML::Window&, double x = 0, double y = 0, double z = 0, double w = 0);
virtual ~DOMPoint() override;
@@ -30,7 +31,7 @@ public:
void set_w(double w) { m_w = w; }
private:
- DOMPoint(HTML::Window&, double x, double y, double z, double w);
+ DOMPoint(JS::Realm&, double x, double y, double z, double w);
};
}
diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp
index aefd2d4cdb..7844540012 100644
--- a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp
+++ b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp
@@ -4,24 +4,24 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Geometry/DOMPointReadOnly.h>
-#include <LibWeb/HTML/Window.h>
namespace Web::Geometry {
-JS::NonnullGCPtr<DOMPointReadOnly> DOMPointReadOnly::create_with_global_object(HTML::Window& window, double x, double y, double z, double w)
+JS::NonnullGCPtr<DOMPointReadOnly> DOMPointReadOnly::construct_impl(JS::Realm& realm, double x, double y, double z, double w)
{
- return *window.heap().allocate<DOMPointReadOnly>(window.realm(), window, x, y, z, w);
+ return *realm.heap().allocate<DOMPointReadOnly>(realm, realm, x, y, z, w);
}
-DOMPointReadOnly::DOMPointReadOnly(HTML::Window& window, double x, double y, double z, double w)
- : PlatformObject(window.realm())
+DOMPointReadOnly::DOMPointReadOnly(JS::Realm& realm, double x, double y, double z, double w)
+ : PlatformObject(realm)
, m_x(x)
, m_y(y)
, m_z(z)
, m_w(w)
{
- set_prototype(&window.cached_web_prototype("DOMPointReadOnly"));
+ set_prototype(&Bindings::cached_web_prototype(realm, "DOMPointReadOnly"));
}
DOMPointReadOnly::~DOMPointReadOnly() = default;
diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h
index f512922cd9..1777bd6e13 100644
--- a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h
+++ b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h
@@ -17,7 +17,7 @@ class DOMPointReadOnly : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(DOMPointReadOnly, Bindings::PlatformObject);
public:
- static JS::NonnullGCPtr<DOMPointReadOnly> create_with_global_object(HTML::Window&, double x = 0, double y = 0, double z = 0, double w = 0);
+ static JS::NonnullGCPtr<DOMPointReadOnly> construct_impl(JS::Realm&, double x = 0, double y = 0, double z = 0, double w = 0);
virtual ~DOMPointReadOnly() override;
@@ -27,7 +27,7 @@ public:
double w() const { return m_w; }
protected:
- DOMPointReadOnly(HTML::Window&, double x, double y, double z, double w);
+ DOMPointReadOnly(JS::Realm&, double x, double y, double z, double w);
double m_x;
double m_y;
diff --git a/Userland/Libraries/LibWeb/Geometry/DOMRect.cpp b/Userland/Libraries/LibWeb/Geometry/DOMRect.cpp
index 202c13a9f5..aacadfb06a 100644
--- a/Userland/Libraries/LibWeb/Geometry/DOMRect.cpp
+++ b/Userland/Libraries/LibWeb/Geometry/DOMRect.cpp
@@ -4,25 +4,25 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Geometry/DOMRect.h>
-#include <LibWeb/HTML/Window.h>
namespace Web::Geometry {
-JS::NonnullGCPtr<DOMRect> DOMRect::create_with_global_object(HTML::Window& window, double x, double y, double width, double height)
+JS::NonnullGCPtr<DOMRect> DOMRect::construct_impl(JS::Realm& realm, double x, double y, double width, double height)
{
- return *window.heap().allocate<DOMRect>(window.realm(), window, x, y, width, height);
+ return *realm.heap().allocate<DOMRect>(realm, realm, x, y, width, height);
}
-JS::NonnullGCPtr<DOMRect> DOMRect::create(HTML::Window& window, Gfx::FloatRect const& rect)
+JS::NonnullGCPtr<DOMRect> DOMRect::create(JS::Realm& realm, Gfx::FloatRect const& rect)
{
- return create_with_global_object(window, rect.x(), rect.y(), rect.width(), rect.height());
+ return construct_impl(realm, rect.x(), rect.y(), rect.width(), rect.height());
}
-DOMRect::DOMRect(HTML::Window& window, double x, double y, double width, double height)
- : DOMRectReadOnly(window, x, y, width, height)
+DOMRect::DOMRect(JS::Realm& realm, double x, double y, double width, double height)
+ : DOMRectReadOnly(realm, x, y, width, height)
{
- set_prototype(&window.cached_web_prototype("DOMRect"));
+ set_prototype(&Bindings::cached_web_prototype(realm, "DOMRect"));
}
DOMRect::~DOMRect() = default;
diff --git a/Userland/Libraries/LibWeb/Geometry/DOMRect.h b/Userland/Libraries/LibWeb/Geometry/DOMRect.h
index 25523ce6c9..babc4897b3 100644
--- a/Userland/Libraries/LibWeb/Geometry/DOMRect.h
+++ b/Userland/Libraries/LibWeb/Geometry/DOMRect.h
@@ -15,8 +15,8 @@ class DOMRect final : public DOMRectReadOnly {
WEB_PLATFORM_OBJECT(DOMRect, DOMRectReadOnly);
public:
- static JS::NonnullGCPtr<DOMRect> create_with_global_object(HTML::Window&, double x = 0, double y = 0, double width = 0, double height = 0);
- static JS::NonnullGCPtr<DOMRect> create(HTML::Window&, Gfx::FloatRect const&);
+ static JS::NonnullGCPtr<DOMRect> construct_impl(JS::Realm&, double x = 0, double y = 0, double width = 0, double height = 0);
+ static JS::NonnullGCPtr<DOMRect> create(JS::Realm&, Gfx::FloatRect const&);
virtual ~DOMRect() override;
@@ -31,7 +31,7 @@ public:
void set_height(double height) { m_rect.set_height(height); }
private:
- DOMRect(HTML::Window&, double x, double y, double width, double height);
+ DOMRect(JS::Realm&, double x, double y, double width, double height);
};
}
diff --git a/Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp b/Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp
index c0888e5124..0e60ddb281 100644
--- a/Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp
+++ b/Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp
@@ -5,22 +5,22 @@
*/
#include <LibJS/Heap/Handle.h>
+#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Geometry/DOMRect.h>
#include <LibWeb/Geometry/DOMRectList.h>
-#include <LibWeb/HTML/Window.h>
namespace Web::Geometry {
-JS::NonnullGCPtr<DOMRectList> DOMRectList::create(HTML::Window& window, Vector<JS::Handle<DOMRect>> rect_handles)
+JS::NonnullGCPtr<DOMRectList> DOMRectList::create(JS::Realm& realm, Vector<JS::Handle<DOMRect>> rect_handles)
{
Vector<JS::NonnullGCPtr<DOMRect>> rects;
for (auto& rect : rect_handles)
rects.append(*rect);
- return *window.heap().allocate<DOMRectList>(window.realm(), window, move(rects));
+ return *realm.heap().allocate<DOMRectList>(realm, realm, move(rects));
}
-DOMRectList::DOMRectList(HTML::Window& window, Vector<JS::NonnullGCPtr<DOMRect>> rects)
- : Bindings::LegacyPlatformObject(window.cached_web_prototype("DOMRectList"))
+DOMRectList::DOMRectList(JS::Realm& realm, Vector<JS::NonnullGCPtr<DOMRect>> rects)
+ : Bindings::LegacyPlatformObject(Bindings::cached_web_prototype(realm, "DOMRectList"))
, m_rects(move(rects))
{
}
diff --git a/Userland/Libraries/LibWeb/Geometry/DOMRectList.h b/Userland/Libraries/LibWeb/Geometry/DOMRectList.h
index c77c3aded9..0eaccfcee9 100644
--- a/Userland/Libraries/LibWeb/Geometry/DOMRectList.h
+++ b/Userland/Libraries/LibWeb/Geometry/DOMRectList.h
@@ -17,7 +17,7 @@ class DOMRectList final : public Bindings::LegacyPlatformObject {
WEB_PLATFORM_OBJECT(DOMRectList, Bindings::LegacyPlatformObject);
public:
- static JS::NonnullGCPtr<DOMRectList> create(HTML::Window&, Vector<JS::Handle<DOMRect>>);
+ static JS::NonnullGCPtr<DOMRectList> create(JS::Realm&, Vector<JS::Handle<DOMRect>>);
virtual ~DOMRectList() override;
@@ -28,7 +28,7 @@ public:
virtual JS::Value item_value(size_t index) const override;
private:
- DOMRectList(HTML::Window&, Vector<JS::NonnullGCPtr<DOMRect>>);
+ DOMRectList(JS::Realm&, Vector<JS::NonnullGCPtr<DOMRect>>);
Vector<JS::NonnullGCPtr<DOMRect>> m_rects;
};
diff --git a/Userland/Libraries/LibWeb/Geometry/DOMRectReadOnly.cpp b/Userland/Libraries/LibWeb/Geometry/DOMRectReadOnly.cpp
index 27d5a09c27..681df18913 100644
--- a/Userland/Libraries/LibWeb/Geometry/DOMRectReadOnly.cpp
+++ b/Userland/Libraries/LibWeb/Geometry/DOMRectReadOnly.cpp
@@ -4,21 +4,21 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Geometry/DOMRectReadOnly.h>
-#include <LibWeb/HTML/Window.h>
namespace Web::Geometry {
-JS::NonnullGCPtr<DOMRectReadOnly> DOMRectReadOnly::create_with_global_object(HTML::Window& window, double x, double y, double width, double height)
+JS::NonnullGCPtr<DOMRectReadOnly> DOMRectReadOnly::construct_impl(JS::Realm& realm, double x, double y, double width, double height)
{
- return *window.heap().allocate<DOMRectReadOnly>(window.realm(), window, x, y, width, height);
+ return *realm.heap().allocate<DOMRectReadOnly>(realm, realm, x, y, width, height);
}
-DOMRectReadOnly::DOMRectReadOnly(HTML::Window& window, double x, double y, double width, double height)
- : PlatformObject(window.realm())
+DOMRectReadOnly::DOMRectReadOnly(JS::Realm& realm, double x, double y, double width, double height)
+ : PlatformObject(realm)
, m_rect(x, y, width, height)
{
- set_prototype(&window.cached_web_prototype("DOMRectReadOnly"));
+ set_prototype(&Bindings::cached_web_prototype(realm, "DOMRectReadOnly"));
}
DOMRectReadOnly::~DOMRectReadOnly() = default;
diff --git a/Userland/Libraries/LibWeb/Geometry/DOMRectReadOnly.h b/Userland/Libraries/LibWeb/Geometry/DOMRectReadOnly.h
index 595be796e1..e34665faa6 100644
--- a/Userland/Libraries/LibWeb/Geometry/DOMRectReadOnly.h
+++ b/Userland/Libraries/LibWeb/Geometry/DOMRectReadOnly.h
@@ -17,7 +17,7 @@ class DOMRectReadOnly : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(DOMRectReadOnly, Bindings::PlatformObject);
public:
- static JS::NonnullGCPtr<DOMRectReadOnly> create_with_global_object(HTML::Window&, double x = 0, double y = 0, double width = 0, double height = 0);
+ static JS::NonnullGCPtr<DOMRectReadOnly> construct_impl(JS::Realm&, double x = 0, double y = 0, double width = 0, double height = 0);
virtual ~DOMRectReadOnly() override;
@@ -32,7 +32,7 @@ public:
double left() const { return min(x(), x() + width()); }
protected:
- DOMRectReadOnly(HTML::Window&, double x, double y, double width, double height);
+ DOMRectReadOnly(JS::Realm&, double x, double y, double width, double height);
Gfx::FloatRect m_rect;
};