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
baf359354b.
This commit is contained in:
Timothy Flynn 2024-03-06 10:36:28 -05:00 committed by Tim Flynn
parent 33640c38d6
commit 18b71a363a
Notes: sideshowbarker 2024-07-17 05:09:48 +09:00

View File

@ -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<Web::MouseEvent>()) {
if (mouse_event->type == event.type)
return mouse_event;
}
if (auto* mouse_event = m_input_event_queue.tail().event.get_pointer<Web::MouseEvent>())
return mouse_event->type == event.type;
return false;
return nullptr;
};
if (should_coalesce()) {
m_input_event_queue.tail().event = move(const_cast<Web::MouseEvent&>(event));
if (auto const* last_mouse_event = event_to_coalesce()) {
auto& mutable_event = const_cast<Web::MouseEvent&>(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;