Skip to content

Truly independent web browser

LibWeb+Compositor: Add internals.beginInputTrace() and takeInputTrace()

Aliaksandr Kalenikb4b38432a54a
diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.cpp b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
index 41ec6d93085..d5f00450d7c 100644
--- a/Libraries/LibWeb/Compositor/CompositorConnection.cpp
+++ b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
@@ -451,6 +451,26 @@ Gfx::FloatPoint CompositorConnection::elastic_overscroll_stretch_for_testing(Web
return response->stretch();
}
+void CompositorConnection::begin_input_trace_for_testing(Web::CompositorContextId context_id)
+{
+ if (!can_send_message_to_compositor())
+ return;
+ if (!send_sync_but_allow_failure<Messages::CompositorWebContentServer::BeginInputTraceForTesting>(context_id))
+ did_lose_compositor();
+}
+
+Vector<Web::InputTraceRecord> CompositorConnection::take_input_trace_for_testing(Web::CompositorContextId context_id)
+{
+ if (!can_send_message_to_compositor())
+ return {};
+ auto response = send_sync_but_allow_failure<Messages::CompositorWebContentServer::TakeInputTraceForTesting>(context_id);
+ if (!response) {
+ did_lose_compositor();
+ return {};
+ }
+ return response->take_records();
+}
+
void CompositorConnection::cancel_smooth_scroll(Web::CompositorContextId context_id, Web::AsyncScrollNodeStableID stable_node_id)
{
if (!can_send_message_to_compositor())
diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.h b/Libraries/LibWeb/Compositor/CompositorConnection.h
index 14d4f30c59c..0d04a698898 100644
--- a/Libraries/LibWeb/Compositor/CompositorConnection.h
+++ b/Libraries/LibWeb/Compositor/CompositorConnection.h
@@ -71,6 +71,8 @@ public:
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);
Gfx::FloatPoint elastic_overscroll_stretch_for_testing(Web::CompositorContextId, Web::AsyncScrollNodeStableID);
+ void begin_input_trace_for_testing(Web::CompositorContextId);
+ Vector<Web::InputTraceRecord> take_input_trace_for_testing(Web::CompositorContextId);
Compositing::PendingAsyncScrollUpdates take_pending_async_scroll_updates(Web::CompositorContextId, Compositing::AsyncScrollUpdateFreshness);
void viewport_size_updated(Web::CompositorContextId, Gfx::IntSize, Compositing::WindowResizingInProgress);
bool request_rendering_opportunity(Web::CompositorContextId, double maximum_frames_per_second);
diff --git a/Libraries/LibWeb/Compositor/CompositorHost.cpp b/Libraries/LibWeb/Compositor/CompositorHost.cpp
index 3ca81551b52..05c8e94dca3 100644
--- a/Libraries/LibWeb/Compositor/CompositorHost.cpp
+++ b/Libraries/LibWeb/Compositor/CompositorHost.cpp
@@ -83,6 +83,16 @@ Gfx::FloatPoint CompositorContextHandle::elastic_overscroll_stretch_for_testing(
return m_host.elastic_overscroll_stretch_for_testing(m_context_id, stable_node_id);
}
+void CompositorContextHandle::begin_input_trace_for_testing()
+{
+ m_host.begin_input_trace_for_testing(m_context_id);
+}
+
+Vector<Web::InputTraceRecord> CompositorContextHandle::take_input_trace_for_testing()
+{
+ return m_host.take_input_trace_for_testing(m_context_id);
+}
+
Compositing::PendingAsyncScrollUpdates CompositorContextHandle::take_pending_async_scroll_updates(Compositing::AsyncScrollUpdateFreshness freshness)
{
return m_host.take_pending_async_scroll_updates(m_context_id, freshness);
@@ -436,6 +446,19 @@ Gfx::FloatPoint CompositorHost::elastic_overscroll_stretch_for_testing(Web::Comp
return {};
}
+void CompositorHost::begin_input_trace_for_testing(Web::CompositorContextId context_id)
+{
+ if (auto* connection = compositor_connection())
+ connection->begin_input_trace_for_testing(context_id);
+}
+
+Vector<Web::InputTraceRecord> CompositorHost::take_input_trace_for_testing(Web::CompositorContextId context_id)
+{
+ if (auto* connection = compositor_connection())
+ return connection->take_input_trace_for_testing(context_id);
+ return {};
+}
+
Compositing::PendingAsyncScrollUpdates CompositorHost::take_pending_async_scroll_updates(Web::CompositorContextId context_id, Compositing::AsyncScrollUpdateFreshness freshness)
{
if (auto* connection = compositor_connection())
diff --git a/Libraries/LibWeb/Compositor/CompositorHost.h b/Libraries/LibWeb/Compositor/CompositorHost.h
index 0c1fcf57271..4eef1f2e80c 100644
--- a/Libraries/LibWeb/Compositor/CompositorHost.h
+++ b/Libraries/LibWeb/Compositor/CompositorHost.h
@@ -22,6 +22,7 @@
#include <LibMedia/VideoSinkHandle.h>
#include <LibWeb/Export.h>
#include <LibWeb/Forward.h>
+#include <LibWebCommon/Page/InputTrace.h>
namespace Web::Compositor {
@@ -61,6 +62,8 @@ public:
Compositing::AsyncScrollEnqueueResult smooth_scroll_to(Web::AsyncScrollNodeStableID, Gfx::FloatPoint offset_in_device_pixels, Gfx::FloatPoint main_thread_offset_in_device_pixels, Gfx::IntRect viewport_rect, Compositing::ScrollAnimationKind, Compositing::SmoothScrollInitiator, Optional<Compositing::AsyncScrollOperationID> operation_to_continue);
void cancel_smooth_scroll(Web::AsyncScrollNodeStableID);
Gfx::FloatPoint elastic_overscroll_stretch_for_testing(Web::AsyncScrollNodeStableID);
+ void begin_input_trace_for_testing();
+ Vector<Web::InputTraceRecord> take_input_trace_for_testing();
Compositing::PendingAsyncScrollUpdates take_pending_async_scroll_updates(Compositing::AsyncScrollUpdateFreshness);
void viewport_size_updated(Gfx::IntSize, Compositing::WindowResizingInProgress);
bool request_rendering_opportunity(double maximum_frames_per_second);
@@ -119,6 +122,8 @@ public:
Compositing::AsyncScrollEnqueueResult smooth_scroll_to(Web::CompositorContextId, Web::AsyncScrollNodeStableID, Gfx::FloatPoint offset_in_device_pixels, Gfx::FloatPoint main_thread_offset_in_device_pixels, Gfx::IntRect viewport_rect, Compositing::ScrollAnimationKind, Compositing::SmoothScrollInitiator, Optional<Compositing::AsyncScrollOperationID> operation_to_continue);
void cancel_smooth_scroll(Web::CompositorContextId, Web::AsyncScrollNodeStableID);
Gfx::FloatPoint elastic_overscroll_stretch_for_testing(Web::CompositorContextId, Web::AsyncScrollNodeStableID);
+ void begin_input_trace_for_testing(Web::CompositorContextId);
+ Vector<Web::InputTraceRecord> take_input_trace_for_testing(Web::CompositorContextId);
Compositing::PendingAsyncScrollUpdates take_pending_async_scroll_updates(Web::CompositorContextId, Compositing::AsyncScrollUpdateFreshness);
void viewport_size_updated(Web::CompositorContextId, Gfx::IntSize, Compositing::WindowResizingInProgress);
bool request_rendering_opportunity(Web::CompositorContextId, double maximum_frames_per_second);
diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
index 6e412950ee5..0d41ce32325 100644
--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
@@ -362,6 +362,21 @@ bool EventLoop::rendering_opportunity(HighResolutionTime::DOMHighResTimeStamp fr
return true;
}
+static InputRoutingDecision input_routing_decision_for_finished_input_event(EventResult result)
+{
+ switch (result) {
+ case EventResult::Accepted:
+ return InputRoutingDecision::FinishedAccepted;
+ case EventResult::Handled:
+ return InputRoutingDecision::FinishedHandled;
+ case EventResult::Dropped:
+ return InputRoutingDecision::FinishedDropped;
+ case EventResult::Cancelled:
+ return InputRoutingDecision::FinishedCancelled;
+ }
+ VERIFY_NOT_REACHED();
+}
+
void EventLoop::process_input_events() const
{
auto process_input_events_queue = [&](Page& page) {
@@ -371,6 +386,18 @@ void EventLoop::process_input_events() const
// Process events only for this page, collecting others to re-enqueue
Queue<Web::QueuedInputEvent> events_for_other_pages;
+ auto record_routing = [&](u64 event_id, InputRoutingDecision decision) {
+ page.input_trace().record({ .input_event_id = event_id, .stage = InputTraceStage::WebContent, .decision = decision });
+ };
+ auto finish_handling_input_event = [&](u64 event_id, EventResult result, InputRoutingDecision decision) {
+ record_routing(event_id, decision);
+ page_client.report_finished_handling_input_event(page_client.id(), event_id, result);
+ };
+ auto finish_handling_coalesced_input_events = [&](QueuedInputEvent const& event) {
+ for (auto coalesced_event_id : event.coalesced_event_ids)
+ finish_handling_input_event(coalesced_event_id, EventResult::Dropped, InputRoutingDecision::CoalescedIntoLaterEvent);
+ };
+
while (!input_events_queue.is_empty()) {
auto event = input_events_queue.dequeue();
@@ -391,9 +418,8 @@ void EventLoop::process_input_events() const
root = page.local_traversable();
if (!root) {
- for (auto coalesced_event_id : event.coalesced_event_ids)
- page_client.report_finished_handling_input_event(event.page_id, coalesced_event_id, EventResult::Dropped);
- page_client.report_finished_handling_input_event(event.page_id, input_event_id(event.event), EventResult::Dropped);
+ finish_handling_coalesced_input_events(event);
+ finish_handling_input_event(input_event_id(event.event), EventResult::Dropped, InputRoutingDecision::DroppedWithoutLocalRoot);
continue;
}
@@ -409,9 +435,8 @@ void EventLoop::process_input_events() const
input_is_outdated = arena && Layout::RustFFI::document_host_mouse_event_is_outdated(arena->host(), mouse_event->id);
// A move with a button held is a drag's, whose script hears every move: it is handled, as outdated.
if (input_is_outdated && mouse_event->buttons == 0 && first_is_one_of(mouse_event->type, Web::MouseEvent::Type::MouseMove, Web::MouseEvent::Type::MouseLeave)) {
- for (auto coalesced_event_id : event.coalesced_event_ids)
- page_client.report_finished_handling_input_event(event.page_id, coalesced_event_id, EventResult::Dropped);
- page_client.report_finished_handling_input_event(event.page_id, mouse_event->id, EventResult::Dropped);
+ finish_handling_coalesced_input_events(event);
+ finish_handling_input_event(mouse_event->id, EventResult::Dropped, InputRoutingDecision::DroppedOutdatedPointerMove);
continue;
}
}
@@ -460,12 +485,12 @@ void EventLoop::process_input_events() const
return page.handle_pinch_event(*root, pinch_event.position, pinch_event.modifiers, pinch_event.scale_delta);
});
- for (auto coalesced_event_id : event.coalesced_event_ids)
- page_client.report_finished_handling_input_event(event.page_id, coalesced_event_id, EventResult::Dropped);
+ finish_handling_coalesced_input_events(event);
// The pointer is over content another process hosts: that process handles the event, at the position in
// the viewport of the navigable it hosts, and finishes it.
if (remote_target.has_value()) {
+ record_routing(input_event_id(event.event), InputRoutingDecision::ForwardedToRemoteFrame);
auto mouse_event = event.event.get<Web::MouseEvent>().clone_without_browser_data();
mouse_event.position = page.css_to_device_point(remote_target->position);
page_client.forward_mouse_event_to_remote_navigable(event.page_id, remote_target->navigable_id, move(mouse_event));
@@ -473,7 +498,7 @@ void EventLoop::process_input_events() const
}
page_client.did_handle_input_event(event.page_id, event.event);
- page_client.report_finished_handling_input_event(event.page_id, input_event_id(event.event), result);
+ finish_handling_input_event(input_event_id(event.event), result, input_routing_decision_for_finished_input_event(result));
}
// Re-enqueue events for other pages
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp
index 6c2531937c3..64d44fe5ac3 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -1227,6 +1227,69 @@ Utf16String Internals::take_display_list_trace()
return Utf16String::from_utf8_without_validation(builder.string_view());
}
+// The compositor context that the UI routes this page's input through.
+static Compositor::CompositorContextHandle* compositor_context_routing_input_for(HTML::Window& window)
+{
+ auto local_root = window.navigable()->local_root();
+ if (!local_root->has_compositor_context())
+ return nullptr;
+ return &local_root->compositor_context();
+}
+
+void Internals::begin_input_trace()
+{
+ page().input_trace().begin();
+ if (auto* compositor_context = compositor_context_routing_input_for(window()))
+ compositor_context->begin_input_trace_for_testing();
+}
+
+static Vector<InputTraceRecord> take_input_trace_records(HTML::Window& window)
+{
+ Vector<InputTraceRecord> records;
+ if (auto* compositor_context = compositor_context_routing_input_for(window))
+ records.extend(compositor_context->take_input_trace_for_testing());
+ records.extend(window.page().input_trace().take());
+
+ // The compositor sees each input event from the UI before this process does. Events in UI order, and within
+ // an event the compositor's records first, read as the way the event went. Input that did not come from the UI
+ // goes last.
+ auto ui_order = [](InputTraceRecord const& record) {
+ return record.input_event_id == 0 ? NumericLimits<u64>::max() : record.input_event_id;
+ };
+ insertion_sort(records, [&](auto const& a, auto const& b) { return ui_order(a) < ui_order(b); });
+ return records;
+}
+
+GC::Ref<JS::Object> Internals::take_input_trace()
+{
+ auto records = take_input_trace_records(window());
+ auto& realm = HTML::relevant_realm(window());
+ auto& wrapper_world = Bindings::host_defined_wrapper_world(realm);
+ auto wrapped_node = [&](UniqueNodeID node_id) -> JS::Value {
+ auto* node = DOM::Node::from_unique_id(node_id);
+ if (!node)
+ return JS::js_null();
+ return Bindings::wrap(wrapper_world, realm, GC::Ref<DOM::Node> { *node });
+ };
+
+ auto array = MUST(JS::Array::create(realm, records.size()));
+ for (size_t i = 0; i < records.size(); ++i) {
+ auto const& record = records[i];
+ auto object = JS::Object::create(realm, nullptr);
+ object->define_direct_property("id"_utf16_fly_string, JS::Value(static_cast<double>(record.input_event_id)), JS::default_attributes);
+ object->define_direct_property("stage"_utf16_fly_string, JS::PrimitiveString::create(vm(), input_trace_stage_name(record.stage)), JS::default_attributes);
+ object->define_direct_property("decision"_utf16_fly_string, JS::PrimitiveString::create(vm(), input_routing_decision_name(record.decision)), JS::default_attributes);
+ object->define_direct_property("scroller"_utf16_fly_string, record.scroller.has_value() ? wrapped_node(record.scroller->node_id) : JS::js_null(), JS::default_attributes);
+ if (record.scroller.has_value() && record.scroller->kind == AsyncScrollNodeKind::PseudoElement) {
+ auto pseudo_element = CSS::pseudo_element_name(static_cast<CSS::PseudoElement>(record.scroller->pseudo_element_type));
+ object->define_direct_property("scrollerPseudoElement"_utf16_fly_string, JS::PrimitiveString::create(vm(), pseudo_element), JS::default_attributes);
+ }
+ object->define_direct_property("target"_utf16_fly_string, record.dom_target.has_value() ? wrapped_node(*record.dom_target) : JS::js_null(), JS::default_attributes);
+ MUST(array->create_data_property_or_throw(i, object));
+ }
+ return array;
+}
+
bool Internals::recorded_display_list_blocks_wheel_event_at(double x, double y)
{
// A script reads the render state, which waits for a frame in flight.
@@ -1666,6 +1729,8 @@ void Internals::perform_per_test_cleanup()
// Clear any input state
if (auto local_root = local_root_of(window()))
local_root->event_handler().clear_per_test_input_state({});
+ if (page().input_trace().is_recording())
+ (void)take_input_trace_records(window());
// Restore the page to the visible state.
page().client().page_did_request_set_system_visibility_state(HTML::VisibilityState::Visible);
diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.h
index 62ccf2c3206..cf4e528a4dd 100644
--- a/Libraries/LibWeb/Internals/Internals.h
+++ b/Libraries/LibWeb/Internals/Internals.h
@@ -166,6 +166,8 @@ public:
WebIDL::UnsignedLongLong accumulated_visual_context_tree_build_count();
void begin_display_list_trace();
Utf16String take_display_list_trace();
+ void begin_input_trace();
+ GC::Ref<JS::Object> take_input_trace();
GC::Ref<JS::Object> recorded_async_scrolling_state_object();
bool recorded_display_list_blocks_wheel_event_at(double x, double y);
void record_display_list_for_testing(bool paint_overlay, bool cold);
diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idl
index 80fb7ac3945..83270a5fc11 100644
--- a/Libraries/LibWeb/Internals/Internals.idl
+++ b/Libraries/LibWeb/Internals/Internals.idl
@@ -158,6 +158,9 @@ interface Internals {
unsigned long long accumulatedVisualContextTreeBuildCount();
undefined beginDisplayListTrace();
DOMString takeDisplayListTrace();
+ // Records where the compositor and this process route each input event, and why, until takeInputTrace().
+ undefined beginInputTrace();
+ object takeInputTrace();
[ImplementedAs=recorded_async_scrolling_state_object] object recordedAsyncScrollingState();
boolean recordedDisplayListBlocksWheelEventAt(double x, double y);
undefined recordDisplayListForTesting(optional boolean paintOverlay = false, optional boolean cold = false);
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp
index 82490e84993..9e211b803f6 100644
--- a/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Libraries/LibWeb/Page/EventHandler.cpp
@@ -384,6 +384,7 @@ EventResult EventHandler::handle_mousedown(CSSPixelPoint visual_viewport_positio
if (!scrollbar)
return EventResult::Dropped;
scrollbar->begin_drag_driven_by_compositor();
+ record_input_routing(InputRoutingDecision::ScrollbarDragDrivenByCompositor, scrollbar_dragged_by_compositor->scroller_stable_node_id);
chrome_widget = scrollbar;
}
@@ -914,6 +915,20 @@ static Layout::Node* scroll_containing_block_chain_smoothly(HTML::LocalNavigable
return nullptr;
}
+void EventHandler::record_input_routing(InputRoutingDecision decision, Optional<AsyncScrollNodeStableID> scroller, GC::Ptr<DOM::Node const> target, InputTraceStage stage)
+{
+ auto& input_trace = m_navigable->page().input_trace();
+ if (!input_trace.is_recording())
+ return;
+ input_trace.record({
+ .input_event_id = handling_input_event_id(),
+ .stage = stage,
+ .decision = decision,
+ .scroller = scroller,
+ .dom_target = target ? target->unique_id() : Optional<UniqueNodeID> {},
+ });
+}
+
EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, u32 button, u32 buttons, u32 modifiers, double wheel_delta_x, double wheel_delta_y, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, bool async_scroll_performed_default_action, Optional<AsyncScrollOperation>* async_scroll_operation, Optional<RemoteInputEventTarget>* remote_target)
{
record_last_known_mouse_position(visual_viewport_position, screen_position, buttons, modifiers);
@@ -956,8 +971,10 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
if (display_list && root_document && root_document->has_paint_state()) {
Layout::ForcedReadScope root_read { *root_document };
root_document->update_paint_and_hit_testing_properties_if_needed();
- if (display_list->compatible_visual_context_tree_structural_epoch() != root_document->paint_state().visual_context_tree_structural_epoch_without_update(root_read))
+ if (display_list->compatible_visual_context_tree_structural_epoch() != root_document->paint_state().visual_context_tree_structural_epoch_without_update(root_read)) {
+ record_input_routing(InputRoutingDecision::AsyncScrollNotAttemptedDisplayListOutdated);
return false;
+ }
}
}
@@ -969,6 +986,7 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
: Compositing::AsyncScrollOperationTracking::No;
auto enqueue_result = m_navigable->compositor_context().async_scroll_by(
document->unique_id(), async_scroll_position, delta_in_device_pixels, viewport_rect, wheel_delta_precision, scroll_gesture_phase, modifiers, operation_tracking, wheel_step_dispatch, handling_input_event_id());
+ record_input_routing(enqueue_result.routing_decision.value_or(InputRoutingDecision::NoAnswerFromCompositor), enqueue_result.routed_scroller, {}, InputTraceStage::CompositorForMainThread);
if (enqueue_result.operation_id.has_value() && async_scroll_operation)
*async_scroll_operation = AsyncScrollOperation { m_navigable, *enqueue_result.operation_id };
dbgln_if(COMPOSITOR_DEBUG, "[Compositor] {} wheel async scroll at {},{} with device delta {},{}",
@@ -1047,8 +1065,10 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
auto async_scroll_delta_in_device_pixels = Gfx::FloatPoint { static_cast<float>(wheel_delta_x), static_cast<float>(wheel_delta_y) }.scaled(device_pixels_per_css_pixel);
if (can_attempt_async_scroll && async_scroll_performed_default_action) {
dbgln_if(COMPOSITOR_DEBUG, "[Compositor] Not attempting wheel async scroll: default action already performed");
+ record_input_routing(InputRoutingDecision::DefaultActionPerformedByCompositor);
} else if (can_attempt_async_scroll && visual_viewport->scale() != 1.0) {
dbgln_if(COMPOSITOR_DEBUG, "[Compositor] Not attempting wheel async scroll: visual viewport is scaled");
+ record_input_routing(InputRoutingDecision::AsyncScrollNotAttemptedVisualViewportScaled);
} else if (can_attempt_async_scroll) {
if (wheel_event_target_layout_node) {
async_scroll_performed_default_action = enqueue_async_scroll(async_scroll_delta_in_device_pixels, Compositing::WheelStepDispatch::NotYetDispatched);
@@ -1057,8 +1077,10 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
}
}
- if (!wheel_event_target_layout_node)
+ if (!wheel_event_target_layout_node) {
+ record_input_routing(InputRoutingDecision::NoWheelTarget);
return EventResult::Dropped;
+ }
auto scroll_viewport_by_wheel_delta = [&](DOM::Document& document, Painting::WheelScrollableAxes viewport_scrollable_axes) -> EventResult {
auto visual_viewport_pan_axes = visual_viewport_pan_axes_for_scroll_step(document, wheel_delta_x, wheel_delta_y);
@@ -1109,6 +1131,7 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
auto scrollable_axes = Painting::wheel_scrollable_axes(*latched_scrolling_box);
if (scrollable_axes.horizontal || scrollable_axes.vertical) {
scroll_latched_wheel_scrolling_box(*document, *latched_scrolling_box, scrollable_axes);
+ record_input_routing(InputRoutingDecision::MainThreadScrolledLatchedScroller, Painting::async_scroll_node_stable_id(*latched_scrolling_box));
return EventResult::Handled;
}
m_wheel_scroll_latch.clear();
@@ -1143,6 +1166,7 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
}
if (scrolled_box) {
latch_gesture_to_scrolling_box(*scrolled_box);
+ record_input_routing(InputRoutingDecision::MainThreadScrolledScroller, Painting::async_scroll_node_stable_id(*scrolled_box));
return EventResult::Handled;
}
}
@@ -1150,14 +1174,21 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
// A step that a box keeps to itself is handled even though nothing scrolled, so that neither the viewport
// nor a document this one is nested in scrolls by it. No scrolling box is latched: the next step may point
// along the other axis, which the box may well pass on.
- if (box_ending_scroll_chain && !box_ending_scroll_chain->is_viewport())
+ if (box_ending_scroll_chain && !box_ending_scroll_chain->is_viewport()) {
+ record_input_routing(InputRoutingDecision::ScrollKeptByOverscrollBehavior, Painting::async_scroll_node_stable_id(*box_ending_scroll_chain));
return EventResult::Handled;
+ }
auto viewport_scroll_result = scroll_viewport_by_wheel_delta(*document, Painting::wheel_scrollable_axes(*viewport_box));
- if (viewport_scroll_result == EventResult::Handled)
+ if (viewport_scroll_result == EventResult::Handled) {
latch_gesture_to_scrolling_box(*viewport_box);
- else if (box_ending_scroll_chain)
+ record_input_routing(InputRoutingDecision::MainThreadScrolledScroller, Painting::async_scroll_node_stable_id(*viewport_box));
+ } else if (box_ending_scroll_chain) {
+ record_input_routing(InputRoutingDecision::ScrollKeptByOverscrollBehavior, Painting::async_scroll_node_stable_id(*box_ending_scroll_chain));
return EventResult::Handled;
+ } else {
+ record_input_routing(InputRoutingDecision::MainThreadScrolledNothing);
+ }
return viewport_scroll_result;
};
@@ -1190,6 +1221,7 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
return event_handler.handle_mousewheel(position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, remote_target);
});
result.has_value()) {
+ record_input_routing(InputRoutingDecision::HandedToNestedNavigable, {}, wheel_event_target_node);
if (result.value() == EventResult::Handled) {
if (m_wheel_scroll_latch.has_value())
m_wheel_scroll_latch->gesture_handed_to_nested_navigable = true;
@@ -1213,6 +1245,10 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
auto is_cancelable = async_scroll_performed_default_action ? UIEvents::WheelEventIsCancelable::No : UIEvents::WheelEventIsCancelable::Yes;
auto dispatch_result = dispatch_wheel_event(read, *wheel_event_target_layout_node, visual_viewport_position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, is_cancelable == UIEvents::WheelEventIsCancelable::Yes);
+ if (dispatch_result == EventResult::Accepted)
+ record_input_routing(InputRoutingDecision::DispatchedWheelEvent, {}, wheel_event_target_node);
+ else if (dispatch_result == EventResult::Cancelled)
+ record_input_routing(InputRoutingDecision::PageCanceledWheelEvent, {}, wheel_event_target_node);
// A listener that cancels the event scrolls by itself, so the next event is targeted afresh.
if (dispatch_result == EventResult::Cancelled)
m_wheel_scroll_latch.clear();
diff --git a/Libraries/LibWeb/Page/EventHandler.h b/Libraries/LibWeb/Page/EventHandler.h
index 59ca2c0bdbc..2b50eae6c56 100644
--- a/Libraries/LibWeb/Page/EventHandler.h
+++ b/Libraries/LibWeb/Page/EventHandler.h
@@ -30,6 +30,7 @@
#include <LibWebCommon/Gamepad/GamepadSnapshot.h>
#include <LibWebCommon/Page/EventResult.h>
#include <LibWebCommon/Page/InputEvent.h>
+#include <LibWebCommon/Page/InputTrace.h>
#include <LibWebCommon/Page/QueuedInputEvent.h>
#include <LibWebCommon/PixelUnits.h>
#include <LibWebCommon/UIEvents/KeyCode.h>
@@ -124,6 +125,7 @@ public:
private:
bool should_ignore_device_input_event() const;
+ void record_input_routing(InputRoutingDecision, Optional<AsyncScrollNodeStableID> scroller = {}, GC::Ptr<DOM::Node const> target = {}, InputTraceStage = InputTraceStage::WebContent);
GC::Ptr<DOM::Node> scroll_target_for_key_input() const;
int page_scroll_distance_for_key_input() const;
diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h
index ff8a2ff6e42..7153ba61bdd 100644
--- a/Libraries/LibWeb/Page/Page.h
+++ b/Libraries/LibWeb/Page/Page.h
@@ -84,6 +84,7 @@
#include <LibWebCommon/Page/ContextMenuForInputEventsTarget.h>
#include <LibWebCommon/Page/EventResult.h>
#include <LibWebCommon/Page/InputEvent.h>
+#include <LibWebCommon/Page/InputTrace.h>
#include <LibWebCommon/Page/MediaContextMenu.h>
#include <LibWebCommon/Page/NavigationTarget.h>
#include <LibWebCommon/Page/PageId.h>
@@ -383,6 +384,9 @@ public:
void did_complete_spelling_menu_action_for_testing(String menu);
Optional<ContextMenuRequest> take_context_menu_request();
+ // The routing decisions this process makes for input events, which a test can trace.
+ InputTraceRecorder& input_trace() { return m_input_trace; }
+
using MediaContextMenu = Web::MediaContextMenu;
void did_request_media_context_menu(UniqueNodeID media_id, HTML::CrossProcessId local_root_id, CSSPixelPoint, ByteString const& target, unsigned modifiers, MediaContextMenu const&, HTML::PreparedNavigationDescriptor);
void toggle_media_play_state();
@@ -563,6 +567,7 @@ private:
Web::HTML::MuteState m_mute_state { Web::HTML::MuteState::Unmuted };
Optional<ContextMenuRequest> m_context_menu_request;
+ InputTraceRecorder m_input_trace;
Optional<Editing::ContextMenuMisspelling> m_context_menu_misspelling;
HashTable<Utf16String> m_accepted_spelling_words;
GC::Ptr<GC::Function<void(String)>> m_on_spelling_menu_action_for_testing;
diff --git a/Libraries/LibWebCommon/CMakeLists.txt b/Libraries/LibWebCommon/CMakeLists.txt
index 9af250e4c78..a351d041e55 100644
--- a/Libraries/LibWebCommon/CMakeLists.txt
+++ b/Libraries/LibWebCommon/CMakeLists.txt
@@ -48,6 +48,7 @@ set(SOURCES
Page/DragEvent.cpp
Page/InputEvent.cpp
Page/InputRoutingDecision.cpp
+ Page/InputTrace.cpp
Page/MediaContextMenu.cpp
Page/SpellingError.cpp
PixelUnits.cpp
diff --git a/Libraries/LibWebCommon/Page/InputRoutingDecision.h b/Libraries/LibWebCommon/Page/InputRoutingDecision.h
index e7343024a9a..568e5b4937a 100644
--- a/Libraries/LibWebCommon/Page/InputRoutingDecision.h
+++ b/Libraries/LibWebCommon/Page/InputRoutingDecision.h
@@ -13,33 +13,59 @@
namespace Web {
// What decided where an input event went, and why, at one step of its way from the UI to the page.
-#define ENUMERATE_INPUT_ROUTING_DECISIONS(X) \
- X(ContextNotPresenting, "context-not-presenting") \
- X(NoAsyncScrollingState, "no-async-scrolling-state") \
- X(BlockingWheelEventListeners, "blocking-wheel-event-listeners") \
- X(NoScrollNode, "no-scroll-node") \
- X(StaleWheelEventListeners, "stale-wheel-event-listeners") \
- X(StepOvertakenByUI, "step-overtaken-by-ui") \
- X(GestureEndWithNothingToSnap, "gesture-end-with-nothing-to-snap") \
- X(SnappedAtGestureEnd, "snapped-at-gesture-end") \
- X(HitTestTargetsOfAnotherVisualContextTree, "hit-test-targets-of-another-visual-context-tree") \
- X(BlockedByMainThreadRegion, "blocked-by-main-thread-region") \
- X(BlockedByWheelEventRegion, "blocked-by-wheel-event-region") \
- X(NoScrollTarget, "no-scroll-target") \
- X(ScrollerInOtherDocument, "scroller-in-other-document") \
- X(StepWithoutDelta, "step-without-delta") \
- X(PannedVisualViewport, "panned-visual-viewport") \
- X(Latched, "latched") \
- X(LatchedOutermostScrollerToStretch, "latched-outermost-scroller-to-stretch") \
- X(ContinuedLatch, "continued-latch") \
- X(NotOverAScrollbar, "not-over-a-scrollbar") \
- X(NotPrimaryButton, "not-primary-button") \
- X(HoveringScrollbarPaintedByCompositor, "hovering-scrollbar-painted-by-compositor") \
- X(BeganScrollbarDrag, "began-scrollbar-drag") \
- X(ContinuedScrollbarDrag, "continued-scrollbar-drag") \
- X(EndedScrollbarDrag, "ended-scrollbar-drag") \
- X(NoScrollbarDrag, "no-scrollbar-drag") \
- X(LeftDuringScrollbarDrag, "left-during-scrollbar-drag")
+#define ENUMERATE_INPUT_ROUTING_DECISIONS(X) \
+ X(ContextNotPresenting, "context-not-presenting") \
+ X(NoAsyncScrollingState, "no-async-scrolling-state") \
+ X(BlockingWheelEventListeners, "blocking-wheel-event-listeners") \
+ X(NoScrollNode, "no-scroll-node") \
+ X(StaleWheelEventListeners, "stale-wheel-event-listeners") \
+ X(StepOvertakenByUI, "step-overtaken-by-ui") \
+ X(GestureEndWithNothingToSnap, "gesture-end-with-nothing-to-snap") \
+ X(SnappedAtGestureEnd, "snapped-at-gesture-end") \
+ X(HitTestTargetsOfAnotherVisualContextTree, "hit-test-targets-of-another-visual-context-tree") \
+ X(BlockedByMainThreadRegion, "blocked-by-main-thread-region") \
+ X(BlockedByWheelEventRegion, "blocked-by-wheel-event-region") \
+ X(NoScrollTarget, "no-scroll-target") \
+ X(ScrollerInOtherDocument, "scroller-in-other-document") \
+ X(StepWithoutDelta, "step-without-delta") \
+ X(PannedVisualViewport, "panned-visual-viewport") \
+ X(Latched, "latched") \
+ X(LatchedOutermostScrollerToStretch, "latched-outermost-scroller-to-stretch") \
+ X(ContinuedLatch, "continued-latch") \
+ X(NotOverAScrollbar, "not-over-a-scrollbar") \
+ X(NotPrimaryButton, "not-primary-button") \
+ X(HoveringScrollbarPaintedByCompositor, "hovering-scrollbar-painted-by-compositor") \
+ X(BeganScrollbarDrag, "began-scrollbar-drag") \
+ X(ContinuedScrollbarDrag, "continued-scrollbar-drag") \
+ X(EndedScrollbarDrag, "ended-scrollbar-drag") \
+ X(NoScrollbarDrag, "no-scrollbar-drag") \
+ X(LeftDuringScrollbarDrag, "left-during-scrollbar-drag") \
+ X(GestureEndAbsorbedByFling, "gesture-end-absorbed-by-fling") \
+ X(FlingStarted, "fling-started") \
+ X(NotDispatchedByCompositor, "not-dispatched-by-compositor") \
+ X(ConsumedByCompositor, "consumed-by-compositor") \
+ X(ForwardedToPage, "forwarded-to-page") \
+ X(NoAnswerFromCompositor, "no-answer-from-compositor") \
+ X(CoalescedIntoLaterEvent, "coalesced-into-later-event") \
+ X(DroppedWithoutLocalRoot, "dropped-without-local-root") \
+ X(DroppedOutdatedPointerMove, "dropped-outdated-pointer-move") \
+ X(ForwardedToRemoteFrame, "forwarded-to-remote-frame") \
+ X(AsyncScrollNotAttemptedDisplayListOutdated, "async-scroll-not-attempted-display-list-outdated") \
+ X(AsyncScrollNotAttemptedVisualViewportScaled, "async-scroll-not-attempted-visual-viewport-scaled") \
+ X(DefaultActionPerformedByCompositor, "default-action-performed-by-compositor") \
+ X(NoWheelTarget, "no-wheel-target") \
+ X(HandedToNestedNavigable, "handed-to-nested-navigable") \
+ X(DispatchedWheelEvent, "dispatched-wheel-event") \
+ X(PageCanceledWheelEvent, "page-canceled-wheel-event") \
+ X(MainThreadScrolledLatchedScroller, "main-thread-scrolled-latched-scroller") \
+ X(MainThreadScrolledScroller, "main-thread-scrolled-scroller") \
+ X(ScrollKeptByOverscrollBehavior, "scroll-kept-by-overscroll-behavior") \
+ X(MainThreadScrolledNothing, "main-thread-scrolled-nothing") \
+ X(ScrollbarDragDrivenByCompositor, "scrollbar-drag-driven-by-compositor") \
+ X(FinishedAccepted, "finished-accepted") \
+ X(FinishedHandled, "finished-handled") \
+ X(FinishedCancelled, "finished-cancelled") \
+ X(FinishedDropped, "finished-dropped")
enum class InputRoutingDecision : u8 {
#define __ENUMERATE_INPUT_ROUTING_DECISION(name, string) name,
diff --git a/Libraries/LibWebCommon/Page/InputTrace.cpp b/Libraries/LibWebCommon/Page/InputTrace.cpp
new file mode 100644
index 00000000000..7bed8259de1
--- /dev/null
+++ b/Libraries/LibWebCommon/Page/InputTrace.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibIPC/Decoder.h>
+#include <LibIPC/Encoder.h>
+#include <LibWebCommon/Page/InputTrace.h>
+
+namespace Web {
+
+// A test that never takes its trace must not grow it without bound.
+static constexpr size_t maximum_input_trace_record_count = 10'000;
+
+StringView input_trace_stage_name(InputTraceStage stage)
+{
+ switch (stage) {
+ case InputTraceStage::Compositor:
+ return "compositor"sv;
+ case InputTraceStage::CompositorForMainThread:
+ return "compositor-for-main-thread"sv;
+ case InputTraceStage::WebContent:
+ return "web-content"sv;
+ }
+ VERIFY_NOT_REACHED();
+}
+
+void InputTraceRecorder::record(InputTraceRecord record)
+{
+ if (!m_records.has_value() || m_records->size() >= maximum_input_trace_record_count)
+ return;
+ m_records->append(move(record));
+}
+
+Vector<InputTraceRecord> InputTraceRecorder::take()
+{
+ if (!m_records.has_value())
+ return {};
+ return m_records.release_value();
+}
+
+}
+
+namespace IPC {
+
+template<>
+ErrorOr<void> encode(Encoder& encoder, Web::InputTraceRecord const& record)
+{
+ TRY(encoder.encode(record.input_event_id));
+ TRY(encoder.encode(record.stage));
+ TRY(encoder.encode(record.decision));
+ TRY(encoder.encode(record.scroller));
+ TRY(encoder.encode(record.dom_target));
+ return {};
+}
+
+template<>
+ErrorOr<Web::InputTraceRecord> decode(Decoder& decoder)
+{
+ return Web::InputTraceRecord {
+ .input_event_id = TRY(decoder.decode<u64>()),
+ .stage = TRY(decoder.decode<Web::InputTraceStage>()),
+ .decision = TRY(decoder.decode<Web::InputRoutingDecision>()),
+ .scroller = TRY(decoder.decode<Optional<Web::AsyncScrollNodeStableID>>()),
+ .dom_target = TRY(decoder.decode<Optional<Web::UniqueNodeID>>()),
+ };
+}
+
+}
diff --git a/Libraries/LibWebCommon/Page/InputTrace.h b/Libraries/LibWebCommon/Page/InputTrace.h
new file mode 100644
index 00000000000..fdb0bf15f35
--- /dev/null
+++ b/Libraries/LibWebCommon/Page/InputTrace.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Optional.h>
+#include <AK/StringView.h>
+#include <AK/Types.h>
+#include <AK/Vector.h>
+#include <LibIPC/Forward.h>
+#include <LibWebCommon/Export.h>
+#include <LibWebCommon/Forward.h>
+#include <LibWebCommon/Page/AsyncScrollNodeStableID.h>
+#include <LibWebCommon/Page/InputRoutingDecision.h>
+
+namespace Web {
+
+enum class InputTraceStage : u8 {
+ // The compositor, as it takes an input event from the UI.
+ Compositor,
+ // The compositor, as WebContent's main thread asks it to scroll for an input event.
+ CompositorForMainThread,
+ WebContent,
+};
+
+WEBCOMMON_API StringView input_trace_stage_name(InputTraceStage);
+
+struct InputTraceRecord {
+ // The id the UI gave the input event, or 0 for input that did not come from the UI.
+ u64 input_event_id { 0 };
+ InputTraceStage stage { InputTraceStage::WebContent };
+ InputRoutingDecision decision { InputRoutingDecision::NoAnswerFromCompositor };
+ Optional<AsyncScrollNodeStableID> scroller {};
+ Optional<UniqueNodeID> dom_target {};
+};
+
+// Collects the routing decisions of input events while a test asks for them.
+class WEBCOMMON_API InputTraceRecorder {
+public:
+ void begin() { m_records = Vector<InputTraceRecord> {}; }
+ bool is_recording() const { return m_records.has_value(); }
+ void record(InputTraceRecord);
+ // Returns what was recorded since the trace began, and stops recording.
+ Vector<InputTraceRecord> take();
+
+private:
+ Optional<Vector<InputTraceRecord>> m_records;
+};
+
+}
+
+namespace IPC {
+
+template<>
+WEBCOMMON_API ErrorOr<void> encode(Encoder&, Web::InputTraceRecord const&);
+template<>
+WEBCOMMON_API ErrorOr<Web::InputTraceRecord> decode(Decoder&);
+
+}
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cpp
index 0193d7036b7..34f95f93527 100644
--- a/Services/Compositor/CompositorState.cpp
+++ b/Services/Compositor/CompositorState.cpp
@@ -533,7 +533,12 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId c
{
VERIFY(m_client);
auto* context = context_if_present(context_id);
+ auto record_routing = [&](Web::InputRoutingDecision decision, Optional<Web::AsyncScrollNodeStableID> scroller = {}) {
+ context->input_trace().record({ .input_event_id = event.id, .stage = Web::InputTraceStage::Compositor, .decision = decision, .scroller = scroller });
+ };
if (!context || !context->can_dispatch_input_to_web_content()) {
+ if (context)
+ record_routing(Web::InputRoutingDecision::NotDispatchedByCompositor);
m_client->did_not_dispatch_input_event(context_id, event.id);
return;
}
@@ -548,6 +553,7 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId c
// The UI can send the end of a gesture more than once. An end that arrives during a fling belongs to the
// flicked gesture, so it does not stop the fling.
if (event.scroll_gesture_phase == Web::ScrollGesturePhase::Ended && context->has_active_scroll_fling()) {
+ record_routing(Web::InputRoutingDecision::GestureEndAbsorbedByFling);
m_client->did_consume_input_event(context_id, event.id);
return;
}
@@ -557,6 +563,7 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId c
// If the gesture continues as a fling, the end of the fling is the end of the gesture.
if (m_synthesizes_scroll_momentum && event.scroll_gesture_phase == Web::ScrollGesturePhase::Ended && context->start_scroll_fling_if_flicked(event)) {
+ record_routing(Web::InputRoutingDecision::FlingStarted);
m_client->did_consume_input_event(context_id, event.id);
schedule_animation_frames_if_needed(*context);
return;
@@ -568,8 +575,10 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId c
result = context->handle_wheel_event(event);
else
result = context->handle_mouse_event(event);
- if (result.routing_decision.has_value())
+ if (result.routing_decision.has_value()) {
dbgln_if(COMPOSITOR_DEBUG, "[Compositor] Context {} routed input event {}: {}", context_id, event.id, Web::input_routing_decision_name(*result.routing_decision));
+ record_routing(*result.routing_decision, result.routed_scroller);
+ }
// Schedules the present, publishes the scroll updates the event produced and asks for a rendering update, all of
// which reach WebContent ahead of the event itself on the same connection.
@@ -581,11 +590,13 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId c
} else if (handled) {
// The page still sees the events of a drag the compositor scrolls for a scrollbar the display list paints.
if (!result.scrollbar_dragged_by_compositor.has_value()) {
+ record_routing(Web::InputRoutingDecision::ConsumedByCompositor);
m_client->did_consume_input_event(context_id, event.id);
return;
}
event.scrollbar_dragged_by_compositor = result.scrollbar_dragged_by_compositor;
}
+ record_routing(Web::InputRoutingDecision::ForwardedToPage);
context->dispatch_mouse_event_to_web_content(event, nested_context_scrolled_since_last_frame(context_id));
}
@@ -614,6 +625,8 @@ void CompositorState::dispatch_scroll_fling_step(Web::CompositorContextId contex
// Send each fling step on the same route as a wheel event from the UI.
if (!step.has_value())
return;
+ if (step->result.routing_decision.has_value())
+ context.input_trace().record({ .input_event_id = step->event.id, .stage = Web::InputTraceStage::Compositor, .decision = *step->result.routing_decision, .scroller = step->result.routed_scroller });
step->event.async_scroll_performed_default_action = apply_context_update_result(context_id, context, step->result);
schedule_animation_frames_if_needed(context);
context.dispatch_mouse_event_to_web_content(step->event);
@@ -1207,6 +1220,20 @@ Gfx::FloatPoint CompositorState::elastic_overscroll_stretch_for_testing(Web::Com
return context->elastic_overscroll_stretch_for_testing(stable_node_id);
}
+void CompositorState::begin_input_trace_for_testing(Web::CompositorContextId context_id)
+{
+ if (auto* context = context_if_present(context_id))
+ context->input_trace().begin();
+}
+
+Vector<Web::InputTraceRecord> CompositorState::take_input_trace_for_testing(Web::CompositorContextId context_id)
+{
+ auto* context = context_if_present(context_id);
+ if (!context)
+ return {};
+ return context->input_trace().take();
+}
+
void CompositorState::set_client_gpu_presentation_capability(bool supported, u64 adapter_luid)
{
Optional<u64> new_adapter_luid;
diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.h
index ff814fc3d3a..1c5cb9dec20 100644
--- a/Services/Compositor/CompositorState.h
+++ b/Services/Compositor/CompositorState.h
@@ -127,6 +127,8 @@ public:
void set_synthesizes_scroll_momentum(bool);
void set_scrolls_elastically(bool);
Gfx::FloatPoint elastic_overscroll_stretch_for_testing(Web::CompositorContextId, Web::AsyncScrollNodeStableID) const;
+ void begin_input_trace_for_testing(Web::CompositorContextId);
+ Vector<Web::InputTraceRecord> take_input_trace_for_testing(Web::CompositorContextId);
struct PlaceholderCanvasAllocation {
Compositing::CanvasId canvas_id;
diff --git a/Services/Compositor/CompositorWebContentServer.ipc b/Services/Compositor/CompositorWebContentServer.ipc
index 1df6f13277b..9dae8215305 100644
--- a/Services/Compositor/CompositorWebContentServer.ipc
+++ b/Services/Compositor/CompositorWebContentServer.ipc
@@ -18,6 +18,7 @@
#include <LibIPC/TransportHandle.h>
#include <LibMedia/VideoSinkHandle.h>
#include <LibWebCommon/Page/InputEvent.h>
+#include <LibWebCommon/Page/InputTrace.h>
endpoint CompositorWebContentServer
{
@@ -63,6 +64,8 @@ endpoint CompositorWebContentServer
smooth_scroll_to(Web::CompositorContextId context_id, Web::AsyncScrollNodeStableID stable_node_id, Gfx::FloatPoint offset, Gfx::FloatPoint main_thread_offset, Gfx::IntRect viewport_rect, Compositing::ScrollAnimationKind animation_kind, Compositing::SmoothScrollInitiator initiator, Optional<Compositing::AsyncScrollOperationID> operation_to_continue) => (Compositing::AsyncScrollEnqueueResult result)
cancel_smooth_scroll(Web::CompositorContextId context_id, Web::AsyncScrollNodeStableID stable_node_id) =|
elastic_overscroll_stretch_for_testing(Web::CompositorContextId context_id, Web::AsyncScrollNodeStableID stable_node_id) => (Gfx::FloatPoint stretch)
+ begin_input_trace_for_testing(Web::CompositorContextId context_id) => ()
+ take_input_trace_for_testing(Web::CompositorContextId context_id) => (Vector<Web::InputTraceRecord> records)
take_pending_async_scroll_updates(Web::CompositorContextId context_id) => (Compositing::PendingAsyncScrollUpdates updates)
viewport_size_updated(Web::CompositorContextId context_id, Gfx::IntSize viewport_size, Compositing::WindowResizingInProgress window_resize_in_progress) =|
diff --git a/Services/Compositor/ConnectionFromWebContent.cpp b/Services/Compositor/ConnectionFromWebContent.cpp
index c4acc7df855..9d31945d12b 100644
--- a/Services/Compositor/ConnectionFromWebContent.cpp
+++ b/Services/Compositor/ConnectionFromWebContent.cpp
@@ -434,6 +434,20 @@ Messages::CompositorWebContentServer::ElasticOverscrollStretchForTestingResponse
return m_compositor_state->elastic_overscroll_stretch_for_testing(context_id, stable_node_id);
}
+void ConnectionFromWebContent::begin_input_trace_for_testing(Web::CompositorContextId context_id)
+{
+ if (!context_is_owned_by_this_connection(context_id))
+ return;
+ m_compositor_state->begin_input_trace_for_testing(context_id);
+}
+
+Messages::CompositorWebContentServer::TakeInputTraceForTestingResponse ConnectionFromWebContent::take_input_trace_for_testing(Web::CompositorContextId context_id)
+{
+ if (!context_is_owned_by_this_connection(context_id))
+ return Vector<Web::InputTraceRecord> {};
+ return m_compositor_state->take_input_trace_for_testing(context_id);
+}
+
void ConnectionFromWebContent::cancel_smooth_scroll(Web::CompositorContextId context_id, Web::AsyncScrollNodeStableID stable_node_id)
{
if (!context_is_owned_by_this_connection(context_id))
diff --git a/Services/Compositor/ConnectionFromWebContent.h b/Services/Compositor/ConnectionFromWebContent.h
index 59d39d8e222..ee6bb7bdf3f 100644
--- a/Services/Compositor/ConnectionFromWebContent.h
+++ b/Services/Compositor/ConnectionFromWebContent.h
@@ -77,6 +77,8 @@ private:
virtual Messages::CompositorWebContentServer::AsyncScrollByResponse 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) override;
virtual Messages::CompositorWebContentServer::SmoothScrollToResponse 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) override;
virtual Messages::CompositorWebContentServer::ElasticOverscrollStretchForTestingResponse elastic_overscroll_stretch_for_testing(Web::CompositorContextId, Web::AsyncScrollNodeStableID) override;
+ virtual void begin_input_trace_for_testing(Web::CompositorContextId) override;
+ virtual Messages::CompositorWebContentServer::TakeInputTraceForTestingResponse take_input_trace_for_testing(Web::CompositorContextId) override;
virtual void cancel_smooth_scroll(Web::CompositorContextId, Web::AsyncScrollNodeStableID) override;
virtual Messages::CompositorWebContentServer::TakePendingAsyncScrollUpdatesResponse take_pending_async_scroll_updates(Web::CompositorContextId) override;
virtual void viewport_size_updated(Web::CompositorContextId, Gfx::IntSize viewport_size, Compositing::WindowResizingInProgress) override;
diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.h
index 34fe12c4ad1..9a1ac67dcdd 100644
--- a/Services/Compositor/ContextState.h
+++ b/Services/Compositor/ContextState.h
@@ -43,6 +43,7 @@
#include <LibGfx/ShareableBitmap.h>
#include <LibGfx/Size.h>
#include <LibWebCommon/Page/InputEvent.h>
+#include <LibWebCommon/Page/InputTrace.h>
#include <LibWebCommon/UIEvents/KeyCode.h>
namespace Gfx {
@@ -155,6 +156,7 @@ public:
void set_scrolls_elastically(bool);
Optional<Gfx::IntRect> advance_elastic_overscroll_rebounds(MonotonicTime frame_time);
Gfx::FloatPoint elastic_overscroll_stretch_for_testing(Web::AsyncScrollNodeStableID) const;
+ Web::InputTraceRecorder& input_trace() { return m_input_trace; }
bool advance_visual_animations(MonotonicTime now);
bool visual_animations_need_frame();
Compositing::PendingAsyncScrollUpdates take_pending_async_scroll_updates();
@@ -297,6 +299,7 @@ private:
bool m_has_async_scrolling_state { false };
CaretBlinkTimer m_caret_blink_timer;
+ Web::InputTraceRecorder m_input_trace;
Optional<u64> m_display_id;
double m_display_refresh_rate { 60.0 };
Compositing::ContextVisibility m_visibility { Compositing::ContextVisibility::Visible };
diff --git a/Tests/LibWeb/Text/expected/all-window-properties.txt b/Tests/LibWeb/Text/expected/all-window-properties.txt
index a6e7bf53239..57b8914fc76 100644
--- a/Tests/LibWeb/Text/expected/all-window-properties.txt
+++ b/Tests/LibWeb/Text/expected/all-window-properties.txt
@@ -606,6 +606,7 @@ animationFrame
asyncTest
httpTestServer
printElement
+printInputTrace
println
promiseTest
removeTestErrorHandler
diff --git a/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-scroll-is-not-repeated-by-the-page.txt b/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-scroll-is-not-repeated-by-the-page.txt
index 1d6b28b4389..0e9567c60f3 100644
--- a/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-scroll-is-not-repeated-by-the-page.txt
+++ b/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-scroll-is-not-repeated-by-the-page.txt
@@ -1,2 +1,7 @@
+#1 compositor: latched scroller=viewport
+#1 compositor: forwarded-to-page
+#1 web-content: default-action-performed-by-compositor
+#1 web-content: dispatched-wheel-event target=body
+#1 web-content: finished-handled
window.scrollY: 50
wheel events: 1
diff --git a/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-scroll-is-not-repeated-by-the-page.html b/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-scroll-is-not-repeated-by-the-page.html
index b5649e463ce..199d0586267 100644
--- a/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-scroll-is-not-repeated-by-the-page.html
+++ b/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-scroll-is-not-repeated-by-the-page.html
@@ -15,7 +15,9 @@
// The compositor scrolls the page for a wheel event from the UI and forwards the event to the page flagged as
// having done so, so the page fires the event without scrolling by its delta a second time.
+ internals.beginInputTrace();
await scrollSettled(document, () => internals.wheelThroughUIProcess(20, 20, 0, 50));
+ printInputTrace(internals.takeInputTrace());
await animationFrame();
await animationFrame();
println(`window.scrollY: ${window.scrollY}`);
diff --git a/Tests/LibWeb/Text/input/include.js b/Tests/LibWeb/Text/input/include.js
index 38f91c4f72c..fb24774ff1a 100644
--- a/Tests/LibWeb/Text/input/include.js
+++ b/Tests/LibWeb/Text/input/include.js
@@ -101,6 +101,33 @@ async function scrollSettled(target, action) {
await scrollend;
}
+// Prints what internals.takeInputTrace() returned, one routing decision per line, optionally only those of the given
+// stages. Input events are numbered in the order they first appear, as the ids the UI gives them keep growing from test
+// to test; input that did not come from the UI is marked "-".
+function printInputTrace(trace, { stages } = {}) {
+ const describe = (node, documentName = "document") => {
+ if (node instanceof Document) return node === document ? documentName : `nested ${documentName}`;
+ if (node.id) return `#${node.id}`;
+ return node.nodeName.toLowerCase();
+ };
+ const eventNumbers = new Map();
+ for (const record of trace) {
+ let eventNumber = "-";
+ if (record.id !== 0) {
+ if (!eventNumbers.has(record.id)) eventNumbers.set(record.id, eventNumbers.size + 1);
+ eventNumber = `#${eventNumbers.get(record.id)}`;
+ }
+ if (stages && !stages.includes(record.stage)) continue;
+ let line = `${eventNumber} ${record.stage}: ${record.decision}`;
+ if (record.scroller) {
+ line += ` scroller=${describe(record.scroller, "viewport")}`;
+ if (record.scrollerPseudoElement) line += `::${record.scrollerPseudoElement}`;
+ }
+ if (record.target) line += ` target=${describe(record.target)}`;
+ println(line);
+ }
+}
+
async function scrollOffsetStopsChanging(readScrollOffset) {
let previousScrollOffset = null;
while (previousScrollOffset !== readScrollOffset()) {