Chromium Code Reviews| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 text_selected_during_click_(false), | 177 text_selected_during_click_(false), |
| 178 text_view_focused_before_button_press_(false), | 178 text_view_focused_before_button_press_(false), |
| 179 #endif | 179 #endif |
| 180 #if !defined(TOOLKIT_VIEWS) | 180 #if !defined(TOOLKIT_VIEWS) |
| 181 theme_provider_(GtkThemeProvider::GetFrom(profile)), | 181 theme_provider_(GtkThemeProvider::GetFrom(profile)), |
| 182 #endif | 182 #endif |
| 183 enter_was_pressed_(false), | 183 enter_was_pressed_(false), |
| 184 tab_was_pressed_(false), | 184 tab_was_pressed_(false), |
| 185 paste_clipboard_requested_(false), | 185 paste_clipboard_requested_(false), |
| 186 enter_was_inserted_(false), | 186 enter_was_inserted_(false), |
| 187 enable_tab_to_search_(true), | |
| 188 selection_suggested_(false), | 187 selection_suggested_(false), |
| 189 delete_was_pressed_(false), | 188 delete_was_pressed_(false), |
| 190 delete_at_end_pressed_(false), | 189 delete_at_end_pressed_(false), |
| 191 handling_key_press_(false), | 190 handling_key_press_(false), |
| 192 content_maybe_changed_by_key_press_(false), | 191 content_maybe_changed_by_key_press_(false), |
| 193 #if GTK_CHECK_VERSION(2, 20, 0) | 192 #if GTK_CHECK_VERSION(2, 20, 0) |
| 194 preedit_size_before_change_(0), | 193 preedit_size_before_change_(0), |
| 195 #endif | 194 #endif |
| 196 going_to_focus_(NULL) { | 195 going_to_focus_(NULL) { |
| 197 model_->SetPopupModel(popup_view_->GetModel()); | 196 model_->SetPopupModel(popup_view_->GetModel()); |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 648 FinishUpdatingHighlightedText(); | 647 FinishUpdatingHighlightedText(); |
| 649 TextChanged(); | 648 TextChanged(); |
| 650 } | 649 } |
| 651 | 650 |
| 652 void AutocompleteEditViewGtk::OnBeforePossibleChange() { | 651 void AutocompleteEditViewGtk::OnBeforePossibleChange() { |
| 653 // If this change is caused by a paste clipboard action and all text is | 652 // If this change is caused by a paste clipboard action and all text is |
| 654 // selected, then call model_->on_paste_replacing_all() to prevent inline | 653 // selected, then call model_->on_paste_replacing_all() to prevent inline |
| 655 // autocomplete. | 654 // autocomplete. |
| 656 if (paste_clipboard_requested_) { | 655 if (paste_clipboard_requested_) { |
| 657 paste_clipboard_requested_ = false; | 656 paste_clipboard_requested_ = false; |
| 658 if (IsSelectAll()) | 657 model_->OnPaste(IsSelectAll()); |
| 659 model_->on_paste_replacing_all(); | |
| 660 } | 658 } |
| 661 | 659 |
| 662 // This method will be called in HandleKeyPress() method just before | 660 // This method will be called in HandleKeyPress() method just before |
| 663 // handling a key press event. So we should prevent it from being called | 661 // handling a key press event. So we should prevent it from being called |
| 664 // when handling the key press event. | 662 // when handling the key press event. |
| 665 if (handling_key_press_) | 663 if (handling_key_press_) |
| 666 return; | 664 return; |
| 667 | 665 |
| 668 // Record our state. | 666 // Record our state. |
| 669 text_before_change_ = GetText(); | 667 text_before_change_ = GetText(); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 689 // PRIMARY selection from being changed. | 687 // PRIMARY selection from being changed. |
| 690 if (enter_was_pressed_ && enter_was_inserted_) { | 688 if (enter_was_pressed_ && enter_was_inserted_) { |
| 691 StartUpdatingHighlightedText(); | 689 StartUpdatingHighlightedText(); |
| 692 SetTextAndSelectedRange(text_before_change_, sel_before_change_); | 690 SetTextAndSelectedRange(text_before_change_, sel_before_change_); |
| 693 FinishUpdatingHighlightedText(); | 691 FinishUpdatingHighlightedText(); |
| 694 return false; | 692 return false; |
| 695 } | 693 } |
| 696 | 694 |
| 697 CharRange new_sel = GetSelection(); | 695 CharRange new_sel = GetSelection(); |
| 698 int length = GetTextLength(); | 696 int length = GetTextLength(); |
| 699 bool selection_differs = (new_sel.cp_min != sel_before_change_.cp_min) || | 697 bool selection_differs = (!sel_before_change_.empty() || !new_sel.empty()) && |
| 700 (new_sel.cp_max != sel_before_change_.cp_max); | 698 ((new_sel.cp_min != sel_before_change_.cp_min) || |
| 699 (new_sel.cp_max != sel_before_change_.cp_max)); | |
| 701 bool at_end_of_edit = (new_sel.cp_min == length && new_sel.cp_max == length); | 700 bool at_end_of_edit = (new_sel.cp_min == length && new_sel.cp_max == length); |
| 702 | 701 |
| 703 // See if the text or selection have changed since OnBeforePossibleChange(). | 702 // See if the text or selection have changed since OnBeforePossibleChange(). |
| 704 std::wstring new_text(GetText()); | 703 std::wstring new_text(GetText()); |
| 705 text_changed_ = (new_text != text_before_change_); | 704 text_changed_ = (new_text != text_before_change_); |
| 706 #if GTK_CHECK_VERSION(2, 20, 0) | 705 #if GTK_CHECK_VERSION(2, 20, 0) |
| 707 text_changed_ = | 706 text_changed_ = |
| 708 text_changed_ || (preedit_.size() != preedit_size_before_change_); | 707 text_changed_ || (preedit_.size() != preedit_size_before_change_); |
| 709 #endif | 708 #endif |
| 710 | 709 |
| (...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1619 void AutocompleteEditViewGtk::HandleViewMoveFocus(GtkWidget* widget, | 1618 void AutocompleteEditViewGtk::HandleViewMoveFocus(GtkWidget* widget, |
| 1620 GtkDirectionType direction) { | 1619 GtkDirectionType direction) { |
| 1621 if (!tab_was_pressed_) | 1620 if (!tab_was_pressed_) |
| 1622 return; | 1621 return; |
| 1623 | 1622 |
| 1624 // If special behavior is triggered, then stop the signal emission to | 1623 // If special behavior is triggered, then stop the signal emission to |
| 1625 // prevent the focus from being moved. | 1624 // prevent the focus from being moved. |
| 1626 bool handled = false; | 1625 bool handled = false; |
| 1627 | 1626 |
| 1628 // Trigger Tab to search behavior only when Tab key is pressed. | 1627 // Trigger Tab to search behavior only when Tab key is pressed. |
| 1629 if (model_->is_keyword_hint() && !model_->keyword().empty()) { | 1628 if (model_->is_keyword_hint()) { |
| 1630 if (enable_tab_to_search_) { | 1629 model_->AcceptKeyword(); |
|
Peter Kasting
2011/01/20 00:04:22
Nit: If you change AcceptKeyword() to return true,
James Su
2011/01/20 06:49:31
Done.
| |
| 1631 model_->AcceptKeyword(); | 1630 handled = true; |
| 1632 handled = true; | 1631 } else if (GTK_WIDGET_VISIBLE(instant_view_)) { |
| 1633 } | 1632 controller_->OnCommitSuggestedText(GetText()); |
| 1633 handled = true; | |
| 1634 } else { | 1634 } else { |
| 1635 if (GTK_WIDGET_VISIBLE(instant_view_)) { | 1635 handled = controller_->AcceptCurrentInstantPreview(); |
| 1636 controller_->OnCommitSuggestedText(GetText()); | |
| 1637 handled = true; | |
| 1638 } else { | |
| 1639 handled = controller_->AcceptCurrentInstantPreview(); | |
| 1640 } | |
| 1641 } | 1636 } |
| 1642 | 1637 |
| 1643 if (handled) { | 1638 if (handled) { |
| 1644 static guint signal_id = g_signal_lookup("move-focus", GTK_TYPE_WIDGET); | 1639 static guint signal_id = g_signal_lookup("move-focus", GTK_TYPE_WIDGET); |
| 1645 g_signal_stop_emission(widget, signal_id, 0); | 1640 g_signal_stop_emission(widget, signal_id, 0); |
| 1646 } | 1641 } |
| 1647 } | 1642 } |
| 1648 | 1643 |
| 1649 void AutocompleteEditViewGtk::HandleCopyClipboard(GtkWidget* sender) { | 1644 void AutocompleteEditViewGtk::HandleCopyClipboard(GtkWidget* sender) { |
| 1650 HandleCopyOrCutClipboard(true); | 1645 HandleCopyOrCutClipboard(true); |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2211 // baseline, so we need to move the |instant_view_| down to make sure it | 2206 // baseline, so we need to move the |instant_view_| down to make sure it |
| 2212 // has the same baseline as the |text_view_|. | 2207 // has the same baseline as the |text_view_|. |
| 2213 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); | 2208 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); |
| 2214 int height; | 2209 int height; |
| 2215 pango_layout_get_size(layout, NULL, &height); | 2210 pango_layout_get_size(layout, NULL, &height); |
| 2216 PangoLayoutIter* iter = pango_layout_get_iter(layout); | 2211 PangoLayoutIter* iter = pango_layout_get_iter(layout); |
| 2217 int baseline = pango_layout_iter_get_baseline(iter); | 2212 int baseline = pango_layout_iter_get_baseline(iter); |
| 2218 pango_layout_iter_free(iter); | 2213 pango_layout_iter_free(iter); |
| 2219 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); | 2214 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); |
| 2220 } | 2215 } |
| OLD | NEW |