fune/widget/cocoa/nsMenuGroupOwnerX.h
Cristian Tuns 8e06a7a853 Backed out 12 changesets (bug 1825325, bug 1825336, bug 1825333, bug 1825332, bug 1825324, bug 1824557, bug 1825328, bug 1825335, bug 1825330, bug 1825329, bug 1825327, bug 1825331) for causing build bustages in nsClipboard.cpp CLOSED TREE
Backed out changeset 9de3ed24d3a0 (bug 1825336)
Backed out changeset aef787728f19 (bug 1825335)
Backed out changeset a04c341244c1 (bug 1825333)
Backed out changeset e3ad15f762ba (bug 1825332)
Backed out changeset eed23da92a27 (bug 1825331)
Backed out changeset 8213bb54376e (bug 1825330)
Backed out changeset 747ec5ac4994 (bug 1825329)
Backed out changeset e91ff431f92d (bug 1825328)
Backed out changeset 59c18d13768b (bug 1825327)
Backed out changeset 538096d99e49 (bug 1825325)
Backed out changeset c76eb9d9b095 (bug 1825324)
Backed out changeset 8b81410eb686 (bug 1824557)
2023-03-31 12:58:53 -04:00

95 lines
3.1 KiB
Objective-C

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsMenuGroupOwnerX_h_
#define nsMenuGroupOwnerX_h_
#import <Cocoa/Cocoa.h>
#include "mozilla/WeakPtr.h"
#include "nsStubMutationObserver.h"
#include "nsHashKeys.h"
#include "nsIObserver.h"
#include "nsTHashMap.h"
#include "nsString.h"
class nsMenuBarX;
class nsMenuItemX;
class nsChangeObserver;
class nsIWidget;
class nsIContent;
@class MOZMenuItemRepresentedObject;
// Fixed command IDs that work even without a JS listener, for our fallback menu bar.
// Dynamic command IDs start counting from eCommand_ID_Last.
enum {
eCommand_ID_About = 1,
eCommand_ID_Prefs = 2,
eCommand_ID_Quit = 3,
eCommand_ID_HideApp = 4,
eCommand_ID_HideOthers = 5,
eCommand_ID_ShowAll = 6,
eCommand_ID_Update = 7,
eCommand_ID_TouchBar = 8,
eCommand_ID_Account = 9,
eCommand_ID_Last = 10
};
// The menu group owner observes DOM mutations, notifies registered nsChangeObservers, and manages
// command registration.
// There is one owner per menubar, and one per standalone native menu.
class nsMenuGroupOwnerX : public nsMultiMutationObserver, public nsIObserver {
public:
// Both parameters can be null.
nsMenuGroupOwnerX(mozilla::dom::Element* aElement, nsMenuBarX* aMenuBarIfMenuBar);
void RegisterForContentChanges(nsIContent* aContent, nsChangeObserver* aMenuObject);
void UnregisterForContentChanges(nsIContent* aContent);
uint32_t RegisterForCommand(nsMenuItemX* aMenuItem);
void UnregisterCommand(uint32_t aCommandID);
nsMenuItemX* GetMenuItemForCommandID(uint32_t aCommandID);
void RegisterForLocaleChanges();
void UnregisterForLocaleChanges();
// The representedObject that's used for all menu items under this menu group owner.
MOZMenuItemRepresentedObject* GetRepresentedObject() { return mRepresentedObject; }
// If this is the group owner for a menubar, return the menubar, otherwise nullptr.
nsMenuBarX* GetMenuBar() { return mMenuBar.get(); }
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_DECL_NSIMUTATIONOBSERVER
protected:
virtual ~nsMenuGroupOwnerX();
nsChangeObserver* LookupContentChangeObserver(nsIContent* aContent);
RefPtr<nsIContent> mContent;
// Unique command id (per menu-bar) to give to next item that asks.
uint32_t mCurrentCommandID = eCommand_ID_Last;
// stores observers for content change notification
nsTHashMap<nsPtrHashKey<nsIContent>, nsChangeObserver*> mContentToObserverTable;
// stores mapping of command IDs to menu objects
nsTHashMap<nsUint32HashKey, nsMenuItemX*> mCommandToMenuObjectTable;
MOZMenuItemRepresentedObject* mRepresentedObject = nil; // [strong]
mozilla::WeakPtr<nsMenuBarX> mMenuBar;
};
@interface MOZMenuItemRepresentedObject : NSObject
- (id)initWithMenuGroupOwner:(nsMenuGroupOwnerX*)aMenuGroupOwner;
- (void)setMenuGroupOwner:(nsMenuGroupOwnerX*)aMenuGroupOwner;
- (nsMenuGroupOwnerX*)menuGroupOwner;
@end
#endif // nsMenuGroupOwner_h_