diff options
author | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-14 02:00:59 +0000 |
---|---|---|
committer | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-14 02:00:59 +0000 |
commit | 3ab90751402a5730b25c2c8e93dce7b6d2c5f618 (patch) | |
tree | 0fcf438b78ce4c7d7257f7f648218d7061a8716a /ui | |
parent | 74263473b50b377b8269d2a5a93526a935dadbe8 (diff) | |
download | chromium_src-3ab90751402a5730b25c2c8e93dce7b6d2c5f618.zip chromium_src-3ab90751402a5730b25c2c8e93dce7b6d2c5f618.tar.gz chromium_src-3ab90751402a5730b25c2c8e93dce7b6d2c5f618.tar.bz2 |
Fix Clipboard::IsFormatAvailable on GTK so that the workaround for broken apps actually works
Some apps don't properly set the TARGETS they support. In that case, we assume
text. However, the logic for that was after the logic for checking TARGETS, so
it was never hit.
BUG=30372
TEST=manual test using xcb
Review URL: http://codereview.chromium.org/9168039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117759 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/base/clipboard/clipboard_gtk.cc | 55 |
1 files changed, 25 insertions, 30 deletions
diff --git a/ui/base/clipboard/clipboard_gtk.cc b/ui/base/clipboard/clipboard_gtk.cc index b1ea51b..a63bb8e 100644 --- a/ui/base/clipboard/clipboard_gtk.cc +++ b/ui/base/clipboard/clipboard_gtk.cc @@ -351,49 +351,44 @@ bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format, if (clipboard == NULL) return false; + bool retval = false; + GtkSelectionData* data = gtk_clipboard_wait_for_contents( + clipboard, gdk_atom_intern_static_string("TARGETS")); + bool format_is_plain_text = GetPlainTextFormatType().Equals(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 = - gtk_clipboard_wait_for_contents(clipboard, - gdk_atom_intern("TARGETS", false)); - - if (!data) - return false; - - 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) { + if (data) { + retval = gtk_selection_data_targets_include_text(data); + } else { + // 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. gchar* text = gtk_clipboard_wait_for_text(clipboard); if (text) { g_free(text); retval = true; } } - } + } else if (data) { + GdkAtom* targets = NULL; + int num = 0; + gtk_selection_data_get_targets(data, &targets, &num); - for (int i = 0; i < num; i++) { - if (targets[i] == format.ToGdkAtom()) { - retval = true; - break; + for (int i = 0; i < num; i++) { + if (targets[i] == format.ToGdkAtom()) { + retval = true; + break; + } } + + g_free(targets); } - g_free(targets); - gtk_selection_data_free(data); + if (data) + gtk_selection_data_free(data); return retval; } |