mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
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:
parent
33640c38d6
commit
18b71a363a
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue