Closed Bug 1736391 Opened 3 years ago Closed 2 years ago

Firefox for Android: Preventing context menu / `"contextmenu"` event through `preventDefault` for an `img` or `a` element does not work.

Categories

(GeckoView :: General, defect, P3)

Firefox 93
Unspecified
All
defect

Tracking

(Webcompat Priority:P3, firefox116 fixed)

RESOLVED FIXED
116 Branch
Webcompat Priority P3
Tracking Status
firefox116 --- fixed

People

(Reporter: mithunder, Assigned: hiro)

References

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:93.0) Gecko/20100101 Firefox/93.0

Steps to reproduce:

  1. Open Firefox for Android on an Android device.
  2. Have an img element and add a "contextmenu" listener to it that calls preventDefault (the listener can also have the argument passive set to false when adding the listener using addEventListener).
  3. Use 'long tap' on the img.
  4. Observe.
  5. (see also https://jsfiddle.net/nc1zuref/ and https://github.com/mozilla-mobile/fenix/issues/21929 ).

Actual results:

A context menu unexpectedly opens.

Expected results:

A context menu should not open.

The issue https://bugzilla.mozilla.org/show_bug.cgi?id=1447227 seem related. This issue was first posted at Github, see https://github.com/mozilla-mobile/fenix/issues/21929 and https://github.com/mozilla-mobile/fenix/issues/14067 . Helpful developers in chat.mozilla.org under Android Components suggested that this could be a GeckoView bug, which is why I am filing it here.

About the jsfiddle.net link as a reproducible example:

https://jsfiddle.net/nc1zuref/ :

  1. Right-click on the images or long-tap on them.
  2. For Firefox on desktop, as well as Chrome on Android, using right-click or long tap, the first two imgs correctly do not show context menus, while the third img correctly does show the context menu.
  3. However, for Firefox on Android, all three imgs show the context menu.

Motivation for the bug: One example where this bug can give problems is if you have a touch event listener on an img, where the user for some actions is meant to continue to touch down on the img for longer periods (for instance for moving some graphical element around while still being able to see the graphical element), detecting the specific touch position on the img, and where there is a real-time aspect to it. The context menu appearing suddenly is therefore troublesome. It works on Chrome on Android. I don't know what an easy work-around would be, apart from finding and using some element other than img where preventDefault does work for the "contextmenu" event for Firefox on Android (while I have not looked into it, I would assume that it would work for some element other than img).

Remarks: While both img and a elements have this bug, p elements do not, though p elements also show a very different kind of menu than for img and a elements.

I am not certain at all, in part given that I am not well versed in Firefox's code base, and I haven't downloaded its source yet, but these might (or might not) be relevant: https://searchfox.org/mozilla-central/source/gfx/layers/apz/util/APZEventState.cpp#294 and https://bugzilla.mozilla.org/show_bug.cgi?id=1558506 .

Priority: -- → P3
Webcompat Priority: --- → P3
Severity: -- → S3

Interestingly there seems to be a test for preventingDefault on Android: https://searchfox.org/mozilla-central/source/gfx/layers/apz/test/mochitest/helper_long_tap.html#97-149

I am not sure if this test tests this case, or if it is not executed at all.

A wild guess (without knowing any FF code): https://searchfox.org/mozilla-central/source/gfx/layers/apz/util/APZEventState.cpp#298
This code seems like a special case for Android, which explains why it does not trigger in mobile simulator..

It would be interesting to know what happens if we handle Context Menus on Android like on all other Platforms.

There are two problems;

  1. ContentDelegate listens contextmenu events with "capture: true"
  2. ContentDelegateChild doesn't ignore preventDefaulted events just like Firefox does

Though I am not sure why we specify the "capture: true" option, it's there since the beginning of GeckoView context menu handling in https://hg.mozilla.org/mozilla-central/rev/60f7e2cb890c . My best guess is that they were misunderstanding its use cases.

Duplicate of this bug: 1809301
Assignee: nobody → hikezoe.birchill
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Pushed by hikezoe.birchill@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/e65727bebcf9 Honor preventDefault information from the contents whether not to open context menu. r=geckoview-reviewers,owlish
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 116 Branch
Duplicate of this bug: 1447227
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: