LibWeb: Add PointerEvent.getCoalescedEvents() and .getPredictedEvents()

Fixes at least 4 WPT subtests in /pointerevents.
This commit is contained in:
Jelle Raaijmakers 2024-10-18 11:26:00 +02:00 committed by Tim Flynn
commit 27928cd28c
Notes: github-actions[bot] 2024-10-21 11:38:58 +00:00
3 changed files with 29 additions and 4 deletions

View file

@ -27,6 +27,13 @@ PointerEvent::PointerEvent(JS::Realm& realm, FlyString const& type, PointerEvent
, m_is_primary(event_init.is_primary)
, m_persistent_device_id(event_init.persistent_device_id)
{
m_coalesced_events.ensure_capacity(event_init.coalesced_events.size());
for (auto const& coalesced_event : event_init.coalesced_events)
m_coalesced_events.unchecked_append(*coalesced_event);
m_predicted_events.ensure_capacity(event_init.predicted_events.size());
for (auto const& predicted_event : event_init.predicted_events)
m_predicted_events.unchecked_append(*predicted_event);
}
PointerEvent::~PointerEvent() = default;
@ -37,6 +44,13 @@ void PointerEvent::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE(PointerEvent);
}
void PointerEvent::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_coalesced_events);
visitor.visit(m_predicted_events);
}
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)
{
return realm.heap().allocate<PointerEvent>(realm, realm, type, event_init, page_x, page_y, offset_x, offset_y);

View file

@ -25,6 +25,8 @@ struct PointerEventInit : public MouseEventInit {
String pointer_type;
bool is_primary { false };
WebIDL::Long persistent_device_id { 0 };
AK::Vector<JS::Handle<PointerEvent>> coalesced_events;
AK::Vector<JS::Handle<PointerEvent>> predicted_events;
};
// https://w3c.github.io/pointerevents/#pointerevent-interface
@ -51,6 +53,8 @@ public:
String const& pointer_type() const { return m_pointer_type; }
bool is_primary() const { return m_is_primary; }
WebIDL::Long persistent_device_id() const { return m_persistent_device_id; }
AK::ReadonlySpan<JS::NonnullGCPtr<PointerEvent>> get_coalesced_events() const { return m_coalesced_events; }
AK::ReadonlySpan<JS::NonnullGCPtr<PointerEvent>> get_predicted_events() const { return m_predicted_events; }
// https://w3c.github.io/pointerevents/#dom-pointerevent-pressure
// For hardware and platforms that do not support pressure, the value MUST be 0.5 when in the active buttons state and 0 otherwise.
@ -60,6 +64,7 @@ protected:
PointerEvent(JS::Realm&, FlyString const& type, PointerEventInit const&, double page_x, double page_y, double offset_x, double offset_y);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
private:
virtual bool is_pointer_event() const final { return true; }
@ -125,6 +130,12 @@ private:
// A unique identifier for the pointing device.
// https://w3c.github.io/pointerevents/#dom-pointerevent-persistentdeviceid
WebIDL::Long m_persistent_device_id { 0 };
// https://w3c.github.io/pointerevents/#dom-pointerevent-getcoalescedevents
AK::Vector<JS::NonnullGCPtr<PointerEvent>> m_coalesced_events;
// https://w3c.github.io/pointerevents/#dom-pointerevent-getpredictedevents
AK::Vector<JS::NonnullGCPtr<PointerEvent>> m_predicted_events;
};
}

View file

@ -15,8 +15,8 @@ dictionary PointerEventInit : MouseEventInit {
DOMString pointerType = "";
boolean isPrimary = false;
long persistentDeviceId = 0;
// FIXME: sequence<PointerEvent> coalescedEvents = [];
// FIXME: sequence<PointerEvent> predictedEvents = [];
sequence<PointerEvent> coalescedEvents = [];
sequence<PointerEvent> predictedEvents = [];
};
// https://w3c.github.io/pointerevents/#pointerevent-interface
@ -36,6 +36,6 @@ interface PointerEvent : MouseEvent {
readonly attribute DOMString pointerType;
readonly attribute boolean isPrimary;
readonly attribute long persistentDeviceId;
[FIXME, SecureContext] sequence<PointerEvent> getCoalescedEvents();
[FIXME] sequence<PointerEvent> getPredictedEvents();
[SecureContext] sequence<PointerEvent> getCoalescedEvents();
sequence<PointerEvent> getPredictedEvents();
};