Truly independent web browser
Compositor: Order wheel steps by numbers the compositor gives them
Jelle Raaijmakersf35ed1117e29
diff --git a/Libraries/LibCompositing/Types.cpp b/Libraries/LibCompositing/Types.cppindex c1b8af8ad5c..09a31cf1f6a 100644--- a/Libraries/LibCompositing/Types.cpp+++ b/Libraries/LibCompositing/Types.cpp@@ -296,7 +296,6 @@ template<>ErrorOr<void> encode(Encoder& encoder, Compositing::WheelStepLetThrough const& step){TRY(encoder.encode(step.document_id));- TRY(encoder.encode(step.input_event_id));TRY(encoder.encode(step.wheel_gesture_mark));TRY(encoder.encode(step.position));TRY(encoder.encode(step.delta_in_css_pixels));@@ -311,7 +310,6 @@ ErrorOr<Compositing::WheelStepLetThrough> decode(Decoder& decoder){return Compositing::WheelStepLetThrough {.document_id = TRY(decoder.decode<Web::UniqueNodeID>()),- .input_event_id = TRY(decoder.decode<u64>()),.wheel_gesture_mark = TRY(decoder.decode<Web::WheelGestureMark>()),.position = TRY(decoder.decode<Gfx::FloatPoint>()),.delta_in_css_pixels = TRY(decoder.decode<Gfx::FloatPoint>()),diff --git a/Libraries/LibCompositing/Types.h b/Libraries/LibCompositing/Types.hindex f8fe2740d49..66a2f55de29 100644--- a/Libraries/LibCompositing/Types.h+++ b/Libraries/LibCompositing/Types.h@@ -140,7 +140,6 @@ enum class WheelEventRouting : u8 {// A step of a wheel gesture that WebContent's page dispatched and did not cancel, which the compositor scrolls by.struct WheelStepLetThrough {Web::UniqueNodeID document_id;- u64 input_event_id { 0 };Web::WheelGestureMark wheel_gesture_mark;// In the device pixels of the viewport of the context the step is let through in.Gfx::FloatPoint position;diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cppindex f089a9c70fd..7f4c0369388 100644--- a/Libraries/LibWeb/Page/EventHandler.cpp+++ b/Libraries/LibWeb/Page/EventHandler.cpp@@ -1032,7 +1032,6 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi.wheel_tick_120ths_y = wheel_tick_120ths_y,.wheel_delta_precision = wheel_delta_precision,.scroll_gesture_phase = scroll_gesture_phase,- .id = handling_input_event_id(),};auto routing = display_list_is_outdated ? Compositing::WheelEventRouting::AfterDispatch : Compositing::WheelEventRouting::BeforeDispatch;auto answer = m_navigable->compositor_context().take_wheel_event_from_main_thread(event, operation_tracking, routing);@@ -1205,7 +1204,6 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positiauto device_position = m_navigable->page().css_to_device_point(visual_viewport_position);Compositing::WheelStepLetThrough step {.document_id = document->unique_id(),- .input_event_id = handling_input_event_id(),.wheel_gesture_mark = *wheel_gesture_mark,.position = { static_cast<float>(device_position.x().value()), static_cast<float>(device_position.y().value()) },.delta_in_css_pixels = { static_cast<float>(wheel_delta_x), static_cast<float>(wheel_delta_y) },diff --git a/Libraries/LibWebCommon/Page/InputEvent.h b/Libraries/LibWebCommon/Page/InputEvent.hindex 17393a3d8a7..fe015a96f12 100644--- a/Libraries/LibWebCommon/Page/InputEvent.h+++ b/Libraries/LibWebCommon/Page/InputEvent.h@@ -150,8 +150,7 @@ struct WheelGestureMark {// 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;+ u64 step_number { 0 };};struct WEBCOMMON_API MouseEvent {diff --git a/Libraries/LibWebCommon/Page/InputEvent.ipc b/Libraries/LibWebCommon/Page/InputEvent.ipcindex 7a27bf51fbe..b5c8d83b5e8 100644--- a/Libraries/LibWebCommon/Page/InputEvent.ipc+++ b/Libraries/LibWebCommon/Page/InputEvent.ipc@@ -39,6 +39,7 @@ enum Web::ScrollGesturePhase : u8 {struct Web::WheelGestureMark {u64 gesture_id;bool lasts_until_fingers_lift;+ u64 step_number;}[ExistingCpp]diff --git a/Libraries/LibWebCommon/Page/InputRoutingDecision.h b/Libraries/LibWebCommon/Page/InputRoutingDecision.hindex 35843dbd121..e2ca5d2bbc9 100644--- a/Libraries/LibWebCommon/Page/InputRoutingDecision.h+++ b/Libraries/LibWebCommon/Page/InputRoutingDecision.h@@ -19,7 +19,7 @@ namespace Web {X(BlockingWheelEventListeners, "blocking-wheel-event-listeners") \X(NoScrollNode, "no-scroll-node") \X(StaleWheelEventListeners, "stale-wheel-event-listeners") \- X(StepOvertakenByUI, "step-overtaken-by-ui") \+ X(StepOvertaken, "step-overtaken") \X(GestureEndWithNothingToSnap, "gesture-end-with-nothing-to-snap") \X(SnappedAtGestureEnd, "snapped-at-gesture-end") \X(HitTestTargetsOfAnotherVisualContextTree, "hit-test-targets-of-another-visual-context-tree") \diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cppindex 1326781d385..29239b6459c 100644--- a/Services/Compositor/CompositorState.cpp+++ b/Services/Compositor/CompositorState.cpp@@ -1248,8 +1248,8 @@ Compositing::WheelEventAnswer CompositorState::scroll_for_wheel_event_the_page_l// A step of a gesture that the contexts around the page have moved past still scrolls, as the page let it.auto routing_context_id = routing_context_of_wheel_gesture(listener_context_id, gesture_id);auto* routing_context = routing_context_id.has_value() ? context_if_present(*routing_context_id) : nullptr;- if (!routing_context || routing_context->wheel_step_was_overtaken_by_ui(step.scroll_gesture_phase, let_through.input_event_id)) {- auto result = listener_context->scroll_for_wheel_step_overtaken_by_ui(step, scroll_chain, now);+ if (!routing_context || routing_context->wheel_step_was_overtaken(step.scroll_gesture_phase, let_through.wheel_gesture_mark.step_number)) {+ auto result = listener_context->scroll_for_overtaken_wheel_step(step, scroll_chain, now);return answer(apply_wheel_step_result(listener_context_id, *listener_context, result, page_client));}diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cppindex 88ddc42b4de..5b8ba52d8db 100644--- a/Services/Compositor/ContextState.cpp+++ b/Services/Compositor/ContextState.cpp@@ -1441,6 +1441,7 @@ ContextState::NotedWheelEvent ContextState::note_wheel_event(Web::MouseEvent con.wheel_gesture_mark = {.gesture_id = m_wheel_gesture_routing.gesture_id().value(),.lasts_until_fingers_lift = m_wheel_gesture_routing.gesture_lasts_until_fingers_lift(),+ .step_number = noted.step_number,},.is_first_wheel_event_with_delta = noted.is_first_wheel_event_with_delta,};@@ -1601,16 +1602,16 @@ Optional<ContextState::ContextUpdateResult> ContextState::scroll_for_latched_whereturn scroll_for_wheel_step_in_this_context(step, latch.scroll_node_index, Compositing::NestedContextRegions::Ignore, WheelStepAdmission::LetThroughByThePage, {}, now);}-ContextState::ContextUpdateResult ContextState::scroll_for_wheel_step_overtaken_by_ui(WheelStep const& step, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain, MonotonicTime now)+ContextState::ContextUpdateResult ContextState::scroll_for_overtaken_wheel_step(WheelStep const& step, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain, MonotonicTime now){if (!m_has_async_scrolling_state)return ContextUpdateResult::declined(Web::InputRoutingDecision::NoAsyncScrollingState);auto delta = step.delta_in_css_pixels.scaled(static_cast<float>(m_async_scroll_tree.device_pixels_per_css_pixel()));if (delta.is_zero())- return ContextUpdateResult::declined(Web::InputRoutingDecision::StepOvertakenByUI);+ return ContextUpdateResult::declined(Web::InputRoutingDecision::StepOvertaken);auto scroll_target = route_first_wheel_step(step.position, delta, step.wheel_delta_precision, Compositing::WheelStepDispatch::DispatchedAndNotCanceled, Compositing::NestedContextRegions::Ignore, scroll_chain);if (!scroll_target.scroll_node_index.has_value())- return ContextUpdateResult::declined(Web::InputRoutingDecision::StepOvertakenByUI);+ return ContextUpdateResult::declined(Web::InputRoutingDecision::StepOvertaken);m_scroll_snap_controller.note_gesture_phase(step.scroll_gesture_phase);auto node_scroll = scroll_node_by_wheel_delta(*scroll_target.scroll_node_index, delta, step.wheel_delta_precision, step.scroll_gesture_phase, step.operation_tracking, m_async_scrolling_viewport_rect, now, Compositing::ScrollChaining::ToScrollableAncestors);@@ -1619,7 +1620,7 @@ ContextState::ContextUpdateResult ContextState::scroll_for_wheel_step_overtaken_.accepted = true,.frame_to_present = outcome.viewport_rect_to_present.map([](auto const& rect) { return PendingFrame::repainting_changes(rect); }),.should_request_rendering_update = outcome.viewport_rect_to_present.has_value(),- .routing_decision = Web::InputRoutingDecision::StepOvertakenByUI,+ .routing_decision = Web::InputRoutingDecision::StepOvertaken,.tracked_scroll_operation = tracked_scroll_operation(step.operation_tracking, outcome.operation_id),};}diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.hindex 2098fd15f11..c062b712682 100644--- a/Services/Compositor/ContextState.h+++ b/Services/Compositor/ContextState.h@@ -227,7 +227,7 @@ public:// Routes the event like one from the UI, also in a context that is nested in another one.ContextUpdateResult scroll_for_wheel_event_from_main_thread(Web::MouseEvent const&, bool is_first_wheel_event_with_delta, WheelEventListenerGate const&, Compositing::AsyncScrollOperationTracking, MonotonicTime now);Optional<u64> wheel_gesture_id() const { return m_wheel_gesture_routing.gesture_id(); }- bool wheel_step_was_overtaken_by_ui(Web::ScrollGesturePhase phase, u64 input_event_id) const { return m_wheel_gesture_routing.step_was_overtaken_by_ui(phase, input_event_id); }+ bool wheel_step_was_overtaken(Web::ScrollGesturePhase phase, u64 step_number) const { return m_wheel_gesture_routing.step_was_overtaken(phase, step_number); }Optional<Web::CompositorContextId> wheel_event_listener_context() const { return m_wheel_gesture_routing.wheel_event_listener_context(); }void set_wheel_event_listener_context(Web::CompositorContextId context_id) { m_wheel_gesture_routing.set_wheel_event_listener_context(context_id); }WheelEventListenerGate wheel_event_listener_gate(Optional<u64> gesture_id) const;@@ -268,7 +268,7 @@ public:Optional<ContextUpdateResult> scroll_for_latched_wheel_step_the_page_let_through(WheelStep const&, MonotonicTime now);// A step of a gesture that this context has moved past scrolls once along its route, latching and stretching// nothing.- ContextUpdateResult scroll_for_wheel_step_overtaken_by_ui(WheelStep const&, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain, MonotonicTime now);+ ContextUpdateResult scroll_for_overtaken_wheel_step(WheelStep const&, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain, MonotonicTime now);Optional<Web::UniqueNodeID> document_id() const { return m_async_scroll_tree.document_id(); }Optional<PendingFrame> apply_scroll_requests(ReadonlySpan<Compositing::ScrollRequest>);void cancel_smooth_scroll(Web::AsyncScrollNodeStableID);diff --git a/Services/Compositor/WheelGestureRouting.cpp b/Services/Compositor/WheelGestureRouting.cppindex e9fd4164a42..b0f6e6d592b 100644--- a/Services/Compositor/WheelGestureRouting.cpp+++ b/Services/Compositor/WheelGestureRouting.cpp@@ -17,6 +17,14 @@ static u64 allocate_wheel_gesture_id()return ++last_wheel_gesture_id;}+// Every wheel step a context notes gets the next number, whether the UI sent it or the main thread made it, so the+// numbers order all of them as the compositor first saw them.+static u64 allocate_wheel_step_number()+{+ static u64 last_wheel_step_number = 0;+ return ++last_wheel_step_number;+}+static float position_slop_in_device_pixels(Compositing::AsyncScrollTree const& async_scroll_tree){return Compositing::wheel_gesture_position_slop_in_css_pixels * static_cast<float>(async_scroll_tree.device_pixels_per_css_pixel());@@ -46,14 +54,13 @@ bool WheelGestureRouting::admits_async_pinch() constWheelGestureRouting::NotedWheelEvent WheelGestureRouting::note_wheel_event(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) {- if (phase == Web::ScrollGesturePhase::Ongoing)- m_newest_wheel_event_ids_from_ui.ongoing = event.id;- else if (phase == Web::ScrollGesturePhase::Momentum)- m_newest_wheel_event_ids_from_ui.momentum = event.id;- else if (phase == Web::ScrollGesturePhase::Ended)- m_newest_wheel_event_ids_from_ui.ended = event.id;- }+ auto step_number = allocate_wheel_step_number();+ if (phase == Web::ScrollGesturePhase::Ongoing)+ m_newest_step_numbers.ongoing = step_number;+ else if (phase == Web::ScrollGesturePhase::Momentum)+ m_newest_step_numbers.momentum = step_number;+ else if (phase == Web::ScrollGesturePhase::Ended)+ m_newest_step_numbers.ended = step_number;bool starts_gesture = !m_gesture.has_value() || !m_gesture->identity.is_continued_by(position, phase, event.modifiers, now, position_slop_in_device_pixels(async_scroll_tree), m_touchpad_gesture_end);if (starts_gesture) {@@ -69,7 +76,7 @@ WheelGestureRouting::NotedWheelEvent WheelGestureRouting::note_wheel_event(Web::bool is_first_wheel_event_with_delta = !m_gesture_had_wheel_event_with_delta && (event.wheel_delta_x != 0 || event.wheel_delta_y != 0);if (is_first_wheel_event_with_delta)m_gesture_had_wheel_event_with_delta = true;- return { .starts_gesture = starts_gesture, .is_first_wheel_event_with_delta = is_first_wheel_event_with_delta };+ return { .starts_gesture = starts_gesture, .is_first_wheel_event_with_delta = is_first_wheel_event_with_delta, .step_number = step_number };}Optional<u64> WheelGestureRouting::gesture_id() const@@ -119,21 +126,23 @@ void WheelGestureRouting::forget_gesture()m_latch.clear();}-bool WheelGestureRouting::step_was_overtaken_by_ui(Web::ScrollGesturePhase phase, u64 input_event_id) const+// Whether this context noted a later wheel step 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 WheelGestureRouting::step_was_overtaken(Web::ScrollGesturePhase phase, u64 step_number) const{- auto const& newest = m_newest_wheel_event_ids_from_ui;+ auto const& newest = m_newest_step_numbers;switch (phase) {case Web::ScrollGesturePhase::None:return false;case Web::ScrollGesturePhase::Ongoing:// The fingers lifted after this step.- return newest.momentum > input_event_id || newest.ended > input_event_id;+ return newest.momentum > step_number || newest.ended > step_number;case Web::ScrollGesturePhase::Momentum:// The momentum ended, or the fingers touched down again, after this step.- return newest.ended > input_event_id || newest.ongoing > input_event_id;+ return newest.ended > step_number || newest.ongoing > step_number;case Web::ScrollGesturePhase::Ended:// Another gesture started after this end.- return newest.ongoing > input_event_id;+ return newest.ongoing > step_number;}VERIFY_NOT_REACHED();}diff --git a/Services/Compositor/WheelGestureRouting.h b/Services/Compositor/WheelGestureRouting.hindex 2d7bb61087d..df0c08c6145 100644--- a/Services/Compositor/WheelGestureRouting.h+++ b/Services/Compositor/WheelGestureRouting.h@@ -37,6 +37,7 @@ public:// The event is the first step of its gesture that moves anything. A touchpad gesture can start with a step that// has no delta.bool is_first_wheel_event_with_delta { false };+ u64 step_number { 0 };};// 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.@@ -52,9 +53,7 @@ public:// scroll here, and in the contexts nested here, for the gesture.void note_delta_left_to_the_page(Gfx::FloatPoint delta_in_css_pixels);bool take_delta_left_to_the_page(Gfx::FloatPoint delta_in_css_pixels);- // 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;+ bool step_was_overtaken(Web::ScrollGesturePhase, u64 step_number) const;bool has_latch() const { return m_latch.has_value(); }bool has_latch_for_gesture(Optional<u64> gesture_id) const { return m_latch.has_value() && m_latch->gesture_id == gesture_id; }@@ -112,7 +111,7 @@ private:bool momentum_has_sprung_the_scroller_back { false };};- struct NewestWheelEventIdsFromUI {+ struct NewestStepNumbers {u64 ongoing { 0 };u64 momentum { 0 };u64 ended { 0 };@@ -132,7 +131,7 @@ private:// thread makes. It says which gesture a step is in, whether the page lets the step through before or after this// context scrolls by it.Optional<Gesture> m_gesture;- NewestWheelEventIdsFromUI m_newest_wheel_event_ids_from_ui;+ NewestStepNumbers m_newest_step_numbers;bool m_gesture_had_wheel_event_with_delta { false };Optional<Latch> m_latch;// The gesture whose step this context's page dispatched and did not cancel, and the state of the page's wheel eventdiff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cppindex f91741f64a2..302836aa55d 100644--- a/Services/WebContent/ConnectionFromClient.cpp+++ b/Services/WebContent/ConnectionFromClient.cpp@@ -892,6 +892,14 @@ void ConnectionFromClient::mouse_event_in_hosted_root(Web::PageId page_id, Web::enqueue_mouse_event(page_id, navigable_id, move(event));}+// The compositor numbers every wheel step, so only the gesture of the steps decides whether they may become one.+static bool wheel_steps_are_of_one_gesture(Optional<Web::WheelGestureMark> const& first, Optional<Web::WheelGestureMark> const& second)+{+ if (!first.has_value() || !second.has_value())+ return first.has_value() == second.has_value();+ return first->gesture_id == second->gesture_id && first->lasts_until_fingers_lift == second->lasts_until_fingers_lift;+}+void ConnectionFromClient::enqueue_mouse_event(Web::PageId page_id, Optional<Web::HTML::CrossProcessId> navigable_id, Web::MouseEvent event){auto page = m_page_host->page(page_id);@@ -923,7 +931,7 @@ void ConnectionFromClient::enqueue_mouse_event(Web::PageId page_id, Optional<Web&& (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->wheel_gesture_mark != event.wheel_gesture_mark))+ || !wheel_steps_are_of_one_gesture(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-keeps-scroller-after-a-gesture-through-the-ui.txt b/Tests/LibWeb/Text/expected/async-scrolling/wheel-latch-keeps-scroller-after-a-gesture-through-the-ui.txtnew file mode 100644index 00000000000..15644869efd--- /dev/null+++ b/Tests/LibWeb/Text/expected/async-scrolling/wheel-latch-keeps-scroller-after-a-gesture-through-the-ui.txt@@ -0,0 +1,3 @@+window.scrollY after the first step: 200+window.scrollY after the second step: 300+nested.scrollTop after the second step: 0diff --git a/Tests/LibWeb/Text/input/async-scrolling/wheel-latch-keeps-scroller-after-a-gesture-through-the-ui.html b/Tests/LibWeb/Text/input/async-scrolling/wheel-latch-keeps-scroller-after-a-gesture-through-the-ui.htmlnew file mode 100644index 00000000000..1bc3c277074--- /dev/null+++ b/Tests/LibWeb/Text/input/async-scrolling/wheel-latch-keeps-scroller-after-a-gesture-through-the-ui.html@@ -0,0 +1,37 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ body {+ margin: 0;+ height: 3000px;+ }+ #nested {+ position: absolute;+ top: 250px;+ left: 0;+ width: 100px;+ height: 300px;+ overflow: scroll;+ }+ #nested > div {+ height: 800px;+ }+</style>+<div id="nested"><div></div></div>+<script>+ promiseTest(async () => {+ await internals.wheelThroughUIProcess(50, 80, 0, 0, true, "ongoing");+ await internals.wheelThroughUIProcess(50, 80, 0, 0, true, "ended");++ window.addEventListener("wheel", () => {}, { passive: false });+ await animationFrame();+ await animationFrame();++ await internals.wheel(50, 80, 0, 200, true, "ongoing");+ println(`window.scrollY after the first step: ${window.scrollY}`);+ await internals.wheel(50, 80, 0, 100, true, "ongoing");+ println(`window.scrollY after the second step: ${window.scrollY}`);+ println(`nested.scrollTop after the second step: ${nested.scrollTop}`);+ await internals.wheel(50, 80, 0, 0, true, "ended");+ });+</script>