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