PointerEvent.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/PointerEventPrototype.h>
  7. #include <LibWeb/UIEvents/PointerEvent.h>
  8. namespace Web::UIEvents {
  9. JS_DEFINE_ALLOCATOR(PointerEvent);
  10. PointerEvent::PointerEvent(JS::Realm& realm, FlyString const& type, PointerEventInit const& event_init, double page_x, double page_y, double offset_x, double offset_y)
  11. : MouseEvent(realm, type, event_init, page_x, page_y, offset_x, offset_y)
  12. , m_pointer_id(event_init.pointer_id)
  13. , m_width(event_init.width)
  14. , m_height(event_init.height)
  15. , m_pressure(event_init.pressure)
  16. , m_tangential_pressure(event_init.tangential_pressure)
  17. , m_tilt_x(event_init.tilt_x.value_or(0))
  18. , m_tilt_y(event_init.tilt_y.value_or(0))
  19. , m_twist(event_init.twist)
  20. , m_altitude_angle(event_init.altitude_angle.value_or(DEFAULT_ALTITUDE_ANGLE))
  21. , m_azimuth_angle(event_init.azimuth_angle.value_or(0))
  22. , m_pointer_type(event_init.pointer_type)
  23. , m_is_primary(event_init.is_primary)
  24. {
  25. }
  26. PointerEvent::~PointerEvent() = default;
  27. void PointerEvent::initialize(JS::Realm& realm)
  28. {
  29. Base::initialize(realm);
  30. WEB_SET_PROTOTYPE_FOR_INTERFACE(PointerEvent);
  31. }
  32. 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)
  33. {
  34. return realm.heap().allocate<PointerEvent>(realm, realm, type, event_init, page_x, page_y, offset_x, offset_y);
  35. }
  36. WebIDL::ExceptionOr<JS::NonnullGCPtr<PointerEvent>> PointerEvent::construct_impl(JS::Realm& realm, FlyString const& type, PointerEventInit const& event_init)
  37. {
  38. return create(realm, type, event_init);
  39. }
  40. }