1 /* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef NativeMenuMac_h
7 #define NativeMenuMac_h
9 #include "mozilla/widget/NativeMenu.h"
11 #include "nsMenuItemIconX.h"
15 class nsMenuGroupOwnerX
;
25 class NativeMenuMac
: public NativeMenu
,
26 public nsMenuItemIconX::Listener
,
27 public nsMenuX::Observer
{
29 explicit NativeMenuMac(dom::Element
* aElement
);
32 void ShowAsContextMenu(nsIFrame
* aClickedFrame
, const CSSIntPoint
& aPosition
,
33 bool aIsContextMenu
) override
;
34 bool Close() override
;
35 void ActivateItem(dom::Element
* aItemElement
, Modifiers aModifiers
, int16_t aButton
,
36 ErrorResult
& aRv
) override
;
37 void OpenSubmenu(dom::Element
* aMenuElement
) override
;
38 void CloseSubmenu(dom::Element
* aMenuElement
) override
;
39 RefPtr
<dom::Element
> Element() override
;
40 void AddObserver(NativeMenu::Observer
* aObserver
) override
{
41 mObservers
.AppendElement(aObserver
);
43 void RemoveObserver(NativeMenu::Observer
* aObserver
) override
{
44 mObservers
.RemoveElement(aObserver
);
47 // nsMenuItemIconX::Listener
48 void IconUpdated() override
;
51 void OnMenuWillOpen(dom::Element
* aPopupElement
) override
;
52 void OnMenuDidOpen(dom::Element
* aPopupElement
) override
;
53 void OnMenuWillActivateItem(dom::Element
* aPopupElement
, dom::Element
* aMenuItemElement
) override
;
54 void OnMenuClosed(dom::Element
* aPopupElement
) override
;
56 NSMenu
* NativeNSMenu() { return mMenu
? mMenu
->NativeNSMenu() : nil
; }
59 // Returns whether a menu item was found at the specified path.
60 bool ActivateNativeMenuItemAt(const nsAString
& aIndexString
);
62 void ForceUpdateNativeMenuAt(const nsAString
& aIndexString
);
65 // If this menu is the menu of a system status bar item (NSStatusItem),
66 // let the menu know about the status item so that it can propagate
67 // any icon changes to the status item.
68 void SetContainerStatusBarItem(NSStatusItem
* aItem
);
71 virtual ~NativeMenuMac();
73 // Find the deepest nsMenuX which contains aElement, only descending into open
75 // Returns nullptr if the element was not found or if the menus on the path
77 RefPtr
<nsMenuX
> GetOpenMenuContainingElement(dom::Element
* aElement
);
79 RefPtr
<dom::Element
> mElement
;
80 RefPtr
<nsMenuGroupOwnerX
> mMenuGroupOwner
;
81 RefPtr
<nsMenuX
> mMenu
;
82 nsTArray
<NativeMenu::Observer
*> mObservers
;
83 NSStatusItem
* mContainerStatusBarItem
;
85 // Non-zero after a call to ShowAsContextMenu. Stores the handle from the
86 // MOZMenuOpeningCoordinator.
87 NSInteger mOpeningHandle
= 0;
91 } // namespace mozilla