}
void Tray::PopUpContextMenu(mate::Arguments* args) {
- Menu* menu = nullptr;
+ mate::Handle<Menu> menu;
args->GetNext(&menu);
gfx::Point pos;
args->GetNext(&pos);
- tray_icon_->PopUpContextMenu(pos, menu ? menu->model() : nullptr);
+ tray_icon_->PopUpContextMenu(pos, menu.IsEmpty() ? nullptr : menu->model());
}
void Tray::SetContextMenu(mate::Arguments* args, Menu* menu) {
atom::TrayIconCocoa* trayIcon_; // weak
AtomMenuController* menuController_; // weak
BOOL isHighlightEnable_;
+ BOOL forceHighlight_;
BOOL inMouseEventSequence_;
base::scoped_nsobject<NSImage> image_;
base::scoped_nsobject<NSImage> alternateImage_;
image_.reset([image copy]);
trayIcon_ = icon;
isHighlightEnable_ = YES;
+ forceHighlight_ = NO;
+ inMouseEventSequence_ = NO;
if ((self = [super initWithFrame: CGRectZero])) {
// Setup the image view.
[self setNeedsDisplay:YES];
}
-- (void)popUpContextMenu {
+- (void)popUpContextMenu:(ui::SimpleMenuModel*)menu_model {
+ // Show a custom menu.
+ if (menu_model) {
+ base::scoped_nsobject<AtomMenuController> menuController(
+ [[AtomMenuController alloc] initWithModel:menu_model]);
+ forceHighlight_ = YES; // Should highlight when showing menu.
+ [self setNeedsDisplay:YES];
+ [statusItem_ popUpStatusItemMenu:[menuController menu]];
+ forceHighlight_ = NO;
+ [self setNeedsDisplay:YES];
+ return;
+ }
+
if (menuController_ && ![menuController_ isMenuOpen]) {
// Redraw the dray icon to show highlight if it is enabled.
[self setNeedsDisplay:YES];
}
- (BOOL)shouldHighlight {
+ if (isHighlightEnable_ && forceHighlight_)
+ return true;
BOOL isMenuOpen = menuController_ && [menuController_ isMenuOpen];
return isHighlightEnable_ && (inMouseEventSequence_ || isMenuOpen);
}
void TrayIconCocoa::PopUpContextMenu(const gfx::Point& pos,
ui::SimpleMenuModel* menu_model) {
- [status_item_view_ popUpContextMenu];
+ [status_item_view_ popUpContextMenu:menu_model];
}
void TrayIconCocoa::SetContextMenu(ui::SimpleMenuModel* menu_model) {