Closed Bug 1704948 Opened 4 years ago Closed 4 years ago

Allow obtaining the mouse button for menuitem clicks from the command event

Categories

(Core :: DOM: Events, task)

task

Tracking

()

RESOLVED FIXED
90 Branch
Tracking Status
firefox89 --- fixed
firefox90 --- fixed

People

(Reporter: mstange, Assigned: mstange)

References

Details

(Whiteboard: [proton-uplift])

Attachments

(6 files, 1 obsolete file)

Bug 1469148 added a click event listener to WebExtension context menu items, which manually fires a command event and closes the menu. This click event listener has two purposes:

  1. It allows the menu item to be clicked with middle clicks. By default, probably for no good reason, menu items only respond to left and right button clicks.
  2. The click event has the information about the mouse button that was used for the event.

Native context menus will not fire a click event. If the mouse button is needed, it will somehow need to be delivered via the command event.

I can think of two ways to do this:

  1. We could add a button property to XULCommandEvent.
  2. Or we could create a DOM mouse event with the right button and put it into the command event's sourceEvent attribute.

Smaug, Masayuki, which solution would you prefer?

This problem is currently preventing native context menus from being enabled by default (bug 1700679), because doing so would make the test browser_ext_menus_capture_secondary_click.js fail. (There are other test failures too, this is just one of them.)

Flags: needinfo?(bugs)
Flags: needinfo?(masayuki)

At the moment, WebExtension menu items are special cased to allow this, by using
a click event listener which manually fires command and closes the menu.
I would like to remove the click listener, because native menus won't fire click.

Depends on D111954

Depends on D111955

This problem isn't exclusive to ext-menus.js; we also have the same setup for the content area context menu:
https://searchfox.org/mozilla-central/search?q=checkForMiddleClick&path=

The menu items have a click handler which calls checkForMiddleClick, which, for middle clicks, dispatches a command event and closes the menu.

I like adding button better since otherwise and if events are stored outside event listeners, source events are also copied into the heap.

Flags: needinfo?(masayuki)

Do we need to dispatch command events for non-primary clicks? Usually only left click triggers command.
...
oh, I see https://searchfox.org/mozilla-central/rev/759872688df15a5d6ab305ffe39d90450590bfec/browser/base/content/utilityOverlay.js#712 is bizarre. Doing something against platform convention.
But yeah, .button property would be fine.

Flags: needinfo?(bugs)
Attachment #9215648 - Attachment is obsolete: true
Attachment #9215646 - Attachment description: Bug 1704948 - Approach 1 part 1: Give XULCommandEvent a button property. r=smaug → Bug 1704948 - Give XULCommandEvent a button property. r=smaug
Attachment #9215647 - Attachment description: Bug 1704948 - Approach 1 part 2: Forward mouse button to menuitem command event. r=smaug → Bug 1704948 - Forward mouse button to menuitem command event. r=smaug

Now that there is no more click handler, we need to go one level lower to keepthis test passing.
At this point in the patch series, activateItem does not yet support the button property.
Later on in this series, I will replace this with an activateItem call so that the test works with native context menus as well.

Pushed by mstange@themasta.com: https://hg.mozilla.org/integration/autoland/rev/bdf396edd692 Allow clicking menuitems with the middle mouse button (or any other non-primary button). r=tnikkel https://hg.mozilla.org/integration/autoland/rev/2369e321069e Give XULCommandEvent a button property. r=smaug,preferences-reviewers https://hg.mozilla.org/integration/autoland/rev/a43a8ef206ea Forward mouse button to menuitem command event. r=smaug,robwu https://hg.mozilla.org/integration/autoland/rev/454597ac2ba3 Remove onclick handlers from menuitems, because menuitems now dispatch command events even on middle click. r=Gijs https://hg.mozilla.org/integration/autoland/rev/eb725de20b11 Use EventUtils.synthesizeMouseAtCenter for middle-clicking the back/forward context menu. r=Gijs
Flags: needinfo?(mstange.moz)

Please also check failures on browser_contextmenu_whereToOpenLink.js -> https://treeherder.mozilla.org/logviewer?job_id=336573344&repo=autoland&lineNumber=4939

Attachment #9215645 - Attachment description: Bug 1704948 - Allow clicking menuitems with the middle mouse button (or any other non-primary button). r=tnikkel → Bug 1704948 - Allow clicking menuitems with the middle mouse button. r=tnikkel

In the past, menus stayed open when an item was middle-clicked. Now that menus
fire command on middle-click, they automatically close when middle-clicked.
So this code now needs to handle middle clicks on menus like left clicks on
menus, and manually keep the menu open (rather than rely on them staying open
by default).
This functionality is covered by browser_stayopenmenu.js.

Depends on D112073

Pushed by mstange@themasta.com: https://hg.mozilla.org/integration/autoland/rev/196422b73904 Allow clicking menuitems with the middle mouse button. r=tnikkel https://hg.mozilla.org/integration/autoland/rev/2b505afdf0ff Give XULCommandEvent a button property. r=smaug,preferences-reviewers https://hg.mozilla.org/integration/autoland/rev/673588cfb191 Forward mouse button to menuitem command event. r=smaug,robwu https://hg.mozilla.org/integration/autoland/rev/8c46cf21aba8 Remove onclick handlers from menuitems, because menuitems now dispatch command events even on middle click. r=Gijs https://hg.mozilla.org/integration/autoland/rev/c28ff25f8047 Use EventUtils.synthesizeMouseAtCenter for middle-clicking the back/forward context menu. r=Gijs https://hg.mozilla.org/integration/autoland/rev/fd72fcc0fa52 Update browser.bookmarks.openInTabClosesMenu handling to keep the menu open for middle clicks. r=Gijs
Whiteboard: [proton-uplift]
Blocks: 1684324
Regressions: 1718436
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: