2022-09-04 01:59:58 +02:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2022-09-04 01:59:58 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2024-04-27 12:09:58 +12:00
|
|
|
#include <LibWeb/Bindings/DOMRectPrototype.h>
|
2022-09-25 18:03:02 -06:00
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2022-09-04 01:59:58 +02:00
|
|
|
#include <LibWeb/Geometry/DOMRect.h>
|
2023-02-19 18:21:27 +01:00
|
|
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
2022-09-04 01:59:58 +02:00
|
|
|
|
|
|
|
namespace Web::Geometry {
|
|
|
|
|
2023-11-19 19:47:52 +01:00
|
|
|
JS_DEFINE_ALLOCATOR(DOMRect);
|
|
|
|
|
2023-02-19 18:21:27 +01:00
|
|
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> DOMRect::construct_impl(JS::Realm& realm, double x, double y, double width, double height)
|
2022-09-04 01:59:58 +02:00
|
|
|
{
|
2023-08-13 13:05:26 +02:00
|
|
|
return create(realm, Gfx::FloatRect { x, y, width, height });
|
2022-09-04 01:59:58 +02:00
|
|
|
}
|
|
|
|
|
2023-08-13 13:05:26 +02:00
|
|
|
JS::NonnullGCPtr<DOMRect> DOMRect::create(JS::Realm& realm, Gfx::FloatRect const& rect)
|
2022-09-04 01:59:58 +02:00
|
|
|
{
|
2023-08-13 13:05:26 +02:00
|
|
|
return realm.heap().allocate<DOMRect>(realm, realm, rect.x(), rect.y(), rect.width(), rect.height());
|
2022-09-04 01:59:58 +02:00
|
|
|
}
|
|
|
|
|
2024-03-10 09:43:00 +01:00
|
|
|
JS::NonnullGCPtr<DOMRect> DOMRect::create(JS::Realm& realm)
|
|
|
|
{
|
|
|
|
return realm.heap().allocate<DOMRect>(realm, realm);
|
|
|
|
}
|
|
|
|
|
2023-07-06 23:21:20 +01:00
|
|
|
// https://drafts.fxtf.org/geometry/#create-a-domrect-from-the-dictionary
|
2023-08-13 13:05:26 +02:00
|
|
|
JS::NonnullGCPtr<DOMRect> DOMRect::from_rect(JS::VM& vm, Geometry::DOMRectInit const& other)
|
2023-07-06 23:21:20 +01:00
|
|
|
{
|
|
|
|
auto& realm = *vm.current_realm();
|
2023-08-13 13:05:26 +02:00
|
|
|
return realm.heap().allocate<DOMRect>(realm, realm, other.x, other.y, other.width, other.height);
|
2023-07-06 23:21:20 +01:00
|
|
|
}
|
|
|
|
|
2022-09-25 18:03:02 -06:00
|
|
|
DOMRect::DOMRect(JS::Realm& realm, double x, double y, double width, double height)
|
|
|
|
: DOMRectReadOnly(realm, x, y, width, height)
|
2022-09-04 01:59:58 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-03-10 09:43:00 +01:00
|
|
|
DOMRect::DOMRect(JS::Realm& realm)
|
|
|
|
: DOMRectReadOnly(realm)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-09-04 01:59:58 +02:00
|
|
|
DOMRect::~DOMRect() = default;
|
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
void DOMRect::initialize(JS::Realm& realm)
|
2023-01-10 06:28:20 -05:00
|
|
|
{
|
2023-08-07 08:41:28 +02:00
|
|
|
Base::initialize(realm);
|
2024-03-16 13:13:08 +01:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(DOMRect);
|
2023-01-10 06:28:20 -05:00
|
|
|
}
|
|
|
|
|
2022-09-04 01:59:58 +02:00
|
|
|
}
|