diff options
author | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-20 18:11:35 +0000 |
---|---|---|
committer | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-20 18:11:35 +0000 |
commit | 15a9c02836a9ce85c260c0827e6f3a037004ba2e (patch) | |
tree | 06690d317fa8bd14ea11b4fefdbf9e9fa13d7d7e /chrome/browser/autocomplete | |
parent | ca38d8e05b6cbd729487c6ed619117ae7510e4c6 (diff) | |
download | chromium_src-15a9c02836a9ce85c260c0827e6f3a037004ba2e.zip chromium_src-15a9c02836a9ce85c260c0827e6f3a037004ba2e.tar.gz chromium_src-15a9c02836a9ce85c260c0827e6f3a037004ba2e.tar.bz2 |
Linux: Attempt #2 at updating PRIMARY selection on Ctrl-C in omnibox.
r23596 was the original attempt; r23714 reverted it. Using
gtk_text_buffer_copy_clipboard() gives the GtkTextBuffer
ownership of the GtkClipboard and appears to prevent it from
unhighlighting its text.
Tested as follows:
1. Select text in webkit and hit Ctrl-C; check that both the
PRIMARY and CLIPBOARD selections contain it.
2. Click in the omnibox. All of the text gets highlighted.
Check that the PRIMARY selection contains the omnibox text and
the CLIPBOARD selection contains the webkit text.
3. Type Ctrl-C and confirm that the CLIPBOARD selection now
contains the omnibox text.
4. Copy webkit text back to both selections.
5. Type Ctrl-L. The omnibox text gets highlighted but both
selections still contain the webkit text.
6. Type Ctrl-C and confirm that both selections now contain the
omnibox text.
7. Try hitting Ctrl-C again while the omnibox text is on the
CLIPBOARD selection to make sure that a bizarre GTK crash
doesn't occur (see comment in code).
BUG=19648
TESTED=see above
Review URL: http://codereview.chromium.org/173098
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23834 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc | 27 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_gtk.h | 5 |
2 files changed, 32 insertions, 0 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc index 0938d83..d41d373 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc @@ -210,6 +210,8 @@ void AutocompleteEditViewGtk::Init() { G_CALLBACK(&HandleDragDataReceivedThunk), this); g_signal_connect(text_view_, "backspace", G_CALLBACK(&HandleBackSpaceThunk), this); + g_signal_connect(text_view_, "copy-clipboard", + G_CALLBACK(&HandleCopyClipboardThunk), this); #if !defined(TOOLKIT_VIEWS) registrar_.Add(this, @@ -921,6 +923,31 @@ void AutocompleteEditViewGtk::HandleBackSpace() { g_signal_stop_emission(text_view_, signal_id, 0); } +void AutocompleteEditViewGtk::HandleCopyClipboard() { + // On copy, we manually update the PRIMARY selection to contain the + // highlighted text. This matches Firefox -- we highlight the URL but don't + // update PRIMARY on Ctrl-L, so Ctrl-L, Ctrl-C and then middle-click is a + // convenient way to paste the current URL somewhere. + if (!gtk_text_buffer_get_has_selection(text_buffer_)) + return; + + GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); + DCHECK(clipboard); + if (!clipboard) + return; + + // Passing gtk_text_buffer_copy_clipboard() a text buffer that already owns + // the clipboard that's being updated clears the highlighted text, which we + // don't want to do (and it also appears to at least sometimes trigger a + // failed G_IS_OBJECT() assertion). + if (gtk_clipboard_get_owner(clipboard) == G_OBJECT(text_buffer_)) + return; + + // We can't just call SavePrimarySelection(); that makes the text view lose + // the selection and unhighlight its text. + gtk_text_buffer_copy_clipboard(text_buffer_, clipboard); +} + void AutocompleteEditViewGtk::SelectAllInternal(bool reversed, bool update_primary_selection) { GtkTextIter start, end; diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h index 50293e3..b9c83a3 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h @@ -271,6 +271,11 @@ class AutocompleteEditViewGtk : public AutocompleteEditView, } void HandleBackSpace(); + static void HandleCopyClipboardThunk(GtkTextView* text_view, gpointer self) { + reinterpret_cast<AutocompleteEditViewGtk*>(self)->HandleCopyClipboard(); + } + void HandleCopyClipboard(); + // Actual implementation of SelectAll(), but also provides control over // whether the PRIMARY selection is set to the selected text (in SelectAll(), // it isn't, but we want set the selection when the user clicks in the entry). |