Skip to content

Truly independent web browser

LibWeb+Compositor: Let tests send mouse events through the UI process

Aliaksandr Kalenikcc06b7200959
diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.cpp b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
index d5f00450d7c..edcd059fc16 100644
--- a/Libraries/LibWeb/Compositor/CompositorConnection.cpp
+++ b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
@@ -451,6 +451,14 @@ Gfx::FloatPoint CompositorConnection::elastic_overscroll_stretch_for_testing(Web
return response->stretch();
}
+void CompositorConnection::synchronize_for_testing()
+{
+ if (!can_send_message_to_compositor())
+ return;
+ if (!send_sync_but_allow_failure<Messages::CompositorWebContentServer::SynchronizeForTesting>())
+ did_lose_compositor();
+}
+
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 0d04a698898..abedb3a8663 100644
--- a/Libraries/LibWeb/Compositor/CompositorConnection.h
+++ b/Libraries/LibWeb/Compositor/CompositorConnection.h
@@ -71,6 +71,7 @@ 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 synchronize_for_testing();
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 05c8e94dca3..2612ded0888 100644
--- a/Libraries/LibWeb/Compositor/CompositorHost.cpp
+++ b/Libraries/LibWeb/Compositor/CompositorHost.cpp
@@ -83,6 +83,11 @@ Gfx::FloatPoint CompositorContextHandle::elastic_overscroll_stretch_for_testing(
return m_host.elastic_overscroll_stretch_for_testing(m_context_id, stable_node_id);
}
+void CompositorContextHandle::synchronize_for_testing()
+{
+ m_host.synchronize_for_testing();
+}
+
void CompositorContextHandle::begin_input_trace_for_testing()
{
m_host.begin_input_trace_for_testing(m_context_id);
@@ -446,6 +451,12 @@ Gfx::FloatPoint CompositorHost::elastic_overscroll_stretch_for_testing(Web::Comp
return {};
}
+void CompositorHost::synchronize_for_testing()
+{
+ if (auto* connection = compositor_connection())
+ connection->synchronize_for_testing();
+}
+
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 4eef1f2e80c..d8190da9e22 100644
--- a/Libraries/LibWeb/Compositor/CompositorHost.h
+++ b/Libraries/LibWeb/Compositor/CompositorHost.h
@@ -62,6 +62,7 @@ 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 synchronize_for_testing();
void begin_input_trace_for_testing();
Vector<Web::InputTraceRecord> take_input_trace_for_testing();
Compositing::PendingAsyncScrollUpdates take_pending_async_scroll_updates(Compositing::AsyncScrollUpdateFreshness);
@@ -122,6 +123,7 @@ 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 synchronize_for_testing();
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 64d44fe5ac3..b87a5f150bf 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -610,8 +610,31 @@ void Internals::send_text(HTML::HTMLElement& target, Utf16String const& text, We
}
}
+// 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();
+}
+
+// Frames reach the compositor from WebContent, and input from the UI. Input that a test sends through the UI once the
+// compositor has every frame rendered so far meets the content the test has rendered, as the user's input would.
+static void let_compositor_take_in_every_rendered_frame(HTML::Window& window)
+{
+ auto& page = window.page();
+ for (auto& navigable : HTML::all_local_navigables()) {
+ if (&navigable->page() == &page && !navigable->has_been_destroyed())
+ (void)navigable->take_recording_in_flight_in(HTML::LocalNavigable::TakeIn::Wait);
+ }
+ if (auto* compositor_context = compositor_context_routing_input_for(window))
+ compositor_context->synchronize_for_testing();
+}
+
void Internals::send_text_through_ui_process(Utf16String const& text)
{
+ let_compositor_take_in_every_rendered_frame(window());
for (auto code_point : text) {
for (auto type : { Web::KeyEvent::Type::KeyDown, Web::KeyEvent::Type::KeyUp }) {
Web::KeyEvent event;
@@ -629,56 +652,99 @@ void Internals::grant_transient_activation()
window().notify_about_user_activation();
}
-// A click the UI process routes, as it would a user's, to the page hosting the document under it.
-void Internals::click_through_ui_process(double x, double y)
+namespace {
+
+struct MouseEventsTheUIProcessHasNotHandledYet : public RefCounted<MouseEventsTheUIProcessHasNotHandledYet> {
+ size_t count { 0 };
+};
+
+}
+
+// A mouse event at a position in this document's viewport, as the UI process sends it to the page hosting the document.
+Web::MouseEvent Internals::mouse_event_through_ui_process_at(Web::MouseEvent::Type type, double x, double y)
+{
+ auto position = page().css_to_device_point(window().navigable()->to_page_position({ x, y }));
+ Web::MouseEvent event;
+ event.type = type;
+ event.position = position;
+ event.screen_position = position;
+ return event;
+}
+
+// Sends mouse events through the UI process as it sends the user's, and resolves the promise once the UI has handled
+// every one of them.
+void Internals::send_mouse_events_through_ui_process(Vector<Web::MouseEvent> events, GC::Ref<WebIDL::Promise> promise)
{
+ let_compositor_take_in_every_rendered_frame(window());
+
auto& page = this->page();
- auto position = page.css_to_device_point(window().navigable()->to_page_position({ x, y }));
auto local_root_id = window().navigable()->local_root()->id();
+ auto& realm = window().principal_realm();
+ auto unhandled_events = make_ref_counted<MouseEventsTheUIProcessHasNotHandledYet>();
+ unhandled_events->count = events.size();
+ for (auto& event : events) {
+ page.client().page_did_request_webdriver_mouse_event(local_root_id, move(event), GC::create_function(heap(), [&realm, promise, unhandled_events] {
+ if (--unhandled_events->count != 0)
+ return;
+ HTML::TemporaryExecutionContext execution_context { realm };
+ WebIDL::resolve_promise(realm, promise);
+ }));
+ }
+}
+
+void Internals::click_through_ui_process(double x, double y, GC::Ref<WebIDL::Promise> promise)
+{
+ Vector<Web::MouseEvent> events;
for (auto type : { Web::MouseEvent::Type::MouseDown, Web::MouseEvent::Type::MouseUp }) {
- Web::MouseEvent event;
- event.type = type;
- event.position = position;
- event.screen_position = position;
+ auto event = mouse_event_through_ui_process_at(type, x, y);
event.button = UIEvents::MouseButton::Primary;
event.buttons = type == Web::MouseEvent::Type::MouseDown ? UIEvents::MouseButton::Primary : UIEvents::MouseButton::None;
event.click_count = 1;
- page.client().page_did_request_webdriver_mouse_event(local_root_id, move(event), GC::create_function(heap(), [] { }));
+ events.append(move(event));
}
+ send_mouse_events_through_ui_process(move(events), promise);
}
-// A mouse move the UI process routes, as it would a user's, through the compositor, which tells the render clock of it
-// too.
-void Internals::mouse_move_through_ui_process(double x, double y)
+static Web::MouseEvent::Type mouse_event_type_from(Bindings::MouseEventThroughUIProcessType type)
{
- auto& page = this->page();
- auto position = page.css_to_device_point(window().navigable()->to_page_position({ x, y }));
- Web::MouseEvent event;
- event.type = Web::MouseEvent::Type::MouseMove;
- event.position = position;
- event.screen_position = position;
- page.client().page_did_request_webdriver_mouse_event(window().navigable()->local_root()->id(), move(event), GC::create_function(heap(), [] { }));
+ switch (type) {
+ case Bindings::MouseEventThroughUIProcessType::Mousedown:
+ return Web::MouseEvent::Type::MouseDown;
+ case Bindings::MouseEventThroughUIProcessType::Mouseup:
+ return Web::MouseEvent::Type::MouseUp;
+ case Bindings::MouseEventThroughUIProcessType::Mousemove:
+ return Web::MouseEvent::Type::MouseMove;
+ case Bindings::MouseEventThroughUIProcessType::Mouseleave:
+ return Web::MouseEvent::Type::MouseLeave;
+ }
+ VERIFY_NOT_REACHED();
}
-void Internals::wheel_through_ui_process(double x, double y, double delta_x, double delta_y, bool precise, Bindings::ScrollGesturePhase phase, GC::Ref<WebIDL::Promise> promise)
+void Internals::mouse_event_through_ui_process(Bindings::MouseEventThroughUIProcessType type, double x, double y, Bindings::MouseEventThroughUIProcessOptions const& options, GC::Ref<WebIDL::Promise> promise)
{
- auto& page = this->page();
- auto position = page.css_to_device_point(window().navigable()->to_page_position({ x, y }));
- auto local_root_id = window().navigable()->local_root()->id();
+ auto event = mouse_event_through_ui_process_at(mouse_event_type_from(type), x, y);
+ event.button = button_from_unsigned_short(options.button);
+ if (options.buttons.has_value())
+ event.buttons = static_cast<UIEvents::MouseButton>(*options.buttons);
+ else if (event.type == Web::MouseEvent::Type::MouseDown)
+ event.buttons = event.button;
+ event.modifiers = static_cast<UIEvents::KeyModifier>(options.modifiers);
+ event.click_count = options.click_count;
+ Vector<Web::MouseEvent> events;
+ events.append(move(event));
+ send_mouse_events_through_ui_process(move(events), promise);
+}
- Web::MouseEvent event;
- event.type = Web::MouseEvent::Type::MouseWheel;
- event.position = position;
- event.screen_position = position;
+void Internals::wheel_through_ui_process(double x, double y, double delta_x, double delta_y, bool precise, Bindings::ScrollGesturePhase phase, GC::Ref<WebIDL::Promise> promise)
+{
+ auto event = mouse_event_through_ui_process_at(Web::MouseEvent::Type::MouseWheel, x, y);
event.wheel_delta_x = delta_x;
event.wheel_delta_y = delta_y;
event.wheel_delta_precision = wheel_delta_precision_from(precise);
event.scroll_gesture_phase = scroll_gesture_phase_from(phase);
- auto& realm = window().principal_realm();
- page.client().page_did_request_webdriver_mouse_event(local_root_id, move(event), GC::create_function(heap(), [&realm, promise] {
- HTML::TemporaryExecutionContext execution_context { realm };
- WebIDL::resolve_promise(realm, promise);
- }));
+ Vector<Web::MouseEvent> events;
+ events.append(move(event));
+ send_mouse_events_through_ui_process(move(events), promise);
}
void Internals::send_key(HTML::HTMLElement& target, Utf16String const& key_name, WebIDL::UnsignedShort modifiers, WebIDL::UnsignedLong repeat_count)
@@ -733,21 +799,6 @@ void Internals::mouse_down(double x, double y, WebIDL::UnsignedShort click_count
page.handle_mousedown(position, position, button_from_unsigned_short(button), 0, modifiers, click_count);
}
-void Internals::mouse_down_on_scrollbar_dragged_by_compositor(double x, double y, DOM::Element& scroller, bool vertical)
-{
- Layout::ForcedReadScope read { scroller.document() };
- scroller.document().update_layout(DOM::UpdateLayoutReason::InternalsHitTest);
- auto const* scrolling_box = scroller.layout_node(read);
- VERIFY(scrolling_box);
- auto scroller_stable_node_id = Painting::async_scroll_node_stable_id(*scrolling_box);
- VERIFY(scroller_stable_node_id.has_value());
-
- auto& page = this->page();
- auto position = page.css_to_device_point({ x, y });
- page.handle_mousedown(position, position, UIEvents::MouseButton::Primary, 0, 0, 1,
- Web::ScrollbarDraggedByCompositor { .scroller_stable_node_id = *scroller_stable_node_id, .vertical = vertical });
-}
-
void Internals::mouse_up(double x, double y, WebIDL::UnsignedShort button, WebIDL::UnsignedShort modifiers)
{
auto& page = this->page();
@@ -1227,15 +1278,6 @@ 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();
diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.h
index cf4e528a4dd..86ae0d1a26a 100644
--- a/Libraries/LibWeb/Internals/Internals.h
+++ b/Libraries/LibWeb/Internals/Internals.h
@@ -14,6 +14,7 @@
#include <LibWeb/Internals/InternalAnimationTimeline.h>
#include <LibWeb/Internals/InternalsBase.h>
#include <LibWeb/Painting/Forward.h>
+#include <LibWebCommon/Page/InputEvent.h>
#include <LibWebCommon/UIEvents/MouseButton.h>
#include <LibWebCommon/WebIDL/Types.h>
@@ -91,8 +92,8 @@ public:
void send_text(HTML::HTMLElement&, Utf16String const&, WebIDL::UnsignedShort modifiers);
void send_text_through_ui_process(Utf16String const&);
void grant_transient_activation();
- void mouse_move_through_ui_process(double x, double y);
- void click_through_ui_process(double x, double y);
+ void click_through_ui_process(double x, double y, GC::Ref<WebIDL::Promise>);
+ void mouse_event_through_ui_process(Bindings::MouseEventThroughUIProcessType, double x, double y, Bindings::MouseEventThroughUIProcessOptions const&, GC::Ref<WebIDL::Promise>);
void wheel_through_ui_process(double x, double y, double delta_x, double delta_y, bool precise, Bindings::ScrollGesturePhase, GC::Ref<WebIDL::Promise>);
void send_key(HTML::HTMLElement&, Utf16String const&, WebIDL::UnsignedShort modifiers, WebIDL::UnsignedLong repeat_count);
WebIDL::ExceptionOr<void> send_text_editing_command(HTML::HTMLElement&, Utf16String const& command_name, bool extend_selection);
@@ -102,7 +103,6 @@ public:
// Low-level mouse primitives
void mouse_down(double x, double y, WebIDL::UnsignedShort click_count, WebIDL::UnsignedShort button, WebIDL::UnsignedShort modifiers);
- void mouse_down_on_scrollbar_dragged_by_compositor(double x, double y, DOM::Element& scroller, bool vertical);
void mouse_up(double x, double y, WebIDL::UnsignedShort button, WebIDL::UnsignedShort modifiers);
void mouse_move(double x, double y, WebIDL::UnsignedShort modifiers);
void mouse_leave();
@@ -313,6 +313,8 @@ public:
String viewport_overflow_x();
private:
+ 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&);
virtual void visit_edges(GC::Cell::Visitor&) override;
diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idl
index 83270a5fc11..44e72113d46 100644
--- a/Libraries/LibWeb/Internals/Internals.idl
+++ b/Libraries/LibWeb/Internals/Internals.idl
@@ -67,9 +67,10 @@ interface Internals {
undefined sendText(HTMLElement target, DOMString text, optional unsigned short modifiers = 0);
undefined sendTextThroughUIProcess(DOMString text);
undefined grantTransientActivation();
- undefined clickThroughUIProcess(double x, double y);
- undefined mouseMoveThroughUIProcess(double x, double y);
- // Resolves once the UI process reports that the event has been handled.
+ // These send input as the UI process would send the user's, after the compositor has every frame rendered so far,
+ // and resolve once the UI process reports that the input has been handled.
+ [CreatesPromise] Promise<undefined> clickThroughUIProcess(double x, double y);
+ [CreatesPromise] Promise<undefined> mouseEventThroughUIProcess(MouseEventThroughUIProcessType type, double x, double y, optional MouseEventThroughUIProcessOptions options = {});
[CreatesPromise] Promise<undefined> wheelThroughUIProcess(double x, double y, double deltaX, double deltaY, optional boolean precise = false, optional ScrollGesturePhase scrollGesturePhase = "none");
undefined sendKey(HTMLElement target, DOMString keyName, optional unsigned short modifiers = 0, optional unsigned long repeatCount = 1);
undefined sendTextEditingCommand(HTMLElement target, DOMString commandName, optional boolean extendSelection = false);
@@ -79,7 +80,6 @@ interface Internals {
// Low-level mouse primitives
undefined mouseDown(double x, double y, optional unsigned short clickCount = 1, optional unsigned short button = 0, optional unsigned short modifiers = 0);
- undefined mouseDownOnScrollbarDraggedByCompositor(double x, double y, Element scroller, boolean vertical);
undefined mouseUp(double x, double y, optional unsigned short button = 0, optional unsigned short modifiers = 0);
undefined mouseMove(double x, double y, optional unsigned short modifiers = 0);
undefined mouseLeave();
@@ -375,3 +375,12 @@ interface Internals {
enum SpellingMenuItem { "none", "guess", "ignore", "learn" };
enum ScrollGesturePhase { "none", "ongoing", "momentum", "ended" };
+enum MouseEventThroughUIProcessType { "mousedown", "mouseup", "mousemove", "mouseleave" };
+
+dictionary MouseEventThroughUIProcessOptions {
+ unsigned short button = 0;
+ // The buttons held once the event has happened. By default, the button a mousedown presses, and none otherwise.
+ unsigned short buttons;
+ unsigned short modifiers = 0;
+ unsigned short clickCount = 1;
+};
diff --git a/Libraries/LibWeb/Page/Page.cpp b/Libraries/LibWeb/Page/Page.cpp
index d7883c5d819..ba1a727b8ea 100644
--- a/Libraries/LibWeb/Page/Page.cpp
+++ b/Libraries/LibWeb/Page/Page.cpp
@@ -445,9 +445,9 @@ EventResult Page::handle_mousedown(HTML::LocalNavigable& root, DevicePixelPoint
return root.event_handler().handle_mousedown(device_to_css_point(position), device_to_css_point(screen_position), button, buttons, modifiers, click_count, scrollbar_dragged_by_compositor, remote_target);
}
-EventResult Page::handle_mousedown(DevicePixelPoint position, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, int click_count, Optional<Web::ScrollbarDraggedByCompositor> const& scrollbar_dragged_by_compositor)
+EventResult Page::handle_mousedown(DevicePixelPoint position, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, int click_count)
{
- return handle_mousedown(local_traversable(), position, screen_position, button, buttons, modifiers, click_count, scrollbar_dragged_by_compositor, nullptr);
+ return handle_mousedown(local_traversable(), position, screen_position, button, buttons, modifiers, click_count, {}, nullptr);
}
void Page::set_mouse_event_tracking_navigable(Badge<EventHandler>, HTML::LocalNavigable& navigable)
diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h
index 7153ba61bdd..e5012a2be4d 100644
--- a/Libraries/LibWeb/Page/Page.h
+++ b/Libraries/LibWeb/Page/Page.h
@@ -196,7 +196,7 @@ public:
EventResult handle_pinch_event(HTML::LocalNavigable& root, DevicePixelPoint point, unsigned modifiers, double scale);
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, Optional<Web::ScrollbarDraggedByCompositor> const& = {});
+ EventResult handle_mousedown(DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, int click_count);
EventResult handle_mousemove(DevicePixelPoint, DevicePixelPoint screen_position, unsigned buttons, unsigned modifiers);
EventResult handle_mouseleave();
void set_mouse_event_tracking_navigable(Badge<EventHandler>, HTML::LocalNavigable&);
diff --git a/Services/Compositor/CompositorWebContentServer.ipc b/Services/Compositor/CompositorWebContentServer.ipc
index 9dae8215305..700dd7486ad 100644
--- a/Services/Compositor/CompositorWebContentServer.ipc
+++ b/Services/Compositor/CompositorWebContentServer.ipc
@@ -64,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)
+ // Returns once the compositor has handled every message WebContent sent before it.
+ synchronize_for_testing() => ()
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.h b/Services/Compositor/ConnectionFromWebContent.h
index ee6bb7bdf3f..b9169abbfc7 100644
--- a/Services/Compositor/ConnectionFromWebContent.h
+++ b/Services/Compositor/ConnectionFromWebContent.h
@@ -77,6 +77,7 @@ 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 synchronize_for_testing() 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/Tests/LibWeb/Text/expected/UIEvents/scrollbar-drag-driven-by-compositor.txt b/Tests/LibWeb/Text/expected/UIEvents/scrollbar-drag-driven-by-compositor.txt
index 2b177a29f1f..67ac93b974e 100644
--- a/Tests/LibWeb/Text/expected/UIEvents/scrollbar-drag-driven-by-compositor.txt
+++ b/Tests/LibWeb/Text/expected/UIEvents/scrollbar-drag-driven-by-compositor.txt
@@ -1,5 +1,19 @@
+#1 compositor: not-over-a-scrollbar
+#1 compositor: forwarded-to-page
+#1 web-content: finished-handled
+#2 compositor: began-scrollbar-drag scroller=#scroller
+#2 compositor: forwarded-to-page
+#2 web-content: scrollbar-drag-driven-by-compositor scroller=#scroller
+#2 web-content: finished-handled
+#3 compositor: continued-scrollbar-drag scroller=#scroller
+#3 compositor: forwarded-to-page
+#3 web-content: finished-handled
+#4 compositor: continued-scrollbar-drag scroller=#scroller
+#4 compositor: forwarded-to-page
+#4 web-content: finished-handled
+#5 compositor: ended-scrollbar-drag scroller=#scroller
+#5 compositor: forwarded-to-page
+#5 web-content: finished-handled
pointerdown reached the scroller: true
-scrolled while the compositor drives the drag: false
-scrolled after leaving the scrollbar: false
-scrolled after the release: false
+scrollTop after the drag: 900
scrolled by an ordinary drag afterwards: true
diff --git a/Tests/LibWeb/Text/input/UIEvents/scrollbar-drag-driven-by-compositor.html b/Tests/LibWeb/Text/input/UIEvents/scrollbar-drag-driven-by-compositor.html
index 0a5c2baac02..5d506bd2b7e 100644
--- a/Tests/LibWeb/Text/input/UIEvents/scrollbar-drag-driven-by-compositor.html
+++ b/Tests/LibWeb/Text/input/UIEvents/scrollbar-drag-driven-by-compositor.html
@@ -20,33 +20,31 @@ body {
</div>
<script src="../include.js"></script>
<script>
- asyncTest(done => {
+ promiseTest(async () => {
let pointerDownCount = 0;
scroller.addEventListener("pointerdown", () => ++pointerDownCount);
+ await animationFrame();
+ await animationFrame();
- // The compositor scrolls for this drag, so the main thread must not.
- internals.mouseMove(147, 5);
- internals.mouseDownOnScrollbarDraggedByCompositor(147, 5, scroller, true);
- internals.mouseMove(147, 60);
+ // The compositor scrolls for a drag of the scrollbar, and the page sees the drag's events without scrolling
+ // for them a second time. A move far away from the scrollbar still belongs to the captured drag.
+ internals.beginInputTrace();
+ await internals.mouseEventThroughUIProcess("mousemove", 147, 5);
+ await internals.mouseEventThroughUIProcess("mousedown", 147, 5);
+ await internals.mouseEventThroughUIProcess("mousemove", 147, 60, { buttons: 1 });
+ await internals.mouseEventThroughUIProcess("mousemove", 20, 90, { buttons: 1 });
+ await internals.mouseEventThroughUIProcess("mouseup", 20, 90);
+ printInputTrace(internals.takeInputTrace());
+ await animationFrame();
println(`pointerdown reached the scroller: ${pointerDownCount === 1}`);
- println(`scrolled while the compositor drives the drag: ${scroller.scrollTop > 0}`);
-
- // A move far away from the scrollbar still belongs to the captured drag.
- internals.mouseMove(20, 90);
- println(`scrolled after leaving the scrollbar: ${scroller.scrollTop > 0}`);
-
- internals.mouseUp(20, 90);
- internals.mouseMove(147, 5);
- println(`scrolled after the release: ${scroller.scrollTop > 0}`);
+ println(`scrollTop after the drag: ${scroller.scrollTop}`);
// The scrollbar takes an ordinary drag again once the compositor's has ended.
+ scroller.scrollTop = 0;
internals.mouseDown(147, 5);
internals.mouseMove(147, 60);
internals.mouseUp(147, 60);
-
- requestAnimationFrame(() => {
- println(`scrolled by an ordinary drag afterwards: ${scroller.scrollTop > 0}`);
- done();
- });
+ await animationFrame();
+ println(`scrolled by an ordinary drag afterwards: ${scroller.scrollTop > 0}`);
});
</script>
diff --git a/Tests/LibWeb/Text/input/async-scrolling/wheel-listener-added-mid-gesture-sees-the-next-step-first.html b/Tests/LibWeb/Text/input/async-scrolling/wheel-listener-added-mid-gesture-sees-the-next-step-first.html
index 84f15446ebe..12c4b204109 100644
--- a/Tests/LibWeb/Text/input/async-scrolling/wheel-listener-added-mid-gesture-sees-the-next-step-first.html
+++ b/Tests/LibWeb/Text/input/async-scrolling/wheel-listener-added-mid-gesture-sees-the-next-step-first.html
@@ -23,8 +23,6 @@
// A blocking listener added during the gesture is asked about the next step, which the page could cancel.
document.addEventListener("wheel", () => {}, { passive: false });
- // A synchronous call to the compositor, so that it has heard about the new listener before the next step.
- internals.elasticOverscrollStretchY();
await internals.wheelThroughUIProcess(400, 300, 0, 50, true, "ongoing");
await internals.wheelThroughUIProcess(400, 300, 0, 50, true, "ongoing");
println(`cancelable steps: ${cancelableSteps.join(", ")}`);