Truly independent web browser
LibWeb+Compositor: Send no wheel event for a step that moves nothing
sideshowbarker01514eb34a0e
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cppindex 5f47dd75da3..97cebfaa823 100644--- a/Libraries/LibWeb/Page/EventHandler.cpp+++ b/Libraries/LibWeb/Page/EventHandler.cpp@@ -1176,7 +1176,11 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi}auto dispatch_result = EventResult::Accepted;- if (wheel_event_target_node) {+ // A step that moves along no axis, as a touchpad sends when fingers come to rest on it or lift off, is no wheel+ // rotation, so no wheel event goes to the page for it. A page could otherwise take one for the start of a scroll,+ // and handle the pinch that follows it as if it were part of that scroll.+ bool moves_along_an_axis = wheel_delta_x != 0 || wheel_delta_y != 0;+ if (wheel_event_target_node && moves_along_an_axis) {dispatch_result = dispatch_wheel_event(read, *wheel_event_target_layout_node, visual_viewport_position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, !async_scroll_performed_default_action);if (dispatch_result == EventResult::Accepted)record_input_routing(InputRoutingDecision::DispatchedWheelEvent, {}, wheel_event_target_node);diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cppindex 918e8fdf201..9e520f3d997 100644--- a/Services/Compositor/CompositorState.cpp+++ b/Services/Compositor/CompositorState.cpp@@ -1262,7 +1262,10 @@ Compositing::WheelEventAnswer CompositorState::scroll_for_wheel_event_the_page_lauto now = MonotonicTime::now();auto gesture_id = let_through.wheel_gesture_mark.gesture_id;- listener_context->note_page_let_wheel_gesture_through(gesture_id);+ // A step that moves along no axis goes to the page as no wheel event, so the page had no say in letting it through,+ // and it decides nothing for the steps after it.+ if (!let_through.delta_in_css_pixels.is_zero())+ listener_context->note_page_let_wheel_gesture_through(gesture_id);ContextState::WheelStep step {.position = let_through.position,.delta_in_css_pixels = let_through.delta_in_css_pixels,diff --git a/Tests/LibWeb/Text/expected/async-scrolling/ui-touchpad-gesture-over-iframe-yields-to-a-listener-added-mid-gesture.txt b/Tests/LibWeb/Text/expected/async-scrolling/ui-touchpad-gesture-over-iframe-yields-to-a-listener-added-mid-gesture.txtindex 265244dffee..eeae234fda8 100644--- a/Tests/LibWeb/Text/expected/async-scrolling/ui-touchpad-gesture-over-iframe-yields-to-a-listener-added-mid-gesture.txt+++ b/Tests/LibWeb/Text/expected/async-scrolling/ui-touchpad-gesture-over-iframe-yields-to-a-listener-added-mid-gesture.txt@@ -3,5 +3,5 @@#1 compositor: forwarded-to-pagecompositor scrolled a later step: falseframe scrolled by the first step: true-canceled wheel events: 2+canceled wheel events: 1frame scrolled by the canceled step: falsediff --git a/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-over-iframe-with-a-wheel-listener-asks-only-about-the-first-step.txt b/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-over-iframe-with-a-wheel-listener-asks-only-about-the-first-step.txtindex fb960fcf016..7f4dadff84e 100644--- a/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-over-iframe-with-a-wheel-listener-asks-only-about-the-first-step.txt+++ b/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-over-iframe-with-a-wheel-listener-asks-only-about-the-first-step.txt@@ -1,4 +1,4 @@-cancelable touchpad steps: true,false,false,false+cancelable touchpad steps: true,false,falseframe scrollY after the touchpad gesture: 90cancelable ticks: true,false,falseframe scrollY after the ticks: 210diff --git a/Tests/LibWeb/Text/expected/async-scrolling/wheel-latch-dom-target-during-compositor-scroll.txt b/Tests/LibWeb/Text/expected/async-scrolling/wheel-latch-dom-target-during-compositor-scroll.txtindex 10713ab4102..f909bccc323 100644--- a/Tests/LibWeb/Text/expected/async-scrolling/wheel-latch-dom-target-during-compositor-scroll.txt+++ b/Tests/LibWeb/Text/expected/async-scrolling/wheel-latch-dom-target-during-compositor-scroll.txt@@ -1,2 +1,2 @@-wheel event targets: a,a,a,b,b+wheel event targets: a,a,bwindow.scrollY: 300diff --git a/Tests/LibWeb/Text/expected/async-scrolling/wheel-latch-nested-navigable-during-compositor-scroll.txt b/Tests/LibWeb/Text/expected/async-scrolling/wheel-latch-nested-navigable-during-compositor-scroll.txtindex 5b98d905664..6bf9e6ab1ff 100644--- a/Tests/LibWeb/Text/expected/async-scrolling/wheel-latch-nested-navigable-during-compositor-scroll.txt+++ b/Tests/LibWeb/Text/expected/async-scrolling/wheel-latch-nested-navigable-during-compositor-scroll.txt@@ -1,3 +1,3 @@iframe scrollY: 200window.scrollY: 0-wheel events in the iframe: 3+wheel events in the iframe: 2diff --git a/Tests/LibWeb/Text/expected/wheel-latch-keeps-wheel-event-target.txt b/Tests/LibWeb/Text/expected/wheel-latch-keeps-wheel-event-target.txtindex ac79e686f1f..f909bccc323 100644--- a/Tests/LibWeb/Text/expected/wheel-latch-keeps-wheel-event-target.txt+++ b/Tests/LibWeb/Text/expected/wheel-latch-keeps-wheel-event-target.txt@@ -1,2 +1,2 @@-wheel event targets: a,a,a,b+wheel event targets: a,a,bwindow.scrollY: 300diff --git a/Tests/LibWeb/Text/expected/wheel-latch-over-text-keeps-dispatching-and-scrolling.txt b/Tests/LibWeb/Text/expected/wheel-latch-over-text-keeps-dispatching-and-scrolling.txtindex 722d035290e..a82a7409fbc 100644--- a/Tests/LibWeb/Text/expected/wheel-latch-over-text-keeps-dispatching-and-scrolling.txt+++ b/Tests/LibWeb/Text/expected/wheel-latch-over-text-keeps-dispatching-and-scrolling.txt@@ -1,2 +1,2 @@-wheel event targets: SPAN,SPAN,SPAN,SPAN+wheel event targets: SPAN,SPAN,SPANscroller.scrollTop: 30diff --git a/Tests/LibWeb/Text/expected/wheel-step-without-delta-dispatches-no-wheel-event.txt b/Tests/LibWeb/Text/expected/wheel-step-without-delta-dispatches-no-wheel-event.txtnew file mode 100644index 00000000000..236363abced--- /dev/null+++ b/Tests/LibWeb/Text/expected/wheel-step-without-delta-dispatches-no-wheel-event.txt@@ -0,0 +1,2 @@+wheel events: 0,40 30,0+window.scrollY: 0diff --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.htmlindex 9c3b3f44b70..4383710b227 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@@ -30,7 +30,8 @@await animationFrame();// 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.+ // second step; the gesture's wheel events keep going to #a. Its end, a step that moves along no axis, goes to+ // the page as no wheel event.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");diff --git a/Tests/LibWeb/Text/input/async-scrolling/wheel-latch-nested-navigable-during-compositor-scroll.html b/Tests/LibWeb/Text/input/async-scrolling/wheel-latch-nested-navigable-during-compositor-scroll.htmlindex 13254511d53..6c80a0dc688 100644--- a/Tests/LibWeb/Text/input/async-scrolling/wheel-latch-nested-navigable-during-compositor-scroll.html+++ b/Tests/LibWeb/Text/input/async-scrolling/wheel-latch-nested-navigable-during-compositor-scroll.html@@ -25,7 +25,7 @@await animationFrame();await animationFrame();- // The compositor scrolls the nested navigable, and every event of the gesture reaches it, its end included.+ // The compositor scrolls the nested navigable, which each event of the gesture that moves on an axis reaches.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");diff --git a/Tests/LibWeb/Text/input/wheel-latch-keeps-wheel-event-target.html b/Tests/LibWeb/Text/input/wheel-latch-keeps-wheel-event-target.htmlindex 4dae309237e..ce9effb86d6 100644--- a/Tests/LibWeb/Text/input/wheel-latch-keeps-wheel-event-target.html+++ b/Tests/LibWeb/Text/input/wheel-latch-keeps-wheel-event-target.html@@ -30,7 +30,8 @@await animationFrame();await animationFrame();- // The first step scrolls #b under the cursor, but the gesture's events keep going to #a, its end included.+ // The first step scrolls #b under the cursor, but the gesture's events keep going to #a. Its end, a step that+ // moves along no axis, goes to the page as no wheel event.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");diff --git a/Tests/LibWeb/Text/input/wheel-latch-over-text-keeps-dispatching-and-scrolling.html b/Tests/LibWeb/Text/input/wheel-latch-over-text-keeps-dispatching-and-scrolling.htmlindex 32f19a8bd76..ec2c88f3288 100644--- a/Tests/LibWeb/Text/input/wheel-latch-over-text-keeps-dispatching-and-scrolling.html+++ b/Tests/LibWeb/Text/input/wheel-latch-over-text-keeps-dispatching-and-scrolling.html@@ -26,7 +26,8 @@await animationFrame();await animationFrame();- // Every step of a gesture that starts over text goes to the element around the text and scrolls the scroller.+ // Every step of a gesture that starts over text and moves along an axis goes to the element around the text and+ // scrolls the scroller.for (let step = 0; step < 3; step++)await internals.wheel(15, 15, 0, 10, true, "ongoing");await internals.wheel(15, 15, 0, 0, true, "ended");diff --git a/Tests/LibWeb/Text/input/wheel-step-without-delta-dispatches-no-wheel-event.html b/Tests/LibWeb/Text/input/wheel-step-without-delta-dispatches-no-wheel-event.htmlnew file mode 100644index 00000000000..f3a0d5a621e--- /dev/null+++ b/Tests/LibWeb/Text/input/wheel-step-without-delta-dispatches-no-wheel-event.html@@ -0,0 +1,33 @@+<!DOCTYPE html>+<script src="include.js"></script>+<style>+ body {+ margin: 0;+ height: 2000px;+ }+ #target {+ width: 200px;+ height: 200px;+ }+</style>+<div id="target"></div>+<script>+ promiseTest(async () => {+ const deltas = [];+ target.addEventListener("wheel", event => {+ deltas.push(`${event.deltaX},${event.deltaY}`);+ event.preventDefault();+ }, { passive: false });+ await animationFrame();+ await animationFrame();++ // Fingers that come to rest on a touchpad, and lift off it, send steps that move along no axis.+ await internals.wheel(50, 50, 0, 0, true, "ongoing");+ await internals.wheel(50, 50, 0, 40, true, "ongoing");+ await internals.wheel(50, 50, 30, 0, true, "ongoing");+ await internals.wheel(50, 50, 0, 0, true, "ended");++ println(`wheel events: ${deltas.join(" ")}`);+ println(`window.scrollY: ${window.scrollY}`);+ });+</script>