From 63b85bccab75961e45d4c5a6d25787f38a279ca6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 14 Aug 2013 23:03:02 +0800 Subject: [PATCH] [Mac] Clean up the menu controller. --- browser/api/atom_api_menu_mac.mm | 6 ++---- browser/ui/atom_menu_controller_mac.h | 16 ++-------------- browser/ui/atom_menu_controller_mac.mm | 19 +------------------ 3 files changed, 5 insertions(+), 36 deletions(-) diff --git a/browser/api/atom_api_menu_mac.mm b/browser/api/atom_api_menu_mac.mm index 2ae9f05e9a9..acf4849435e 100644 --- a/browser/api/atom_api_menu_mac.mm +++ b/browser/api/atom_api_menu_mac.mm @@ -24,8 +24,7 @@ MenuMac::~MenuMac() { void MenuMac::Popup(NativeWindow* native_window) { scoped_nsobject menu_controller( - [[AtomMenuController alloc] initWithModel:model_.get() - useWithPopUpButtonCell:NO]); + [[AtomMenuController alloc] initWithModel:model_.get()]); NSWindow* window = native_window->GetNativeWindow(); content::WebContents* web_contents = native_window->GetWebContents(); @@ -82,8 +81,7 @@ v8::Handle Menu::SetApplicationMenu(const v8::Arguments &args) { return node::ThrowError("Menu is destroyed"); scoped_nsobject menu_controller( - [[AtomMenuController alloc] initWithModel:menu->model_.get() - useWithPopUpButtonCell:NO]); + [[AtomMenuController alloc] initWithModel:menu->model_.get()]); [NSApp setMainMenu:[menu_controller menu]]; // Ensure the menu_controller_ is destroyed after main menu is set. diff --git a/browser/ui/atom_menu_controller_mac.h b/browser/ui/atom_menu_controller_mac.h index 0455de17eb8..74c2240efac 100644 --- a/browser/ui/atom_menu_controller_mac.h +++ b/browser/ui/atom_menu_controller_mac.h @@ -25,14 +25,10 @@ class MenuModel; @protected ui::MenuModel* model_; // weak scoped_nsobject menu_; - BOOL useWithPopUpButtonCell_; // If YES, 0th item is blank BOOL isMenuOpen_; } @property(nonatomic, assign) ui::MenuModel* model; -// Note that changing this will have no effect if you use -// |-initWithModel:useWithPopUpButtonCell:| or after the first call to |-menu|. -@property(nonatomic) BOOL useWithPopUpButtonCell; // NIB-based initializer. This does not create a menu. Clients can set the // properties of the object and the menu will be created upon the first call to @@ -40,12 +36,8 @@ class MenuModel; - (id)init; // Builds a NSMenu from the pre-built model (must not be nil). Changes made -// to the contents of the model after calling this will not be noticed. If -// the menu will be displayed by a NSPopUpButtonCell, it needs to be of a -// slightly different form (0th item is empty). Note this attribute of the menu -// cannot be changed after it has been created. -- (id)initWithModel:(ui::MenuModel*)model - useWithPopUpButtonCell:(BOOL)useWithCell; +// to the contents of the model after calling this will not be noticed. +- (id)initWithModel:(ui::MenuModel*)model; // Programmatically close the constructed menu. - (void)cancel; @@ -75,10 +67,6 @@ class MenuModel; atIndex:(NSInteger)index fromModel:(ui::MenuModel*)model; - (NSMenu*)menuFromModel:(ui::MenuModel*)model; -// Returns the maximum width for the menu item. Returns -1 to indicate -// that there's no maximum width. -- (int)maxWidthForMenuModel:(ui::MenuModel*)model - modelIndex:(int)modelIndex; @end #endif // ATOM_BROWSER_UI_ATOM_MENU_CONTROLLER_MAC_H_ diff --git a/browser/ui/atom_menu_controller_mac.mm b/browser/ui/atom_menu_controller_mac.mm index ae352a5967b..ea4a0d9358c 100644 --- a/browser/ui/atom_menu_controller_mac.mm +++ b/browser/ui/atom_menu_controller_mac.mm @@ -68,18 +68,15 @@ int EventFlagsFromNSEvent(NSEvent* event) { @implementation AtomMenuController @synthesize model = model_; -@synthesize useWithPopUpButtonCell = useWithPopUpButtonCell_; - (id)init { self = [super init]; return self; } -- (id)initWithModel:(ui::MenuModel*)model - useWithPopUpButtonCell:(BOOL)useWithCell { +- (id)initWithModel:(ui::MenuModel*)model { if ((self = [super init])) { model_ = model; - useWithPopUpButtonCell_ = useWithCell; [self menu]; } return self; @@ -120,11 +117,6 @@ int EventFlagsFromNSEvent(NSEvent* event) { return menu; } -- (int)maxWidthForMenuModel:(ui::MenuModel*)model - modelIndex:(int)modelIndex { - return -1; -} - // Adds a separator item at the given index. As the separator doesn't need // anything from the model, this method doesn't need the model index as the // other method below does. @@ -241,15 +233,6 @@ int EventFlagsFromNSEvent(NSEvent* event) { if (!menu_ && model_) { menu_.reset([[self menuFromModel:model_] retain]); [menu_ setDelegate:self]; - // If this is to be used with a NSPopUpButtonCell, add an item at the 0th - // position that's empty. Doing it after the menu has been constructed won't - // complicate creation logic, and since the tags are model indexes, they - // are unaffected by the extra item. - if (useWithPopUpButtonCell_) { - scoped_nsobject blankItem( - [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]); - [menu_ insertItem:blankItem atIndex:0]; - } } return menu_.get(); }