mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 12:15:14 +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:
parent
f0c5f77f99
commit
62a8c26b73
11 changed files with 51 additions and 44 deletions
|
@ -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
|
||||
|
|
|
@ -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::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)
|
||||
: DOMPointReadOnly(window, x, y, z, w)
|
||||
JS::NonnullGCPtr<DOMPoint> DOMPoint::create_with_global_object(HTML::Window& window, double x, double y, double z, double 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;
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue