From 59fe7ca8300ca64ad92e47a694ee352e8f99a1f8 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 29 Aug 2024 11:46:06 -0400 Subject: [PATCH] LibWeb: Convert internal test event coordinates to device pixels This allows for coming up with coordinates that work on macOS with a DPR of 2 more easily. --- .../Libraries/LibWeb/Internals/Internals.cpp | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibWeb/Internals/Internals.cpp b/Userland/Libraries/LibWeb/Internals/Internals.cpp index 5271d8e2396..41584f3da2b 100644 --- a/Userland/Libraries/LibWeb/Internals/Internals.cpp +++ b/Userland/Libraries/LibWeb/Internals/Internals.cpp @@ -98,20 +98,26 @@ void Internals::middle_click(double x, double y) void Internals::click(double x, double y, UIEvents::MouseButton button) { auto& page = global_object().browsing_context()->page(); - page.handle_mousedown({ x, y }, { x, y }, button, 0, 0); - page.handle_mouseup({ x, y }, { x, y }, button, 0, 0); + + auto position = page.css_to_device_point({ x, y }); + page.handle_mousedown(position, position, button, 0, 0); + page.handle_mouseup(position, position, button, 0, 0); } void Internals::move_pointer_to(double x, double y) { auto& page = global_object().browsing_context()->page(); - page.handle_mousemove({ x, y }, { x, y }, 0, 0); + + auto position = page.css_to_device_point({ x, y }); + page.handle_mousemove(position, position, 0, 0); } void Internals::wheel(double x, double y, double delta_x, double delta_y) { auto& page = global_object().browsing_context()->page(); - page.handle_mousewheel({ x, y }, { x, y }, 0, 0, 0, delta_x, delta_y); + + auto position = page.css_to_device_point({ x, y }); + page.handle_mousewheel(position, position, 0, 0, 0, delta_x, delta_y); } WebIDL::ExceptionOr Internals::dispatch_user_activated_event(DOM::EventTarget& target, DOM::Event& event) @@ -132,19 +138,25 @@ void Internals::simulate_drag_start(double x, double y, String const& name, Stri files.empend(name.to_byte_string(), MUST(ByteBuffer::copy(contents.bytes()))); auto& page = global_object().browsing_context()->page(); - page.handle_drag_and_drop_event(DragEvent::Type::DragStart, { x, y }, { x, y }, UIEvents::MouseButton::Primary, 0, 0, move(files)); + + auto position = page.css_to_device_point({ x, y }); + page.handle_drag_and_drop_event(DragEvent::Type::DragStart, position, position, UIEvents::MouseButton::Primary, 0, 0, move(files)); } void Internals::simulate_drag_move(double x, double y) { auto& page = global_object().browsing_context()->page(); - page.handle_drag_and_drop_event(DragEvent::Type::DragMove, { x, y }, { x, y }, UIEvents::MouseButton::Primary, 0, 0, {}); + + auto position = page.css_to_device_point({ x, y }); + page.handle_drag_and_drop_event(DragEvent::Type::DragMove, position, position, UIEvents::MouseButton::Primary, 0, 0, {}); } void Internals::simulate_drop(double x, double y) { auto& page = global_object().browsing_context()->page(); - page.handle_drag_and_drop_event(DragEvent::Type::Drop, { x, y }, { x, y }, UIEvents::MouseButton::Primary, 0, 0, {}); + + auto position = page.css_to_device_point({ x, y }); + page.handle_drag_and_drop_event(DragEvent::Type::Drop, position, position, UIEvents::MouseButton::Primary, 0, 0, {}); } }