Skip to content

Truly independent web browser

Compositor: Let the first step of a pinch decide for its gesture

Andreas Klinga59aa64530a2
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cpp
index ab0d3b37272..c599ebcbb0d 100644
--- a/Services/Compositor/CompositorState.cpp
+++ b/Services/Compositor/CompositorState.cpp
@@ -1202,10 +1202,12 @@ void CompositorState::handle_and_dispatch_pinch_event(Web::CompositorContextId c
return;
}
- // A page that already let the event through leaves only the zoom to do.
+ // The first step of a gesture decides for the steps after it: a gesture the page let through zooms from here on,
+ // whatever listeners have appeared since. A page that already let this step through leaves only the zoom to do.
Gfx::FloatPoint position { static_cast<float>(event.position.x().value()), static_cast<float>(event.position.y().value()) };
- if (event.wheel_event_was_dispatched || !page_under_pinch_may_cancel_it(context_id, *context, position))
+ if ((event.continues_gesture && context->pinch_gesture_was_let_through()) || event.wheel_event_was_dispatched || !page_under_pinch_may_cancel_it(context_id, *context, position))
event.async_zoom_performed_default_action = apply_context_update_result(context_id, *context, context->handle_pinch_event(event));
+ context->set_pinch_gesture_was_let_through(event.async_zoom_performed_default_action);
// The scroll updates the event produced reach WebContent ahead of the event itself on the same connection.
publish_pending_async_scroll_updates(context_id, *context);
diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cpp
index 877babb7631..107d7ddf25b 100644
--- a/Services/Compositor/ContextState.cpp
+++ b/Services/Compositor/ContextState.cpp
@@ -166,6 +166,10 @@ void ContextState::install_display_list_update(
m_visual_viewport_document_id.clear();
}
+ // NB: What the page of one document let through of a pinch says nothing about the page of the next.
+ if (async_scrolling_state.document_id != m_async_scroll_tree.document_id())
+ m_pinch_gesture_was_let_through = false;
+
auto box_of_dragged_scrollbar = box_of_captured_scrollbar();
m_scrollbar_controller.set_scrollbars(async_scrolling_state.scrollbars);
if (!m_scrollbar_controller.has_captured_scrollbar())
diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.h
index a69899a4bc7..c497d0dcb7e 100644
--- a/Services/Compositor/ContextState.h
+++ b/Services/Compositor/ContextState.h
@@ -246,6 +246,8 @@ public:
bool admits_async_pinch() const { return m_wheel_gesture_routing.admits_async_pinch(); }
// Whether this context's page may cancel the ctrl+wheel event of a pinch at the position, or has yet to tell.
bool page_may_cancel_pinch_at(Gfx::FloatPoint position);
+ bool pinch_gesture_was_let_through() const { return m_pinch_gesture_was_let_through; }
+ void set_pinch_gesture_was_let_through(bool was_let_through) { m_pinch_gesture_was_let_through = was_let_through; }
bool may_hand_first_wheel_steps_to_nested_contexts() const;
Optional<Compositing::NestedContextHit> nested_context_for_wheel_at(Gfx::FloatPoint position);
@@ -487,6 +489,7 @@ private:
bool m_scroll_offsets_differ_from_last_frame { false };
// The document whose visual viewport this context zoomed or panned, which it presents as it left it from then on.
Optional<Web::UniqueNodeID> m_visual_viewport_document_id;
+ bool m_pinch_gesture_was_let_through { false };
KeyboardScrollController m_keyboard_scroll_controller;
// The boxes that the keys held since none was have scrolled, whose gesture lasts until the last of them is released.
Vector<Web::AsyncScrollNodeStableID> m_boxes_scrolled_by_held_keys;
diff --git a/Tests/LibWeb/Text/expected/async-scrolling/pinch-gesture-is-decided-by-its-first-step.txt b/Tests/LibWeb/Text/expected/async-scrolling/pinch-gesture-is-decided-by-its-first-step.txt
index 63e6d413955..df2e62299d8 100644
--- a/Tests/LibWeb/Text/expected/async-scrolling/pinch-gesture-is-decided-by-its-first-step.txt
+++ b/Tests/LibWeb/Text/expected/async-scrolling/pinch-gesture-is-decided-by-its-first-step.txt
@@ -1,7 +1,7 @@
first step, beside the task: compositor scale=1.5
-step after the listener appeared, beside the task: compositor scale=1.5
+step after the listener appeared, beside the task: compositor scale=2.25
listener could cancel an event of that gesture: false
next gesture: cancelable=true
rest of the canceled gesture: cancelable=true
-compositor scale: 1.5
-main thread scale: 1.5
+compositor scale: 2.25
+main thread scale: 2.25