summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-18 00:25:09 +0000
committerderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-18 00:25:09 +0000
commit20deda2c8abbbe492fb631de3b8661904236f13f (patch)
treed775df89d988ff24d3b6539631c64dbfb9cf5afe
parentf7943fbbb15643f9d7c40ae49ff0e0d987ae0793 (diff)
downloadchromium_src-20deda2c8abbbe492fb631de3b8661904236f13f.zip
chromium_src-20deda2c8abbbe492fb631de3b8661904236f13f.tar.gz
chromium_src-20deda2c8abbbe492fb631de3b8661904236f13f.tar.bz2
Linux: Update PRIMARY selection on omnibox copy-to-clipboard.
This brings us in line with Firefox's behavior. Ctrl-L highlights the URL but doesn't update the PRIMARY selection, so Ctrl-C is a common* way to get the current location into PRIMARY so you can middle-click somewhere else to paste it. * I use it and a user mentioned that they do too. :-P Tested as follows: - highlight some text on the page to make it PRIMARY - hit Ctrl-L and confirm that text on page is still PRIMARY - hit Ctrl-C and confirm that location is now PRIMARY - repeat, but this time hit the right arrow key between Ctrl-L and Ctrl-C to unhighlight the text first. the text on the page should remain the PRIMARY selection BUG=18403 TESTED=see above Review URL: http://codereview.chromium.org/164539 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23596 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc16
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.h5
2 files changed, 21 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..0db115f 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,20 @@ 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.
+ GtkTextIter start, end;
+ if (!gtk_text_buffer_get_selection_bounds(text_buffer_, &start, &end))
+ return;
+
+ gchar* text = gtk_text_buffer_get_text(text_buffer_, &start, &end, FALSE);
+ SavePrimarySelection(text);
+ g_free(text);
+}
+
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).