This commit is contained in:
Cheng Zhao 2013-04-30 16:10:25 +08:00
Родитель a34a63797a
Коммит 7a2734ed71
5 изменённых файлов: 139 добавлений и 0 удалений

Просмотреть файл

@ -12,6 +12,7 @@
'browser/atom/atom.coffee',
'browser/atom/objects_registry.coffee',
'browser/atom/rpc_server.coffee',
'common/api/lib/clipboard.coffee',
'common/api/lib/id_weak_map.coffee',
'common/api/lib/shell.coffee',
'renderer/api/lib/ipc.coffee',
@ -45,6 +46,8 @@
'browser/native_window_observer.h',
'common/api/api_messages.cc',
'common/api/api_messages.h',
'common/api/atom_api_clipboard.cc',
'common/api/atom_api_clipboard.h',
'common/api/atom_api_idle_gc.cc',
'common/api/atom_api_id_weak_map.cc',
'common/api/atom_api_id_weak_map.h',

Просмотреть файл

@ -0,0 +1,101 @@
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "common/api/atom_api_clipboard.h"
#include <string>
#include "ui/base/clipboard/clipboard.h"
#include "vendor/node/src/node.h"
namespace atom {
namespace api {
// static
v8::Handle<v8::Value> Clipboard::Has(const v8::Arguments &args) {
v8::HandleScope scope;
if (!args[0]->IsString())
return node::ThrowTypeError("Bad argument");
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
std::string format_string(*v8::String::Utf8Value(args[0]));
ui::Clipboard::FormatType format(ui::Clipboard::GetFormatType(format_string));
return scope.Close(v8::Boolean::New(
clipboard->IsFormatAvailable(format, ui::Clipboard::BUFFER_STANDARD)));
}
// static
v8::Handle<v8::Value> Clipboard::Read(const v8::Arguments &args) {
v8::HandleScope scope;
if (!args[0]->IsString())
return node::ThrowTypeError("Bad argument");
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
std::string format_string(*v8::String::Utf8Value(args[0]));
ui::Clipboard::FormatType format(ui::Clipboard::GetFormatType(format_string));
std::string data;
clipboard->ReadData(format, &data);
return scope.Close(v8::String::New(data.c_str(), data.size()));
}
// static
v8::Handle<v8::Value> Clipboard::ReadText(const v8::Arguments &args) {
v8::HandleScope scope;
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
std::string data;
clipboard->ReadAsciiText(ui::Clipboard::BUFFER_STANDARD, &data);
return scope.Close(v8::String::New(data.c_str(), data.size()));
}
// static
v8::Handle<v8::Value> Clipboard::WriteText(const v8::Arguments &args) {
v8::HandleScope scope;
if (!args[0]->IsString())
return node::ThrowTypeError("Bad argument");
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
std::string text(*v8::String::Utf8Value(args[0]));
ui::Clipboard::ObjectMap object_map;
object_map[ui::Clipboard::CBF_TEXT].push_back(
std::vector<char>(text.begin(), text.end()));
clipboard->WriteObjects(ui::Clipboard::BUFFER_STANDARD, object_map, NULL);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Clipboard::Clear(const v8::Arguments &args) {
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
clipboard->Clear(ui::Clipboard::BUFFER_STANDARD);
return v8::Undefined();
}
// static
void Clipboard::Initialize(v8::Handle<v8::Object> target) {
node::SetMethod(target, "has", Has);
node::SetMethod(target, "read", Read);
node::SetMethod(target, "readText", ReadText);
node::SetMethod(target, "writeText", WriteText);
node::SetMethod(target, "clear", Clear);
}
} // namespace api
} // namespace atom
NODE_MODULE(atom_common_clipboard, atom::api::Clipboard::Initialize)

Просмотреть файл

@ -0,0 +1,33 @@
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ATOM_COMMON_API_ATOM_API_CLIPBOARD_H_
#define ATOM_COMMON_API_ATOM_API_CLIPBOARD_H_
#include "base/basictypes.h"
#include "v8/include/v8.h"
namespace atom {
namespace api {
class Clipboard {
public:
static void Initialize(v8::Handle<v8::Object> target);
private:
static v8::Handle<v8::Value> Has(const v8::Arguments &args);
static v8::Handle<v8::Value> Read(const v8::Arguments &args);
static v8::Handle<v8::Value> ReadText(const v8::Arguments &args);
static v8::Handle<v8::Value> WriteText(const v8::Arguments &args);
static v8::Handle<v8::Value> Clear(const v8::Arguments &args);
DISALLOW_IMPLICIT_CONSTRUCTORS(Clipboard);
};
} // namespace api
} // namespace atom
#endif // ATOM_COMMON_API_ATOM_API_CLIPBOARD_H_

Просмотреть файл

@ -18,6 +18,7 @@ NODE_EXT_LIST_ITEM(atom_renderer_ipc)
// Module names start with `atom_common_` can be used by both browser and
// renderer processes.
NODE_EXT_LIST_ITEM(atom_common_clipboard)
NODE_EXT_LIST_ITEM(atom_common_idle_gc)
NODE_EXT_LIST_ITEM(atom_common_id_weak_map)
NODE_EXT_LIST_ITEM(atom_common_shell)

Просмотреть файл

@ -0,0 +1 @@
module.exports = process.atomBinding 'clipboard'