| OLD | NEW |
| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 g_signal_connect(text_view_, "size-request", | 202 g_signal_connect(text_view_, "size-request", |
| 203 G_CALLBACK(&HandleViewSizeRequestThunk), this); | 203 G_CALLBACK(&HandleViewSizeRequestThunk), this); |
| 204 g_signal_connect(text_view_, "populate-popup", | 204 g_signal_connect(text_view_, "populate-popup", |
| 205 G_CALLBACK(&HandlePopulatePopupThunk), this); | 205 G_CALLBACK(&HandlePopulatePopupThunk), this); |
| 206 mark_set_handler_id_ = g_signal_connect( | 206 mark_set_handler_id_ = g_signal_connect( |
| 207 text_buffer_, "mark-set", G_CALLBACK(&HandleMarkSetThunk), this); | 207 text_buffer_, "mark-set", G_CALLBACK(&HandleMarkSetThunk), this); |
| 208 g_signal_connect(text_view_, "drag-data-received", | 208 g_signal_connect(text_view_, "drag-data-received", |
| 209 G_CALLBACK(&HandleDragDataReceivedThunk), this); | 209 G_CALLBACK(&HandleDragDataReceivedThunk), this); |
| 210 g_signal_connect(text_view_, "backspace", | 210 g_signal_connect(text_view_, "backspace", |
| 211 G_CALLBACK(&HandleBackSpaceThunk), this); | 211 G_CALLBACK(&HandleBackSpaceThunk), this); |
| 212 g_signal_connect(text_view_, "copy-clipboard", |
| 213 G_CALLBACK(&HandleCopyClipboardThunk), this); |
| 212 | 214 |
| 213 #if !defined(TOOLKIT_VIEWS) | 215 #if !defined(TOOLKIT_VIEWS) |
| 214 registrar_.Add(this, | 216 registrar_.Add(this, |
| 215 NotificationType::BROWSER_THEME_CHANGED, | 217 NotificationType::BROWSER_THEME_CHANGED, |
| 216 NotificationService::AllSources()); | 218 NotificationService::AllSources()); |
| 217 theme_provider_->InitThemesFor(this); | 219 theme_provider_->InitThemesFor(this); |
| 218 #else | 220 #else |
| 219 // Manually invoke SetBaseColor() because TOOLKIT_VIEWS doesn't observe | 221 // Manually invoke SetBaseColor() because TOOLKIT_VIEWS doesn't observe |
| 220 // themes. | 222 // themes. |
| 221 SetBaseColor(); | 223 SetBaseColor(); |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 | 902 |
| 901 // We're showing a keyword and the user pressed backspace at the beginning | 903 // We're showing a keyword and the user pressed backspace at the beginning |
| 902 // of the text. Delete the selected keyword. | 904 // of the text. Delete the selected keyword. |
| 903 model_->ClearKeyword(GetText()); | 905 model_->ClearKeyword(GetText()); |
| 904 | 906 |
| 905 // Stop propagating the signal emission into GtkTextView. | 907 // Stop propagating the signal emission into GtkTextView. |
| 906 static guint signal_id = g_signal_lookup("backspace", GTK_TYPE_TEXT_VIEW); | 908 static guint signal_id = g_signal_lookup("backspace", GTK_TYPE_TEXT_VIEW); |
| 907 g_signal_stop_emission(text_view_, signal_id, 0); | 909 g_signal_stop_emission(text_view_, signal_id, 0); |
| 908 } | 910 } |
| 909 | 911 |
| 912 void AutocompleteEditViewGtk::HandleCopyClipboard() { |
| 913 // On copy, we manually update the PRIMARY selection to contain the |
| 914 // highlighted text. This matches Firefox -- we highlight the URL but don't |
| 915 // update PRIMARY on Ctrl-L, so Ctrl-L, Ctrl-C and then middle-click is a |
| 916 // convenient way to paste the current URL somewhere. |
| 917 GtkTextIter start, end; |
| 918 if (!gtk_text_buffer_get_selection_bounds(text_buffer_, &start, &end)) |
| 919 return; |
| 920 |
| 921 gchar* text = gtk_text_buffer_get_text(text_buffer_, &start, &end, FALSE); |
| 922 SavePrimarySelection(text); |
| 923 g_free(text); |
| 924 } |
| 925 |
| 910 void AutocompleteEditViewGtk::SelectAllInternal(bool reversed, | 926 void AutocompleteEditViewGtk::SelectAllInternal(bool reversed, |
| 911 bool update_primary_selection) { | 927 bool update_primary_selection) { |
| 912 GtkTextIter start, end; | 928 GtkTextIter start, end; |
| 913 if (reversed) { | 929 if (reversed) { |
| 914 gtk_text_buffer_get_bounds(text_buffer_, &end, &start); | 930 gtk_text_buffer_get_bounds(text_buffer_, &end, &start); |
| 915 } else { | 931 } else { |
| 916 gtk_text_buffer_get_bounds(text_buffer_, &start, &end); | 932 gtk_text_buffer_get_bounds(text_buffer_, &start, &end); |
| 917 } | 933 } |
| 918 if (!update_primary_selection) | 934 if (!update_primary_selection) |
| 919 StartUpdatingHighlightedText(); | 935 StartUpdatingHighlightedText(); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1035 const std::string& selected_text) { | 1051 const std::string& selected_text) { |
| 1036 GtkClipboard* clipboard = | 1052 GtkClipboard* clipboard = |
| 1037 gtk_widget_get_clipboard(text_view_, GDK_SELECTION_PRIMARY); | 1053 gtk_widget_get_clipboard(text_view_, GDK_SELECTION_PRIMARY); |
| 1038 DCHECK(clipboard); | 1054 DCHECK(clipboard); |
| 1039 if (!clipboard) | 1055 if (!clipboard) |
| 1040 return; | 1056 return; |
| 1041 | 1057 |
| 1042 gtk_clipboard_set_text( | 1058 gtk_clipboard_set_text( |
| 1043 clipboard, selected_text.data(), selected_text.size()); | 1059 clipboard, selected_text.data(), selected_text.size()); |
| 1044 } | 1060 } |
| OLD | NEW |