]> khamidou — GitHub mirrors - electron.git/commitdiff
Add clipboard.readImage method
authorCheng Zhao <zcbenz@gmail.com>
Wed, 11 Feb 2015 06:55:44 +0000 (14:55 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 12 Feb 2015 02:45:03 +0000 (10:45 +0800)
atom/common/api/atom_api_clipboard.cc
atom/common/api/lib/clipboard.coffee

index 36b8cecb7c86a3c699adfa07727a403590659b56..645e6a68b2d5250eef181c28bb34c8c6394d605f 100644 (file)
@@ -5,10 +5,13 @@
 #include <string>
 #include <vector>
 
+#include "atom/common/native_mate_converters/image_converter.h"
 #include "atom/common/native_mate_converters/string16_converter.h"
 #include "native_mate/dictionary.h"
+#include "third_party/skia/include/core/SkBitmap.h"
 #include "ui/base/clipboard/clipboard.h"
 #include "ui/base/clipboard/scoped_clipboard_writer.h"
+#include "ui/gfx/image/image.h"
 
 #include "atom/common/node_includes.h"
 
@@ -16,8 +19,7 @@ namespace mate {
 
 template<>
 struct Converter<ui::ClipboardType> {
-  static bool FromV8(v8::Isolate* isolate,
-                     v8::Handle<v8::Value> val,
+  static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
                      ui::ClipboardType* out) {
     std::string type;
     if (!Converter<std::string>::FromV8(isolate, val, &type))
@@ -62,6 +64,11 @@ void WriteText(const base::string16& text, ui::ClipboardType type) {
   writer.WriteText(text);
 }
 
+gfx::Image ReadImage(ui::ClipboardType type) {
+  SkBitmap bitmap = ui::Clipboard::GetForCurrentThread()->ReadImage(type);
+  return gfx::Image::CreateFrom1xBitmap(bitmap);
+}
+
 void Clear(ui::ClipboardType type) {
   ui::Clipboard::GetForCurrentThread()->Clear(type);
 }
@@ -73,6 +80,7 @@ void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
   dict.SetMethod("_read", &Read);
   dict.SetMethod("_readText", &ReadText);
   dict.SetMethod("_writeText", &WriteText);
+  dict.SetMethod("_readImage", &ReadImage);
   dict.SetMethod("_clear", &Clear);
 }
 
index 6438207a96a655f17caaf87d4b1ad112f0e016f1..17b98e4aa1764e2dd31108561ade6be1a66f4949 100644 (file)
@@ -9,4 +9,5 @@ else
     read: (format, type='standard') -> binding._read format, type
     readText: (type='standard') -> binding._readText type
     writeText: (text, type='standard') -> binding._writeText text, type
+    readImage: (type='standard') -> binding._readImage type
     clear: (type='standard') -> binding._clear type