OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 // Now the last thing is to prevent the content of omnibox from being changed | 885 // Now the last thing is to prevent the content of omnibox from being changed |
886 // by GtkTextView when Enter key is pressed. As OnBeforePossibleChange() and | 886 // by GtkTextView when Enter key is pressed. As OnBeforePossibleChange() and |
887 // OnAfterPossibleChange() will be called by GtkTextView before and after | 887 // OnAfterPossibleChange() will be called by GtkTextView before and after |
888 // changing the content, and the content is already saved in | 888 // changing the content, and the content is already saved in |
889 // OnBeforePossibleChange(), so if the Enter key press event was not handled | 889 // OnBeforePossibleChange(), so if the Enter key press event was not handled |
890 // by IME, it's easy to restore the content in OnAfterPossibleChange(), as if | 890 // by IME, it's easy to restore the content in OnAfterPossibleChange(), as if |
891 // it's not changed at all. | 891 // it's not changed at all. |
892 | 892 |
893 GtkWidgetClass* klass = GTK_WIDGET_GET_CLASS(widget); | 893 GtkWidgetClass* klass = GTK_WIDGET_GET_CLASS(widget); |
894 | 894 |
895 enter_was_pressed_ = (event->keyval == GDK_Return || | 895 enter_was_pressed_ = event->keyval == GDK_Return || |
896 event->keyval == GDK_ISO_Enter || | 896 event->keyval == GDK_ISO_Enter || |
897 event->keyval == GDK_KP_Enter); | 897 event->keyval == GDK_KP_Enter; |
898 | 898 |
899 // Set |tab_was_pressed_| to true if it's a Tab key press event, so that our | 899 // Set |tab_was_pressed_| to true if it's a Tab key press event, so that our |
900 // handler of "move-focus" signal can trigger Tab to search behavior when | 900 // handler of "move-focus" signal can trigger Tab to search behavior when |
901 // necessary. | 901 // necessary. |
902 tab_was_pressed_ = ((event->keyval == GDK_Tab || | 902 tab_was_pressed_ = (event->keyval == GDK_Tab || |
903 event->keyval == GDK_ISO_Left_Tab || | 903 event->keyval == GDK_ISO_Left_Tab || |
904 event->keyval == GDK_KP_Tab) && | 904 event->keyval == GDK_KP_Tab) && |
905 !(event->state & GDK_CONTROL_MASK)); | 905 !(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)); |
906 | 906 |
907 delete_was_pressed_ = (event->keyval == GDK_Delete || | 907 delete_was_pressed_ = event->keyval == GDK_Delete || |
908 event->keyval == GDK_KP_Delete); | 908 event->keyval == GDK_KP_Delete; |
909 | 909 |
910 // Reset |enter_was_inserted_|, which may be set in the "insert-text" signal | 910 // Reset |enter_was_inserted_|, which may be set in the "insert-text" signal |
911 // handler, so that we'll know if an Enter key event was handled by IME. | 911 // handler, so that we'll know if an Enter key event was handled by IME. |
912 enter_was_inserted_ = false; | 912 enter_was_inserted_ = false; |
913 | 913 |
914 // Reset |paste_clipboard_requested_| to make sure we won't misinterpret this | 914 // Reset |paste_clipboard_requested_| to make sure we won't misinterpret this |
915 // key input action as a paste action. | 915 // key input action as a paste action. |
916 paste_clipboard_requested_ = false; | 916 paste_clipboard_requested_ = false; |
917 | 917 |
918 // Reset |text_changed_| before passing the key event on to the text view. | 918 // Reset |text_changed_| before passing the key event on to the text view. |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1378 // of the text. Delete the selected keyword. | 1378 // of the text. Delete the selected keyword. |
1379 model_->ClearKeyword(GetText()); | 1379 model_->ClearKeyword(GetText()); |
1380 | 1380 |
1381 // Stop propagating the signal emission into GtkTextView. | 1381 // Stop propagating the signal emission into GtkTextView. |
1382 static guint signal_id = g_signal_lookup("backspace", GTK_TYPE_TEXT_VIEW); | 1382 static guint signal_id = g_signal_lookup("backspace", GTK_TYPE_TEXT_VIEW); |
1383 g_signal_stop_emission(text_view_, signal_id, 0); | 1383 g_signal_stop_emission(text_view_, signal_id, 0); |
1384 } | 1384 } |
1385 | 1385 |
1386 void AutocompleteEditViewGtk::HandleViewMoveFocus(GtkWidget* widget, | 1386 void AutocompleteEditViewGtk::HandleViewMoveFocus(GtkWidget* widget, |
1387 GtkDirectionType direction) { | 1387 GtkDirectionType direction) { |
| 1388 if (!tab_was_pressed_) |
| 1389 return; |
| 1390 |
| 1391 // If special behavior is triggered, then stop the signal emission to |
| 1392 // prevent the focus from being moved. |
| 1393 bool handled = false; |
| 1394 |
1388 // Trigger Tab to search behavior only when Tab key is pressed. | 1395 // Trigger Tab to search behavior only when Tab key is pressed. |
1389 if (tab_was_pressed_ && enable_tab_to_search_ && | 1396 if (model_->is_keyword_hint() && !model_->keyword().empty()) { |
1390 model_->is_keyword_hint() && !model_->keyword().empty()) { | 1397 if (enable_tab_to_search_) { |
1391 model_->AcceptKeyword(); | 1398 model_->AcceptKeyword(); |
| 1399 handled = true; |
| 1400 } |
| 1401 } else { |
| 1402 if (GTK_WIDGET_VISIBLE(instant_view_)) { |
| 1403 controller_->OnCommitSuggestedText(GetText()); |
| 1404 handled = true; |
| 1405 } else { |
| 1406 handled = controller_->AcceptCurrentInstantPreview(); |
| 1407 } |
| 1408 } |
1392 | 1409 |
1393 // If Tab to search behavior is triggered, then stop the signal emission to | 1410 if (handled) { |
1394 // prevent the focus from being moved. | |
1395 static guint signal_id = g_signal_lookup("move-focus", GTK_TYPE_WIDGET); | 1411 static guint signal_id = g_signal_lookup("move-focus", GTK_TYPE_WIDGET); |
1396 g_signal_stop_emission(widget, signal_id, 0); | 1412 g_signal_stop_emission(widget, signal_id, 0); |
1397 } | 1413 } |
1398 | |
1399 // Propagate the signal so that focus can be moved as normal. | |
1400 } | 1414 } |
1401 | 1415 |
1402 void AutocompleteEditViewGtk::HandleCopyClipboard(GtkWidget* sender) { | 1416 void AutocompleteEditViewGtk::HandleCopyClipboard(GtkWidget* sender) { |
1403 HandleCopyOrCutClipboard(true); | 1417 HandleCopyOrCutClipboard(true); |
1404 } | 1418 } |
1405 | 1419 |
1406 void AutocompleteEditViewGtk::HandleCutClipboard(GtkWidget* sender) { | 1420 void AutocompleteEditViewGtk::HandleCutClipboard(GtkWidget* sender) { |
1407 HandleCopyOrCutClipboard(false); | 1421 HandleCopyOrCutClipboard(false); |
1408 } | 1422 } |
1409 | 1423 |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1958 // baseline, so we need to move the |instant_view_| down to make sure it | 1972 // baseline, so we need to move the |instant_view_| down to make sure it |
1959 // has the same baseline as the |text_view_|. | 1973 // has the same baseline as the |text_view_|. |
1960 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); | 1974 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); |
1961 int height; | 1975 int height; |
1962 pango_layout_get_size(layout, NULL, &height); | 1976 pango_layout_get_size(layout, NULL, &height); |
1963 PangoLayoutIter* iter = pango_layout_get_iter(layout); | 1977 PangoLayoutIter* iter = pango_layout_get_iter(layout); |
1964 int baseline = pango_layout_iter_get_baseline(iter); | 1978 int baseline = pango_layout_iter_get_baseline(iter); |
1965 pango_layout_iter_free(iter); | 1979 pango_layout_iter_free(iter); |
1966 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); | 1980 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); |
1967 } | 1981 } |
OLD | NEW |