[Mac] Clean up the menu controller.
This commit is contained in:
parent
f908619630
commit
63b85bccab
3 changed files with 5 additions and 36 deletions
|
@ -24,8 +24,7 @@ MenuMac::~MenuMac() {
|
|||
|
||||
void MenuMac::Popup(NativeWindow* native_window) {
|
||||
scoped_nsobject<AtomMenuController> 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<v8::Value> Menu::SetApplicationMenu(const v8::Arguments &args) {
|
|||
return node::ThrowError("Menu is destroyed");
|
||||
|
||||
scoped_nsobject<AtomMenuController> 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.
|
||||
|
|
|
@ -25,14 +25,10 @@ class MenuModel;
|
|||
@protected
|
||||
ui::MenuModel* model_; // weak
|
||||
scoped_nsobject<NSMenu> 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_
|
||||
|
|
|
@ -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<NSMenuItem> blankItem(
|
||||
[[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]);
|
||||
[menu_ insertItem:blankItem atIndex:0];
|
||||
}
|
||||
}
|
||||
return menu_.get();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue