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/. */
5 
6 #ifndef nsMenuGroupOwnerX_h_
7 #define nsMenuGroupOwnerX_h_
8 
9 #import <Cocoa/Cocoa.h>
10 
11 #include "nsMenuBaseX.h"
12 #include "nsIMutationObserver.h"
13 #include "nsHashKeys.h"
14 #include "nsDataHashtable.h"
15 #include "nsString.h"
16 
17 class nsMenuItemX;
18 class nsChangeObserver;
19 class nsIWidget;
20 class nsIContent;
21 
22 class nsMenuGroupOwnerX : public nsMenuObjectX, public nsIMutationObserver {
23  public:
24   nsMenuGroupOwnerX();
25 
26   nsresult Create(mozilla::dom::Element* aContent);
27 
28   void RegisterForContentChanges(nsIContent* aContent, nsChangeObserver* aMenuObject);
29   void UnregisterForContentChanges(nsIContent* aContent);
30   uint32_t RegisterForCommand(nsMenuItemX* aItem);
31   void UnregisterCommand(uint32_t aCommandID);
32   nsMenuItemX* GetMenuItemForCommandID(uint32_t inCommandID);
33   void AddMenuItemInfoToSet(MenuItemInfo* info);
34 
35   NS_DECL_ISUPPORTS
36   NS_DECL_NSIMUTATIONOBSERVER
37 
38  protected:
39   virtual ~nsMenuGroupOwnerX();
40 
41   nsChangeObserver* LookupContentChangeObserver(nsIContent* aContent);
42 
43   uint32_t mCurrentCommandID;  // unique command id (per menu-bar) to
44                                // give to next item that asks
45 
46   // stores observers for content change notification
47   nsDataHashtable<nsPtrHashKey<nsIContent>, nsChangeObserver*> mContentToObserverTable;
48 
49   // stores mapping of command IDs to menu objects
50   nsDataHashtable<nsUint32HashKey, nsMenuItemX*> mCommandToMenuObjectTable;
51 
52   // Stores references to all the MenuItemInfo objects created with weak
53   // references to us.  They may live longer than we do, so when we're
54   // destroyed we need to clear all their weak references.  This avoids
55   // crashes in -[NativeMenuItemTarget menuItemHit:].  See bug 1131473.
56   NSMutableSet* mInfoSet;
57 };
58 
59 #endif  // nsMenuGroupOwner_h_
60