diff --git a/docs/api/tray.md b/docs/api/tray.md index 0411b9386798c..a8b370c240891 100644 --- a/docs/api/tray.md +++ b/docs/api/tray.md @@ -261,6 +261,10 @@ Returns `Boolean` - Whether double click events will be ignored. Displays a tray balloon. +#### `tray.focus()` _Windows_ + +Returns focus to the taskbar notification area. Notification area icons should use this message when they have completed their UI operation. For example, if the icon displays a shortcut menu, but the user presses ESC to cancel it, use `tray.focus()` to return focus to the notification area. + #### `tray.popUpContextMenu([menu, position])` _macOS_ _Windows_ * `menu` Menu (optional) diff --git a/shell/browser/api/atom_api_tray.cc b/shell/browser/api/atom_api_tray.cc index 9700440937643..6230d1ea06a56 100644 --- a/shell/browser/api/atom_api_tray.cc +++ b/shell/browser/api/atom_api_tray.cc @@ -207,6 +207,10 @@ void Tray::DisplayBalloon(mate::Arguments* args, #endif } +void Tray::Focus() { + tray_icon_->Focus(); +} + void Tray::PopUpContextMenu(mate::Arguments* args) { mate::Handle menu; args->GetNext(&menu); @@ -241,6 +245,7 @@ void Tray::BuildPrototype(v8::Isolate* isolate, .SetMethod("getIgnoreDoubleClickEvents", &Tray::GetIgnoreDoubleClickEvents) .SetMethod("displayBalloon", &Tray::DisplayBalloon) + .SetMethod("focus", &Tray::Focus) .SetMethod("popUpContextMenu", &Tray::PopUpContextMenu) .SetMethod("setContextMenu", &Tray::SetContextMenu) .SetMethod("getBounds", &Tray::GetBounds); diff --git a/shell/browser/api/atom_api_tray.h b/shell/browser/api/atom_api_tray.h index 4d9dc1255213f..d37a16b7a0c8a 100644 --- a/shell/browser/api/atom_api_tray.h +++ b/shell/browser/api/atom_api_tray.h @@ -74,6 +74,7 @@ class Tray : public mate::TrackableObject, public TrayIconObserver { void SetIgnoreDoubleClickEvents(bool ignore); bool GetIgnoreDoubleClickEvents(); void DisplayBalloon(mate::Arguments* args, const mate::Dictionary& options); + void Focus(); void PopUpContextMenu(mate::Arguments* args); void SetContextMenu(v8::Isolate* isolate, mate::Handle menu); gfx::Rect GetBounds(); diff --git a/shell/browser/ui/tray_icon.cc b/shell/browser/ui/tray_icon.cc index 555eb05ed621a..6345e0efb118a 100644 --- a/shell/browser/ui/tray_icon.cc +++ b/shell/browser/ui/tray_icon.cc @@ -18,6 +18,8 @@ void TrayIcon::DisplayBalloon(ImageType icon, const base::string16& title, const base::string16& contents) {} +void TrayIcon::Focus() {} + void TrayIcon::PopUpContextMenu(const gfx::Point& pos, AtomMenuModel* menu_model) {} diff --git a/shell/browser/ui/tray_icon.h b/shell/browser/ui/tray_icon.h index 8169180c60327..428ea2ed8c25b 100644 --- a/shell/browser/ui/tray_icon.h +++ b/shell/browser/ui/tray_icon.h @@ -63,6 +63,9 @@ class TrayIcon { const base::string16& title, const base::string16& contents); + // Returns focus to the taskbar notification area. + virtual void Focus(); + // Popups the menu. virtual void PopUpContextMenu(const gfx::Point& pos, AtomMenuModel* menu_model); diff --git a/shell/browser/ui/win/notify_icon.cc b/shell/browser/ui/win/notify_icon.cc index dd9d5f6891a75..8f45706200277 100644 --- a/shell/browser/ui/win/notify_icon.cc +++ b/shell/browser/ui/win/notify_icon.cc @@ -138,6 +138,13 @@ void NotifyIcon::DisplayBalloon(HICON icon, LOG(WARNING) << "Unable to create status tray balloon."; } +void NotifyIcon::Focus() { + NOTIFYICONDATA icon_data; + InitIconData(&icon_data); + + Shell_NotifyIcon(NIM_SETFOCUS, &icon_data); +} + void NotifyIcon::PopUpContextMenu(const gfx::Point& pos, AtomMenuModel* menu_model) { // Returns if context menu isn't set. diff --git a/shell/browser/ui/win/notify_icon.h b/shell/browser/ui/win/notify_icon.h index 6c71034f15e79..1aee032d2bc78 100644 --- a/shell/browser/ui/win/notify_icon.h +++ b/shell/browser/ui/win/notify_icon.h @@ -61,6 +61,7 @@ class NotifyIcon : public TrayIcon { void DisplayBalloon(HICON icon, const base::string16& title, const base::string16& contents) override; + void Focus(); void PopUpContextMenu(const gfx::Point& pos, AtomMenuModel* menu_model) override; void SetContextMenu(AtomMenuModel* menu_model) override;