From 3182485e6882e7ddd6d778e6da9c62f3157619ef Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 20 May 2016 22:28:07 +0900 Subject: [PATCH] No need to reference the icon in Tray --- atom/browser/api/atom_api_tray.cc | 2 -- atom/browser/api/atom_api_tray.h | 2 -- atom/browser/native_window_views.cc | 10 ++++++++++ atom/browser/native_window_views_win.cc | 8 -------- atom/browser/ui/win/notify_icon.cc | 6 +++--- atom/browser/ui/win/notify_icon.h | 3 ++- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/atom/browser/api/atom_api_tray.cc b/atom/browser/api/atom_api_tray.cc index 5de3b63..c84e8a1 100644 --- a/atom/browser/api/atom_api_tray.cc +++ b/atom/browser/api/atom_api_tray.cc @@ -97,7 +97,6 @@ void Tray::OnDragEnded() { } void Tray::SetImage(v8::Isolate* isolate, mate::Handle image) { - image_.Reset(isolate, image.ToV8()); #if defined(OS_WIN) tray_icon_->SetImage(image->GetHICON(GetSystemMetrics(SM_CXSMICON))); #else @@ -107,7 +106,6 @@ void Tray::SetImage(v8::Isolate* isolate, mate::Handle image) { void Tray::SetPressedImage(v8::Isolate* isolate, mate::Handle image) { - pressed_image_.Reset(isolate, image.ToV8()); #if defined(OS_WIN) tray_icon_->SetPressedImage(image->GetHICON(GetSystemMetrics(SM_CXSMICON))); #else diff --git a/atom/browser/api/atom_api_tray.h b/atom/browser/api/atom_api_tray.h index 312185a..3c3d02e 100644 --- a/atom/browser/api/atom_api_tray.h +++ b/atom/browser/api/atom_api_tray.h @@ -69,8 +69,6 @@ class Tray : public mate::TrackableObject, private: v8::Local ModifiersToObject(v8::Isolate* isolate, int modifiers); - v8::Global image_; - v8::Global pressed_image_; v8::Global menu_; scoped_ptr tray_icon_; diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 42da62c..82c1158 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -779,12 +779,22 @@ gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() { return GetNativeWindow()->GetHost()->GetAcceleratedWidget(); } +#if defined(OS_WIN) +void NativeWindowViews::SetIcon(HICON small_icon, HICON app_icon) { + HWND hwnd = GetAcceleratedWidget(); + SendMessage(hwnd, WM_SETICON, ICON_SMALL, + reinterpret_cast(small_icon)); + SendMessage(hwnd, WM_SETICON, ICON_BIG, + reinterpret_cast(app_icon)); +} +#elif defined(USE_X11) void NativeWindowViews::SetIcon(const gfx::ImageSkia& icon) { views::DesktopWindowTreeHostX11* tree_host = views::DesktopWindowTreeHostX11::GetHostForXID(GetAcceleratedWidget()); static_cast(tree_host)->SetWindowIcons( icon, icon); } +#endif void NativeWindowViews::OnWidgetActivationChanged( views::Widget* widget, bool active) { diff --git a/atom/browser/native_window_views_win.cc b/atom/browser/native_window_views_win.cc index 0cb6859..038ab10 100644 --- a/atom/browser/native_window_views_win.cc +++ b/atom/browser/native_window_views_win.cc @@ -73,14 +73,6 @@ const char* AppCommandToString(int command_id) { } // namespace -void NativeWindowViews::SetIcon(HICON small_icon, HICON app_icon) { - HWND hwnd = GetAcceleratedWidget(); - SendMessage(hwnd, WM_SETICON, ICON_SMALL, - reinterpret_cast(small_icon)); - SendMessage(hwnd, WM_SETICON, ICON_BIG, - reinterpret_cast(app_icon)); -} - bool NativeWindowViews::ExecuteWindowsCommand(int command_id) { std::string command = AppCommandToString(command_id); NotifyWindowExecuteWindowsCommand(command); diff --git a/atom/browser/ui/win/notify_icon.cc b/atom/browser/ui/win/notify_icon.cc index 98c967e..1cc6162 100644 --- a/atom/browser/ui/win/notify_icon.cc +++ b/atom/browser/ui/win/notify_icon.cc @@ -25,7 +25,6 @@ NotifyIcon::NotifyIcon(NotifyIconHost* host, icon_id_(id), window_(window), message_id_(message), - icon_(NULL), menu_model_(NULL) { NOTIFYICONDATA icon_data; InitIconData(&icon_data); @@ -80,7 +79,7 @@ void NotifyIcon::ResetIcon() { InitIconData(&icon_data); icon_data.uFlags |= NIF_MESSAGE; icon_data.uCallbackMessage = message_id_; - icon_data.hIcon = icon_; + icon_data.hIcon = icon_.get(); // If we have an image, then set the NIF_ICON flag, which tells // Shell_NotifyIcon() to set the image for the status icon it creates. if (icon_data.hIcon) @@ -92,8 +91,9 @@ void NotifyIcon::ResetIcon() { } void NotifyIcon::SetImage(HICON image) { + icon_ = base::win::ScopedHICON(CopyIcon(image)); + // Create the icon. - icon_ = image; NOTIFYICONDATA icon_data; InitIconData(&icon_data); icon_data.uFlags |= NIF_ICON; diff --git a/atom/browser/ui/win/notify_icon.h b/atom/browser/ui/win/notify_icon.h index 1c6f240..95e9945 100644 --- a/atom/browser/ui/win/notify_icon.h +++ b/atom/browser/ui/win/notify_icon.h @@ -14,6 +14,7 @@ #include "base/macros.h" #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" +#include "base/win/scoped_gdi_object.h" namespace gfx { class Point; @@ -70,7 +71,7 @@ class NotifyIcon : public TrayIcon { UINT message_id_; // The currently-displayed icon for the window. - HICON icon_; + base::win::ScopedHICON icon_; // The context menu. ui::SimpleMenuModel* menu_model_; -- 2.7.4