]> khamidou — GitHub mirrors - electron.git/commitdiff
Add 'tray.popContextMenu()' Windows implementation.
authorHaojian Wu <hokein.wu@gmail.com>
Thu, 16 Jul 2015 03:39:49 +0000 (11:39 +0800)
committerHaojian Wu <hokein.wu@gmail.com>
Thu, 16 Jul 2015 03:42:43 +0000 (11:42 +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/win/notify_icon.cc
atom/browser/ui/win/notify_icon.h

index 6fd9599d32bcc958e7dfad191c4ac51afeb84ab6..bf3a521d76e7c456d71d1b4d9b778286c5e4fe74 100644 (file)
@@ -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) {
index e7df28548c17a6d8a2b928cd9826e6e256598d22..5b40937d717a2f3b85e329239cb2e3466352f8b4 100644 (file)
@@ -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:
index 7f67a02160a6b9e5dee3aafe4249042f37a9b6f0..ab1ebfa67790679a05b543ea7052544d26b863f1 100644 (file)
@@ -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) {
index e57d751b07137aac6baad03e9c0bb2bd794eed5d..a9e9b414ec94673e9d04a834fbedc6d0dadcf650 100644 (file)
@@ -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;
index 64329a63e5e44750b66156684d55e4d6877ee8e8..bc9ff46f939ad74415f4787172e284a861ba2969 100644 (file)
@@ -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;
 }
index 12eea1fcf7251bfeb5a473930e38af7d62472691..8e00f12679207d1acbe34e515610127d343ab3d7 100644 (file)
@@ -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: