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

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

Issue 6252003: Accept keyword by pressing space. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Only allow 0x0020 and 0x3000 for now. Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <gdk/gdkkeysyms.h> 7 #include <gdk/gdkkeysyms.h>
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 } 642 }
644 643
645 void AutocompleteEditViewGtk::OnRevertTemporaryText() { 644 void AutocompleteEditViewGtk::OnRevertTemporaryText() {
646 StartUpdatingHighlightedText(); 645 StartUpdatingHighlightedText();
647 SetSelectedRange(saved_temporary_selection_); 646 SetSelectedRange(saved_temporary_selection_);
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 // Record this paste, so we can do different behavior.
654 // selected, then call model_->on_paste_replacing_all() to prevent inline
655 // autocomplete.
656 if (paste_clipboard_requested_) { 653 if (paste_clipboard_requested_) {
657 paste_clipboard_requested_ = false; 654 paste_clipboard_requested_ = false;
658 if (IsSelectAll()) 655 model_->on_paste();
659 model_->on_paste_replacing_all();
660 } 656 }
661 657
662 // This method will be called in HandleKeyPress() method just before 658 // This method will be called in HandleKeyPress() method just before
663 // handling a key press event. So we should prevent it from being called 659 // handling a key press event. So we should prevent it from being called
664 // when handling the key press event. 660 // when handling the key press event.
665 if (handling_key_press_) 661 if (handling_key_press_)
666 return; 662 return;
667 663
668 // Record our state. 664 // Record our state.
669 text_before_change_ = GetText(); 665 text_before_change_ = GetText();
(...skipping 19 matching lines...) Expand all
689 // PRIMARY selection from being changed. 685 // PRIMARY selection from being changed.
690 if (enter_was_pressed_ && enter_was_inserted_) { 686 if (enter_was_pressed_ && enter_was_inserted_) {
691 StartUpdatingHighlightedText(); 687 StartUpdatingHighlightedText();
692 SetTextAndSelectedRange(text_before_change_, sel_before_change_); 688 SetTextAndSelectedRange(text_before_change_, sel_before_change_);
693 FinishUpdatingHighlightedText(); 689 FinishUpdatingHighlightedText();
694 return false; 690 return false;
695 } 691 }
696 692
697 CharRange new_sel = GetSelection(); 693 CharRange new_sel = GetSelection();
698 int length = GetTextLength(); 694 int length = GetTextLength();
699 bool selection_differs = (new_sel.cp_min != sel_before_change_.cp_min) || 695 bool selection_differs =
700 (new_sel.cp_max != sel_before_change_.cp_max); 696 ((new_sel.cp_min != new_sel.cp_max) ||
697 (sel_before_change_.cp_min != 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
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 handled = model_->AcceptKeyword();
1631 model_->AcceptKeyword(); 1630 } else if (GTK_WIDGET_VISIBLE(instant_view_)) {
1632 handled = true; 1631 controller_->OnCommitSuggestedText(GetText());
1633 } 1632 handled = true;
1634 } else { 1633 } else {
1635 if (GTK_WIDGET_VISIBLE(instant_view_)) { 1634 handled = controller_->AcceptCurrentInstantPreview();
1636 controller_->OnCommitSuggestedText(GetText());
1637 handled = true;
1638 } else {
1639 handled = controller_->AcceptCurrentInstantPreview();
1640 }
1641 } 1635 }
1642 1636
1643 if (handled) { 1637 if (handled) {
1644 static guint signal_id = g_signal_lookup("move-focus", GTK_TYPE_WIDGET); 1638 static guint signal_id = g_signal_lookup("move-focus", GTK_TYPE_WIDGET);
1645 g_signal_stop_emission(widget, signal_id, 0); 1639 g_signal_stop_emission(widget, signal_id, 0);
1646 } 1640 }
1647 } 1641 }
1648 1642
1649 void AutocompleteEditViewGtk::HandleCopyClipboard(GtkWidget* sender) { 1643 void AutocompleteEditViewGtk::HandleCopyClipboard(GtkWidget* sender) {
1650 HandleCopyOrCutClipboard(true); 1644 HandleCopyOrCutClipboard(true);
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
2211 // baseline, so we need to move the |instant_view_| down to make sure it 2205 // baseline, so we need to move the |instant_view_| down to make sure it
2212 // has the same baseline as the |text_view_|. 2206 // has the same baseline as the |text_view_|.
2213 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); 2207 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_));
2214 int height; 2208 int height;
2215 pango_layout_get_size(layout, NULL, &height); 2209 pango_layout_get_size(layout, NULL, &height);
2216 PangoLayoutIter* iter = pango_layout_get_iter(layout); 2210 PangoLayoutIter* iter = pango_layout_get_iter(layout);
2217 int baseline = pango_layout_iter_get_baseline(iter); 2211 int baseline = pango_layout_iter_get_baseline(iter);
2218 pango_layout_iter_free(iter); 2212 pango_layout_iter_free(iter);
2219 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); 2213 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL);
2220 } 2214 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit_view_gtk.h ('k') | chrome/browser/autocomplete/autocomplete_edit_view_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698