1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 16:08:10 +00:00

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.
This commit is contained in:
Andrew Kaster 2022-09-25 18:03:02 -06:00 committed by Linus Groh
parent f0c5f77f99
commit 62a8c26b73
11 changed files with 51 additions and 44 deletions

View file

@ -587,12 +587,12 @@ JS::NonnullGCPtr<Geometry::DOMRect> Element::get_bounding_client_rect() const
// FIXME: Support inline layout nodes as well. // FIXME: Support inline layout nodes as well.
auto* paint_box = this->paint_box(); auto* paint_box = this->paint_box();
if (!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()); VERIFY(document().browsing_context());
auto viewport_offset = document().browsing_context()->viewport_scroll_offset(); 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 // 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. // 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()) 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 // 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. // 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(); auto bounding_rect = get_bounding_client_rect();
rects.append(*bounding_rect); rects.append(*bounding_rect);
return Geometry::DOMRectList::create(window(), move(rects)); return Geometry::DOMRectList::create(realm(), move(rects));
} }
int Element::client_top() const int Element::client_top() const

View file

@ -4,20 +4,26 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Geometry/DOMPoint.h> #include <LibWeb/Geometry/DOMPoint.h>
#include <LibWeb/HTML/Window.h> #include <LibWeb/HTML/Window.h>
namespace Web::Geometry { namespace Web::Geometry {
JS::NonnullGCPtr<DOMPoint> DOMPoint::create_with_global_object(HTML::Window& window, double x, double y, double z, double w) JS::NonnullGCPtr<DOMPoint> DOMPoint::construct_impl(JS::Realm& realm, double x, double y, double z, double w)
{ {
return *window.heap().allocate<DOMPoint>(window.realm(), window, x, y, z, w); return *realm.heap().allocate<DOMPoint>(realm, realm, x, y, z, w);
} }
DOMPoint::DOMPoint(HTML::Window& window, double x, double y, double z, double w) JS::NonnullGCPtr<DOMPoint> DOMPoint::create_with_global_object(HTML::Window& window, double x, double y, double z, double w)
: DOMPointReadOnly(window, x, y, z, w)
{ {
set_prototype(&window.cached_web_prototype("DOMPoint")); return construct_impl(window.realm(), 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(&Bindings::cached_web_prototype(realm, "DOMPoint"));
} }
DOMPoint::~DOMPoint() = default; DOMPoint::~DOMPoint() = default;

View file

@ -15,6 +15,7 @@ class DOMPoint final : public DOMPointReadOnly {
WEB_PLATFORM_OBJECT(DOMPoint, DOMPointReadOnly); WEB_PLATFORM_OBJECT(DOMPoint, DOMPointReadOnly);
public: 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); 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; virtual ~DOMPoint() override;
@ -30,7 +31,7 @@ public:
void set_w(double w) { m_w = w; } void set_w(double w) { m_w = w; }
private: private:
DOMPoint(HTML::Window&, double x, double y, double z, double w); DOMPoint(JS::Realm&, double x, double y, double z, double w);
}; };
} }

View file

@ -4,24 +4,24 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Geometry/DOMPointReadOnly.h> #include <LibWeb/Geometry/DOMPointReadOnly.h>
#include <LibWeb/HTML/Window.h>
namespace Web::Geometry { 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) DOMPointReadOnly::DOMPointReadOnly(JS::Realm& realm, double x, double y, double z, double w)
: PlatformObject(window.realm()) : PlatformObject(realm)
, m_x(x) , m_x(x)
, m_y(y) , m_y(y)
, m_z(z) , m_z(z)
, m_w(w) , m_w(w)
{ {
set_prototype(&window.cached_web_prototype("DOMPointReadOnly")); set_prototype(&Bindings::cached_web_prototype(realm, "DOMPointReadOnly"));
} }
DOMPointReadOnly::~DOMPointReadOnly() = default; DOMPointReadOnly::~DOMPointReadOnly() = default;

View file

@ -17,7 +17,7 @@ class DOMPointReadOnly : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(DOMPointReadOnly, Bindings::PlatformObject); WEB_PLATFORM_OBJECT(DOMPointReadOnly, Bindings::PlatformObject);
public: 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; virtual ~DOMPointReadOnly() override;
@ -27,7 +27,7 @@ public:
double w() const { return m_w; } double w() const { return m_w; }
protected: 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_x;
double m_y; double m_y;

View file

@ -4,25 +4,25 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Geometry/DOMRect.h> #include <LibWeb/Geometry/DOMRect.h>
#include <LibWeb/HTML/Window.h>
namespace Web::Geometry { 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) DOMRect::DOMRect(JS::Realm& realm, double x, double y, double width, double height)
: DOMRectReadOnly(window, x, y, width, 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; DOMRect::~DOMRect() = default;

View file

@ -15,8 +15,8 @@ class DOMRect final : public DOMRectReadOnly {
WEB_PLATFORM_OBJECT(DOMRect, DOMRectReadOnly); WEB_PLATFORM_OBJECT(DOMRect, DOMRectReadOnly);
public: 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> construct_impl(JS::Realm&, 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> create(JS::Realm&, Gfx::FloatRect const&);
virtual ~DOMRect() override; virtual ~DOMRect() override;
@ -31,7 +31,7 @@ public:
void set_height(double height) { m_rect.set_height(height); } void set_height(double height) { m_rect.set_height(height); }
private: private:
DOMRect(HTML::Window&, double x, double y, double width, double height); DOMRect(JS::Realm&, double x, double y, double width, double height);
}; };
} }

View file

@ -5,22 +5,22 @@
*/ */
#include <LibJS/Heap/Handle.h> #include <LibJS/Heap/Handle.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Geometry/DOMRect.h> #include <LibWeb/Geometry/DOMRect.h>
#include <LibWeb/Geometry/DOMRectList.h> #include <LibWeb/Geometry/DOMRectList.h>
#include <LibWeb/HTML/Window.h>
namespace Web::Geometry { 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; Vector<JS::NonnullGCPtr<DOMRect>> rects;
for (auto& rect : rect_handles) for (auto& rect : rect_handles)
rects.append(*rect); 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) DOMRectList::DOMRectList(JS::Realm& realm, Vector<JS::NonnullGCPtr<DOMRect>> rects)
: Bindings::LegacyPlatformObject(window.cached_web_prototype("DOMRectList")) : Bindings::LegacyPlatformObject(Bindings::cached_web_prototype(realm, "DOMRectList"))
, m_rects(move(rects)) , m_rects(move(rects))
{ {
} }

View file

@ -17,7 +17,7 @@ class DOMRectList final : public Bindings::LegacyPlatformObject {
WEB_PLATFORM_OBJECT(DOMRectList, Bindings::LegacyPlatformObject); WEB_PLATFORM_OBJECT(DOMRectList, Bindings::LegacyPlatformObject);
public: 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; virtual ~DOMRectList() override;
@ -28,7 +28,7 @@ public:
virtual JS::Value item_value(size_t index) const override; virtual JS::Value item_value(size_t index) const override;
private: private:
DOMRectList(HTML::Window&, Vector<JS::NonnullGCPtr<DOMRect>>); DOMRectList(JS::Realm&, Vector<JS::NonnullGCPtr<DOMRect>>);
Vector<JS::NonnullGCPtr<DOMRect>> m_rects; Vector<JS::NonnullGCPtr<DOMRect>> m_rects;
}; };

View file

@ -4,21 +4,21 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Geometry/DOMRectReadOnly.h> #include <LibWeb/Geometry/DOMRectReadOnly.h>
#include <LibWeb/HTML/Window.h>
namespace Web::Geometry { 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) DOMRectReadOnly::DOMRectReadOnly(JS::Realm& realm, double x, double y, double width, double height)
: PlatformObject(window.realm()) : PlatformObject(realm)
, m_rect(x, y, width, height) , m_rect(x, y, width, height)
{ {
set_prototype(&window.cached_web_prototype("DOMRectReadOnly")); set_prototype(&Bindings::cached_web_prototype(realm, "DOMRectReadOnly"));
} }
DOMRectReadOnly::~DOMRectReadOnly() = default; DOMRectReadOnly::~DOMRectReadOnly() = default;

View file

@ -17,7 +17,7 @@ class DOMRectReadOnly : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(DOMRectReadOnly, Bindings::PlatformObject); WEB_PLATFORM_OBJECT(DOMRectReadOnly, Bindings::PlatformObject);
public: 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; virtual ~DOMRectReadOnly() override;
@ -32,7 +32,7 @@ public:
double left() const { return min(x(), x() + width()); } double left() const { return min(x(), x() + width()); }
protected: 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; Gfx::FloatRect m_rect;
}; };