/src/serenity/Userland/Libraries/LibWeb/Geometry/DOMRect.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibWeb/Bindings/DOMRectPrototype.h> |
8 | | #include <LibWeb/Bindings/Intrinsics.h> |
9 | | #include <LibWeb/Geometry/DOMRect.h> |
10 | | #include <LibWeb/WebIDL/ExceptionOr.h> |
11 | | |
12 | | namespace Web::Geometry { |
13 | | |
14 | | JS_DEFINE_ALLOCATOR(DOMRect); |
15 | | |
16 | | WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> DOMRect::construct_impl(JS::Realm& realm, double x, double y, double width, double height) |
17 | 0 | { |
18 | 0 | return create(realm, Gfx::FloatRect { x, y, width, height }); |
19 | 0 | } |
20 | | |
21 | | JS::NonnullGCPtr<DOMRect> DOMRect::create(JS::Realm& realm, Gfx::FloatRect const& rect) |
22 | 0 | { |
23 | 0 | return realm.heap().allocate<DOMRect>(realm, realm, rect.x(), rect.y(), rect.width(), rect.height()); |
24 | 0 | } |
25 | | |
26 | | JS::NonnullGCPtr<DOMRect> DOMRect::create(JS::Realm& realm) |
27 | 0 | { |
28 | 0 | return realm.heap().allocate<DOMRect>(realm, realm); |
29 | 0 | } |
30 | | |
31 | | // https://drafts.fxtf.org/geometry/#create-a-domrect-from-the-dictionary |
32 | | JS::NonnullGCPtr<DOMRect> DOMRect::from_rect(JS::VM& vm, Geometry::DOMRectInit const& other) |
33 | 0 | { |
34 | 0 | auto& realm = *vm.current_realm(); |
35 | 0 | return realm.heap().allocate<DOMRect>(realm, realm, other.x, other.y, other.width, other.height); |
36 | 0 | } |
37 | | |
38 | | DOMRect::DOMRect(JS::Realm& realm, double x, double y, double width, double height) |
39 | 0 | : DOMRectReadOnly(realm, x, y, width, height) |
40 | 0 | { |
41 | 0 | } |
42 | | |
43 | | DOMRect::DOMRect(JS::Realm& realm) |
44 | 0 | : DOMRectReadOnly(realm) |
45 | 0 | { |
46 | 0 | } |
47 | | |
48 | 0 | DOMRect::~DOMRect() = default; |
49 | | |
50 | | void DOMRect::initialize(JS::Realm& realm) |
51 | 0 | { |
52 | 0 | Base::initialize(realm); |
53 | 0 | WEB_SET_PROTOTYPE_FOR_INTERFACE(DOMRect); |
54 | 0 | } |
55 | | |
56 | | } |