feat: add tray.focus() (#19548)

This commit is contained in:
Milan Burda 2019-08-09 16:43:48 +02:00 committed by Shelley Vohr
parent ed3b69ffb1
commit 03debb4ef9
7 changed files with 28 additions and 0 deletions

View file

@ -240,6 +240,13 @@ Displays a tray balloon.
Removes a tray balloon. Removes 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_ #### `tray.popUpContextMenu([menu, position])` _macOS_ _Windows_
* `menu` Menu (optional) * `menu` Menu (optional)

View file

@ -221,6 +221,10 @@ void Tray::RemoveBalloon() {
tray_icon_->RemoveBalloon(); tray_icon_->RemoveBalloon();
} }
void Tray::Focus() {
tray_icon_->Focus();
}
void Tray::PopUpContextMenu(mate::Arguments* args) { void Tray::PopUpContextMenu(mate::Arguments* args) {
mate::Handle<Menu> menu; mate::Handle<Menu> menu;
args->GetNext(&menu); args->GetNext(&menu);
@ -255,6 +259,7 @@ void Tray::BuildPrototype(v8::Isolate* isolate,
&Tray::GetIgnoreDoubleClickEvents) &Tray::GetIgnoreDoubleClickEvents)
.SetMethod("displayBalloon", &Tray::DisplayBalloon) .SetMethod("displayBalloon", &Tray::DisplayBalloon)
.SetMethod("removeBalloon", &Tray::RemoveBalloon) .SetMethod("removeBalloon", &Tray::RemoveBalloon)
.SetMethod("focus", &Tray::Focus)
.SetMethod("popUpContextMenu", &Tray::PopUpContextMenu) .SetMethod("popUpContextMenu", &Tray::PopUpContextMenu)
.SetMethod("setContextMenu", &Tray::SetContextMenu) .SetMethod("setContextMenu", &Tray::SetContextMenu)
.SetMethod("getBounds", &Tray::GetBounds); .SetMethod("getBounds", &Tray::GetBounds);

View file

@ -74,6 +74,7 @@ class Tray : public mate::TrackableObject<Tray>, public TrayIconObserver {
bool GetIgnoreDoubleClickEvents(); bool GetIgnoreDoubleClickEvents();
void DisplayBalloon(mate::Arguments* args, const mate::Dictionary& options); void DisplayBalloon(mate::Arguments* args, const mate::Dictionary& options);
void RemoveBalloon(); void RemoveBalloon();
void Focus();
void PopUpContextMenu(mate::Arguments* args); void PopUpContextMenu(mate::Arguments* args);
void SetContextMenu(v8::Isolate* isolate, mate::Handle<Menu> menu); void SetContextMenu(v8::Isolate* isolate, mate::Handle<Menu> menu);
gfx::Rect GetBounds(); gfx::Rect GetBounds();

View file

@ -18,6 +18,8 @@ void TrayIcon::DisplayBalloon(const BalloonOptions& options) {}
void TrayIcon::RemoveBalloon() {} void TrayIcon::RemoveBalloon() {}
void TrayIcon::Focus() {}
void TrayIcon::PopUpContextMenu(const gfx::Point& pos, void TrayIcon::PopUpContextMenu(const gfx::Point& pos,
AtomMenuModel* menu_model) {} AtomMenuModel* menu_model) {}

View file

@ -74,6 +74,9 @@ class TrayIcon {
// Removes the notification balloon. // Removes the notification balloon.
virtual void RemoveBalloon(); virtual void RemoveBalloon();
// Returns focus to the taskbar notification area.
virtual void Focus();
// Popups the menu. // Popups the menu.
virtual void PopUpContextMenu(const gfx::Point& pos, virtual void PopUpContextMenu(const gfx::Point& pos,
AtomMenuModel* menu_model); AtomMenuModel* menu_model);

View file

@ -176,6 +176,15 @@ void NotifyIcon::RemoveBalloon() {
LOG(WARNING) << "Unable to remove status tray balloon."; LOG(WARNING) << "Unable to remove status tray balloon.";
} }
void NotifyIcon::Focus() {
NOTIFYICONDATA icon_data;
InitIconData(&icon_data);
BOOL result = Shell_NotifyIcon(NIM_SETFOCUS, &icon_data);
if (!result)
LOG(WARNING) << "Unable to focus tray icon.";
}
void NotifyIcon::PopUpContextMenu(const gfx::Point& pos, void NotifyIcon::PopUpContextMenu(const gfx::Point& pos,
AtomMenuModel* menu_model) { AtomMenuModel* menu_model) {
// Returns if context menu isn't set. // Returns if context menu isn't set.

View file

@ -60,6 +60,7 @@ class NotifyIcon : public TrayIcon {
void SetToolTip(const std::string& tool_tip) override; void SetToolTip(const std::string& tool_tip) override;
void DisplayBalloon(const BalloonOptions& options) override; void DisplayBalloon(const BalloonOptions& options) override;
void RemoveBalloon() override; void RemoveBalloon() override;
void Focus() override;
void PopUpContextMenu(const gfx::Point& pos, void PopUpContextMenu(const gfx::Point& pos,
AtomMenuModel* menu_model) override; AtomMenuModel* menu_model) override;
void SetContextMenu(AtomMenuModel* menu_model) override; void SetContextMenu(AtomMenuModel* menu_model) override;