From 18b71a363a17625f87b98a080925e8eb680df263 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 6 Mar 2024 10:36:28 -0500 Subject: [PATCH] WebContent: Update mouse event data when coalescing consecutive events When we coalesce mouse wheel events, we need to be sure to include the previous event's wheel deltas. This was errantly excluded in commit baf359354b4f55b33372951a2a60f797ad071071. --- .../WebContent/ConnectionFromClient.cpp | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index d6293779275..cdc8eb54242 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -278,24 +278,29 @@ void ConnectionFromClient::key_event(u64 page_id, Web::KeyEvent const& event) void ConnectionFromClient::mouse_event(u64 page_id, Web::MouseEvent const& event) { // OPTIMIZATION: Coalesce consecutive unprocessed mouse move and wheel events. - auto should_coalesce = [&]() { + auto event_to_coalesce = [&]() -> Web::MouseEvent const* { if (m_input_event_queue.is_empty()) - return false; + return nullptr; + if (m_input_event_queue.tail().page_id != page_id) + return nullptr; if (event.type != Web::MouseEvent::Type::MouseMove && event.type != Web::MouseEvent::Type::MouseWheel) - return false; + return nullptr; - if (m_input_event_queue.tail().page_id != page_id) - return false; + if (auto const* mouse_event = m_input_event_queue.tail().event.get_pointer()) { + if (mouse_event->type == event.type) + return mouse_event; + } - if (auto* mouse_event = m_input_event_queue.tail().event.get_pointer()) - return mouse_event->type == event.type; - - return false; + return nullptr; }; - if (should_coalesce()) { - m_input_event_queue.tail().event = move(const_cast(event)); + if (auto const* last_mouse_event = event_to_coalesce()) { + auto& mutable_event = const_cast(event); + mutable_event.wheel_delta_x += last_mouse_event->wheel_delta_x; + mutable_event.wheel_delta_y += last_mouse_event->wheel_delta_y; + + m_input_event_queue.tail().event = move(mutable_event); ++m_input_event_queue.tail().coalesced_event_count; return;