Truly independent web browser
Everywhere: Keep a touchpad gesture going while its fingers rest
Zaggy10240ed7cf1996bd
diff --git a/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.cpp b/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.cppindex efa21941664..f735837c56a 100644--- a/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.cpp+++ b/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.cpp@@ -30,9 +30,15 @@ WheelGestureIdentity WheelGestureIdentity::started_by(Gfx::FloatPoint position,return gesture;}-bool WheelGestureIdentity::is_continued_by(Gfx::FloatPoint position, Web::ScrollGesturePhase phase, u32 modifiers, MonotonicTime now, float position_slop) const+bool WheelGestureIdentity::is_held_by_fingers() const{- if (now - m_last_event_time > user_scroll_settle_delay)+ return m_kind == Kind::Phased && !m_ended_at.has_value() && !m_momentum_has_started;+}++bool WheelGestureIdentity::is_continued_by(Gfx::FloatPoint position, Web::ScrollGesturePhase phase, u32 modifiers, MonotonicTime now, float position_slop, TouchpadGestureEnd touchpad_gesture_end) const+{+ bool lasts_while_fingers_rest = touchpad_gesture_end == TouchpadGestureEnd::WhenFingersLift && is_held_by_fingers();+ if (!lasts_while_fingers_rest && now - m_last_event_time > user_scroll_settle_delay)return false;if (kind_for(phase) != m_kind)return false;diff --git a/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.h b/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.hindex 1f117b45563..5bc06fefd76 100644--- a/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.h+++ b/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.h@@ -18,6 +18,13 @@ namespace Compositing {inline constexpr AK::Duration wheel_gesture_momentum_grace_after_end = AK::Duration::from_milliseconds(100);inline constexpr float wheel_gesture_position_slop_in_css_pixels = 10;+// When a touchpad gesture ends: once its steps stop arriving for a while, or once the platform reports that the fingers+// lifted, however long they rest on the touchpad before that.+enum class TouchpadGestureEnd : u8 {+ AfterIdleDelay,+ 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.@@ -26,7 +33,9 @@ public:static WheelGestureIdentity started_by(Gfx::FloatPoint position, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now);// Positions and the slop are in whatever unit the caller routes in.- bool is_continued_by(Gfx::FloatPoint position, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now, float position_slop) const;+ bool is_continued_by(Gfx::FloatPoint position, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now, float position_slop, TouchpadGestureEnd) const;+ // 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);diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.cpp b/Libraries/LibWeb/Compositor/CompositorConnection.cppindex ac72d744fdb..2fd4faf8a1a 100644--- a/Libraries/LibWeb/Compositor/CompositorConnection.cpp+++ b/Libraries/LibWeb/Compositor/CompositorConnection.cpp@@ -542,6 +542,14 @@ void CompositorConnection::begin_input_trace_for_testing(Web::CompositorContextIdid_lose_compositor();}+void CompositorConnection::clear_per_test_input_state_for_testing(Web::CompositorContextId context_id)+{+ if (!can_send_message_to_compositor())+ return;+ if (!send_sync_but_allow_failure<Messages::CompositorWebContentServer::ClearPerTestInputStateForTesting>(context_id))+ did_lose_compositor();+}+Vector<Web::InputTraceRecord> CompositorConnection::take_input_trace_for_testing(Web::CompositorContextId context_id){if (!can_send_message_to_compositor())diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.h b/Libraries/LibWeb/Compositor/CompositorConnection.hindex 75491a15832..c500fb56a59 100644--- a/Libraries/LibWeb/Compositor/CompositorConnection.h+++ b/Libraries/LibWeb/Compositor/CompositorConnection.h@@ -71,6 +71,7 @@ public:void synchronize_for_testing();Optional<Compositing::FirstWheelStepRouteForTesting> route_first_wheel_step_for_testing(Web::CompositorContextId, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels);void begin_input_trace_for_testing(Web::CompositorContextId);+ void clear_per_test_input_state_for_testing(Web::CompositorContextId);Vector<Web::InputTraceRecord> take_input_trace_for_testing(Web::CompositorContextId);Compositing::PendingAsyncScrollUpdates take_pending_async_scroll_updates(Web::CompositorContextId, Compositing::AsyncScrollUpdateFreshness);void viewport_size_updated(Web::CompositorContextId, Gfx::IntSize, double device_pixel_ratio, Compositing::WindowResizingInProgress);diff --git a/Libraries/LibWeb/Compositor/CompositorHost.cpp b/Libraries/LibWeb/Compositor/CompositorHost.cppindex f4ae83285cf..2a8309d6a69 100644--- a/Libraries/LibWeb/Compositor/CompositorHost.cpp+++ b/Libraries/LibWeb/Compositor/CompositorHost.cpp@@ -87,6 +87,11 @@ void CompositorContextHandle::begin_input_trace_for_testing()m_host.begin_input_trace_for_testing(m_context_id);}+void CompositorContextHandle::clear_per_test_input_state_for_testing()+{+ m_host.clear_per_test_input_state_for_testing(m_context_id);+}+Vector<Web::InputTraceRecord> CompositorContextHandle::take_input_trace_for_testing(){return m_host.take_input_trace_for_testing(m_context_id);@@ -491,6 +496,12 @@ void CompositorHost::begin_input_trace_for_testing(Web::CompositorContextId contconnection->begin_input_trace_for_testing(context_id);}+void CompositorHost::clear_per_test_input_state_for_testing(Web::CompositorContextId context_id)+{+ if (auto* connection = compositor_connection())+ connection->clear_per_test_input_state_for_testing(context_id);+}+Vector<Web::InputTraceRecord> CompositorHost::take_input_trace_for_testing(Web::CompositorContextId context_id){if (auto* connection = compositor_connection())diff --git a/Libraries/LibWeb/Compositor/CompositorHost.h b/Libraries/LibWeb/Compositor/CompositorHost.hindex 755426d2293..3afb17ce110 100644--- a/Libraries/LibWeb/Compositor/CompositorHost.h+++ b/Libraries/LibWeb/Compositor/CompositorHost.h@@ -65,6 +65,7 @@ public:void synchronize_for_testing();Optional<Compositing::FirstWheelStepRouteForTesting> route_first_wheel_step_for_testing(Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels);void begin_input_trace_for_testing();+ void clear_per_test_input_state_for_testing();Vector<Web::InputTraceRecord> take_input_trace_for_testing();Compositing::PendingAsyncScrollUpdates take_pending_async_scroll_updates(Compositing::AsyncScrollUpdateFreshness);void viewport_size_updated(Gfx::IntSize, double device_pixel_ratio, Compositing::WindowResizingInProgress);@@ -126,6 +127,7 @@ public:void synchronize_for_testing();Optional<Compositing::FirstWheelStepRouteForTesting> route_first_wheel_step_for_testing(Web::CompositorContextId, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels);void begin_input_trace_for_testing(Web::CompositorContextId);+ void clear_per_test_input_state_for_testing(Web::CompositorContextId);Vector<Web::InputTraceRecord> take_input_trace_for_testing(Web::CompositorContextId);Compositing::PendingAsyncScrollUpdates take_pending_async_scroll_updates(Web::CompositorContextId, Compositing::AsyncScrollUpdateFreshness);void viewport_size_updated(Web::CompositorContextId, Gfx::IntSize, double device_pixel_ratio, Compositing::WindowResizingInProgress);diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex 33b1a0705d7..54dca5d182b 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -5297,13 +5297,18 @@ void LocalNavigable::note_user_scroll_gesture_phase(Web::ScrollGesturePhase phas}}-void LocalNavigable::did_handle_wheel_event()+void LocalNavigable::did_handle_wheel_event(bool gesture_lasts_until_fingers_lift){if (!m_wheel_user_scroll_gesture_hold)return;// The compositor latched the gesture to the box it scrolls before it handed the event on.if (m_compositor_wheel_latched_scroller.has_value())m_wheel_user_scroll_gesture_hold->hold(m_compositor_wheel_latched_scroller.value());+ if (gesture_lasts_until_fingers_lift) {+ if (m_wheel_user_scroll_gesture_hold_expiry_timer)+ m_wheel_user_scroll_gesture_hold_expiry_timer->stop();+ return;+ }if (!m_wheel_user_scroll_gesture_hold_expiry_timer) {m_wheel_user_scroll_gesture_hold_expiry_timer = Core::Timer::create_single_shot(Compositing::user_scroll_settle_delay, [this] {m_wheel_user_scroll_gesture_hold = nullptr;diff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.hindex 7a202de7452..44cabe7dfc7 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.h+++ b/Libraries/LibWeb/HTML/LocalNavigable.h@@ -424,7 +424,8 @@ public:// Returns false if the scroller is not in this navigable's active document.bool set_overlay_scrollbar_hidden(Web::AsyncScrollNodeStableID, bool vertical, bool hidden);void note_user_scroll_gesture_phase(Web::ScrollGesturePhase);- void did_handle_wheel_event();+ // A gesture that lasts until its fingers lift is held until their lift arrives, not until its events pause.+ void did_handle_wheel_event(bool gesture_lasts_until_fingers_lift);void note_wheel_user_scroll_gesture_scrolls(Web::AsyncScrollNodeStableID);void extend_user_scroll_gesture_of(Web::AsyncScrollNodeStableID);void extend_wheel_user_scroll_gesture(Optional<Web::AsyncScrollNodeStableID> box_latched_on_this_thread);diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cppindex 849dee7dca7..6d210206ebc 100644--- a/Libraries/LibWeb/Internals/Internals.cpp+++ b/Libraries/LibWeb/Internals/Internals.cpp@@ -634,8 +634,8 @@ void Internals::send_text(HTML::HTMLElement& target, Utf16String const& text, We// The compositor context that the UI routes this page's input through.static Compositor::CompositorContextHandle* compositor_context_routing_input_for(HTML::Window& window){- auto local_root = window.navigable()->local_root();- if (!local_root->has_compositor_context())+ auto local_root = local_root_of(window);+ if (!local_root || !local_root->has_compositor_context())return nullptr;return &local_root->compositor_context();}@@ -2062,6 +2062,8 @@ void Internals::perform_per_test_cleanup()local_root->event_handler().clear_per_test_input_state({});WebDriver::reset_input_state(*local_root->top_level_traversable());}+ if (auto* compositor_context = compositor_context_routing_input_for(window()))+ compositor_context->clear_per_test_input_state_for_testing();if (page().input_trace().is_recording())(void)take_input_trace_records(window());diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cppindex 39850ab6d5b..209f38f78af 100644--- a/Libraries/LibWeb/Page/EventHandler.cpp+++ b/Libraries/LibWeb/Page/EventHandler.cpp@@ -968,17 +968,18 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positiif (wheel_gesture_mark.has_value())continues_latched_gesture = wheel_gesture_mark->continues_gesture;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);+ 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);}if (continues_latched_gesture)m_wheel_scroll_latch->gesture.advance_to(scroll_gesture_phase, now);elsem_wheel_scroll_latch.clear();- ScopeGuard measure_next_pause_from_end_of_handling = [this] {+ 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();+ m_navigable->did_handle_wheel_event(gesture_lasts_until_fingers_lift);};// A wheel step is routed against the offsets the compositor holds now, which a step it just took maydiff --git a/Libraries/LibWebCommon/Page/InputEvent.h b/Libraries/LibWebCommon/Page/InputEvent.hindex 4a3895bacb9..3c3da5202cc 100644--- a/Libraries/LibWebCommon/Page/InputEvent.h+++ b/Libraries/LibWebCommon/Page/InputEvent.h@@ -147,6 +147,9 @@ private:struct WheelGestureMark {// Whether the event continues the gesture before it, rather than starting one.bool continues_gesture { false };+ // 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 };bool operator==(WheelGestureMark const&) const = default;};diff --git a/Libraries/LibWebCommon/Page/InputEvent.ipc b/Libraries/LibWebCommon/Page/InputEvent.ipcindex df053c2637f..535922789d4 100644--- a/Libraries/LibWebCommon/Page/InputEvent.ipc+++ b/Libraries/LibWebCommon/Page/InputEvent.ipc@@ -38,6 +38,7 @@ enum Web::ScrollGesturePhase : u8 {[ExistingCpp]struct Web::WheelGestureMark {bool continues_gesture;+ bool lasts_until_fingers_lift;}[ExistingCpp]diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cppindex 40c98680481..6acec986ed0 100644--- a/Services/Compositor/CompositorState.cpp+++ b/Services/Compositor/CompositorState.cpp@@ -853,7 +853,7 @@ void CompositorState::dispatch_scroll_fling_step(Web::CompositorContextId contexevent->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 };+ event->wheel_gesture_mark = Web::WheelGestureMark { .continues_gesture = true, .lasts_until_fingers_lift = false };context.dispatch_mouse_event_to_web_content(*event);}@@ -1486,13 +1486,20 @@ BackingStoreManager::GpuSharing CompositorState::gpu_sharing_for_context([[maybereturn BackingStoreManager::GpuSharing::Allowed;}-// A context scrolls elastically, and takes presses on scrollbar tracks, as the presentation of its root context does.+// A context scrolls elastically, takes presses on scrollbar tracks, and ends touchpad gestures as the presentation of+// its root context does. A platform that reports the momentum of a flick reports when the fingers lift for it.void CompositorState::update_scroll_capabilities(){for (auto& [context_id, context] : m_contexts) {- auto* presentation = presentation_for_context(root_context_of(*context)->context_id());- context->set_scrolls_elastically(presentation && m_presentations.get(presentation)->scrolls_elastically);- context->set_scrollbar_track_press_jumps(presentation && m_presentations.get(presentation)->scrollbar_track_press_jumps);+ ContextState::ScrollCapabilities capabilities;+ if (auto* presentation = presentation_for_context(root_context_of(*context)->context_id())) {+ auto const& presentation_capabilities = *m_presentations.get(presentation);+ capabilities.scrolls_elastically = presentation_capabilities.scrolls_elastically;+ capabilities.scrollbar_track_press_jumps = presentation_capabilities.scrollbar_track_press_jumps;+ if (!presentation_capabilities.synthesizes_scroll_momentum)+ capabilities.touchpad_gesture_end = Compositing::TouchpadGestureEnd::WhenFingersLift;+ }+ context->set_scroll_capabilities(capabilities);}}@@ -1539,6 +1546,12 @@ void CompositorState::begin_input_trace_for_testing(Web::CompositorContextId concontext->input_trace().begin();}+void CompositorState::clear_per_test_input_state_for_testing(Web::CompositorContextId context_id)+{+ if (auto* context = context_if_present(context_id))+ context->clear_per_test_input_state();+}+Vector<Web::InputTraceRecord> CompositorState::take_input_trace_for_testing(Web::CompositorContextId context_id){auto* context = context_if_present(context_id);diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.hindex 5642327a117..838cdf5ca86 100644--- a/Services/Compositor/CompositorState.h+++ b/Services/Compositor/CompositorState.h@@ -148,6 +148,7 @@ public:String scroll_state_for_testing(Web::CompositorContextId, Web::AsyncScrollNodeStableID stretched_scroller) const;Optional<Compositing::FirstWheelStepRouteForTesting> route_first_wheel_step_for_testing(Web::CompositorContextId, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels);void begin_input_trace_for_testing(Web::CompositorContextId);+ void clear_per_test_input_state_for_testing(Web::CompositorContextId);Vector<Web::InputTraceRecord> take_input_trace_for_testing(Web::CompositorContextId);struct PlaceholderCanvasAllocation {diff --git a/Services/Compositor/CompositorWebContentServer.ipc b/Services/Compositor/CompositorWebContentServer.ipcindex 4da39f3e063..aac4fc292b6 100644--- a/Services/Compositor/CompositorWebContentServer.ipc+++ b/Services/Compositor/CompositorWebContentServer.ipc@@ -76,6 +76,7 @@ endpoint CompositorWebContentServersynchronize_for_testing() => ()route_first_wheel_step_for_testing(Web::CompositorContextId context_id, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels) => (Optional<Web::InputRoutingDecision> decision, Optional<Web::AsyncScrollNodeStableID> scroller, Optional<Web::UniqueNodeID> document_id)begin_input_trace_for_testing(Web::CompositorContextId context_id) => ()+ clear_per_test_input_state_for_testing(Web::CompositorContextId context_id) => ()take_input_trace_for_testing(Web::CompositorContextId context_id) => (Vector<Web::InputTraceRecord> records)take_pending_async_scroll_updates(Web::CompositorContextId context_id) => (Compositing::PendingAsyncScrollUpdates updates)diff --git a/Services/Compositor/ConnectionFromWebContent.cpp b/Services/Compositor/ConnectionFromWebContent.cppindex 949843c15e8..9d997b9ddbb 100644--- a/Services/Compositor/ConnectionFromWebContent.cpp+++ b/Services/Compositor/ConnectionFromWebContent.cpp@@ -554,6 +554,13 @@ void ConnectionFromWebContent::begin_input_trace_for_testing(Web::CompositorContm_compositor_state->begin_input_trace_for_testing(context_id);}+void ConnectionFromWebContent::clear_per_test_input_state_for_testing(Web::CompositorContextId context_id)+{+ if (!context_is_owned_by_this_connection(context_id))+ return;+ m_compositor_state->clear_per_test_input_state_for_testing(context_id);+}+Messages::CompositorWebContentServer::TakeInputTraceForTestingResponse ConnectionFromWebContent::take_input_trace_for_testing(Web::CompositorContextId context_id){if (!context_is_owned_by_this_connection(context_id))diff --git a/Services/Compositor/ConnectionFromWebContent.h b/Services/Compositor/ConnectionFromWebContent.hindex 9c03638fe51..82815d51823 100644--- a/Services/Compositor/ConnectionFromWebContent.h+++ b/Services/Compositor/ConnectionFromWebContent.h@@ -83,6 +83,7 @@ private:virtual void synchronize_for_testing() override { }virtual Messages::CompositorWebContentServer::RouteFirstWheelStepForTestingResponse route_first_wheel_step_for_testing(Web::CompositorContextId, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels) override;virtual void begin_input_trace_for_testing(Web::CompositorContextId) override;+ virtual void clear_per_test_input_state_for_testing(Web::CompositorContextId) override;virtual Messages::CompositorWebContentServer::TakeInputTraceForTestingResponse take_input_trace_for_testing(Web::CompositorContextId) override;virtual Messages::CompositorWebContentServer::TakePendingAsyncScrollUpdatesResponse take_pending_async_scroll_updates(Web::CompositorContextId) override;virtual void viewport_size_updated(Web::CompositorContextId, Gfx::IntSize viewport_size, double device_pixel_ratio, Compositing::WindowResizingInProgress) override;diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cppindex 29a7ea9cd86..e71c58630a3 100644--- a/Services/Compositor/ContextState.cpp+++ b/Services/Compositor/ContextState.cpp@@ -1475,7 +1475,7 @@ 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 { .continues_gesture = !starts_gesture };+ return { .continues_gesture = !starts_gesture, .lasts_until_fingers_lift = m_wheel_gesture_routing.gesture_lasts_until_fingers_lift() };}bool ContextState::start_scroll_fling_if_flicked(Web::MouseEvent const& gesture_end_event, Optional<MonotonicTime> now_for_testing)@@ -1516,6 +1516,14 @@ Optional<Web::MouseEvent> ContextState::end_momentum_scrolling(Web::AsyncScrollNreturn interrupt_reported_scroll_momentum();}+void ContextState::clear_per_test_input_state()+{+ // A gesture held by fingers never ends by itself, so one a test left unended would take in the next test's steps.+ m_wheel_gesture_routing.forget_gesture();+ m_last_reported_scroll_momentum_step.clear();+ m_reported_scroll_momentum_was_interrupted = false;+}+bool ContextState::absorbs_wheel_event_of_interrupted_momentum(Web::MouseEvent const& event){if (!m_reported_scroll_momentum_was_interrupted)@@ -1798,9 +1806,11 @@ bool ContextState::pull_elastic_overscroll_by(Compositing::AsyncScrollNode constreturn m_elastic_overscroll_controller.pull_by(node, *scroll_offset, step_delta, delta_the_scroller_did_not_scroll_by, m_scene.visual_viewport_magnification());}-void ContextState::set_scrolls_elastically(bool scrolls_elastically)+void ContextState::set_scroll_capabilities(ScrollCapabilities const& capabilities){- m_elastic_overscroll_controller.set_enabled(scrolls_elastically);+ m_elastic_overscroll_controller.set_enabled(capabilities.scrolls_elastically);+ m_scrollbar_track_press_jumps = capabilities.scrollbar_track_press_jumps;+ m_wheel_gesture_routing.set_touchpad_gesture_end(capabilities.touchpad_gesture_end);}Optional<Gfx::IntRect> ContextState::advance_elastic_overscroll_rebounds(MonotonicTime frame_time)@@ -2249,6 +2259,8 @@ AsyncScrollUpdateOutbox::UserScrollGestureState ContextState::user_scroll_gesturif (!state.boxes_in_user_scroll_gesture.contains_slow(box))state.boxes_in_user_scroll_gesture.append(box);}+ if (auto box = m_wheel_gesture_routing.scroller_held_by_fingers(); box.has_value() && !state.boxes_in_user_scroll_gesture.contains_slow(box.value()))+ state.boxes_in_user_scroll_gesture.append(box.value());state.wheel_latched_scroller = m_wheel_gesture_routing.latched_scroller();return state;}diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.hindex d4f195ea39b..ce65b46ea88 100644--- a/Services/Compositor/ContextState.h+++ b/Services/Compositor/ContextState.h@@ -173,6 +173,7 @@ public:ContextUpdateResult scroll_for_wheel_event_passed_on_by_nested_context(Web::MouseEvent const&, 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();FirstWheelStepRoute route_first_wheel_step_from_containing_context(Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels, Web::WheelDeltaPrecision, Compositing::NestedContextRegions);// Latches the gesture to the scroller the route found, or to the one that keeps the step, and scrolls by the step.@@ -213,8 +214,13 @@ public:Optional<Web::MouseEvent> end_momentum_scrolling(Web::AsyncScrollNodeStableID);// Whether the wheel event from the UI is momentum, or the end, of a gesture whose momentum was interrupted.bool absorbs_wheel_event_of_interrupted_momentum(Web::MouseEvent const&);- void set_scrolls_elastically(bool);- void set_scrollbar_track_press_jumps(bool jumps) { m_scrollbar_track_press_jumps = jumps; }+ // What the presentation a context is shown through makes of the user's scrolling.+ struct ScrollCapabilities {+ bool scrolls_elastically { false };+ bool scrollbar_track_press_jumps { false };+ Compositing::TouchpadGestureEnd touchpad_gesture_end { Compositing::TouchpadGestureEnd::AfterIdleDelay };+ };+ void set_scroll_capabilities(ScrollCapabilities const&);Optional<Gfx::IntRect> advance_elastic_overscroll_rebounds(MonotonicTime frame_time);Optional<PendingFrame> advance_scrollbar_fades(MonotonicTime frame_time);// The installed scrolling state, its routing admission, and how far the given scroller is stretched, as JSON.diff --git a/Services/Compositor/WheelGestureRouting.cpp b/Services/Compositor/WheelGestureRouting.cppindex ca311478e41..dea9a1e32c2 100644--- a/Services/Compositor/WheelGestureRouting.cpp+++ b/Services/Compositor/WheelGestureRouting.cpp@@ -58,7 +58,7 @@ bool WheelGestureRouting::note_wheel_event(u64 input_event_id, Web::ScrollGesturm_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));+ 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);if (starts_gesture) {m_gesture = Compositing::WheelGestureIdentity::started_by(position, phase, modifiers, now);m_gesture_had_wheel_event_with_delta = false;@@ -73,6 +73,14 @@ bool WheelGestureRouting::note_wheel_event(u64 input_event_id, Web::ScrollGesturreturn starts_gesture;}+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();+}+bool WheelGestureRouting::step_was_overtaken_by_ui(Web::ScrollGesturePhase phase, u64 input_event_id) const{auto const& newest = m_newest_wheel_event_ids_from_ui;@@ -119,6 +127,22 @@ Optional<Web::AsyncScrollNodeStableID> WheelGestureRouting::latched_scroller() creturn m_latch->stable_node_id;}+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();+}++Optional<Web::AsyncScrollNodeStableID> WheelGestureRouting::scroller_held_by_fingers() const+{+ 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;+ if (!held_by_fingers)+ return {};+ return m_latch->stable_node_id;+}+void WheelGestureRouting::latch(Web::AsyncScrollNodeStableID stable_node_id, Web::ScrollGesturePhase scroll_gesture_phase){m_latch = Latch {diff --git a/Services/Compositor/WheelGestureRouting.h b/Services/Compositor/WheelGestureRouting.hindex 3c6c6b51fce..72b213f0d7f 100644--- a/Services/Compositor/WheelGestureRouting.h+++ b/Services/Compositor/WheelGestureRouting.h@@ -45,6 +45,11 @@ public:bool has_latch() const { return m_latch.has_value(); }Optional<Web::AsyncScrollNodeStableID> latched_scroller() const;+ void set_touchpad_gesture_end(Compositing::TouchpadGestureEnd touchpad_gesture_end) { m_touchpad_gesture_end = touchpad_gesture_end; }+ // Whether the fingers of the gesture are on the touchpad, where the gesture lasts until they lift.+ bool gesture_lasts_until_fingers_lift() const;+ // The scroller of such a gesture, or of one a containing context hands the steps of to this one.+ Optional<Web::AsyncScrollNodeStableID> scroller_held_by_fingers() const;// What a gesture is latched to: a scroller in the current scroll tree, a context nested in this one that latched the// gesture to a scroller of its own, or nothing that scrolls, when this context keeps the steps from the document// around it.@@ -60,6 +65,7 @@ public:void latch_to_nested_context(Web::CompositorContextId, Optional<Web::AsyncScrollNodeStableID> scroller, Web::ScrollGesturePhase);void latch_keeping_steps(Web::ScrollGesturePhase);void clear_latch() { m_latch.clear(); }+ void forget_gesture();void relatch_to(Web::AsyncScrollNodeStableID);void note_page_let_latched_gesture_through();bool page_let_latched_touchpad_gesture_through(Web::WheelDeltaPrecision, Web::ScrollGesturePhase) const;@@ -100,6 +106,7 @@ private: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/LibCompositing/CMakeLists.txt b/Tests/LibCompositing/CMakeLists.txtindex 21d939e3c34..25ad8c6b584 100644--- a/Tests/LibCompositing/CMakeLists.txt+++ b/Tests/LibCompositing/CMakeLists.txt@@ -10,6 +10,7 @@ set(TEST_SOURCESTestTextureUpload.cppTestUIOverlays.cppTestVideoFrameHold.cpp+ TestWheelGestureIdentity.cpp)foreach(source IN LISTS TEST_SOURCES)diff --git a/Tests/LibCompositing/TestWheelGestureIdentity.cpp b/Tests/LibCompositing/TestWheelGestureIdentity.cppnew file mode 100644index 00000000000..08e2d05bc32--- /dev/null+++ b/Tests/LibCompositing/TestWheelGestureIdentity.cpp@@ -0,0 +1,62 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include <LibCompositing/Scrolling/WheelGestureIdentity.h>+#include <LibCompositing/Types.h>+#include <LibTest/TestCase.h>+#include <LibWebCommon/Page/InputEvent.h>++using namespace Compositing;++static constexpr Gfx::FloatPoint position { 100, 100 };+static constexpr float position_slop = wheel_gesture_position_slop_in_css_pixels;+static auto const rest_longer_than_the_idle_delay = user_scroll_settle_delay + AK::Duration::from_milliseconds(100);++TEST_CASE(fingers_resting_on_the_touchpad_end_the_gesture_after_the_idle_delay)+{+ auto start = MonotonicTime::now_coarse();+ auto gesture = WheelGestureIdentity::started_by(position, Web::ScrollGesturePhase::Ongoing, 0, start);+ EXPECT(gesture.is_held_by_fingers());++ auto after_rest = start + rest_longer_than_the_idle_delay;+ EXPECT(!gesture.is_continued_by(position, Web::ScrollGesturePhase::Ongoing, 0, after_rest, position_slop, TouchpadGestureEnd::AfterIdleDelay));+}++TEST_CASE(fingers_resting_on_the_touchpad_keep_the_gesture_until_they_lift)+{+ auto start = MonotonicTime::now_coarse();+ auto gesture = WheelGestureIdentity::started_by(position, Web::ScrollGesturePhase::Ongoing, 0, start);++ auto after_rest = start + rest_longer_than_the_idle_delay;+ EXPECT(gesture.is_continued_by(position, Web::ScrollGesturePhase::Ongoing, 0, after_rest, position_slop, TouchpadGestureEnd::WhenFingersLift));++ // The fingers lift, and fingers that touch down long after start another gesture.+ gesture.advance_to(Web::ScrollGesturePhase::Ended, after_rest);+ EXPECT(!gesture.is_held_by_fingers());+ auto much_later = after_rest + rest_longer_than_the_idle_delay;+ EXPECT(!gesture.is_continued_by(position, Web::ScrollGesturePhase::Ongoing, 0, much_later, position_slop, TouchpadGestureEnd::WhenFingersLift));+}++TEST_CASE(momentum_that_pauses_ends_the_gesture_after_the_idle_delay)+{+ auto start = MonotonicTime::now_coarse();+ auto gesture = WheelGestureIdentity::started_by(position, Web::ScrollGesturePhase::Ongoing, 0, start);+ gesture.advance_to(Web::ScrollGesturePhase::Momentum, start);+ EXPECT(!gesture.is_held_by_fingers());++ auto after_pause = start + rest_longer_than_the_idle_delay;+ EXPECT(!gesture.is_continued_by(position, Web::ScrollGesturePhase::Momentum, 0, after_pause, position_slop, TouchpadGestureEnd::WhenFingersLift));+}++TEST_CASE(a_mouse_wheel_that_pauses_ends_the_gesture_after_the_idle_delay)+{+ auto start = MonotonicTime::now_coarse();+ auto gesture = WheelGestureIdentity::started_by(position, Web::ScrollGesturePhase::None, 0, start);+ EXPECT(!gesture.is_held_by_fingers());++ auto after_pause = start + rest_longer_than_the_idle_delay;+ EXPECT(!gesture.is_continued_by(position, Web::ScrollGesturePhase::None, 0, after_pause, position_slop, TouchpadGestureEnd::WhenFingersLift));+}diff --git a/Tests/LibWeb/Text/expected/async-scrolling/ui-touchpad-gesture-paused-over-iframe-ends-the-iframe-scroll.txt b/Tests/LibWeb/Text/expected/async-scrolling/ui-touchpad-gesture-paused-over-iframe-ends-the-iframe-scroll.txtdeleted file mode 100644index 75f55e23af3..00000000000--- a/Tests/LibWeb/Text/expected/async-scrolling/ui-touchpad-gesture-paused-over-iframe-ends-the-iframe-scroll.txt+++ /dev/null@@ -1 +0,0 @@-frame scrollY: 150diff --git a/Tests/LibWeb/Text/expected/async-scrolling/ui-touchpad-gesture-resting-over-iframe-stays-with-the-iframe.txt b/Tests/LibWeb/Text/expected/async-scrolling/ui-touchpad-gesture-resting-over-iframe-stays-with-the-iframe.txtnew file mode 100644index 00000000000..3970ab8da16--- /dev/null+++ b/Tests/LibWeb/Text/expected/async-scrolling/ui-touchpad-gesture-resting-over-iframe-stays-with-the-iframe.txt@@ -0,0 +1,2 @@+Before the fingers lift: frame scrollY 150, page scrollY 0, frame scrollend events: 0+After they lift: frame scrollY 150, page scrollY 0, frame scrollend events: 1diff --git a/Tests/LibWeb/Text/input/async-scrolling/ui-touchpad-gesture-paused-over-iframe-ends-the-iframe-scroll.html b/Tests/LibWeb/Text/input/async-scrolling/ui-touchpad-gesture-paused-over-iframe-ends-the-iframe-scroll.htmldeleted file mode 100644index 14343cc1ee0..00000000000--- a/Tests/LibWeb/Text/input/async-scrolling/ui-touchpad-gesture-paused-over-iframe-ends-the-iframe-scroll.html+++ /dev/null@@ -1,33 +0,0 @@-<!DOCTYPE html>-<script src="../include.js"></script>-<style>- body {- margin: 0;- height: 2000px;- }-- iframe {- display: block;- width: 200px;- height: 150px;- border: 0;- }-</style>-<script>- promiseTest(async () => {- const frame = document.createElement("iframe");- const frameLoaded = new Promise(resolve => frame.addEventListener("load", resolve, { once: true }));- frame.srcdoc = "<body style='margin: 0; height: 300px'></body>";- document.body.prepend(frame);- await frameLoaded;- await waitForCondition(() => internals.compositorWheelTargetAt(100, 75, 0, 50).document === frame.contentDocument);-- // A touchpad gesture whose steps stop arriving is over, and the frame gets the scrollend event of its scroll- // even if the end of the gesture never arrives, as when it goes to the page instead.- await scrollSettled(frame.contentDocument, async () => {- await internals.wheelThroughUIProcess(100, 75, 0, 100, true, "ongoing");- await internals.wheelThroughUIProcess(100, 75, 0, 100, true, "ongoing");- });- println(`frame scrollY: ${frame.contentWindow.scrollY}`);- });-</script>diff --git a/Tests/LibWeb/Text/input/async-scrolling/ui-touchpad-gesture-resting-over-iframe-stays-with-the-iframe.html b/Tests/LibWeb/Text/input/async-scrolling/ui-touchpad-gesture-resting-over-iframe-stays-with-the-iframe.htmlnew file mode 100644index 00000000000..1dab4fa099d--- /dev/null+++ b/Tests/LibWeb/Text/input/async-scrolling/ui-touchpad-gesture-resting-over-iframe-stays-with-the-iframe.html@@ -0,0 +1,44 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ body {+ margin: 0;+ height: 2000px;+ }++ iframe {+ display: block;+ width: 200px;+ height: 150px;+ border: 0;+ }+</style>+<script>+ promiseTest(async () => {+ const frame = document.createElement("iframe");+ const frameLoaded = new Promise(resolve => frame.addEventListener("load", resolve, { once: true }));+ frame.srcdoc = "<body style='margin: 0; height: 300px'></body>";+ document.body.prepend(frame);+ await frameLoaded;+ await waitForCondition(() => internals.compositorWheelTargetAt(100, 75, 0, 50).document === frame.contentDocument);++ let frameScrollends = 0;+ frame.contentDocument.addEventListener("scrollend", () => frameScrollends++);++ // The fingers of a touchpad gesture that rest on the touchpad keep the gesture going until they lift, however+ // long they rest, so the steps after the rest stay with the frame at its edge rather than scroll the page.+ for (let step = 0; step < 2; step++)+ await internals.wheelThroughUIProcess(100, 75, 0, 100, true, "ongoing");+ await new Promise(resolve => setTimeout(resolve, 600));+ for (let step = 0; step < 2; step++)+ await internals.wheelThroughUIProcess(100, 75, 0, 100, true, "ongoing");+ await animationFrame();+ await animationFrame();+ println(`Before the fingers lift: frame scrollY ${frame.contentWindow.scrollY}, page scrollY ${window.scrollY}, frame scrollend events: ${frameScrollends}`);++ await internals.wheelThroughUIProcess(100, 75, 0, 0, true, "ended");+ for (let frameCount = 0; frameCount < 3; frameCount++)+ await animationFrame();+ println(`After they lift: frame scrollY ${frame.contentWindow.scrollY}, page scrollY ${window.scrollY}, frame scrollend events: ${frameScrollends}`);+ });+</script>