Skip to content

Commit

Permalink
REGRESSION(268459@main): PointerEvent pointerup button value does n…
Browse files Browse the repository at this point in the history
…ot match pointerdown

https://bugs.webkit.org/show_bug.cgi?id=267008
rdar://120429508

Reviewed by Wenson Hsieh.

In 268459@main, we unified the cases where a pointer event's 'button'
value would be '-1', i.e. indicating that buttons or touch/pen contact
haven't changed since the last event. Unfortunately, this regressed a
longstanding behavior of corresponding pointerup/pointerdown events
having matching 'button' values.

It turns out that we should hold off on our logic to produce the '-1'
value until we've ensured that the pointerup/pointerdown case has been
dealt with, and not the other way around. Furthermore, we should consult
whether or not the pointer is pressed before producing the '-1' value.

This patch fixes both of these logic errors, and introduces a WPT to
protect against future regressions in this case.

* LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerup_button_value_matches_corresponding_pointerdown-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerup_button_value_matches_corresponding_pointerdown.html: Added.
* Source/WebCore/page/PointerCaptureController.cpp:
(WebCore::PointerCaptureController::pointerEventForMouseEvent):

Canonical link: https://commits.webkit.org/273263@main
  • Loading branch information
aprotyas committed Jan 20, 2024
1 parent 75760f4 commit 29875ec
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@


PASS Test that the 'button' property of a pointerup event matches the 'button' property of the corresponding pointerdown event

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE HTML>
<title>Button value of corresponding pointerup/pointerdown are equivalent</title>
<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>
<script src="pointerevent_support.js"></script>

<input id="target" style="margin: 20px">

<script>
'use strict';
const target = document.getElementById("target");

promise_test(async test => {
const test_pointer = "testPointer";

let actions = new test_driver.Actions();
actions = actions.addPointer(test_pointer, "mouse")
.pointerMove(0,0, {sourceName:test_pointer, origin:target})
.pointerDown({sourceName:test_pointer, button:actions.ButtonType.RIGHT})
.pointerUp({sourceName:test_pointer, button:actions.ButtonType.RIGHT});
target.addEventListener("contextmenu", event => { event.preventDefault(); });
let pointerdown_promise = getEvent("pointerdown", target, test);
let pointerup_promise = getEvent("pointerup", target, test);

await actions.send();
let pointerdown_event = await pointerdown_promise;
let pointerup_event = await pointerup_promise;

assert_equals(pointerup_event.button, pointerdown_event.button, "The 'button' property of a pointerup event should match the 'button' property of the corresponding pointerdown event");
}, "Test that the 'button' property of a pointerup event matches the 'button' property of the corresponding pointerdown event");
</script>
10 changes: 6 additions & 4 deletions Source/WebCore/page/PointerCaptureController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,12 @@ RefPtr<PointerEvent> PointerCaptureController::pointerEventForMouseEvent(const M

MouseButton newButton = mouseEvent.button();
MouseButton previousMouseButton = capturingData ? capturingData->previousMouseButton : MouseButton::PointerHasNotChanged;
MouseButton button = [newButton, previousMouseButton, type = pointerEventType(type)] {
if (newButton == previousMouseButton)
return PointerEvent::buttonForType(type);
return PointerEvent::typeIsUpOrDown(type) ? newButton : MouseButton::PointerHasNotChanged;
MouseButton button = [&] {
if (!PointerEvent::typeIsUpOrDown(pointerEventType(type))) {
if (newButton == previousMouseButton || !pointerIsPressed)
return MouseButton::PointerHasNotChanged;
}
return newButton;
}();

// https://w3c.github.io/pointerevents/#chorded-button-interactions
Expand Down

0 comments on commit 29875ec

Please sign in to comment.