Skip to content

Truly independent web browser

LibWeb+Compositor: Ask the compositor where a wheel step would go

Aliaksandr Kalenik87e9118c306c
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp
index 06e4862cf57..678c0e5be44 100644
--- a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp
+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp
@@ -490,6 +490,19 @@ WheelHitTestResult AsyncScrollTree::hit_test_scroll_node_for_wheel(Compositing::
return hit_test_result_for_scroll_node(*viewport_node_id, delta, in_flight_destination_for, scroll_nodes_behind_scroll_chaining_barriers);
}
+FirstWheelStepRoute AsyncScrollTree::route_first_wheel_step(WheelRoutingAdmission admission, Compositing::AccumulatedVisualContextTree const& visual_context_tree, Gfx::FloatPoint position, Gfx::FloatPoint delta) const
+{
+ if (admission != WheelRoutingAdmission::Accepted)
+ return { input_routing_decision_for_wheel_step_not_admitted_by(admission) };
+ auto scroll_target = hit_test_scroll_node_for_wheel(visual_context_tree, position, delta);
+ FirstWheelStepRoute route { input_routing_decision_for_first_wheel_step(scroll_target.outcome) };
+ if (scroll_target.node_id.has_value()) {
+ if (auto const* node = scroll_node_for_id(*scroll_target.node_id))
+ route.scroller = node->stable_node_id;
+ }
+ return route;
+}
+
bool AsyncScrollTree::is_covered_by_hit_test_target_painted_after(u32 paint_order_index, Compositing::AccumulatedVisualContextTree const& visual_context_tree, Gfx::FloatPoint position) const
{
if (m_visual_context_tree_structural_epoch != visual_context_tree.structural_epoch())
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h
index 8035398eb02..1dca1196f18 100644
--- a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h
+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h
@@ -48,6 +48,18 @@ struct WheelHitTestResult {
// thread for the outcome's reason.
COMPOSITING_API Web::InputRoutingDecision input_routing_decision_for_first_wheel_step(WheelHitTestOutcome);
+// Where the first step of a wheel gesture over a position goes, as far as the admission and the hit test decide it.
+struct FirstWheelStepRoute {
+ Web::InputRoutingDecision decision;
+ Optional<Web::AsyncScrollNodeStableID> scroller {};
+};
+
+struct FirstWheelStepRouteForTesting {
+ FirstWheelStepRoute route;
+ // The document whose scrolling state decided the route.
+ Optional<Web::UniqueNodeID> document_id;
+};
+
struct WheelScrollTarget {
Web::AsyncScrollNodeStableID stable_node_id;
Gfx::FloatPoint current_offset;
@@ -116,6 +128,9 @@ public:
// to be covered whenever that cannot be told.
bool is_covered_by_hit_test_target_painted_after(u32 paint_order_index, Compositing::AccumulatedVisualContextTree const&, Gfx::FloatPoint position) const;
bool scroll_node_is_viewport(AsyncScrollNodeID) const;
+ // Leaves out what only a compositor holding a gesture decides: whether a step continues a latched gesture, which
+ // scroller fingers at its edge stretch, and whether a zoomed page pans its visual viewport.
+ FirstWheelStepRoute route_first_wheel_step(WheelRoutingAdmission, Compositing::AccumulatedVisualContextTree const&, Gfx::FloatPoint position, Gfx::FloatPoint delta) const;
// Of the scroller and the scrollers around it that a scroll by the delta may be passed on to, the outermost one a
// wheel can scroll along the main axis of the delta at all, wherever it is scrolled to.
Optional<AsyncScrollNodeID> outermost_scroll_node_wheel_scrollable_along_main_axis_of(AsyncScrollNodeID innermost_node_id, Gfx::FloatPoint delta) const;
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.cpp b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.cpp
index 233e278780d..6ce2a019051 100644
--- a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.cpp
+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.cpp
@@ -230,6 +230,13 @@ Web::InputRoutingDecision input_routing_decision_for_wheel_step_not_admitted_by(
VERIFY_NOT_REACHED();
}
+WheelRoutingAdmission wheel_routing_admission_for(AsyncScrollingState const& state, u64 newest_wheel_event_listener_state_generation)
+{
+ if (state.wheel_event_listener_state_generation < newest_wheel_event_listener_state_generation)
+ return WheelRoutingAdmission::StaleWheelEventListeners;
+ return wheel_routing_admission_for(state);
+}
+
Utf16View wheel_routing_admission_to_utf16_view(WheelRoutingAdmission admission)
{
switch (admission) {
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h
index d39df9f9855..632e143bd95 100644
--- a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h
+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h
@@ -182,6 +182,9 @@ enum class WheelScrollAdmission {
COMPOSITING_API AsyncScrollingState async_scrolling_state_from_display_list(Compositing::DisplayList const&);
COMPOSITING_API WheelRoutingAdmission wheel_routing_admission_for(AsyncScrollingState const&);
+// The admission of a scrolling state recorded before the newest change to the page's blocking wheel event listeners is
+// stale, as the state may not have the regions that change made.
+COMPOSITING_API WheelRoutingAdmission wheel_routing_admission_for(AsyncScrollingState const&, u64 newest_wheel_event_listener_state_generation);
COMPOSITING_API Utf16View wheel_routing_admission_to_utf16_view(WheelRoutingAdmission);
// Why a wheel step that the admission does not let the compositor scroll is left to the main thread.
COMPOSITING_API Web::InputRoutingDecision input_routing_decision_for_wheel_step_not_admitted_by(WheelRoutingAdmission);
diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.cpp b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
index edcd059fc16..19916bd778a 100644
--- a/Libraries/LibWeb/Compositor/CompositorConnection.cpp
+++ b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
@@ -459,6 +459,20 @@ void CompositorConnection::synchronize_for_testing()
did_lose_compositor();
}
+Optional<Compositing::FirstWheelStepRouteForTesting> CompositorConnection::route_first_wheel_step_for_testing(Web::CompositorContextId context_id, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels)
+{
+ if (!can_send_message_to_compositor())
+ return {};
+ auto response = send_sync_but_allow_failure<Messages::CompositorWebContentServer::RouteFirstWheelStepForTesting>(context_id, position, delta_in_css_pixels);
+ if (!response) {
+ did_lose_compositor();
+ return {};
+ }
+ if (!response->decision().has_value())
+ return {};
+ return Compositing::FirstWheelStepRouteForTesting { .route = { *response->decision(), response->scroller() }, .document_id = response->document_id() };
+}
+
void CompositorConnection::begin_input_trace_for_testing(Web::CompositorContextId context_id)
{
if (!can_send_message_to_compositor())
diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.h b/Libraries/LibWeb/Compositor/CompositorConnection.h
index abedb3a8663..2a4906618f2 100644
--- a/Libraries/LibWeb/Compositor/CompositorConnection.h
+++ b/Libraries/LibWeb/Compositor/CompositorConnection.h
@@ -16,6 +16,7 @@
#include <LibCompositing/DisplayList/Canvas2DCommandStream.h>
#include <LibCompositing/DisplayList/DisplayList.h>
#include <LibCompositing/DisplayList/DisplayListResourceStorage.h>
+#include <LibCompositing/Scrolling/AsyncScrollTree.h>
#include <LibCompositing/Scrolling/ScrollState.h>
#include <LibCompositing/Types.h>
#include <LibCompositing/WebGL/Types.h>
@@ -72,6 +73,7 @@ public:
void cancel_smooth_scroll(Web::CompositorContextId, Web::AsyncScrollNodeStableID);
Gfx::FloatPoint elastic_overscroll_stretch_for_testing(Web::CompositorContextId, Web::AsyncScrollNodeStableID);
void synchronize_for_testing();
+ Optional<Compositing::FirstWheelStepRouteForTesting> route_first_wheel_step_for_testing(Web::CompositorContextId, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels);
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);
diff --git a/Libraries/LibWeb/Compositor/CompositorHost.cpp b/Libraries/LibWeb/Compositor/CompositorHost.cpp
index 2612ded0888..e63782b488c 100644
--- a/Libraries/LibWeb/Compositor/CompositorHost.cpp
+++ b/Libraries/LibWeb/Compositor/CompositorHost.cpp
@@ -88,6 +88,11 @@ void CompositorContextHandle::synchronize_for_testing()
m_host.synchronize_for_testing();
}
+Optional<Compositing::FirstWheelStepRouteForTesting> CompositorContextHandle::route_first_wheel_step_for_testing(Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels)
+{
+ return m_host.route_first_wheel_step_for_testing(m_context_id, position, delta_in_css_pixels);
+}
+
void CompositorContextHandle::begin_input_trace_for_testing()
{
m_host.begin_input_trace_for_testing(m_context_id);
@@ -457,6 +462,13 @@ void CompositorHost::synchronize_for_testing()
connection->synchronize_for_testing();
}
+Optional<Compositing::FirstWheelStepRouteForTesting> CompositorHost::route_first_wheel_step_for_testing(Web::CompositorContextId context_id, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels)
+{
+ if (auto* connection = compositor_connection())
+ return connection->route_first_wheel_step_for_testing(context_id, position, delta_in_css_pixels);
+ return {};
+}
+
void CompositorHost::begin_input_trace_for_testing(Web::CompositorContextId context_id)
{
if (auto* connection = compositor_connection())
diff --git a/Libraries/LibWeb/Compositor/CompositorHost.h b/Libraries/LibWeb/Compositor/CompositorHost.h
index d8190da9e22..c29f0bbce16 100644
--- a/Libraries/LibWeb/Compositor/CompositorHost.h
+++ b/Libraries/LibWeb/Compositor/CompositorHost.h
@@ -13,6 +13,7 @@
#include <AK/OwnPtr.h>
#include <AK/Types.h>
#include <LibCompositing/DisplayList/DisplayListResourceStorage.h>
+#include <LibCompositing/Scrolling/AsyncScrollTree.h>
#include <LibCompositing/Types.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Point.h>
@@ -63,6 +64,7 @@ public:
void cancel_smooth_scroll(Web::AsyncScrollNodeStableID);
Gfx::FloatPoint elastic_overscroll_stretch_for_testing(Web::AsyncScrollNodeStableID);
void synchronize_for_testing();
+ Optional<Compositing::FirstWheelStepRouteForTesting> route_first_wheel_step_for_testing(Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels);
void begin_input_trace_for_testing();
Vector<Web::InputTraceRecord> take_input_trace_for_testing();
Compositing::PendingAsyncScrollUpdates take_pending_async_scroll_updates(Compositing::AsyncScrollUpdateFreshness);
@@ -124,6 +126,7 @@ public:
void cancel_smooth_scroll(Web::CompositorContextId, Web::AsyncScrollNodeStableID);
Gfx::FloatPoint elastic_overscroll_stretch_for_testing(Web::CompositorContextId, Web::AsyncScrollNodeStableID);
void synchronize_for_testing();
+ Optional<Compositing::FirstWheelStepRouteForTesting> route_first_wheel_step_for_testing(Web::CompositorContextId, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels);
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);
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp
index b87a5f150bf..99da255c261 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -1302,18 +1302,36 @@ static Vector<InputTraceRecord> take_input_trace_records(HTML::Window& window)
return records;
}
+static Gfx::FloatPoint device_position_as_float_point(DevicePixelPoint position)
+{
+ return { static_cast<float>(position.x().value()), static_cast<float>(position.y().value()) };
+}
+
+static JS::Value wrapped_node_with_unique_id(HTML::Window& window, Optional<UniqueNodeID> node_id)
+{
+ auto* node = node_id.has_value() ? DOM::Node::from_unique_id(*node_id) : nullptr;
+ if (!node)
+ return JS::js_null();
+ auto& realm = HTML::relevant_realm(window);
+ return Bindings::wrap(Bindings::host_defined_wrapper_world(realm), realm, GC::Ref<DOM::Node> { *node });
+}
+
+// A scroller as the input hooks describe it: the document for its viewport, or the element whose box scrolls, with the
+// pseudo-element that generated the box, if any.
+static void define_scroller_properties(HTML::Window& window, JS::Object& object, Optional<AsyncScrollNodeStableID> scroller)
+{
+ auto& vm = window.vm();
+ object.define_direct_property("scroller"_utf16_fly_string, wrapped_node_with_unique_id(window, scroller.map([](auto const& id) { return id.node_id; })), JS::default_attributes);
+ if (scroller.has_value() && scroller->kind == AsyncScrollNodeKind::PseudoElement) {
+ auto pseudo_element = CSS::pseudo_element_name(static_cast<CSS::PseudoElement>(scroller->pseudo_element_type));
+ object.define_direct_property("scrollerPseudoElement"_utf16_fly_string, JS::PrimitiveString::create(vm, pseudo_element), JS::default_attributes);
+ }
+}
+
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];
@@ -1321,28 +1339,88 @@ GC::Ref<JS::Object> Internals::take_input_trace()
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);
+ define_scroller_properties(window(), *object, record.scroller);
+ object->define_direct_property("target"_utf16_fly_string, wrapped_node_with_unique_id(window(), record.dom_target), JS::default_attributes);
MUST(array->create_data_property_or_throw(i, object));
}
return array;
}
+GC::Ref<JS::Object> Internals::first_wheel_step_route_to_object(Compositing::FirstWheelStepRouteForTesting const& result)
+{
+ auto& realm = HTML::relevant_realm(window());
+ auto object = JS::Object::create(realm, nullptr);
+ object->define_direct_property("decision"_utf16_fly_string, JS::PrimitiveString::create(vm(), input_routing_decision_name(result.route.decision)), JS::default_attributes);
+ define_scroller_properties(window(), *object, result.route.scroller);
+ object->define_direct_property("document"_utf16_fly_string, wrapped_node_with_unique_id(window(), result.document_id), JS::default_attributes);
+ return object;
+}
+
+GC::Ref<JS::Object> Internals::compositor_wheel_target_at(double x, double y, double delta_x, double delta_y)
+{
+ let_compositor_take_in_every_rendered_frame(window());
+ Optional<Compositing::FirstWheelStepRouteForTesting> result;
+ if (auto* compositor_context = compositor_context_routing_input_for(window())) {
+ auto position = page().css_to_device_point(window().navigable()->to_page_position({ x, y }));
+ result = compositor_context->route_first_wheel_step_for_testing(device_position_as_float_point(position), { static_cast<float>(delta_x), static_cast<float>(delta_y) });
+ }
+ return first_wheel_step_route_to_object(result.value_or({ .route = { InputRoutingDecision::NoAnswerFromCompositor }, .document_id = {} }));
+}
+
+namespace {
+
+struct RecordedScrollTree {
+ Compositing::AsyncScrollTree scroll_tree;
+ Compositing::AccumulatedVisualContextTree visual_context_tree;
+ Compositing::WheelRoutingAdmission admission;
+};
+
+}
+
+// The scroll tree of the display list the document last recorded, as the compositor builds it once the list reaches it.
+static Optional<RecordedScrollTree> recorded_scroll_tree_of(DOM::Document& document, Layout::BegunRead const& read)
+{
+ auto* display_list = document.paint_state().display_list_used_as_paint_command_cache_source();
+ if (!display_list)
+ return {};
+ RecordedScrollTree recorded {
+ .scroll_tree = {},
+ .visual_context_tree = document.paint_state().visual_context_tree_without_update(read, document),
+ .admission = {},
+ };
+ auto async_scrolling_state = Compositing::async_scrolling_state_from_display_list(*display_list);
+ recorded.admission = Compositing::wheel_routing_admission_for(async_scrolling_state, document.page().wheel_event_listener_state_generation());
+ recorded.scroll_tree.set_state(move(async_scrolling_state));
+ recorded.scroll_tree.rebuild_wheel_hit_test_targets(display_list, &recorded.visual_context_tree, document.scroll_state_snapshot());
+ return recorded;
+}
+
+GC::Ref<JS::Object> Internals::recorded_display_list_wheel_target_at(double x, double y, double delta_x, double delta_y)
+{
+ // A script reads the render state, which waits for a frame in flight.
+ Layout::ForcedReadScope read { window().associated_document() };
+ auto recorded = recorded_scroll_tree_of(window().associated_document(), read);
+ if (!recorded.has_value())
+ return first_wheel_step_route_to_object({ .route = { InputRoutingDecision::NoAsyncScrollingState }, .document_id = {} });
+ auto const& scroll_tree = recorded->scroll_tree;
+
+ auto position = device_position_as_float_point(page().css_to_device_point({ x, y }));
+ auto delta = Gfx::FloatPoint { static_cast<float>(delta_x), static_cast<float>(delta_y) }.scaled(static_cast<float>(scroll_tree.device_pixels_per_css_pixel()));
+ return first_wheel_step_route_to_object({
+ .route = scroll_tree.route_first_wheel_step(recorded->admission, recorded->visual_context_tree, position, delta),
+ .document_id = scroll_tree.document_id(),
+ });
+}
+
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.
Layout::ForcedReadScope read { window().associated_document() };
- auto& document = window().associated_document();
- auto* display_list = document.paint_state().display_list_used_as_paint_command_cache_source();
- if (!display_list)
+ auto recorded = recorded_scroll_tree_of(window().associated_document(), read);
+ if (!recorded.has_value())
return false;
- auto tree = document.paint_state().visual_context_tree_without_update(read, document);
- auto state = Compositing::async_scrolling_state_from_display_list(*display_list);
- return Compositing::blocks_wheel_event_at_position(state, display_list, &tree, document.scroll_state_snapshot(), { static_cast<float>(x), static_cast<float>(y) });
+ auto position = device_position_as_float_point(page().css_to_device_point({ x, y }));
+ return recorded->scroll_tree.blocks_wheel_event_at_position(recorded->visual_context_tree, position);
}
void Internals::record_display_list_for_testing(bool paint_overlay, bool cold)
diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.h
index 86ae0d1a26a..775fa4d8092 100644
--- a/Libraries/LibWeb/Internals/Internals.h
+++ b/Libraries/LibWeb/Internals/Internals.h
@@ -6,6 +6,7 @@
#pragma once
+#include <LibCompositing/Scrolling/AsyncScrollTree.h>
#include <LibCompositing/Scrolling/AsyncScrollingState.h>
#include <LibWeb/Bindings/Internals.h>
#include <LibWeb/DOM/Document.h>
@@ -168,8 +169,10 @@ public:
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();
+ GC::Ref<JS::Object> compositor_wheel_target_at(double x, double y, double delta_x, double delta_y);
+ GC::Ref<JS::Object> recorded_display_list_wheel_target_at(double x, double y, double delta_x, double delta_y);
bool recorded_display_list_blocks_wheel_event_at(double x, double y);
+ GC::Ref<JS::Object> recorded_async_scrolling_state_object();
void record_display_list_for_testing(bool paint_overlay, bool cold);
void set_autoplay_policy(Utf16String const& policy);
@@ -313,6 +316,7 @@ public:
String viewport_overflow_x();
private:
+ GC::Ref<JS::Object> first_wheel_step_route_to_object(Compositing::FirstWheelStepRouteForTesting const&);
Web::MouseEvent mouse_event_through_ui_process_at(Web::MouseEvent::Type, double x, double y);
void send_mouse_events_through_ui_process(Vector<Web::MouseEvent>, GC::Ref<WebIDL::Promise>);
explicit Internals(HTML::Window&);
diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idl
index 44e72113d46..c9b9bd5791f 100644
--- a/Libraries/LibWeb/Internals/Internals.idl
+++ b/Libraries/LibWeb/Internals/Internals.idl
@@ -161,8 +161,15 @@ interface Internals {
// 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();
+ // Where the first step of a wheel gesture at the position would go, and why: as the compositor routes it with the
+ // frames rendered so far, and as the display list this document last recorded routes it. Neither knows of a gesture
+ // in progress.
+ object compositorWheelTargetAt(double x, double y, double deltaX, double deltaY);
+ object recordedDisplayListWheelTargetAt(double x, double y, double deltaX, double deltaY);
+ // Whether the display list this document last recorded has blocking wheel event listeners take a wheel at the
+ // position.
boolean recordedDisplayListBlocksWheelEventAt(double x, double y);
+ [ImplementedAs=recorded_async_scrolling_state_object] object recordedAsyncScrollingState();
undefined recordDisplayListForTesting(optional boolean paintOverlay = false, optional boolean cold = false);
undefined setAutoplayPolicy(DOMString policy);
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cpp
index 34f95f93527..8768aaddb6a 100644
--- a/Services/Compositor/CompositorState.cpp
+++ b/Services/Compositor/CompositorState.cpp
@@ -1220,6 +1220,14 @@ Gfx::FloatPoint CompositorState::elastic_overscroll_stretch_for_testing(Web::Com
return context->elastic_overscroll_stretch_for_testing(stable_node_id);
}
+Optional<Compositing::FirstWheelStepRouteForTesting> CompositorState::route_first_wheel_step_for_testing(Web::CompositorContextId context_id, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels)
+{
+ auto* context = context_if_present(context_id);
+ if (!context)
+ return {};
+ return context->route_first_wheel_step_for_testing(position, delta_in_css_pixels);
+}
+
void CompositorState::begin_input_trace_for_testing(Web::CompositorContextId context_id)
{
if (auto* context = context_if_present(context_id))
diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.h
index 1c5cb9dec20..13973a6d7e0 100644
--- a/Services/Compositor/CompositorState.h
+++ b/Services/Compositor/CompositorState.h
@@ -127,6 +127,7 @@ public:
void set_synthesizes_scroll_momentum(bool);
void set_scrolls_elastically(bool);
Gfx::FloatPoint elastic_overscroll_stretch_for_testing(Web::CompositorContextId, Web::AsyncScrollNodeStableID) const;
+ Optional<Compositing::FirstWheelStepRouteForTesting> route_first_wheel_step_for_testing(Web::CompositorContextId, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels);
void begin_input_trace_for_testing(Web::CompositorContextId);
Vector<Web::InputTraceRecord> take_input_trace_for_testing(Web::CompositorContextId);
diff --git a/Services/Compositor/CompositorWebContentServer.ipc b/Services/Compositor/CompositorWebContentServer.ipc
index 700dd7486ad..407cf411c9d 100644
--- a/Services/Compositor/CompositorWebContentServer.ipc
+++ b/Services/Compositor/CompositorWebContentServer.ipc
@@ -66,6 +66,7 @@ endpoint CompositorWebContentServer
elastic_overscroll_stretch_for_testing(Web::CompositorContextId context_id, Web::AsyncScrollNodeStableID stable_node_id) => (Gfx::FloatPoint stretch)
// Returns once the compositor has handled every message WebContent sent before it.
synchronize_for_testing() => ()
+ route_first_wheel_step_for_testing(Web::CompositorContextId context_id, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels) => (Optional<Web::InputRoutingDecision> decision, Optional<Web::AsyncScrollNodeStableID> scroller, Optional<Web::UniqueNodeID> document_id)
begin_input_trace_for_testing(Web::CompositorContextId context_id) => ()
take_input_trace_for_testing(Web::CompositorContextId context_id) => (Vector<Web::InputTraceRecord> records)
diff --git a/Services/Compositor/ConnectionFromWebContent.cpp b/Services/Compositor/ConnectionFromWebContent.cpp
index 9d31945d12b..6cc48fe8478 100644
--- a/Services/Compositor/ConnectionFromWebContent.cpp
+++ b/Services/Compositor/ConnectionFromWebContent.cpp
@@ -434,6 +434,16 @@ Messages::CompositorWebContentServer::ElasticOverscrollStretchForTestingResponse
return m_compositor_state->elastic_overscroll_stretch_for_testing(context_id, stable_node_id);
}
+Messages::CompositorWebContentServer::RouteFirstWheelStepForTestingResponse ConnectionFromWebContent::route_first_wheel_step_for_testing(Web::CompositorContextId context_id, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels)
+{
+ if (!context_is_owned_by_this_connection(context_id))
+ return { {}, {}, {} };
+ auto result = m_compositor_state->route_first_wheel_step_for_testing(context_id, position, delta_in_css_pixels);
+ if (!result.has_value())
+ return { {}, {}, {} };
+ return { result->route.decision, result->route.scroller, result->document_id };
+}
+
void ConnectionFromWebContent::begin_input_trace_for_testing(Web::CompositorContextId context_id)
{
if (!context_is_owned_by_this_connection(context_id))
diff --git a/Services/Compositor/ConnectionFromWebContent.h b/Services/Compositor/ConnectionFromWebContent.h
index b9169abbfc7..9429b0fedeb 100644
--- a/Services/Compositor/ConnectionFromWebContent.h
+++ b/Services/Compositor/ConnectionFromWebContent.h
@@ -78,6 +78,7 @@ private:
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 synchronize_for_testing() override { }
+ virtual Messages::CompositorWebContentServer::RouteFirstWheelStepForTestingResponse route_first_wheel_step_for_testing(Web::CompositorContextId, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels) 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;
diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cpp
index 5711f740f64..111cf79976a 100644
--- a/Services/Compositor/ContextState.cpp
+++ b/Services/Compositor/ContextState.cpp
@@ -1244,6 +1244,17 @@ Optional<Gfx::IntRect> ContextState::advance_elastic_overscroll_rebounds(Monoton
return m_async_scrolling_viewport_rect;
}
+Compositing::FirstWheelStepRouteForTesting ContextState::route_first_wheel_step_for_testing(Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels)
+{
+ auto document_id = m_async_scroll_tree.document_id();
+ if (!presents_to_client())
+ return { { Web::InputRoutingDecision::ContextNotPresenting }, document_id };
+ if (!m_scene.display_list() || !m_scene.visual_context_tree().has_value())
+ return { { Web::InputRoutingDecision::NoAsyncScrollingState }, document_id };
+ auto delta = delta_in_css_pixels.scaled(static_cast<float>(m_async_scroll_tree.device_pixels_per_css_pixel()) / m_scene.visual_viewport_magnification());
+ return { m_async_scroll_tree.route_first_wheel_step(m_wheel_gesture_routing.admission(), m_scene.visual_context_tree_for_compositing(), position, delta), document_id };
+}
+
Gfx::FloatPoint ContextState::elastic_overscroll_stretch_for_testing(Web::AsyncScrollNodeStableID stable_node_id) const
{
return m_elastic_overscroll_controller.stretch_of(stable_node_id);
diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.h
index 9a1ac67dcdd..92e1ded21da 100644
--- a/Services/Compositor/ContextState.h
+++ b/Services/Compositor/ContextState.h
@@ -157,6 +157,8 @@ public:
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; }
+ // Where the first step of a wheel gesture at the position, by the delta in CSS pixels, would go.
+ Compositing::FirstWheelStepRouteForTesting route_first_wheel_step_for_testing(Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels);
bool advance_visual_animations(MonotonicTime now);
bool visual_animations_need_frame();
Compositing::PendingAsyncScrollUpdates take_pending_async_scroll_updates();
diff --git a/Services/Compositor/WheelGestureRouting.cpp b/Services/Compositor/WheelGestureRouting.cpp
index d30860446bb..c659fe95bed 100644
--- a/Services/Compositor/WheelGestureRouting.cpp
+++ b/Services/Compositor/WheelGestureRouting.cpp
@@ -18,14 +18,8 @@ static float position_slop_in_device_pixels(Compositing::AsyncScrollTree const&
void WheelGestureRouting::did_install_scrolling_state(Compositing::AsyncScrollingState const& async_scrolling_state)
{
- auto wheel_event_listener_state_generation = async_scrolling_state.wheel_event_listener_state_generation;
- auto admission = Compositing::wheel_routing_admission_for(async_scrolling_state);
- if (wheel_event_listener_state_generation < m_wheel_event_listener_state_generation)
- admission = Compositing::WheelRoutingAdmission::StaleWheelEventListeners;
- else
- m_wheel_event_listener_state_generation = wheel_event_listener_state_generation;
-
- m_admission = admission;
+ m_admission = Compositing::wheel_routing_admission_for(async_scrolling_state, m_wheel_event_listener_state_generation);
+ m_wheel_event_listener_state_generation = max(m_wheel_event_listener_state_generation, async_scrolling_state.wheel_event_listener_state_generation);
m_has_blocking_wheel_event_listeners = async_scrolling_state.has_blocking_wheel_event_listeners;
}
diff --git a/Tests/LibWeb/Text/expected/all-window-properties.txt b/Tests/LibWeb/Text/expected/all-window-properties.txt
index 57b8914fc76..a8ce5a01cb4 100644
--- a/Tests/LibWeb/Text/expected/all-window-properties.txt
+++ b/Tests/LibWeb/Text/expected/all-window-properties.txt
@@ -600,6 +600,8 @@ XRSession
XRSessionEvent
XRSystem
XRWebGLLayer
+__describeNodeOfInputHook
+__describeScrollerOfInputHook
__finishTest
__preventMultipleTestFunctions
animationFrame
@@ -616,4 +618,5 @@ test
timeout
uniqueLocalhostHostname
webkitURL
+wheelTargetToString
withCollectedWrapper
diff --git a/Tests/LibWeb/Text/expected/async-scrolling/recorded-and-compositor-wheel-targets-agree-once-a-frame-lands.txt b/Tests/LibWeb/Text/expected/async-scrolling/recorded-and-compositor-wheel-targets-agree-once-a-frame-lands.txt
new file mode 100644
index 00000000000..d90f3c5850b
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/async-scrolling/recorded-and-compositor-wheel-targets-agree-once-a-frame-lands.txt
@@ -0,0 +1,4 @@
+compositor: latched scroller=viewport
+recorded after the box starts to scroll: latched scroller=#box
+compositor before the next frame: latched scroller=viewport
+compositor after the next frame: latched scroller=#box
diff --git a/Tests/LibWeb/Text/input/async-scrolling/recorded-and-compositor-wheel-targets-agree-once-a-frame-lands.html b/Tests/LibWeb/Text/input/async-scrolling/recorded-and-compositor-wheel-targets-agree-once-a-frame-lands.html
new file mode 100644
index 00000000000..e42b3c5ae4e
--- /dev/null
+++ b/Tests/LibWeb/Text/input/async-scrolling/recorded-and-compositor-wheel-targets-agree-once-a-frame-lands.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<style>
+ body {
+ margin: 0;
+ height: 2000px;
+ }
+ #box {
+ width: 100px;
+ height: 100px;
+ }
+ #box.scrolls {
+ overflow: scroll;
+ }
+ #content {
+ height: 300px;
+ }
+</style>
+<div id="box"><div id="content"></div></div>
+<script>
+ promiseTest(async () => {
+ await animationFrame();
+ await animationFrame();
+ println(`compositor: ${wheelTargetToString(internals.compositorWheelTargetAt(50, 50, 0, 10))}`);
+
+ // The display list that WebContent records once the box scrolls routes the step to the box. The compositor
+ // routes it with the last frame it has until the next one lands.
+ box.classList.add("scrolls");
+ internals.recordDisplayListForTesting();
+ println(`recorded after the box starts to scroll: ${wheelTargetToString(internals.recordedDisplayListWheelTargetAt(50, 50, 0, 10))}`);
+ println(`compositor before the next frame: ${wheelTargetToString(internals.compositorWheelTargetAt(50, 50, 0, 10))}`);
+
+ await animationFrame();
+ await animationFrame();
+ println(`compositor after the next frame: ${wheelTargetToString(internals.compositorWheelTargetAt(50, 50, 0, 10))}`);
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/include.js b/Tests/LibWeb/Text/input/include.js
index fb24774ff1a..2e470f0c8e4 100644
--- a/Tests/LibWeb/Text/input/include.js
+++ b/Tests/LibWeb/Text/input/include.js
@@ -101,15 +101,29 @@ async function scrollSettled(target, action) {
await scrollend;
}
+function __describeNodeOfInputHook(node, documentName = "document") {
+ if (node instanceof Document) return node === document ? documentName : `nested ${documentName}`;
+ if (node.id) return `#${node.id}`;
+ return node.nodeName.toLowerCase();
+}
+
+function __describeScrollerOfInputHook(result) {
+ if (!result.scroller) return "";
+ let description = ` scroller=${__describeNodeOfInputHook(result.scroller, "viewport")}`;
+ if (result.scrollerPseudoElement) description += `::${result.scrollerPseudoElement}`;
+ return description;
+}
+
+// Describes where internals.compositorWheelTargetAt() or internals.recordedDisplayListWheelTargetAt() says a wheel step
+// goes.
+function wheelTargetToString(target) {
+ return `${target.decision}${__describeScrollerOfInputHook(target)}`;
+}
+
// 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 = "-";
@@ -118,12 +132,8 @@ function printInputTrace(trace, { stages } = {}) {
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)}`;
+ let line = `${eventNumber} ${record.stage}: ${record.decision}${__describeScrollerOfInputHook(record)}`;
+ if (record.target) line += ` target=${__describeNodeOfInputHook(record.target)}`;
println(line);
}
}