]> khamidou — GitHub mirrors - electron.git/commitdiff
mac: Initialize gfx::Image from NSImage
authorCheng Zhao <zcbenz@gmail.com>
Sat, 3 Jan 2015 02:22:03 +0000 (18:22 -0800)
committerCheng Zhao <zcbenz@gmail.com>
Sat, 3 Jan 2015 02:24:23 +0000 (18:24 -0800)
atom.gyp
atom/common/native_mate_converters/image_converter.cc
atom/common/native_mate_converters/image_converter_mac.mm [new file with mode: 0644]

index a34a5af042f7bd8ec6929618e5d23f7f347455a6..3a08bd0705726a6b0a13107128e2e5b5368cf8c0 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
       'atom/common/native_mate_converters/gurl_converter.h',
       'atom/common/native_mate_converters/image_converter.cc',
       'atom/common/native_mate_converters/image_converter.h',
+      'atom/common/native_mate_converters/image_converter_mac.mm',
       'atom/common/native_mate_converters/string16_converter.h',
       'atom/common/native_mate_converters/v8_value_converter.cc',
       'atom/common/native_mate_converters/v8_value_converter.h',
index 9fa66af12ae643b7c2819edd9aba5e74b192c18c..314e4fadb4f15c014b88abf2bf10f167ea4063b0 100644 (file)
@@ -106,6 +106,7 @@ bool Converter<gfx::ImageSkia>::FromV8(v8::Isolate* isolate,
   return PopulateImageSkiaRepsFromPath(out, path);
 }
 
+#if !defined(OS_MACOSX)
 bool Converter<gfx::Image>::FromV8(v8::Isolate* isolate,
                                    v8::Handle<v8::Value> val,
                                    gfx::Image* out) {
@@ -116,5 +117,6 @@ bool Converter<gfx::Image>::FromV8(v8::Isolate* isolate,
   *out = gfx::Image(image);
   return true;
 }
+#endif
 
 }  // namespace mate
diff --git a/atom/common/native_mate_converters/image_converter_mac.mm b/atom/common/native_mate_converters/image_converter_mac.mm
new file mode 100644 (file)
index 0000000..999bf60
--- /dev/null
@@ -0,0 +1,29 @@
+// Copyright (c) 2015 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#include "atom/common/native_mate_converters/image_converter.h"
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/mac/foundation_util.h"
+#include "base/mac/scoped_nsobject.h"
+#include "base/strings/sys_string_conversions.h"
+#include "ui/gfx/image/image.h"
+
+namespace mate {
+
+bool Converter<gfx::Image>::FromV8(v8::Isolate* isolate,
+                                   v8::Handle<v8::Value> val,
+                                   gfx::Image* out) {
+  std::string path;
+  if (!ConvertFromV8(isolate, val, &path))
+    return false;
+
+  base::scoped_nsobject<NSImage> image([[NSImage alloc]
+      initByReferencingFile:base::SysUTF8ToNSString(path)]);
+  *out = gfx::Image(image.release());
+  return true;
+}
+
+}  // namespace mate