No need to reference the icon in Tray
This commit is contained in:
parent
a93c9462ed
commit
3182485e68
6 changed files with 15 additions and 16 deletions
|
@ -97,7 +97,6 @@ void Tray::OnDragEnded() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tray::SetImage(v8::Isolate* isolate, mate::Handle<NativeImage> image) {
|
void Tray::SetImage(v8::Isolate* isolate, mate::Handle<NativeImage> image) {
|
||||||
image_.Reset(isolate, image.ToV8());
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
tray_icon_->SetImage(image->GetHICON(GetSystemMetrics(SM_CXSMICON)));
|
tray_icon_->SetImage(image->GetHICON(GetSystemMetrics(SM_CXSMICON)));
|
||||||
#else
|
#else
|
||||||
|
@ -107,7 +106,6 @@ void Tray::SetImage(v8::Isolate* isolate, mate::Handle<NativeImage> image) {
|
||||||
|
|
||||||
void Tray::SetPressedImage(v8::Isolate* isolate,
|
void Tray::SetPressedImage(v8::Isolate* isolate,
|
||||||
mate::Handle<NativeImage> image) {
|
mate::Handle<NativeImage> image) {
|
||||||
pressed_image_.Reset(isolate, image.ToV8());
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
tray_icon_->SetPressedImage(image->GetHICON(GetSystemMetrics(SM_CXSMICON)));
|
tray_icon_->SetPressedImage(image->GetHICON(GetSystemMetrics(SM_CXSMICON)));
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -69,8 +69,6 @@ class Tray : public mate::TrackableObject<Tray>,
|
||||||
private:
|
private:
|
||||||
v8::Local<v8::Object> ModifiersToObject(v8::Isolate* isolate, int modifiers);
|
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_;
|
v8::Global<v8::Object> menu_;
|
||||||
scoped_ptr<TrayIcon> tray_icon_;
|
scoped_ptr<TrayIcon> tray_icon_;
|
||||||
|
|
||||||
|
|
|
@ -779,12 +779,22 @@ gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() {
|
||||||
return GetNativeWindow()->GetHost()->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) {
|
void NativeWindowViews::SetIcon(const gfx::ImageSkia& icon) {
|
||||||
views::DesktopWindowTreeHostX11* tree_host =
|
views::DesktopWindowTreeHostX11* tree_host =
|
||||||
views::DesktopWindowTreeHostX11::GetHostForXID(GetAcceleratedWidget());
|
views::DesktopWindowTreeHostX11::GetHostForXID(GetAcceleratedWidget());
|
||||||
static_cast<views::DesktopWindowTreeHost*>(tree_host)->SetWindowIcons(
|
static_cast<views::DesktopWindowTreeHost*>(tree_host)->SetWindowIcons(
|
||||||
icon, icon);
|
icon, icon);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void NativeWindowViews::OnWidgetActivationChanged(
|
void NativeWindowViews::OnWidgetActivationChanged(
|
||||||
views::Widget* widget, bool active) {
|
views::Widget* widget, bool active) {
|
||||||
|
|
|
@ -73,14 +73,6 @@ const char* AppCommandToString(int command_id) {
|
||||||
|
|
||||||
} // namespace
|
} // 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) {
|
bool NativeWindowViews::ExecuteWindowsCommand(int command_id) {
|
||||||
std::string command = AppCommandToString(command_id);
|
std::string command = AppCommandToString(command_id);
|
||||||
NotifyWindowExecuteWindowsCommand(command);
|
NotifyWindowExecuteWindowsCommand(command);
|
||||||
|
|
|
@ -25,7 +25,6 @@ NotifyIcon::NotifyIcon(NotifyIconHost* host,
|
||||||
icon_id_(id),
|
icon_id_(id),
|
||||||
window_(window),
|
window_(window),
|
||||||
message_id_(message),
|
message_id_(message),
|
||||||
icon_(NULL),
|
|
||||||
menu_model_(NULL) {
|
menu_model_(NULL) {
|
||||||
NOTIFYICONDATA icon_data;
|
NOTIFYICONDATA icon_data;
|
||||||
InitIconData(&icon_data);
|
InitIconData(&icon_data);
|
||||||
|
@ -80,7 +79,7 @@ void NotifyIcon::ResetIcon() {
|
||||||
InitIconData(&icon_data);
|
InitIconData(&icon_data);
|
||||||
icon_data.uFlags |= NIF_MESSAGE;
|
icon_data.uFlags |= NIF_MESSAGE;
|
||||||
icon_data.uCallbackMessage = message_id_;
|
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
|
// 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.
|
// Shell_NotifyIcon() to set the image for the status icon it creates.
|
||||||
if (icon_data.hIcon)
|
if (icon_data.hIcon)
|
||||||
|
@ -92,8 +91,9 @@ void NotifyIcon::ResetIcon() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotifyIcon::SetImage(HICON image) {
|
void NotifyIcon::SetImage(HICON image) {
|
||||||
|
icon_ = base::win::ScopedHICON(CopyIcon(image));
|
||||||
|
|
||||||
// Create the icon.
|
// Create the icon.
|
||||||
icon_ = image;
|
|
||||||
NOTIFYICONDATA icon_data;
|
NOTIFYICONDATA icon_data;
|
||||||
InitIconData(&icon_data);
|
InitIconData(&icon_data);
|
||||||
icon_data.uFlags |= NIF_ICON;
|
icon_data.uFlags |= NIF_ICON;
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "base/macros.h"
|
#include "base/macros.h"
|
||||||
#include "base/compiler_specific.h"
|
#include "base/compiler_specific.h"
|
||||||
#include "base/memory/scoped_ptr.h"
|
#include "base/memory/scoped_ptr.h"
|
||||||
|
#include "base/win/scoped_gdi_object.h"
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
class Point;
|
class Point;
|
||||||
|
@ -70,7 +71,7 @@ class NotifyIcon : public TrayIcon {
|
||||||
UINT message_id_;
|
UINT message_id_;
|
||||||
|
|
||||||
// The currently-displayed icon for the window.
|
// The currently-displayed icon for the window.
|
||||||
HICON icon_;
|
base::win::ScopedHICON icon_;
|
||||||
|
|
||||||
// The context menu.
|
// The context menu.
|
||||||
ui::SimpleMenuModel* menu_model_;
|
ui::SimpleMenuModel* menu_model_;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue