Skip to content

Truly independent web browser

Compositor+LibWeb: Route wheel events the UI did not send as the UI's

Aliaksandr Kalenik0dad74564ee6
diff --git a/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.cpp b/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.cpp
index f735837c56a..b00ee7556d2 100644
--- a/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.cpp
+++ b/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.cpp
@@ -67,12 +67,4 @@ void WheelGestureIdentity::advance_to(Web::ScrollGesturePhase phase, MonotonicTi
m_ended_at = now;
}
-void WheelGestureIdentity::did_handle_event(MonotonicTime now)
-{
- bool handled_event_ended_gesture = m_ended_at == m_last_event_time;
- if (handled_event_ended_gesture)
- m_ended_at = now;
- m_last_event_time = now;
-}
-
}
diff --git a/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.h b/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.h
index 5bc06fefd76..b5fba19665e 100644
--- a/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.h
+++ b/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.h
@@ -25,9 +25,8 @@ enum class TouchpadGestureEnd : u8 {
WhenFingersLift,
};
-// A wheel gesture keeps scrolling the scroller its first event was routed to, so the compositor and the main thread
-// both have to tell whether a wheel event continues the gesture they latched or starts another one. Both decide by
-// the rules here, so that they agree on the scroller an event belongs to without telling each other.
+// A wheel gesture keeps scrolling the scroller its first event was routed to, so the compositor has to tell whether a
+// wheel event continues the gesture it latched or starts another one.
class COMPOSITING_API WheelGestureIdentity {
public:
static WheelGestureIdentity started_by(Gfx::FloatPoint position, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now);
@@ -37,7 +36,6 @@ public:
// Whether the fingers of a touchpad gesture are still on the touchpad, before it ends or hands over to momentum.
bool is_held_by_fingers() const;
void advance_to(Web::ScrollGesturePhase, MonotonicTime now);
- void did_handle_event(MonotonicTime now);
private:
enum class Kind : u8 {
diff --git a/Libraries/LibCompositing/Types.cpp b/Libraries/LibCompositing/Types.cpp
index f63080c2468..4fea0138d70 100644
--- a/Libraries/LibCompositing/Types.cpp
+++ b/Libraries/LibCompositing/Types.cpp
@@ -288,4 +288,29 @@ ErrorOr<Compositing::AsyncScrollEnqueueResult> decode(Decoder& decoder)
};
}
+template<>
+ErrorOr<void> encode(Encoder& encoder, Compositing::WheelEventAnswer const& answer)
+{
+ TRY(encoder.encode(answer.performed_default_action));
+ TRY(encoder.encode(answer.wheel_gesture_mark));
+ TRY(encoder.encode(answer.operation_id));
+ TRY(encoder.encode(answer.operation_context_id));
+ TRY(encoder.encode(answer.routing_decision));
+ TRY(encoder.encode(answer.routed_scroller));
+ return {};
+}
+
+template<>
+ErrorOr<Compositing::WheelEventAnswer> decode(Decoder& decoder)
+{
+ return Compositing::WheelEventAnswer {
+ .performed_default_action = TRY(decoder.decode<bool>()),
+ .wheel_gesture_mark = TRY(decoder.decode<Optional<Web::WheelGestureMark>>()),
+ .operation_id = TRY(decoder.decode<Optional<Compositing::AsyncScrollOperationID>>()),
+ .operation_context_id = TRY(decoder.decode<Optional<Web::CompositorContextId>>()),
+ .routing_decision = TRY(decoder.decode<Optional<Web::InputRoutingDecision>>()),
+ .routed_scroller = TRY(decoder.decode<Optional<Web::AsyncScrollNodeStableID>>()),
+ };
+}
+
}
diff --git a/Libraries/LibCompositing/Types.h b/Libraries/LibCompositing/Types.h
index 0b69f4d6b82..d23a4312d6a 100644
--- a/Libraries/LibCompositing/Types.h
+++ b/Libraries/LibCompositing/Types.h
@@ -18,6 +18,7 @@
#include <LibCompositing/Scrolling/AsyncScrollingState.h>
#include <LibIPC/Forward.h>
#include <LibWebCommon/Page/CompositorContextId.h>
+#include <LibWebCommon/Page/InputEvent.h>
#include <LibWebCommon/Page/InputRoutingDecision.h>
#include <LibWebCommon/Page/PageId.h>
#include <LibWebCommon/PixelUnits.h>
@@ -109,11 +110,31 @@ struct AsyncScrollEnqueueResult {
Optional<Web::AsyncScrollNodeStableID> routed_scroller {};
};
+// What the compositor did with a wheel event that WebContent's main thread passed on to it, as the compositor does with
+// the UI's wheel events before the main thread gets them.
+struct WheelEventAnswer {
+ bool performed_default_action { false };
+ Optional<Web::WheelGestureMark> wheel_gesture_mark {};
+ // The operation the event started, whose end the scroll updates of the context report.
+ Optional<AsyncScrollOperationID> operation_id {};
+ Optional<Web::CompositorContextId> operation_context_id {};
+ // Why the compositor took or turned away the event, and the scroller it routed the event to.
+ Optional<Web::InputRoutingDecision> routing_decision {};
+ Optional<Web::AsyncScrollNodeStableID> routed_scroller {};
+};
+
enum class AsyncScrollOperationTracking {
No,
Yes,
};
+// Who scrolls by a wheel event that WebContent's main thread passes on to the compositor, which names the gesture of
+// the event either way.
+enum class WheelEventScrolling : u8 {
+ ByCompositor,
+ ByMainThread,
+};
+
// Blocking wheel event listeners hold a wheel step back from the compositor until the page has dispatched it. A step
// that the page dispatched and did not cancel has nothing left to wait for.
enum class WheelStepDispatch : u8 {
@@ -304,4 +325,9 @@ COMPOSITING_API ErrorOr<void> encode(Encoder&, Compositing::AsyncScrollEnqueueRe
template<>
COMPOSITING_API ErrorOr<Compositing::AsyncScrollEnqueueResult> decode(Decoder&);
+template<>
+COMPOSITING_API ErrorOr<void> encode(Encoder&, Compositing::WheelEventAnswer const&);
+template<>
+COMPOSITING_API ErrorOr<Compositing::WheelEventAnswer> decode(Decoder&);
+
}
diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.cpp b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
index a22dae58f96..93a9cfa79f8 100644
--- a/Libraries/LibWeb/Compositor/CompositorConnection.cpp
+++ b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
@@ -486,12 +486,25 @@ 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, Optional<u64> wheel_gesture_id, u64 input_event_id)
+Compositing::WheelEventAnswer CompositorConnection::take_wheel_event_from_main_thread(Web::CompositorContextId context_id, Web::MouseEvent const& event, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelEventScrolling scrolling)
{
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, wheel_gesture_id, input_event_id);
+ auto response = send_sync_but_allow_failure<Messages::CompositorWebContentServer::TakeWheelEventFromMainThread>(context_id, event.clone_without_browser_data(), operation_tracking, scrolling);
+ if (!response) {
+ did_lose_compositor();
+ return {};
+ }
+ return response->take_answer();
+}
+
+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, 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, 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 0273a95db0c..e0426e55253 100644
--- a/Libraries/LibWeb/Compositor/CompositorConnection.h
+++ b/Libraries/LibWeb/Compositor/CompositorConnection.h
@@ -66,7 +66,8 @@ 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, Optional<u64> wheel_gesture_id, u64 input_event_id);
+ Compositing::WheelEventAnswer take_wheel_event_from_main_thread(Web::CompositorContextId, Web::MouseEvent const&, Compositing::AsyncScrollOperationTracking, Compositing::WheelEventScrolling);
+ 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, 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 f7156339817..6bf3a2b5b78 100644
--- a/Libraries/LibWeb/Compositor/CompositorHost.cpp
+++ b/Libraries/LibWeb/Compositor/CompositorHost.cpp
@@ -61,10 +61,15 @@ void CompositorContextHandle::invalidate_wheel_event_listener_state(u64 generati
m_host.invalidate_wheel_event_listener_state(m_context_id, generation);
}
+Compositing::WheelEventAnswer CompositorContextHandle::take_wheel_event_from_main_thread(Web::MouseEvent const& event, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelEventScrolling scrolling)
+{
+ return m_host.take_wheel_event_from_main_thread(m_context_id, event, operation_tracking, scrolling);
+}
+
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, Optional<u64> wheel_gesture_id, u64 input_event_id)
+ Gfx::FloatPoint delta_in_device_pixels, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, 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, wheel_gesture_id, 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, operation_tracking, wheel_step_dispatch, wheel_gesture_id, input_event_id);
}
String CompositorContextHandle::scroll_state_for_testing(Web::AsyncScrollNodeStableID stretched_scroller)
@@ -462,11 +467,18 @@ void CompositorHost::invalidate_wheel_event_listener_state(Web::CompositorContex
connection->invalidate_wheel_event_listener_state(context_id, generation);
}
+Compositing::WheelEventAnswer CompositorHost::take_wheel_event_from_main_thread(Web::CompositorContextId context_id, Web::MouseEvent const& event, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelEventScrolling scrolling)
+{
+ if (auto* connection = compositor_connection())
+ return connection->take_wheel_event_from_main_thread(context_id, event, operation_tracking, scrolling);
+ return {};
+}
+
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, Optional<u64> wheel_gesture_id, u64 input_event_id)
+ Gfx::FloatPoint delta_in_device_pixels, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, 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, wheel_gesture_id, 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, 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 48da30eaf12..943dd1be8ec 100644
--- a/Libraries/LibWeb/Compositor/CompositorHost.h
+++ b/Libraries/LibWeb/Compositor/CompositorHost.h
@@ -65,8 +65,9 @@ public:
void set_video_sink_ticking(Media::VideoSinkHandle, bool should_tick);
void invalidate_wheel_event_listener_state(u64 generation);
void invalidate_keyboard_scroll_state(u64 generation);
+ Compositing::WheelEventAnswer take_wheel_event_from_main_thread(Web::MouseEvent const&, Compositing::AsyncScrollOperationTracking, Compositing::WheelEventScrolling);
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, Optional<u64> wheel_gesture_id, u64 input_event_id);
+ Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, 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);
@@ -127,8 +128,9 @@ public:
Compositing::VideoFrameHold::ReleaseThroughCompositor video_frame_hold_releaser_for_current_connection() const;
void invalidate_wheel_event_listener_state(Web::CompositorContextId, u64 generation);
void invalidate_keyboard_scroll_state(Web::CompositorContextId, u64 generation);
+ Compositing::WheelEventAnswer take_wheel_event_from_main_thread(Web::CompositorContextId, Web::MouseEvent const&, Compositing::AsyncScrollOperationTracking, Compositing::WheelEventScrolling);
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, Optional<u64> wheel_gesture_id, u64 input_event_id);
+ Gfx::FloatPoint delta_in_device_pixels, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, 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 e6234418ac6..571bd9cff9b 100644
--- a/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Libraries/LibWeb/Page/EventHandler.cpp
@@ -944,6 +944,15 @@ static Layout::Node* scroll_containing_block_chain_smoothly(HTML::LocalNavigable
return nullptr;
}
+static GC::Ptr<HTML::LocalNavigable> local_navigable_with_compositor_context(Page& page, Web::CompositorContextId context_id)
+{
+ for (auto& navigable : HTML::all_local_navigables()) {
+ if (&navigable->page() == &page && navigable->has_compositor_context() && navigable->compositor_context().id() == context_id)
+ return navigable;
+ }
+ return {};
+}
+
void EventHandler::record_input_routing(InputRoutingDecision decision, Optional<AsyncScrollNodeStableID> scroller, GC::Ptr<DOM::Node const> target, InputTraceStage stage)
{
auto& input_trace = m_navigable->page().input_trace();
@@ -971,28 +980,77 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
if (!document->is_fully_active())
return EventResult::Dropped;
- 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 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_id.has_value())
- continues_latched_gesture = m_wheel_scroll_latch->wheel_gesture_id == wheel_gesture_id;
+ auto can_attempt_async_scroll = m_navigable->has_compositor_context();
+ auto operation_tracking = async_scroll_operation
+ ? Compositing::AsyncScrollOperationTracking::Yes
+ : Compositing::AsyncScrollOperationTracking::No;
+
+ // NB: Layout reads can remove scrolling boxes before their updated tree reaches the compositor.
+ // Only fall back when the presented display list refers to an older tree structure.
+ auto compositor_display_list_is_outdated = [&] {
+ auto local_root = m_navigable->local_root();
+ if (!local_root->needs_to_record_display_list() && !local_root->has_recording_in_flight())
+ return false;
+ auto display_list = local_root->presenter().compositor_display_list();
+ auto root_document = local_root->active_document();
+ if (!display_list || !root_document || !root_document->has_paint_state())
+ return false;
+ Layout::ForcedReadScope root_read { *root_document };
+ root_document->update_paint_and_hit_testing_properties_if_needed();
+ return display_list->compatible_visual_context_tree_structural_epoch() != root_document->paint_state().visual_context_tree_structural_epoch_without_update(root_read);
+ };
+
+ // An event that no compositor has seen, such as one a test makes, goes there first, as the UI's events do. The
+ // compositor names the gesture of the event, and scrolls by it before the page sees it unless this thread keeps
+ // the scrolling.
+ bool asked_compositor_first = false;
+ if (!wheel_gesture_mark.has_value() && can_attempt_async_scroll) {
+ Optional<InputRoutingDecision> reason_to_scroll_on_this_thread;
+ if (document->visual_viewport()->scale() != 1.0)
+ reason_to_scroll_on_this_thread = InputRoutingDecision::AsyncScrollNotAttemptedVisualViewportScaled;
+ else if (compositor_display_list_is_outdated())
+ reason_to_scroll_on_this_thread = InputRoutingDecision::AsyncScrollNotAttemptedDisplayListOutdated;
+ auto scrolling = reason_to_scroll_on_this_thread.has_value() ? Compositing::WheelEventScrolling::ByMainThread : Compositing::WheelEventScrolling::ByCompositor;
+
+ Web::MouseEvent event {
+ .type = Web::MouseEvent::Type::MouseWheel,
+ .position = m_navigable->page().css_to_device_point(visual_viewport_position),
+ .screen_position = m_navigable->page().css_to_device_point(screen_position),
+ .button = static_cast<UIEvents::MouseButton>(button),
+ .buttons = static_cast<UIEvents::MouseButton>(buttons),
+ .modifiers = static_cast<UIEvents::KeyModifier>(modifiers),
+ .wheel_delta_x = wheel_delta_x,
+ .wheel_delta_y = wheel_delta_y,
+ .wheel_tick_120ths_x = wheel_tick_120ths_x,
+ .wheel_tick_120ths_y = wheel_tick_120ths_y,
+ .wheel_delta_precision = wheel_delta_precision,
+ .scroll_gesture_phase = scroll_gesture_phase,
+ .id = handling_input_event_id(),
+ };
+ auto answer = m_navigable->compositor_context().take_wheel_event_from_main_thread(event, operation_tracking, scrolling);
+ if (reason_to_scroll_on_this_thread.has_value())
+ record_input_routing(*reason_to_scroll_on_this_thread);
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);
+ record_input_routing(answer.routing_decision.value_or(InputRoutingDecision::NoAnswerFromCompositor), answer.routed_scroller, {}, InputTraceStage::CompositorForMainThread);
+ wheel_gesture_mark = answer.wheel_gesture_mark;
+ async_scroll_performed_default_action = answer.performed_default_action;
+ if (async_scroll_operation && answer.operation_id.has_value() && answer.operation_context_id.has_value()) {
+ if (auto navigable = local_navigable_with_compositor_context(m_navigable->page(), *answer.operation_context_id))
+ *async_scroll_operation = AsyncScrollOperation { navigable, *answer.operation_id };
+ }
+ asked_compositor_first = true;
}
- if (continues_latched_gesture)
- m_wheel_scroll_latch->gesture.advance_to(scroll_gesture_phase, now);
- else
+
+ // The compositor names the gesture of each event, 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 = m_wheel_scroll_latch.has_value() && wheel_gesture_id.has_value() && m_wheel_scroll_latch->wheel_gesture_id == wheel_gesture_id;
+ if (!continues_latched_gesture)
m_wheel_scroll_latch.clear();
bool gesture_lasts_until_fingers_lift = wheel_gesture_mark.has_value() && wheel_gesture_mark->lasts_until_fingers_lift;
ScopeGuard measure_next_pause_from_end_of_handling = [this, gesture_lasts_until_fingers_lift] {
- if (m_wheel_scroll_latch.has_value())
- m_wheel_scroll_latch->gesture.did_handle_event(MonotonicTime::now());
m_navigable->did_handle_wheel_event(gesture_lasts_until_fingers_lift);
};
@@ -1001,35 +1059,20 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
m_navigable->adopt_pending_async_scroll_offsets(Compositing::AsyncScrollUpdateFreshness::FromCompositor);
auto visual_viewport = document->visual_viewport();
- auto can_attempt_async_scroll = m_navigable->has_compositor_context();
// Hands the wheel input to the compositor, which scrolls from the offsets it holds now; the operation it starts
// for the input is the one a caller follows.
auto enqueue_async_scroll = [&](Gfx::FloatPoint delta_in_device_pixels, Compositing::WheelStepDispatch wheel_step_dispatch) {
- // NB: Layout reads can remove scrolling boxes before their updated tree reaches the compositor.
- // Only fall back when the presented display list refers to an older tree structure.
- auto local_root = m_navigable->local_root();
- if (local_root->needs_to_record_display_list() || local_root->has_recording_in_flight()) {
- auto display_list = local_root->presenter().compositor_display_list();
- auto root_document = local_root->active_document();
- if (display_list && root_document && root_document->has_paint_state()) {
- Layout::ForcedReadScope root_read { *root_document };
- root_document->update_paint_and_hit_testing_properties_if_needed();
- if (display_list->compatible_visual_context_tree_structural_epoch() != root_document->paint_state().visual_context_tree_structural_epoch_without_update(root_read)) {
- record_input_routing(InputRoutingDecision::AsyncScrollNotAttemptedDisplayListOutdated);
- return false;
- }
- }
+ if (compositor_display_list_is_outdated()) {
+ record_input_routing(InputRoutingDecision::AsyncScrollNotAttemptedDisplayListOutdated);
+ return false;
}
auto viewport_rect = m_navigable->page().css_to_device_rect(m_navigable->viewport_rect()).to_type<int>();
auto device_position = m_navigable->page().css_to_device_point(visual_viewport_position);
auto async_scroll_position = Gfx::FloatPoint { static_cast<float>(device_position.x().value()), static_cast<float>(device_position.y().value()) };
- auto operation_tracking = async_scroll_operation
- ? 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, wheel_gesture_id, handling_input_event_id());
+ document->unique_id(), async_scroll_position, delta_in_device_pixels, viewport_rect, wheel_delta_precision, scroll_gesture_phase, 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 };
@@ -1042,7 +1085,7 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
// The end of a gesture is reported to the compositor before the gesture settles here, so that a snap scroll
// the compositor starts for it is the scroll the settlement finds in flight rather than one of its own.
- if (scroll_gesture_phase == Web::ScrollGesturePhase::Ended && !async_scroll_performed_default_action && can_attempt_async_scroll
+ if (scroll_gesture_phase == Web::ScrollGesturePhase::Ended && !async_scroll_performed_default_action && can_attempt_async_scroll && !asked_compositor_first
&& visual_viewport->scale() == 1.0 && enqueue_async_scroll({}, Compositing::WheelStepDispatch::NotYetDispatched)) {
async_scroll_performed_default_action = true;
m_navigable->adopt_pending_async_scroll_offsets(Compositing::AsyncScrollUpdateFreshness::FromCompositor);
@@ -1080,7 +1123,6 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
if (!wheel_event_has_delta || !target.dom_node())
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> {},
@@ -1119,6 +1161,8 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
if (can_attempt_async_scroll && async_scroll_performed_default_action) {
dbgln_if(COMPOSITOR_DEBUG, "[Compositor] Not attempting wheel async scroll: default action already performed");
record_input_routing(InputRoutingDecision::DefaultActionPerformedByCompositor);
+ } else if (asked_compositor_first) {
+ dbgln_if(COMPOSITOR_DEBUG, "[Compositor] Not attempting wheel async scroll: the compositor was asked first");
} else if (can_attempt_async_scroll && visual_viewport->scale() != 1.0) {
dbgln_if(COMPOSITOR_DEBUG, "[Compositor] Not attempting wheel async scroll: visual viewport is scaled");
record_input_routing(InputRoutingDecision::AsyncScrollNotAttemptedVisualViewportScaled);
diff --git a/Libraries/LibWeb/Page/EventHandler.h b/Libraries/LibWeb/Page/EventHandler.h
index d2a5b1f0c50..f7260908fdc 100644
--- a/Libraries/LibWeb/Page/EventHandler.h
+++ b/Libraries/LibWeb/Page/EventHandler.h
@@ -15,7 +15,6 @@
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <LibCompositing/Scrolling/AsyncScrollingState.h>
-#include <LibCompositing/Scrolling/WheelGestureIdentity.h>
#include <LibCompositing/Types.h>
#include <LibGC/Ptr.h>
#include <LibGC/Weak.h>
@@ -362,8 +361,6 @@ 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;
diff --git a/Services/Compositor/AsyncScrollUpdateOutbox.h b/Services/Compositor/AsyncScrollUpdateOutbox.h
index c90dcab5cb8..ee94291d64d 100644
--- a/Services/Compositor/AsyncScrollUpdateOutbox.h
+++ b/Services/Compositor/AsyncScrollUpdateOutbox.h
@@ -17,6 +17,8 @@ class AsyncScrollUpdateOutbox {
public:
Compositing::AsyncScrollOperationID allocate_operation_id() { return ++m_last_allocated_operation_id; }
void complete_operation(Compositing::AsyncScrollOperationID operation_id) { m_completed_operation_ids.append(operation_id); }
+ // Whether the operation ended since the updates were last taken.
+ bool has_completed_operation(Compositing::AsyncScrollOperationID operation_id) const { return m_completed_operation_ids.contains_slow(operation_id); }
void note_operation_taken_over_by_user_input(Compositing::AsyncScrollOperationID operation_id) { m_operation_ids_taken_over_by_user_input.append(operation_id); }
void record_scroll_offsets(ReadonlySpan<Compositing::AsyncScrollOffset>);
void record_started_user_scroll(Compositing::StartedUserScroll started_user_scroll) { m_started_user_scrolls.append(move(started_user_scroll)); }
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cpp
index 366f1e62278..57c2022b240 100644
--- a/Services/Compositor/CompositorState.cpp
+++ b/Services/Compositor/CompositorState.cpp
@@ -635,6 +635,7 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId c
dispatch_scroll_fling_step(context_id, *context, context->end_scroll_fling(), MonotonicTime::now());
auto is_wheel_event = event.type == Web::MouseEvent::Type::MouseWheel;
+ bool is_first_wheel_event_with_delta = false;
if (is_wheel_event) {
// A key or a script that scrolls takes over from momentum, until wheel input other than the momentum takes
// over again.
@@ -643,7 +644,9 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId c
presentation->did_consume_input_event(context_id, event.id);
return;
}
- event.wheel_gesture_mark = context->note_wheel_event_from_ui(event);
+ auto noted = context->note_wheel_event_from_ui(event);
+ event.wheel_gesture_mark = noted.wheel_gesture_mark;
+ is_first_wheel_event_with_delta = noted.is_first_wheel_event_with_delta;
// The UI can send the end of a gesture more than once. An end that arrives during a fling belongs to the
// flicked gesture, so it does not stop the fling.
@@ -667,7 +670,7 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId c
ContextState::ContextUpdateResult result;
if (is_wheel_event)
- result = scroll_for_wheel_step(context_id, *context, event, WheelStepOrigin::UI);
+ result = scroll_for_wheel_step(context_id, *context, event, WheelStepOrigin::UI, is_first_wheel_event_with_delta, Compositing::AsyncScrollOperationTracking::No, MonotonicTime::now());
else
result = handle_mouse_event_in_nested_contexts(context_id, *context, event);
if (result.nested_context_hand_off.has_value())
@@ -922,13 +925,23 @@ bool CompositorState::is_nested_in(Web::CompositorContextId containing_context_i
return false;
}
-ContextState::ContextUpdateResult CompositorState::scroll_for_wheel_step(Web::CompositorContextId context_id, ContextState& context, Web::MouseEvent const& event, WheelStepOrigin origin, Optional<MonotonicTime> fling_step_time)
+ContextState::ContextUpdateResult CompositorState::scroll_for_wheel_step(Web::CompositorContextId context_id, ContextState& context, Web::MouseEvent const& event, WheelStepOrigin origin, bool is_first_wheel_event_with_delta, Compositing::AsyncScrollOperationTracking operation_tracking, MonotonicTime now)
{
- auto now = fling_step_time.value_or(MonotonicTime::now());
- auto result = origin == WheelStepOrigin::UI ? context.handle_wheel_event(event) : context.scroll_for_fling_step(event, now);
+ ContextState::ContextUpdateResult result;
+ switch (origin) {
+ case WheelStepOrigin::UI:
+ result = context.handle_wheel_event(event, is_first_wheel_event_with_delta, now);
+ break;
+ case WheelStepOrigin::Fling:
+ result = context.scroll_for_fling_step(event, now);
+ break;
+ case WheelStepOrigin::MainThread:
+ result = context.scroll_for_wheel_event_from_main_thread(event, is_first_wheel_event_with_delta, operation_tracking, now);
+ break;
+ }
bool presents_frame = result.frame_to_present.has_value();
if (result.nested_context_wheel_step.has_value()) {
- auto handed_step = hand_wheel_step_to_nested_context(context_id, context, event, *result.nested_context_wheel_step, now);
+ auto handed_step = hand_wheel_step_to_nested_context(context_id, context, event, *result.nested_context_wheel_step, operation_tracking, now);
result = move(handed_step.result);
presents_frame = handed_step.nested_context_presents_frame;
}
@@ -940,20 +953,22 @@ ContextState::ContextUpdateResult CompositorState::scroll_for_wheel_step(Web::Co
return result;
}
-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)
+CompositorState::WheelStepHandedToNestedContext CompositorState::hand_wheel_step_to_nested_context(Web::CompositorContextId context_id, ContextState& context, Web::MouseEvent const& event, ContextState::NestedContextWheelStep const& nested_step, Compositing::AsyncScrollOperationTracking operation_tracking, MonotonicTime now)
{
- auto step = ContextState::WheelStepFromContainingContext::for_wheel_event(event, context.wheel_gesture_id());
+ auto step = ContextState::WheelStepFromContainingContext::for_wheel_event(event, context.wheel_gesture_id(), operation_tracking);
// 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);
schedule_animation_frames_if_needed(nested_context);
- // Node ids are only unique within the process that made them.
+ // Node ids are only unique within the process that made them, and only that process follows the operations of
+ // the context.
bool ids_are_of_this_process = nested_context.is_owned_by(context.web_content_client());
return WheelStepHandedToNestedContext {
.result = {
.accepted = nested_result.accepted,
.routing_decision = nested_result.routing_decision,
.routed_scroller = ids_are_of_this_process ? nested_result.routed_scroller : Optional<Web::AsyncScrollNodeStableID> {},
+ .tracked_scroll_operation = ids_are_of_this_process ? nested_result.tracked_scroll_operation : Optional<ContextState::TrackedScrollOperation> {},
},
.nested_context_presents_frame = nested_result.frame_to_present.has_value(),
};
@@ -975,7 +990,7 @@ CompositorState::WheelStepHandedToNestedContext CompositorState::hand_wheel_step
auto taking_context = nested_context_taking_first_wheel_step(context_id, *nested_step.hit, step.delta_in_css_pixels, step.wheel_delta_precision);
if (!taking_context.has_value()) {
- auto result = context.scroll_for_wheel_event_passed_on_by_nested_context(event, now);
+ auto result = context.scroll_for_wheel_event_passed_on_by_nested_context(event, operation_tracking, now);
result.nested_context_hand_off = Web::InputRoutingDecision::NestedContextPassedStepOn;
return { .result = result, .nested_context_presents_frame = result.frame_to_present.has_value() };
}
@@ -1031,7 +1046,7 @@ void CompositorState::dispatch_scroll_fling_step(Web::CompositorContextId contex
// Send each fling step on the same route as a wheel event from the UI.
if (!event.has_value())
return;
- auto result = scroll_for_wheel_step(context_id, context, *event, WheelStepOrigin::Fling, now);
+ auto result = scroll_for_wheel_step(context_id, context, *event, WheelStepOrigin::Fling, false, Compositing::AsyncScrollOperationTracking::No, now);
if (result.nested_context_hand_off.has_value())
context.input_trace().record({ .input_event_id = event->id, .stage = Web::InputTraceStage::Compositor, .decision = *result.nested_context_hand_off });
if (result.routing_decision.has_value())
@@ -1074,12 +1089,35 @@ 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, Optional<u64> wheel_gesture_id, u64 input_event_id)
+Compositing::WheelEventAnswer CompositorState::take_wheel_event_from_main_thread(Web::CompositorContextId context_id, Web::MouseEvent const& event, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelEventScrolling scrolling)
+{
+ auto* context = context_if_present(context_id);
+ VERIFY(context);
+
+ auto now = MonotonicTime::now();
+ auto noted = context->note_wheel_event_from_main_thread(event, now);
+ if (scrolling == Compositing::WheelEventScrolling::ByMainThread)
+ return { .wheel_gesture_mark = noted.wheel_gesture_mark };
+ auto result = scroll_for_wheel_step(context_id, *context, event, WheelStepOrigin::MainThread, noted.is_first_wheel_event_with_delta, operation_tracking, now);
+ auto performed_default_action = apply_context_update_result(context_id, *context, result);
+ schedule_animation_frames_if_needed(*context);
+ auto const& tracked_scroll_operation = result.tracked_scroll_operation;
+ return {
+ .performed_default_action = performed_default_action,
+ .wheel_gesture_mark = noted.wheel_gesture_mark,
+ .operation_id = tracked_scroll_operation.map([](auto const& operation) { return operation.operation_id; }),
+ .operation_context_id = tracked_scroll_operation.map([](auto const& operation) { return operation.context_id; }),
+ .routing_decision = result.routing_decision,
+ .routed_scroller = result.routed_scroller,
+ };
+}
+
+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, 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, wheel_gesture_id, input_event_id);
+ auto result = context->async_scroll_by(expected_document_id, position, delta, viewport_rect, wheel_delta_precision, scroll_gesture_phase, 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 95ec19a7e7d..4a6d356ba66 100644
--- a/Services/Compositor/CompositorState.h
+++ b/Services/Compositor/CompositorState.h
@@ -130,7 +130,9 @@ 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, Optional<u64> wheel_gesture_id, u64 input_event_id);
+ // Routes a wheel event the UI did not send here, such as one a test makes, as the UI's wheel events are routed.
+ Compositing::WheelEventAnswer take_wheel_event_from_main_thread(Web::CompositorContextId, Web::MouseEvent const&, Compositing::AsyncScrollOperationTracking, Compositing::WheelEventScrolling);
+ 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, 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);
@@ -241,15 +243,16 @@ private:
enum class WheelStepOrigin : u8 {
UI,
Fling,
+ MainThread,
};
// A fling step is scrolled at the frame time the fling synthesized it for.
- ContextState::ContextUpdateResult scroll_for_wheel_step(Web::CompositorContextId, ContextState&, Web::MouseEvent const&, WheelStepOrigin, Optional<MonotonicTime> fling_step_time = {});
+ ContextState::ContextUpdateResult scroll_for_wheel_step(Web::CompositorContextId, ContextState&, Web::MouseEvent const&, WheelStepOrigin, bool is_first_wheel_event_with_delta, Compositing::AsyncScrollOperationTracking, MonotonicTime now);
struct WheelStepHandedToNestedContext {
// What is left for the context the step was handed from to present and report.
ContextState::ContextUpdateResult result;
bool nested_context_presents_frame { false };
};
- WheelStepHandedToNestedContext hand_wheel_step_to_nested_context(Web::CompositorContextId, ContextState&, Web::MouseEvent const&, ContextState::NestedContextWheelStep const&, MonotonicTime now);
+ WheelStepHandedToNestedContext hand_wheel_step_to_nested_context(Web::CompositorContextId, ContextState&, Web::MouseEvent const&, ContextState::NestedContextWheelStep const&, Compositing::AsyncScrollOperationTracking, MonotonicTime now);
struct NestedContextTakingWheelStep {
Web::CompositorContextId context_id;
// Null when the step cannot be handed to the context.
diff --git a/Services/Compositor/CompositorWebContentServer.ipc b/Services/Compositor/CompositorWebContentServer.ipc
index 9e1c2977187..e2ca6dab802 100644
--- a/Services/Compositor/CompositorWebContentServer.ipc
+++ b/Services/Compositor/CompositorWebContentServer.ipc
@@ -69,7 +69,8 @@ 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, Optional<u64> wheel_gesture_id, u64 input_event_id) => (Compositing::AsyncScrollEnqueueResult result)
+ take_wheel_event_from_main_thread(Web::CompositorContextId context_id, Web::MouseEvent event, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelEventScrolling scrolling) => (Compositing::WheelEventAnswer answer)
+ 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, 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 c29a1c63ef8..4e7031269a0 100644
--- a/Services/Compositor/ConnectionFromWebContent.cpp
+++ b/Services/Compositor/ConnectionFromWebContent.cpp
@@ -485,11 +485,29 @@ 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, Optional<u64> wheel_gesture_id, u64 input_event_id)
+static bool is_valid_wheel_event(Web::MouseEvent const& event)
+{
+ // Wheel deltas are scrolled by as floats.
+ auto is_valid_wheel_delta = [](double delta) {
+ return isfinite(delta) && fabs(delta) <= NumericLimits<float>::max();
+ };
+ return event.type == Web::MouseEvent::Type::MouseWheel
+ && is_valid_wheel_delta(event.wheel_delta_x)
+ && is_valid_wheel_delta(event.wheel_delta_y);
+}
+
+Messages::CompositorWebContentServer::TakeWheelEventFromMainThreadResponse ConnectionFromWebContent::take_wheel_event_from_main_thread(Web::CompositorContextId context_id, Web::MouseEvent event, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelEventScrolling scrolling)
+{
+ if (!context_is_owned_by_this_connection(context_id) || !is_valid_wheel_event(event))
+ return Compositing::WheelEventAnswer {};
+ return m_compositor_state->take_wheel_event_from_main_thread(context_id, event, operation_tracking, scrolling);
+}
+
+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, 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, wheel_gesture_id, 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, 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 2803e68fb4b..67a12dd8d37 100644
--- a/Services/Compositor/ConnectionFromWebContent.h
+++ b/Services/Compositor/ConnectionFromWebContent.h
@@ -77,7 +77,8 @@ 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, Optional<u64> wheel_gesture_id, u64 input_event_id) override;
+ virtual Messages::CompositorWebContentServer::TakeWheelEventFromMainThreadResponse take_wheel_event_from_main_thread(Web::CompositorContextId, Web::MouseEvent, Compositing::AsyncScrollOperationTracking, Compositing::WheelEventScrolling) 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, 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 2ca128be076..4db1c538fe3 100644
--- a/Services/Compositor/ContextState.cpp
+++ b/Services/Compositor/ContextState.cpp
@@ -967,10 +967,9 @@ ContextState::AsyncScrollResult ContextState::async_scroll_by(
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_of_ui_event,
+ Optional<u64> wheel_gesture_id_from_mark,
u64 input_event_id,
Optional<MonotonicTime> now_for_testing)
{
@@ -1001,21 +1000,14 @@ ContextState::AsyncScrollResult ContextState::async_scroll_by(
&& first_is_one_of(scroll_gesture_phase, Web::ScrollGesturePhase::Ongoing, Web::ScrollGesturePhase::Momentum);
bool only_blocking_wheel_event_listeners_hold_steps_back = m_wheel_gesture_routing.only_blocking_wheel_event_listeners_hold_steps_back();
- // 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);
- // 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;
+ // The presenting context noted the gesture of the step as the step arrived. A context nested in another one knows
+ // the gesture only from the mark of the event.
+ auto gesture_id = presents_to_client() ? m_wheel_gesture_routing.gesture_id() : wheel_gesture_id_from_mark;
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);
auto latched_scroll_node_index = latch.scroll_node_index;
- // The end of the gesture before this one may never have arrived. Whether a step of the UI starts another gesture
- // was decided when the UI sent it.
- if (!latched_scroll_node_index.has_value() && !step_came_from_ui)
- m_elastic_overscroll_controller.end_gesture(now);
if (!m_wheel_gesture_routing.admits_async_wheel()
&& !step_continues_touchpad_gesture_the_page_let_through(latched_scroll_node_index, wheel_delta_precision, scroll_gesture_phase)
@@ -1493,12 +1485,20 @@ Optional<Gfx::IntRect> ContextState::advance_smooth_scroll_animations(MonotonicT
return {};
}
-ContextState::ContextUpdateResult ContextState::handle_wheel_event(Web::MouseEvent const& event, Optional<MonotonicTime> now_for_testing)
+ContextState::ContextUpdateResult ContextState::handle_wheel_event(Web::MouseEvent const& event, bool is_first_wheel_event_with_delta, Optional<MonotonicTime> now_for_testing)
{
VERIFY(event.type == Web::MouseEvent::Type::MouseWheel);
+ if (!presents_to_client())
+ return ContextUpdateResult::declined(Web::InputRoutingDecision::ContextNotPresenting);
auto now = now_for_testing.value_or(MonotonicTime::now());
m_scroll_fling_controller.note_wheel_event(event, now);
- return scroll_for_wheel_event(event, now);
+ return scroll_for_wheel_event(event, is_first_wheel_event_with_delta, Compositing::AsyncScrollOperationTracking::No, now);
+}
+
+ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event_from_main_thread(Web::MouseEvent const& event, bool is_first_wheel_event_with_delta, Compositing::AsyncScrollOperationTracking operation_tracking, MonotonicTime now)
+{
+ VERIFY(event.type == Web::MouseEvent::Type::MouseWheel);
+ return scroll_for_wheel_event(event, is_first_wheel_event_with_delta, operation_tracking, now);
}
static Gfx::FloatPoint wheel_event_position(Web::MouseEvent const& event)
@@ -1524,24 +1524,31 @@ bool ContextState::step_continues_touchpad_gesture_the_page_let_through(Optional
return latched_scroll_node_index.has_value() && presents_to_client() && m_wheel_gesture_routing.page_let_latched_touchpad_gesture_through(wheel_delta_precision, scroll_gesture_phase);
}
-Web::WheelGestureMark ContextState::note_wheel_event_from_ui(Web::MouseEvent const& event, Optional<MonotonicTime> now_for_testing)
+ContextState::NotedWheelEvent ContextState::note_wheel_event(Web::MouseEvent const& event, MonotonicTime now)
{
VERIFY(event.type == Web::MouseEvent::Type::MouseWheel);
- auto now = now_for_testing.value_or(MonotonicTime::now());
- auto phase = event.scroll_gesture_phase;
-
// 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)
+ auto noted = m_wheel_gesture_routing.note_wheel_event(event, wheel_event_position(event), m_async_scroll_tree, now);
+ if (noted.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(),
+ return {
+ .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(),
+ },
+ .is_first_wheel_event_with_delta = noted.is_first_wheel_event_with_delta,
};
+}
+
+ContextState::NotedWheelEvent ContextState::note_wheel_event_from_ui(Web::MouseEvent const& event, Optional<MonotonicTime> now_for_testing)
+{
+ auto now = now_for_testing.value_or(MonotonicTime::now());
+ auto phase = event.scroll_gesture_phase;
+ auto noted = note_wheel_event(event, now);
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;
+ m_last_reported_scroll_momentum_step->wheel_gesture_mark = noted.wheel_gesture_mark;
} else {
m_last_reported_scroll_momentum_step.clear();
}
@@ -1550,7 +1557,12 @@ Web::WheelGestureMark ContextState::note_wheel_event_from_ui(Web::MouseEvent con
// 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 wheel_gesture_mark;
+ return noted;
+}
+
+ContextState::NotedWheelEvent ContextState::note_wheel_event_from_main_thread(Web::MouseEvent const& event, MonotonicTime now)
+{
+ return note_wheel_event(event, now);
}
bool ContextState::start_scroll_fling_if_flicked(Web::MouseEvent const& gesture_end_event, Optional<MonotonicTime> now_for_testing)
@@ -1622,7 +1634,9 @@ Optional<Web::MouseEvent> ContextState::end_scroll_fling()
ContextState::ContextUpdateResult ContextState::scroll_for_fling_step(Web::MouseEvent const& event, MonotonicTime now)
{
- return scroll_for_wheel_event(event, now);
+ if (!presents_to_client())
+ return ContextUpdateResult::declined(Web::InputRoutingDecision::ContextNotPresenting);
+ return scroll_for_wheel_event(event, false, Compositing::AsyncScrollOperationTracking::No, now);
}
void ContextState::end_scroll_fling_on_next_step()
@@ -1630,11 +1644,8 @@ void ContextState::end_scroll_fling_on_next_step()
m_scroll_fling_controller.end_on_next_step();
}
-ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event(Web::MouseEvent const& event, MonotonicTime now)
+ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event(Web::MouseEvent const& event, bool is_first_wheel_event_with_delta, Compositing::AsyncScrollOperationTracking operation_tracking, MonotonicTime now)
{
- if (!presents_to_client())
- return ContextUpdateResult::declined(Web::InputRoutingDecision::ContextNotPresenting);
-
auto position = wheel_event_position(event);
// The end of a gesture lets go of the scroller it stretched even if the context has stopped taking wheel events.
if (event.scroll_gesture_phase == Web::ScrollGesturePhase::Ended)
@@ -1648,22 +1659,33 @@ ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event(Web::Mous
// went elsewhere is not handed to a nested context that comes under the pointer later.
auto nested_context_regions = Compositing::NestedContextRegions::LeaveToMainThread;
bool may_hand_step_to_nested_context = !latch.scroll_node_index.has_value()
- && m_wheel_gesture_routing.is_first_wheel_event_with_delta(event.id)
+ && is_first_wheel_event_with_delta
&& may_hand_first_wheel_steps_to_nested_contexts();
if (may_hand_step_to_nested_context) {
nested_context_regions = Compositing::NestedContextRegions::HandToNestedContext;
if (auto hit = nested_context_for_wheel_at(position); hit.has_value())
return { .nested_context_wheel_step = NestedContextWheelStep { .context_id = hit->child_context_id, .hit = hit } };
}
- return scroll_for_wheel_event_in_this_context(event, latch.scroll_node_index, nested_context_regions, now);
+ return scroll_for_wheel_event_in_this_context(event, latch.scroll_node_index, nested_context_regions, operation_tracking, now);
}
-ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event_passed_on_by_nested_context(Web::MouseEvent const& event, MonotonicTime now)
+ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event_passed_on_by_nested_context(Web::MouseEvent const& event, Compositing::AsyncScrollOperationTracking operation_tracking, MonotonicTime now)
{
- return scroll_for_wheel_event_in_this_context(event, {}, Compositing::NestedContextRegions::Ignore, now);
+ return scroll_for_wheel_event_in_this_context(event, {}, Compositing::NestedContextRegions::Ignore, operation_tracking, now);
}
-ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event_in_this_context(Web::MouseEvent const& event, Optional<Compositing::SpatialNodeIndex> latched_scroll_node_index, Compositing::NestedContextRegions nested_context_regions, MonotonicTime now)
+Optional<ContextState::TrackedScrollOperation> ContextState::tracked_scroll_operation(Compositing::AsyncScrollOperationTracking operation_tracking, Optional<Compositing::AsyncScrollOperationID> operation_id) const
+{
+ if (operation_tracking == Compositing::AsyncScrollOperationTracking::No || !operation_id.has_value())
+ return {};
+ // An operation that ended as the step was taken, such as an instant scroll, leaves nothing to follow. The main
+ // thread adopts the offsets of the step as it handles the event.
+ if (m_async_scroll_update_outbox.has_completed_operation(*operation_id))
+ return {};
+ return TrackedScrollOperation { .context_id = m_context_id, .operation_id = *operation_id };
+}
+
+ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event_in_this_context(Web::MouseEvent const& event, Optional<Compositing::SpatialNodeIndex> latched_scroll_node_index, Compositing::NestedContextRegions nested_context_regions, Compositing::AsyncScrollOperationTracking operation_tracking, MonotonicTime now)
{
auto position = wheel_event_position(event);
auto delta = wheel_event_delta_in_device_pixels(event);
@@ -1678,13 +1700,15 @@ ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event_in_this_c
m_scroll_snap_controller.note_gesture_phase(event.scroll_gesture_phase);
if (event.scroll_gesture_phase == Web::ScrollGesturePhase::Ended && delta.is_zero()) {
- if (!snap_at_gesture_end(now).has_value())
+ auto operation_id = snap_at_gesture_end(now);
+ if (!operation_id.has_value())
return ContextUpdateResult::declined(Web::InputRoutingDecision::GestureEndWithNothingToSnap);
return {
.accepted = true,
.frame_to_present = PendingFrame::repainting_changes(m_async_scrolling_viewport_rect),
.should_request_rendering_update = true,
.routing_decision = Web::InputRoutingDecision::SnappedAtGestureEnd,
+ .tracked_scroll_operation = tracked_scroll_operation(operation_tracking, operation_id),
};
}
@@ -1729,13 +1753,14 @@ ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event_in_this_c
}
auto scroll_chaining = is_first_step_of_gesture ? Compositing::ScrollChaining::ToScrollableAncestors : Compositing::ScrollChaining::None;
- auto outcome = perform_wheel_scroll_of_node(*latched_scroll_node_index, delta, event.wheel_delta_precision, event.scroll_gesture_phase, Compositing::AsyncScrollOperationTracking::No, m_async_scrolling_viewport_rect, now, scroll_chaining, VisualViewportPanning::BeforeScrolling);
+ auto outcome = perform_wheel_scroll_of_node(*latched_scroll_node_index, delta, event.wheel_delta_precision, event.scroll_gesture_phase, operation_tracking, m_async_scrolling_viewport_rect, now, scroll_chaining, VisualViewportPanning::BeforeScrolling);
return {
.accepted = true,
.frame_to_present = outcome.viewport_rect_to_present.map([](auto const& rect) { return PendingFrame::repainting_changes(rect); }),
.should_request_rendering_update = outcome.viewport_rect_to_present.has_value() && !outcome.only_elastic_overscroll_changed,
.routing_decision = routing_decision,
.routed_scroller = m_wheel_gesture_routing.latched_scroller(),
+ .tracked_scroll_operation = tracked_scroll_operation(operation_tracking, outcome.operation_id),
};
}
@@ -1758,7 +1783,7 @@ void ContextState::latch_wheel_gesture_to_nested_context(Web::CompositorContextI
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, Optional<u64> gesture_id)
+ContextState::WheelStepFromContainingContext ContextState::WheelStepFromContainingContext::for_wheel_event(Web::MouseEvent const& event, Optional<u64> gesture_id, Compositing::AsyncScrollOperationTracking operation_tracking)
{
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)
@@ -1770,6 +1795,7 @@ ContextState::WheelStepFromContainingContext ContextState::WheelStepFromContaini
.scroll_gesture_phase = event.scroll_gesture_phase,
.modifiers = event.modifiers,
.gesture_id = gesture_id,
+ .operation_tracking = operation_tracking,
};
}
@@ -1843,7 +1869,8 @@ ContextState::ContextUpdateResult ContextState::take_latched_wheel_step_from_con
if (step.scroll_gesture_phase == Web::ScrollGesturePhase::Ended && step.delta_in_css_pixels.is_zero()) {
m_scroll_snap_controller.note_gesture_phase(step.scroll_gesture_phase);
- if (!snap_at_gesture_end(now).has_value())
+ auto operation_id = snap_at_gesture_end(now);
+ if (!operation_id.has_value())
return ContextUpdateResult::declined(Web::InputRoutingDecision::GestureEndWithNothingToSnap);
return {
.accepted = true,
@@ -1851,6 +1878,7 @@ ContextState::ContextUpdateResult ContextState::take_latched_wheel_step_from_con
.should_request_rendering_update = true,
.routing_decision = Web::InputRoutingDecision::SnappedAtGestureEnd,
.routed_scroller = m_wheel_gesture_routing.latched_scroller(),
+ .tracked_scroll_operation = tracked_scroll_operation(step.operation_tracking, operation_id),
};
}
return take_wheel_step_from_containing_context(*latch.scroll_node_index, Web::InputRoutingDecision::ContinuedLatch, step, Compositing::ScrollChaining::None, now);
@@ -1860,13 +1888,14 @@ ContextState::ContextUpdateResult ContextState::take_wheel_step_from_containing_
{
m_scroll_snap_controller.note_gesture_phase(step.scroll_gesture_phase);
auto delta = step.delta_in_css_pixels.scaled(static_cast<float>(m_async_scroll_tree.device_pixels_per_css_pixel()));
- auto outcome = perform_wheel_scroll_of_node(scroll_node_index, delta, step.wheel_delta_precision, step.scroll_gesture_phase, Compositing::AsyncScrollOperationTracking::No, m_async_scrolling_viewport_rect, now, scroll_chaining, VisualViewportPanning::No);
+ auto outcome = perform_wheel_scroll_of_node(scroll_node_index, delta, step.wheel_delta_precision, step.scroll_gesture_phase, step.operation_tracking, m_async_scrolling_viewport_rect, now, scroll_chaining, VisualViewportPanning::No);
return {
.accepted = true,
.frame_to_present = outcome.viewport_rect_to_present.map([](auto const& rect) { return PendingFrame::repainting_changes(rect); }),
.should_request_rendering_update = outcome.viewport_rect_to_present.has_value() && !outcome.only_elastic_overscroll_changed,
.routing_decision = decision,
.routed_scroller = m_wheel_gesture_routing.latched_scroller(),
+ .tracked_scroll_operation = tracked_scroll_operation(step.operation_tracking, outcome.operation_id),
};
}
diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.h
index 18582441c6b..50da31f6dd1 100644
--- a/Services/Compositor/ContextState.h
+++ b/Services/Compositor/ContextState.h
@@ -78,6 +78,12 @@ public:
Optional<Compositing::NestedContextHit> hit {};
};
+ // An operation that a wheel step asked to follow, whose end the scroll updates of the context report.
+ struct TrackedScrollOperation {
+ Web::CompositorContextId context_id;
+ Compositing::AsyncScrollOperationID operation_id;
+ };
+
struct ContextUpdateResult {
bool accepted { false };
Optional<PendingFrame> frame_to_present {};
@@ -93,6 +99,7 @@ public:
// Set, with at most the frame of the scrollbar the pointer left here, for a mouse event that the nested context
// under the pointer is to take.
Optional<Compositing::NestedContextHit> nested_context_mouse_hit {};
+ Optional<TrackedScrollOperation> tracked_scroll_operation {};
static ContextUpdateResult declined(Web::InputRoutingDecision decision) { return { .routing_decision = decision }; }
};
@@ -107,8 +114,9 @@ public:
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 {};
+ Compositing::AsyncScrollOperationTracking operation_tracking { Compositing::AsyncScrollOperationTracking::No };
- static WheelStepFromContainingContext for_wheel_event(Web::MouseEvent const&, Optional<u64> gesture_id);
+ static WheelStepFromContainingContext for_wheel_event(Web::MouseEvent const&, Optional<u64> gesture_id, Compositing::AsyncScrollOperationTracking);
};
// Where the first step of a gesture that the containing context hands in goes in this context. A nested context
@@ -182,18 +190,29 @@ public:
Optional<Web::CompositorContextId> context_under_pointer;
};
PointerInNestedContexts& pointer_in_nested_contexts() { return m_pointer_in_nested_contexts; }
- // The UI's wheel deltas are in CSS pixels; this scales them for the scroll tree, which works in device pixels.
- ContextUpdateResult handle_wheel_event(Web::MouseEvent const&, Optional<MonotonicTime> now_for_testing = {});
+ // What this context noted of a wheel event as the event arrived.
+ struct NotedWheelEvent {
+ Web::WheelGestureMark wheel_gesture_mark;
+ // Only the first step of a gesture that moves anything goes to a nested context.
+ bool is_first_wheel_event_with_delta { false };
+ };
// 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 = {});
+ NotedWheelEvent note_wheel_event_from_ui(Web::MouseEvent const&, Optional<MonotonicTime> now_for_testing = {});
+ // Takes note of a wheel event that the main thread has and the UI did not send here, as the UI's events are noted.
+ // Such an event adds nothing to the velocity of a flick or of a stretch release.
+ NotedWheelEvent note_wheel_event_from_main_thread(Web::MouseEvent const&, MonotonicTime now);
+ // The UI's wheel deltas are in CSS pixels; this scales them for the scroll tree, which works in device pixels.
+ ContextUpdateResult handle_wheel_event(Web::MouseEvent const&, bool is_first_wheel_event_with_delta, Optional<MonotonicTime> now_for_testing = {});
+ // Routes the event like one from the UI, also in a context that is nested in another one.
+ ContextUpdateResult scroll_for_wheel_event_from_main_thread(Web::MouseEvent const&, bool is_first_wheel_event_with_delta, Compositing::AsyncScrollOperationTracking, MonotonicTime now);
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(); }
bool may_hand_first_wheel_steps_to_nested_contexts() const;
Optional<Compositing::NestedContextHit> nested_context_for_wheel_at(Gfx::FloatPoint position);
- ContextUpdateResult scroll_for_wheel_event_passed_on_by_nested_context(Web::MouseEvent const&, MonotonicTime now);
+ ContextUpdateResult scroll_for_wheel_event_passed_on_by_nested_context(Web::MouseEvent const&, Compositing::AsyncScrollOperationTracking, MonotonicTime now);
void latch_wheel_gesture_to_nested_context(Web::CompositorContextId, Optional<Web::AsyncScrollNodeStableID> scroller, Web::MouseEvent const&);
void forget_wheel_gesture_latch() { m_wheel_gesture_routing.clear_latch(); }
void clear_per_test_input_state();
@@ -210,11 +229,10 @@ public:
Gfx::IntRect viewport_rect,
Web::WheelDeltaPrecision,
Web::ScrollGesturePhase,
- 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 gesture the compositor named in the mark of the wheel event.
+ Optional<u64> wheel_gesture_id_from_mark,
// 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 = {});
@@ -370,8 +388,10 @@ private:
bool wheel_step_can_stretch_elastically(Web::WheelDeltaPrecision, Web::ScrollGesturePhase) const;
bool pull_elastic_overscroll_by(Compositing::AsyncScrollNode const&, Gfx::FloatPoint step_delta, Gfx::FloatPoint delta_the_scroller_did_not_scroll_by);
Optional<Compositing::ScrollStateSnapshot> scroll_state_snapshot_stretched_by_elastic_overscrolls() const;
- ContextUpdateResult scroll_for_wheel_event(Web::MouseEvent const&, MonotonicTime now);
- ContextUpdateResult scroll_for_wheel_event_in_this_context(Web::MouseEvent const&, Optional<Compositing::SpatialNodeIndex> latched_scroll_node_index, Compositing::NestedContextRegions, MonotonicTime now);
+ NotedWheelEvent note_wheel_event(Web::MouseEvent const&, MonotonicTime now);
+ ContextUpdateResult scroll_for_wheel_event(Web::MouseEvent const&, bool is_first_wheel_event_with_delta, Compositing::AsyncScrollOperationTracking, MonotonicTime now);
+ ContextUpdateResult scroll_for_wheel_event_in_this_context(Web::MouseEvent const&, Optional<Compositing::SpatialNodeIndex> latched_scroll_node_index, Compositing::NestedContextRegions, Compositing::AsyncScrollOperationTracking, MonotonicTime now);
+ Optional<TrackedScrollOperation> tracked_scroll_operation(Compositing::AsyncScrollOperationTracking, Optional<Compositing::AsyncScrollOperationID>) const;
Gfx::FloatPoint wheel_event_delta_in_device_pixels(Web::MouseEvent const&) const;
bool step_continues_touchpad_gesture_the_page_let_through(Optional<Compositing::SpatialNodeIndex> const& latched_scroll_node_index, Web::WheelDeltaPrecision, Web::ScrollGesturePhase) const;
Optional<Gfx::FloatPoint> in_flight_wheel_destination(Web::AsyncScrollNodeStableID) const;
diff --git a/Services/Compositor/WheelGestureRouting.cpp b/Services/Compositor/WheelGestureRouting.cpp
index 375b33a3a92..72497b73444 100644
--- a/Services/Compositor/WheelGestureRouting.cpp
+++ b/Services/Compositor/WheelGestureRouting.cpp
@@ -48,38 +48,33 @@ bool WheelGestureRouting::only_blocking_wheel_event_listeners_hold_steps_back()
return first_is_one_of(m_admission, Compositing::WheelRoutingAdmission::BlockingWheelEventListeners, Compositing::WheelRoutingAdmission::StaleWheelEventListeners);
}
-bool WheelGestureRouting::note_wheel_event_from_ui(Web::MouseEvent const& event, Gfx::FloatPoint position, Compositing::AsyncScrollTree const& async_scroll_tree, MonotonicTime now)
+WheelGestureRouting::NotedWheelEvent WheelGestureRouting::note_wheel_event(Web::MouseEvent const& event, Gfx::FloatPoint position, Compositing::AsyncScrollTree const& async_scroll_tree, MonotonicTime now)
{
- return note_wheel_event(event.id, event.scroll_gesture_phase, event.modifiers, { event.wheel_delta_x, event.wheel_delta_y }, position, async_scroll_tree, now);
-}
-
-bool WheelGestureRouting::note_wheel_event(u64 input_event_id, Web::ScrollGesturePhase phase, u32 modifiers, Gfx::FloatPoint wheel_delta, Gfx::FloatPoint position, Compositing::AsyncScrollTree const& async_scroll_tree, MonotonicTime now)
-{
- if (input_event_id != 0) {
+ auto phase = event.scroll_gesture_phase;
+ if (event.id != 0) {
if (phase == Web::ScrollGesturePhase::Ongoing)
- m_newest_wheel_event_ids_from_ui.ongoing = input_event_id;
+ m_newest_wheel_event_ids_from_ui.ongoing = event.id;
else if (phase == Web::ScrollGesturePhase::Momentum)
- m_newest_wheel_event_ids_from_ui.momentum = input_event_id;
+ m_newest_wheel_event_ids_from_ui.momentum = event.id;
else if (phase == Web::ScrollGesturePhase::Ended)
- m_newest_wheel_event_ids_from_ui.ended = input_event_id;
+ m_newest_wheel_event_ids_from_ui.ended = event.id;
}
- 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);
+ bool starts_gesture = !m_gesture.has_value() || !m_gesture->identity.is_continued_by(position, phase, event.modifiers, now, position_slop_in_device_pixels(async_scroll_tree), m_touchpad_gesture_end);
if (starts_gesture) {
m_gesture = Gesture {
.id = allocate_wheel_gesture_id(),
- .identity = Compositing::WheelGestureIdentity::started_by(position, phase, modifiers, now),
+ .identity = Compositing::WheelGestureIdentity::started_by(position, phase, event.modifiers, now),
};
m_gesture_had_wheel_event_with_delta = false;
m_latch.clear();
} else {
m_gesture->identity.advance_to(phase, now);
}
- if (!m_gesture_had_wheel_event_with_delta && !wheel_delta.is_zero()) {
+ bool is_first_wheel_event_with_delta = !m_gesture_had_wheel_event_with_delta && (event.wheel_delta_x != 0 || event.wheel_delta_y != 0);
+ if (is_first_wheel_event_with_delta)
m_gesture_had_wheel_event_with_delta = true;
- m_id_of_first_wheel_event_with_delta = input_event_id;
- }
- return starts_gesture;
+ return { .starts_gesture = starts_gesture, .is_first_wheel_event_with_delta = is_first_wheel_event_with_delta };
}
Optional<u64> WheelGestureRouting::gesture_id() const
@@ -93,7 +88,6 @@ void WheelGestureRouting::forget_gesture()
{
m_gesture.clear();
m_gesture_had_wheel_event_with_delta = false;
- m_id_of_first_wheel_event_with_delta = 0;
m_latch.clear();
}
diff --git a/Services/Compositor/WheelGestureRouting.h b/Services/Compositor/WheelGestureRouting.h
index f2d123e4b1c..7ecc07c63f2 100644
--- a/Services/Compositor/WheelGestureRouting.h
+++ b/Services/Compositor/WheelGestureRouting.h
@@ -32,16 +32,19 @@ public:
bool admits_async_pinch() const;
bool only_blocking_wheel_event_listeners_hold_steps_back() const;
- // Returns whether the event starts another gesture than the one before it, which lets go of the latch. Every wheel
- // 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);
+ struct NotedWheelEvent {
+ // The event starts another gesture than the one before it, which lets go of the latch.
+ bool starts_gesture { false };
+ // The event is the first step of its gesture that moves anything. A touchpad gesture can start with a step that
+ // has no delta.
+ bool is_first_wheel_event_with_delta { false };
+ };
+ // Every wheel event is noted as this context first sees it: from the UI, or from the main thread for one the UI did
+ // not send.
+ NotedWheelEvent note_wheel_event(Web::MouseEvent const&, 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; }
// Whether the UI sent a later wheel event that this step cannot come before in one gesture, which makes it a step
// of a gesture this context has already ended or moved past.
bool step_was_overtaken_by_ui(Web::ScrollGesturePhase, u64 input_event_id) const;
@@ -114,7 +117,6 @@ private:
// thread makes. It says which gesture a step is in, whether this context or the main thread scrolls the step.
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 };
Optional<Latch> m_latch;
Compositing::TouchpadGestureEnd m_touchpad_gesture_end { Compositing::TouchpadGestureEnd::AfterIdleDelay };
diff --git a/Tests/Compositor/TestContextState.cpp b/Tests/Compositor/TestContextState.cpp
index c0f163bdd08..56cf1cbec72 100644
--- a/Tests/Compositor/TestContextState.cpp
+++ b/Tests/Compositor/TestContextState.cpp
@@ -135,11 +135,11 @@ TEST_CASE(wheel_pans_the_zoomed_visual_viewport_of_a_page_without_scroll_nodes)
wheel_event.wheel_delta_precision = Web::WheelDeltaPrecision::Precise;
// Before the page is zoomed in, there is nothing for the wheel to pan.
- EXPECT(!context.handle_wheel_event(wheel_event).accepted);
+ EXPECT(!context.handle_wheel_event(wheel_event, false).accepted);
EXPECT(context.handle_pinch_event(pinch_event(1.0)).accepted);
(void)context.take_pending_async_scroll_updates();
- auto result = context.handle_wheel_event(wheel_event);
+ auto result = context.handle_wheel_event(wheel_event, false);
EXPECT(result.accepted);
EXPECT(result.frame_to_present.has_value());
diff --git a/Tests/LibWeb/Text/input/async-scrolling/wheel-latch-dom-target-during-compositor-scroll.html b/Tests/LibWeb/Text/input/async-scrolling/wheel-latch-dom-target-during-compositor-scroll.html
index 653d8600ba7..9c3b3f44b70 100644
--- a/Tests/LibWeb/Text/input/async-scrolling/wheel-latch-dom-target-during-compositor-scroll.html
+++ b/Tests/LibWeb/Text/input/async-scrolling/wheel-latch-dom-target-during-compositor-scroll.html
@@ -12,10 +12,10 @@
}
#a {
top: 0;
- height: 100px;
+ height: 200px;
}
#b {
- top: 100px;
+ top: 200px;
height: 300px;
}
</style>
@@ -29,8 +29,8 @@
await animationFrame();
await animationFrame();
- // The compositor scrolls the page, and #b slides under the cursor after the first step; the gesture's wheel
- // events keep going to #a, its end included.
+ // The compositor scrolls the page by each step before the page sees it, and #b slides under the cursor with the
+ // second step; the gesture's wheel events keep going to #a, its end included.
await internals.wheel(50, 50, 0, 100, true, "ongoing");
await internals.wheel(50, 50, 0, 100, true, "ongoing");
await internals.wheel(50, 50, 0, 0, true, "ended");