Files
sousa-gecko/testing/web-platform/tests/pointerlock/pointerlock-maintains-mousedown.html
T
Gastón Rodríguez 5565ecace7 Bug 2013914 [wpt PR 57487] - Fix pointer lock button down status tracking in Windows, a=testonly
Automatic update from web-platform-tests
Fix pointer lock button down status tracking in Windows

When the pointer is locked on Windows with the `unadjustedMovement`
option set to `true`, Chromium uses Raw Input (WM_INPUT) instead of
standard WM_MOUSEMOVE messages to receive unadjusted mouse movement
deltas. However, the RAWINPUT structure's `usButtonFlags` field only
reports button state transitions (down/up events), not the current
button state. This meant that mousemove events during pointer lock
incorrectly reported buttons=0 even when a button was held down, unlike
the non-pointer-lock path which correctly includes button state from
WPARAM.

This change adds button state tracking to `HWNDMessageHandler`. A new
member variable `raw_input_button_state_` maintains the current button
state by setting flags on RI_MOUSE_BUTTON_*_DOWN transitions and
clearing them on RI_MOUSE_BUTTON_*_UP transitions. The tracked state is
then used when creating MouseEvent objects in OnInputEvent, ensuring
consistent behavior between locked and unlocked pointer modes.

A WPT test is added to verify that mousemove events during pointer lock
correctly report event.buttons=1 when the left mouse button is held
down.

Bug: 353249342, 479025316
Change-Id: I33a1c8e3326e804e9609024fce22c115fee158c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7520467
Commit-Queue: Gaston Rodriguez <gastonr@microsoft.com>
Reviewed-by: Mustaq Ahmed <mustaq@chromium.org>
Reviewed-by: Dana Fried <dfried@chromium.org>
Reviewed-by: Jesse McKenna <jessemckenna@google.com>
Cr-Commit-Position: refs/heads/main@{#1578186}

--

wpt-commits: 726cde2f8e483882193cec8fd126ae3f12ffa8e0
wpt-pr: 57487
2026-02-05 18:15:19 +00:00

91 lines
3.0 KiB
HTML

<!DOCTYPE html>
<meta name="variant" content="?unadjustedmovement=true">
<meta name="variant" content="?unadjustedmovement=false">
<html>
<head>
<meta charset="utf-8" />
<title>Pointer lock maintains button state during mouse move</title>
<link rel="help" href="https://w3c.github.io/pointerlock/" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
</head>
<body></body>
<script>
// The test will do two mouse actions:
// 1. A simple click to request pointer lock via a gesture.
// 2. A drag to verify that mousemove events report correct button state.
let waiting_for_first_mouseup = true;
let pointer_locked = false;
const test_buttons_during_drag = async_test(
'Tests that mousemove events during pointer lock report correct button state'
);
document.addEventListener('mousemove', function(e) {
if (!pointer_locked) {
return;
}
test_buttons_during_drag.step(function() {
// e.buttons is a bitmask: 1 = left button down
assert_equals(e.buttons, 1,
'mousemove event should have left button (buttons=1) while dragging'
);
});
});
// We will use the first "mouseup" to request pointer lock, and the second one
// as the signal that the drag is complete and we can finish the test.
document.addEventListener('mouseup', function(e) {
if (waiting_for_first_mouseup) {
const urlSearch = new URLSearchParams(window.location.search);
document.body.requestPointerLock({
unadjustedMovement: urlSearch.get("unadjustedmovement") === "true"
});
waiting_for_first_mouseup = false;
} else {
test_buttons_during_drag.done();
}
});
document.addEventListener("pointerlockerror", function() {
test_buttons_during_drag.step(function() {
assert_unreached("Pointer lock error occurred");
});
});
// When pointer lock is acquired, run the drag test
document.addEventListener("pointerlockchange", async function() {
if (document.pointerLockElement) {
pointer_locked = true;
test_buttons_during_drag.step(function() {
assert_equals(document.pointerLockElement, document.body,
'Pointer should be locked to body');
});
var dragActions = new test_driver.Actions();
await dragActions
.pointerDown({button: dragActions.ButtonType.LEFT})
.pointerMove(10, 10)
.pointerMove(20, 20)
.pointerMove(30, 30)
.pointerUp({button: dragActions.ButtonType.LEFT})
.send();
} else {
pointer_locked = false;
}
}, {once: true});
// Step 0: Click to acquire pointer lock.
(async function() {
var actions = new test_driver.Actions();
await actions
.pointerMove(1, 1)
.pointerDown({button: actions.ButtonType.LEFT})
.pointerUp({button: actions.ButtonType.LEFT})
.send();
})();
</script>
</html>