Truly independent web browser
LibWeb: Settle a paused touchpad gesture without waiting for its end
Tim Ledbetterca7086ae117f
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex 0ca85c4d663..d230c1f6f4d 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -5133,7 +5133,7 @@ void LocalNavigable::note_user_scroll_gesture_phase(Web::ScrollGesturePhase phascase Web::ScrollGesturePhase::None:m_user_scroll_gesture_travels_under_momentum = false;reset_momentum_fling_state();- m_wheel_user_scroll_gesture_hold = nullptr;+ release_wheel_user_scroll_gesture_hold();break;case Web::ScrollGesturePhase::Ongoing:case Web::ScrollGesturePhase::Momentum: {@@ -5143,7 +5143,7 @@ void LocalNavigable::note_user_scroll_gesture_phase(Web::ScrollGesturePhase phasreset_momentum_fling_state();if (m_wheel_user_scroll_gesture_hold && m_user_scroll_gesture_travels_under_momentum != travels_under_momentum)- m_wheel_user_scroll_gesture_hold = nullptr;+ release_wheel_user_scroll_gesture_hold();m_user_scroll_gesture_travels_under_momentum = travels_under_momentum;if (!m_wheel_user_scroll_gesture_hold)@@ -5154,7 +5154,7 @@ void LocalNavigable::note_user_scroll_gesture_phase(Web::ScrollGesturePhase phasm_user_scroll_gesture_travels_under_momentum = false;reset_momentum_fling_state();if (m_wheel_user_scroll_gesture_hold) {- m_wheel_user_scroll_gesture_hold = nullptr;+ release_wheel_user_scroll_gesture_hold();break;}settle_user_scroll_gesture();@@ -5162,6 +5162,25 @@ void LocalNavigable::note_user_scroll_gesture_phase(Web::ScrollGesturePhase phas}}+void LocalNavigable::did_handle_wheel_event()+{+ if (!m_wheel_user_scroll_gesture_hold)+ 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;+ });+ }+ m_wheel_user_scroll_gesture_hold_expiry_timer->restart();+}++void LocalNavigable::release_wheel_user_scroll_gesture_hold()+{+ if (m_wheel_user_scroll_gesture_hold_expiry_timer)+ m_wheel_user_scroll_gesture_hold_expiry_timer->stop();+ m_wheel_user_scroll_gesture_hold = nullptr;+}+void LocalNavigable::reset_momentum_fling_state(){m_momentum_snap_position_selection = MomentumSnapPositionSelection::NotSelectedYet;@@ -5291,7 +5310,7 @@ void LocalNavigable::cancel_user_scroll_settlement()m_user_scroll_settle_timer->stop();m_pending_user_scrollend_targets.clear();m_compositor_user_scroll_gesture_hold = nullptr;- m_wheel_user_scroll_gesture_hold = nullptr;+ release_wheel_user_scroll_gesture_hold();}void LocalNavigable::begin_user_scroll_gesture_hold(Badge<UserScrollGestureHold>)diff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.hindex 9b073b01ed0..cd842358185 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.h+++ b/Libraries/LibWeb/HTML/LocalNavigable.h@@ -411,6 +411,7 @@ public:void note_user_scroll_input_intent(Compositing::SnapSelectionStrategy::Type);RefPtr<Painting::Scrollbar> scrollbar_dragged_by_compositor(Layout::BegunRead const& read, Web::ScrollbarDraggedByCompositor const&);void note_user_scroll_gesture_phase(Web::ScrollGesturePhase);+ void did_handle_wheel_event();void defer_user_scroll_settlement();void snap_user_scroll_gestures_that_awaited_layout();void begin_user_scroll_gesture_hold(Badge<UserScrollGestureHold>);@@ -514,6 +515,7 @@ private:void abandon_snapping_of_user_scroll_gesture(Web::AsyncScrollNodeStableID);void settle_user_scroll_gesture();void settle_user_scroll_gesture_if_input_deadline_passed();+ void release_wheel_user_scroll_gesture_hold();void reset_momentum_fling_state();// Which of the latched gestures a settlement is for: every gesture that ran out of input, or only those left// waiting for layout by an earlier settlement.@@ -612,6 +614,7 @@ private:RefPtr<Core::Timer> m_user_scroll_settle_timer;OwnPtr<UserScrollGestureHold> m_compositor_user_scroll_gesture_hold;OwnPtr<UserScrollGestureHold> m_wheel_user_scroll_gesture_hold;+ RefPtr<Core::Timer> m_wheel_user_scroll_gesture_hold_expiry_timer;size_t m_user_scroll_gesture_hold_count { 0 };Compositing::SnapSelectionStrategy::Type m_user_scroll_input_intent { Compositing::SnapSelectionStrategy::Type::EndPosition };bool m_user_scroll_gesture_travels_under_momentum { false };diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cppindex 488e0ecabe6..0ff3a33fa61 100644--- a/Libraries/LibWeb/Page/EventHandler.cpp+++ b/Libraries/LibWeb/Page/EventHandler.cpp@@ -955,6 +955,7 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positiScopeGuard measure_next_pause_from_end_of_handling = [this] {if (m_wheel_scroll_latch.has_value())m_wheel_scroll_latch->gesture.did_handle_event(MonotonicTime::now());+ m_navigable->did_handle_wheel_event();};// A wheel step is routed against the offsets the compositor holds now, which a step it just took maydiff --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.txtnew file mode 100644index 00000000000..75f55e23af3--- /dev/null+++ b/Tests/LibWeb/Text/expected/async-scrolling/ui-touchpad-gesture-paused-over-iframe-ends-the-iframe-scroll.txt@@ -0,0 +1 @@+frame scrollY: 150diff --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.htmlnew file mode 100644index 00000000000..14343cc1ee0--- /dev/null+++ b/Tests/LibWeb/Text/input/async-scrolling/ui-touchpad-gesture-paused-over-iframe-ends-the-iframe-scroll.html@@ -0,0 +1,33 @@+<!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>