/src/serenity/Userland/Libraries/LibWeb/UIEvents/PointerEvent.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2024, Shannon Booth <shannon@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibWeb/Bindings/PointerEventPrototype.h> |
8 | | #include <LibWeb/UIEvents/PointerEvent.h> |
9 | | |
10 | | namespace Web::UIEvents { |
11 | | |
12 | | JS_DEFINE_ALLOCATOR(PointerEvent); |
13 | | |
14 | | PointerEvent::PointerEvent(JS::Realm& realm, FlyString const& type, PointerEventInit const& event_init, double page_x, double page_y, double offset_x, double offset_y) |
15 | 0 | : MouseEvent(realm, type, event_init, page_x, page_y, offset_x, offset_y) |
16 | 0 | , m_pointer_id(event_init.pointer_id) |
17 | 0 | , m_width(event_init.width) |
18 | 0 | , m_height(event_init.height) |
19 | 0 | , m_pressure(event_init.pressure) |
20 | 0 | , m_tangential_pressure(event_init.tangential_pressure) |
21 | 0 | , m_tilt_x(event_init.tilt_x.value_or(0)) |
22 | 0 | , m_tilt_y(event_init.tilt_y.value_or(0)) |
23 | 0 | , m_twist(event_init.twist) |
24 | 0 | , m_altitude_angle(event_init.altitude_angle.value_or(DEFAULT_ALTITUDE_ANGLE)) |
25 | 0 | , m_azimuth_angle(event_init.azimuth_angle.value_or(0)) |
26 | 0 | , m_pointer_type(event_init.pointer_type) |
27 | 0 | , m_is_primary(event_init.is_primary) |
28 | 0 | , m_persistent_device_id(event_init.persistent_device_id) |
29 | 0 | { |
30 | 0 | m_coalesced_events.ensure_capacity(event_init.coalesced_events.size()); |
31 | 0 | for (auto const& coalesced_event : event_init.coalesced_events) |
32 | 0 | m_coalesced_events.unchecked_append(*coalesced_event); |
33 | |
|
34 | 0 | m_predicted_events.ensure_capacity(event_init.predicted_events.size()); |
35 | 0 | for (auto const& predicted_event : event_init.predicted_events) |
36 | 0 | m_predicted_events.unchecked_append(*predicted_event); |
37 | 0 | } |
38 | | |
39 | 0 | PointerEvent::~PointerEvent() = default; |
40 | | |
41 | | void PointerEvent::initialize(JS::Realm& realm) |
42 | 0 | { |
43 | 0 | Base::initialize(realm); |
44 | 0 | WEB_SET_PROTOTYPE_FOR_INTERFACE(PointerEvent); |
45 | 0 | } |
46 | | |
47 | | void PointerEvent::visit_edges(Cell::Visitor& visitor) |
48 | 0 | { |
49 | 0 | Base::visit_edges(visitor); |
50 | 0 | visitor.visit(m_coalesced_events); |
51 | 0 | visitor.visit(m_predicted_events); |
52 | 0 | } |
53 | | |
54 | | JS::NonnullGCPtr<PointerEvent> PointerEvent::create(JS::Realm& realm, FlyString const& type, PointerEventInit const& event_init, double page_x, double page_y, double offset_x, double offset_y) |
55 | 0 | { |
56 | 0 | return realm.heap().allocate<PointerEvent>(realm, realm, type, event_init, page_x, page_y, offset_x, offset_y); |
57 | 0 | } |
58 | | |
59 | | WebIDL::ExceptionOr<JS::NonnullGCPtr<PointerEvent>> PointerEvent::construct_impl(JS::Realm& realm, FlyString const& type, PointerEventInit const& event_init) |
60 | 0 | { |
61 | 0 | return create(realm, type, event_init); |
62 | 0 | } |
63 | | |
64 | | } |