Closed Bug 1912812 Opened 1 year ago Closed 1 year ago

setPointerCapture() causes an onclick event for the wrong element

Categories

(Core :: DOM: UI Events & Focus Handling, defect)

Firefox 129
defect

Tracking

()

RESOLVED DUPLICATE of bug 1885232

People

(Reporter: octogonz, Unassigned)

References

(Regression)

Details

(Keywords: nightly-community, regression)

Attachments

(1 file)

Attached file bug.html

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:

  1. Click on this "MOUSEDOWN" div, holding the mouse down.
  2. Drag the mouse over some unrelated element on the page. Let's call that the "MOUSEUP" element.
  3. 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.

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.

Component: Untriaged → DOM: UI Events & Focus Handling
Product: Firefox → Core
  • Also repros when using onpointerdown/onpointerup events instead of onmousedown/onmouseup.

  • Does NOT repro with the Safari browser.

  • Does NOT repro with Internet Explorer.

  • Does repro with Firefox on macOS.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Regressed by: 1511388, 1792110
Regressed by: 1089326
No longer regressed by: 1511388

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.

Status: NEW → RESOLVED
Closed: 1 year ago
Duplicate of bug: 1885232
Resolution: --- → DUPLICATE

Very helpful, thank you!

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: