]> khamidou — GitHub mirrors - electron.git/commitdiff
Use gfx::Image instead of gfx::ImageSkia in API
authorCheng Zhao <zcbenz@gmail.com>
Sat, 3 Jan 2015 02:43:56 +0000 (18:43 -0800)
committerCheng Zhao <zcbenz@gmail.com>
Sat, 3 Jan 2015 02:43:56 +0000 (18:43 -0800)
The gfx::Image can use NSImage directly as underlying format, so we
don't have to decode images ourselves on Mac, and we will also be able
to make use of template images.

atom/browser/api/atom_api_tray.cc
atom/browser/api/atom_api_tray.h
atom/browser/ui/tray_icon.cc
atom/browser/ui/tray_icon.h
atom/browser/ui/tray_icon_cocoa.h
atom/browser/ui/tray_icon_cocoa.mm
atom/browser/ui/tray_icon_gtk.cc
atom/browser/ui/tray_icon_gtk.h
atom/browser/ui/win/notify_icon.cc
atom/browser/ui/win/notify_icon.h

index dfb0d6e1d10272c5fa34845f4f1304e6c55c0a0e..6315c4059d435ebd3d72951d57e34693915c43b0 100644 (file)
@@ -12,6 +12,7 @@
 #include "atom/common/native_mate_converters/string16_converter.h"
 #include "native_mate/constructor.h"
 #include "native_mate/dictionary.h"
+#include "ui/gfx/image/image.h"
 
 #include "atom/common/node_includes.h"
 
@@ -19,7 +20,7 @@ namespace atom {
 
 namespace api {
 
-Tray::Tray(const gfx::ImageSkia& image)
+Tray::Tray(const gfx::Image& image)
     : tray_icon_(TrayIcon::Create()) {
   tray_icon_->SetImage(image);
   tray_icon_->AddObserver(this);
@@ -29,7 +30,7 @@ Tray::~Tray() {
 }
 
 // static
-mate::Wrappable* Tray::New(const gfx::ImageSkia& image) {
+mate::Wrappable* Tray::New(const gfx::Image& image) {
   return new Tray(image);
 }
 
@@ -57,13 +58,13 @@ void Tray::Destroy() {
   tray_icon_.reset();
 }
 
-void Tray::SetImage(mate::Arguments* args, const gfx::ImageSkia& image) {
+void Tray::SetImage(mate::Arguments* args, const gfx::Image& image) {
   if (!CheckTrayLife(args))
     return;
   tray_icon_->SetImage(image);
 }
 
-void Tray::SetPressedImage(mate::Arguments* args, const gfx::ImageSkia& image) {
+void Tray::SetPressedImage(mate::Arguments* args, const gfx::Image& image) {
   if (!CheckTrayLife(args))
     return;
   tray_icon_->SetPressedImage(image);
@@ -92,7 +93,7 @@ void Tray::DisplayBalloon(mate::Arguments* args,
   if (!CheckTrayLife(args))
     return;
 
-  gfx::ImageSkia icon;
+  gfx::Image icon;
   options.Get("icon", &icon);
   base::string16 title, content;
   if (!options.Get("title", &title) ||
index 87bc84a50148bfd0013b060d5d9eb1b3c4b69952..48828d2c936658dba080bdd81d42a4a63c481a97 100644 (file)
@@ -12,7 +12,7 @@
 #include "base/memory/scoped_ptr.h"
 
 namespace gfx {
-class ImageSkia;
+class Image;
 }
 
 namespace mate {
@@ -31,13 +31,13 @@ class Menu;
 class Tray : public mate::EventEmitter,
              public TrayIconObserver {
  public:
-  static mate::Wrappable* New(const gfx::ImageSkia& image);
+  static mate::Wrappable* New(const gfx::Image& image);
 
   static void BuildPrototype(v8::Isolate* isolate,
                              v8::Handle<v8::ObjectTemplate> prototype);
 
  protected:
-  explicit Tray(const gfx::ImageSkia& image);
+  explicit Tray(const gfx::Image& image);
   virtual ~Tray();
 
   // TrayIconObserver:
@@ -48,8 +48,8 @@ class Tray : public mate::EventEmitter,
   void OnBalloonClosed() override;
 
   void Destroy();
-  void SetImage(mate::Arguments* args, const gfx::ImageSkia& image);
-  void SetPressedImage(mate::Arguments* args, const gfx::ImageSkia& image);
+  void SetImage(mate::Arguments* args, const gfx::Image& image);
+  void SetPressedImage(mate::Arguments* args, const gfx::Image& image);
   void SetToolTip(mate::Arguments* args, const std::string& tool_tip);
   void SetTitle(mate::Arguments* args, const std::string& title);
   void SetHighlightMode(mate::Arguments* args, bool highlight);
index c8fb40902d464e5e3d31714c8d40a310c4c5a8fe..68770c1e5cfdbe04d1c1731abdaf8f4320361642 100644 (file)
@@ -12,7 +12,7 @@ TrayIcon::TrayIcon() {
 TrayIcon::~TrayIcon() {
 }
 
-void TrayIcon::SetPressedImage(const gfx::ImageSkia& image) {
+void TrayIcon::SetPressedImage(const gfx::Image& image) {
 }
 
 void TrayIcon::SetTitle(const std::string& title) {
@@ -21,7 +21,7 @@ void TrayIcon::SetTitle(const std::string& title) {
 void TrayIcon::SetHighlightMode(bool highlight) {
 }
 
-void TrayIcon::DisplayBalloon(const gfx::ImageSkia& icon,
+void TrayIcon::DisplayBalloon(const gfx::Image& icon,
                               const base::string16& title,
                               const base::string16& contents) {
 }
index a27ea82f224ec5b1f425df19189b7c251e438a4b..6293b39002b69480ab056103c45a47fd0101e20b 100644 (file)
@@ -20,10 +20,10 @@ class TrayIcon {
   virtual ~TrayIcon();
 
   // Sets the image associated with this status icon.
-  virtual void SetImage(const gfx::ImageSkia& image) = 0;
+  virtual void SetImage(const gfx::Image& image) = 0;
 
   // Sets the image associated with this status icon when pressed.
-  virtual void SetPressedImage(const gfx::ImageSkia& image);
+  virtual void SetPressedImage(const gfx::Image& image);
 
   // Sets the hover text for this status icon. This is also used as the label
   // for the menu item which is created as a replacement for the status icon
@@ -41,7 +41,7 @@ class TrayIcon {
 
   // 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,
+  virtual void DisplayBalloon(const gfx::Image& icon,
                               const base::string16& title,
                               const base::string16& contents);
 
index bec04147af59e7eed0e785dc7a7b42300562c40c..8d0cd5d5e2902d44a622c9683a534a94914c74bd 100644 (file)
@@ -22,8 +22,8 @@ class TrayIconCocoa : public TrayIcon {
   TrayIconCocoa();
   virtual ~TrayIconCocoa();
 
-  virtual void SetImage(const gfx::ImageSkia& image) OVERRIDE;
-  virtual void SetPressedImage(const gfx::ImageSkia& image) OVERRIDE;
+  virtual void SetImage(const gfx::Image& image) OVERRIDE;
+  virtual void SetPressedImage(const gfx::Image& image) OVERRIDE;
   virtual void SetToolTip(const std::string& tool_tip) OVERRIDE;
   virtual void SetTitle(const std::string& title) OVERRIDE;
   virtual void SetHighlightMode(bool highlight) OVERRIDE;
index 143e767831a8fcac6bbdb34cf379640296415d81..408ba29a14e0533451c7c7185f2abaf52e5a9679 100644 (file)
@@ -53,20 +53,14 @@ TrayIconCocoa::~TrayIconCocoa() {
   [[NSStatusBar systemStatusBar] removeStatusItem:item_];
 }
 
-void TrayIconCocoa::SetImage(const gfx::ImageSkia& image) {
-  if (!image.isNull()) {
-    gfx::Image neutral(image);
-    if (!neutral.IsEmpty())
-      [item_ setImage:neutral.ToNSImage()];
-  }
+void TrayIconCocoa::SetImage(const gfx::Image& image) {
+  if (!image.IsEmpty())
+    [item_ setImage:image.ToNSImage()];
 }
 
-void TrayIconCocoa::SetPressedImage(const gfx::ImageSkia& image) {
-  if (!image.isNull()) {
-    gfx::Image neutral(image);
-    if (!neutral.IsEmpty())
-      [item_ setAlternateImage:neutral.ToNSImage()];
-  }
+void TrayIconCocoa::SetPressedImage(const gfx::Image& image) {
+  if (!image.IsEmpty())
+    [item_ setAlternateImage:image.ToNSImage()];
 }
 
 void TrayIconCocoa::SetToolTip(const std::string& tool_tip) {
index c7a56ddb037ed7c1669b3382fee2a3dcf3fe3eb5..3f97a40c6ddb9c7c2e6f8f93a3d67c40491dd4ca 100644 (file)
@@ -17,9 +17,9 @@ TrayIconGtk::TrayIconGtk() {
 TrayIconGtk::~TrayIconGtk() {
 }
 
-void TrayIconGtk::SetImage(const gfx::ImageSkia& image) {
+void TrayIconGtk::SetImage(const gfx::Image& image) {
   if (icon_) {
-    icon_->SetImage(image);
+    icon_->SetImage(image.AsImageSkia());
     return;
   }
 
index 5027a2d44891bfb5df21a909e169d7c56f4ef870..ce9ae3cf2b7eef8f1ad81a3c0725689b5b3d2132 100644 (file)
@@ -23,7 +23,7 @@ class TrayIconGtk : public TrayIcon,
   virtual ~TrayIconGtk();
 
   // TrayIcon:
-  virtual void SetImage(const gfx::ImageSkia& image) OVERRIDE;
+  virtual void SetImage(const gfx::Image& image) OVERRIDE;
   virtual void SetToolTip(const std::string& tool_tip) OVERRIDE;
   virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) OVERRIDE;
 
index 97842989559eff98e69bd7a54df8d34ae47d097e..4b1e212d5d5ad0008c175a7cbbb61d5659dccc4e 100644 (file)
@@ -90,19 +90,19 @@ void NotifyIcon::ResetIcon() {
     LOG(WARNING) << "Unable to re-create status tray icon.";
 }
 
-void NotifyIcon::SetImage(const gfx::ImageSkia& image) {
+void NotifyIcon::SetImage(const gfx::Image& image) {
   // Create the icon.
   NOTIFYICONDATA icon_data;
   InitIconData(&icon_data);
   icon_data.uFlags = NIF_ICON;
-  icon_.Set(IconUtil::CreateHICONFromSkBitmap(*image.bitmap()));
+  icon_.Set(IconUtil::CreateHICONFromSkBitmap(image.AsBitmap()));
   icon_data.hIcon = icon_.Get();
   BOOL result = Shell_NotifyIcon(NIM_MODIFY, &icon_data);
   if (!result)
     LOG(WARNING) << "Error setting status tray icon image";
 }
 
-void NotifyIcon::SetPressedImage(const gfx::ImageSkia& image) {
+void NotifyIcon::SetPressedImage(const gfx::Image& image) {
   // Ignore pressed images, since the standard on Windows is to not highlight
   // pressed status icons.
 }
@@ -118,7 +118,7 @@ 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,
+void NotifyIcon::DisplayBalloon(const gfx::Image& icon,
                                 const base::string16& title,
                                 const base::string16& contents) {
   NOTIFYICONDATA icon_data;
@@ -131,7 +131,7 @@ void NotifyIcon::DisplayBalloon(const gfx::ImageSkia& icon,
 
   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()));
+    balloon_icon_.Set(IconUtil::CreateHICONFromSkBitmap(icon.AsBitmap()));
     icon_data.hBalloonIcon = balloon_icon_.Get();
     icon_data.dwInfoFlags = NIIF_USER | NIIF_LARGE_ICON;
   }
index 2ac309d5dbaf6e17b6c6ecfd5a8e84ff7532c819..12eea1fcf7251bfeb5a473930e38af7d62472691 100644 (file)
@@ -43,10 +43,10 @@ class NotifyIcon : public TrayIcon {
   UINT message_id() const { return message_id_; }
 
   // Overridden from TrayIcon:
-  void SetImage(const gfx::ImageSkia& image) override;
-  void SetPressedImage(const gfx::ImageSkia& image) override;
+  void SetImage(const gfx::Image& image) override;
+  void SetPressedImage(const gfx::Image& image) override;
   void SetToolTip(const std::string& tool_tip) override;
-  void DisplayBalloon(const gfx::ImageSkia& icon,
+  void DisplayBalloon(const gfx::Image& icon,
                       const base::string16& title,
                       const base::string16& contents) override;
   void SetContextMenu(ui::SimpleMenuModel* menu_model) override;