Bug 1835241 - Part 6: Use the same parameter names at definition and declaration...
[gecko.git] / widget / cocoa / NativeMenuMac.h
blobf2f5d200339b31fd35679a148a1bd8ab0c4da51c
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"
12 #include "nsMenuX.h"
14 class nsIContent;
15 class nsMenuGroupOwnerX;
17 namespace mozilla {
19 namespace dom {
20 class Element;
23 namespace widget {
25 class NativeMenuMac : public NativeMenu,
26 public nsMenuItemIconX::Listener,
27 public nsMenuX::Observer {
28 public:
29 explicit NativeMenuMac(dom::Element* aElement);
31 // NativeMenu
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;
50 // nsMenuX::Observer
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; }
57 void MenuWillOpen();
59 // Returns whether a menu item was found at the specified path.
60 bool ActivateNativeMenuItemAt(const nsAString& aIndexString);
62 void ForceUpdateNativeMenuAt(const nsAString& aIndexString);
63 void Dump();
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);
70 protected:
71 virtual ~NativeMenuMac();
73 // Find the deepest nsMenuX which contains aElement, only descending into open
74 // menus.
75 // Returns nullptr if the element was not found or if the menus on the path
76 // were not all open.
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;
90 } // namespace widget
91 } // namespace mozilla
93 #endif