Truly independent web browser
LibCompositing: Start a new wheel gesture when fingers catch momentum
Aliaksandr Kalenik8eb56b1673cc
diff --git a/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.cpp b/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.cppindex 0ff08a143ff..3af9bcb7e84 100644--- a/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.cpp+++ b/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.cpp@@ -38,6 +38,10 @@ bool WheelGestureIdentity::is_continued_by(Gfx::FloatPoint position, Web::Scrollreturn false;if (m_kind == Kind::PhaseLess)return modifiers == m_modifiers && position.distance_from(m_first_position) <= position_slop;+ // Fingers that touch down while the momentum of the gesture runs start another gesture, whether or not the end of+ // that momentum arrived first.+ if (phase == Web::ScrollGesturePhase::Ongoing && m_momentum_has_started)+ return false;if (!m_ended_at.has_value())return true;bool phase_may_follow_an_ended_gesture = phase == Web::ScrollGesturePhase::Momentum || phase == Web::ScrollGesturePhase::Ended;@@ -47,6 +51,8 @@ bool WheelGestureIdentity::is_continued_by(Gfx::FloatPoint position, Web::Scrollvoid WheelGestureIdentity::advance_to(Web::ScrollGesturePhase phase, MonotonicTime now){m_last_event_time = now;+ if (phase == Web::ScrollGesturePhase::Momentum)+ m_momentum_has_started = true;if (phase != Web::ScrollGesturePhase::Ended) {m_ended_at.clear();return;diff --git a/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.h b/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.hindex 18c1ee7a444..b46d714deaa 100644--- a/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.h+++ b/Libraries/LibCompositing/Scrolling/WheelGestureIdentity.h@@ -44,6 +44,7 @@ private:u32 m_modifiers { 0 };MonotonicTime m_last_event_time;Optional<MonotonicTime> m_ended_at;+ bool m_momentum_has_started { false };};}diff --git a/Tests/LibWeb/Text/expected/async-scrolling/wheel-latch-fingers-during-momentum-start-new-gesture.txt b/Tests/LibWeb/Text/expected/async-scrolling/wheel-latch-fingers-during-momentum-start-new-gesture.txtnew file mode 100644index 00000000000..5c921e67d5e--- /dev/null+++ b/Tests/LibWeb/Text/expected/async-scrolling/wheel-latch-fingers-during-momentum-start-new-gesture.txt@@ -0,0 +1,4 @@+nested.scrollTop after the flick: 200+window.scrollY after the flick: 0+window.scrollY after fingers touch down again: 100+nested.scrollTop after fingers touch down again: 200diff --git a/Tests/LibWeb/Text/input/async-scrolling/wheel-latch-fingers-during-momentum-start-new-gesture.html b/Tests/LibWeb/Text/input/async-scrolling/wheel-latch-fingers-during-momentum-start-new-gesture.htmlnew file mode 100644index 00000000000..dd90e1ed4c5--- /dev/null+++ b/Tests/LibWeb/Text/input/async-scrolling/wheel-latch-fingers-during-momentum-start-new-gesture.html@@ -0,0 +1,37 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ body {+ margin: 0;+ height: 2000px;+ }+ #nested {+ width: 100px;+ height: 100px;+ overflow: scroll;+ }+ #nested > div {+ height: 300px;+ }+</style>+<div id="nested"><div></div></div>+<script>+ promiseTest(async () => {+ await animationFrame();+ await animationFrame();++ // The nested scroller reaches its extent, and the momentum of the flick keeps it latched.+ await internals.wheel(50, 50, 0, 150, true, "ongoing");+ await internals.wheel(50, 50, 0, 150, true, "ongoing");+ await internals.wheel(50, 50, 0, 20, true, "momentum");+ println(`nested.scrollTop after the flick: ${nested.scrollTop}`);+ println(`window.scrollY after the flick: ${window.scrollY}`);++ // Fingers that touch down during the momentum start a new gesture, even though the momentum never ended. It+ // goes to the page, because the nested scroller under the cursor is at its extent.+ await internals.wheel(50, 50, 0, 100, true, "ongoing");+ println(`window.scrollY after fingers touch down again: ${window.scrollY}`);+ println(`nested.scrollTop after fingers touch down again: ${nested.scrollTop}`);+ await internals.wheel(50, 50, 0, 0, true, "ended");+ });+</script>