Skip to content

Truly independent web browser

LibWebCommon+Compositor+LibWeb: Name the gesture of each wheel event

Aliaksandr Kalenika06341e89fd3
diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.cpp b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
index a3ce8af4245..a22dae58f96 100644
--- a/Libraries/LibWeb/Compositor/CompositorConnection.cpp
+++ b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
@@ -486,12 +486,12 @@ void CompositorConnection::invalidate_wheel_event_listener_state(Web::Compositor
async_invalidate_wheel_event_listener_state(context_id, generation);
}
-Compositing::AsyncScrollEnqueueResult CompositorConnection::async_scroll_by(Web::CompositorContextId context_id, Web::UniqueNodeID document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelStepDispatch wheel_step_dispatch, u64 input_event_id)
+Compositing::AsyncScrollEnqueueResult CompositorConnection::async_scroll_by(Web::CompositorContextId context_id, Web::UniqueNodeID document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelStepDispatch wheel_step_dispatch, Optional<u64> wheel_gesture_id, u64 input_event_id)
{
if (!can_send_message_to_compositor())
return {};
- auto response = send_sync_but_allow_failure<Messages::CompositorWebContentServer::AsyncScrollBy>(context_id, document_id, position, delta, viewport_rect, wheel_delta_precision, scroll_gesture_phase, modifiers, operation_tracking, wheel_step_dispatch, input_event_id);
+ auto response = send_sync_but_allow_failure<Messages::CompositorWebContentServer::AsyncScrollBy>(context_id, document_id, position, delta, viewport_rect, wheel_delta_precision, scroll_gesture_phase, modifiers, operation_tracking, wheel_step_dispatch, wheel_gesture_id, input_event_id);
if (!response) {
did_lose_compositor();
return {};
diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.h b/Libraries/LibWeb/Compositor/CompositorConnection.h
index 31f37c7134c..0273a95db0c 100644
--- a/Libraries/LibWeb/Compositor/CompositorConnection.h
+++ b/Libraries/LibWeb/Compositor/CompositorConnection.h
@@ -66,7 +66,7 @@ public:
bool rasterize_display_list(Compositing::DisplayList const&, Compositing::AccumulatedVisualContextTree const&, Compositing::DisplayListResourceTransaction, NonnullRefPtr<Gfx::Bitmap> target);
void invalidate_wheel_event_listener_state(Web::CompositorContextId, u64 generation);
void invalidate_keyboard_scroll_state(Web::CompositorContextId, u64 generation);
- Compositing::AsyncScrollEnqueueResult async_scroll_by(Web::CompositorContextId, Web::UniqueNodeID document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, u32 modifiers, Compositing::AsyncScrollOperationTracking, Compositing::WheelStepDispatch, u64 input_event_id);
+ Compositing::AsyncScrollEnqueueResult async_scroll_by(Web::CompositorContextId, Web::UniqueNodeID document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, u32 modifiers, Compositing::AsyncScrollOperationTracking, Compositing::WheelStepDispatch, Optional<u64> wheel_gesture_id, u64 input_event_id);
String scroll_state_for_testing(Web::CompositorContextId, Web::AsyncScrollNodeStableID stretched_scroller);
void synchronize_for_testing();
Optional<Compositing::FirstWheelStepRouteForTesting> route_first_wheel_step_for_testing(Web::CompositorContextId, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels);
diff --git a/Libraries/LibWeb/Compositor/CompositorHost.cpp b/Libraries/LibWeb/Compositor/CompositorHost.cpp
index 22058db39ff..f7156339817 100644
--- a/Libraries/LibWeb/Compositor/CompositorHost.cpp
+++ b/Libraries/LibWeb/Compositor/CompositorHost.cpp
@@ -62,9 +62,9 @@ void CompositorContextHandle::invalidate_wheel_event_listener_state(u64 generati
}
Compositing::AsyncScrollEnqueueResult CompositorContextHandle::async_scroll_by(UniqueNodeID expected_document_id, Gfx::FloatPoint position,
- Gfx::FloatPoint delta_in_device_pixels, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelStepDispatch wheel_step_dispatch, u64 input_event_id)
+ Gfx::FloatPoint delta_in_device_pixels, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelStepDispatch wheel_step_dispatch, Optional<u64> wheel_gesture_id, u64 input_event_id)
{
- return m_host.async_scroll_by(m_context_id, expected_document_id, position, delta_in_device_pixels, viewport_rect, wheel_delta_precision, scroll_gesture_phase, modifiers, operation_tracking, wheel_step_dispatch, input_event_id);
+ return m_host.async_scroll_by(m_context_id, expected_document_id, position, delta_in_device_pixels, viewport_rect, wheel_delta_precision, scroll_gesture_phase, modifiers, operation_tracking, wheel_step_dispatch, wheel_gesture_id, input_event_id);
}
String CompositorContextHandle::scroll_state_for_testing(Web::AsyncScrollNodeStableID stretched_scroller)
@@ -463,10 +463,10 @@ void CompositorHost::invalidate_wheel_event_listener_state(Web::CompositorContex
}
Compositing::AsyncScrollEnqueueResult CompositorHost::async_scroll_by(Web::CompositorContextId context_id, Web::UniqueNodeID expected_document_id, Gfx::FloatPoint position,
- Gfx::FloatPoint delta_in_device_pixels, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelStepDispatch wheel_step_dispatch, u64 input_event_id)
+ Gfx::FloatPoint delta_in_device_pixels, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelStepDispatch wheel_step_dispatch, Optional<u64> wheel_gesture_id, u64 input_event_id)
{
if (auto* connection = compositor_connection())
- return connection->async_scroll_by(context_id, expected_document_id, position, delta_in_device_pixels, viewport_rect, wheel_delta_precision, scroll_gesture_phase, modifiers, operation_tracking, wheel_step_dispatch, input_event_id);
+ return connection->async_scroll_by(context_id, expected_document_id, position, delta_in_device_pixels, viewport_rect, wheel_delta_precision, scroll_gesture_phase, modifiers, operation_tracking, wheel_step_dispatch, wheel_gesture_id, input_event_id);
return {};
}
diff --git a/Libraries/LibWeb/Compositor/CompositorHost.h b/Libraries/LibWeb/Compositor/CompositorHost.h
index e57f137eb61..48da30eaf12 100644
--- a/Libraries/LibWeb/Compositor/CompositorHost.h
+++ b/Libraries/LibWeb/Compositor/CompositorHost.h
@@ -66,7 +66,7 @@ public:
void invalidate_wheel_event_listener_state(u64 generation);
void invalidate_keyboard_scroll_state(u64 generation);
Compositing::AsyncScrollEnqueueResult async_scroll_by(UniqueNodeID expected_document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_device_pixels,
- Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, u32 modifiers, Compositing::AsyncScrollOperationTracking, Compositing::WheelStepDispatch, u64 input_event_id);
+ Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, u32 modifiers, Compositing::AsyncScrollOperationTracking, Compositing::WheelStepDispatch, Optional<u64> wheel_gesture_id, u64 input_event_id);
String scroll_state_for_testing(Web::AsyncScrollNodeStableID stretched_scroller);
void synchronize_for_testing();
Optional<Compositing::FirstWheelStepRouteForTesting> route_first_wheel_step_for_testing(Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels);
@@ -128,7 +128,7 @@ public:
void invalidate_wheel_event_listener_state(Web::CompositorContextId, u64 generation);
void invalidate_keyboard_scroll_state(Web::CompositorContextId, u64 generation);
Compositing::AsyncScrollEnqueueResult async_scroll_by(Web::CompositorContextId, UniqueNodeID expected_document_id, Gfx::FloatPoint position,
- Gfx::FloatPoint delta_in_device_pixels, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, u32 modifiers, Compositing::AsyncScrollOperationTracking, Compositing::WheelStepDispatch, u64 input_event_id);
+ Gfx::FloatPoint delta_in_device_pixels, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, u32 modifiers, Compositing::AsyncScrollOperationTracking, Compositing::WheelStepDispatch, Optional<u64> wheel_gesture_id, u64 input_event_id);
String scroll_state_for_testing(Web::CompositorContextId, Web::AsyncScrollNodeStableID stretched_scroller);
void synchronize_for_testing();
Optional<Compositing::FirstWheelStepRouteForTesting> route_first_wheel_step_for_testing(Web::CompositorContextId, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels);
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp
index 910d395ce91..e6234418ac6 100644
--- a/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Libraries/LibWeb/Page/EventHandler.cpp
@@ -974,12 +974,13 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
auto now = MonotonicTime::now();
auto gesture_position = visual_viewport_position.to_type<float>();
bool wheel_event_has_delta = wheel_delta_x != 0 || wheel_delta_y != 0;
- // The compositor tells which gesture an event it passed on belongs to, which this navigable follows so that the two
- // route the event alike.
+ // The compositor names the gesture of an event it passed on, which this navigable follows so that the two route the
+ // event alike.
+ auto wheel_gesture_id = wheel_gesture_mark.map([](auto const& mark) { return mark.gesture_id; });
bool continues_latched_gesture = false;
if (m_wheel_scroll_latch.has_value()) {
- if (wheel_gesture_mark.has_value())
- continues_latched_gesture = wheel_gesture_mark->continues_gesture;
+ if (wheel_gesture_id.has_value())
+ continues_latched_gesture = m_wheel_scroll_latch->wheel_gesture_id == wheel_gesture_id;
else
continues_latched_gesture = m_wheel_scroll_latch->gesture.is_continued_by(gesture_position, scroll_gesture_phase, modifiers, now, Compositing::wheel_gesture_position_slop_in_css_pixels, Compositing::TouchpadGestureEnd::AfterIdleDelay);
}
@@ -1028,7 +1029,7 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
? Compositing::AsyncScrollOperationTracking::Yes
: Compositing::AsyncScrollOperationTracking::No;
auto enqueue_result = m_navigable->compositor_context().async_scroll_by(
- document->unique_id(), async_scroll_position, delta_in_device_pixels, viewport_rect, wheel_delta_precision, scroll_gesture_phase, modifiers, operation_tracking, wheel_step_dispatch, handling_input_event_id());
+ document->unique_id(), async_scroll_position, delta_in_device_pixels, viewport_rect, wheel_delta_precision, scroll_gesture_phase, modifiers, operation_tracking, wheel_step_dispatch, wheel_gesture_id, handling_input_event_id());
record_input_routing(enqueue_result.routing_decision.value_or(InputRoutingDecision::NoAnswerFromCompositor), enqueue_result.routed_scroller, {}, InputTraceStage::CompositorForMainThread);
if (enqueue_result.operation_id.has_value() && async_scroll_operation)
*async_scroll_operation = AsyncScrollOperation { m_navigable, *enqueue_result.operation_id };
@@ -1080,6 +1081,7 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
return;
m_wheel_scroll_latch = WheelScrollLatch {
.gesture = Compositing::WheelGestureIdentity::started_by(gesture_position, scroll_gesture_phase, modifiers, now),
+ .wheel_gesture_id = wheel_gesture_id,
.wheel_event_target = target.dom_node(),
.wheel_event_target_pseudo_element = target_layout_node ? target_layout_node->generated_for_pseudo_element() : Optional<CSS::PseudoElement> {},
};
diff --git a/Libraries/LibWeb/Page/EventHandler.h b/Libraries/LibWeb/Page/EventHandler.h
index e8fa58a0039..d2a5b1f0c50 100644
--- a/Libraries/LibWeb/Page/EventHandler.h
+++ b/Libraries/LibWeb/Page/EventHandler.h
@@ -362,7 +362,11 @@ private:
// without hit testing, and the scrolling box absorbs the gesture at its edge. The compositor latches by the same
// rules, so the two agree on the scroller of an event.
struct WheelScrollLatch {
+ // Tells whether an event the compositor did not pass on continues the gesture.
Compositing::WheelGestureIdentity gesture;
+ // The gesture the compositor named for the event that started the latch, which only events it names the same
+ // gesture for continue.
+ Optional<u64> wheel_gesture_id;
GC::Weak<DOM::Node> wheel_event_target;
// The default action walks the boxes of this pseudo-element rather than the target's own.
Optional<CSS::PseudoElement> wheel_event_target_pseudo_element {};
diff --git a/Libraries/LibWebCommon/Page/InputEvent.h b/Libraries/LibWebCommon/Page/InputEvent.h
index 25864e9566e..17393a3d8a7 100644
--- a/Libraries/LibWebCommon/Page/InputEvent.h
+++ b/Libraries/LibWebCommon/Page/InputEvent.h
@@ -145,8 +145,8 @@ private:
// What the compositor found of a wheel event's gesture as it passed the event on, which WebContent follows rather
// than deciding again.
struct WheelGestureMark {
- // Whether the event continues the gesture before it, rather than starting one.
- bool continues_gesture { false };
+ // The gesture the event is in. The events of one gesture carry the same id, and no other gesture has it.
+ u64 gesture_id { 0 };
// Whether the gesture goes on for as long as its fingers rest on the touchpad, which the platform reports the lift
// of, rather than until its events pause.
bool lasts_until_fingers_lift { false };
diff --git a/Libraries/LibWebCommon/Page/InputEvent.ipc b/Libraries/LibWebCommon/Page/InputEvent.ipc
index ec2f2d3f154..7a27bf51fbe 100644
--- a/Libraries/LibWebCommon/Page/InputEvent.ipc
+++ b/Libraries/LibWebCommon/Page/InputEvent.ipc
@@ -37,7 +37,7 @@ enum Web::ScrollGesturePhase : u8 {
[ExistingCpp]
struct Web::WheelGestureMark {
- bool continues_gesture;
+ u64 gesture_id;
bool lasts_until_fingers_lift;
}
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cpp
index 7c9c42ac411..366f1e62278 100644
--- a/Services/Compositor/CompositorState.cpp
+++ b/Services/Compositor/CompositorState.cpp
@@ -942,7 +942,7 @@ ContextState::ContextUpdateResult CompositorState::scroll_for_wheel_step(Web::Co
CompositorState::WheelStepHandedToNestedContext CompositorState::hand_wheel_step_to_nested_context(Web::CompositorContextId context_id, ContextState& context, Web::MouseEvent const& event, ContextState::NestedContextWheelStep const& nested_step, MonotonicTime now)
{
- auto step = ContextState::WheelStepFromContainingContext::for_wheel_event(event);
+ auto step = ContextState::WheelStepFromContainingContext::for_wheel_event(event, context.wheel_gesture_id());
// The nested context presents and publishes what its step changed, and this context reports how the step went.
auto apply_result_of_nested_context = [&](Web::CompositorContextId nested_context_id, ContextState& nested_context, ContextState::ContextUpdateResult const& nested_result) {
apply_context_update_result(nested_context_id, nested_context, nested_result);
@@ -1038,8 +1038,6 @@ void CompositorState::dispatch_scroll_fling_step(Web::CompositorContextId contex
context.input_trace().record({ .input_event_id = event->id, .stage = Web::InputTraceStage::Compositor, .decision = *result.routing_decision, .scroller = result.routed_scroller });
event->async_scroll_performed_default_action = apply_context_update_result(context_id, context, result);
schedule_animation_frames_if_needed(context);
- // The steps this context makes itself carry on the gesture of the wheel events before them.
- event->wheel_gesture_mark = Web::WheelGestureMark { .continues_gesture = true, .lasts_until_fingers_lift = false };
context.dispatch_mouse_event_to_web_content(*event);
}
@@ -1076,12 +1074,12 @@ void CompositorState::handle_and_dispatch_pinch_event(Web::CompositorContextId c
context->dispatch_pinch_event_to_web_content(event);
}
-Compositing::AsyncScrollEnqueueResult CompositorState::async_scroll_by(Web::CompositorContextId context_id, Web::UniqueNodeID expected_document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelStepDispatch wheel_step_dispatch, u64 input_event_id)
+Compositing::AsyncScrollEnqueueResult CompositorState::async_scroll_by(Web::CompositorContextId context_id, Web::UniqueNodeID expected_document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelStepDispatch wheel_step_dispatch, Optional<u64> wheel_gesture_id, u64 input_event_id)
{
auto* context = context_if_present(context_id);
VERIFY(context);
- auto result = context->async_scroll_by(expected_document_id, position, delta, viewport_rect, wheel_delta_precision, scroll_gesture_phase, modifiers, operation_tracking, wheel_step_dispatch, input_event_id);
+ auto result = context->async_scroll_by(expected_document_id, position, delta, viewport_rect, wheel_delta_precision, scroll_gesture_phase, modifiers, operation_tracking, wheel_step_dispatch, wheel_gesture_id, input_event_id);
if (result.frame_to_present.has_value())
schedule_present_frame(context_id, *context, *result.frame_to_present);
schedule_animation_frames_if_needed(*context);
diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.h
index 6b69888d654..95ec19a7e7d 100644
--- a/Services/Compositor/CompositorState.h
+++ b/Services/Compositor/CompositorState.h
@@ -130,7 +130,7 @@ public:
void handle_and_dispatch_key_event(Web::CompositorContextId, Web::KeyEvent, bool allow_keyboard_scroll);
void handle_and_dispatch_mouse_event(Web::CompositorContextId, Web::MouseEvent);
void handle_and_dispatch_pinch_event(Web::CompositorContextId, Web::PinchEvent);
- Compositing::AsyncScrollEnqueueResult async_scroll_by(Web::CompositorContextId, Web::UniqueNodeID document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, u32 modifiers, Compositing::AsyncScrollOperationTracking, Compositing::WheelStepDispatch, u64 input_event_id);
+ Compositing::AsyncScrollEnqueueResult async_scroll_by(Web::CompositorContextId, Web::UniqueNodeID document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, u32 modifiers, Compositing::AsyncScrollOperationTracking, Compositing::WheelStepDispatch, Optional<u64> wheel_gesture_id, u64 input_event_id);
void apply_scroll_requests(Web::CompositorContextId, ReadonlySpan<Compositing::ScrollRequest>);
void viewport_size_updated(Web::CompositorContextId, Gfx::IntSize, double device_pixel_ratio, Compositing::WindowResizingInProgress);
void request_rendering_opportunity(Web::CompositorContextId, double maximum_frames_per_second);
diff --git a/Services/Compositor/CompositorWebContentServer.ipc b/Services/Compositor/CompositorWebContentServer.ipc
index aac4fc292b6..9e1c2977187 100644
--- a/Services/Compositor/CompositorWebContentServer.ipc
+++ b/Services/Compositor/CompositorWebContentServer.ipc
@@ -69,7 +69,7 @@ endpoint CompositorWebContentServer
invalidate_wheel_event_listener_state(Web::CompositorContextId context_id, u64 generation) =|
invalidate_keyboard_scroll_state(Web::CompositorContextId context_id, u64 generation) => ()
- async_scroll_by(Web::CompositorContextId context_id, Web::UniqueNodeID document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelStepDispatch wheel_step_dispatch, u64 input_event_id) => (Compositing::AsyncScrollEnqueueResult result)
+ async_scroll_by(Web::CompositorContextId context_id, Web::UniqueNodeID document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelStepDispatch wheel_step_dispatch, Optional<u64> wheel_gesture_id, u64 input_event_id) => (Compositing::AsyncScrollEnqueueResult result)
apply_scroll_requests(Web::CompositorContextId context_id, Vector<Compositing::ScrollRequest> scroll_requests) =|
scroll_state_for_testing(Web::CompositorContextId context_id, Web::AsyncScrollNodeStableID stretched_scroller) => (String scroll_state)
// Returns once the compositor has handled every message WebContent sent before it.
diff --git a/Services/Compositor/ConnectionFromWebContent.cpp b/Services/Compositor/ConnectionFromWebContent.cpp
index 6999ad5d66a..c29a1c63ef8 100644
--- a/Services/Compositor/ConnectionFromWebContent.cpp
+++ b/Services/Compositor/ConnectionFromWebContent.cpp
@@ -485,11 +485,11 @@ void ConnectionFromWebContent::invalidate_wheel_event_listener_state(Web::Compos
m_compositor_state->invalidate_wheel_event_listener_state(context_id, generation);
}
-Messages::CompositorWebContentServer::AsyncScrollByResponse ConnectionFromWebContent::async_scroll_by(Web::CompositorContextId context_id, Web::UniqueNodeID document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelStepDispatch wheel_step_dispatch, u64 input_event_id)
+Messages::CompositorWebContentServer::AsyncScrollByResponse ConnectionFromWebContent::async_scroll_by(Web::CompositorContextId context_id, Web::UniqueNodeID document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelStepDispatch wheel_step_dispatch, Optional<u64> wheel_gesture_id, u64 input_event_id)
{
if (!context_is_owned_by_this_connection(context_id))
return Compositing::AsyncScrollEnqueueResult {};
- auto result = m_compositor_state->async_scroll_by(context_id, document_id, position, delta, viewport_rect, wheel_delta_precision, scroll_gesture_phase, modifiers, operation_tracking, wheel_step_dispatch, input_event_id);
+ auto result = m_compositor_state->async_scroll_by(context_id, document_id, position, delta, viewport_rect, wheel_delta_precision, scroll_gesture_phase, modifiers, operation_tracking, wheel_step_dispatch, wheel_gesture_id, input_event_id);
if (result.accepted)
async_request_rendering_update();
return result;
diff --git a/Services/Compositor/ConnectionFromWebContent.h b/Services/Compositor/ConnectionFromWebContent.h
index 82815d51823..2803e68fb4b 100644
--- a/Services/Compositor/ConnectionFromWebContent.h
+++ b/Services/Compositor/ConnectionFromWebContent.h
@@ -77,7 +77,7 @@ private:
virtual Messages::CompositorWebContentServer::WebglReadBufferSubDataResponse webgl_read_buffer_sub_data(Compositing::CanvasId canvas_id, u32 target, i64 offset, i64 size, Core::AnonymousBuffer data) override;
virtual void invalidate_wheel_event_listener_state(Web::CompositorContextId, u64 generation) override;
virtual void invalidate_keyboard_scroll_state(Web::CompositorContextId, u64 generation) override;
- virtual Messages::CompositorWebContentServer::AsyncScrollByResponse async_scroll_by(Web::CompositorContextId, Web::UniqueNodeID document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, u32 modifiers, Compositing::AsyncScrollOperationTracking, Compositing::WheelStepDispatch, u64 input_event_id) override;
+ virtual Messages::CompositorWebContentServer::AsyncScrollByResponse async_scroll_by(Web::CompositorContextId, Web::UniqueNodeID document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, u32 modifiers, Compositing::AsyncScrollOperationTracking, Compositing::WheelStepDispatch, Optional<u64> wheel_gesture_id, u64 input_event_id) override;
virtual void apply_scroll_requests(Web::CompositorContextId, Vector<Compositing::ScrollRequest>) override;
virtual Messages::CompositorWebContentServer::ScrollStateForTestingResponse scroll_state_for_testing(Web::CompositorContextId, Web::AsyncScrollNodeStableID) override;
virtual void synchronize_for_testing() override { }
diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cpp
index 6cdad7eb068..2ca128be076 100644
--- a/Services/Compositor/ContextState.cpp
+++ b/Services/Compositor/ContextState.cpp
@@ -970,6 +970,7 @@ ContextState::AsyncScrollResult ContextState::async_scroll_by(
u32 modifiers,
Compositing::AsyncScrollOperationTracking operation_tracking,
Compositing::WheelStepDispatch wheel_step_dispatch,
+ Optional<u64> wheel_gesture_id_of_ui_event,
u64 input_event_id,
Optional<MonotonicTime> now_for_testing)
{
@@ -1003,7 +1004,10 @@ ContextState::AsyncScrollResult ContextState::async_scroll_by(
// A step the UI never sent, such as one a test makes on the main thread, is noted as the UI's events are.
if (input_event_id == 0)
m_wheel_gesture_routing.note_wheel_event(input_event_id, scroll_gesture_phase, modifiers, delta, position, m_async_scroll_tree, now);
- auto latch = resolve_wheel_scroll_latch(scroll_gesture_phase);
+ // This context noted the gesture of a step the UI sent to it, and of a step the UI never sent. A context nested in
+ // another one knows the gesture of a step the UI sent only from the mark of the event.
+ auto gesture_id = presents_to_client() || input_event_id == 0 ? m_wheel_gesture_routing.gesture_id() : wheel_gesture_id_of_ui_event;
+ auto latch = resolve_wheel_scroll_latch(scroll_gesture_phase, gesture_id);
// The compositor hands every step of a gesture latched to a nested context's scroller to that context itself.
if (latch.nested_context_id.has_value())
return AsyncScrollResult::declined(Web::InputRoutingDecision::ScrollerInOtherDocument);
@@ -1040,7 +1044,7 @@ ContextState::AsyncScrollResult ContextState::async_scroll_by(
auto routing_decision = Web::InputRoutingDecision::ContinuedLatch;
if (is_first_step_of_gesture) {
auto wheel_step_dispatch_for_hit_test = page_let_touchpad_step_through ? Compositing::WheelStepDispatch::DispatchedAndNotCanceled : Compositing::WheelStepDispatch::NotYetDispatched;
- auto latch_attempt = hit_test_and_latch_wheel_gesture(position, delta, wheel_delta_precision, scroll_gesture_phase, expected_document_id, wheel_step_dispatch_for_hit_test, Compositing::NestedContextRegions::LeaveToMainThread);
+ auto latch_attempt = hit_test_and_latch_wheel_gesture(position, delta, wheel_delta_precision, scroll_gesture_phase, gesture_id, expected_document_id, wheel_step_dispatch_for_hit_test, Compositing::NestedContextRegions::LeaveToMainThread);
if (!latch_attempt.latched_scroll_node_index.has_value())
return AsyncScrollResult::declined(latch_attempt.decision);
latched_scroll_node_index = latch_attempt.latched_scroll_node_index;
@@ -1526,21 +1530,27 @@ Web::WheelGestureMark ContextState::note_wheel_event_from_ui(Web::MouseEvent con
auto now = now_for_testing.value_or(MonotonicTime::now());
auto phase = event.scroll_gesture_phase;
- if (phase == Web::ScrollGesturePhase::Momentum)
- m_last_reported_scroll_momentum_step = event.clone_without_browser_data();
- else
- m_last_reported_scroll_momentum_step.clear();
-
// The end of the gesture before this one may never have arrived.
bool starts_gesture = m_wheel_gesture_routing.note_wheel_event_from_ui(event, wheel_event_position(event), m_async_scroll_tree, now);
if (starts_gesture)
m_elastic_overscroll_controller.end_gesture(now);
+ Web::WheelGestureMark wheel_gesture_mark {
+ .gesture_id = m_wheel_gesture_routing.gesture_id().value(),
+ .lasts_until_fingers_lift = m_wheel_gesture_routing.gesture_lasts_until_fingers_lift(),
+ };
+
+ if (phase == Web::ScrollGesturePhase::Momentum) {
+ m_last_reported_scroll_momentum_step = event.clone_without_browser_data();
+ m_last_reported_scroll_momentum_step->wheel_gesture_mark = wheel_gesture_mark;
+ } else {
+ m_last_reported_scroll_momentum_step.clear();
+ }
// A stretch is released with the velocity of the steps as they arrived from the UI, not as they were scrolled.
// Fling steps are not timed here, which leaves them out of the velocity; no platform both flings and stretches.
if (wheel_step_can_stretch_elastically(event.wheel_delta_precision, phase))
m_elastic_overscroll_controller.note_step_from_ui(wheel_event_delta_in_device_pixels(event).scaled(1.0f / m_scene.visual_viewport_magnification()), now);
- return { .continues_gesture = !starts_gesture, .lasts_until_fingers_lift = m_wheel_gesture_routing.gesture_lasts_until_fingers_lift() };
+ return wheel_gesture_mark;
}
bool ContextState::start_scroll_fling_if_flicked(Web::MouseEvent const& gesture_end_event, Optional<MonotonicTime> now_for_testing)
@@ -1630,7 +1640,7 @@ ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event(Web::Mous
if (event.scroll_gesture_phase == Web::ScrollGesturePhase::Ended)
m_elastic_overscroll_controller.end_gesture(now);
- auto latch = resolve_wheel_scroll_latch(event.scroll_gesture_phase);
+ auto latch = resolve_wheel_scroll_latch(event.scroll_gesture_phase, m_wheel_gesture_routing.gesture_id());
if (latch.nested_context_id.has_value())
return { .nested_context_wheel_step = NestedContextWheelStep { .context_id = *latch.nested_context_id } };
@@ -1701,7 +1711,7 @@ ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event_in_this_c
// for as long as the gesture only pans.
auto routing_decision = Web::InputRoutingDecision::ContinuedLatch;
if (is_first_step_of_gesture) {
- auto latch_attempt = hit_test_and_latch_wheel_gesture(position, delta.scaled(1.0f / m_scene.visual_viewport_magnification()), event.wheel_delta_precision, event.scroll_gesture_phase, {}, Compositing::WheelStepDispatch::NotYetDispatched, nested_context_regions);
+ auto latch_attempt = hit_test_and_latch_wheel_gesture(position, delta.scaled(1.0f / m_scene.visual_viewport_magnification()), event.wheel_delta_precision, event.scroll_gesture_phase, m_wheel_gesture_routing.gesture_id(), {}, Compositing::WheelStepDispatch::NotYetDispatched, nested_context_regions);
latched_scroll_node_index = latch_attempt.latched_scroll_node_index;
routing_decision = latch_attempt.decision;
}
@@ -1745,10 +1755,10 @@ Optional<Compositing::NestedContextHit> ContextState::nested_context_for_wheel_a
void ContextState::latch_wheel_gesture_to_nested_context(Web::CompositorContextId nested_context_id, Optional<Web::AsyncScrollNodeStableID> scroller, Web::MouseEvent const& event)
{
- m_wheel_gesture_routing.latch_to_nested_context(nested_context_id, scroller, event.scroll_gesture_phase);
+ m_wheel_gesture_routing.latch_to_nested_context(nested_context_id, scroller, event.scroll_gesture_phase, m_wheel_gesture_routing.gesture_id());
}
-ContextState::WheelStepFromContainingContext ContextState::WheelStepFromContainingContext::for_wheel_event(Web::MouseEvent const& event)
+ContextState::WheelStepFromContainingContext ContextState::WheelStepFromContainingContext::for_wheel_event(Web::MouseEvent const& event, Optional<u64> gesture_id)
{
Gfx::FloatPoint delta_in_css_pixels { static_cast<float>(event.wheel_delta_x), static_cast<float>(event.wheel_delta_y) };
if (event.modifiers & Web::UIEvents::KeyModifier::Mod_Shift)
@@ -1759,6 +1769,7 @@ ContextState::WheelStepFromContainingContext ContextState::WheelStepFromContaini
.wheel_delta_precision = event.wheel_delta_precision,
.scroll_gesture_phase = event.scroll_gesture_phase,
.modifiers = event.modifiers,
+ .gesture_id = gesture_id,
};
}
@@ -1806,12 +1817,12 @@ ContextState::ContextUpdateResult ContextState::take_first_wheel_step_from_conta
VERIFY(first_is_one_of(route.kind, FirstWheelStepRoute::Kind::ScrollNode, FirstWheelStepRoute::Kind::Kept));
if (route.kind == FirstWheelStepRoute::Kind::Kept) {
if (route.scroller.has_value())
- m_wheel_gesture_routing.latch(*route.scroller, step.scroll_gesture_phase);
+ m_wheel_gesture_routing.latch(*route.scroller, step.scroll_gesture_phase, step.gesture_id);
else
- m_wheel_gesture_routing.latch_keeping_steps(step.scroll_gesture_phase);
+ m_wheel_gesture_routing.latch_keeping_steps(step.scroll_gesture_phase, step.gesture_id);
return { .accepted = true, .routing_decision = route.decision, .routed_scroller = route.scroller };
}
- m_wheel_gesture_routing.latch(*route.scroller, step.scroll_gesture_phase);
+ m_wheel_gesture_routing.latch(*route.scroller, step.scroll_gesture_phase, step.gesture_id);
return take_wheel_step_from_containing_context(*route.scroll_node_index, route.decision, step, Compositing::ScrollChaining::ToScrollableAncestors, now);
}
@@ -1824,7 +1835,7 @@ ContextState::ContextUpdateResult ContextState::take_latched_wheel_step_from_con
if (first_is_one_of(admission, Compositing::WheelRoutingAdmission::BlockingWheelEventListeners, Compositing::WheelRoutingAdmission::StaleWheelEventListeners))
return ContextUpdateResult::declined(Compositing::input_routing_decision_for_wheel_step_not_admitted_by(admission));
- auto latch = m_wheel_gesture_routing.resolve_latch(m_async_scroll_tree, m_scene.current_visual_context_tree(), step.scroll_gesture_phase);
+ auto latch = m_wheel_gesture_routing.resolve_latch(m_async_scroll_tree, m_scene.current_visual_context_tree(), step.scroll_gesture_phase, step.gesture_id);
if (latch.keeps_steps)
return { .accepted = true, .routing_decision = Web::InputRoutingDecision::ScrollKeptByOverscrollBehavior };
if (!latch.scroll_node_index.has_value())
@@ -2219,15 +2230,15 @@ void ContextState::store_pending_async_scroll_offsets(
m_async_scroll_update_outbox.complete_operation(*operation_id);
}
-WheelGestureRouting::ResolvedLatch ContextState::resolve_wheel_scroll_latch(Web::ScrollGesturePhase scroll_gesture_phase)
+WheelGestureRouting::ResolvedLatch ContextState::resolve_wheel_scroll_latch(Web::ScrollGesturePhase scroll_gesture_phase, Optional<u64> gesture_id)
{
// Only a hit test takes a latch, and it needs the tree of an installed display list.
if (!m_wheel_gesture_routing.has_latch())
return {};
- return m_wheel_gesture_routing.resolve_latch(m_async_scroll_tree, m_scene.current_visual_context_tree(), scroll_gesture_phase);
+ return m_wheel_gesture_routing.resolve_latch(m_async_scroll_tree, m_scene.current_visual_context_tree(), scroll_gesture_phase, gesture_id);
}
-ContextState::WheelGestureLatchAttempt ContextState::hit_test_and_latch_wheel_gesture(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, Optional<Web::UniqueNodeID> expected_document_id, Compositing::WheelStepDispatch wheel_step_dispatch, Compositing::NestedContextRegions nested_context_regions)
+ContextState::WheelGestureLatchAttempt ContextState::hit_test_and_latch_wheel_gesture(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, Optional<u64> gesture_id, Optional<Web::UniqueNodeID> expected_document_id, Compositing::WheelStepDispatch wheel_step_dispatch, Compositing::NestedContextRegions nested_context_regions)
{
Function<Optional<Gfx::FloatPoint>(Web::AsyncScrollNodeStableID)> in_flight_destination_for;
if (wheel_delta_precision == Web::WheelDeltaPrecision::Discrete)
@@ -2253,7 +2264,7 @@ ContextState::WheelGestureLatchAttempt ContextState::hit_test_and_latch_wheel_ge
return { Web::InputRoutingDecision::ScrollerInOtherDocument };
auto const* node = m_async_scroll_tree.scroll_node_for_index(*scroll_node_index_to_latch);
VERIFY(node);
- m_wheel_gesture_routing.latch(node->stable_node_id, scroll_gesture_phase);
+ m_wheel_gesture_routing.latch(node->stable_node_id, scroll_gesture_phase, gesture_id);
return { decision, scroll_node_index_to_latch };
}
diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.h
index 433e132b9c8..18582441c6b 100644
--- a/Services/Compositor/ContextState.h
+++ b/Services/Compositor/ContextState.h
@@ -105,8 +105,10 @@ public:
Web::WheelDeltaPrecision wheel_delta_precision { Web::WheelDeltaPrecision::Discrete };
Web::ScrollGesturePhase scroll_gesture_phase { Web::ScrollGesturePhase::None };
Web::UIEvents::KeyModifier modifiers { Web::UIEvents::KeyModifier::Mod_None };
+ // The gesture of the containing context that the step is in, which the latch this context takes is for.
+ Optional<u64> gesture_id {};
- static WheelStepFromContainingContext for_wheel_event(Web::MouseEvent const&);
+ static WheelStepFromContainingContext for_wheel_event(Web::MouseEvent const&, Optional<u64> gesture_id);
};
// Where the first step of a gesture that the containing context hands in goes in this context. A nested context
@@ -185,6 +187,7 @@ public:
// Takes note of a wheel event from the UI as it arrives, ahead of anything that may turn it away or leave it to
// the main thread.
Web::WheelGestureMark note_wheel_event_from_ui(Web::MouseEvent const&, Optional<MonotonicTime> now_for_testing = {});
+ Optional<u64> wheel_gesture_id() const { return m_wheel_gesture_routing.gesture_id(); }
ContextUpdateResult handle_pinch_event(Web::PinchEvent const&);
bool admits_async_pinch() const { return m_wheel_gesture_routing.admits_async_pinch(); }
@@ -210,6 +213,8 @@ public:
u32 modifiers,
Compositing::AsyncScrollOperationTracking,
Compositing::WheelStepDispatch,
+ // The gesture the compositor named in the mark of the UI's wheel event, if it passed the event on.
+ Optional<u64> wheel_gesture_id_of_ui_event,
// The id the UI gave the wheel event, or 0 for a step that did not come from the UI.
u64 input_event_id,
Optional<MonotonicTime> now_for_testing = {});
@@ -348,13 +353,13 @@ private:
Optional<Gfx::FloatPoint> delta_the_node_did_not_scroll_by;
};
NodeScrollByWheelDelta scroll_node_by_wheel_delta(Compositing::SpatialNodeIndex, Gfx::FloatPoint delta, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, Compositing::AsyncScrollOperationTracking, Gfx::IntRect viewport_rect, MonotonicTime now, Compositing::ScrollChaining);
- WheelGestureRouting::ResolvedLatch resolve_wheel_scroll_latch(Web::ScrollGesturePhase);
+ WheelGestureRouting::ResolvedLatch resolve_wheel_scroll_latch(Web::ScrollGesturePhase, Optional<u64> gesture_id);
struct WheelGestureLatchAttempt {
Web::InputRoutingDecision decision;
Optional<Compositing::SpatialNodeIndex> latched_scroll_node_index {};
};
// The scroller the first step of a wheel gesture is routed to, which the gesture is latched to.
- WheelGestureLatchAttempt hit_test_and_latch_wheel_gesture(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, Optional<Web::UniqueNodeID> expected_document_id, Compositing::WheelStepDispatch, Compositing::NestedContextRegions);
+ WheelGestureLatchAttempt hit_test_and_latch_wheel_gesture(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, Optional<u64> gesture_id, Optional<Web::UniqueNodeID> expected_document_id, Compositing::WheelStepDispatch, Compositing::NestedContextRegions);
ContextUpdateResult take_wheel_step_from_containing_context(Compositing::SpatialNodeIndex, Web::InputRoutingDecision, WheelStepFromContainingContext const&, Compositing::ScrollChaining, MonotonicTime now);
Gfx::IntRect note_async_scrolling_viewport_rect(Gfx::IntRect viewport_rect, Optional<Compositing::AsyncScrollOffset> const&);
Optional<Compositing::AsyncScrollOperationID> snap_at_gesture_end(MonotonicTime now);
diff --git a/Services/Compositor/ScrollFlingController.cpp b/Services/Compositor/ScrollFlingController.cpp
index b5e318e706a..4a6e31c9efe 100644
--- a/Services/Compositor/ScrollFlingController.cpp
+++ b/Services/Compositor/ScrollFlingController.cpp
@@ -41,6 +41,7 @@ bool ScrollFlingController::start_if_flicked(Web::MouseEvent const& gesture_end_
.position = gesture_end_event.position,
.screen_position = gesture_end_event.screen_position,
.modifiers = gesture_end_event.modifiers,
+ .wheel_gesture_mark = gesture_end_event.wheel_gesture_mark,
};
return true;
}
@@ -107,6 +108,7 @@ Web::MouseEvent ScrollFlingController::event_of_active_fling(Gfx::FloatPoint del
.async_scroll_performed_default_action = false,
// The IDs of UI input events start at 1. Thus, ID 0 does not match a UI event.
.id = 0,
+ .wheel_gesture_mark = m_active_fling->wheel_gesture_mark,
};
}
diff --git a/Services/Compositor/ScrollFlingController.h b/Services/Compositor/ScrollFlingController.h
index a94b99d0047..7358e993af5 100644
--- a/Services/Compositor/ScrollFlingController.h
+++ b/Services/Compositor/ScrollFlingController.h
@@ -33,10 +33,11 @@ public:
private:
struct ActiveFling {
Compositing::ScrollFling fling;
- // The fling steps use the position and modifiers of the gesture end event.
+ // The fling steps use the position, modifiers and gesture of the gesture end event.
Web::DevicePixelPoint position;
Web::DevicePixelPoint screen_position;
Web::UIEvents::KeyModifier modifiers { Web::UIEvents::KeyModifier::Mod_None };
+ Optional<Web::WheelGestureMark> wheel_gesture_mark;
bool ends_on_next_step { false };
};
diff --git a/Services/Compositor/WheelGestureRouting.cpp b/Services/Compositor/WheelGestureRouting.cpp
index 02b9120a014..375b33a3a92 100644
--- a/Services/Compositor/WheelGestureRouting.cpp
+++ b/Services/Compositor/WheelGestureRouting.cpp
@@ -11,6 +11,12 @@
namespace Compositor {
+static u64 allocate_wheel_gesture_id()
+{
+ static u64 last_wheel_gesture_id = 0;
+ return ++last_wheel_gesture_id;
+}
+
static float position_slop_in_device_pixels(Compositing::AsyncScrollTree const& async_scroll_tree)
{
return Compositing::wheel_gesture_position_slop_in_css_pixels * static_cast<float>(async_scroll_tree.device_pixels_per_css_pixel());
@@ -58,13 +64,16 @@ bool WheelGestureRouting::note_wheel_event(u64 input_event_id, Web::ScrollGestur
m_newest_wheel_event_ids_from_ui.ended = input_event_id;
}
- bool starts_gesture = !m_gesture.has_value() || !m_gesture->is_continued_by(position, phase, modifiers, now, position_slop_in_device_pixels(async_scroll_tree), m_touchpad_gesture_end);
+ bool starts_gesture = !m_gesture.has_value() || !m_gesture->identity.is_continued_by(position, phase, modifiers, now, position_slop_in_device_pixels(async_scroll_tree), m_touchpad_gesture_end);
if (starts_gesture) {
- m_gesture = Compositing::WheelGestureIdentity::started_by(position, phase, modifiers, now);
+ m_gesture = Gesture {
+ .id = allocate_wheel_gesture_id(),
+ .identity = Compositing::WheelGestureIdentity::started_by(position, phase, modifiers, now),
+ };
m_gesture_had_wheel_event_with_delta = false;
m_latch.clear();
} else {
- m_gesture->advance_to(phase, now);
+ m_gesture->identity.advance_to(phase, now);
}
if (!m_gesture_had_wheel_event_with_delta && !wheel_delta.is_zero()) {
m_gesture_had_wheel_event_with_delta = true;
@@ -73,6 +82,13 @@ bool WheelGestureRouting::note_wheel_event(u64 input_event_id, Web::ScrollGestur
return starts_gesture;
}
+Optional<u64> WheelGestureRouting::gesture_id() const
+{
+ if (!m_gesture.has_value())
+ return {};
+ return m_gesture->id;
+}
+
void WheelGestureRouting::forget_gesture()
{
m_gesture.clear();
@@ -100,10 +116,14 @@ bool WheelGestureRouting::step_was_overtaken_by_ui(Web::ScrollGesturePhase phase
VERIFY_NOT_REACHED();
}
-WheelGestureRouting::ResolvedLatch WheelGestureRouting::resolve_latch(Compositing::AsyncScrollTree const& async_scroll_tree, Compositing::AccumulatedVisualContextTree const& current_visual_context_tree, Web::ScrollGesturePhase scroll_gesture_phase)
+WheelGestureRouting::ResolvedLatch WheelGestureRouting::resolve_latch(Compositing::AsyncScrollTree const& async_scroll_tree, Compositing::AccumulatedVisualContextTree const& current_visual_context_tree, Web::ScrollGesturePhase scroll_gesture_phase, Optional<u64> gesture_id)
{
if (!m_latch.has_value())
return {};
+ if (m_latch->gesture_id != gesture_id) {
+ m_latch.clear();
+ return {};
+ }
if (m_latch->nested_context_id.has_value() || !m_latch->stable_node_id.has_value()) {
m_latch->last_scroll_gesture_phase = scroll_gesture_phase;
return { .nested_context_id = m_latch->nested_context_id, .keeps_steps = !m_latch->nested_context_id.has_value() };
@@ -129,7 +149,7 @@ Optional<Web::AsyncScrollNodeStableID> WheelGestureRouting::latched_scroller() c
bool WheelGestureRouting::gesture_lasts_until_fingers_lift() const
{
- return m_touchpad_gesture_end == Compositing::TouchpadGestureEnd::WhenFingersLift && m_gesture.has_value() && m_gesture->is_held_by_fingers();
+ return m_touchpad_gesture_end == Compositing::TouchpadGestureEnd::WhenFingersLift && m_gesture.has_value() && m_gesture->identity.is_held_by_fingers();
}
Optional<Web::AsyncScrollNodeStableID> WheelGestureRouting::scroller_held_by_fingers() const
@@ -137,32 +157,35 @@ Optional<Web::AsyncScrollNodeStableID> WheelGestureRouting::scroller_held_by_fin
if (m_touchpad_gesture_end != Compositing::TouchpadGestureEnd::WhenFingersLift || !m_latch.has_value())
return {};
// The gesture here has every event; a context nested in another has only the steps handed to it, on its latch.
- bool held_by_fingers = m_gesture.has_value() ? m_gesture->is_held_by_fingers() : m_latch->last_scroll_gesture_phase == Web::ScrollGesturePhase::Ongoing;
+ bool held_by_fingers = m_gesture.has_value() ? m_gesture->identity.is_held_by_fingers() : m_latch->last_scroll_gesture_phase == Web::ScrollGesturePhase::Ongoing;
if (!held_by_fingers)
return {};
return m_latch->stable_node_id;
}
-void WheelGestureRouting::latch(Web::AsyncScrollNodeStableID stable_node_id, Web::ScrollGesturePhase scroll_gesture_phase)
+void WheelGestureRouting::latch(Web::AsyncScrollNodeStableID stable_node_id, Web::ScrollGesturePhase scroll_gesture_phase, Optional<u64> gesture_id)
{
m_latch = Latch {
+ .gesture_id = gesture_id,
.stable_node_id = stable_node_id,
.last_scroll_gesture_phase = scroll_gesture_phase,
};
}
-void WheelGestureRouting::latch_to_nested_context(Web::CompositorContextId nested_context_id, Optional<Web::AsyncScrollNodeStableID> scroller, Web::ScrollGesturePhase scroll_gesture_phase)
+void WheelGestureRouting::latch_to_nested_context(Web::CompositorContextId nested_context_id, Optional<Web::AsyncScrollNodeStableID> scroller, Web::ScrollGesturePhase scroll_gesture_phase, Optional<u64> gesture_id)
{
m_latch = Latch {
+ .gesture_id = gesture_id,
.stable_node_id = scroller,
.last_scroll_gesture_phase = scroll_gesture_phase,
.nested_context_id = nested_context_id,
};
}
-void WheelGestureRouting::latch_keeping_steps(Web::ScrollGesturePhase scroll_gesture_phase)
+void WheelGestureRouting::latch_keeping_steps(Web::ScrollGesturePhase scroll_gesture_phase, Optional<u64> gesture_id)
{
m_latch = Latch {
+ .gesture_id = gesture_id,
.stable_node_id = {},
.last_scroll_gesture_phase = scroll_gesture_phase,
};
diff --git a/Services/Compositor/WheelGestureRouting.h b/Services/Compositor/WheelGestureRouting.h
index 0d3c758da2f..f2d123e4b1c 100644
--- a/Services/Compositor/WheelGestureRouting.h
+++ b/Services/Compositor/WheelGestureRouting.h
@@ -36,6 +36,9 @@ public:
// event is noted as this context first sees it: from the UI, or from the main thread for one the UI did not send.
bool note_wheel_event_from_ui(Web::MouseEvent const&, Gfx::FloatPoint position, Compositing::AsyncScrollTree const&, MonotonicTime now);
bool note_wheel_event(u64 input_event_id, Web::ScrollGesturePhase, u32 modifiers, Gfx::FloatPoint wheel_delta, Gfx::FloatPoint position, Compositing::AsyncScrollTree const&, MonotonicTime now);
+ // The id of the gesture of the wheel events this context notes. No gesture of any context in the process has the
+ // same id, so a context nested in another one can tell the gestures of the containing context from its own.
+ Optional<u64> gesture_id() const;
// Whether the wheel event is the first step of the gesture from the UI that moves anything. A touchpad gesture can
// start with a step that has no delta.
bool is_first_wheel_event_with_delta(u64 input_event_id) const { return input_event_id != 0 && input_event_id == m_id_of_first_wheel_event_with_delta; }
@@ -59,11 +62,11 @@ public:
bool keeps_steps { false };
};
// The latch of the gesture a step continues, advanced to the step's phase. A latch whose scroller the current
- // display list no longer has is dropped here; one the step does not continue was let go of as the step was noted.
- ResolvedLatch resolve_latch(Compositing::AsyncScrollTree const&, Compositing::AccumulatedVisualContextTree const& current_visual_context_tree, Web::ScrollGesturePhase);
- void latch(Web::AsyncScrollNodeStableID, Web::ScrollGesturePhase);
- void latch_to_nested_context(Web::CompositorContextId, Optional<Web::AsyncScrollNodeStableID> scroller, Web::ScrollGesturePhase);
- void latch_keeping_steps(Web::ScrollGesturePhase);
+ // display list no longer has, or that was taken for another gesture than the step's, is dropped here.
+ ResolvedLatch resolve_latch(Compositing::AsyncScrollTree const&, Compositing::AccumulatedVisualContextTree const& current_visual_context_tree, Web::ScrollGesturePhase, Optional<u64> gesture_id);
+ void latch(Web::AsyncScrollNodeStableID, Web::ScrollGesturePhase, Optional<u64> gesture_id);
+ void latch_to_nested_context(Web::CompositorContextId, Optional<Web::AsyncScrollNodeStableID> scroller, Web::ScrollGesturePhase, Optional<u64> gesture_id);
+ void latch_keeping_steps(Web::ScrollGesturePhase, Optional<u64> gesture_id);
void clear_latch() { m_latch.clear(); }
void forget_gesture();
void relatch_to(Web::AsyncScrollNodeStableID);
@@ -76,6 +79,10 @@ private:
// The scroller the first step of a wheel gesture was routed to. Every later step of the gesture scrolls it without
// hit testing, and stops at its edge rather than handing the rest of the gesture to an ancestor.
struct Latch {
+ // The gesture the latch was taken for, which only the steps of that gesture continue. A context nested in
+ // another one takes it for the gesture of the containing context. Empty when the step that took it was in no
+ // gesture the compositor knows of.
+ Optional<u64> gesture_id;
// Empty for a latch that keeps the steps without a scroller.
Optional<Web::AsyncScrollNodeStableID> stable_node_id;
// The phase of the last step that reached the latch, which says whether the fingers of its gesture are down.
@@ -99,9 +106,13 @@ private:
Compositing::WheelRoutingAdmission m_admission { Compositing::WheelRoutingAdmission::NoAsyncScrollingState };
bool m_has_blocking_wheel_event_listeners { false };
u64 m_wheel_event_listener_state_generation { 0 };
+ struct Gesture {
+ u64 id;
+ Compositing::WheelGestureIdentity identity;
+ };
// The gesture of the wheel events this context sees first: the UI's, or ones the UI never sent that the main
// thread makes. It says which gesture a step is in, whether this context or the main thread scrolls the step.
- Optional<Compositing::WheelGestureIdentity> m_gesture;
+ Optional<Gesture> m_gesture;
NewestWheelEventIdsFromUI m_newest_wheel_event_ids_from_ui;
u64 m_id_of_first_wheel_event_with_delta { 0 };
bool m_gesture_had_wheel_event_with_delta { false };