Backed out changeset b4a0f8afc02e (bug 1857946) for causing bc failures at browser...
[gecko.git] / widget / cocoa / nsMenuGroupOwnerX.h
bloba9060a60295e77d51e0f36ceaa01c654ee31fab1
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 nsMenuGroupOwnerX_h_
7 #define nsMenuGroupOwnerX_h_
9 #import <Cocoa/Cocoa.h>
11 #include "mozilla/WeakPtr.h"
13 #include "nsStubMutationObserver.h"
14 #include "nsHashKeys.h"
15 #include "nsIObserver.h"
16 #include "nsMenuBarX.h"
17 #include "nsTHashMap.h"
18 #include "nsString.h"
20 class nsMenuItemX;
21 class nsChangeObserver;
22 class nsIWidget;
23 class nsIContent;
25 @class MOZMenuItemRepresentedObject;
27 // Fixed command IDs that work even without a JS listener, for our fallback menu bar.
28 // Dynamic command IDs start counting from eCommand_ID_Last.
29 enum {
30 eCommand_ID_About = 1,
31 eCommand_ID_Prefs = 2,
32 eCommand_ID_Quit = 3,
33 eCommand_ID_HideApp = 4,
34 eCommand_ID_HideOthers = 5,
35 eCommand_ID_ShowAll = 6,
36 eCommand_ID_Update = 7,
37 eCommand_ID_TouchBar = 8,
38 eCommand_ID_Account = 9,
39 eCommand_ID_Last = 10
42 // The menu group owner observes DOM mutations, notifies registered nsChangeObservers, and manages
43 // command registration.
44 // There is one owner per menubar, and one per standalone native menu.
45 class nsMenuGroupOwnerX : public nsMultiMutationObserver, public nsIObserver {
46 public:
47 // Both parameters can be null.
48 nsMenuGroupOwnerX(mozilla::dom::Element* aElement, nsMenuBarX* aMenuBarIfMenuBar);
50 void RegisterForContentChanges(nsIContent* aContent, nsChangeObserver* aMenuObject);
51 void UnregisterForContentChanges(nsIContent* aContent);
52 uint32_t RegisterForCommand(nsMenuItemX* aMenuItem);
53 void UnregisterCommand(uint32_t aCommandID);
54 nsMenuItemX* GetMenuItemForCommandID(uint32_t aCommandID);
56 void RegisterForLocaleChanges();
57 void UnregisterForLocaleChanges();
59 // The representedObject that's used for all menu items under this menu group owner.
60 MOZMenuItemRepresentedObject* GetRepresentedObject() { return mRepresentedObject; }
62 // If this is the group owner for a menubar, return the menubar, otherwise nullptr.
63 nsMenuBarX* GetMenuBar() { return mMenuBar.get(); }
65 NS_DECL_ISUPPORTS
66 NS_DECL_NSIOBSERVER
67 NS_DECL_NSIMUTATIONOBSERVER
69 protected:
70 virtual ~nsMenuGroupOwnerX();
72 nsChangeObserver* LookupContentChangeObserver(nsIContent* aContent);
74 RefPtr<nsIContent> mContent;
76 // Unique command id (per menu-bar) to give to next item that asks.
77 uint32_t mCurrentCommandID = eCommand_ID_Last;
79 // stores observers for content change notification
80 nsTHashMap<nsPtrHashKey<nsIContent>, nsChangeObserver*> mContentToObserverTable;
82 // stores mapping of command IDs to menu objects
83 nsTHashMap<nsUint32HashKey, nsMenuItemX*> mCommandToMenuObjectTable;
85 MOZMenuItemRepresentedObject* mRepresentedObject = nil; // [strong]
86 mozilla::WeakPtr<nsMenuBarX> mMenuBar;
89 @interface MOZMenuItemRepresentedObject : NSObject
90 - (id)initWithMenuGroupOwner:(nsMenuGroupOwnerX*)aMenuGroupOwner;
91 - (void)setMenuGroupOwner:(nsMenuGroupOwnerX*)aMenuGroupOwner;
92 - (nsMenuGroupOwnerX*)menuGroupOwner;
93 @end
95 #endif // nsMenuGroupOwner_h_