Implement 'tray.popContextMenu' API on OS X.
This commit is contained in:
parent
002eb1a326
commit
4421fbf9f3
6 changed files with 27 additions and 0 deletions
|
@ -106,6 +106,10 @@ void Tray::DisplayBalloon(mate::Arguments* args,
|
|||
tray_icon_->DisplayBalloon(icon, title, content);
|
||||
}
|
||||
|
||||
void Tray::PopContextMenu() {
|
||||
tray_icon_->PopContextMenu();
|
||||
}
|
||||
|
||||
void Tray::SetContextMenu(mate::Arguments* args, Menu* menu) {
|
||||
tray_icon_->SetContextMenu(menu->model());
|
||||
}
|
||||
|
@ -121,6 +125,7 @@ void Tray::BuildPrototype(v8::Isolate* isolate,
|
|||
.SetMethod("setTitle", &Tray::SetTitle)
|
||||
.SetMethod("setHighlightMode", &Tray::SetHighlightMode)
|
||||
.SetMethod("displayBalloon", &Tray::DisplayBalloon)
|
||||
.SetMethod("popContextMenu", &Tray::PopContextMenu)
|
||||
.SetMethod("_setContextMenu", &Tray::SetContextMenu);
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ class Tray : public mate::EventEmitter,
|
|||
void SetTitle(mate::Arguments* args, const std::string& title);
|
||||
void SetHighlightMode(mate::Arguments* args, bool highlight);
|
||||
void DisplayBalloon(mate::Arguments* args, const mate::Dictionary& options);
|
||||
void PopContextMenu();
|
||||
void SetContextMenu(mate::Arguments* args, Menu* menu);
|
||||
|
||||
private:
|
||||
|
|
|
@ -26,6 +26,9 @@ void TrayIcon::DisplayBalloon(const gfx::Image& icon,
|
|||
const base::string16& contents) {
|
||||
}
|
||||
|
||||
void TrayIcon::PopContextMenu() {
|
||||
}
|
||||
|
||||
void TrayIcon::NotifyClicked(const gfx::Rect& bounds) {
|
||||
FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnClicked(bounds));
|
||||
}
|
||||
|
|
|
@ -46,6 +46,8 @@ class TrayIcon {
|
|||
const base::string16& title,
|
||||
const base::string16& contents);
|
||||
|
||||
virtual void PopContextMenu();
|
||||
|
||||
// Set the context menu for this icon.
|
||||
virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) = 0;
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ class TrayIconCocoa : public TrayIcon {
|
|||
void SetToolTip(const std::string& tool_tip) override;
|
||||
void SetTitle(const std::string& title) override;
|
||||
void SetHighlightMode(bool highlight) override;
|
||||
void PopContextMenu() override;
|
||||
void SetContextMenu(ui::SimpleMenuModel* menu_model) override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -153,6 +153,17 @@ const CGFloat kMargin = 3;
|
|||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
- (void)popContextMenu {
|
||||
if (menuController_ && ![menuController_ isMenuOpen]) {
|
||||
// redraw the dray icon to show highlight if it is enabled.
|
||||
[self setNeedsDisplay:YES];
|
||||
[statusItem_ popUpStatusItemMenu:[menuController_ menu]];
|
||||
// The popUpStatusItemMenu returns only after the showing menu is closed.
|
||||
// When it returns, we need to redraw the tray icon to not show highlight.
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)rightMouseUp:(NSEvent*)event {
|
||||
trayIcon_->NotifyRightClicked([self getBoundsFromEvent:event]);
|
||||
}
|
||||
|
@ -201,6 +212,10 @@ void TrayIconCocoa::SetHighlightMode(bool highlight) {
|
|||
[status_item_view_ setHighlight:highlight];
|
||||
}
|
||||
|
||||
void TrayIconCocoa::PopContextMenu() {
|
||||
[status_item_view_ popContextMenu];
|
||||
}
|
||||
|
||||
void TrayIconCocoa::SetContextMenu(ui::SimpleMenuModel* menu_model) {
|
||||
menu_.reset([[AtomMenuController alloc] initWithModel:menu_model]);
|
||||
[status_item_view_ setMenuController:menu_.get()];
|
||||
|
|
Loading…
Reference in a new issue