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();
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.
@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
- (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;
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_
@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;
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.
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();
}