LibWeb: Use CSSPixelPoint in MouseEvent::create_from_platform_event()

This commit is contained in:
Itamar 2022-12-31 16:19:41 +02:00 committed by Andreas Kling
parent 66ee08c3dc
commit f6862a4203
Notes: sideshowbarker 2024-07-17 02:22:23 +09:00
3 changed files with 11 additions and 11 deletions

View file

@ -248,12 +248,12 @@ bool EventHandler::handle_mouseup(CSSPixelPoint position, unsigned button, unsig
auto offset = compute_mouse_event_offset(position, *layout_node);
auto client_offset = compute_mouse_event_client_offset(position);
node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::mouseup, offset.x(), offset.y(), client_offset.x(), client_offset.y(), buttons, button));
node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::mouseup, offset, client_offset, buttons, button));
handled_event = true;
bool run_activation_behavior = true;
if (node.ptr() == m_mousedown_target && button == GUI::MouseButton::Primary) {
run_activation_behavior = node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::click, offset.x(), offset.y(), client_offset.x(), client_offset.y(), button));
run_activation_behavior = node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::click, offset, client_offset, button));
}
if (run_activation_behavior) {
@ -370,7 +370,7 @@ bool EventHandler::handle_mousedown(CSSPixelPoint position, unsigned button, uns
m_mousedown_target = node.ptr();
auto offset = compute_mouse_event_offset(position, *layout_node);
auto client_offset = compute_mouse_event_client_offset(position);
node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::mousedown, offset.x(), offset.y(), client_offset.x(), client_offset.y(), buttons, button));
node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::mousedown, offset, client_offset, buttons, button));
}
// NOTE: Dispatching an event may have disturbed the world.
@ -483,7 +483,7 @@ bool EventHandler::handle_mousemove(CSSPixelPoint position, unsigned buttons, un
auto offset = compute_mouse_event_offset(position, *layout_node);
auto client_offset = compute_mouse_event_client_offset(position);
node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::mousemove, offset.x(), offset.y(), client_offset.x(), client_offset.y(), buttons));
node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::mousemove, offset, client_offset, buttons));
// NOTE: Dispatching an event may have disturbed the world.
if (!paint_root() || paint_root() != node->document().paint_box())
return true;
@ -565,7 +565,7 @@ bool EventHandler::handle_doubleclick(CSSPixelPoint position, unsigned button, u
auto offset = compute_mouse_event_offset(position, *layout_node);
auto client_offset = compute_mouse_event_client_offset(position);
node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::dblclick, offset.x(), offset.y(), client_offset.x(), client_offset.y(), buttons, button));
node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::dblclick, offset, client_offset, buttons, button));
// NOTE: Dispatching an event may have disturbed the world.
if (!paint_root() || paint_root() != node->document().paint_box())

View file

@ -52,13 +52,13 @@ MouseEvent* MouseEvent::create(JS::Realm& realm, FlyString const& event_name, Mo
return realm.heap().allocate<MouseEvent>(realm, realm, event_name, event_init);
}
MouseEvent* MouseEvent::create_from_platform_event(JS::Realm& realm, FlyString const& event_name, CSSPixels offset_x, CSSPixels offset_y, CSSPixels client_x, CSSPixels client_y, unsigned buttons, unsigned mouse_button)
MouseEvent* MouseEvent::create_from_platform_event(JS::Realm& realm, FlyString const& event_name, CSSPixelPoint offset, CSSPixelPoint client_offset, unsigned buttons, unsigned mouse_button)
{
MouseEventInit event_init {};
event_init.offset_x = static_cast<double>(offset_x.value());
event_init.offset_y = static_cast<double>(offset_y.value());
event_init.client_x = static_cast<double>(client_x.value());
event_init.client_y = static_cast<double>(client_y.value());
event_init.offset_x = static_cast<double>(offset.x().value());
event_init.offset_y = static_cast<double>(offset.y().value());
event_init.client_x = static_cast<double>(client_offset.x().value());
event_init.client_y = static_cast<double>(client_offset.y().value());
event_init.button = determine_button(mouse_button);
event_init.buttons = buttons;
return MouseEvent::create(realm, event_name, event_init);

View file

@ -28,7 +28,7 @@ class MouseEvent : public UIEvent {
public:
static MouseEvent* create(JS::Realm&, FlyString const& event_name, MouseEventInit const& event_init = {});
static MouseEvent* create_from_platform_event(JS::Realm&, FlyString const& event_name, CSSPixels offset_x, CSSPixels offset_y, CSSPixels client_x, CSSPixels client_y, unsigned buttons, unsigned mouse_button = 1);
static MouseEvent* create_from_platform_event(JS::Realm&, FlyString const& event_name, CSSPixelPoint offset, CSSPixelPoint client_offset, unsigned buttons, unsigned mouse_button = 1);
virtual ~MouseEvent() override;