No need to reference the icon in Tray
authorCheng Zhao <zcbenz@gmail.com>
Fri, 20 May 2016 13:28:07 +0000 (22:28 +0900)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 20 May 2016 13:44:02 +0000 (22:44 +0900)
atom/browser/api/atom_api_tray.cc
atom/browser/api/atom_api_tray.h
atom/browser/native_window_views.cc
atom/browser/native_window_views_win.cc
atom/browser/ui/win/notify_icon.cc
atom/browser/ui/win/notify_icon.h

index 5de3b63..c84e8a1 100644 (file)
@@ -97,7 +97,6 @@ void Tray::OnDragEnded() {
 }
 
 void Tray::SetImage(v8::Isolate* isolate, mate::Handle<NativeImage> 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<NativeImage> image) {
 
 void Tray::SetPressedImage(v8::Isolate* isolate,
                            mate::Handle<NativeImage> image) {
-  pressed_image_.Reset(isolate, image.ToV8());
 #if defined(OS_WIN)
   tray_icon_->SetPressedImage(image->GetHICON(GetSystemMetrics(SM_CXSMICON)));
 #else
index 312185a..3c3d02e 100644 (file)
@@ -69,8 +69,6 @@ class Tray : public mate::TrackableObject<Tray>,
  private:
   v8::Local<v8::Object> ModifiersToObject(v8::Isolate* isolate, int modifiers);
 
-  v8::Global<v8::Object> image_;
-  v8::Global<v8::Object> pressed_image_;
   v8::Global<v8::Object> menu_;
   scoped_ptr<TrayIcon> tray_icon_;
 
index 42da62c..82c1158 100644 (file)
@@ -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<LPARAM>(small_icon));
+  SendMessage(hwnd, WM_SETICON, ICON_BIG,
+              reinterpret_cast<LPARAM>(app_icon));
+}
+#elif defined(USE_X11)
 void NativeWindowViews::SetIcon(const gfx::ImageSkia& icon) {
   views::DesktopWindowTreeHostX11* tree_host =
       views::DesktopWindowTreeHostX11::GetHostForXID(GetAcceleratedWidget());
   static_cast<views::DesktopWindowTreeHost*>(tree_host)->SetWindowIcons(
       icon, icon);
 }
+#endif
 
 void NativeWindowViews::OnWidgetActivationChanged(
     views::Widget* widget, bool active) {
index 0cb6859..038ab10 100644 (file)
@@ -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<LPARAM>(small_icon));
-  SendMessage(hwnd, WM_SETICON, ICON_BIG,
-              reinterpret_cast<LPARAM>(app_icon));
-}
-
 bool NativeWindowViews::ExecuteWindowsCommand(int command_id) {
   std::string command = AppCommandToString(command_id);
   NotifyWindowExecuteWindowsCommand(command);
index 98c967e..1cc6162 100644 (file)
@@ -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;
index 1c6f240..95e9945 100644 (file)
@@ -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_;