Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / widget / cocoa / NativeMenuMac.h
blobe230fd184c2d717b823eea5b6d6167081d9daa70
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,
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;
50 // nsMenuX::Observer
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; }
58 void MenuWillOpen();
60 // Returns whether a menu item was found at the specified path.
61 bool ActivateNativeMenuItemAt(const nsAString& aIndexString);
63 void ForceUpdateNativeMenuAt(const nsAString& aIndexString);
64 void Dump();
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);
71 protected:
72 virtual ~NativeMenuMac();
74 // Find the deepest nsMenuX which contains aElement, only descending into open
75 // menus.
76 // Returns nullptr if the element was not found or if the menus on the path
77 // were not all open.
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;
91 } // namespace widget
92 } // namespace mozilla
94 #endif