From 0bb7abd7a43dae1d6b391265b1b19f7449b900c8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 26 Mar 2015 12:53:48 +0800 Subject: [PATCH 1/4] docs: clipboard.readImage/.writeImage --- docs/api/clipboard.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/api/clipboard.md b/docs/api/clipboard.md index 33fb1207f038..c0f830491c1b 100644 --- a/docs/api/clipboard.md +++ b/docs/api/clipboard.md @@ -30,6 +30,19 @@ Returns the content in clipboard as plain text. Writes the `text` into clipboard as plain text. +## clipboard.readImage([type]) + +* `type` String + +Returns the content in clipboard as [NativeImage](native-image.md). + +## clipboard.writeImage(image[, type]) + +* `image` [NativeImage](native-image.md) +* `type` String + +Writes the `image` into clipboard. + ## clipboard.clear([type]) * `type` String From 6f082b630dc4a9b942b8e83f6a661913ee9633b8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 26 Mar 2015 12:54:15 +0800 Subject: [PATCH 2/4] Add clipboard.writeImage API --- atom/common/api/atom_api_clipboard.cc | 6 ++++++ atom/common/api/lib/clipboard.coffee | 1 + 2 files changed, 7 insertions(+) diff --git a/atom/common/api/atom_api_clipboard.cc b/atom/common/api/atom_api_clipboard.cc index 645e6a68b2d5..349b35ce5853 100644 --- a/atom/common/api/atom_api_clipboard.cc +++ b/atom/common/api/atom_api_clipboard.cc @@ -69,6 +69,11 @@ gfx::Image ReadImage(ui::ClipboardType type) { return gfx::Image::CreateFrom1xBitmap(bitmap); } +void WriteImage(const gfx::Image& image, ui::ClipboardType type) { + ui::ScopedClipboardWriter writer(type); + writer.WriteImage(image.AsBitmap()); +} + void Clear(ui::ClipboardType type) { ui::Clipboard::GetForCurrentThread()->Clear(type); } @@ -81,6 +86,7 @@ void Initialize(v8::Handle exports, v8::Handle unused, dict.SetMethod("_readText", &ReadText); dict.SetMethod("_writeText", &WriteText); dict.SetMethod("_readImage", &ReadImage); + dict.SetMethod("_writeImage", &WriteImage); dict.SetMethod("_clear", &Clear); } diff --git a/atom/common/api/lib/clipboard.coffee b/atom/common/api/lib/clipboard.coffee index 17b98e4aa176..174856181ab4 100644 --- a/atom/common/api/lib/clipboard.coffee +++ b/atom/common/api/lib/clipboard.coffee @@ -10,4 +10,5 @@ else readText: (type='standard') -> binding._readText type writeText: (text, type='standard') -> binding._writeText text, type readImage: (type='standard') -> binding._readImage type + writeImage: (image, type='standard') -> binding._writeImage image, type clear: (type='standard') -> binding._clear type From b5bc8c9811e674bdaa6afca45d09339a9e2c8ca8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 26 Mar 2015 15:25:34 +0800 Subject: [PATCH 3/4] spec: clipboard.readImage() --- spec/api-clipboard-spec.coffee | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/api-clipboard-spec.coffee b/spec/api-clipboard-spec.coffee index eecf61ca4548..feadd15b0a6f 100644 --- a/spec/api-clipboard-spec.coffee +++ b/spec/api-clipboard-spec.coffee @@ -1,7 +1,18 @@ assert = require 'assert' clipboard = require 'clipboard' +nativeImage = require 'native-image' +path = require 'path' describe 'clipboard module', -> + fixtures = path.resolve __dirname, 'fixtures' + + describe 'clipboard.readImage()', -> + it 'returns NativeImage intance', -> + p = path.join fixtures, 'assets', 'logo.png' + i = nativeImage.createFromPath p + clipboard.writeImage p + assert.equal clipboard.readImage().toDataUrl(), i.toDataUrl() + describe 'clipboard.readText()', -> it 'returns unicode string correctly', -> text = '千江有水千江月,万里无云万里天' From b54e786b0907ab5120134bfef6cce3628167c325 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 26 Mar 2015 15:46:08 +0800 Subject: [PATCH 4/4] linux: it is now safe to use clipboard in renderer process --- atom/common/api/lib/clipboard.coffee | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/atom/common/api/lib/clipboard.coffee b/atom/common/api/lib/clipboard.coffee index 174856181ab4..582feba4b1ef 100644 --- a/atom/common/api/lib/clipboard.coffee +++ b/atom/common/api/lib/clipboard.coffee @@ -1,14 +1,9 @@ -if process.platform is 'linux' and process.type is 'renderer' - # On Linux we could not access clipboard in renderer process. - module.exports = require('remote').require 'clipboard' -else - binding = process.atomBinding 'clipboard' - - module.exports = - has: (format, type='standard') -> binding._has format, type - 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 - writeImage: (image, type='standard') -> binding._writeImage image, type - clear: (type='standard') -> binding._clear type +binding = process.atomBinding 'clipboard' +module.exports = + has: (format, type='standard') -> binding._has format, type + 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 + writeImage: (image, type='standard') -> binding._writeImage image, type + clear: (type='standard') -> binding._clear type