1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/cocoa/nsMenuX.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsMenuX_h_ 1.10 +#define nsMenuX_h_ 1.11 + 1.12 +#import <Cocoa/Cocoa.h> 1.13 + 1.14 +#include "nsMenuBaseX.h" 1.15 +#include "nsMenuBarX.h" 1.16 +#include "nsMenuGroupOwnerX.h" 1.17 +#include "nsCOMPtr.h" 1.18 +#include "nsChangeObserver.h" 1.19 +#include "nsAutoPtr.h" 1.20 + 1.21 +class nsMenuX; 1.22 +class nsMenuItemIconX; 1.23 +class nsMenuItemX; 1.24 +class nsIWidget; 1.25 + 1.26 +// MenuDelegate is used to receive Cocoa notifications for setting 1.27 +// up carbon events. Protocol is defined as of 10.6 SDK. 1.28 +#if defined(MAC_OS_X_VERSION_10_6) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6) 1.29 +@interface MenuDelegate : NSObject < NSMenuDelegate > 1.30 +#else 1.31 +@interface MenuDelegate : NSObject 1.32 +#endif 1.33 +{ 1.34 + nsMenuX* mGeckoMenu; // weak ref 1.35 +} 1.36 +- (id)initWithGeckoMenu:(nsMenuX*)geckoMenu; 1.37 +@end 1.38 + 1.39 +// Once instantiated, this object lives until its DOM node or its parent window is destroyed. 1.40 +// Do not hold references to this, they can become invalid any time the DOM node can be destroyed. 1.41 +class nsMenuX : public nsMenuObjectX, 1.42 + public nsChangeObserver 1.43 +{ 1.44 +public: 1.45 + nsMenuX(); 1.46 + virtual ~nsMenuX(); 1.47 + 1.48 + // If > 0, the OS is indexing all the app's menus (triggered by opening 1.49 + // Help menu on Leopard and higher). There are some things that are 1.50 + // unsafe to do while this is happening. 1.51 + static int32_t sIndexingMenuLevel; 1.52 + 1.53 + NS_DECL_CHANGEOBSERVER 1.54 + 1.55 + // nsMenuObjectX 1.56 + void* NativeData() {return (void*)mNativeMenu;} 1.57 + nsMenuObjectTypeX MenuObjectType() {return eSubmenuObjectType;} 1.58 + 1.59 + // nsMenuX 1.60 + nsresult Create(nsMenuObjectX* aParent, nsMenuGroupOwnerX* aMenuGroupOwner, nsIContent* aNode); 1.61 + uint32_t GetItemCount(); 1.62 + nsMenuObjectX* GetItemAt(uint32_t aPos); 1.63 + nsresult GetVisibleItemCount(uint32_t &aCount); 1.64 + nsMenuObjectX* GetVisibleItemAt(uint32_t aPos); 1.65 + nsEventStatus MenuOpened(); 1.66 + void MenuClosed(); 1.67 + void SetRebuild(bool aMenuEvent); 1.68 + NSMenuItem* NativeMenuItem(); 1.69 + 1.70 + static bool IsXULHelpMenu(nsIContent* aMenuContent); 1.71 + 1.72 +protected: 1.73 + void MenuConstruct(); 1.74 + nsresult RemoveAll(); 1.75 + nsresult SetEnabled(bool aIsEnabled); 1.76 + nsresult GetEnabled(bool* aIsEnabled); 1.77 + nsresult SetupIcon(); 1.78 + void GetMenuPopupContent(nsIContent** aResult); 1.79 + bool OnOpen(); 1.80 + bool OnClose(); 1.81 + nsresult AddMenuItem(nsMenuItemX* aMenuItem); 1.82 + nsresult AddMenu(nsMenuX* aMenu); 1.83 + void LoadMenuItem(nsIContent* inMenuItemContent); 1.84 + void LoadSubMenu(nsIContent* inMenuContent); 1.85 + GeckoNSMenu* CreateMenuWithGeckoString(nsString& menuTitle); 1.86 + 1.87 + nsTArray< nsAutoPtr<nsMenuObjectX> > mMenuObjectsArray; 1.88 + nsString mLabel; 1.89 + uint32_t mVisibleItemsCount; // cache 1.90 + nsMenuObjectX* mParent; // [weak] 1.91 + nsMenuGroupOwnerX* mMenuGroupOwner; // [weak] 1.92 + // The icon object should never outlive its creating nsMenuX object. 1.93 + nsRefPtr<nsMenuItemIconX> mIcon; 1.94 + GeckoNSMenu* mNativeMenu; // [strong] 1.95 + MenuDelegate* mMenuDelegate; // [strong] 1.96 + // nsMenuX objects should always have a valid native menu item. 1.97 + NSMenuItem* mNativeMenuItem; // [strong] 1.98 + bool mIsEnabled; 1.99 + bool mDestroyHandlerCalled; 1.100 + bool mNeedsRebuild; 1.101 + bool mConstructed; 1.102 + bool mVisible; 1.103 + bool mXBLAttached; 1.104 +}; 1.105 + 1.106 +#endif // nsMenuX_h_