diff --git a/docs/api/tray.md b/docs/api/tray.md index bc34738f3e..487dcc025c 100644 --- a/docs/api/tray.md +++ b/docs/api/tray.md @@ -111,6 +111,15 @@ Returns: Emitted when the tray icon is double clicked. +#### Event: 'middle-click' _Windows_ + +Returns: + +* `event` [KeyboardEvent](structures/keyboard-event.md) +* `bounds` [Rectangle](structures/rectangle.md) - The bounds of tray icon. + +Emitted when the tray icon is middle clicked. + #### Event: 'balloon-show' _Windows_ Emitted when the tray balloon shows. diff --git a/shell/browser/api/electron_api_tray.cc b/shell/browser/api/electron_api_tray.cc index 8b729fb00e..309c677778 100644 --- a/shell/browser/api/electron_api_tray.cc +++ b/shell/browser/api/electron_api_tray.cc @@ -102,6 +102,12 @@ void Tray::OnRightClicked(const gfx::Rect& bounds, int modifiers) { EmitWithoutEvent("right-click", CreateEventFromFlags(modifiers), bounds); } +void Tray::OnMiddleClicked(const gfx::Rect& bounds, int modifiers) { + v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); + v8::HandleScope scope(isolate); + EmitWithoutEvent("middle-click", CreateEventFromFlags(modifiers), bounds); +} + void Tray::OnBalloonShow() { Emit("balloon-show"); } diff --git a/shell/browser/api/electron_api_tray.h b/shell/browser/api/electron_api_tray.h index c7a3f75821..5b6b1b5752 100644 --- a/shell/browser/api/electron_api_tray.h +++ b/shell/browser/api/electron_api_tray.h @@ -69,6 +69,7 @@ class Tray : public gin::Wrappable, int modifiers) override; void OnDoubleClicked(const gfx::Rect& bounds, int modifiers) override; void OnRightClicked(const gfx::Rect& bounds, int modifiers) override; + void OnMiddleClicked(const gfx::Rect& bounds, int modifiers) override; void OnBalloonShow() override; void OnBalloonClicked() override; void OnBalloonClosed() override; diff --git a/shell/browser/ui/tray_icon.cc b/shell/browser/ui/tray_icon.cc index 7f22f3b6da..5870ca6410 100644 --- a/shell/browser/ui/tray_icon.cc +++ b/shell/browser/ui/tray_icon.cc @@ -41,6 +41,11 @@ void TrayIcon::NotifyDoubleClicked(const gfx::Rect& bounds, int modifiers) { observer.OnDoubleClicked(bounds, modifiers); } +void TrayIcon::NotifyMiddleClicked(const gfx::Rect& bounds, int modifiers) { + for (TrayIconObserver& observer : observers_) + observer.OnMiddleClicked(bounds, modifiers); +} + void TrayIcon::NotifyBalloonShow() { for (TrayIconObserver& observer : observers_) observer.OnBalloonShow(); diff --git a/shell/browser/ui/tray_icon.h b/shell/browser/ui/tray_icon.h index 85a66163b6..98ebe66480 100644 --- a/shell/browser/ui/tray_icon.h +++ b/shell/browser/ui/tray_icon.h @@ -106,6 +106,7 @@ class TrayIcon { const gfx::Point& location = gfx::Point(), int modifiers = 0); void NotifyDoubleClicked(const gfx::Rect& = gfx::Rect(), int modifiers = 0); + void NotifyMiddleClicked(const gfx::Rect& = gfx::Rect(), int modifiers = 0); void NotifyBalloonShow(); void NotifyBalloonClicked(); void NotifyBalloonClosed(); diff --git a/shell/browser/ui/tray_icon_observer.h b/shell/browser/ui/tray_icon_observer.h index 10c86bcd02..6412d234f8 100644 --- a/shell/browser/ui/tray_icon_observer.h +++ b/shell/browser/ui/tray_icon_observer.h @@ -23,6 +23,7 @@ class TrayIconObserver : public base::CheckedObserver { const gfx::Point& location, int modifiers) {} virtual void OnDoubleClicked(const gfx::Rect& bounds, int modifiers) {} + virtual void OnMiddleClicked(const gfx::Rect& bounds, int modifiers) {} virtual void OnBalloonShow() {} virtual void OnBalloonClicked() {} virtual void OnBalloonClosed() {} diff --git a/shell/browser/ui/win/notify_icon.cc b/shell/browser/ui/win/notify_icon.cc index 195589f877..71a937a937 100644 --- a/shell/browser/ui/win/notify_icon.cc +++ b/shell/browser/ui/win/notify_icon.cc @@ -73,7 +73,8 @@ NotifyIcon::~NotifyIcon() { void NotifyIcon::HandleClickEvent(int modifiers, bool left_mouse_click, - bool double_button_click) { + bool double_button_click, + bool middle_button_click) { gfx::Rect bounds = GetBounds(); if (left_mouse_click) { @@ -84,6 +85,8 @@ void NotifyIcon::HandleClickEvent(int modifiers, display::Screen::GetScreen()->GetCursorScreenPoint(), modifiers); return; + } else if (middle_button_click) { // single middle click + NotifyMiddleClicked(bounds, modifiers); } else if (!double_button_click) { // single right click if (menu_model_) PopUpContextMenu(gfx::Point(), menu_model_->GetWeakPtr()); diff --git a/shell/browser/ui/win/notify_icon.h b/shell/browser/ui/win/notify_icon.h index ee45864292..fa3a3f3902 100644 --- a/shell/browser/ui/win/notify_icon.h +++ b/shell/browser/ui/win/notify_icon.h @@ -45,7 +45,8 @@ class NotifyIcon : public TrayIcon { // otherwise displays the context menu if there is one. void HandleClickEvent(int modifiers, bool left_button_click, - bool double_button_click); + bool double_button_click, + bool middle_button_click); // Handles a mouse move event from the user. void HandleMouseMoveEvent(int modifiers); diff --git a/shell/browser/ui/win/notify_icon_host.cc b/shell/browser/ui/win/notify_icon_host.cc index dc522708c1..bcd9ce662b 100644 --- a/shell/browser/ui/win/notify_icon_host.cc +++ b/shell/browser/ui/win/notify_icon_host.cc @@ -189,8 +189,10 @@ LRESULT CALLBACK NotifyIconHost::WndProc(HWND hwnd, case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: + case WM_MBUTTONDOWN: case WM_LBUTTONDBLCLK: case WM_RBUTTONDBLCLK: + case WM_MBUTTONDBLCLK: case WM_CONTEXTMENU: // Walk our icons, find which one was clicked on, and invoke its // HandleClickEvent() method. @@ -200,7 +202,8 @@ LRESULT CALLBACK NotifyIconHost::WndProc(HWND hwnd, &NotifyIcon::HandleClickEvent, win_icon_weak, GetKeyboardModifiers(), (lparam == WM_LBUTTONDOWN || lparam == WM_LBUTTONDBLCLK), - (lparam == WM_LBUTTONDBLCLK || lparam == WM_RBUTTONDBLCLK))); + (lparam == WM_LBUTTONDBLCLK || lparam == WM_RBUTTONDBLCLK), + (lparam == WM_MBUTTONDOWN || lparam == WM_MBUTTONDBLCLK))); return TRUE;