Browse Source

win: Pass modifers in 'clicked' events

Cheng Zhao 9 years ago
parent
commit
d42fd6fc7e

+ 4 - 3
atom/browser/ui/win/notify_icon.cc

@@ -63,6 +63,7 @@ NotifyIcon::~NotifyIcon() {
 }
 
 void NotifyIcon::HandleClickEvent(const gfx::Point& cursor_pos,
+                                  int modifiers,
                                   bool left_mouse_click,
                                   bool double_button_click) {
   NOTIFYICONIDENTIFIER icon_id;
@@ -80,12 +81,12 @@ void NotifyIcon::HandleClickEvent(const gfx::Point& cursor_pos,
 
   if (left_mouse_click) {
     if (double_button_click)  // double left click
-      NotifyDoubleClicked(gfx::Rect(rect));
+      NotifyDoubleClicked(gfx::Rect(rect), modifiers);
     else  // single left click
-      NotifyClicked(gfx::Rect(rect));
+      NotifyClicked(gfx::Rect(rect), modifiers);
     return;
   } else if (!double_button_click) {  // single right click
-    NotifyRightClicked(gfx::Rect(rect));
+    NotifyRightClicked(gfx::Rect(rect), modifiers);
     PopContextMenu(cursor_pos);
   }
 }

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

@@ -34,6 +34,7 @@ class NotifyIcon : public TrayIcon {
   // there is a registered observer, passes the click event to the observer,
   // otherwise displays the context menu if there is one.
   void HandleClickEvent(const gfx::Point& cursor_pos,
+                        int modifiers,
                         bool left_button_click,
                         bool double_button_click);
 

+ 14 - 0
atom/browser/ui/win/notify_icon_host.cc

@@ -11,7 +11,9 @@
 #include "base/stl_util.h"
 #include "base/threading/non_thread_safe.h"
 #include "base/threading/thread.h"
+#include "base/win/win_util.h"
 #include "base/win/wrapped_window_proc.h"
+#include "ui/events/event_constants.h"
 #include "ui/gfx/screen.h"
 #include "ui/gfx/win/hwnd_util.h"
 
@@ -26,6 +28,17 @@ const UINT kBaseIconId = 2;
 
 const wchar_t kNotifyIconHostWindowClass[] = L"Electron_NotifyIconHostWindow";
 
+int GetKeyboardModifers() {
+  int modifiers = ui::EF_NONE;
+  if (base::win::IsShiftPressed())
+    modifiers |= ui::EF_SHIFT_DOWN;
+  if (base::win::IsCtrlPressed())
+    modifiers |= ui::EF_CONTROL_DOWN;
+  if (base::win::IsAltPressed())
+    modifiers |= ui::EF_ALT_DOWN;
+  return modifiers;
+}
+
 }  // namespace
 
 NotifyIconHost::NotifyIconHost()
@@ -155,6 +168,7 @@ LRESULT CALLBACK NotifyIconHost::WndProc(HWND hwnd,
             gfx::Screen::GetNativeScreen()->GetCursorScreenPoint());
         win_icon->HandleClickEvent(
             cursor_pos,
+            GetKeyboardModifers(),
             (lparam == WM_LBUTTONDOWN || lparam == WM_LBUTTONDBLCLK),
             (lparam == WM_LBUTTONDBLCLK || lparam == WM_RBUTTONDBLCLK));
         return TRUE;