Lightpanda: the headless browser designed for AI and automation
webdriver: reuse buttonsBitmask from user_input
Adrià Arrufat6be87585c7ee
diff --git a/src/browser/frame/user_input.zig b/src/browser/frame/user_input.zigindex 73bbbca2e..b2b66ad5c 100644--- a/src/browser/frame/user_input.zig+++ b/src/browser/frame/user_input.zig@@ -229,7 +229,7 @@ fn dispatchPointerEventOn(frame: *Frame, target: *Element, comptime typ: []const/// MouseEvent/PointerEvent.buttons bitmask for a MouseEvent.button value./// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons-fn buttonsBitmask(button: i32) u16 {+pub fn buttonsBitmask(button: i32) u16 {return switch (button) {mouse_button.main => 1,mouse_button.secondary => 2,@@ -316,7 +316,6 @@ pub fn triggerMousePress(frame: *Frame, x: f64, y: f64, button: i32, click_count// fresh gesture rather than continuing a chord.const other_already_held = frame._page.input_pressed_buttons & ~button_bit != 0;frame._page.input_pressed_buttons |= button_bit;- const buttons = frame._page.input_pressed_buttons;// A caller that doesn't track click counts (or a CDP message that omits// clickCount) sends 0 — preserved as-is rather than forced to 1, since// Chrome and Firefox both fire mousedown with detail 0 in that case.@@ -341,6 +340,7 @@ pub fn triggerMousePress(frame: *Frame, x: f64, y: f64, button: i32, click_count// pointerdown — https://www.w3.org/TR/pointerevents3/#chorded-button-interactions.// The compatibility mousedown for this button still fires unless// the gesture's own pointerdown was already cancelled.+ const buttons = frame._page.input_pressed_buttons;_ = try dispatchPointerEventOn(frame, target, "pointermove", x, y, button, buttons, 0, .{});if (!frame._page.input_mousedown_suppressed) {const suppress_focus = try dispatchMouseEventOn(frame, target, "mousedown", x, y, button, buttons, detail, .{});@@ -402,8 +402,6 @@ pub fn triggerMouseRelease(frame: *Frame, x: f64, y: f64, button: i32, click_couconst detail: u32 = if (click_count > 0) @intCast(click_count) else 1;if (ends_gesture) {- // The last held button releasing ends the gesture: full pointerup,- // then (unless suppressed) mouseup.try dispatchPointerRelease(frame, target, x, y, button, was_suppressed, detail, .{});} else {// A chorded release: another button remains held, so this is adiff --git a/src/browser/webapi/WebDriver.zig b/src/browser/webapi/WebDriver.zigindex 129ea097f..8ec782653 100644--- a/src/browser/webapi/WebDriver.zig+++ b/src/browser/webapi/WebDriver.zig@@ -296,18 +296,18 @@ fn performPointerSource(source: js.Object, frame: *Frame) !void {const el = target orelse continue;const button = readI32(action, "button", 0);pressed = true;- pressed_mask = buttonsMask(button);+ pressed_mask = Frame.user_input.buttonsBitmask(button);down_target = el;if (last_click_target == el and last_click_button == button) {click_count += 1;} else {click_count = 1;}- dispatchPointer(el, "pointerdown", button, buttonsMask(button), frame);+ dispatchPointer(el, "pointerdown", button, Frame.user_input.buttonsBitmask(button), frame);if (is_touch) {dispatchTouch(el, "touchstart", frame);} else {- const suppressed = dispatchMouse(el, "mousedown", button, buttonsMask(button), click_count, frame);+ const suppressed = dispatchMouse(el, "mousedown", button, Frame.user_input.buttonsBitmask(button), click_count, frame);if (!suppressed) {Frame.user_input.focusForMouseDown(frame, el) catch |err| {log.warn(.app, "webdriver mousedown focus", .{ .err = err });@@ -348,17 +348,6 @@ fn performPointerSource(source: js.Object, frame: *Frame) !void {// The `buttons` bitmask bit for a WebDriver button number: the flag order does// not follow the button numbering (left=1, right=2, middle=4).-fn buttonsMask(button: i32) u16 {- return switch (button) {- 0 => 1,- 1 => 4,- 2 => 2,- 3 => 8,- 4 => 16,- else => 0,- };-}-// A click whose mousedown and mouseup landed on different elements fires at// their nearest common inclusive ancestor element.fn commonClickTarget(down: *Element, up: *Element) *Element {