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
,
36 int16_t aButton
, 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
,
54 dom::Element
* aMenuItemElement
) override
;
55 void OnMenuClosed(dom::Element
* aPopupElement
) override
;
57 NSMenu
* NativeNSMenu() { return mMenu
? mMenu
->NativeNSMenu() : nil
; }
60 // Returns whether a menu item was found at the specified path.
61 bool ActivateNativeMenuItemAt(const nsAString
& aIndexString
);
63 void ForceUpdateNativeMenuAt(const nsAString
& aIndexString
);
66 // If this menu is the menu of a system status bar item (NSStatusItem),
67 // let the menu know about the status item so that it can propagate
68 // any icon changes to the status item.
69 void SetContainerStatusBarItem(NSStatusItem
* aItem
);
72 virtual ~NativeMenuMac();
74 // Find the deepest nsMenuX which contains aElement, only descending into open
76 // Returns nullptr if the element was not found or if the menus on the path
78 RefPtr
<nsMenuX
> GetOpenMenuContainingElement(dom::Element
* aElement
);
80 RefPtr
<dom::Element
> mElement
;
81 RefPtr
<nsMenuGroupOwnerX
> mMenuGroupOwner
;
82 RefPtr
<nsMenuX
> mMenu
;
83 nsTArray
<NativeMenu::Observer
*> mObservers
;
84 NSStatusItem
* mContainerStatusBarItem
;
86 // Non-zero after a call to ShowAsContextMenu. Stores the handle from the
87 // MOZMenuOpeningCoordinator.
88 NSInteger mOpeningHandle
= 0;
92 } // namespace mozilla