Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 nsMenuBarX_h_ |
michael@0 | 7 | #define nsMenuBarX_h_ |
michael@0 | 8 | |
michael@0 | 9 | #import <Cocoa/Cocoa.h> |
michael@0 | 10 | |
michael@0 | 11 | #include "nsMenuBaseX.h" |
michael@0 | 12 | #include "nsMenuGroupOwnerX.h" |
michael@0 | 13 | #include "nsChangeObserver.h" |
michael@0 | 14 | #include "nsINativeMenuService.h" |
michael@0 | 15 | #include "nsAutoPtr.h" |
michael@0 | 16 | #include "nsString.h" |
michael@0 | 17 | |
michael@0 | 18 | class nsMenuX; |
michael@0 | 19 | class nsMenuBarX; |
michael@0 | 20 | class nsMenuItemX; |
michael@0 | 21 | class nsIWidget; |
michael@0 | 22 | class nsIContent; |
michael@0 | 23 | |
michael@0 | 24 | // The native menu service for creating native menu bars. |
michael@0 | 25 | class nsNativeMenuServiceX : public nsINativeMenuService |
michael@0 | 26 | { |
michael@0 | 27 | public: |
michael@0 | 28 | NS_DECL_ISUPPORTS |
michael@0 | 29 | |
michael@0 | 30 | nsNativeMenuServiceX() {} |
michael@0 | 31 | virtual ~nsNativeMenuServiceX() {} |
michael@0 | 32 | |
michael@0 | 33 | NS_IMETHOD CreateNativeMenuBar(nsIWidget* aParent, nsIContent* aMenuBarNode); |
michael@0 | 34 | }; |
michael@0 | 35 | |
michael@0 | 36 | @interface NSMenu (Undocumented) |
michael@0 | 37 | // Undocumented method, present unchanged since OS X 10.6, used to temporarily |
michael@0 | 38 | // highlight a top-level menu item when an appropriate Cmd+key combination is |
michael@0 | 39 | // pressed. |
michael@0 | 40 | - (void)_performActionWithHighlightingForItemAtIndex:(NSInteger)index; |
michael@0 | 41 | @end |
michael@0 | 42 | |
michael@0 | 43 | // Objective-C class used to allow us to intervene with keyboard event handling. |
michael@0 | 44 | // We allow mouse actions to work normally. |
michael@0 | 45 | @interface GeckoNSMenu : NSMenu |
michael@0 | 46 | { |
michael@0 | 47 | @private |
michael@0 | 48 | nsMenuBarX *mMenuBarOwner; // Weak -- if non-null it owns us |
michael@0 | 49 | bool mDelayResignMainMenu; |
michael@0 | 50 | } |
michael@0 | 51 | - (id)initWithTitle:(NSString *)aTitle andMenuBarOwner:(nsMenuBarX *)aMenuBarOwner; |
michael@0 | 52 | - (void)resetMenuBarOwner; |
michael@0 | 53 | - (bool)delayResignMainMenu; |
michael@0 | 54 | - (void)setDelayResignMainMenu:(bool)aShouldDelay; |
michael@0 | 55 | - (void)delayedPaintMenuBar:(id)unused; |
michael@0 | 56 | @end |
michael@0 | 57 | |
michael@0 | 58 | // Objective-C class used as action target for menu items |
michael@0 | 59 | @interface NativeMenuItemTarget : NSObject |
michael@0 | 60 | { |
michael@0 | 61 | } |
michael@0 | 62 | -(IBAction)menuItemHit:(id)sender; |
michael@0 | 63 | @end |
michael@0 | 64 | |
michael@0 | 65 | // Objective-C class used for menu items on the Services menu to allow Gecko |
michael@0 | 66 | // to override their standard behavior in order to stop key equivalents from |
michael@0 | 67 | // firing in certain instances. |
michael@0 | 68 | @interface GeckoServicesNSMenuItem : NSMenuItem |
michael@0 | 69 | { |
michael@0 | 70 | } |
michael@0 | 71 | - (id) target; |
michael@0 | 72 | - (SEL) action; |
michael@0 | 73 | - (void) _doNothing:(id)sender; |
michael@0 | 74 | @end |
michael@0 | 75 | |
michael@0 | 76 | // Objective-C class used as the Services menu so that Gecko can override the |
michael@0 | 77 | // standard behavior of the Services menu in order to stop key equivalents |
michael@0 | 78 | // from firing in certain instances. |
michael@0 | 79 | @interface GeckoServicesNSMenu : NSMenu |
michael@0 | 80 | { |
michael@0 | 81 | } |
michael@0 | 82 | - (void)addItem:(NSMenuItem *)newItem; |
michael@0 | 83 | - (NSMenuItem *)addItemWithTitle:(NSString *)aString action:(SEL)aSelector keyEquivalent:(NSString *)keyEquiv; |
michael@0 | 84 | - (void)insertItem:(NSMenuItem *)newItem atIndex:(NSInteger)index; |
michael@0 | 85 | - (NSMenuItem *)insertItemWithTitle:(NSString *)aString action:(SEL)aSelector keyEquivalent:(NSString *)keyEquiv atIndex:(NSInteger)index; |
michael@0 | 86 | - (void) _overrideClassOfMenuItem:(NSMenuItem *)menuItem; |
michael@0 | 87 | @end |
michael@0 | 88 | |
michael@0 | 89 | // Once instantiated, this object lives until its DOM node or its parent window is destroyed. |
michael@0 | 90 | // Do not hold references to this, they can become invalid any time the DOM node can be destroyed. |
michael@0 | 91 | class nsMenuBarX : public nsMenuGroupOwnerX, public nsChangeObserver |
michael@0 | 92 | { |
michael@0 | 93 | public: |
michael@0 | 94 | nsMenuBarX(); |
michael@0 | 95 | virtual ~nsMenuBarX(); |
michael@0 | 96 | |
michael@0 | 97 | static NativeMenuItemTarget* sNativeEventTarget; |
michael@0 | 98 | static nsMenuBarX* sLastGeckoMenuBarPainted; |
michael@0 | 99 | static nsMenuBarX* sCurrentPaintDelayedMenuBar; |
michael@0 | 100 | |
michael@0 | 101 | // The following content nodes have been removed from the menu system. |
michael@0 | 102 | // We save them here for use in command handling. |
michael@0 | 103 | nsCOMPtr<nsIContent> mAboutItemContent; |
michael@0 | 104 | nsCOMPtr<nsIContent> mUpdateItemContent; |
michael@0 | 105 | nsCOMPtr<nsIContent> mPrefItemContent; |
michael@0 | 106 | nsCOMPtr<nsIContent> mQuitItemContent; |
michael@0 | 107 | |
michael@0 | 108 | // nsChangeObserver |
michael@0 | 109 | NS_DECL_CHANGEOBSERVER |
michael@0 | 110 | |
michael@0 | 111 | // nsMenuObjectX |
michael@0 | 112 | void* NativeData() {return (void*)mNativeMenu;} |
michael@0 | 113 | nsMenuObjectTypeX MenuObjectType() {return eMenuBarObjectType;} |
michael@0 | 114 | |
michael@0 | 115 | // nsMenuBarX |
michael@0 | 116 | nsresult Create(nsIWidget* aParent, nsIContent* aContent); |
michael@0 | 117 | void SetParent(nsIWidget* aParent); |
michael@0 | 118 | uint32_t GetMenuCount(); |
michael@0 | 119 | bool MenuContainsAppMenu(); |
michael@0 | 120 | nsMenuX* GetMenuAt(uint32_t aIndex); |
michael@0 | 121 | nsMenuX* GetXULHelpMenu(); |
michael@0 | 122 | void SetSystemHelpMenu(); |
michael@0 | 123 | nsresult Paint(bool aDelayed = false); |
michael@0 | 124 | void PaintMenuBarAfterDelay(); |
michael@0 | 125 | void ResetAwaitingDelayedPaint() { mAwaitingDelayedPaint = false; } |
michael@0 | 126 | void ForceUpdateNativeMenuAt(const nsAString& indexString); |
michael@0 | 127 | void ForceNativeMenuReload(); // used for testing |
michael@0 | 128 | static char GetLocalizedAccelKey(const char *shortcutID); |
michael@0 | 129 | |
michael@0 | 130 | protected: |
michael@0 | 131 | void ConstructNativeMenus(); |
michael@0 | 132 | nsresult InsertMenuAtIndex(nsMenuX* aMenu, uint32_t aIndex); |
michael@0 | 133 | void RemoveMenuAtIndex(uint32_t aIndex); |
michael@0 | 134 | void HideItem(nsIDOMDocument* inDoc, const nsAString & inID, nsIContent** outHiddenNode); |
michael@0 | 135 | void AquifyMenuBar(); |
michael@0 | 136 | NSMenuItem* CreateNativeAppMenuItem(nsMenuX* inMenu, const nsAString& nodeID, SEL action, |
michael@0 | 137 | int tag, NativeMenuItemTarget* target); |
michael@0 | 138 | nsresult CreateApplicationMenu(nsMenuX* inMenu); |
michael@0 | 139 | |
michael@0 | 140 | nsTArray< nsAutoPtr<nsMenuX> > mMenuArray; |
michael@0 | 141 | nsIWidget* mParentWindow; // [weak] |
michael@0 | 142 | GeckoNSMenu* mNativeMenu; // root menu, representing entire menu bar |
michael@0 | 143 | |
michael@0 | 144 | bool mAwaitingDelayedPaint; |
michael@0 | 145 | }; |
michael@0 | 146 | |
michael@0 | 147 | #endif // nsMenuBarX_h_ |