| 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 "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 G_CALLBACK(&HandleViewMoveCursorThunk), this); | 185 G_CALLBACK(&HandleViewMoveCursorThunk), this); |
| 186 // Override the size request. We want to keep the original height request | 186 // Override the size request. We want to keep the original height request |
| 187 // from the widget, since that's font dependent. We want to ignore the width | 187 // from the widget, since that's font dependent. We want to ignore the width |
| 188 // so we don't force a minimum width based on the text length. | 188 // so we don't force a minimum width based on the text length. |
| 189 g_signal_connect(text_view_, "size-request", | 189 g_signal_connect(text_view_, "size-request", |
| 190 G_CALLBACK(&HandleViewSizeRequestThunk), this); | 190 G_CALLBACK(&HandleViewSizeRequestThunk), this); |
| 191 g_signal_connect(text_view_, "populate-popup", | 191 g_signal_connect(text_view_, "populate-popup", |
| 192 G_CALLBACK(&HandlePopulatePopupThunk), this); | 192 G_CALLBACK(&HandlePopulatePopupThunk), this); |
| 193 mark_set_handler_id_ = g_signal_connect( | 193 mark_set_handler_id_ = g_signal_connect( |
| 194 text_buffer_, "mark-set", G_CALLBACK(&HandleMarkSetThunk), this); | 194 text_buffer_, "mark-set", G_CALLBACK(&HandleMarkSetThunk), this); |
| 195 g_signal_connect(text_view_, "drag-data-received", |
| 196 G_CALLBACK(&HandleDragDataReceivedThunk), this); |
| 195 } | 197 } |
| 196 | 198 |
| 197 void AutocompleteEditViewGtk::SetFocus() { | 199 void AutocompleteEditViewGtk::SetFocus() { |
| 198 gtk_widget_grab_focus(text_view_); | 200 gtk_widget_grab_focus(text_view_); |
| 199 } | 201 } |
| 200 | 202 |
| 201 void AutocompleteEditViewGtk::SaveStateToTab(TabContents* tab) { | 203 void AutocompleteEditViewGtk::SaveStateToTab(TabContents* tab) { |
| 202 DCHECK(tab); | 204 DCHECK(tab); |
| 203 GetStateAccessor()->SetProperty( | 205 GetStateAccessor()->SetProperty( |
| 204 tab->property_bag(), | 206 tab->property_bag(), |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 } | 666 } |
| 665 | 667 |
| 666 // If we have some previously-selected text but it's no longer highlighted | 668 // If we have some previously-selected text but it's no longer highlighted |
| 667 // and we haven't saved it as the selection yet, we save it now. | 669 // and we haven't saved it as the selection yet, we save it now. |
| 668 if (!selected_text_.empty() && no_text_selected && !selection_saved_) { | 670 if (!selected_text_.empty() && no_text_selected && !selection_saved_) { |
| 669 SavePrimarySelection(selected_text_); | 671 SavePrimarySelection(selected_text_); |
| 670 selection_saved_ = true; | 672 selection_saved_ = true; |
| 671 } | 673 } |
| 672 } | 674 } |
| 673 | 675 |
| 676 // Just use the default behavior for DnD, except if the drop can be a PasteAndGo |
| 677 // then override. |
| 678 void AutocompleteEditViewGtk::HandleDragDataReceived( |
| 679 GdkDragContext* context, gint x, gint y, |
| 680 GtkSelectionData* selection_data, guint target_type, guint time) { |
| 681 // Don't try to PasteAndGo on drops originating from this omnibox. However, do |
| 682 // allow default behavior for such drags. |
| 683 if (context->source_window == text_view_->window) |
| 684 return; |
| 685 |
| 686 guchar* text = gtk_selection_data_get_text(selection_data); |
| 687 if (!text) |
| 688 return; |
| 689 |
| 690 std::wstring possible_url = UTF8ToWide(reinterpret_cast<char*>(text)); |
| 691 g_free(text); |
| 692 if (model_->CanPasteAndGo(CollapseWhitespace(possible_url, true))) { |
| 693 model_->PasteAndGo(); |
| 694 gtk_drag_finish(context, TRUE, TRUE, time); |
| 695 g_signal_stop_emission_by_name(text_view_, "drag-data-received"); |
| 696 } |
| 697 } |
| 698 |
| 674 void AutocompleteEditViewGtk::SelectAllInternal(bool reversed, | 699 void AutocompleteEditViewGtk::SelectAllInternal(bool reversed, |
| 675 bool update_primary_selection) { | 700 bool update_primary_selection) { |
| 676 GtkTextIter start, end; | 701 GtkTextIter start, end; |
| 677 if (reversed) { | 702 if (reversed) { |
| 678 gtk_text_buffer_get_bounds(text_buffer_, &end, &start); | 703 gtk_text_buffer_get_bounds(text_buffer_, &end, &start); |
| 679 } else { | 704 } else { |
| 680 gtk_text_buffer_get_bounds(text_buffer_, &start, &end); | 705 gtk_text_buffer_get_bounds(text_buffer_, &start, &end); |
| 681 } | 706 } |
| 682 if (!update_primary_selection) | 707 if (!update_primary_selection) |
| 683 StartUpdatingHighlightedText(); | 708 StartUpdatingHighlightedText(); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 const std::string& selected_text) { | 828 const std::string& selected_text) { |
| 804 GtkClipboard* clipboard = | 829 GtkClipboard* clipboard = |
| 805 gtk_widget_get_clipboard(text_view_, GDK_SELECTION_PRIMARY); | 830 gtk_widget_get_clipboard(text_view_, GDK_SELECTION_PRIMARY); |
| 806 DCHECK(clipboard); | 831 DCHECK(clipboard); |
| 807 if (!clipboard) | 832 if (!clipboard) |
| 808 return; | 833 return; |
| 809 | 834 |
| 810 gtk_clipboard_set_text( | 835 gtk_clipboard_set_text( |
| 811 clipboard, selected_text.data(), selected_text.size()); | 836 clipboard, selected_text.data(), selected_text.size()); |
| 812 } | 837 } |
| OLD | NEW |