Truly independent web browser
Everywhere: Let the compositor say which gesture a wheel event is in
Zaggy1024e2d299b016d6
diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cppindex 200567aa529..8ded8d27e01 100644--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp@@ -493,9 +493,9 @@ void EventLoop::process_input_events() constcase Web::MouseEvent::Type::MouseWheel:if (mouse_event.async_scroll_performed_default_action) {dbgln_if(COMPOSITOR_DEBUG, "[Compositor] Main thread handling DOM wheel after async default action");- return page.handle_mousewheel(*root, mouse_event.position, mouse_event.screen_position, mouse_event.button, mouse_event.buttons, mouse_event.modifiers, mouse_event.wheel_delta_x, mouse_event.wheel_delta_y, mouse_event.wheel_tick_120ths_x, mouse_event.wheel_tick_120ths_y, mouse_event.wheel_delta_precision, mouse_event.scroll_gesture_phase, true, nullptr, &remote_target);+ return page.handle_mousewheel(*root, mouse_event.position, mouse_event.screen_position, mouse_event.button, mouse_event.buttons, mouse_event.modifiers, mouse_event.wheel_delta_x, mouse_event.wheel_delta_y, mouse_event.wheel_tick_120ths_x, mouse_event.wheel_tick_120ths_y, mouse_event.wheel_delta_precision, mouse_event.scroll_gesture_phase, true, nullptr, &remote_target, mouse_event.wheel_gesture_mark);}- return page.handle_mousewheel(*root, mouse_event.position, mouse_event.screen_position, mouse_event.button, mouse_event.buttons, mouse_event.modifiers, mouse_event.wheel_delta_x, mouse_event.wheel_delta_y, mouse_event.wheel_tick_120ths_x, mouse_event.wheel_tick_120ths_y, mouse_event.wheel_delta_precision, mouse_event.scroll_gesture_phase, false, nullptr, &remote_target);+ return page.handle_mousewheel(*root, mouse_event.position, mouse_event.screen_position, mouse_event.button, mouse_event.buttons, mouse_event.modifiers, mouse_event.wheel_delta_x, mouse_event.wheel_delta_y, mouse_event.wheel_tick_120ths_x, mouse_event.wheel_tick_120ths_y, mouse_event.wheel_delta_precision, mouse_event.scroll_gesture_phase, false, nullptr, &remote_target, mouse_event.wheel_gesture_mark);}VERIFY_NOT_REACHED();},diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cppindex fc6ec28d871..39850ab6d5b 100644--- a/Libraries/LibWeb/Page/EventHandler.cpp+++ b/Libraries/LibWeb/Page/EventHandler.cpp@@ -945,7 +945,7 @@ void EventHandler::record_input_routing(InputRoutingDecision decision, Optional<});}-EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, u32 button, u32 buttons, u32 modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, bool async_scroll_performed_default_action, Optional<AsyncScrollOperation>* async_scroll_operation, Optional<RemoteInputEventTarget>* remote_target)+EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, u32 button, u32 buttons, u32 modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, bool async_scroll_performed_default_action, Optional<AsyncScrollOperation>* async_scroll_operation, Optional<RemoteInputEventTarget>* remote_target, Optional<Web::WheelGestureMark> wheel_gesture_mark){record_last_known_mouse_position(visual_viewport_position, screen_position, buttons, modifiers);@@ -961,8 +961,15 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positiauto 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;- bool continues_latched_gesture = m_wheel_scroll_latch.has_value()- && m_wheel_scroll_latch->gesture.is_continued_by(gesture_position, scroll_gesture_phase, modifiers, now, Compositing::wheel_gesture_position_slop_in_css_pixels);+ // The compositor tells which gesture an event it passed on belongs to, which this navigable follows so that the two+ // route the event alike.+ bool continues_latched_gesture = false;+ if (m_wheel_scroll_latch.has_value()) {+ if (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);+ }if (continues_latched_gesture)m_wheel_scroll_latch->gesture.advance_to(scroll_gesture_phase, now);else@@ -1250,8 +1257,8 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi// A gesture this navigable latched to a scrolling box of its own is not offered to a nested navigable again.bool offer_to_nested_navigable = !continues_latched_gesture || m_wheel_scroll_latch->gesture_handed_to_nested_navigable;if (offer_to_nested_navigable) {- if (auto result = dispatch_event_to_nested_navigable(*this, *wheel_event_target_layout_node, wheel_event_target_node, visual_viewport_position, remote_target, [screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, remote_target](EventHandler& event_handler, CSSPixelPoint position) -> EventResult {- return event_handler.handle_mousewheel(position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, remote_target);+ if (auto result = dispatch_event_to_nested_navigable(*this, *wheel_event_target_layout_node, wheel_event_target_node, visual_viewport_position, remote_target, [screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, remote_target, wheel_gesture_mark](EventHandler& event_handler, CSSPixelPoint position) -> EventResult {+ return event_handler.handle_mousewheel(position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, remote_target, wheel_gesture_mark);});result.has_value()) {record_input_routing(InputRoutingDecision::HandedToNestedNavigable, {}, wheel_event_target_node);diff --git a/Libraries/LibWeb/Page/EventHandler.h b/Libraries/LibWeb/Page/EventHandler.hindex bcc19be55ca..799e05b15c7 100644--- a/Libraries/LibWeb/Page/EventHandler.h+++ b/Libraries/LibWeb/Page/EventHandler.h@@ -76,7 +76,7 @@ public:bool handling_outdated_input() const { return m_handling_outdated_input; }u64 handling_input_event_id() const { return m_handling_input_event_id; }EventResult handle_mouseup(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, Optional<RemoteInputEventTarget>* remote_target = nullptr);- EventResult handle_mousewheel(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, Web::WheelDeltaPrecision = Web::WheelDeltaPrecision::Discrete, Web::ScrollGesturePhase = Web::ScrollGesturePhase::None, bool async_scroll_performed_default_action = false, Optional<AsyncScrollOperation>* async_scroll_operation = nullptr, Optional<RemoteInputEventTarget>* remote_target = nullptr);+ EventResult handle_mousewheel(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, Web::WheelDeltaPrecision = Web::WheelDeltaPrecision::Discrete, Web::ScrollGesturePhase = Web::ScrollGesturePhase::None, bool async_scroll_performed_default_action = false, Optional<AsyncScrollOperation>* async_scroll_operation = nullptr, Optional<RemoteInputEventTarget>* remote_target = nullptr, Optional<Web::WheelGestureMark> = {});EventResult handle_mouseleave();EventResult handle_mousecancel();EventResult handle_pointer_event(Web::MouseEvent const&, CSSPixelPoint, CSSPixelPoint screen_position, Optional<RemoteInputEventTarget>* remote_target = nullptr);diff --git a/Libraries/LibWeb/Page/Page.cpp b/Libraries/LibWeb/Page/Page.cppindex f68c288c065..f08ef30ea83 100644--- a/Libraries/LibWeb/Page/Page.cpp+++ b/Libraries/LibWeb/Page/Page.cpp@@ -532,14 +532,14 @@ UniqueNodeID Page::node_id_at_position(DevicePixelPoint position)return node->unique_id();}-EventResult Page::handle_mousewheel(HTML::LocalNavigable& root, DevicePixelPoint position, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, bool async_scroll_performed_default_action, Optional<AsyncScrollOperation>* async_scroll_operation, Optional<RemoteInputEventTarget>* remote_target)+EventResult Page::handle_mousewheel(HTML::LocalNavigable& root, DevicePixelPoint position, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, bool async_scroll_performed_default_action, Optional<AsyncScrollOperation>* async_scroll_operation, Optional<RemoteInputEventTarget>* remote_target, Optional<Web::WheelGestureMark> wheel_gesture_mark){- return root.event_handler().handle_mousewheel(device_to_css_point(position), device_to_css_point(screen_position), button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, remote_target);+ return root.event_handler().handle_mousewheel(device_to_css_point(position), device_to_css_point(screen_position), button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, remote_target, wheel_gesture_mark);}EventResult Page::handle_mousewheel(DevicePixelPoint position, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, bool async_scroll_performed_default_action, Optional<AsyncScrollOperation>* async_scroll_operation){- return handle_mousewheel(local_traversable(), position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, nullptr);+ return handle_mousewheel(local_traversable(), position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, nullptr, {});}EventResult Page::handle_drag_and_drop_event(HTML::LocalNavigable& root, DragEvent::Type type, DevicePixelPoint position, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, Vector<HTML::SelectedFile> files)diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.hindex 8e55e45551b..1260f0af8d8 100644--- a/Libraries/LibWeb/Page/Page.h+++ b/Libraries/LibWeb/Page/Page.h@@ -195,7 +195,7 @@ public:EventResult handle_mousemove(HTML::LocalNavigable& root, DevicePixelPoint, DevicePixelPoint screen_position, unsigned buttons, unsigned modifiers, Optional<RemoteInputEventTarget>* remote_target);EventResult handle_mouseleave(HTML::LocalNavigable& root);EventResult handle_mousecancel(HTML::LocalNavigable& root);- EventResult handle_mousewheel(HTML::LocalNavigable& root, DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, bool async_scroll_performed_default_action, Optional<AsyncScrollOperation>* async_scroll_operation, Optional<RemoteInputEventTarget>* remote_target);+ EventResult handle_mousewheel(HTML::LocalNavigable& root, DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, bool async_scroll_performed_default_action, Optional<AsyncScrollOperation>* async_scroll_operation, Optional<RemoteInputEventTarget>* remote_target, Optional<Web::WheelGestureMark>);EventResult handle_drag_and_drop_event(HTML::LocalNavigable& root, DragEvent::Type, DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, Vector<HTML::SelectedFile> files);EventResult handle_pinch_event(HTML::LocalNavigable& root, DevicePixelPoint point, unsigned modifiers, double scale, bool async_zoom_performed_default_action);diff --git a/Libraries/LibWebCommon/Page/InputEvent.cpp b/Libraries/LibWebCommon/Page/InputEvent.cppindex db48c6c873e..0177ed88d7c 100644--- a/Libraries/LibWebCommon/Page/InputEvent.cpp+++ b/Libraries/LibWebCommon/Page/InputEvent.cpp@@ -33,7 +33,7 @@ KeyEvent KeyEvent::clone_without_browser_data() constMouseEvent MouseEvent::clone_without_browser_data() const{- return { type, position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, click_count, nullptr, async_scroll_performed_default_action, id, scrollbar_dragged_by_compositor, pointer_data };+ return { type, position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, click_count, nullptr, async_scroll_performed_default_action, id, scrollbar_dragged_by_compositor, pointer_data, wheel_gesture_mark };}}diff --git a/Libraries/LibWebCommon/Page/InputEvent.h b/Libraries/LibWebCommon/Page/InputEvent.hindex 1ccd54c5804..4a3895bacb9 100644--- a/Libraries/LibWebCommon/Page/InputEvent.h+++ b/Libraries/LibWebCommon/Page/InputEvent.h@@ -142,6 +142,15 @@ private:OwnPtr<PointerProperties> m_properties;};+// What the compositor found of a wheel event's gesture as it passed the event on, which WebContent follows rather+// than deciding again.+struct WheelGestureMark {+ // Whether the event continues the gesture before it, rather than starting one.+ bool continues_gesture { false };++ bool operator==(WheelGestureMark const&) const = default;+};+struct WEBCOMMON_API MouseEvent {enum class Type : u8 {MouseDown,@@ -173,6 +182,7 @@ struct WEBCOMMON_API MouseEvent {u64 id { 0 };Optional<Web::ScrollbarDraggedByCompositor> scrollbar_dragged_by_compositor {};PointerInputData pointer_data {};+ Optional<WheelGestureMark> wheel_gesture_mark {};};struct WEBCOMMON_API PinchEvent {diff --git a/Libraries/LibWebCommon/Page/InputEvent.ipc b/Libraries/LibWebCommon/Page/InputEvent.ipcindex 947cc6be532..df053c2637f 100644--- a/Libraries/LibWebCommon/Page/InputEvent.ipc+++ b/Libraries/LibWebCommon/Page/InputEvent.ipc@@ -35,6 +35,11 @@ enum Web::ScrollGesturePhase : u8 {Ended,}+[ExistingCpp]+struct Web::WheelGestureMark {+ bool continues_gesture;+}+[ExistingCpp]struct Web::KeyEvent {Web::KeyEvent::Type type;@@ -95,6 +100,7 @@ struct Web::MouseEvent {u64 id;Optional<Web::ScrollbarDraggedByCompositor> scrollbar_dragged_by_compositor;Web::PointerInputData pointer_data;+ Optional<Web::WheelGestureMark> wheel_gesture_mark;}[ExistingCpp]diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cppindex 683a4f948fe..77f41847b2e 100644--- a/Libraries/LibWebView/WebContentPage.cpp+++ b/Libraries/LibWebView/WebContentPage.cpp@@ -2818,6 +2818,7 @@ void WebContentPage::did_request_webdriver_mouse_event(u64 request_id, Web::HTML// Only the compositor sets these, on its way to WebContent.event.async_scroll_performed_default_action = false;event.scrollbar_dragged_by_compositor = {};+ event.wheel_gesture_mark = {};view().enqueue_webdriver_mouse_event({}, move(event), move(on_handled));}diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cppindex 528f16fdd35..40c98680481 100644--- a/Services/Compositor/CompositorState.cpp+++ b/Services/Compositor/CompositorState.cpp@@ -643,7 +643,7 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId cpresentation->did_consume_input_event(context_id, event.id);return;}- context->note_wheel_event_from_ui(event);+ event.wheel_gesture_mark = context->note_wheel_event_from_ui(event);// 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.@@ -787,7 +787,7 @@ CompositorState::WheelStepHandedToNestedContext CompositorState::hand_wheel_stepstep.position = taking_context->position;auto nested_result = taking_context->context->take_first_wheel_step_from_containing_context(taking_context->route, step, now);handed_step = apply_result_of_nested_context(taking_context->context_id, *taking_context->context, nested_result);- context.latch_wheel_gesture_to_nested_context(taking_context->context_id, handed_step.result.routed_scroller, event, now);+ context.latch_wheel_gesture_to_nested_context(taking_context->context_id, handed_step.result.routed_scroller, event);} else {handed_step.result = ContextState::ContextUpdateResult::declined(taking_context->route.decision);}@@ -852,6 +852,8 @@ void CompositorState::dispatch_scroll_fling_step(Web::CompositorContextId contexcontext.input_trace().record({ .input_event_id = event->id, .stage = Web::InputTraceStage::Compositor, .decision = *result.routing_decision, .scroller = result.routed_scroller });event->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 };context.dispatch_mouse_event_to_web_content(*event);}diff --git a/Services/Compositor/ConnectionFromPresentation.cpp b/Services/Compositor/ConnectionFromPresentation.cppindex 93a77ebd68e..9c8df3577d6 100644--- a/Services/Compositor/ConnectionFromPresentation.cpp+++ b/Services/Compositor/ConnectionFromPresentation.cpp@@ -57,7 +57,8 @@ static bool is_valid_mouse_event(Web::MouseEvent const& event)&& event.click_count >= 0// Only the compositor sets these, on its way to WebContent.&& !event.async_scroll_performed_default_action- && !event.scrollbar_dragged_by_compositor.has_value();+ && !event.scrollbar_dragged_by_compositor.has_value()+ && !event.wheel_gesture_mark.has_value();}static bool is_valid_pinch_event(Web::PinchEvent const& event)diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cppindex 9c43ac8e838..29a7ea9cd86 100644--- a/Services/Compositor/ContextState.cpp+++ b/Services/Compositor/ContextState.cpp@@ -935,7 +935,10 @@ 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();- auto latch = resolve_wheel_scroll_latch(position, scroll_gesture_phase, modifiers, now);+ // 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);+ auto latch = resolve_wheel_scroll_latch(scroll_gesture_phase);// 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);@@ -972,7 +975,7 @@ ContextState::AsyncScrollResult ContextState::async_scroll_by(auto routing_decision = Web::InputRoutingDecision::ContinuedLatch;if (is_first_step_of_gesture) {auto wheel_step_dispatch_for_hit_test = page_let_touchpad_step_through ? Compositing::WheelStepDispatch::DispatchedAndNotCanceled : Compositing::WheelStepDispatch::NotYetDispatched;- auto latch_attempt = hit_test_and_latch_wheel_gesture(position, delta, wheel_delta_precision, scroll_gesture_phase, modifiers, now, expected_document_id, wheel_step_dispatch_for_hit_test, Compositing::NestedContextRegions::LeaveToMainThread);+ auto latch_attempt = hit_test_and_latch_wheel_gesture(position, delta, wheel_delta_precision, scroll_gesture_phase, expected_document_id, wheel_step_dispatch_for_hit_test, Compositing::NestedContextRegions::LeaveToMainThread);if (!latch_attempt.latched_node_id.has_value())return AsyncScrollResult::declined(latch_attempt.decision);latched_node_id = latch_attempt.latched_node_id;@@ -1452,7 +1455,7 @@ bool ContextState::step_continues_touchpad_gesture_the_page_let_through(Optionalreturn latched_node_id.has_value() && presents_to_client() && m_wheel_gesture_routing.page_let_latched_touchpad_gesture_through(wheel_delta_precision, scroll_gesture_phase);}-void ContextState::note_wheel_event_from_ui(Web::MouseEvent const& event, Optional<MonotonicTime> now_for_testing)+Web::WheelGestureMark ContextState::note_wheel_event_from_ui(Web::MouseEvent const& event, Optional<MonotonicTime> now_for_testing){VERIFY(event.type == Web::MouseEvent::Type::MouseWheel);auto now = now_for_testing.value_or(MonotonicTime::now());@@ -1464,13 +1467,15 @@ void ContextState::note_wheel_event_from_ui(Web::MouseEvent const& event, Optionm_last_reported_scroll_momentum_step.clear();// The end of the gesture before this one may never have arrived.- if (m_wheel_gesture_routing.note_wheel_event_from_ui(event, wheel_event_position(event), m_async_scroll_tree, now))+ 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)m_elastic_overscroll_controller.end_gesture(now);// A stretch is released with the velocity of the steps as they arrived from the UI, not as they were scrolled.// 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 };}bool ContextState::start_scroll_fling_if_flicked(Web::MouseEvent const& gesture_end_event, Optional<MonotonicTime> now_for_testing)@@ -1551,7 +1556,7 @@ ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event(Web::Mousif (event.scroll_gesture_phase == Web::ScrollGesturePhase::Ended)m_elastic_overscroll_controller.end_gesture(now);- auto latch = resolve_wheel_scroll_latch(position, event.scroll_gesture_phase, event.modifiers, now);+ auto latch = resolve_wheel_scroll_latch(event.scroll_gesture_phase);if (latch.nested_context_id.has_value())return { .nested_context_wheel_step = NestedContextWheelStep { .context_id = *latch.nested_context_id } };@@ -1559,7 +1564,7 @@ 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.node_id.has_value()- && m_wheel_gesture_routing.is_first_wheel_event_from_ui_with_delta(event.id)+ && m_wheel_gesture_routing.is_first_wheel_event_with_delta(event.id)&& may_hand_first_wheel_steps_to_nested_contexts();if (may_hand_step_to_nested_context) {nested_context_regions = Compositing::NestedContextRegions::HandToNestedContext;@@ -1622,7 +1627,7 @@ ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event_in_this_c// for as long as the gesture only pans.auto routing_decision = Web::InputRoutingDecision::ContinuedLatch;if (is_first_step_of_gesture) {- auto latch_attempt = hit_test_and_latch_wheel_gesture(position, delta.scaled(1.0f / m_scene.visual_viewport_magnification()), event.wheel_delta_precision, event.scroll_gesture_phase, event.modifiers, now, {}, Compositing::WheelStepDispatch::NotYetDispatched, nested_context_regions);+ auto latch_attempt = hit_test_and_latch_wheel_gesture(position, delta.scaled(1.0f / m_scene.visual_viewport_magnification()), event.wheel_delta_precision, event.scroll_gesture_phase, {}, Compositing::WheelStepDispatch::NotYetDispatched, nested_context_regions);latched_node_id = latch_attempt.latched_node_id;routing_decision = latch_attempt.decision;}@@ -1664,9 +1669,9 @@ Optional<Compositing::NestedContextWheelHit> ContextState::nested_context_for_whreturn m_async_scroll_tree.nested_context_for_wheel_at(m_scene.visual_context_tree_for_compositing(), position);}-void ContextState::latch_wheel_gesture_to_nested_context(Web::CompositorContextId nested_context_id, Optional<Web::AsyncScrollNodeStableID> scroller, Web::MouseEvent const& event, MonotonicTime now)+void ContextState::latch_wheel_gesture_to_nested_context(Web::CompositorContextId nested_context_id, Optional<Web::AsyncScrollNodeStableID> scroller, Web::MouseEvent const& event){- m_wheel_gesture_routing.latch_to_nested_context(nested_context_id, scroller, wheel_event_position(event), event.scroll_gesture_phase, event.modifiers, now);+ m_wheel_gesture_routing.latch_to_nested_context(nested_context_id, scroller, event.scroll_gesture_phase);}ContextState::WheelStepFromContainingContext ContextState::WheelStepFromContainingContext::for_wheel_event(Web::MouseEvent const& event)@@ -1727,12 +1732,12 @@ ContextState::ContextUpdateResult ContextState::take_first_wheel_step_from_contaVERIFY(first_is_one_of(route.kind, FirstWheelStepRoute::Kind::ScrollNode, FirstWheelStepRoute::Kind::Kept));if (route.kind == FirstWheelStepRoute::Kind::Kept) {if (route.scroller.has_value())- m_wheel_gesture_routing.latch(*route.scroller, step.position, step.scroll_gesture_phase, step.modifiers, now);+ m_wheel_gesture_routing.latch(*route.scroller, step.scroll_gesture_phase);else- m_wheel_gesture_routing.latch_keeping_steps(step.position, step.scroll_gesture_phase, step.modifiers, now);+ m_wheel_gesture_routing.latch_keeping_steps(step.scroll_gesture_phase);return { .accepted = true, .routing_decision = route.decision, .routed_scroller = route.scroller };}- m_wheel_gesture_routing.latch(*route.scroller, step.position, step.scroll_gesture_phase, step.modifiers, now);+ m_wheel_gesture_routing.latch(*route.scroller, step.scroll_gesture_phase);return take_wheel_step_from_containing_context(*route.node_id, route.decision, step, Compositing::ScrollChaining::ToScrollableAncestors, now);}@@ -1745,7 +1750,7 @@ ContextState::ContextUpdateResult ContextState::take_latched_wheel_step_from_conif (first_is_one_of(admission, Compositing::WheelRoutingAdmission::BlockingWheelEventListeners, Compositing::WheelRoutingAdmission::StaleWheelEventListeners))return ContextUpdateResult::declined(Compositing::input_routing_decision_for_wheel_step_not_admitted_by(admission));- auto latch = m_wheel_gesture_routing.resolve_latch_continued_by_containing_context(m_async_scroll_tree, m_scene.current_visual_context_tree(), step.scroll_gesture_phase, now);+ auto latch = m_wheel_gesture_routing.resolve_latch(m_async_scroll_tree, m_scene.current_visual_context_tree(), step.scroll_gesture_phase);if (latch.keeps_steps)return { .accepted = true, .routing_decision = Web::InputRoutingDecision::ScrollKeptByOverscrollBehavior };if (!latch.node_id.has_value())@@ -2140,15 +2145,15 @@ void ContextState::store_pending_async_scroll_offsets(m_async_scroll_update_outbox.complete_operation(*operation_id);}-WheelGestureRouting::ResolvedLatch ContextState::resolve_wheel_scroll_latch(Gfx::FloatPoint position, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, MonotonicTime now)+WheelGestureRouting::ResolvedLatch ContextState::resolve_wheel_scroll_latch(Web::ScrollGesturePhase scroll_gesture_phase){// Only a hit test takes a latch, and it needs the tree of an installed display list.if (!m_wheel_gesture_routing.has_latch())return {};- return m_wheel_gesture_routing.resolve_latch(m_async_scroll_tree, m_scene.current_visual_context_tree(), position, scroll_gesture_phase, modifiers, now);+ return m_wheel_gesture_routing.resolve_latch(m_async_scroll_tree, m_scene.current_visual_context_tree(), scroll_gesture_phase);}-ContextState::WheelGestureLatchAttempt ContextState::hit_test_and_latch_wheel_gesture(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, MonotonicTime now, Optional<Web::UniqueNodeID> expected_document_id, Compositing::WheelStepDispatch wheel_step_dispatch, Compositing::NestedContextRegions nested_context_regions)+ContextState::WheelGestureLatchAttempt ContextState::hit_test_and_latch_wheel_gesture(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, Optional<Web::UniqueNodeID> expected_document_id, Compositing::WheelStepDispatch wheel_step_dispatch, Compositing::NestedContextRegions nested_context_regions){Function<Optional<Gfx::FloatPoint>(Web::AsyncScrollNodeStableID)> in_flight_destination_for;if (wheel_delta_precision == Web::WheelDeltaPrecision::Discrete)@@ -2174,7 +2179,7 @@ ContextState::WheelGestureLatchAttempt ContextState::hit_test_and_latch_wheel_gereturn { Web::InputRoutingDecision::ScrollerInOtherDocument };auto const* node = m_async_scroll_tree.scroll_node_for_id(*node_id_to_latch);VERIFY(node);- m_wheel_gesture_routing.latch(node->stable_node_id, position, scroll_gesture_phase, modifiers, now);+ m_wheel_gesture_routing.latch(node->stable_node_id, scroll_gesture_phase);return { decision, node_id_to_latch };}diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.hindex 3ebf6c8ca1e..d4f195ea39b 100644--- a/Services/Compositor/ContextState.h+++ b/Services/Compositor/ContextState.h@@ -165,13 +165,13 @@ public:ContextUpdateResult handle_wheel_event(Web::MouseEvent const&, Optional<MonotonicTime> now_for_testing = {});// 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.- void note_wheel_event_from_ui(Web::MouseEvent const&, Optional<MonotonicTime> now_for_testing = {});+ Web::WheelGestureMark note_wheel_event_from_ui(Web::MouseEvent const&, Optional<MonotonicTime> now_for_testing = {});ContextUpdateResult handle_pinch_event(Web::PinchEvent const&);bool may_hand_first_wheel_steps_to_nested_contexts() const;Optional<Compositing::NestedContextWheelHit> nested_context_for_wheel_at(Gfx::FloatPoint position);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&, 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(); }FirstWheelStepRoute route_first_wheel_step_from_containing_context(Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels, Web::WheelDeltaPrecision, Compositing::NestedContextRegions);@@ -319,13 +319,13 @@ private:Optional<Gfx::FloatPoint> delta_the_node_did_not_scroll_by;};NodeScrollByWheelDelta scroll_node_by_wheel_delta(Compositing::AsyncScrollNodeID, Gfx::FloatPoint delta, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, Compositing::AsyncScrollOperationTracking, Gfx::IntRect viewport_rect, MonotonicTime now, Compositing::ScrollChaining);- WheelGestureRouting::ResolvedLatch resolve_wheel_scroll_latch(Gfx::FloatPoint position, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now);+ WheelGestureRouting::ResolvedLatch resolve_wheel_scroll_latch(Web::ScrollGesturePhase);struct WheelGestureLatchAttempt {Web::InputRoutingDecision decision;Optional<Compositing::AsyncScrollNodeID> latched_node_id {};};// The scroller the first step of a wheel gesture is routed to, which the gesture is latched to.- WheelGestureLatchAttempt hit_test_and_latch_wheel_gesture(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now, Optional<Web::UniqueNodeID> expected_document_id, Compositing::WheelStepDispatch, Compositing::NestedContextRegions);+ WheelGestureLatchAttempt hit_test_and_latch_wheel_gesture(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, Optional<Web::UniqueNodeID> expected_document_id, Compositing::WheelStepDispatch, Compositing::NestedContextRegions);ContextUpdateResult take_wheel_step_from_containing_context(Compositing::AsyncScrollNodeID, Web::InputRoutingDecision, WheelStepFromContainingContext const&, Compositing::ScrollChaining, MonotonicTime now);Gfx::IntRect note_async_scrolling_viewport_rect(Gfx::IntRect viewport_rect, Optional<Compositing::AsyncScrollOffset> const&);Optional<Compositing::AsyncScrollOperationID> snap_at_gesture_end(MonotonicTime now);diff --git a/Services/Compositor/WheelGestureRouting.cpp b/Services/Compositor/WheelGestureRouting.cppindex ebafe412361..ca311478e41 100644--- a/Services/Compositor/WheelGestureRouting.cpp+++ b/Services/Compositor/WheelGestureRouting.cpp@@ -44,26 +44,31 @@ bool WheelGestureRouting::only_blocking_wheel_event_listeners_hold_steps_back()bool WheelGestureRouting::note_wheel_event_from_ui(Web::MouseEvent const& event, Gfx::FloatPoint position, Compositing::AsyncScrollTree const& async_scroll_tree, MonotonicTime now){- auto phase = event.scroll_gesture_phase;- if (event.id != 0) {+ 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) {if (phase == Web::ScrollGesturePhase::Ongoing)- m_newest_wheel_event_ids_from_ui.ongoing = event.id;+ m_newest_wheel_event_ids_from_ui.ongoing = input_event_id;else if (phase == Web::ScrollGesturePhase::Momentum)- m_newest_wheel_event_ids_from_ui.momentum = event.id;+ m_newest_wheel_event_ids_from_ui.momentum = input_event_id;else if (phase == Web::ScrollGesturePhase::Ended)- m_newest_wheel_event_ids_from_ui.ended = event.id;+ m_newest_wheel_event_ids_from_ui.ended = input_event_id;}- bool starts_gesture = !m_gesture_from_ui.has_value() || !m_gesture_from_ui->is_continued_by(position, phase, event.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));if (starts_gesture) {- m_gesture_from_ui = Compositing::WheelGestureIdentity::started_by(position, phase, event.modifiers, now);- m_gesture_from_ui_had_wheel_event_with_delta = false;+ m_gesture = Compositing::WheelGestureIdentity::started_by(position, phase, modifiers, now);+ m_gesture_had_wheel_event_with_delta = false;+ m_latch.clear();} else {- m_gesture_from_ui->advance_to(phase, now);+ m_gesture->advance_to(phase, now);}- if (!m_gesture_from_ui_had_wheel_event_with_delta && (event.wheel_delta_x != 0 || event.wheel_delta_y != 0)) {- m_gesture_from_ui_had_wheel_event_with_delta = true;- m_id_of_first_wheel_event_from_ui_with_delta = event.id;+ if (!m_gesture_had_wheel_event_with_delta && !wheel_delta.is_zero()) {+ m_gesture_had_wheel_event_with_delta = true;+ m_id_of_first_wheel_event_with_delta = input_event_id;}return starts_gesture;}@@ -87,23 +92,12 @@ bool WheelGestureRouting::step_was_overtaken_by_ui(Web::ScrollGesturePhase phaseVERIFY_NOT_REACHED();}-WheelGestureRouting::ResolvedLatch WheelGestureRouting::resolve_latch(Compositing::AsyncScrollTree const& async_scroll_tree, Compositing::AccumulatedVisualContextTree const& current_visual_context_tree, Gfx::FloatPoint position, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, MonotonicTime now)-{- if (!m_latch.has_value())- return {};- if (!m_latch->gesture.is_continued_by(position, scroll_gesture_phase, modifiers, now, position_slop_in_device_pixels(async_scroll_tree))) {- m_latch.clear();- return {};- }- return resolve_latch_continued_by_containing_context(async_scroll_tree, current_visual_context_tree, scroll_gesture_phase, now);-}--WheelGestureRouting::ResolvedLatch WheelGestureRouting::resolve_latch_continued_by_containing_context(Compositing::AsyncScrollTree const& async_scroll_tree, Compositing::AccumulatedVisualContextTree const& current_visual_context_tree, Web::ScrollGesturePhase scroll_gesture_phase, MonotonicTime now)+WheelGestureRouting::ResolvedLatch WheelGestureRouting::resolve_latch(Compositing::AsyncScrollTree const& async_scroll_tree, Compositing::AccumulatedVisualContextTree const& current_visual_context_tree, Web::ScrollGesturePhase scroll_gesture_phase){if (!m_latch.has_value())return {};if (m_latch->nested_context_id.has_value() || !m_latch->stable_node_id.has_value()) {- m_latch->gesture.advance_to(scroll_gesture_phase, now);+ m_latch->last_scroll_gesture_phase = scroll_gesture_phase;return { .nested_context_id = m_latch->nested_context_id, .keeps_steps = !m_latch->nested_context_id.has_value() };}auto node_id = async_scroll_tree.scroll_node_id_for_stable_id(*m_latch->stable_node_id);@@ -114,7 +108,7 @@ WheelGestureRouting::ResolvedLatch WheelGestureRouting::resolve_latch_continued_// The hit test a latched step skips would refuse a tree the wheel hit-test targets were not built for.if (!async_scroll_tree.has_wheel_hit_test_targets_for(current_visual_context_tree))return {};- m_latch->gesture.advance_to(scroll_gesture_phase, now);+ m_latch->last_scroll_gesture_phase = scroll_gesture_phase;return { .node_id = node_id };}@@ -125,28 +119,28 @@ Optional<Web::AsyncScrollNodeStableID> WheelGestureRouting::latched_scroller() creturn m_latch->stable_node_id;}-void WheelGestureRouting::latch(Web::AsyncScrollNodeStableID stable_node_id, Gfx::FloatPoint position, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, MonotonicTime now)+void WheelGestureRouting::latch(Web::AsyncScrollNodeStableID stable_node_id, Web::ScrollGesturePhase scroll_gesture_phase){m_latch = Latch {.stable_node_id = stable_node_id,- .gesture = Compositing::WheelGestureIdentity::started_by(position, scroll_gesture_phase, modifiers, now),+ .last_scroll_gesture_phase = scroll_gesture_phase,};}-void WheelGestureRouting::latch_to_nested_context(Web::CompositorContextId nested_context_id, Optional<Web::AsyncScrollNodeStableID> scroller, Gfx::FloatPoint position, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, MonotonicTime now)+void WheelGestureRouting::latch_to_nested_context(Web::CompositorContextId nested_context_id, Optional<Web::AsyncScrollNodeStableID> scroller, Web::ScrollGesturePhase scroll_gesture_phase){m_latch = Latch {.stable_node_id = scroller,- .gesture = Compositing::WheelGestureIdentity::started_by(position, scroll_gesture_phase, modifiers, now),+ .last_scroll_gesture_phase = scroll_gesture_phase,.nested_context_id = nested_context_id,};}-void WheelGestureRouting::latch_keeping_steps(Gfx::FloatPoint position, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, MonotonicTime now)+void WheelGestureRouting::latch_keeping_steps(Web::ScrollGesturePhase scroll_gesture_phase){m_latch = Latch {.stable_node_id = {},- .gesture = Compositing::WheelGestureIdentity::started_by(position, scroll_gesture_phase, modifiers, now),+ .last_scroll_gesture_phase = scroll_gesture_phase,};}diff --git a/Services/Compositor/WheelGestureRouting.h b/Services/Compositor/WheelGestureRouting.hindex 2bb26411a29..3c6c6b51fce 100644--- a/Services/Compositor/WheelGestureRouting.h+++ b/Services/Compositor/WheelGestureRouting.h@@ -32,11 +32,13 @@ 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 the UI was sending.+ // 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);// 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_from_ui_with_delta(u64 input_event_id) const { return input_event_id != 0 && input_event_id == m_id_of_first_wheel_event_from_ui_with_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;@@ -51,14 +53,12 @@ public:Optional<Web::CompositorContextId> nested_context_id {};bool keeps_steps { false };};- // The latch of the gesture the wheel event continues, with the gesture advanced to the event. A latch the event- // does not continue, or whose scroller the current display list no longer has, is dropped here.- ResolvedLatch resolve_latch(Compositing::AsyncScrollTree const&, Compositing::AccumulatedVisualContextTree const& current_visual_context_tree, Gfx::FloatPoint position, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now);- // The same for a step that the containing context hands in, which has decided that the step continues the gesture.- ResolvedLatch resolve_latch_continued_by_containing_context(Compositing::AsyncScrollTree const&, Compositing::AccumulatedVisualContextTree const& current_visual_context_tree, Web::ScrollGesturePhase, MonotonicTime now);- void latch(Web::AsyncScrollNodeStableID, Gfx::FloatPoint position, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now);- void latch_to_nested_context(Web::CompositorContextId, Optional<Web::AsyncScrollNodeStableID> scroller, Gfx::FloatPoint position, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now);- void latch_keeping_steps(Gfx::FloatPoint position, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now);+ // The latch of the gesture a step continues, advanced to the step's phase. A latch whose scroller the current+ // display list no longer has is dropped here; one the step does not continue was let go of as the step was noted.+ ResolvedLatch resolve_latch(Compositing::AsyncScrollTree const&, Compositing::AccumulatedVisualContextTree const& current_visual_context_tree, Web::ScrollGesturePhase);+ void latch(Web::AsyncScrollNodeStableID, Web::ScrollGesturePhase);+ 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 relatch_to(Web::AsyncScrollNodeStableID);void note_page_let_latched_gesture_through();@@ -72,7 +72,8 @@ private:struct Latch {// Empty for a latch that keeps the steps without a scroller.Optional<Web::AsyncScrollNodeStableID> stable_node_id;- Compositing::WheelGestureIdentity gesture;+ // The phase of the last step that reached the latch, which says whether the fingers of its gesture are down.+ Web::ScrollGesturePhase last_scroll_gesture_phase { Web::ScrollGesturePhase::None };Optional<Web::CompositorContextId> nested_context_id {};// The momentum of the gesture has gone into a rebound of the scroller. Momentum outlasts that rebound, and the// rest of it must not start another one.@@ -92,11 +93,12 @@ private:Compositing::WheelRoutingAdmission m_admission { Compositing::WheelRoutingAdmission::NoAsyncScrollingState };bool m_has_blocking_wheel_event_listeners { false };u64 m_wheel_event_listener_state_generation { 0 };- // The touchpad gesture the UI is sending, whether this context or the main thread scrolls its steps.- Optional<Compositing::WheelGestureIdentity> m_gesture_from_ui;+ // The gesture of the wheel events this context sees first: the UI's, or ones the UI never sent that the main+ // thread makes. It says which gesture a step is in, whether this context or the main thread scrolls the step.+ Optional<Compositing::WheelGestureIdentity> m_gesture;NewestWheelEventIdsFromUI m_newest_wheel_event_ids_from_ui;- u64 m_id_of_first_wheel_event_from_ui_with_delta { 0 };- bool m_gesture_from_ui_had_wheel_event_with_delta { false };+ u64 m_id_of_first_wheel_event_with_delta { 0 };+ bool m_gesture_had_wheel_event_with_delta { false };Optional<Latch> m_latch;};diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cppindex e29bc090f45..28942f95a12 100644--- a/Services/WebContent/ConnectionFromClient.cpp+++ b/Services/WebContent/ConnectionFromClient.cpp@@ -910,7 +910,8 @@ void ConnectionFromClient::enqueue_mouse_event(Web::PageId page_id, Optional<Webif (event.type == Web::MouseEvent::Type::MouseWheel&& (mouse_event->async_scroll_performed_default_action != event.async_scroll_performed_default_action|| mouse_event->wheel_delta_precision != event.wheel_delta_precision- || mouse_event->scroll_gesture_phase != event.scroll_gesture_phase))+ || mouse_event->scroll_gesture_phase != event.scroll_gesture_phase+ || mouse_event->wheel_gesture_mark != event.wheel_gesture_mark))return nullptr;return mouse_event;}diff --git a/Tests/LibWeb/Text/expected/async-scrolling/wheel-latch-new-gesture-queued-behind-a-busy-page.txt b/Tests/LibWeb/Text/expected/async-scrolling/wheel-latch-new-gesture-queued-behind-a-busy-page.txtnew file mode 100644index 00000000000..d0e703742b5--- /dev/null+++ b/Tests/LibWeb/Text/expected/async-scrolling/wheel-latch-new-gesture-queued-behind-a-busy-page.txt@@ -0,0 +1,2 @@+first.scrollTop: 30+second.scrollTop: 60diff --git a/Tests/LibWeb/Text/input/async-scrolling/wheel-latch-new-gesture-queued-behind-a-busy-page.html b/Tests/LibWeb/Text/input/async-scrolling/wheel-latch-new-gesture-queued-behind-a-busy-page.htmlnew file mode 100644index 00000000000..a5d5cfe7ccf--- /dev/null+++ b/Tests/LibWeb/Text/input/async-scrolling/wheel-latch-new-gesture-queued-behind-a-busy-page.html@@ -0,0 +1,45 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ body {+ margin: 0;+ }+ .scroller {+ width: 100px;+ height: 100px;+ overflow: scroll;+ }+ .scroller > div {+ height: 1000px;+ }+ #second {+ margin-top: 100px;+ }+</style>+<div id="first" class="scroller"><div></div></div>+<div id="second" class="scroller"><div></div></div>+<script>+ promiseTest(async () => {+ // A listener that may cancel the wheel leaves the scrolling to the main thread, which follows its latch.+ window.addEventListener("wheel", () => {}, { passive: false });+ await animationFrame();+ await animationFrame();++ await internals.wheelThroughUIProcess(50, 50, 0, 30, true);++ // The first two ticks of a gesture over the other scroller arrive together while the page is busy, and must+ // not be taken for ticks of the gesture before them.+ const ticks = Promise.all([+ internals.wheelThroughUIProcess(50, 250, 0, 30, true),+ internals.wheelThroughUIProcess(50, 250, 0, 30, true),+ ]);+ const busyUntil = performance.now() + 100;+ while (performance.now() < busyUntil) { }+ await ticks;+ await animationFrame();+ await animationFrame();++ println(`first.scrollTop: ${first.scrollTop}`);+ println(`second.scrollTop: ${second.scrollTop}`);+ });+</script>