widget/cocoa/nsMenuX.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsMenuX_h_
michael@0 7 #define nsMenuX_h_
michael@0 8
michael@0 9 #import <Cocoa/Cocoa.h>
michael@0 10
michael@0 11 #include "nsMenuBaseX.h"
michael@0 12 #include "nsMenuBarX.h"
michael@0 13 #include "nsMenuGroupOwnerX.h"
michael@0 14 #include "nsCOMPtr.h"
michael@0 15 #include "nsChangeObserver.h"
michael@0 16 #include "nsAutoPtr.h"
michael@0 17
michael@0 18 class nsMenuX;
michael@0 19 class nsMenuItemIconX;
michael@0 20 class nsMenuItemX;
michael@0 21 class nsIWidget;
michael@0 22
michael@0 23 // MenuDelegate is used to receive Cocoa notifications for setting
michael@0 24 // up carbon events. Protocol is defined as of 10.6 SDK.
michael@0 25 #if defined(MAC_OS_X_VERSION_10_6) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6)
michael@0 26 @interface MenuDelegate : NSObject < NSMenuDelegate >
michael@0 27 #else
michael@0 28 @interface MenuDelegate : NSObject
michael@0 29 #endif
michael@0 30 {
michael@0 31 nsMenuX* mGeckoMenu; // weak ref
michael@0 32 }
michael@0 33 - (id)initWithGeckoMenu:(nsMenuX*)geckoMenu;
michael@0 34 @end
michael@0 35
michael@0 36 // Once instantiated, this object lives until its DOM node or its parent window is destroyed.
michael@0 37 // Do not hold references to this, they can become invalid any time the DOM node can be destroyed.
michael@0 38 class nsMenuX : public nsMenuObjectX,
michael@0 39 public nsChangeObserver
michael@0 40 {
michael@0 41 public:
michael@0 42 nsMenuX();
michael@0 43 virtual ~nsMenuX();
michael@0 44
michael@0 45 // If > 0, the OS is indexing all the app's menus (triggered by opening
michael@0 46 // Help menu on Leopard and higher). There are some things that are
michael@0 47 // unsafe to do while this is happening.
michael@0 48 static int32_t sIndexingMenuLevel;
michael@0 49
michael@0 50 NS_DECL_CHANGEOBSERVER
michael@0 51
michael@0 52 // nsMenuObjectX
michael@0 53 void* NativeData() {return (void*)mNativeMenu;}
michael@0 54 nsMenuObjectTypeX MenuObjectType() {return eSubmenuObjectType;}
michael@0 55
michael@0 56 // nsMenuX
michael@0 57 nsresult Create(nsMenuObjectX* aParent, nsMenuGroupOwnerX* aMenuGroupOwner, nsIContent* aNode);
michael@0 58 uint32_t GetItemCount();
michael@0 59 nsMenuObjectX* GetItemAt(uint32_t aPos);
michael@0 60 nsresult GetVisibleItemCount(uint32_t &aCount);
michael@0 61 nsMenuObjectX* GetVisibleItemAt(uint32_t aPos);
michael@0 62 nsEventStatus MenuOpened();
michael@0 63 void MenuClosed();
michael@0 64 void SetRebuild(bool aMenuEvent);
michael@0 65 NSMenuItem* NativeMenuItem();
michael@0 66
michael@0 67 static bool IsXULHelpMenu(nsIContent* aMenuContent);
michael@0 68
michael@0 69 protected:
michael@0 70 void MenuConstruct();
michael@0 71 nsresult RemoveAll();
michael@0 72 nsresult SetEnabled(bool aIsEnabled);
michael@0 73 nsresult GetEnabled(bool* aIsEnabled);
michael@0 74 nsresult SetupIcon();
michael@0 75 void GetMenuPopupContent(nsIContent** aResult);
michael@0 76 bool OnOpen();
michael@0 77 bool OnClose();
michael@0 78 nsresult AddMenuItem(nsMenuItemX* aMenuItem);
michael@0 79 nsresult AddMenu(nsMenuX* aMenu);
michael@0 80 void LoadMenuItem(nsIContent* inMenuItemContent);
michael@0 81 void LoadSubMenu(nsIContent* inMenuContent);
michael@0 82 GeckoNSMenu* CreateMenuWithGeckoString(nsString& menuTitle);
michael@0 83
michael@0 84 nsTArray< nsAutoPtr<nsMenuObjectX> > mMenuObjectsArray;
michael@0 85 nsString mLabel;
michael@0 86 uint32_t mVisibleItemsCount; // cache
michael@0 87 nsMenuObjectX* mParent; // [weak]
michael@0 88 nsMenuGroupOwnerX* mMenuGroupOwner; // [weak]
michael@0 89 // The icon object should never outlive its creating nsMenuX object.
michael@0 90 nsRefPtr<nsMenuItemIconX> mIcon;
michael@0 91 GeckoNSMenu* mNativeMenu; // [strong]
michael@0 92 MenuDelegate* mMenuDelegate; // [strong]
michael@0 93 // nsMenuX objects should always have a valid native menu item.
michael@0 94 NSMenuItem* mNativeMenuItem; // [strong]
michael@0 95 bool mIsEnabled;
michael@0 96 bool mDestroyHandlerCalled;
michael@0 97 bool mNeedsRebuild;
michael@0 98 bool mConstructed;
michael@0 99 bool mVisible;
michael@0 100 bool mXBLAttached;
michael@0 101 };
michael@0 102
michael@0 103 #endif // nsMenuX_h_

mercurial