clipboard: api to list supported types, reading and writing markup
This commit is contained in:
parent
4a376694b4
commit
5584e3fd49
4 changed files with 56 additions and 12 deletions
|
@ -37,10 +37,12 @@ struct Converter<ui::ClipboardType> {
|
|||
|
||||
namespace {
|
||||
|
||||
bool Has(const std::string& format_string, ui::ClipboardType type) {
|
||||
std::vector<base::string16> AvailableFormats(ui::ClipboardType type) {
|
||||
std::vector<base::string16> format_types;
|
||||
bool ignore;
|
||||
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
|
||||
ui::Clipboard::FormatType format(ui::Clipboard::GetFormatType(format_string));
|
||||
return clipboard->IsFormatAvailable(format, type);
|
||||
clipboard->ReadAvailableTypes(type, &format_types, &ignore);
|
||||
return format_types;
|
||||
}
|
||||
|
||||
std::string Read(const std::string& format_string,
|
||||
|
@ -64,6 +66,24 @@ void WriteText(const base::string16& text, ui::ClipboardType type) {
|
|||
writer.WriteText(text);
|
||||
}
|
||||
|
||||
base::string16 ReadHtml(ui::ClipboardType type) {
|
||||
base::string16 data;
|
||||
base::string16 html;
|
||||
std::string url;
|
||||
uint32 start;
|
||||
uint32 end;
|
||||
ui::Clipboard::GetForCurrentThread()->ReadHTML(type, &html, &url,
|
||||
&start, &end);
|
||||
data = html.substr(start, end - start);
|
||||
return data;
|
||||
}
|
||||
|
||||
void WriteHtml(const base::string16& html,
|
||||
ui::ClipboardType type) {
|
||||
ui::ScopedClipboardWriter writer(type);
|
||||
writer.WriteHTML(html, std::string());
|
||||
}
|
||||
|
||||
gfx::Image ReadImage(ui::ClipboardType type) {
|
||||
SkBitmap bitmap = ui::Clipboard::GetForCurrentThread()->ReadImage(type);
|
||||
return gfx::Image::CreateFrom1xBitmap(bitmap);
|
||||
|
@ -81,10 +101,12 @@ void Clear(ui::ClipboardType type) {
|
|||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context, void* priv) {
|
||||
mate::Dictionary dict(context->GetIsolate(), exports);
|
||||
dict.SetMethod("_has", &Has);
|
||||
dict.SetMethod("_availableFormats", &AvailableFormats);
|
||||
dict.SetMethod("_read", &Read);
|
||||
dict.SetMethod("_readText", &ReadText);
|
||||
dict.SetMethod("_writeText", &WriteText);
|
||||
dict.SetMethod("_readHtml", &ReadHtml);
|
||||
dict.SetMethod("_writeHtml", &WriteHtml);
|
||||
dict.SetMethod("_readImage", &ReadImage);
|
||||
dict.SetMethod("_writeImage", &WriteImage);
|
||||
dict.SetMethod("_clear", &Clear);
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
binding = process.atomBinding 'clipboard'
|
||||
module.exports =
|
||||
has: (format, type='standard') -> binding._has format, type
|
||||
availableFormats: (type='standard') -> binding._availableFormats type
|
||||
read: (format, type='standard') -> binding._read format, type
|
||||
readText: (type='standard') -> binding._readText type
|
||||
writeText: (text, type='standard') -> binding._writeText text, type
|
||||
readHtml: (type='standard') -> binding._readHtml type
|
||||
writeHtml: (markup, type='standard') -> binding._writeHtml markup, type
|
||||
readImage: (type='standard') -> binding._readImage type
|
||||
writeImage: (image, type='standard') -> binding._writeImage image, type
|
||||
clear: (type='standard') -> binding._clear type
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue