widget/cocoa/nsMenuBarX.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/cocoa/nsMenuBarX.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,147 @@
     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 nsMenuBarX_h_
    1.10 +#define nsMenuBarX_h_
    1.11 +
    1.12 +#import <Cocoa/Cocoa.h>
    1.13 +
    1.14 +#include "nsMenuBaseX.h"
    1.15 +#include "nsMenuGroupOwnerX.h"
    1.16 +#include "nsChangeObserver.h"
    1.17 +#include "nsINativeMenuService.h"
    1.18 +#include "nsAutoPtr.h"
    1.19 +#include "nsString.h"
    1.20 +
    1.21 +class nsMenuX;
    1.22 +class nsMenuBarX;
    1.23 +class nsMenuItemX;
    1.24 +class nsIWidget;
    1.25 +class nsIContent;
    1.26 +
    1.27 +// The native menu service for creating native menu bars.
    1.28 +class nsNativeMenuServiceX : public nsINativeMenuService
    1.29 +{
    1.30 +public:
    1.31 +  NS_DECL_ISUPPORTS
    1.32 +
    1.33 +  nsNativeMenuServiceX() {}
    1.34 +  virtual ~nsNativeMenuServiceX() {}
    1.35 +
    1.36 +  NS_IMETHOD CreateNativeMenuBar(nsIWidget* aParent, nsIContent* aMenuBarNode);
    1.37 +};
    1.38 +
    1.39 +@interface NSMenu (Undocumented)
    1.40 +// Undocumented method, present unchanged since OS X 10.6, used to temporarily
    1.41 +// highlight a top-level menu item when an appropriate Cmd+key combination is
    1.42 +// pressed.
    1.43 +- (void)_performActionWithHighlightingForItemAtIndex:(NSInteger)index;
    1.44 +@end
    1.45 +
    1.46 +// Objective-C class used to allow us to intervene with keyboard event handling.
    1.47 +// We allow mouse actions to work normally.
    1.48 +@interface GeckoNSMenu : NSMenu
    1.49 +{
    1.50 +@private
    1.51 +  nsMenuBarX *mMenuBarOwner; // Weak -- if non-null it owns us
    1.52 +  bool mDelayResignMainMenu;
    1.53 +}
    1.54 +- (id)initWithTitle:(NSString *)aTitle andMenuBarOwner:(nsMenuBarX *)aMenuBarOwner;
    1.55 +- (void)resetMenuBarOwner;
    1.56 +- (bool)delayResignMainMenu;
    1.57 +- (void)setDelayResignMainMenu:(bool)aShouldDelay;
    1.58 +- (void)delayedPaintMenuBar:(id)unused;
    1.59 +@end
    1.60 +
    1.61 +// Objective-C class used as action target for menu items
    1.62 +@interface NativeMenuItemTarget : NSObject
    1.63 +{
    1.64 +}
    1.65 +-(IBAction)menuItemHit:(id)sender;
    1.66 +@end
    1.67 +
    1.68 +// Objective-C class used for menu items on the Services menu to allow Gecko
    1.69 +// to override their standard behavior in order to stop key equivalents from
    1.70 +// firing in certain instances.
    1.71 +@interface GeckoServicesNSMenuItem : NSMenuItem
    1.72 +{
    1.73 +}
    1.74 +- (id) target;
    1.75 +- (SEL) action;
    1.76 +- (void) _doNothing:(id)sender;
    1.77 +@end
    1.78 +
    1.79 +// Objective-C class used as the Services menu so that Gecko can override the
    1.80 +// standard behavior of the Services menu in order to stop key equivalents
    1.81 +// from firing in certain instances.
    1.82 +@interface GeckoServicesNSMenu : NSMenu
    1.83 +{
    1.84 +}
    1.85 +- (void)addItem:(NSMenuItem *)newItem;
    1.86 +- (NSMenuItem *)addItemWithTitle:(NSString *)aString action:(SEL)aSelector keyEquivalent:(NSString *)keyEquiv;
    1.87 +- (void)insertItem:(NSMenuItem *)newItem atIndex:(NSInteger)index;
    1.88 +- (NSMenuItem *)insertItemWithTitle:(NSString *)aString action:(SEL)aSelector  keyEquivalent:(NSString *)keyEquiv atIndex:(NSInteger)index;
    1.89 +- (void) _overrideClassOfMenuItem:(NSMenuItem *)menuItem;
    1.90 +@end
    1.91 +
    1.92 +// Once instantiated, this object lives until its DOM node or its parent window is destroyed.
    1.93 +// Do not hold references to this, they can become invalid any time the DOM node can be destroyed.
    1.94 +class nsMenuBarX : public nsMenuGroupOwnerX, public nsChangeObserver
    1.95 +{
    1.96 +public:
    1.97 +  nsMenuBarX();
    1.98 +  virtual ~nsMenuBarX();
    1.99 +
   1.100 +  static NativeMenuItemTarget* sNativeEventTarget;
   1.101 +  static nsMenuBarX*           sLastGeckoMenuBarPainted;
   1.102 +  static nsMenuBarX*           sCurrentPaintDelayedMenuBar;
   1.103 +
   1.104 +  // The following content nodes have been removed from the menu system.
   1.105 +  // We save them here for use in command handling.
   1.106 +  nsCOMPtr<nsIContent> mAboutItemContent;
   1.107 +  nsCOMPtr<nsIContent> mUpdateItemContent;
   1.108 +  nsCOMPtr<nsIContent> mPrefItemContent;
   1.109 +  nsCOMPtr<nsIContent> mQuitItemContent;
   1.110 +
   1.111 +  // nsChangeObserver
   1.112 +  NS_DECL_CHANGEOBSERVER
   1.113 +
   1.114 +  // nsMenuObjectX
   1.115 +  void*             NativeData()     {return (void*)mNativeMenu;}
   1.116 +  nsMenuObjectTypeX MenuObjectType() {return eMenuBarObjectType;}
   1.117 +
   1.118 +  // nsMenuBarX
   1.119 +  nsresult          Create(nsIWidget* aParent, nsIContent* aContent);
   1.120 +  void              SetParent(nsIWidget* aParent);
   1.121 +  uint32_t          GetMenuCount();
   1.122 +  bool              MenuContainsAppMenu();
   1.123 +  nsMenuX*          GetMenuAt(uint32_t aIndex);
   1.124 +  nsMenuX*          GetXULHelpMenu();
   1.125 +  void              SetSystemHelpMenu();
   1.126 +  nsresult          Paint(bool aDelayed = false);
   1.127 +  void              PaintMenuBarAfterDelay();
   1.128 +  void              ResetAwaitingDelayedPaint() { mAwaitingDelayedPaint = false; }
   1.129 +  void              ForceUpdateNativeMenuAt(const nsAString& indexString);
   1.130 +  void              ForceNativeMenuReload(); // used for testing
   1.131 +  static char       GetLocalizedAccelKey(const char *shortcutID);
   1.132 +
   1.133 +protected:
   1.134 +  void              ConstructNativeMenus();
   1.135 +  nsresult          InsertMenuAtIndex(nsMenuX* aMenu, uint32_t aIndex);
   1.136 +  void              RemoveMenuAtIndex(uint32_t aIndex);
   1.137 +  void              HideItem(nsIDOMDocument* inDoc, const nsAString & inID, nsIContent** outHiddenNode);
   1.138 +  void              AquifyMenuBar();
   1.139 +  NSMenuItem*       CreateNativeAppMenuItem(nsMenuX* inMenu, const nsAString& nodeID, SEL action,
   1.140 +                                            int tag, NativeMenuItemTarget* target);
   1.141 +  nsresult          CreateApplicationMenu(nsMenuX* inMenu);
   1.142 +
   1.143 +  nsTArray< nsAutoPtr<nsMenuX> > mMenuArray;
   1.144 +  nsIWidget*         mParentWindow;        // [weak]
   1.145 +  GeckoNSMenu*       mNativeMenu;            // root menu, representing entire menu bar
   1.146 +
   1.147 +  bool               mAwaitingDelayedPaint;
   1.148 +};
   1.149 +
   1.150 +#endif // nsMenuBarX_h_

mercurial