setPointerCapture() causes an onclick event for the wrong element
Categories
(Core :: DOM: UI Events & Focus Handling, defect)
Tracking
()
People
(Reporter: octogonz, Unassigned)
References
(Regression)
Details
(Keywords: nightly-community, regression)
Attachments
(1 file)
|
1.76 KB,
text/html
|
Details |
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:129.0) Gecko/20100101 Firefox/129.0
Steps to reproduce:
A complete repro file is attached.
The problem occurs when a control is using setPointerCapture() to behave like a button, for example this div:
HTML:
<div
class="button"
onmousedown="buttonDown(event)"
onmouseup="buttonUp(event)"
>
MOUSEDOWN HERE
</div>
JavaScript:
function buttonDown(event) {
// The repro works even without this line:
event.preventDefault();
event.currentTarget.setPointerCapture(event.pointerId);
}
function buttonUp(event) {
// The repro works even without this line:
event.currentTarget.releasePointerCapture(event.pointerId);
}
Steps:
- Click on this "MOUSEDOWN" div, holding the mouse down.
- Drag the mouse over some unrelated element on the page. Let's call that the "MOUSEUP" element.
- Release the mouse over the "MOUSEUP" element.
Actual results:
In Firefox, the MOUSEUP element incorrectly receives an onclick event (but not mousedown or mouseup events). If it is an <a> tag, Firefox will wrongly navigate to its href URL. (This can be highly confusing, for example if the MOUSEDOWN control is a custom scrollbar, with no expectation to release the mouse within its client area.)
Expected results:
In Chrome, the MOUSEUP element does not receive any mouse events. This is correct behavior at that time the pointer is still captured by the MOUSEDOWN div.
Comment 1•1 year ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::DOM: UI Events & Focus Handling' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
| Reporter | ||
Comment 2•1 year ago
|
||
-
Also repros when using
onpointerdown/onpointerupevents instead ofonmousedown/onmouseup. -
Does NOT repro with the Safari browser.
-
Does NOT repro with Internet Explorer.
-
Does repro with Firefox on macOS.
Comment 3•1 year ago
•
|
||
There are two regression window as follows.
#1 Regression window (click event will fire on <DIV>, but not on <A>):
https://hg.mozilla.org/integration/mozilla-inbound/pushloghtml?fromchange=f6eebcc14c22762f521fb567a9588963b8720592&tochange=61570c16c2d564c24fab36713fb169c4144453e9
Suspect: Bug 1089326
#2 Regression window (click event will fire on both <DIV> and <A>):
https://hg.mozilla.org/integration/autoland/pushloghtml?fromchange=728f4a4d08f5b369ce5c7bea17a23cdfbb30f196&tochange=92ad9c748611fc9b5be547415a651f136a27346f
Regressed by: Bug 1792110
Updated•1 year ago
|
| Reporter | ||
Comment 4•1 year ago
|
||
Thanks for the quick investigation!
FYI: MouseEvent.pointerId is undefined on all browsers. So, you call setPointerCapture with 0 in the example. Firefox uses 0 for mouse, but Chrome and Safari use 1 for mouse. Therefore, the setPointerCapture call works only on Firefox.
About the click event target issue of setPointerCapture will be fixed in bug 1885232.
| Reporter | ||
Comment 6•1 year ago
|
||
Very helpful, thank you!
Description
•