]> khamidou — GitHub mirrors - electron.git/commitdiff
Win: Implement context menu for tray icon.
authorCheng Zhao <zcbenz@gmail.com>
Tue, 3 Jun 2014 03:52:57 +0000 (11:52 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 3 Jun 2014 03:52:57 +0000 (11:52 +0800)
atom/browser/ui/win/notify_icon.cc
atom/browser/ui/win/notify_icon.h

index b44791fe90a63346ab254025f528da2f2428065c..86ce15d698ee5fdeba230389dc1e15c252eabba6 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "atom/browser/ui/win/notify_icon.h"
 
+#include "atom/browser/ui/win/menu_2.h"
 #include "atom/browser/ui/win/notify_icon_host.h"
 #include "base/strings/string_number_conversions.h"
 #include "base/strings/utf_string_conversions.h"
@@ -22,7 +23,8 @@ NotifyIcon::NotifyIcon(NotifyIconHost* host,
     : host_(host),
       icon_id_(id),
       window_(window),
-      message_id_(message) {
+      message_id_(message),
+      menu_model_(NULL) {
   NOTIFYICONDATA icon_data;
   InitIconData(&icon_data);
   icon_data.uFlags = NIF_MESSAGE;
@@ -50,7 +52,6 @@ void NotifyIcon::HandleClickEvent(const gfx::Point& cursor_pos,
     return;
   }
 
-  /*
   if (!menu_model_)
     return;
 
@@ -59,15 +60,8 @@ void NotifyIcon::HandleClickEvent(const gfx::Point& cursor_pos,
   if (!SetForegroundWindow(window_))
     return;
 
-  menu_runner_.reset(new views::MenuRunner(menu_model_));
-
-  ignore_result(menu_runner_->RunMenuAt(NULL,
-                                        NULL,
-                                        gfx::Rect(cursor_pos, gfx::Size()),
-                                        views::MENU_ANCHOR_TOPLEFT,
-                                        ui::MENU_SOURCE_MOUSE,
-                                        views::MenuRunner::HAS_MNEMONICS));
-                                        */
+  scoped_ptr<Menu2> menu(new Menu2(menu_model_));
+  menu->RunContextMenuAt(cursor_pos);
 }
 
 void NotifyIcon::ResetIcon() {
@@ -120,6 +114,7 @@ void NotifyIcon::SetToolTip(const std::string& tool_tip) {
 }
 
 void NotifyIcon::SetContextMenu(ui::SimpleMenuModel* menu_model) {
+  menu_model_ = menu_model;
 }
 
 void NotifyIcon::InitIconData(NOTIFYICONDATA* icon_data) {
index 850b3961b47d5b11133ea3e010dd2edf6ddafadf..d76960ad4925dbed6478264608d9a868a986279b 100644 (file)
@@ -66,6 +66,9 @@ class NotifyIcon : public TrayIcon {
   // The currently-displayed icon for the window.
   base::win::ScopedHICON icon_;
 
+  // The context menu.
+  ui::SimpleMenuModel* menu_model_;
+
   DISALLOW_COPY_AND_ASSIGN(NotifyIcon);
 };