diff options
author | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-15 21:40:16 +0000 |
---|---|---|
committer | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-15 21:40:16 +0000 |
commit | 0b7825364256151b9d63a870e0d995125573cff7 (patch) | |
tree | 6662f5e562d91b5a27976beab6d679a27456e244 /ui | |
parent | fc643f52f16712e1dcaea0aed8bc61f6b587286d (diff) | |
download | chromium_src-0b7825364256151b9d63a870e0d995125573cff7.zip chromium_src-0b7825364256151b9d63a870e0d995125573cff7.tar.gz chromium_src-0b7825364256151b9d63a870e0d995125573cff7.tar.bz2 |
Implement Clipboard::ReadAvailableTypes for Linux.
BUG=75237
TEST=Local testing.
Review URL: http://codereview.chromium.org/6825064
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81809 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/base/clipboard/clipboard_linux.cc | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/ui/base/clipboard/clipboard_linux.cc b/ui/base/clipboard/clipboard_linux.cc index b37b676..e688875 100644 --- a/ui/base/clipboard/clipboard_linux.cc +++ b/ui/base/clipboard/clipboard_linux.cc @@ -21,11 +21,9 @@ namespace ui { namespace { -const char kMimeBmp[] = "image/bmp"; -const char kMimeHtml[] = "text/html"; -const char kMimeText[] = "text/plain"; -const char kMimeMozillaUrl[] = "text/x-moz-url"; -const char kMimeWebkitSmartPaste[] = "chromium/x-webkit-paste"; +const char kMimeTypeBitmap[] = "image/bmp"; +const char kMimeTypeMozillaURL[] = "text/x-moz-url"; +const char kMimeTypeWebkitSmartPaste[] = "chromium/x-webkit-paste"; std::string GdkAtomToString(const GdkAtom& atom) { gchar* name = gdk_atom_name(atom); @@ -53,7 +51,7 @@ void GetData(GtkClipboard* clipboard, if (iter == data_map->end()) return; - if (target_string == kMimeBmp) { + if (target_string == kMimeTypeBitmap) { gtk_selection_data_set_pixbuf(selection_data, reinterpret_cast<GdkPixbuf*>(iter->second.first)); } else { @@ -76,7 +74,7 @@ void ClearData(GtkClipboard* clipboard, for (Clipboard::TargetMap::iterator iter = map->begin(); iter != map->end(); ++iter) { - if (iter->first == kMimeBmp) + if (iter->first == kMimeTypeBitmap) g_object_unref(reinterpret_cast<GdkPixbuf*>(iter->second.first)); else ptrs.insert(iter->second.first); @@ -155,7 +153,7 @@ void Clipboard::WriteText(const char* text_data, size_t text_len) { char* data = new char[text_len]; memcpy(data, text_data, text_len); - InsertMapping(kMimeText, data, text_len); + InsertMapping(kMimeTypeText, data, text_len); InsertMapping("TEXT", data, text_len); InsertMapping("STRING", data, text_len); InsertMapping("UTF8_STRING", data, text_len); @@ -178,13 +176,13 @@ void Clipboard::WriteHTML(const char* markup_data, // Some programs expect NULL-terminated data. See http://crbug.com/42624 data[total_len - 1] = '\0'; - InsertMapping(kMimeHtml, data, total_len); + InsertMapping(kMimeTypeHTML, data, total_len); } // Write an extra flavor that signifies WebKit was the last to modify the // pasteboard. This flavor has no data. void Clipboard::WriteWebSmartPaste() { - InsertMapping(kMimeWebkitSmartPaste, NULL, 0); + InsertMapping(kMimeTypeWebkitSmartPaste, NULL, 0); } void Clipboard::WriteBitmap(const char* pixel_data, const char* size_data) { @@ -201,7 +199,7 @@ void Clipboard::WriteBitmap(const char* pixel_data, const char* size_data) { // We store the GdkPixbuf*, and the size_t half of the pair is meaningless. // Note that this contrasts with the vast majority of entries in our target // map, which directly store the data and its length. - InsertMapping(kMimeBmp, reinterpret_cast<char*>(pixbuf), 0); + InsertMapping(kMimeTypeBitmap, reinterpret_cast<char*>(pixbuf), 0); } void Clipboard::WriteBookmark(const char* title_data, size_t title_len, @@ -214,7 +212,7 @@ void Clipboard::WriteBookmark(const char* title_data, size_t title_len, char* data = new char[data_len]; memcpy(data, url.data(), 2 * url.length()); memcpy(data + 2 * url.length(), title.data(), 2 * title.length()); - InsertMapping(kMimeMozillaUrl, data, data_len); + InsertMapping(kMimeTypeMozillaURL, data, data_len); } void Clipboard::WriteData(const char* format_name, size_t format_len, @@ -222,7 +220,7 @@ void Clipboard::WriteData(const char* format_name, size_t format_len, std::string format(format_name, format_len); // We assume that certain mapping types are only written by trusted code. // Therefore we must upkeep their integrity. - if (format == kMimeBmp) + if (format == kMimeTypeBitmap) return; char* data = new char[data_len]; memcpy(data, data_data, data_len); @@ -300,8 +298,11 @@ void Clipboard::ReadAvailableTypes(Clipboard::Buffer buffer, return; } - // TODO(dcheng): Implement me. types->clear(); + if (IsFormatAvailable(GetPlainTextFormatType(), buffer)) + types->push_back(UTF8ToUTF16(kMimeTypeText)); + if (IsFormatAvailable(GetHtmlFormatType(), buffer)) + types->push_back(UTF8ToUTF16(kMimeTypeHTML)); *contains_filenames = false; } @@ -409,17 +410,17 @@ Clipboard::FormatType Clipboard::GetPlainTextWFormatType() { // static Clipboard::FormatType Clipboard::GetHtmlFormatType() { - return std::string(kMimeHtml); + return std::string(kMimeTypeHTML); } // static Clipboard::FormatType Clipboard::GetBitmapFormatType() { - return std::string(kMimeBmp); + return std::string(kMimeTypeBitmap); } // static Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { - return std::string(kMimeWebkitSmartPaste); + return std::string(kMimeTypeWebkitSmartPaste); } void Clipboard::InsertMapping(const char* key, |