diff --git a/atom/browser/ui/tray_icon.cc b/atom/browser/ui/tray_icon.cc index de9a16143b4d..538f259dbb1d 100644 --- a/atom/browser/ui/tray_icon.cc +++ b/atom/browser/ui/tray_icon.cc @@ -18,6 +18,11 @@ void TrayIcon::SetTitle(const std::string& title) { void TrayIcon::SetHighlightMode(bool highlight) { } +void TrayIcon::DisplayBalloon(const gfx::ImageSkia& icon, + const base::string16& title, + const base::string16& contents) { +} + void TrayIcon::NotifyClicked() { FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnClicked()); } diff --git a/atom/browser/ui/tray_icon.h b/atom/browser/ui/tray_icon.h index 8fe3160ee939..0aa28ad07646 100644 --- a/atom/browser/ui/tray_icon.h +++ b/atom/browser/ui/tray_icon.h @@ -39,6 +39,12 @@ class TrayIcon { // works on OS X. virtual void SetHighlightMode(bool highlight); + // Displays a notification balloon with the specified contents. + // Depending on the platform it might not appear by the icon tray. + virtual void DisplayBalloon(const gfx::ImageSkia& icon, + const base::string16& title, + const base::string16& contents); + // Set the context menu for this icon. virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) = 0; diff --git a/atom/browser/ui/win/notify_icon.cc b/atom/browser/ui/win/notify_icon.cc index 7be52db42cf4..dc22773688be 100644 --- a/atom/browser/ui/win/notify_icon.cc +++ b/atom/browser/ui/win/notify_icon.cc @@ -118,6 +118,35 @@ void NotifyIcon::SetToolTip(const std::string& tool_tip) { LOG(WARNING) << "Unable to set tooltip for status tray icon"; } +void NotifyIcon::DisplayBalloon(const gfx::ImageSkia& icon, + const base::string16& title, + const base::string16& contents) { + NOTIFYICONDATA icon_data; + InitIconData(&icon_data); + icon_data.uFlags = NIF_INFO; + icon_data.dwInfoFlags = NIIF_INFO; + wcscpy_s(icon_data.szInfoTitle, title.c_str()); + wcscpy_s(icon_data.szInfo, contents.c_str()); + icon_data.uTimeout = 0; + + base::win::Version win_version = base::win::GetVersion(); + if (!icon.isNull() && win_version != base::win::VERSION_PRE_XP) { + balloon_icon_.Set(IconUtil::CreateHICONFromSkBitmap(*icon.bitmap())); + if (win_version >= base::win::VERSION_VISTA) { + icon_data.hBalloonIcon = balloon_icon_.Get(); + icon_data.dwInfoFlags = NIIF_USER | NIIF_LARGE_ICON; + } else { + icon_data.hIcon = balloon_icon_.Get(); + icon_data.uFlags |= NIF_ICON; + icon_data.dwInfoFlags = NIIF_USER; + } + } + + BOOL result = Shell_NotifyIcon(NIM_MODIFY, &icon_data); + if (!result) + LOG(WARNING) << "Unable to create status tray balloon."; +} + void NotifyIcon::SetContextMenu(ui::SimpleMenuModel* menu_model) { menu_model_ = menu_model; } diff --git a/atom/browser/ui/win/notify_icon.h b/atom/browser/ui/win/notify_icon.h index 5f55c57b5054..2ac309d5dbaf 100644 --- a/atom/browser/ui/win/notify_icon.h +++ b/atom/browser/ui/win/notify_icon.h @@ -46,6 +46,9 @@ class NotifyIcon : public TrayIcon { void SetImage(const gfx::ImageSkia& image) override; void SetPressedImage(const gfx::ImageSkia& image) override; void SetToolTip(const std::string& tool_tip) override; + void DisplayBalloon(const gfx::ImageSkia& icon, + const base::string16& title, + const base::string16& contents) override; void SetContextMenu(ui::SimpleMenuModel* menu_model) override; private: @@ -66,6 +69,9 @@ class NotifyIcon : public TrayIcon { // The currently-displayed icon for the window. base::win::ScopedHICON icon_; + // The currently-displayed icon for the notification balloon. + base::win::ScopedHICON balloon_icon_; + // The context menu. ui::SimpleMenuModel* menu_model_;