Skip to content

Lightpanda: the headless browser designed for AI and automation

refactor(input): trim refactor-narration comments to stated invariants

Ramiro_quaid11293f328fa
diff --git a/src/browser/actions.zig b/src/browser/actions.zig
index cf097ba40..729c9eae5 100644
--- a/src/browser/actions.zig
+++ b/src/browser/actions.zig
@@ -39,11 +39,8 @@ fn dispatchInputAndChangeEvents(el: *Element, frame: *Frame) !void {
}
/// The trusted primary-button gesture a real user click produces; widgets key
-/// off pointerdown/mousedown, not click alone. Shares its dispatch mechanics
-/// with `WebDriver.click` and the CDP mouse-press/release path (both go
-/// through `Frame.user_input.dispatchPointer{Press,Release}`); this call
-/// site's own error-handling choice — a focus failure is worth a warning,
-/// not aborting the click — lives here, not in the shared code.
+/// off pointerdown/mousedown, not click alone. A focus failure is worth a
+/// warning, not aborting the click.
pub fn click(node: *DOMNode, frame: *Frame) !void {
const el = node.is(Element) orelse return error.InvalidNodeType;
diff --git a/src/browser/frame/user_input.zig b/src/browser/frame/user_input.zig
index d70377daa..b23bd677b 100644
--- a/src/browser/frame/user_input.zig
+++ b/src/browser/frame/user_input.zig
@@ -305,12 +305,12 @@ pub fn triggerMousePress(frame: *Frame, x: f64, y: f64, button: i32) !void {
.type = frame._type,
});
}
- // CDP's mousedown has never carried a click count (params.clickCount is
- // only read on the release side); preserve that rather than fixing it
- // here. mousePressed/mouseReleased arrive as two independent CDP
- // messages, so the release half (below) can't observe this gesture's
- // pointerdown directly — stash the outcome on the page first, before
- // the fallible focus call, mirroring input_hover_target.
+ // triggerMousePress takes no click-count parameter, so mousedown always
+ // fires with detail 0; only the release side (below) carries a click
+ // count. mousePressed/mouseReleased arrive as two independent CDP
+ // messages, so the release half can't observe this gesture's pointerdown
+ // directly — stash the outcome on the page first, before the fallible
+ // focus call, mirroring input_hover_target.
const press = try dispatchPointerPress(frame, target, x, y, button, 0, .{});
frame._page.input_mousedown_suppressed = press.suppress_mouse;
if (!press.suppress_mouse and !press.suppress_focus) {
diff --git a/src/browser/webapi/WebDriver.zig b/src/browser/webapi/WebDriver.zig
index 980e65a53..769d2ad0b 100644
--- a/src/browser/webapi/WebDriver.zig
+++ b/src/browser/webapi/WebDriver.zig
@@ -67,13 +67,8 @@ pub fn click(_: *const WebDriver, element: *Element, frame: *Frame) !void {
}
}
- // Shares its dispatch mechanics with actions.click and the CDP mouse
- // press/release path (Frame.user_input.dispatchPointer{Press,Release}),
- // which also gives this call its suppress/focus handling and its
- // PointerEvent click for the first time — previously this dispatched a
- // fixed five-event sequence unconditionally. Every dispatch here keeps
- // this function's pre-existing contract of never failing: a dispatch
- // error is a warning, not a rejection of the testdriver command.
+ // A dispatch error must never reject the testdriver command, so each
+ // stage is caught and logged rather than propagated.
const main = Frame.user_input.mouse_button.main;
const modifiers = frame._page.input_modifiers;
const press = Frame.user_input.dispatchPointerPress(frame, element, 0, 0, main, 1, modifiers) catch |err| {
diff --git a/src/server/cdp/domains/input.zig b/src/server/cdp/domains/input.zig
index 1ed759818..ee0fd2994 100644
--- a/src/server/cdp/domains/input.zig
+++ b/src/server/cdp/domains/input.zig
@@ -596,14 +596,11 @@ test "cdp.input: dispatchMouseEvent right button fires contextmenu, double-click
try testing.expect(result.isTrue());
}
-// Regression for the shared click-dispatch refactor: mousePressed/
-// mouseReleased now go through the same Frame.user_input.dispatchPointer*
-// primitives as actions.click and WebDriver.click, so CDP (i.e. Puppeteer,
-// Playwright) gets pointerdown/pointerup for the first time. #btn's
-// listeners (mcp_actions.html) record the same five-event sequence the MCP
-// click test asserts on the actions.click path, modulo one pre-existing,
-// deliberately-untouched CDP quirk: mousedown's detail (click count) has
-// never been threaded from clickCount here, unlike mouseup/click below.
+// A CDP mousePressed/mouseReleased pair fires the full pointerdown/mousedown/
+// pointerup/mouseup/click sequence, matching actions.click's five-event
+// sequence (asserted in the MCP click test) except that mousedown's detail
+// (click count) is always 0 — triggerMousePress takes no click-count
+// parameter, so only the release half's mouseup/click carries one.
test "cdp.input: dispatchMouseEvent mousePressed/mouseReleased fires the full pointer/mouse sequence" {
var ctx = try testing.context();
defer ctx.deinit();
@@ -647,11 +644,9 @@ test "cdp.input: dispatchMouseEvent mousePressed/mouseReleased fires the full po
try testing.expect(result.isTrue());
}
-// Regression for the same refactor's page-level suppression state
-// (Page.input_mousedown_suppressed): mousePressed and mouseReleased are two
-// independent CDP messages, so a pointerdown cancelled on the press half
-// must still suppress mouseup on the release half, with no state carried by
-// the caller between the two calls.
+// mousePressed and mouseReleased are two independent CDP messages, so a
+// pointerdown cancelled on the press half must still suppress mouseup on the
+// release half, with no state carried by the caller between the two calls.
test "cdp.input: a cancelled pointerdown suppresses mousedown and mouseup across the split mousePressed/mouseReleased calls" {
var ctx = try testing.context();
defer ctx.deinit();