Skip to content

Commit b76615f

Browse files
committed
Add clipboard.readImage method
1 parent 878d25e commit b76615f

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

atom/common/api/atom_api_clipboard.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
#include <string>
66
#include <vector>
77

8+
#include "atom/common/native_mate_converters/image_converter.h"
89
#include "atom/common/native_mate_converters/string16_converter.h"
910
#include "native_mate/dictionary.h"
11+
#include "third_party/skia/include/core/SkBitmap.h"
1012
#include "ui/base/clipboard/clipboard.h"
1113
#include "ui/base/clipboard/scoped_clipboard_writer.h"
14+
#include "ui/gfx/image/image.h"
1215

1316
#include "atom/common/node_includes.h"
1417

1518
namespace mate {
1619

1720
template<>
1821
struct Converter<ui::ClipboardType> {
19-
static bool FromV8(v8::Isolate* isolate,
20-
v8::Handle<v8::Value> val,
22+
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
2123
ui::ClipboardType* out) {
2224
std::string type;
2325
if (!Converter<std::string>::FromV8(isolate, val, &type))
@@ -62,6 +64,11 @@ void WriteText(const base::string16& text, ui::ClipboardType type) {
6264
writer.WriteText(text);
6365
}
6466

67+
gfx::Image ReadImage(ui::ClipboardType type) {
68+
SkBitmap bitmap = ui::Clipboard::GetForCurrentThread()->ReadImage(type);
69+
return gfx::Image::CreateFrom1xBitmap(bitmap);
70+
}
71+
6572
void Clear(ui::ClipboardType type) {
6673
ui::Clipboard::GetForCurrentThread()->Clear(type);
6774
}
@@ -73,6 +80,7 @@ void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
7380
dict.SetMethod("_read", &Read);
7481
dict.SetMethod("_readText", &ReadText);
7582
dict.SetMethod("_writeText", &WriteText);
83+
dict.SetMethod("_readImage", &ReadImage);
7684
dict.SetMethod("_clear", &Clear);
7785
}
7886

atom/common/api/lib/clipboard.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ else
99
read: (format, type='standard') -> binding._read format, type
1010
readText: (type='standard') -> binding._readText type
1111
writeText: (text, type='standard') -> binding._writeText text, type
12+
readImage: (type='standard') -> binding._readImage type
1213
clear: (type='standard') -> binding._clear type

0 commit comments

Comments
 (0)