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 | |
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
-rw-r--r-- | base/clipboard.h | 2 | ||||
-rw-r--r-- | base/clipboard_linux.cc | 28 | ||||
-rw-r--r-- | tools/gtk_clipboard_dump/gtk_clipboard_dump.cc | 21 |
3 files changed, 43 insertions, 8 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; } diff --git a/tools/gtk_clipboard_dump/gtk_clipboard_dump.cc b/tools/gtk_clipboard_dump/gtk_clipboard_dump.cc index f0f6016..a064792 100644 --- a/tools/gtk_clipboard_dump/gtk_clipboard_dump.cc +++ b/tools/gtk_clipboard_dump/gtk_clipboard_dump.cc @@ -11,9 +11,17 @@ namespace { void PrintClipboardContents(GtkClipboard* clip) { GdkAtom* targets; int num_targets = 0; - gtk_clipboard_wait_for_targets(clip, &targets, &num_targets); - printf("Available targets:\n---------------\n"); + // This call is bugged, the cache it checks is often stale; see + // <http://bugzilla.gnome.org/show_bug.cgi?id=557315>. + // gtk_clipboard_wait_for_targets(clip, &targets, &num_targets); + + GtkSelectionData* target_data = + gtk_clipboard_wait_for_contents(clip, + gdk_atom_intern("TARGETS", false)); + gtk_selection_data_get_targets(target_data, &targets, &num_targets); + + printf("%d available targets:\n---------------\n", num_targets); for (int i = 0; i < num_targets; i++) { printf(" [format: %s", gdk_atom_name(targets[i])); @@ -41,6 +49,15 @@ void PrintClipboardContents(GtkClipboard* clip) { } printf("\n\n"); } + + if (num_targets <= 0) { + printf("No targets advertised. Text is: "); + gchar* text = gtk_clipboard_wait_for_text(clip); + printf("%s\n", text ? text : "NULL"); + g_free(text); + } + + g_free(targets); } } |