From b76615f3e71399289473d59784d6fb7ef7ee81d0 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 11 Feb 2015 14:55:44 +0800 Subject: [PATCH] Add clipboard.readImage method --- atom/common/api/atom_api_clipboard.cc | 12 ++++++++++-- atom/common/api/lib/clipboard.coffee | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/atom/common/api/atom_api_clipboard.cc b/atom/common/api/atom_api_clipboard.cc index 36b8cecb7c8..645e6a68b2d 100644 --- a/atom/common/api/atom_api_clipboard.cc +++ b/atom/common/api/atom_api_clipboard.cc @@ -5,10 +5,13 @@ #include #include +#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 { - static bool FromV8(v8::Isolate* isolate, - v8::Handle val, + static bool FromV8(v8::Isolate* isolate, v8::Handle val, ui::ClipboardType* out) { std::string type; if (!Converter::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 exports, v8::Handle unused, dict.SetMethod("_read", &Read); dict.SetMethod("_readText", &ReadText); dict.SetMethod("_writeText", &WriteText); + dict.SetMethod("_readImage", &ReadImage); dict.SetMethod("_clear", &Clear); } diff --git a/atom/common/api/lib/clipboard.coffee b/atom/common/api/lib/clipboard.coffee index 6438207a96a..17b98e4aa17 100644 --- a/atom/common/api/lib/clipboard.coffee +++ b/atom/common/api/lib/clipboard.coffee @@ -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