Skip to content

Truly independent web browser

Everywhere: Let the compositor own the pinch zoom

Zaggy10248131be00599d
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp
index c008cb4c5c8..1c48e6a38fc 100644
--- a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp
+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp
@@ -228,6 +228,7 @@ Optional<AsyncScrollOffset> AsyncScrollTree::apply_scroll_delta(AsyncScrollNodeI
.compositor_scroll_offset = scroll_offset_for_node(*node, scroll_state_snapshot),
.unadopted_scroll_delta = delta - remaining_delta,
.last_relative_scroll_delta = {},
+ .visual_viewport_scale = {},
};
}
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h
index cd3e6f60c9f..bef9cf8737d 100644
--- a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h
+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h
@@ -47,10 +47,14 @@ struct AsyncScrollOffset {
// The most recent nonzero delta of a relative scroll in each axis, such as a wheel or panning scroll. Absolute
// scrolls, such as dragging a scrollbar thumb, leave it as it is.
Gfx::FloatPoint last_relative_scroll_delta;
+ // The scale the visual viewport was zoomed to, which only its scroll node reports.
+ Optional<float> visual_viewport_scale;
void merge_later_scroll(AsyncScrollOffset const& later)
{
compositor_scroll_offset = later.compositor_scroll_offset;
+ if (later.visual_viewport_scale.has_value())
+ visual_viewport_scale = later.visual_viewport_scale;
unadopted_scroll_delta.translate_by(later.unadopted_scroll_delta);
if (later.last_relative_scroll_delta.x() != 0)
last_relative_scroll_delta.set_x(later.last_relative_scroll_delta.x());
diff --git a/Libraries/LibCompositing/Types.cpp b/Libraries/LibCompositing/Types.cpp
index c574a71b166..056d678b074 100644
--- a/Libraries/LibCompositing/Types.cpp
+++ b/Libraries/LibCompositing/Types.cpp
@@ -40,6 +40,7 @@ ErrorOr<void> encode(Encoder& encoder, Compositing::AsyncScrollOffset const& off
TRY(encoder.encode(offset.compositor_scroll_offset));
TRY(encoder.encode(offset.unadopted_scroll_delta));
TRY(encoder.encode(offset.last_relative_scroll_delta));
+ TRY(encoder.encode(offset.visual_viewport_scale));
return {};
}
@@ -51,6 +52,7 @@ ErrorOr<Compositing::AsyncScrollOffset> decode(Decoder& decoder)
.compositor_scroll_offset = TRY(decoder.decode<Gfx::FloatPoint>()),
.unadopted_scroll_delta = TRY(decoder.decode<Gfx::FloatPoint>()),
.last_relative_scroll_delta = TRY(decoder.decode<Gfx::FloatPoint>()),
+ .visual_viewport_scale = TRY(decoder.decode<Optional<float>>()),
};
}
diff --git a/Libraries/LibWeb/CSS/VisualViewport.cpp b/Libraries/LibWeb/CSS/VisualViewport.cpp
index 66f569d5a0d..5c61fb48fa5 100644
--- a/Libraries/LibWeb/CSS/VisualViewport.cpp
+++ b/Libraries/LibWeb/CSS/VisualViewport.cpp
@@ -208,6 +208,15 @@ void VisualViewport::zoom(CSSPixelPoint position, double scale_delta)
m_document->set_needs_repaint(Badge<CSS::VisualViewport> {}, InvalidateDisplayList::No);
}
+void VisualViewport::set_scale_zoomed_by_compositor(double scale)
+{
+ if (scale == m_scale)
+ return;
+ m_scale = scale;
+ update_accumulated_visual_context();
+ m_document->set_needs_repaint(Badge<CSS::VisualViewport> {}, InvalidateDisplayList::No);
+}
+
CSSPixelPoint VisualViewport::map_to_layout_viewport(CSSPixelPoint position) const
{
auto inverse = transform().inverse().value_or({});
diff --git a/Libraries/LibWeb/CSS/VisualViewport.h b/Libraries/LibWeb/CSS/VisualViewport.h
index f40a502244e..49ba4c86ea1 100644
--- a/Libraries/LibWeb/CSS/VisualViewport.h
+++ b/Libraries/LibWeb/CSS/VisualViewport.h
@@ -51,6 +51,7 @@ public:
[[nodiscard]] Gfx::AffineTransform transform() const;
void zoom(CSSPixelPoint position, double scale_delta);
+ void set_scale_zoomed_by_compositor(double scale);
CSSPixelPoint map_to_layout_viewport(CSSPixelPoint) const;
CSSPixelPoint map_from_layout_viewport(CSSPixelPoint) const;
CSSPixelRect map_from_layout_viewport(CSSPixelRect const&) const;
diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.cpp b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
index 577b43c0a97..aa5bc3f94d1 100644
--- a/Libraries/LibWeb/Compositor/CompositorConnection.cpp
+++ b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
@@ -822,6 +822,12 @@ void CompositorConnection::key_event(u64 page_id, Web::KeyEvent event)
on_key_event(Web::PageId { page_id }, move(event));
}
+void CompositorConnection::pinch_event(u64 page_id, Web::PinchEvent event)
+{
+ if (on_pinch_event)
+ on_pinch_event(Web::PageId { page_id }, event);
+}
+
void CompositorConnection::mouse_event(u64 page_id, Web::MouseEvent event)
{
if (on_mouse_event)
diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.h b/Libraries/LibWeb/Compositor/CompositorConnection.h
index 36e5cf2e344..cf2dc1f9e22 100644
--- a/Libraries/LibWeb/Compositor/CompositorConnection.h
+++ b/Libraries/LibWeb/Compositor/CompositorConnection.h
@@ -97,6 +97,7 @@ public:
void attach_render_clock(IPC::TransportHandle);
Function<void(Web::PageId page_id, Web::MouseEvent)> on_mouse_event;
Function<void(Web::PageId page_id, Web::KeyEvent)> on_key_event;
+ Function<void(Web::PageId page_id, Web::PinchEvent)> on_pinch_event;
Function<void()> on_compositor_lost;
// Asks the Browser to connect this process's media server to the Compositor.
Function<void()> on_request_video_presentation_channel;
@@ -112,6 +113,7 @@ private:
virtual void mouse_event(u64 page_id, Web::MouseEvent) override;
virtual void key_event(u64 page_id, Web::KeyEvent) override;
+ virtual void pinch_event(u64 page_id, Web::PinchEvent) override;
virtual void request_rendering_update() override;
virtual void rendering_opportunity(Web::CompositorContextId, i64 frame_time_nanoseconds, double frame_interval_milliseconds) override;
virtual void async_scroll_updates(Web::CompositorContextId, Compositing::PendingAsyncScrollUpdates) override;
diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
index 65546f044e0..c39f0875b70 100644
--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
@@ -503,7 +503,7 @@ void EventLoop::process_input_events() const
return page.handle_drag_and_drop_event(*root, drag_event.type, drag_event.position, drag_event.screen_position, drag_event.button, drag_event.buttons, drag_event.modifiers, move(drag_event.files));
},
[&](Web::PinchEvent& pinch_event) {
- return page.handle_pinch_event(*root, pinch_event.position, pinch_event.modifiers, pinch_event.scale_delta);
+ return page.handle_pinch_event(*root, pinch_event.position, pinch_event.modifiers, pinch_event.scale_delta, pinch_event.async_zoom_performed_default_action);
});
finish_handling_coalesced_input_events(event);
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index 4a6767e224f..85564409515 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -5673,7 +5673,7 @@ bool LocalNavigable::adopt_async_viewport_scroll_delta(CSSPixelPoint scroll_delt
return m_viewport_scroll_offset != viewport_scroll_offset;
}
-bool LocalNavigable::adopt_async_visual_viewport_scroll_delta(CSSPixelPoint scroll_delta)
+bool LocalNavigable::adopt_async_visual_viewport_scroll(Optional<float> scale, CSSPixelPoint scroll_delta)
{
auto document = active_document();
if (!document)
@@ -5681,7 +5681,11 @@ bool LocalNavigable::adopt_async_visual_viewport_scroll_delta(CSSPixelPoint scro
defer_user_scroll_settlement();
+ // A zoom moves the offset as well, which is then only in range for the new scale.
auto visual_viewport = document->visual_viewport();
+ auto scale_before_adoption = visual_viewport->scale();
+ if (scale.has_value())
+ visual_viewport->set_scale_zoomed_by_compositor(scale.value());
auto max_x = m_viewport_size.width().to_double() - visual_viewport->width();
auto max_y = m_viewport_size.height().to_double() - visual_viewport->height();
@@ -5692,7 +5696,7 @@ bool LocalNavigable::adopt_async_visual_viewport_scroll_delta(CSSPixelPoint scro
min(max_y, max(0.0, visual_y + scroll_delta.y().to_double())) - visual_y,
};
if (visual_delta.is_zero())
- return false;
+ return visual_viewport->scale() != scale_before_adoption;
visual_viewport->scroll_by(visual_delta);
queue_scrollend_event(*document, *visual_viewport, {}, ScrollTrigger::UserInput);
@@ -5794,7 +5798,7 @@ void LocalNavigable::adopt_pending_async_scroll_offsets(Compositing::AsyncScroll
if (async_scroll_offset.stable_node_id.kind == Web::AsyncScrollNodeKind::VisualViewport) {
if (async_scroll_offset.stable_node_id.node_id != document->unique_id())
continue;
- if (adopt_async_visual_viewport_scroll_delta(css_scroll_delta)) {
+ if (adopt_async_visual_viewport_scroll(async_scroll_offset.visual_viewport_scale, css_scroll_delta)) {
adopted_any_scroll_offset = true;
dbgln_if(COMPOSITOR_DEBUG, "[Compositor] Main thread adopting async visual viewport delta {},{}",
async_scroll_offset.unadopted_scroll_delta.x(), async_scroll_offset.unadopted_scroll_delta.y());
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.h
index beb6c55f992..d97d9b82b72 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.h
+++ b/Libraries/LibWeb/HTML/LocalNavigable.h
@@ -495,7 +495,7 @@ private:
GC::Ref<WebIDL::Promise> perform_a_scroll_of_a_scrolling_box(Web::AsyncScrollNodeStableID, CSSPixelPoint position, Bindings::ScrollBehavior, GC::Ptr<DOM::Element> associated_element, ScrollTrigger, Optional<CSSPixelPoint> relative_displacement = {}, DestinationSnapping = DestinationSnapping::SelectSnapPosition, Compositing::ScrollAnimationKind = Compositing::ScrollAnimationKind::SmoothScroll, Painting::ScrollKind = Painting::ScrollKind::Absolute);
GC::Ref<WebIDL::Promise> perform_a_scroll_of_the_layout_viewport(CSSPixelPoint delta, Bindings::ScrollBehavior, ScrollTrigger, Optional<CSSPixelPoint> relative_displacement, Painting::ScrollKind, Compositing::ScrollAnimationKind);
bool adopt_async_viewport_scroll_delta(CSSPixelPoint);
- bool adopt_async_visual_viewport_scroll_delta(CSSPixelPoint);
+ bool adopt_async_visual_viewport_scroll(Optional<float> scale, CSSPixelPoint scroll_delta);
Gfx::FloatPoint device_scroll_offset(CSSPixelPoint) const;
GC::Ptr<WebIDL::Promise> continue_in_flight_user_smooth_scroll(Web::AsyncScrollNodeStableID, CSSPixelPoint position, Compositing::ScrollAnimationKind);
Optional<CSSPixelPoint> scroll_offset_for(Web::AsyncScrollNodeStableID) const;
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp
index 6d8f92c8234..19dc3f58a4b 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -1036,6 +1036,16 @@ void Internals::pinch(double x, double y, double scale_delta, WebIDL::UnsignedSh
page.handle_pinch_event(position, modifiers, scale_delta);
}
+void Internals::pinch_through_ui_process(double x, double y, double scale_delta)
+{
+ let_compositor_take_in_every_rendered_frame(window());
+
+ Web::PinchEvent event;
+ event.position = page().css_to_device_point(window().navigable()->to_page_position({ x, y }));
+ event.scale_delta = scale_delta;
+ page().client().page_did_request_pinch_event_for_testing(window().navigable()->local_root()->id(), event);
+}
+
void Internals::reset_zoom()
{
if (auto local_root = local_root_of(window()))
diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.h
index 317e5249fca..66554daa056 100644
--- a/Libraries/LibWeb/Internals/Internals.h
+++ b/Libraries/LibWeb/Internals/Internals.h
@@ -123,6 +123,7 @@ public:
void wheel(double x, double y, double delta_x, double delta_y, bool precise, Bindings::ScrollGesturePhase, Bindings::WheelTicks const&, GC::Ref<WebIDL::Promise>);
GC::Ref<JS::Object> compositor_scroll_state(GC::Ptr<DOM::Element> scroller);
void pinch(double x, double y, double scale_delta, WebIDL::UnsignedShort modifiers);
+ void pinch_through_ui_process(double x, double y, double scale_delta);
void reset_zoom();
Utf16String current_cursor();
diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idl
index 6e7f6a2d3dd..e21217b1573 100644
--- a/Libraries/LibWeb/Internals/Internals.idl
+++ b/Libraries/LibWeb/Internals/Internals.idl
@@ -103,6 +103,8 @@ interface Internals {
// viewport if none is given.
object compositorScrollState(optional Element? scroller = null);
undefined pinch(double x, double y, double scaleDelta, optional unsigned short modifiers = 0);
+ // Sends a pinch through the UI process as it sends the user's, so that the compositor zooms for it if it can.
+ undefined pinchThroughUIProcess(double x, double y, double scaleDelta);
undefined resetZoom();
DOMString currentCursor();
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp
index c9c4eae19ec..848ccbdb5e4 100644
--- a/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Libraries/LibWeb/Page/EventHandler.cpp
@@ -1321,7 +1321,7 @@ EventResult EventHandler::dispatch_wheel_event(Layout::BegunRead const& read, La
return node->dispatch_event(event) ? EventResult::Accepted : EventResult::Cancelled;
}
-EventResult EventHandler::dispatch_synthetic_pinch_wheel_event(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, u32 modifiers, double wheel_delta_y)
+EventResult EventHandler::dispatch_synthetic_pinch_wheel_event(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, u32 modifiers, double wheel_delta_y, bool is_cancelable)
{
auto document = m_navigable->active_document();
if (!document || !document->is_fully_active())
@@ -1342,8 +1342,8 @@ EventResult EventHandler::dispatch_synthetic_pinch_wheel_event(CSSPixelPoint vis
if (!target_layout_node || !target_dom_node)
return EventResult::Dropped;
- if (auto result = dispatch_event_to_nested_navigable(*this, *target_layout_node, target_dom_node, visual_viewport_position, nullptr, [screen_position, modifiers, wheel_delta_y](EventHandler& event_handler, CSSPixelPoint position) -> EventResult {
- return event_handler.dispatch_synthetic_pinch_wheel_event(position, screen_position, modifiers, wheel_delta_y);
+ if (auto result = dispatch_event_to_nested_navigable(*this, *target_layout_node, target_dom_node, visual_viewport_position, nullptr, [screen_position, modifiers, wheel_delta_y, is_cancelable](EventHandler& event_handler, CSSPixelPoint position) -> EventResult {
+ return event_handler.dispatch_synthetic_pinch_wheel_event(position, screen_position, modifiers, wheel_delta_y, is_cancelable);
});
result.has_value()) {
if (result.value() == EventResult::Handled || result.value() == EventResult::Cancelled)
@@ -1354,7 +1354,7 @@ EventResult EventHandler::dispatch_synthetic_pinch_wheel_event(CSSPixelPoint vis
}
modifiers |= UIEvents::KeyModifier::Mod_Ctrl;
- return dispatch_wheel_event(read, *target_layout_node, visual_viewport_position, screen_position, UIEvents::MouseButton::None, UIEvents::MouseButton::None, modifiers, 0, wheel_delta_y, 0, Web::wheel_tick_120ths_from_pixel_delta(wheel_delta_y, Web::WheelDeltaPrecision::Precise), true);
+ return dispatch_wheel_event(read, *target_layout_node, visual_viewport_position, screen_position, UIEvents::MouseButton::None, UIEvents::MouseButton::None, modifiers, 0, wheel_delta_y, 0, Web::wheel_tick_120ths_from_pixel_delta(wheel_delta_y, Web::WheelDeltaPrecision::Precise), is_cancelable);
}
EventResult EventHandler::handle_mouseleave()
@@ -2457,7 +2457,7 @@ bool EventHandler::should_ignore_device_input_event() const
return m_drag_and_drop_event_handler->has_ongoing_drag_and_drop_operation();
}
-EventResult EventHandler::handle_pinch_event(CSSPixelPoint point, u32 modifiers, double scale_delta)
+EventResult EventHandler::handle_pinch_event(CSSPixelPoint point, u32 modifiers, double scale_delta, bool async_zoom_performed_default_action)
{
auto document = m_navigable->active_document();
if (!document)
@@ -2472,9 +2472,13 @@ EventResult EventHandler::handle_pinch_event(CSSPixelPoint point, u32 modifiers,
if (scale == 1.0)
return EventResult::Handled;
+ // The compositor process zoomed without waiting to see whether the page cancels the event, and reported the zoom in
+ // the scroll updates it sent ahead of the event.
auto wheel_delta_y = -100.0 * AK::log(scale);
- if (dispatch_synthetic_pinch_wheel_event(point, point, modifiers, wheel_delta_y) == EventResult::Cancelled)
+ if (dispatch_synthetic_pinch_wheel_event(point, point, modifiers, wheel_delta_y, !async_zoom_performed_default_action) == EventResult::Cancelled)
return EventResult::Cancelled;
+ if (async_zoom_performed_default_action)
+ return EventResult::Handled;
document = m_navigable->active_document();
if (!document || !document->is_fully_active())
diff --git a/Libraries/LibWeb/Page/EventHandler.h b/Libraries/LibWeb/Page/EventHandler.h
index 3fc527790fd..bcc19be55ca 100644
--- a/Libraries/LibWeb/Page/EventHandler.h
+++ b/Libraries/LibWeb/Page/EventHandler.h
@@ -111,7 +111,7 @@ public:
EventResult handle_keyup(UIEvents::KeyCode, unsigned modifiers, u32 code_point, bool repeat);
EventResult handle_drag_and_drop_event(DragEvent::Type, CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, Vector<HTML::SelectedFile> files);
- EventResult handle_pinch_event(CSSPixelPoint, unsigned modifiers, double scale_delta);
+ EventResult handle_pinch_event(CSSPixelPoint, unsigned modifiers, double scale_delta, bool async_zoom_performed_default_action);
[[nodiscard]] EventResult perform_paste_action();
EventResult perform_paste_action(NonnullRefPtr<HTML::DragDataStore> const&);
@@ -266,7 +266,7 @@ private:
// Both drop the latch when what it refers to is gone from the document, so that the event is targeted afresh.
Layout::Node* validated_wheel_scroll_latch_target_layout_node(Layout::BegunRead const& read, DOM::Document&);
Layout::Node* validated_latched_wheel_scrolling_box();
- EventResult dispatch_synthetic_pinch_wheel_event(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, unsigned modifiers, double wheel_delta_y);
+ EventResult dispatch_synthetic_pinch_wheel_event(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, unsigned modifiers, double wheel_delta_y, bool is_cancelable);
enum class PointerEventType : u8 {
PointerDown,
diff --git a/Libraries/LibWeb/Page/Page.cpp b/Libraries/LibWeb/Page/Page.cpp
index 110ad03fd6a..f68c288c065 100644
--- a/Libraries/LibWeb/Page/Page.cpp
+++ b/Libraries/LibWeb/Page/Page.cpp
@@ -552,14 +552,16 @@ EventResult Page::handle_drag_and_drop_event(DragEvent::Type type, DevicePixelPo
return handle_drag_and_drop_event(local_traversable(), type, position, screen_position, button, buttons, modifiers, move(files));
}
-EventResult Page::handle_pinch_event(HTML::LocalNavigable& root, DevicePixelPoint position, unsigned modifiers, double scale)
+EventResult Page::handle_pinch_event(HTML::LocalNavigable& root, DevicePixelPoint position, unsigned modifiers, double scale, bool async_zoom_performed_default_action)
{
- return root.event_handler().handle_pinch_event(device_to_css_point(position), modifiers, scale);
+ if (async_zoom_performed_default_action)
+ root.adopt_pending_async_scroll_offsets(Compositing::AsyncScrollUpdateFreshness::Pushed);
+ return root.event_handler().handle_pinch_event(device_to_css_point(position), modifiers, scale, async_zoom_performed_default_action);
}
EventResult Page::handle_pinch_event(DevicePixelPoint position, unsigned modifiers, double scale)
{
- return handle_pinch_event(local_traversable(), position, modifiers, scale);
+ return handle_pinch_event(local_traversable(), position, modifiers, scale, false);
}
EventResult Page::handle_keydown(UIEvents::KeyCode key, unsigned modifiers, u32 code_point, bool repeat, bool should_insert_text, bool async_scroll_performed_default_action, ReadonlySpan<TextEditingCommand> editing_commands, bool native_editing_binding_resolved)
diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h
index f7cc8a00840..8e55e45551b 100644
--- a/Libraries/LibWeb/Page/Page.h
+++ b/Libraries/LibWeb/Page/Page.h
@@ -197,7 +197,7 @@ public:
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_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);
+ EventResult handle_pinch_event(HTML::LocalNavigable& root, DevicePixelPoint point, unsigned modifiers, double scale, bool async_zoom_performed_default_action);
EventResult handle_mouseup(DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers);
EventResult handle_mousedown(DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, int click_count);
@@ -844,6 +844,7 @@ public:
virtual void page_did_request_key_event_for_testing([[maybe_unused]] Web::KeyEvent event) { }
virtual void page_did_request_spelling_menu_action_for_testing([[maybe_unused]] SpellingMenuActionForTesting action, [[maybe_unused]] u32 guess_index) { }
virtual void page_did_request_webdriver_mouse_event([[maybe_unused]] HTML::CrossProcessId local_root_id, [[maybe_unused]] Web::MouseEvent event, GC::Ref<GC::Function<void()>> on_handled) { on_handled->function()(); }
+ virtual void page_did_request_pinch_event_for_testing([[maybe_unused]] HTML::CrossProcessId local_root_id, [[maybe_unused]] Web::PinchEvent const& event) { }
virtual void page_did_request_set_system_visibility_state([[maybe_unused]] HTML::VisibilityState visibility_state) { }
virtual String page_did_request_ui_process_session_history_for_testing() { return "{}"_string; }
virtual bool page_did_request_has_populated_document_for_testing([[maybe_unused]] HTML::CrossProcessId navigable_id) { return false; }
diff --git a/Libraries/LibWebCommon/Page/InputEvent.h b/Libraries/LibWebCommon/Page/InputEvent.h
index 746bd16b9c2..1ccd54c5804 100644
--- a/Libraries/LibWebCommon/Page/InputEvent.h
+++ b/Libraries/LibWebCommon/Page/InputEvent.h
@@ -179,6 +179,7 @@ struct WEBCOMMON_API PinchEvent {
Web::DevicePixelPoint position;
Web::UIEvents::KeyModifier modifiers { Web::UIEvents::KeyModifier::Mod_None };
double scale_delta;
+ bool async_zoom_performed_default_action { false };
u64 id { 0 };
};
diff --git a/Libraries/LibWebCommon/Page/InputEvent.ipc b/Libraries/LibWebCommon/Page/InputEvent.ipc
index 274df947cb4..947cc6be532 100644
--- a/Libraries/LibWebCommon/Page/InputEvent.ipc
+++ b/Libraries/LibWebCommon/Page/InputEvent.ipc
@@ -102,5 +102,6 @@ struct Web::PinchEvent {
Web::DevicePixelPoint position;
Web::UIEvents::KeyModifier modifiers;
[Finite] double scale_delta;
+ bool async_zoom_performed_default_action;
u64 id;
}
diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cpp
index 2cafff3b703..b80aea8adfd 100644
--- a/Libraries/LibWebView/Application.cpp
+++ b/Libraries/LibWebView/Application.cpp
@@ -1531,12 +1531,14 @@ bool Application::handle_and_dispatch_key_event_in_compositor(Web::CompositorCon
return true;
}
-void Application::handle_pinch_event_in_compositor(Web::CompositorContextId context_id, Web::PinchEvent const& event)
+bool Application::handle_and_dispatch_pinch_event_in_compositor(Web::CompositorContextId context_id, Web::PinchEvent const& event)
{
if (!can_send_compositor_process_ipc(m_compositor_presentation_client))
- return;
+ return false;
+ VERIFY(m_compositor_presentation_client);
- m_compositor_presentation_client->async_handle_pinch_event(context_id, event);
+ m_compositor_presentation_client->async_handle_and_dispatch_pinch_event(context_id, event);
+ return true;
}
bool Application::handle_and_dispatch_mouse_event_in_compositor(Web::CompositorContextId context_id, Web::MouseEvent const& event)
diff --git a/Libraries/LibWebView/Application.h b/Libraries/LibWebView/Application.h
index 0b99140acd5..e376e34d2ed 100644
--- a/Libraries/LibWebView/Application.h
+++ b/Libraries/LibWebView/Application.h
@@ -265,7 +265,7 @@ public:
void update_compositor_display_metadata(Web::CompositorContextId, Optional<u64> display_id, double refresh_rate);
void update_compositor_context_visibility(Web::CompositorContextId, Web::HTML::VisibilityState);
bool handle_and_dispatch_key_event_in_compositor(Web::CompositorContextId, Web::KeyEvent const&, bool allow_keyboard_scroll);
- void handle_pinch_event_in_compositor(Web::CompositorContextId, Web::PinchEvent const&);
+ bool handle_and_dispatch_pinch_event_in_compositor(Web::CompositorContextId, Web::PinchEvent const&);
bool handle_and_dispatch_mouse_event_in_compositor(Web::CompositorContextId, Web::MouseEvent const&);
void notify_compositor_presented_bitmap_ready_to_paint(Web::CompositorContextId, i32 bitmap_id);
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index 33d7343eab8..e1c45994eca 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -788,6 +788,11 @@ void ViewImplementation::enqueue_webdriver_mouse_event(Badge<WebContentPage>, We
enqueue_input_event(move(event));
}
+void ViewImplementation::enqueue_pinch_event_for_testing(Badge<WebContentPage>, Web::PinchEvent event)
+{
+ enqueue_input_event(event);
+}
+
// https://html.spec.whatwg.org/multipage/interaction.html#activation-triggering-input-event
static bool is_activation_triggering_input_event(Web::InputEvent const& event)
{
@@ -933,8 +938,12 @@ void ViewImplementation::send_input_event(size_t index)
pending.endpoint->async_drag_event(cloned_event);
},
[&](Web::PinchEvent const& event) {
- pending.endpoint->handle_pinch_event_in_compositor(event);
- pending.endpoint->async_pinch_event(event);
+ // The compositor zooms for the event when it can, then forwards the event to WebContent behind the scroll
+ // updates that produced, or hands it back for direct dispatch.
+ if (pending.endpoint->handle_and_dispatch_pinch_event_in_compositor(event))
+ pending.routed_through_compositor = true;
+ else
+ pending.endpoint->async_pinch_event(event);
});
}
@@ -1252,6 +1261,9 @@ void ViewImplementation::did_not_dispatch_input_event_through_compositor(Badge<W
[&](Web::MouseEvent const& event) {
pending.endpoint->async_mouse_event(event.clone_without_browser_data());
},
+ [&](Web::PinchEvent const& event) {
+ pending.endpoint->async_pinch_event(event);
+ },
[](auto const&) {
VERIFY_NOT_REACHED();
});
diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h
index 129afacfbd9..c5fc8a68744 100644
--- a/Libraries/LibWebView/ViewImplementation.h
+++ b/Libraries/LibWebView/ViewImplementation.h
@@ -438,6 +438,7 @@ public:
void did_complete_webdriver_content_command(WebContentPage&, u64 command_id, Web::WebDriver::Response);
void did_set_webdriver_current_browsing_context(Badge<WebContentPage>, u64 command_id, Web::HTML::CrossProcessId navigable_id);
void enqueue_webdriver_mouse_event(Badge<WebContentPage>, Web::MouseEvent, Function<void()> on_handled);
+ void enqueue_pinch_event_for_testing(Badge<WebContentPage>, Web::PinchEvent);
void did_lose_page(Badge<CanonicalTraversable>, WebContentPage&, WebContentProcessLost);
void move_pending_webdriver_commands_to_new_host(Badge<CanonicalNavigable>, Web::HTML::CrossProcessId navigable_id, WebContentPage& old_host, WebContentPage& new_host);
void set_webdriver_current_browsing_context_to_top_level();
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index 79cdb121cb6..683a4f948fe 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -494,10 +494,11 @@ bool WebContentPage::handle_and_dispatch_key_event_in_compositor(Web::KeyEvent c
return posted;
}
-void WebContentPage::handle_pinch_event_in_compositor(Web::PinchEvent const& event)
+bool WebContentPage::handle_and_dispatch_pinch_event_in_compositor(Web::PinchEvent const& event)
{
- dbgln_if(COMPOSITOR_DEBUG, "[Compositor] UI posted pinch event {} for page {} to the compositor", event.id, m_id);
- Application::the().handle_pinch_event_in_compositor(compositor_context_id(), event);
+ auto posted = Application::the().handle_and_dispatch_pinch_event_in_compositor(compositor_context_id(), event);
+ dbgln_if(COMPOSITOR_DEBUG, "[Compositor] UI posted pinch event {} for page {} to the compositor: {}", event.id, m_id, posted);
+ return posted;
}
bool WebContentPage::handle_and_dispatch_mouse_event_in_compositor(Web::MouseEvent const& event)
@@ -2781,6 +2782,22 @@ void WebContentPage::did_update_session_history_entry_scroll_restoration_mode(We
navigable->top_level_traversable().update_session_history_entry_scroll_restoration_mode(*navigable, entry_identity, scroll_restoration_mode);
}
+void WebContentPage::did_request_pinch_event_for_testing(Web::HTML::CrossProcessId local_root_id, Web::PinchEvent event)
+{
+ // NB: As for a key event for testing, the event is dispatched as the user's own.
+ if (!WebContentClient::renderers_may_synthesize_input()) {
+ client().did_misbehave("did_request_pinch_event_for_testing"sv, "not driven by WebDriver or a test"sv);
+ return;
+ }
+
+ // The event is relative to the viewport of the local root its page dispatches input to.
+ if (auto root = view().traversable().find(local_root_id); root.has_value())
+ event.position.translate_by(view().traversable().local_root_offset(*root));
+ // Only the compositor sets this, on its way to WebContent.
+ event.async_zoom_performed_default_action = false;
+ view().enqueue_pinch_event_for_testing({}, event);
+}
+
void WebContentPage::did_request_webdriver_mouse_event(u64 request_id, Web::HTML::CrossProcessId local_root_id, Web::MouseEvent event)
{
// NB: As for a key event for testing, the event is dispatched as the user's own.
diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.h
index 314b27ba993..9c5ee0a1ac2 100644
--- a/Libraries/LibWebView/WebContentPage.h
+++ b/Libraries/LibWebView/WebContentPage.h
@@ -140,7 +140,7 @@ public:
Web::CompositorContextId compositor_context_id();
// Returns whether the event was posted; a page without a compositor sends it to WebContent itself.
bool handle_and_dispatch_key_event_in_compositor(Web::KeyEvent const&, bool allow_keyboard_scroll);
- void handle_pinch_event_in_compositor(Web::PinchEvent const&);
+ bool handle_and_dispatch_pinch_event_in_compositor(Web::PinchEvent const&);
// Returns whether the event was posted; a page without a compositor sends it to WebContent itself.
bool handle_and_dispatch_mouse_event_in_compositor(Web::MouseEvent const&);
void did_consume_input_event_in_compositor(u64 event_id);
@@ -352,6 +352,7 @@ private:
virtual void did_update_primary_selection(String text) override;
virtual void did_update_session_history_entry_scroll_restoration_mode(Web::HTML::CrossProcessId navigable_id, Web::HTML::SessionHistoryEntryIdentity entry_identity, Web::HTML::ScrollRestorationMode scroll_restoration_mode) override;
virtual void did_request_webdriver_mouse_event(u64 request_id, Web::HTML::CrossProcessId local_root_id, Web::MouseEvent event) override;
+ virtual void did_request_pinch_event_for_testing(Web::HTML::CrossProcessId local_root_id, Web::PinchEvent event) override;
virtual void request_unload_check(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId check_id) override;
Messages::WebContentClient::StartWorkerAgentResponse start_worker_agent(Web::HTML::WorkerAgentStartRequest request);
Messages::WebContentClient::DidRequestStorageUsageResponse did_request_storage_usage(Web::HTML::EnvironmentId environment_id);
diff --git a/Services/Compositor/AsyncScrollUpdateOutbox.cpp b/Services/Compositor/AsyncScrollUpdateOutbox.cpp
index e82254a8ffd..d834e8fdbad 100644
--- a/Services/Compositor/AsyncScrollUpdateOutbox.cpp
+++ b/Services/Compositor/AsyncScrollUpdateOutbox.cpp
@@ -50,11 +50,12 @@ Compositing::PendingAsyncScrollUpdates AsyncScrollUpdateOutbox::take_updates(boo
continue;
unreconciled.sequence = updates.sequence;
unreconciled.compositor_scroll_offset = scroll_offset.compositor_scroll_offset;
+ unreconciled.visual_viewport_scale = scroll_offset.visual_viewport_scale;
replaced = true;
break;
}
if (!replaced)
- m_unreconciled_scroll_offsets.append({ updates.sequence, scroll_offset.stable_node_id, scroll_offset.compositor_scroll_offset });
+ m_unreconciled_scroll_offsets.append({ updates.sequence, scroll_offset.stable_node_id, scroll_offset.compositor_scroll_offset, scroll_offset.visual_viewport_scale });
}
AK::swap(updates.completed_operation_ids, m_completed_operation_ids);
AK::swap(updates.operation_ids_taken_over_by_user_input, m_operation_ids_taken_over_by_user_input);
@@ -66,6 +67,21 @@ Compositing::PendingAsyncScrollUpdates AsyncScrollUpdateOutbox::take_updates(boo
return updates;
}
+Optional<AsyncScrollUpdateOutbox::VisualViewportState> AsyncScrollUpdateOutbox::unadopted_visual_viewport_state(Web::UniqueNodeID document_id) const
+{
+ Web::AsyncScrollNodeStableID visual_viewport { .node_id = document_id, .kind = Web::AsyncScrollNodeKind::VisualViewport };
+ // The updates that are still to be published are the latest.
+ for (auto const& pending : m_pending_scroll_offsets) {
+ if (pending.stable_node_id == visual_viewport && pending.visual_viewport_scale.has_value())
+ return VisualViewportState { pending.compositor_scroll_offset, pending.visual_viewport_scale.value() };
+ }
+ for (auto const& unreconciled : m_unreconciled_scroll_offsets) {
+ if (unreconciled.stable_node_id == visual_viewport && unreconciled.visual_viewport_scale.has_value())
+ return VisualViewportState { unreconciled.compositor_scroll_offset, unreconciled.visual_viewport_scale.value() };
+ }
+ return {};
+}
+
void AsyncScrollUpdateOutbox::retire_scroll_offsets_adopted_by(u64 adopted_sequence)
{
m_unreconciled_scroll_offsets.remove_all_matching([&](auto const& unreconciled) { return unreconciled.sequence <= adopted_sequence; });
diff --git a/Services/Compositor/AsyncScrollUpdateOutbox.h b/Services/Compositor/AsyncScrollUpdateOutbox.h
index 1f53fbe8102..16ad2ac8b25 100644
--- a/Services/Compositor/AsyncScrollUpdateOutbox.h
+++ b/Services/Compositor/AsyncScrollUpdateOutbox.h
@@ -21,6 +21,12 @@ public:
u64 sequence { 0 };
Web::AsyncScrollNodeStableID stable_node_id;
Gfx::FloatPoint compositor_scroll_offset;
+ Optional<float> visual_viewport_scale;
+ };
+
+ struct VisualViewportState {
+ Gfx::FloatPoint scroll_offset;
+ float scale { 1 };
};
Compositing::AsyncScrollOperationID allocate_operation_id() { return ++m_last_allocated_operation_id; }
@@ -34,6 +40,8 @@ public:
Compositing::PendingAsyncScrollUpdates take_updates(bool user_scroll_gesture_in_progress);
ReadonlySpan<UnreconciledScrollOffset> unreconciled_scroll_offsets() const { return m_unreconciled_scroll_offsets; }
+ // Where the compositor zoomed and panned the document's visual viewport to, until WebContent has adopted it.
+ Optional<VisualViewportState> unadopted_visual_viewport_state(Web::UniqueNodeID document_id) const;
void retire_scroll_offsets_adopted_by(u64 adopted_sequence);
private:
diff --git a/Services/Compositor/CompositorPresentationServer.ipc b/Services/Compositor/CompositorPresentationServer.ipc
index 51e763324e7..910f4f54a02 100644
--- a/Services/Compositor/CompositorPresentationServer.ipc
+++ b/Services/Compositor/CompositorPresentationServer.ipc
@@ -4,7 +4,7 @@
endpoint CompositorPresentationServer
{
handle_and_dispatch_key_event(Web::CompositorContextId context_id, Web::KeyEvent event, bool allow_keyboard_scroll) =|
- handle_pinch_event(Web::CompositorContextId context_id, Web::PinchEvent event) =|
+ handle_and_dispatch_pinch_event(Web::CompositorContextId context_id, Web::PinchEvent event) =|
handle_and_dispatch_mouse_event(Web::CompositorContextId context_id, Web::MouseEvent event) =|
presented_bitmap_ready_to_paint(Web::CompositorContextId context_id, i32 bitmap_id) =|
set_client_gpu_presentation_capability(bool supported, u64 adapter_luid) =|
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cpp
index 3c5d20a0a69..47c9de6a297 100644
--- a/Services/Compositor/CompositorState.cpp
+++ b/Services/Compositor/CompositorState.cpp
@@ -848,13 +848,22 @@ void CompositorState::dispatch_scroll_fling_step(Web::CompositorContextId contex
context.dispatch_mouse_event_to_web_content(*event);
}
-void CompositorState::handle_pinch_event(Web::CompositorContextId context_id, Web::PinchEvent const& event)
+void CompositorState::handle_and_dispatch_pinch_event(Web::CompositorContextId context_id, Web::PinchEvent event)
{
+ // NB: The presentation connection only passes on input for the contexts bound to it.
+ auto* presentation = presentation_for_context(context_id);
+ VERIFY(presentation);
auto* context = context_if_present(context_id);
- if (!context)
+ if (!context || !context->can_dispatch_input_to_web_content()) {
+ presentation->did_not_dispatch_input_event(context_id, event.id);
return;
+ }
+
+ event.async_zoom_performed_default_action = apply_context_update_result(context_id, *context, context->handle_pinch_event(event));
- apply_context_update_result(context_id, *context, context->handle_pinch_event(event));
+ // 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);
+ context->dispatch_pinch_event_to_web_content(event);
}
Compositing::AsyncScrollEnqueueResult CompositorState::async_scroll_by(Web::CompositorContextId context_id, Web::UniqueNodeID expected_document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelStepDispatch wheel_step_dispatch, u64 input_event_id)
diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.h
index 896ee2654bb..4c0a977206c 100644
--- a/Services/Compositor/CompositorState.h
+++ b/Services/Compositor/CompositorState.h
@@ -59,6 +59,7 @@ public:
virtual void dispatch_mouse_event_to_web_content(u64 page_id, Web::MouseEvent const&) = 0;
virtual void dispatch_key_event_to_web_content(u64 page_id, Web::KeyEvent const&) = 0;
+ virtual void dispatch_pinch_event_to_web_content(u64 page_id, Web::PinchEvent const&) = 0;
virtual void request_rendering_update() = 0;
virtual void rendering_opportunity(Web::CompositorContextId, i64 frame_time_nanoseconds, double frame_interval_milliseconds) = 0;
virtual void clock_tick(Web::CompositorContextId, i64 frame_time_nanoseconds, double frame_interval_milliseconds, Vector<Web::CompositorScrollOffset> const& scroll_offsets) = 0;
@@ -126,7 +127,7 @@ public:
void invalidate_keyboard_scroll_state(Web::CompositorContextId, u64 generation);
void handle_and_dispatch_key_event(Web::CompositorContextId, Web::KeyEvent, bool allow_keyboard_scroll);
void handle_and_dispatch_mouse_event(Web::CompositorContextId, Web::MouseEvent);
- void handle_pinch_event(Web::CompositorContextId, Web::PinchEvent const&);
+ void handle_and_dispatch_pinch_event(Web::CompositorContextId, Web::PinchEvent);
Compositing::AsyncScrollEnqueueResult async_scroll_by(Web::CompositorContextId, Web::UniqueNodeID document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, u32 modifiers, Compositing::AsyncScrollOperationTracking, Compositing::WheelStepDispatch, u64 input_event_id);
Compositing::AsyncScrollEnqueueResult smooth_scroll_to(Web::CompositorContextId, Web::AsyncScrollNodeStableID, Gfx::FloatPoint offset, Gfx::FloatPoint main_thread_offset, Gfx::IntRect viewport_rect, Compositing::ScrollAnimationKind, Compositing::SmoothScrollInitiator, Optional<Compositing::AsyncScrollOperationID> operation_to_continue);
void cancel_smooth_scroll(Web::CompositorContextId, Web::AsyncScrollNodeStableID);
diff --git a/Services/Compositor/CompositorWebContentClient.ipc b/Services/Compositor/CompositorWebContentClient.ipc
index 341dc044c2a..1989ad84c1f 100644
--- a/Services/Compositor/CompositorWebContentClient.ipc
+++ b/Services/Compositor/CompositorWebContentClient.ipc
@@ -7,6 +7,7 @@ endpoint CompositorWebContentClient
{
mouse_event(u64 page_id, Web::MouseEvent event) =|
key_event(u64 page_id, Web::KeyEvent event) =|
+ pinch_event(u64 page_id, Web::PinchEvent event) =|
request_rendering_update() =|
rendering_opportunity(Web::CompositorContextId context_id, i64 frame_time_nanoseconds, double frame_interval_milliseconds) =|
async_scroll_updates(Web::CompositorContextId context_id, Compositing::PendingAsyncScrollUpdates updates) =|
diff --git a/Services/Compositor/ConnectionFromPresentation.cpp b/Services/Compositor/ConnectionFromPresentation.cpp
index 1fbcac04831..93a77ebd68e 100644
--- a/Services/Compositor/ConnectionFromPresentation.cpp
+++ b/Services/Compositor/ConnectionFromPresentation.cpp
@@ -62,7 +62,9 @@ static bool is_valid_mouse_event(Web::MouseEvent const& event)
static bool is_valid_pinch_event(Web::PinchEvent const& event)
{
- return is_valid_modifiers(event.modifiers);
+ return is_valid_modifiers(event.modifiers)
+ // Only the compositor sets this, on its way to WebContent.
+ && !event.async_zoom_performed_default_action;
}
ConnectionFromPresentation::ConnectionFromPresentation(NonnullOwnPtr<IPC::Transport> transport, NonnullRefPtr<CompositorState> compositor_state, CompositorState::PresentationCapabilities capabilities)
@@ -138,15 +140,17 @@ void ConnectionFromPresentation::handle_and_dispatch_key_event(Web::CompositorCo
m_compositor_state->handle_and_dispatch_key_event(context_id, move(event), allow_keyboard_scroll);
}
-void ConnectionFromPresentation::handle_pinch_event(Web::CompositorContextId context_id, Web::PinchEvent event)
+void ConnectionFromPresentation::handle_and_dispatch_pinch_event(Web::CompositorContextId context_id, Web::PinchEvent event)
{
if (!is_valid_pinch_event(event)) {
did_misbehave("Invalid pinch event");
return;
}
- if (!is_bound_to(context_id))
+ if (!is_bound_to(context_id)) {
+ did_not_dispatch_input_event(context_id, event.id);
return;
- m_compositor_state->handle_pinch_event(context_id, event);
+ }
+ m_compositor_state->handle_and_dispatch_pinch_event(context_id, event);
}
void ConnectionFromPresentation::handle_and_dispatch_mouse_event(Web::CompositorContextId context_id, Web::MouseEvent event)
diff --git a/Services/Compositor/ConnectionFromPresentation.h b/Services/Compositor/ConnectionFromPresentation.h
index 18f663eff64..b1eb255ac22 100644
--- a/Services/Compositor/ConnectionFromPresentation.h
+++ b/Services/Compositor/ConnectionFromPresentation.h
@@ -39,7 +39,7 @@ private:
virtual void did_dispatch_input_event(Web::CompositorContextId, u64 event_id, bool async_scroll_performed_default_action) override;
virtual void handle_and_dispatch_key_event(Web::CompositorContextId, Web::KeyEvent, bool allow_keyboard_scroll) override;
- virtual void handle_pinch_event(Web::CompositorContextId, Web::PinchEvent) override;
+ virtual void handle_and_dispatch_pinch_event(Web::CompositorContextId, Web::PinchEvent) override;
virtual void handle_and_dispatch_mouse_event(Web::CompositorContextId, Web::MouseEvent) override;
virtual void presented_bitmap_ready_to_paint(Web::CompositorContextId, i32 bitmap_id) override;
virtual void set_client_gpu_presentation_capability(bool supported, u64 adapter_luid) override;
diff --git a/Services/Compositor/ConnectionFromWebContent.cpp b/Services/Compositor/ConnectionFromWebContent.cpp
index 8d98fc2dab8..7e136721e5c 100644
--- a/Services/Compositor/ConnectionFromWebContent.cpp
+++ b/Services/Compositor/ConnectionFromWebContent.cpp
@@ -167,6 +167,11 @@ void ConnectionFromWebContent::dispatch_key_event_to_web_content(u64 page_id, We
async_key_event(page_id, event);
}
+void ConnectionFromWebContent::dispatch_pinch_event_to_web_content(u64 page_id, Web::PinchEvent const& event)
+{
+ async_pinch_event(page_id, event);
+}
+
bool ConnectionFromWebContent::context_is_owned_by_this_connection(Web::CompositorContextId context_id)
{
switch (m_compositor_state->check_context_owner(context_id, *this)) {
diff --git a/Services/Compositor/ConnectionFromWebContent.h b/Services/Compositor/ConnectionFromWebContent.h
index 8a1499e70af..9531bbba998 100644
--- a/Services/Compositor/ConnectionFromWebContent.h
+++ b/Services/Compositor/ConnectionFromWebContent.h
@@ -94,6 +94,7 @@ private:
virtual void dispatch_mouse_event_to_web_content(u64 page_id, Web::MouseEvent const&) override;
virtual void dispatch_key_event_to_web_content(u64 page_id, Web::KeyEvent const&) override;
+ virtual void dispatch_pinch_event_to_web_content(u64 page_id, Web::PinchEvent const&) override;
virtual void request_rendering_update() override;
virtual void rendering_opportunity(Web::CompositorContextId, i64 frame_time_nanoseconds, double frame_interval_milliseconds) override;
virtual void clock_tick(Web::CompositorContextId, i64 frame_time_nanoseconds, double frame_interval_milliseconds, Vector<Web::CompositorScrollOffset> const& scroll_offsets) override;
diff --git a/Services/Compositor/ContextScene.cpp b/Services/Compositor/ContextScene.cpp
index 50acfd88ddf..130190cbca1 100644
--- a/Services/Compositor/ContextScene.cpp
+++ b/Services/Compositor/ContextScene.cpp
@@ -4,29 +4,11 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <AK/Math.h>
#include <Compositor/ContextScene.h>
#include <LibCompositing/DisplayList/DisplayListDamage.h>
namespace Compositor {
-static bool visual_viewport_transforms_match(Compositing::TransformWithOrigin const& a, Compositing::TransformWithOrigin const& b)
-{
- static constexpr float transform_epsilon = 0.01f;
- static constexpr float translation_epsilon = 0.5f;
-
- for (size_t row = 0; row < 4; ++row) {
- for (size_t column = 0; column < 4; ++column) {
- auto epsilon = (column == 3 && (row == 0 || row == 1)) ? translation_epsilon : transform_epsilon;
- if (AK::fabs(a.matrix[row, column] - b.matrix[row, column]) > epsilon)
- return false;
- }
- }
-
- return AK::fabs(a.origin.x() - b.origin.x()) <= translation_epsilon
- && AK::fabs(a.origin.y() - b.origin.y()) <= translation_epsilon;
-}
-
static void update_visual_animation_sampling_state(Compositing::AccumulatedVisualContextTree const& visual_context_tree, Optional<i64>& sample_time_ns, bool& has_active_animations)
{
auto now = MonotonicTime::now();
@@ -45,7 +27,6 @@ void ContextScene::install(NonnullRefPtr<Compositing::DisplayList> display_list,
m_display_list = move(display_list);
m_visual_context_tree = move(visual_context_tree);
update_visual_animation_sampling_state(*m_visual_context_tree, m_visual_animation_sample_time_ns, m_has_active_visual_animations);
- drop_async_visual_viewport_transform_the_visual_context_tree_caught_up_with();
}
bool ContextScene::replace_visual_context_tree(Compositing::AccumulatedVisualContextTree visual_context_tree, Compositing::DisplayListResourceTransaction&& resource_transaction)
@@ -60,7 +41,6 @@ bool ContextScene::replace_visual_context_tree(Compositing::AccumulatedVisualCon
apply_resource_transaction(move(resource_transaction));
m_visual_context_tree = move(visual_context_tree);
update_visual_animation_sampling_state(*m_visual_context_tree, m_visual_animation_sample_time_ns, m_has_active_visual_animations);
- drop_async_visual_viewport_transform_the_visual_context_tree_caught_up_with();
return true;
}
@@ -131,12 +111,6 @@ void ContextScene::drop_async_visual_viewport_transform()
m_async_visual_viewport_transform.clear();
}
-void ContextScene::drop_async_visual_viewport_transform_the_visual_context_tree_caught_up_with()
-{
- if (m_async_visual_viewport_transform.has_value() && visual_viewport_transforms_match(m_visual_context_tree->visual_viewport_transform(), *m_async_visual_viewport_transform))
- m_async_visual_viewport_transform.clear();
-}
-
bool ContextScene::advance_visual_animations(MonotonicTime now)
{
if (!m_visual_context_tree->has_visual_animations())
diff --git a/Services/Compositor/ContextScene.h b/Services/Compositor/ContextScene.h
index 5c90ac66592..8826dd3dd72 100644
--- a/Services/Compositor/ContextScene.h
+++ b/Services/Compositor/ContextScene.h
@@ -61,7 +61,6 @@ public:
private:
void invalidate_visual_context_tree_for_compositing();
- void drop_async_visual_viewport_transform_the_visual_context_tree_caught_up_with();
RefPtr<Compositing::DisplayList const> m_display_list;
Optional<Compositing::AccumulatedVisualContextTree> m_visual_context_tree;
diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cpp
index 99fb93eae92..bd16416330b 100644
--- a/Services/Compositor/ContextState.cpp
+++ b/Services/Compositor/ContextState.cpp
@@ -119,6 +119,12 @@ void ContextState::dispatch_key_event_to_web_content(Web::KeyEvent const& event)
m_web_content_client.dispatch_key_event_to_web_content(*m_page_id, event);
}
+void ContextState::dispatch_pinch_event_to_web_content(Web::PinchEvent const& event)
+{
+ VERIFY(m_page_id.has_value());
+ m_web_content_client.dispatch_pinch_event_to_web_content(*m_page_id, event);
+}
+
void ContextState::stop_presenting_to_client()
{
end_keyboard_scroll_gesture();
@@ -152,8 +158,7 @@ void ContextState::install_display_list_update(
auto async_scrolling_state = Compositing::async_scrolling_state_from_display_list(*m_scene.display_list());
auto async_scrolling_viewport_rect = async_scrolling_state.viewport_rect;
m_wheel_gesture_routing.did_install_scrolling_state(async_scrolling_state);
- if (m_scene.has_async_visual_viewport_transform() && !m_wheel_gesture_routing.admits_async_pinch())
- m_scene.drop_async_visual_viewport_transform();
+ reapply_unadopted_visual_viewport_state();
auto was_dragging_scrollbar = m_scrollbar_controller.has_captured_scrollbar();
m_scrollbar_controller.set_scrollbars(async_scrolling_state.scrollbars);
@@ -218,6 +223,7 @@ void ContextState::update_scroll_state(Compositing::ScrollStateSnapshot&& scroll
if (!m_has_async_scrolling_state)
return;
+ reapply_unadopted_visual_viewport_state();
auto reconciled_viewport_scroll_offset = reapply_unreconciled_async_scroll_offsets();
rebuild_wheel_hit_test_targets();
if (reconciled_viewport_scroll_offset.has_value()) {
@@ -610,11 +616,24 @@ ContextState::ContextUpdateResult ContextState::handle_pinch_event(Web::PinchEve
* Gfx::scale_matrix(Gfx::FloatVector3 { applied_scale, applied_scale, 1 })
* Gfx::translation_matrix(Gfx::FloatVector3 { -position.x(), -position.y(), 0 });
+ auto old_scroll_offset = visual_viewport_scroll_offset(transform);
transform.matrix = gesture_transform * transform.matrix;
clamp_visual_viewport_transform_to_viewport(transform, m_async_scrolling_viewport_rect);
m_scene.set_async_visual_viewport_transform(transform);
rebuild_wheel_hit_test_targets();
+ if (auto document_id = m_async_scroll_tree.document_id(); document_id.has_value()) {
+ auto new_scroll_offset = visual_viewport_scroll_offset(transform);
+ Compositing::AsyncScrollOffset scroll_offset {
+ .stable_node_id = { .node_id = document_id.value(), .kind = Web::AsyncScrollNodeKind::VisualViewport },
+ .compositor_scroll_offset = new_scroll_offset,
+ .unadopted_scroll_delta = new_scroll_offset - old_scroll_offset,
+ .last_relative_scroll_delta = {},
+ .visual_viewport_scale = transform.matrix[0, 0],
+ };
+ store_pending_async_scroll_offsets({ &scroll_offset, 1 });
+ }
+
return {
.accepted = true,
.frame_to_present = PendingFrame::repainting_everything(m_async_scrolling_viewport_rect),
@@ -1120,6 +1139,7 @@ Optional<Gfx::IntRect> ContextState::advance_smooth_scroll_animations(MonotonicT
.compositor_scroll_offset = *new_offset,
.unadopted_scroll_delta = scroll_delta,
.last_relative_scroll_delta = {},
+ .visual_viewport_scale = {},
});
changed_scroll_offset = true;
if (m_async_scroll_tree.scroll_node_is_viewport(*node_id))
@@ -1515,6 +1535,7 @@ String ContextState::scroll_state_for_testing(Web::AsyncScrollNodeStableID stret
stretch_object.set("x"sv, stretch.x());
stretch_object.set("y"sv, stretch.y());
scroll_state.set("stretch"sv, move(stretch_object));
+ scroll_state.set("visualViewportScale"sv, m_scene.visual_viewport_scale().value_or(1.0f));
return scroll_state.serialized();
}
@@ -1733,6 +1754,7 @@ Optional<ContextState::VisualViewportScrollDelta> ContextState::apply_visual_vie
.compositor_scroll_offset = visual_viewport_scroll_offset(transform),
.unadopted_scroll_delta = consumed_delta.scaled(1.0f / scale),
.last_relative_scroll_delta = {},
+ .visual_viewport_scale = scale,
},
.consumed_delta = consumed_delta,
};
@@ -1747,6 +1769,28 @@ Gfx::FloatPoint ContextState::pan_visual_viewport_by(Gfx::FloatPoint delta_in_sc
return visual_viewport_scroll_delta->consumed_delta;
}
+// The visual context tree carries the visual viewport as the main thread last left it, which the zooming and panning
+// that it has yet to adopt still go over.
+void ContextState::reapply_unadopted_visual_viewport_state()
+{
+ Optional<AsyncScrollUpdateOutbox::VisualViewportState> state;
+ if (auto document_id = m_async_scroll_tree.document_id(); document_id.has_value())
+ state = m_async_scroll_update_outbox.unadopted_visual_viewport_state(document_id.value());
+ if (!state.has_value() || !m_scene.visual_context_tree().has_value()) {
+ if (m_scene.has_async_visual_viewport_transform())
+ m_scene.drop_async_visual_viewport_transform();
+ return;
+ }
+
+ auto transform = m_scene.current_visual_context_tree().visual_viewport_transform();
+ auto scale = state.value().scale;
+ transform.matrix[0, 0] = scale;
+ transform.matrix[1, 1] = scale;
+ transform.matrix[0, 3] = -state.value().scroll_offset.x() * scale;
+ transform.matrix[1, 3] = -state.value().scroll_offset.y() * scale;
+ m_scene.set_async_visual_viewport_transform(transform);
+}
+
Optional<Gfx::FloatPoint> ContextState::reapply_unreconciled_async_scroll_offsets()
{
Optional<Gfx::FloatPoint> viewport_scroll_offset;
@@ -2003,6 +2047,7 @@ Optional<PendingFrame> ContextState::apply_scrollbar_drag(ScrollbarController::D
.compositor_scroll_offset = *new_scroll_offset,
.unadopted_scroll_delta = *new_scroll_offset - *old_scroll_offset,
.last_relative_scroll_delta = {},
+ .visual_viewport_scale = {},
});
store_pending_async_scroll_offsets(scroll_offsets);
diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.h
index 08aecae0e2f..26d70588627 100644
--- a/Services/Compositor/ContextState.h
+++ b/Services/Compositor/ContextState.h
@@ -131,6 +131,7 @@ public:
void request_rendering_update();
void dispatch_mouse_event_to_web_content(Web::MouseEvent const&, bool nested_context_scrolled_since_last_frame = false);
void dispatch_key_event_to_web_content(Web::KeyEvent const&);
+ void dispatch_pinch_event_to_web_content(Web::PinchEvent const&);
// Whether the scroll offsets here moved past those of the last frame WebContent presented.
bool scrolled_since_last_frame() const;
bool can_dispatch_input_to_web_content() const { return m_page_id.has_value(); }
@@ -269,6 +270,7 @@ private:
Compositing::ScrollStateSnapshot scroll_state_snapshot_at_keyboard_step_starts() const;
void adopt_keyboard_scroll_state(Compositing::KeyboardScrollState);
Optional<VisualViewportScrollDelta> apply_visual_viewport_scroll_delta(Gfx::FloatPoint);
+ void reapply_unadopted_visual_viewport_state();
// Pans the visual viewport of a zoomed page by as much of a delta in screen pixels as it has room for, and returns
// that part of the delta.
Gfx::FloatPoint pan_visual_viewport_by(Gfx::FloatPoint delta_in_screen_pixels);
diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp
index 0c3dd25e7b4..e29bc090f45 100644
--- a/Services/WebContent/ConnectionFromClient.cpp
+++ b/Services/WebContent/ConnectionFromClient.cpp
@@ -460,6 +460,9 @@ void ConnectionFromClient::connect_to_compositor_process(IPC::TransportHandle ha
m_compositor_connection->on_key_event = [this](Web::PageId page_id, Web::KeyEvent event) {
key_event(page_id, move(event));
};
+ m_compositor_connection->on_pinch_event = [this](Web::PageId page_id, Web::PinchEvent event) {
+ pinch_event(page_id, event);
+ };
m_compositor_connection->on_compositor_lost = [this] {
m_page_host->compositor_process_lost();
};
@@ -952,7 +955,8 @@ void ConnectionFromClient::pinch_event(Web::PageId page_id, Web::PinchEvent even
// to applying each zoom in sequence.
if (!m_input_event_queue.is_empty() && m_input_event_queue.tail().page_id == page_id) {
if (auto const* pinch_event = m_input_event_queue.tail().event.get_pointer<Web::PinchEvent>()) {
- if (pinch_event->position != event.position || pinch_event->modifiers != event.modifiers)
+ if (pinch_event->position != event.position || pinch_event->modifiers != event.modifiers
+ || pinch_event->async_zoom_performed_default_action != event.async_zoom_performed_default_action)
return enqueue_input_event({ page_id, move(event), {}, {} });
event.scale_delta = (1.0 + pinch_event->scale_delta) * (1.0 + event.scale_delta) - 1.0;
diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cpp
index 40de7b9f511..9780dc3fe16 100644
--- a/Services/WebContent/PageClient.cpp
+++ b/Services/WebContent/PageClient.cpp
@@ -1692,6 +1692,11 @@ void PageClient::page_did_request_webdriver_mouse_event(Web::HTML::CrossProcessI
client().async_did_request_webdriver_mouse_event(m_id, request_id, local_root_id, move(event));
}
+void PageClient::page_did_request_pinch_event_for_testing(Web::HTML::CrossProcessId local_root_id, Web::PinchEvent const& event)
+{
+ client().async_did_request_pinch_event_for_testing(m_id, local_root_id, event);
+}
+
void PageClient::did_handle_webdriver_mouse_event(u64 request_id)
{
if (auto on_handled = m_pending_webdriver_mouse_events.take(request_id); on_handled.has_value())
diff --git a/Services/WebContent/PageClient.h b/Services/WebContent/PageClient.h
index 37526aa609f..a6af1a46212 100644
--- a/Services/WebContent/PageClient.h
+++ b/Services/WebContent/PageClient.h
@@ -317,6 +317,7 @@ private:
virtual void page_did_change_focused_navigable(Web::HTML::CrossProcessId) override;
virtual void page_did_request_key_event_for_testing(Web::KeyEvent) override;
virtual void page_did_request_webdriver_mouse_event(Web::HTML::CrossProcessId local_root_id, Web::MouseEvent, GC::Ref<GC::Function<void()>> on_handled) override;
+ virtual void page_did_request_pinch_event_for_testing(Web::HTML::CrossProcessId local_root_id, Web::PinchEvent const&) override;
virtual void page_did_request_set_system_visibility_state(Web::HTML::VisibilityState) override;
virtual void page_did_request_history_operation(Web::HTML::CrossProcessId operation_id, Web::HistoryOperationParameters) override;
virtual void page_did_revoke_history_operation(Web::HTML::CrossProcessId operation_id) override;
diff --git a/Services/WebContent/WebContentClient.ipc b/Services/WebContent/WebContentClient.ipc
index abc96929415..633de920bb4 100644
--- a/Services/WebContent/WebContentClient.ipc
+++ b/Services/WebContent/WebContentClient.ipc
@@ -258,6 +258,7 @@ endpoint WebContentClient routed by Web::PageId page_id
did_request_key_event_for_testing(Web::PageId page_id, Web::KeyEvent event) =|
did_request_spelling_menu_action_for_testing(Web::PageId page_id, Web::SpellingMenuActionForTesting action, u32 guess_index) =|
did_request_webdriver_mouse_event(Web::PageId page_id, u64 request_id, Web::HTML::CrossProcessId local_root_id, Web::MouseEvent event) =|
+ did_request_pinch_event_for_testing(Web::PageId page_id, Web::HTML::CrossProcessId local_root_id, Web::PinchEvent event) =|
did_request_set_system_visibility_state(Web::PageId page_id, Web::HTML::VisibilityState visibility_state) =|
request_history_operation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id, Web::HistoryOperationParameters parameters) =|
revoke_history_operation(Web::PageId page_id, Web::HTML::CrossProcessId operation_id) =|
diff --git a/Tests/Compositor/TestContextState.cpp b/Tests/Compositor/TestContextState.cpp
index c23312bdbdb..9b57c1e42c3 100644
--- a/Tests/Compositor/TestContextState.cpp
+++ b/Tests/Compositor/TestContextState.cpp
@@ -16,6 +16,7 @@ class NullWebContentClient final : public Compositor::CompositorStateWebContentC
public:
virtual void dispatch_mouse_event_to_web_content(u64, Web::MouseEvent const&) override { }
virtual void dispatch_key_event_to_web_content(u64, Web::KeyEvent const&) override { }
+ virtual void dispatch_pinch_event_to_web_content(u64, Web::PinchEvent const&) override { }
virtual void request_rendering_update() override { }
virtual void rendering_opportunity(Web::CompositorContextId, i64, double) override { }
virtual void clock_tick(Web::CompositorContextId, i64, double, Vector<Web::CompositorScrollOffset> const&) override { }
@@ -29,13 +30,15 @@ public:
static Web::UniqueNodeID const document_id { 7 };
// A display list of a page whose viewport cannot be scrolled, so it records no scroll node.
-static void install_display_list_without_scroll_nodes(Compositor::ContextState& context)
+static void install_display_list_without_scroll_nodes(Compositor::ContextState& context, u64 adopted_async_scroll_sequence = 0)
{
Compositing::VisualContextTreeTestBuilder builder;
auto visual_context_tree = builder.finish();
auto display_list = Compositing::DisplayList::create(visual_context_tree);
display_list->set_async_scrolling_metadata({ .document_id = document_id, .viewport_rect = { 0, 0, 800, 600 } });
- context.install_display_list_update(display_list, move(visual_context_tree), {});
+ Compositing::ScrollStateSnapshot scroll_state_snapshot;
+ scroll_state_snapshot.set_adopted_async_scroll_sequence(adopted_async_scroll_sequence);
+ context.install_display_list_update(display_list, move(visual_context_tree), move(scroll_state_snapshot));
}
static Web::PinchEvent pinch_event(double scale_delta)
@@ -73,6 +76,44 @@ TEST_CASE(pinch_zoom_of_a_page_without_scroll_nodes_survives_a_display_list_upda
EXPECT(!context.handle_pinch_event(pinch_event(1.0)).accepted);
}
+TEST_CASE(pinch_zoom_is_reported_on_the_visual_viewport)
+{
+ NullWebContentClient client;
+ Compositor::CanvasSurfaceRegistry canvas_surface_registry;
+ Compositor::ContextState context { Web::CompositorContextId { 1 }, 1, client, Compositor::OwnedCanvasSurfaces { canvas_surface_registry, client.canvas_surface_owner_id() } };
+ install_display_list_without_scroll_nodes(context);
+
+ // Zooming in 2x around the middle of the viewport moves the visual viewport to the middle of the page.
+ EXPECT(context.handle_pinch_event(pinch_event(1.0)).accepted);
+ auto updates = context.take_pending_async_scroll_updates();
+ EXPECT_EQ(updates.scroll_offsets.size(), 1u);
+ auto const& scroll_offset = updates.scroll_offsets.first();
+ EXPECT_EQ(scroll_offset.stable_node_id.node_id, document_id);
+ EXPECT(scroll_offset.stable_node_id.kind == Web::AsyncScrollNodeKind::VisualViewport);
+ EXPECT_EQ(scroll_offset.visual_viewport_scale, 2.0f);
+ EXPECT_EQ(scroll_offset.compositor_scroll_offset, Gfx::FloatPoint(200, 150));
+ EXPECT_EQ(scroll_offset.unadopted_scroll_delta, Gfx::FloatPoint(200, 150));
+}
+
+TEST_CASE(pinch_zoom_is_presented_until_the_main_thread_adopts_it)
+{
+ NullWebContentClient client;
+ Compositor::CanvasSurfaceRegistry canvas_surface_registry;
+ Compositor::ContextState context { Web::CompositorContextId { 1 }, 1, client, Compositor::OwnedCanvasSurfaces { canvas_surface_registry, client.canvas_surface_owner_id() } };
+ install_display_list_without_scroll_nodes(context);
+
+ EXPECT(context.handle_pinch_event(pinch_event(4.0)).accepted);
+ auto updates = context.take_pending_async_scroll_updates();
+
+ // A display list recorded before the main thread adopted the zoom keeps it at its maximum.
+ install_display_list_without_scroll_nodes(context, updates.sequence - 1);
+ EXPECT(!context.handle_pinch_event(pinch_event(1.0)).accepted);
+
+ // Once the main thread has adopted the zoom, its display list says where the visual viewport is, here reset since.
+ install_display_list_without_scroll_nodes(context, updates.sequence);
+ EXPECT(context.handle_pinch_event(pinch_event(1.0)).accepted);
+}
+
TEST_CASE(wheel_pans_the_zoomed_visual_viewport_of_a_page_without_scroll_nodes)
{
NullWebContentClient client;
@@ -90,6 +131,7 @@ TEST_CASE(wheel_pans_the_zoomed_visual_viewport_of_a_page_without_scroll_nodes)
EXPECT(!context.handle_wheel_event(wheel_event).accepted);
EXPECT(context.handle_pinch_event(pinch_event(1.0)).accepted);
+ (void)context.take_pending_async_scroll_updates();
auto result = context.handle_wheel_event(wheel_event);
EXPECT(result.accepted);
EXPECT(result.frame_to_present.has_value());
diff --git a/Tests/LibWeb/Text/expected/async-scrolling/pinch-wheel-event-cancelability.txt b/Tests/LibWeb/Text/expected/async-scrolling/pinch-wheel-event-cancelability.txt
new file mode 100644
index 00000000000..a7fea741b68
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/async-scrolling/pinch-wheel-event-cancelability.txt
@@ -0,0 +1,2 @@
+passive listener: ctrlKey=true cancelable=false scale=2
+canceling listener: ctrlKey=true cancelable=true defaultPrevented=true scale=1 compositor scale=1
diff --git a/Tests/LibWeb/Text/expected/async-scrolling/pinch-wheel-event-sees-the-compositor-zoom.txt b/Tests/LibWeb/Text/expected/async-scrolling/pinch-wheel-event-sees-the-compositor-zoom.txt
new file mode 100644
index 00000000000..d834708b3af
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/async-scrolling/pinch-wheel-event-sees-the-compositor-zoom.txt
@@ -0,0 +1 @@
+listener: scale=2 offset=200,150
diff --git a/Tests/LibWeb/Text/expected/async-scrolling/pinch-zoom-through-compositor.txt b/Tests/LibWeb/Text/expected/async-scrolling/pinch-zoom-through-compositor.txt
new file mode 100644
index 00000000000..05f0456d64e
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/async-scrolling/pinch-zoom-through-compositor.txt
@@ -0,0 +1,2 @@
+after the pinch: scale=2 offset=200,150 compositor scale=2
+after resetting the zoom: scale=1 offset=0,0 compositor scale=1
diff --git a/Tests/LibWeb/Text/input/async-scrolling/pinch-wheel-event-cancelability.html b/Tests/LibWeb/Text/input/async-scrolling/pinch-wheel-event-cancelability.html
new file mode 100644
index 00000000000..7ba10b0b32d
--- /dev/null
+++ b/Tests/LibWeb/Text/input/async-scrolling/pinch-wheel-event-cancelability.html
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<style>
+ body {
+ margin: 0;
+ height: 3000px;
+ }
+</style>
+<script>
+ promiseTest(async () => {
+ await animationFrame();
+ await animationFrame();
+
+ const vv = window.visualViewport;
+ const nextWheelEvent = (options, handler = () => {}) => new Promise(resolve => {
+ window.addEventListener("wheel", event => {
+ handler(event);
+ resolve(event);
+ }, { ...options, once: true });
+ });
+
+ // A passive listener does not hold the pinch back, so the compositor zooms before the page sees the event,
+ // which can then no longer be canceled.
+ let wheelEvent = nextWheelEvent({ passive: true });
+ internals.pinchThroughUIProcess(400, 300, 1.0);
+ let event = await wheelEvent;
+ while (vv.scale === 1)
+ await animationFrame();
+ println(`passive listener: ctrlKey=${event.ctrlKey} cancelable=${event.cancelable} scale=${vv.scale}`);
+
+ internals.resetZoom();
+ await animationFrame();
+ await animationFrame();
+
+ // A listener that may cancel the event holds the pinch back until the page has seen it, and canceling it keeps
+ // the page from zooming.
+ wheelEvent = nextWheelEvent({ passive: false }, event => event.preventDefault());
+ await animationFrame();
+ await animationFrame();
+ internals.pinchThroughUIProcess(400, 300, 1.0);
+ event = await wheelEvent;
+ await animationFrame();
+ await animationFrame();
+ println(`canceling listener: ctrlKey=${event.ctrlKey} cancelable=${event.cancelable} defaultPrevented=${event.defaultPrevented} scale=${vv.scale} compositor scale=${internals.compositorScrollState().visualViewportScale}`);
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/async-scrolling/pinch-wheel-event-sees-the-compositor-zoom.html b/Tests/LibWeb/Text/input/async-scrolling/pinch-wheel-event-sees-the-compositor-zoom.html
new file mode 100644
index 00000000000..71b334ad057
--- /dev/null
+++ b/Tests/LibWeb/Text/input/async-scrolling/pinch-wheel-event-sees-the-compositor-zoom.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<style>
+ body {
+ margin: 0;
+ height: 3000px;
+ }
+</style>
+<script>
+ promiseTest(async () => {
+ await animationFrame();
+ await animationFrame();
+
+ const vv = window.visualViewport;
+ let seenByListener;
+ const wheelEvent = new Promise(resolve => {
+ window.addEventListener("wheel", event => {
+ seenByListener = `scale=${vv.scale} offset=${vv.offsetLeft},${vv.offsetTop}`;
+ resolve(event);
+ }, { passive: true, once: true });
+ });
+
+ // The compositor zooms before the page sees the event of a pinch no listener can cancel, so the page sees the
+ // zoom it was already shown.
+ internals.pinchThroughUIProcess(400, 300, 1.0);
+ await wheelEvent;
+ println(`listener: ${seenByListener}`);
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/async-scrolling/pinch-zoom-through-compositor.html b/Tests/LibWeb/Text/input/async-scrolling/pinch-zoom-through-compositor.html
new file mode 100644
index 00000000000..bbbc3bb364e
--- /dev/null
+++ b/Tests/LibWeb/Text/input/async-scrolling/pinch-zoom-through-compositor.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<style>
+ body {
+ margin: 0;
+ height: 3000px;
+ }
+</style>
+<script>
+ promiseTest(async () => {
+ await animationFrame();
+ await animationFrame();
+
+ const vv = window.visualViewport;
+ const state = label => {
+ println(`${label}: scale=${vv.scale} offset=${vv.offsetLeft},${vv.offsetTop} compositor scale=${internals.compositorScrollState().visualViewportScale}`);
+ };
+
+ // The compositor zooms for the pinch, and the main thread takes its zoom rather than zooming a second time.
+ internals.pinchThroughUIProcess(400, 300, 1.0);
+ while (vv.scale === 1)
+ await animationFrame();
+ await animationFrame();
+ await animationFrame();
+ state("after the pinch");
+
+ // Once the main thread has adopted the zoom, the compositor presents whatever the main thread sets it to.
+ internals.resetZoom();
+ await animationFrame();
+ await animationFrame();
+ state("after resetting the zoom");
+ });
+</script>