Bug 1705120 - Add OnNativeMenuWillActivateItem observer method for NativeMenu::Observer and call it at the right times. r=harry

Differential Revision: https://phabricator.services.mozilla.com/D114435
This commit is contained in:
Markus Stange 2021-05-07 17:00:21 +00:00
parent 607f63b94a
commit 0350405261
4 changed files with 18 additions and 1 deletions

View File

@ -891,6 +891,9 @@ void nsXULPopupManager::OnNativeSubMenuClosed(
mNativeMenuSubmenuStates.Remove(aPopupElement);
}
void nsXULPopupManager::OnNativeMenuWillActivateItem(
mozilla::dom::Element* aMenuItemElement) {}
void nsXULPopupManager::ShowPopupAtScreenRect(
nsIContent* aPopup, const nsAString& aPosition, const nsIntRect& aRect,
bool aIsContextMenu, bool aAttributesOverride, Event* aTriggerEvent) {

View File

@ -368,6 +368,8 @@ class nsXULPopupManager final : public nsIDOMEventListener,
void OnNativeSubMenuWillOpen(mozilla::dom::Element* aPopupElement) override;
void OnNativeSubMenuDidOpen(mozilla::dom::Element* aPopupElement) override;
void OnNativeSubMenuClosed(mozilla::dom::Element* aPopupElement) override;
void OnNativeMenuWillActivateItem(
mozilla::dom::Element* aMenuItemElement) override;
static nsXULPopupManager* sInstance;

View File

@ -73,6 +73,10 @@ class NativeMenu {
// Called after the popuphidden event of a submenu fired.
virtual void OnNativeSubMenuClosed(dom::Element* aPopupElement) = 0;
// Called before the command event of an activated menu item fires.
virtual void OnNativeMenuWillActivateItem(
dom::Element* aMenuItemElement) = 0;
};
// Add an observer that gets notified of menu opening and closing.

View File

@ -193,7 +193,15 @@ void NativeMenuMac::OnMenuDidOpen(dom::Element* aPopupElement) {
}
void NativeMenuMac::OnMenuWillActivateItem(mozilla::dom::Element* aPopupElement,
mozilla::dom::Element* aMenuItemElement) {}
mozilla::dom::Element* aMenuItemElement) {
// Our caller isn't keeping us alive, so make sure we stay alive throughout this function in case
// one of the observer notifications destroys us.
RefPtr<NativeMenuMac> kungFuDeathGrip(this);
for (NativeMenu::Observer* observer : mObservers.Clone()) {
observer->OnNativeMenuWillActivateItem(aMenuItemElement);
}
}
void NativeMenuMac::OnMenuClosed(dom::Element* aPopupElement) {
// Our caller isn't keeping us alive, so make sure we stay alive throughout this function in case