widget/cocoa/nsMenuBarX.h

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

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

mercurial