Closed Bug 1705842 Opened 4 years ago Closed 4 years ago

Support dynamic changes to native menu contents while the menu is open

Categories

(Core :: Widget: Cocoa, task, P3)

All
macOS
task

Tracking

()

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

People

(Reporter: mstange, Assigned: mstange)

References

Details

(Whiteboard: [proton-context-menus][mac:mr1] [proton-uplift])

Attachments

(12 files)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

The contents of a native (context) menu are determined by the XUL elements inside the <menupopup>. At the moment, we only synchronize these contents when the menu opens (after the popupshowing event). If any elements are added or removed while the menu is open, this won't be reflected in the native menu until the next opening.

Unfortunately, there is a WebExtension API that requires these changes to work: browser.menus.refresh()
Changing a menu while it's open does not lead to a good user experience; it can display as a flicker, give a sense of instability, and in some cases cause accidental misclicks.
Nevertheless, this API exists and there is a test for it, and supporting it with native menus is possible.

In this bug I'm going to implement support for dynamic changes of open native menus.

This means that it'll happen even if the menu item is not visible. This will make
it possible to make a menu item visible after initial menu construction.

Depends on D112447

Before, we were only calling SetUpIcon if the item was visible during menu
construction on menu opening, but not if the item became visible after menu
opening.

Depends on D112451

This will make a difference once code inside MenuChildChangedVisibility starts
calling IsVisible(). The method name has "Changed" in it, so it should be called
after the change.

Depends on D112452

This makes the WebExtension API menus.refresh() work.

Depends on D112456

This is exercised by one of the subtests of
browser/components/extensions/test/browser/browser_ext_menus_replace_menu.js :

The menu is opened while it's empty, and then the content items are added
asynchronously while the menu is open.

If we try to open an NSMenu with zero NSMenuItems, macOS immediately closes the
menu after opening it. With a placeholder item it stays open as expected.

Depends on D112457

Priority: -- → P3
Pushed by mstange@themasta.com: https://hg.mozilla.org/integration/autoland/rev/17312473a6d5 Add nsMenuItemX::IsVisible() and nsMenuX::IsVisible(). r=harry https://hg.mozilla.org/integration/autoland/rev/04c8316f671f Move command registration and NSMenuItem target/action initialization into nsMenuItemX. r=harry https://hg.mozilla.org/integration/autoland/rev/e6fe584b0c8c Make InsertChildNativeMenuItem support nsMenuItemX, too. r=harry https://hg.mozilla.org/integration/autoland/rev/bff1875da8b0 Combine the two methods and properly update mVisibleItemsCount, and add some asserts. r=harry https://hg.mozilla.org/integration/autoland/rev/359a257f20b1 Allow showing and hiding items with the collapsed/hidden attributes while a menu is open. r=harry https://hg.mozilla.org/integration/autoland/rev/6c46f730e7bf Make sure that items that are un-hidden while the menu is open get their icon set up. r=harry https://hg.mozilla.org/integration/autoland/rev/2cd75d5e7509 Change internal visibility before calling MenuChildChangedVisibility. r=harry https://hg.mozilla.org/integration/autoland/rev/9445397a5ab5 Remove unnecessary null check and submenu assignment. r=harry https://hg.mozilla.org/integration/autoland/rev/b7186c85ec33 Create generic CreateMenuChild and AddMenuChild methods. r=harry https://hg.mozilla.org/integration/autoland/rev/d0b9c629a807 Add WillInsertChild and WillRemoveChild. r=harry https://hg.mozilla.org/integration/autoland/rev/a144273d02b0 Support inserting and removing menu elements while the menu is open. r=harry https://hg.mozilla.org/integration/autoland/rev/a7e2ed98d5e1 Allow opening empty menus, by putting a placeholder item in place. r=harry

Hey mstange, can we presume this is part of the set of patches that need to have beta uplift requested for MR1?

Flags: needinfo?(mstange.moz)

Definitely. The current plan is to uplift all native menu fixes in one big chunk in bug 1700679, next Monday morning (European time).

Flags: needinfo?(mstange.moz)
Whiteboard: [proton-context-menus][mac:mr1] → [proton-context-menus][mac:mr1] [proton-uplift]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: