No need to reference the icon in Tray

This commit is contained in:
Cheng Zhao 2016-05-20 22:28:07 +09:00
parent a93c9462ed
commit 3182485e68
6 changed files with 15 additions and 16 deletions

View 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

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

View 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) {

View 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);

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

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