Skip to content

Truly independent web browser

LibWeb+LibWebCommon+Compositor: Let the browser cancel a press

Luke Wildef92c8bcc4ce8
diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h
index 3178dd342d1..4361397f9ad 100644
--- a/Libraries/LibWeb/DOM/Document.h
+++ b/Libraries/LibWeb/DOM/Document.h
@@ -150,6 +150,7 @@ enum class InvalidateLayoutTreeReason {
X(EventHandlerDispatchChromeWidgetEvent, false) \
X(EventHandlerHandleDragAndDrop, false) \
X(EventHandlerHandleKeyDown, false) \
+ X(EventHandlerHandleMouseCancel, false) \
X(EventHandlerHandleMouseDown, false) \
X(EventHandlerHandleMouseMove, false) \
X(EventHandlerHandleMouseUp, false) \
diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
index 0d41ce32325..4bfc384015a 100644
--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
@@ -469,6 +469,8 @@ void EventLoop::process_input_events() const
return page.handle_mousemove(*root, mouse_event.position, mouse_event.screen_position, mouse_event.buttons, mouse_event.modifiers, &remote_target);
case Web::MouseEvent::Type::MouseLeave:
return page.handle_mouseleave(*root);
+ case Web::MouseEvent::Type::MouseCancel:
+ return page.handle_mousecancel(*root);
case Web::MouseEvent::Type::MouseWheel:
if (mouse_event.async_scroll_performed_default_action) {
dbgln_if(COMPOSITOR_DEBUG, "[Compositor] Main thread handling DOM wheel after async default action");
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp
index e95ce84323d..d20a74374c2 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -819,6 +819,11 @@ void Internals::mouse_leave()
this->page().handle_mouseleave();
}
+void Internals::mouse_cancel()
+{
+ this->page().handle_mousecancel();
+}
+
void Internals::click(double x, double y, WebIDL::UnsignedShort click_count, WebIDL::UnsignedShort button, WebIDL::UnsignedShort modifiers)
{
click_and_hold(x, y, click_count, button, modifiers);
diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.h
index afdc5e1f098..8db2c77650a 100644
--- a/Libraries/LibWeb/Internals/Internals.h
+++ b/Libraries/LibWeb/Internals/Internals.h
@@ -107,6 +107,7 @@ public:
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();
+ void mouse_cancel();
// High-level mouse conveniences
void click(double x, double y, WebIDL::UnsignedShort click_count, WebIDL::UnsignedShort button, WebIDL::UnsignedShort modifiers);
diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idl
index 7ce265ba551..bcd6616da77 100644
--- a/Libraries/LibWeb/Internals/Internals.idl
+++ b/Libraries/LibWeb/Internals/Internals.idl
@@ -83,6 +83,7 @@ interface Internals {
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();
+ undefined mouseCancel();
// High-level mouse conveniences
undefined click(double x, double y, optional unsigned short clickCount = 1, optional unsigned short button = 0, optional unsigned short modifiers = 0);
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp
index a6d36bb421d..9c2e1f480ee 100644
--- a/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Libraries/LibWeb/Page/EventHandler.cpp
@@ -1364,6 +1364,63 @@ EventResult EventHandler::handle_mouseleave()
return EventResult::Handled;
}
+// https://w3c.github.io/pointerevents/#dfn-suppress-a-pointer-event-stream
+EventResult EventHandler::handle_mousecancel()
+{
+ if (should_ignore_device_input_event()) {
+ if (m_mousedown_target_is_drag_candidate)
+ return cancel_drag_and_drop_event(m_last_known_mouse_visual_viewport_position.value_or({}), m_last_known_mouse_screen_position, UIEvents::MouseButton::Primary, UIEvents::MouseButton::Primary, 0);
+
+ return EventResult::Dropped;
+ }
+
+ ScopeGuard clear_mousedown_tracking_and_stop_selection([&] {
+ clear_mousedown_tracking();
+ stop_updating_selection();
+ });
+
+ auto document = m_navigable->active_document();
+ if (!document)
+ return EventResult::Dropped;
+ if (!document->is_fully_active())
+ return EventResult::Dropped;
+
+ Layout::ForcedReadScope read { *document };
+ document->update_layout(DOM::UpdateLayoutReason::EventHandlerHandleMouseCancel);
+
+ if (!has_committed_root_box())
+ return EventResult::Dropped;
+
+ // NB: The browser cancels the pointer that presses, so there is a stream to suppress only while a press lasts. The
+ // last pointer event's target is the effective position of the legacy mouse pointer.
+ GC::Ptr<DOM::Node> target = m_effective_legacy_mouse_pointer_position.ptr();
+ if (!m_mousedown_target || !target || !m_last_dispatched_pointer_event_position.has_value())
+ return EventResult::Dropped;
+
+ // 1. Fire a pointercancel event.
+ // https://w3c.github.io/pointerevents/#dfn-pointercancel
+ // The values of the following properties of the pointercancel event MUST match the values of the last dispatched
+ // pointer event with the same pointerId: [...] and the coordinates inherited from Mouse Events.
+ auto const& last_position = *m_last_dispatched_pointer_event_position;
+ dispatch_a_pointer_event_for_a_device_that_supports_hover(PointerEventType::PointerCancel, target, nullptr, last_position.coordinates, last_position.screen_position, {}, UIEvents::MouseButton::Primary, m_last_known_mouse_buttons, m_last_known_mouse_modifiers);
+
+ // NB: Dispatching an event may have disturbed the world.
+ if (m_navigable->active_document() != document)
+ return EventResult::Handled;
+
+ // 2. Fire a pointerout event.
+ // 3. Fire a pointerleave event.
+ // NB: Moving the legacy mouse pointer out of the window fires both, along with the compatibility mouse events of
+ // a pointerleave event at the window.
+ track_the_effective_position_of_the_legacy_mouse_pointer(nullptr);
+
+ // 4. Implicitly release the pointer capture if the pointer is currently captured.
+ // NB: The press is released as this returns.
+ // FIXME: Also end a drag that a chrome widget, such as a scrollbar, has captured.
+
+ return EventResult::Handled;
+}
+
// The same-process nested navigable the pointer was over last hears that it left, as the pointer moves elsewhere: its
// document hovers nothing more, and fires the boundary events of that.
void EventHandler::update_nested_navigable_under_pointer(GC::Ptr<HTML::LocalNavigable> navigable)
@@ -4175,6 +4232,11 @@ EventHandler::PointerEventDispatchResult EventHandler::dispatch_a_pointer_event_
}();
auto pointer_event = MUST(UIEvents::PointerEvent::create_from_platform_event(relevant_global_object, m_navigable->active_window_proxy(), pointer_event_name, screen_position, coordinates.page_offset, coordinates.viewport_position, coordinates.offset, movement, button, buttons, modifiers));
+ // https://w3c.github.io/pointerevents/#dfn-pointercancel
+ // The event's cancelable attribute MUST be false.
+ if (type == PointerEventType::PointerCancel)
+ pointer_event->set_cancelable(false);
+
// FIXME: 1. If the isPrimary property for the pointer event to be dispatched is false then dispatch the
// pointer event and terminate these steps.
@@ -4214,6 +4276,7 @@ EventHandler::PointerEventDispatchResult EventHandler::dispatch_a_pointer_event_
light_dismiss_activities(pointer_event, *node);
// 3. Dispatch the pointer event.
+ m_last_dispatched_pointer_event_position = PointerEventPosition { coordinates, screen_position };
bool pointer_event_cancelled = !node->dispatch_event(pointer_event);
// 4. If the pointer event dispatched was pointerdown and event's canceled flag is set, then set the PREVENT MOUSE
diff --git a/Libraries/LibWeb/Page/EventHandler.h b/Libraries/LibWeb/Page/EventHandler.h
index 2b50eae6c56..dc533bfd524 100644
--- a/Libraries/LibWeb/Page/EventHandler.h
+++ b/Libraries/LibWeb/Page/EventHandler.h
@@ -70,6 +70,7 @@ public:
EventResult handle_mouseup(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, Optional<RemoteInputEventTarget>* remote_target = nullptr);
EventResult handle_mousewheel(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, Web::WheelDeltaPrecision = Web::WheelDeltaPrecision::Discrete, Web::ScrollGesturePhase = Web::ScrollGesturePhase::None, bool async_scroll_performed_default_action = false, Optional<AsyncScrollOperation>* async_scroll_operation = nullptr, Optional<RemoteInputEventTarget>* remote_target = nullptr);
EventResult handle_mouseleave();
+ EventResult handle_mousecancel();
EventResult insert_replacement_text(Utf16String const&);
#if defined(AK_OS_MACOS)
bool select_word_for_dictionary_lookup(CSSPixelPoint visual_viewport_position);
@@ -261,6 +262,13 @@ private:
unsigned m_last_known_mouse_buttons { 0 };
unsigned m_last_known_mouse_modifiers { 0 };
+ // Where the last pointer event dispatched to the page was, which a pointercancel repeats.
+ struct PointerEventPosition {
+ MouseEventCoordinates coordinates;
+ CSSPixelPoint screen_position;
+ };
+ Optional<PointerEventPosition> m_last_dispatched_pointer_event_position;
+
OwnPtr<AutoScrollHandler> m_auto_scroll_handler;
OwnPtr<MiddleButtonScrollHandler> m_middle_button_scroll_handler;
NonnullOwnPtr<DragAndDropEventHandler> m_drag_and_drop_event_handler;
diff --git a/Libraries/LibWeb/Page/Page.cpp b/Libraries/LibWeb/Page/Page.cpp
index 847f25742f7..832bdf2fcc4 100644
--- a/Libraries/LibWeb/Page/Page.cpp
+++ b/Libraries/LibWeb/Page/Page.cpp
@@ -483,6 +483,25 @@ EventResult Page::handle_mouseleave()
return handle_mouseleave(local_traversable());
}
+EventResult Page::handle_mousecancel(HTML::LocalNavigable& root)
+{
+ // The press that is cancelled is tracked by the navigable it began in, which may be nested in the root.
+ GC::Ptr<HTML::LocalNavigable> navigable = m_mouse_event_tracking_navigable.ptr();
+ m_mouse_event_tracking_navigable = nullptr;
+ if (!navigable)
+ navigable = root;
+ auto result = navigable->event_handler().handle_mousecancel();
+
+ // The cancelled pointer has left the page, so no document in it hovers anything until the pointer moves again.
+ (void)root.event_handler().handle_mouseleave();
+ return result;
+}
+
+EventResult Page::handle_mousecancel()
+{
+ return handle_mousecancel(local_traversable());
+}
+
#if defined(AK_OS_MACOS)
bool Page::select_word_for_dictionary_lookup(DevicePixelPoint position)
{
diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h
index 4f5f8e76f48..224977d29d6 100644
--- a/Libraries/LibWeb/Page/Page.h
+++ b/Libraries/LibWeb/Page/Page.h
@@ -193,6 +193,7 @@ public:
EventResult handle_mousedown(HTML::LocalNavigable& root, DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, int click_count, Optional<Web::ScrollbarDraggedByCompositor> const&, Optional<RemoteInputEventTarget>* remote_target);
EventResult handle_mousemove(HTML::LocalNavigable& root, DevicePixelPoint, DevicePixelPoint screen_position, unsigned buttons, unsigned modifiers, Optional<RemoteInputEventTarget>* remote_target);
EventResult handle_mouseleave(HTML::LocalNavigable& root);
+ EventResult handle_mousecancel(HTML::LocalNavigable& root);
EventResult handle_mousewheel(HTML::LocalNavigable& root, DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, bool async_scroll_performed_default_action, Optional<AsyncScrollOperation>* async_scroll_operation, Optional<RemoteInputEventTarget>* remote_target);
EventResult handle_drag_and_drop_event(HTML::LocalNavigable& root, DragEvent::Type, DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, Vector<HTML::SelectedFile> files);
EventResult handle_pinch_event(HTML::LocalNavigable& root, DevicePixelPoint point, unsigned modifiers, double scale);
@@ -201,6 +202,7 @@ public:
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();
+ EventResult handle_mousecancel();
void set_mouse_event_tracking_navigable(Badge<EventHandler>, HTML::LocalNavigable&);
#if defined(AK_OS_MACOS)
bool select_word_for_dictionary_lookup(DevicePixelPoint);
diff --git a/Libraries/LibWebCommon/Page/InputEvent.h b/Libraries/LibWebCommon/Page/InputEvent.h
index 99310fe558e..659602d5488 100644
--- a/Libraries/LibWebCommon/Page/InputEvent.h
+++ b/Libraries/LibWebCommon/Page/InputEvent.h
@@ -92,6 +92,7 @@ struct WEBCOMMON_API MouseEvent {
MouseUp,
MouseMove,
MouseLeave,
+ MouseCancel,
MouseWheel,
};
diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cpp
index 853bcafd809..f017aef394c 100644
--- a/Services/Compositor/ContextState.cpp
+++ b/Services/Compositor/ContextState.cpp
@@ -481,6 +481,22 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event(Web::MouseEve
.routing_decision = had_capture ? Web::InputRoutingDecision::LeftDuringScrollbarDrag : Web::InputRoutingDecision::NoScrollbarDrag,
};
}
+ case Web::MouseEvent::Type::MouseCancel: {
+ // A cancel ends a drag where it last scrolled to, as a cancel has no position of its own, and the pointer then
+ // counts as having left. The page still sees the cancel, so it is not accepted.
+ auto was_dragging_scrollbar = m_scrollbar_controller.has_captured_scrollbar();
+ auto scrollbar_dragged_by_compositor = m_scrollbar_controller.captured_scrollbar_painted_by_display_list();
+ (void)m_scrollbar_controller.release_captured_drag(m_scene.visual_context_tree_for_compositing(), m_scroll_state_snapshot, position);
+ note_user_scroll_gesture_end_if_drag_ended(was_dragging_scrollbar);
+ auto hovered_scrollbar_changed = m_scrollbar_controller.set_hovered_scrollbar({});
+
+ ContextUpdateResult result;
+ // As for a release, the main thread learns that the drag ended from the next update it takes.
+ result.should_request_rendering_update = was_dragging_scrollbar;
+ if ((was_dragging_scrollbar && !scrollbar_dragged_by_compositor.has_value()) || hovered_scrollbar_changed)
+ result.frame_to_present = frame_repainting_scrollbars_painted_by_compositor();
+ return result;
+ }
case Web::MouseEvent::Type::MouseWheel:
return {};
}
diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cpp
index 4f5b6fcae09..e9ee25673b2 100644
--- a/Services/WebContent/PageClient.cpp
+++ b/Services/WebContent/PageClient.cpp
@@ -508,6 +508,7 @@ void PageClient::did_handle_input_event(Web::PageId page_id, Web::InputEvent con
switch (mouse_event.type) {
case Web::MouseEvent::Type::MouseDown:
case Web::MouseEvent::Type::MouseUp:
+ case Web::MouseEvent::Type::MouseCancel:
return true;
case Web::MouseEvent::Type::MouseMove:
return mouse_event.buttons != Web::UIEvents::MouseButton::None;
diff --git a/Tests/LibWeb/Text/expected/UIEvents/pointercancel-suppresses-the-press.txt b/Tests/LibWeb/Text/expected/UIEvents/pointercancel-suppresses-the-press.txt
new file mode 100644
index 00000000000..c480327d1db
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/UIEvents/pointercancel-suppresses-the-press.txt
@@ -0,0 +1,14 @@
+hover: pointerover at target, mouseover at target, pointerenter at target, mouseenter at target
+press: pointerdown at target, mousedown at target
+cancel: pointercancel at target cancelable=false, mouseup at window, pointerout at target, mouseout at target, pointerleave at target, mouseleave at target
+active after cancel: false
+move after cancel: pointerover at target, mouseover at target, pointerenter at target, mouseenter at target
+leave after cancel: pointerout at target, mouseout at target, pointerleave at target, mouseleave at target
+cancel while dragging: dragend at link
+cancel in nested document: pointercancel at nested cancelable=false, mouseup at window, pointerout at nested, mouseout at nested, pointerleave at nested, mouseleave at nested
+scrolled while pressed: true
+coordinates: pointerdown at client (50, 50), page (50, 50), pointercancel at client (50, 50), page (50, 50)
+scrolled after cancel: true
+scroll after cancel: (none)
+scrolled after cancel: true
+scroll after cancel in nested document: (none)
diff --git a/Tests/LibWeb/Text/input/UIEvents/pointercancel-suppresses-the-press.html b/Tests/LibWeb/Text/input/UIEvents/pointercancel-suppresses-the-press.html
new file mode 100644
index 00000000000..4ba5946d4b4
--- /dev/null
+++ b/Tests/LibWeb/Text/input/UIEvents/pointercancel-suppresses-the-press.html
@@ -0,0 +1,115 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<style>
+ body { margin: 0 }
+ #target, iframe { display: block; width: 100px; height: 100px; border: none }
+ #link { display: inline-block; padding: 10px }
+</style>
+<div id="target"></div>
+<a id="link" href="#link">link</a>
+<script>
+ asyncTest(async done => {
+ const iframe = document.createElement("iframe");
+ iframe.srcdoc = "<style>body { margin: 0 } div { width: 100px; height: 100px }</style><div id=nested></div>";
+ document.body.appendChild(iframe);
+ await new Promise(resolve => iframe.addEventListener("load", resolve, { once: true }));
+
+ const events = [];
+ const log = event => {
+ const target = event.currentTarget.nodeType ? event.currentTarget.id : "window";
+ const cancelable = event.type === "pointercancel" ? ` cancelable=${event.cancelable}` : "";
+ events.push(`${event.type} at ${target}${cancelable}`);
+ };
+ const listen = (element, window) => {
+ for (const type of ["pointerdown", "pointerup", "pointercancel", "pointerout", "pointerleave", "pointerover", "pointerenter",
+ "mousedown", "mouseup", "mouseout", "mouseleave", "mouseover", "mouseenter", "click", "dragend"])
+ element.addEventListener(type, log);
+ window.addEventListener("mouseup", log);
+ };
+ const flush = label => {
+ println(`${label}: ${events.join(", ") || "(none)"}`);
+ events.length = 0;
+ };
+
+ listen(target, window);
+ internals.mouseMove(50, 50);
+ flush("hover");
+
+ internals.mouseDown(50, 50);
+ flush("press");
+
+ internals.mouseCancel();
+ flush("cancel");
+ println(`active after cancel: ${target.matches(":active")}`);
+
+ internals.mouseMove(50, 50);
+ flush("move after cancel");
+
+ internals.mouseLeave();
+ flush("leave after cancel");
+
+ // A press that has started dragging the link ends its drag.
+ link.addEventListener("dragend", log);
+ const linkRect = link.getBoundingClientRect();
+ internals.mouseDown(linkRect.x + 5, linkRect.y + 5);
+ internals.mouseMove(linkRect.right + 20, linkRect.y + 5);
+ events.length = 0;
+ internals.mouseCancel();
+ flush("cancel while dragging");
+
+ // A press in a nested document is cancelled there.
+ const nested = iframe.contentDocument.getElementById("nested");
+ listen(nested, iframe.contentWindow);
+ const iframeRect = iframe.getBoundingClientRect();
+ internals.mouseMove(iframeRect.x + 50, iframeRect.y + 50);
+ internals.mouseDown(iframeRect.x + 50, iframeRect.y + 50);
+ events.length = 0;
+ internals.mouseCancel();
+ flush("cancel in nested document");
+
+ // A cancel repeats the coordinates of the last pointer event, even once the page has scrolled under the pointer.
+ const spacer = document.createElement("div");
+ spacer.style.height = "2000px";
+ document.body.appendChild(spacer);
+ const positions = [];
+ const logPosition = event => positions.push(`${event.type} at client (${event.clientX}, ${event.clientY}), page (${event.pageX}, ${event.pageY})`);
+ target.addEventListener("pointerdown", logPosition);
+ target.addEventListener("pointercancel", logPosition);
+ internals.mouseMove(50, 50);
+ internals.mouseDown(50, 50);
+ await internals.wheel(50, 50, 0, 40);
+ await new Promise(resolve => requestAnimationFrame(resolve));
+ println(`scrolled while pressed: ${scrollY > 0}`);
+ internals.mouseCancel();
+ println(`coordinates: ${positions.join(", ")}`);
+
+ // A cancelled pointer has left the page, so a scroll that keeps an element under where it was does not hover
+ // that element again, not even in a nested document.
+ const tall = document.createElement("div");
+ tall.id = "tall";
+ tall.style.height = "400px";
+ document.body.prepend(tall);
+ listen(tall, window);
+ iframe.style.height = "400px";
+ nested.style.height = "400px";
+ const scrollAfterCancel = async element => {
+ window.scrollTo(0, 0);
+ const rect = element.getBoundingClientRect();
+ internals.mouseMove(rect.x + 50, rect.y + 50);
+ internals.mouseDown(rect.x + 50, rect.y + 50);
+ internals.mouseCancel();
+ events.length = 0;
+ window.scrollBy({ top: 100, behavior: "smooth" });
+ await new Promise(resolve => window.addEventListener("scrollend", resolve, { once: true }));
+ await new Promise(resolve => setTimeout(resolve, 300));
+ await new Promise(resolve => requestAnimationFrame(resolve));
+ println(`scrolled after cancel: ${scrollY > 0}`);
+ };
+ await scrollAfterCancel(tall);
+ flush("scroll after cancel");
+ await scrollAfterCancel(iframe);
+ flush("scroll after cancel in nested document");
+
+ done();
+ });
+</script>
diff --git a/Tests/LibWebView/TestCompositorInputRouting.cpp b/Tests/LibWebView/TestCompositorInputRouting.cpp
index 4b0c9903c0a..39d8277ebf8 100644
--- a/Tests/LibWebView/TestCompositorInputRouting.cpp
+++ b/Tests/LibWebView/TestCompositorInputRouting.cpp
@@ -64,11 +64,35 @@ void move_mouse_to(WebView::ViewImplementation& view, Web::DevicePixelPoint posi
});
}
+void press_mouse_at(WebView::ViewImplementation& view, Web::DevicePixelPoint position)
+{
+ view.enqueue_input_event(Web::MouseEvent {
+ .type = Web::MouseEvent::Type::MouseDown,
+ .position = position,
+ .screen_position = position,
+ .button = Web::UIEvents::MouseButton::Primary,
+ .buttons = Web::UIEvents::MouseButton::Primary,
+ .click_count = 1,
+ .browser_data = nullptr,
+ });
+}
+
+void cancel_mouse_press(WebView::ViewImplementation& view)
+{
+ view.enqueue_input_event(Web::MouseEvent {
+ .type = Web::MouseEvent::Type::MouseCancel,
+ .position = {},
+ .screen_position = {},
+ .browser_data = nullptr,
+ });
+}
+
}
// Mouse input reaches the compositor without the UI waiting for it. A wheel step is scrolled by the compositor and then
// forwarded to WebContent, whose acknowledgement settles the UI's pending entry; a plain move is forwarded and settled
-// the same way. Either way the pending queue drains, which is what lets later compositor key scrolling proceed.
+// the same way. Either way the pending queue drains, which is what lets later compositor key scrolling proceed. A press
+// that the UI cancels reaches the page along the same route, so the page sees its pointer stream suppressed.
ErrorOr<int> ladybird_main(Main::Arguments arguments)
{
@@ -99,11 +123,15 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
Utf16String last_title;
view->on_title_change = [&](auto const& title) { last_title = title; };
- // A page three viewports tall that reports its scroll position through its title.
+ // A page three viewports tall that reports its scroll position, and presses being cancelled, through its title.
view->load_html(R"~~~(<!DOCTYPE html>
<title>unscrolled</title>
<body style="margin:0;height:3000px">
-<script>addEventListener("scroll", () => { document.title = "scrolled to " + scrollY; });</script>
+<script>
+addEventListener("scroll", () => { document.title = "scrolled to " + scrollY; });
+addEventListener("pointerdown", () => { document.title = "pressed"; });
+addEventListener("pointercancel", () => { document.title = "press cancelled"; });
+</script>
</body>)~~~"sv);
Core::EventLoop::current().spin_until([&]() { return loads_finished >= 2; });
VERIFY(last_title == "unscrolled"sv);
@@ -119,6 +147,12 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
VERIFY(view->pending_input_event_count_for_testing() == 1);
Core::EventLoop::current().spin_until([&]() { return view->pending_input_event_count_for_testing() == 0; });
- outln("PASS: mouse input routed through the compositor scrolls the page and settles the UI's pending events");
+ press_mouse_at(*view, { 100, 100 });
+ Core::EventLoop::current().spin_until([&]() { return last_title == "pressed"sv; });
+ cancel_mouse_press(*view);
+ Core::EventLoop::current().spin_until([&]() { return last_title == "press cancelled"sv; });
+ Core::EventLoop::current().spin_until([&]() { return view->pending_input_event_count_for_testing() == 0; });
+
+ outln("PASS: mouse input routed through the compositor scrolls the page, reaches it and settles the UI's pending events");
return 0;
}