Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc

Issue 173098: Linux: Attempt #2 at updating PRIMARY selection on Ctrl-C in omnibox. (Closed)
Patch Set: update comment Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit_view_gtk.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h" 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 #include <gdk/gdkkeysyms.h> 8 #include <gdk/gdkkeysyms.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 g_signal_connect(text_view_, "size-request", 203 g_signal_connect(text_view_, "size-request",
204 G_CALLBACK(&HandleViewSizeRequestThunk), this); 204 G_CALLBACK(&HandleViewSizeRequestThunk), this);
205 g_signal_connect(text_view_, "populate-popup", 205 g_signal_connect(text_view_, "populate-popup",
206 G_CALLBACK(&HandlePopulatePopupThunk), this); 206 G_CALLBACK(&HandlePopulatePopupThunk), this);
207 mark_set_handler_id_ = g_signal_connect( 207 mark_set_handler_id_ = g_signal_connect(
208 text_buffer_, "mark-set", G_CALLBACK(&HandleMarkSetThunk), this); 208 text_buffer_, "mark-set", G_CALLBACK(&HandleMarkSetThunk), this);
209 g_signal_connect(text_view_, "drag-data-received", 209 g_signal_connect(text_view_, "drag-data-received",
210 G_CALLBACK(&HandleDragDataReceivedThunk), this); 210 G_CALLBACK(&HandleDragDataReceivedThunk), this);
211 g_signal_connect(text_view_, "backspace", 211 g_signal_connect(text_view_, "backspace",
212 G_CALLBACK(&HandleBackSpaceThunk), this); 212 G_CALLBACK(&HandleBackSpaceThunk), this);
213 g_signal_connect(text_view_, "copy-clipboard",
214 G_CALLBACK(&HandleCopyClipboardThunk), this);
213 215
214 #if !defined(TOOLKIT_VIEWS) 216 #if !defined(TOOLKIT_VIEWS)
215 registrar_.Add(this, 217 registrar_.Add(this,
216 NotificationType::BROWSER_THEME_CHANGED, 218 NotificationType::BROWSER_THEME_CHANGED,
217 NotificationService::AllSources()); 219 NotificationService::AllSources());
218 theme_provider_->InitThemesFor(this); 220 theme_provider_->InitThemesFor(this);
219 #else 221 #else
220 // Manually invoke SetBaseColor() because TOOLKIT_VIEWS doesn't observe 222 // Manually invoke SetBaseColor() because TOOLKIT_VIEWS doesn't observe
221 // themes. 223 // themes.
222 SetBaseColor(); 224 SetBaseColor();
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 916
915 // We're showing a keyword and the user pressed backspace at the beginning 917 // We're showing a keyword and the user pressed backspace at the beginning
916 // of the text. Delete the selected keyword. 918 // of the text. Delete the selected keyword.
917 model_->ClearKeyword(GetText()); 919 model_->ClearKeyword(GetText());
918 920
919 // Stop propagating the signal emission into GtkTextView. 921 // Stop propagating the signal emission into GtkTextView.
920 static guint signal_id = g_signal_lookup("backspace", GTK_TYPE_TEXT_VIEW); 922 static guint signal_id = g_signal_lookup("backspace", GTK_TYPE_TEXT_VIEW);
921 g_signal_stop_emission(text_view_, signal_id, 0); 923 g_signal_stop_emission(text_view_, signal_id, 0);
922 } 924 }
923 925
926 void AutocompleteEditViewGtk::HandleCopyClipboard() {
927 // On copy, we manually update the PRIMARY selection to contain the
928 // highlighted text. This matches Firefox -- we highlight the URL but don't
929 // update PRIMARY on Ctrl-L, so Ctrl-L, Ctrl-C and then middle-click is a
930 // convenient way to paste the current URL somewhere.
931 if (!gtk_text_buffer_get_has_selection(text_buffer_))
932 return;
933
934 GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
935 DCHECK(clipboard);
936 if (!clipboard)
937 return;
938
939 // Passing gtk_text_buffer_copy_clipboard() a text buffer that already owns
940 // the clipboard that's being updated clears the highlighted text, which we
941 // don't want to do (and it also appears to at least sometimes trigger a
942 // failed G_IS_OBJECT() assertion).
943 if (gtk_clipboard_get_owner(clipboard) == G_OBJECT(text_buffer_))
944 return;
945
946 // We can't just call SavePrimarySelection(); that makes the text view lose
947 // the selection and unhighlight its text.
948 gtk_text_buffer_copy_clipboard(text_buffer_, clipboard);
949 }
950
924 void AutocompleteEditViewGtk::SelectAllInternal(bool reversed, 951 void AutocompleteEditViewGtk::SelectAllInternal(bool reversed,
925 bool update_primary_selection) { 952 bool update_primary_selection) {
926 GtkTextIter start, end; 953 GtkTextIter start, end;
927 if (reversed) { 954 if (reversed) {
928 gtk_text_buffer_get_bounds(text_buffer_, &end, &start); 955 gtk_text_buffer_get_bounds(text_buffer_, &end, &start);
929 } else { 956 } else {
930 gtk_text_buffer_get_bounds(text_buffer_, &start, &end); 957 gtk_text_buffer_get_bounds(text_buffer_, &start, &end);
931 } 958 }
932 if (!update_primary_selection) 959 if (!update_primary_selection)
933 StartUpdatingHighlightedText(); 960 StartUpdatingHighlightedText();
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 const std::string& selected_text) { 1076 const std::string& selected_text) {
1050 GtkClipboard* clipboard = 1077 GtkClipboard* clipboard =
1051 gtk_widget_get_clipboard(text_view_, GDK_SELECTION_PRIMARY); 1078 gtk_widget_get_clipboard(text_view_, GDK_SELECTION_PRIMARY);
1052 DCHECK(clipboard); 1079 DCHECK(clipboard);
1053 if (!clipboard) 1080 if (!clipboard)
1054 return; 1081 return;
1055 1082
1056 gtk_clipboard_set_text( 1083 gtk_clipboard_set_text(
1057 clipboard, selected_text.data(), selected_text.size()); 1084 clipboard, selected_text.data(), selected_text.size());
1058 } 1085 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit_view_gtk.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698