diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-21 01:21:54 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-21 01:21:54 +0000 |
commit | 27f3d73d16b6b041e06a39451d2cda51562ce1c6 (patch) | |
tree | 308e836cd5f03a1809a3296ab69e1ddadcabfcca /base | |
parent | 4b32fe696f8a3b84a4feb16f1ce8dfa5d5f41a9a (diff) | |
download | chromium_src-27f3d73d16b6b041e06a39451d2cda51562ce1c6.zip chromium_src-27f3d73d16b6b041e06a39451d2cda51562ce1c6.tar.gz chromium_src-27f3d73d16b6b041e06a39451d2cda51562ce1c6.tar.bz2 |
Support pasting text from a clipboard that has no published targets.
BUG=16887
TEST=paste from intellij into chrome render view
Review URL: http://codereview.chromium.org/159107
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21142 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/clipboard.h | 2 | ||||
-rw-r--r-- | base/clipboard_linux.cc | 28 |
2 files changed, 24 insertions, 6 deletions
diff --git a/base/clipboard.h b/base/clipboard.h index a404418..a0a7827 100644 --- a/base/clipboard.h +++ b/base/clipboard.h @@ -40,7 +40,7 @@ class Clipboard { CBF_FILES, CBF_WEBKIT, CBF_BITMAP, - CBF_SMBITMAP // bitmap from shared memory + CBF_SMBITMAP // bitmap from shared memory }; // ObjectMap is a map from ObjectType to associated data. diff --git a/base/clipboard_linux.cc b/base/clipboard_linux.cc index 10c0deb..eb5012c 100644 --- a/base/clipboard_linux.cc +++ b/base/clipboard_linux.cc @@ -214,11 +214,14 @@ void Clipboard::WriteFiles(const char* file_data, size_t file_len) { // We do not use gtk_clipboard_wait_is_target_available because of // a bug with the gtk clipboard. It caches the available targets // and does not always refresh the cache when it is appropriate. -// TODO(estade): When gnome bug 557315 is resolved, change this function -// to use gtk_clipboard_wait_is_target_available. Also, catch requests -// for plain text and change them to gtk_clipboard_wait_is_text_available -// (which checks for several standard text targets). bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format) const { + bool format_is_plain_text = GetPlainTextFormatType() == format; + if (format_is_plain_text) { + // This tries a number of common text targets. + if (gtk_clipboard_wait_is_text_available(clipboard_)) + return true; + } + bool retval = false; GdkAtom* targets = NULL; GtkSelectionData* data = @@ -231,6 +234,21 @@ bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format) const { int num = 0; gtk_selection_data_get_targets(data, &targets, &num); + // Some programs post data to the clipboard without any targets. If this is + // the case we attempt to make sense of the contents as text. This is pretty + // unfortunate since it means we have to actually copy the data to see if it + // is available, but at least this path shouldn't be hit for conforming + // programs. + if (num <= 0) { + if (format_is_plain_text) { + gchar* text = gtk_clipboard_wait_for_text(clipboard_); + if (text) { + g_free(text); + retval = true; + } + } + } + GdkAtom format_atom = StringToGdkAtom(format); for (int i = 0; i < num; i++) { @@ -240,8 +258,8 @@ bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format) const { } } - gtk_selection_data_free(data); g_free(targets); + gtk_selection_data_free(data); return retval; } |