Browse Source

Add 'tray.popContextMenu()' Windows implementation.

Haojian Wu 9 years ago
parent
commit
ed4c69343f

+ 4 - 2
atom/browser/api/atom_api_tray.cc

@@ -106,8 +106,10 @@ void Tray::DisplayBalloon(mate::Arguments* args,
   tray_icon_->DisplayBalloon(icon, title, content);
 }
 
-void Tray::PopContextMenu() {
-  tray_icon_->PopContextMenu();
+void Tray::PopContextMenu(mate::Arguments* args) {
+  gfx::Point pos;
+  args->GetNext(&pos);
+  tray_icon_->PopContextMenu(pos);
 }
 
 void Tray::SetContextMenu(mate::Arguments* args, Menu* menu) {

+ 1 - 1
atom/browser/api/atom_api_tray.h

@@ -58,7 +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 PopContextMenu(mate::Arguments* args);
   void SetContextMenu(mate::Arguments* args, Menu* menu);
 
  private:

+ 1 - 1
atom/browser/ui/tray_icon.cc

@@ -26,7 +26,7 @@ void TrayIcon::DisplayBalloon(const gfx::Image& icon,
                               const base::string16& contents) {
 }
 
-void TrayIcon::PopContextMenu() {
+void TrayIcon::PopContextMenu(const gfx::Point& pos) {
 }
 
 void TrayIcon::NotifyClicked(const gfx::Rect& bounds) {

+ 1 - 1
atom/browser/ui/tray_icon.h

@@ -46,7 +46,7 @@ class TrayIcon {
                               const base::string16& title,
                               const base::string16& contents);
 
-  virtual void PopContextMenu();
+  virtual void PopContextMenu(const gfx::Point& pos);
 
   // Set the context menu for this icon.
   virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) = 0;

+ 18 - 18
atom/browser/ui/win/notify_icon.cc

@@ -62,24 +62,7 @@ void NotifyIcon::HandleClickEvent(const gfx::Point& cursor_pos,
   }
 
   NotifyRightClicked(gfx::Rect(rect));
-
-  if (!menu_model_)
-    return;
-
-  // Set our window as the foreground window, so the context menu closes when
-  // we click away from it.
-  if (!SetForegroundWindow(window_))
-    return;
-
-  views::MenuRunner menu_runner(
-      menu_model_,
-      views::MenuRunner::CONTEXT_MENU | views::MenuRunner::HAS_MNEMONICS);
-  ignore_result(menu_runner.RunMenuAt(
-      NULL,
-      NULL,
-      gfx::Rect(cursor_pos, gfx::Size()),
-      views::MENU_ANCHOR_TOPLEFT,
-      ui::MENU_SOURCE_MOUSE));
+  PopContextMenu(cursor_pos);
 }
 
 void NotifyIcon::ResetIcon() {
@@ -152,6 +135,23 @@ void NotifyIcon::DisplayBalloon(const gfx::Image& icon,
     LOG(WARNING) << "Unable to create status tray balloon.";
 }
 
+void NotifyIcon::PopContextMenu(const gfx::Point& pos) {
+  // Set our window as the foreground window, so the context menu closes when
+  // we click away from it.
+  if (!SetForegroundWindow(window_))
+    return;
+
+  views::MenuRunner menu_runner(
+      menu_model_,
+      views::MenuRunner::CONTEXT_MENU | views::MenuRunner::HAS_MNEMONICS);
+  ignore_result(menu_runner.RunMenuAt(
+      NULL,
+      NULL,
+      gfx::Rect(pos, gfx::Size()),
+      views::MENU_ANCHOR_TOPLEFT,
+      ui::MENU_SOURCE_MOUSE));
+}
+
 void NotifyIcon::SetContextMenu(ui::SimpleMenuModel* menu_model) {
   menu_model_ = menu_model;
 }

+ 1 - 0
atom/browser/ui/win/notify_icon.h

@@ -49,6 +49,7 @@ class NotifyIcon : public TrayIcon {
   void DisplayBalloon(const gfx::Image& icon,
                       const base::string16& title,
                       const base::string16& contents) override;
+  void PopContextMenu(const gfx::Point& pos) override;
   void SetContextMenu(ui::SimpleMenuModel* menu_model) override;
 
  private: