]> khamidou — GitHub mirrors - electron.git/commitdiff
Implement 'tray.popContextMenu' API on OS X.
authorHaojian Wu <hokein.wu@gmail.com>
Thu, 16 Jul 2015 02:50:53 +0000 (10:50 +0800)
committerHaojian Wu <hokein.wu@gmail.com>
Thu, 16 Jul 2015 02:50:53 +0000 (10:50 +0800)
atom/browser/api/atom_api_tray.cc
atom/browser/api/atom_api_tray.h
atom/browser/ui/tray_icon.cc
atom/browser/ui/tray_icon.h
atom/browser/ui/tray_icon_cocoa.h
atom/browser/ui/tray_icon_cocoa.mm

index 7c1bfdfac95a0d885ec01467e3f377de87e46184..6fd9599d32bcc958e7dfad191c4ac51afeb84ab6 100644 (file)
@@ -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);
 }
 
index 366a847ac602c20fe33273d407930a82e096d14a..e7df28548c17a6d8a2b928cd9826e6e256598d22 100644 (file)
@@ -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:
index 4f801faf862ead2ecbfe4b55d20e6b88a534802f..7f67a02160a6b9e5dee3aafe4249042f37a9b6f0 100644 (file)
@@ -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));
 }
index 4e097e0ac84aa1cfb9e8a4b7f5634d66bec653c3..e57d751b07137aac6baad03e9c0bb2bd794eed5d 100644 (file)
@@ -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;
 
index d4cfd431e466fecd1d996697b15209216e374845..eb80250f6fc0bd2fea81731f6b7c5f89da093eca 100644 (file)
@@ -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:
index 514631c21065d7ff2251cef7e8012c71ae5893e3..f751f131b4e2ad7c8b0a2ac9bda801a8a0221d51 100644 (file)
@@ -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()];