win: Add NotifyIcon::DisplayBalloon

This commit is contained in:
Cheng Zhao 2014-11-28 18:30:43 +08:00
parent 9f0b5a14a4
commit 2650e34867
4 changed files with 46 additions and 0 deletions

View file

@ -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());
}

View file

@ -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;

View file

@ -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;
}

View file

@ -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_;