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

Side by Side Diff: chrome/browser/ui/omnibox/omnibox_edit_model.cc

Issue 11414303: Make Google Search autocomplete provider cursor aware. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 8 years 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/ui/omnibox/omnibox_edit_model.h" 5 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // OmniboxEditModel 84 // OmniboxEditModel
85 85
86 OmniboxEditModel::OmniboxEditModel(OmniboxView* view, 86 OmniboxEditModel::OmniboxEditModel(OmniboxView* view,
87 OmniboxEditController* controller, 87 OmniboxEditController* controller,
88 Profile* profile) 88 Profile* profile)
89 : view_(view), 89 : view_(view),
90 popup_(NULL), 90 popup_(NULL),
91 controller_(controller), 91 controller_(controller),
92 has_focus_(false), 92 has_focus_(false),
93 user_input_in_progress_(false), 93 user_input_in_progress_(false),
94 cursor_position_(string16::npos),
94 just_deleted_text_(false), 95 just_deleted_text_(false),
95 has_temporary_text_(false), 96 has_temporary_text_(false),
96 is_temporary_text_set_by_instant_(false), 97 is_temporary_text_set_by_instant_(false),
97 paste_state_(NONE), 98 paste_state_(NONE),
98 control_key_state_(UP), 99 control_key_state_(UP),
99 is_keyword_hint_(false), 100 is_keyword_hint_(false),
100 profile_(profile), 101 profile_(profile),
101 in_revert_(false), 102 in_revert_(false),
102 allow_exact_keyword_match_(false) { 103 allow_exact_keyword_match_(false) {
103 // Use a restricted subset of the autocomplete providers if we're using the 104 // Use a restricted subset of the autocomplete providers if we're using the
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 443
443 void OmniboxEditModel::StartAutocomplete( 444 void OmniboxEditModel::StartAutocomplete(
444 bool has_selected_text, 445 bool has_selected_text,
445 bool prevent_inline_autocomplete) const { 446 bool prevent_inline_autocomplete) const {
446 ClearPopupKeywordMode(); 447 ClearPopupKeywordMode();
447 448
448 bool keyword_is_selected = KeywordIsSelected(); 449 bool keyword_is_selected = KeywordIsSelected();
449 popup_->SetHoveredLine(OmniboxPopupModel::kNoMatch); 450 popup_->SetHoveredLine(OmniboxPopupModel::kNoMatch);
450 // We don't explicitly clear OmniboxPopupModel::manually_selected_match, as 451 // We don't explicitly clear OmniboxPopupModel::manually_selected_match, as
451 // Start ends up invoking OmniboxPopupModel::OnResultChanged which clears it. 452 // Start ends up invoking OmniboxPopupModel::OnResultChanged which clears it.
452 autocomplete_controller_->Start( 453 autocomplete_controller_->Start(AutocompleteInput(
453 user_text_, GetDesiredTLD(), 454 user_text_, cursor_position_, GetDesiredTLD(),
454 prevent_inline_autocomplete || just_deleted_text_ || 455 prevent_inline_autocomplete || just_deleted_text_ ||
455 (has_selected_text && inline_autocomplete_text_.empty()) || 456 (has_selected_text && inline_autocomplete_text_.empty()) ||
456 (paste_state_ != NONE), keyword_is_selected, 457 (paste_state_ != NONE), keyword_is_selected,
457 keyword_is_selected || allow_exact_keyword_match_, 458 keyword_is_selected || allow_exact_keyword_match_,
458 AutocompleteInput::ALL_MATCHES); 459 AutocompleteInput::ALL_MATCHES));
459 } 460 }
460 461
461 void OmniboxEditModel::StopAutocomplete() { 462 void OmniboxEditModel::StopAutocomplete() {
462 autocomplete_controller_->Stop(true); 463 autocomplete_controller_->Stop(true);
463 } 464 }
464 465
465 bool OmniboxEditModel::CanPasteAndGo(const string16& text) const { 466 bool OmniboxEditModel::CanPasteAndGo(const string16& text) const {
466 if (!view_->command_updater()->IsCommandEnabled(IDC_OPEN_CURRENT_URL)) 467 if (!view_->command_updater()->IsCommandEnabled(IDC_OPEN_CURRENT_URL))
467 return false; 468 return false;
468 469
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 has_temporary_text_ = false; 960 has_temporary_text_ = false;
960 is_temporary_text_set_by_instant_ = false; 961 is_temporary_text_set_by_instant_ = false;
961 962
962 // Track when the user has deleted text so we won't allow inline 963 // Track when the user has deleted text so we won't allow inline
963 // autocomplete. 964 // autocomplete.
964 just_deleted_text_ = just_deleted_text; 965 just_deleted_text_ = just_deleted_text;
965 } 966 }
966 967
967 const bool no_selection = selection_start == selection_end; 968 const bool no_selection = selection_start == selection_end;
968 969
970 // Update the cursor position based on the current selection. This works fine
971 // even if there is |no_selection|.
972 cursor_position_ = selection_start >= user_text_.length() ? string16::npos
973 : selection_start;
974
969 // Update the popup for the change, in the process changing to keyword mode 975 // Update the popup for the change, in the process changing to keyword mode
970 // if the user hit space in mid-string after a keyword. 976 // if the user hit space in mid-string after a keyword.
971 // |allow_exact_keyword_match_| will be used by StartAutocomplete() method, 977 // |allow_exact_keyword_match_| will be used by StartAutocomplete() method,
972 // which will be called by |view_->UpdatePopup()|; so after that returns we 978 // which will be called by |view_->UpdatePopup()|; so after that returns we
973 // can safely reset this flag. 979 // can safely reset this flag.
974 allow_exact_keyword_match_ = text_differs && allow_keyword_ui_change && 980 allow_exact_keyword_match_ = text_differs && allow_keyword_ui_change &&
975 !just_deleted_text && no_selection && 981 !just_deleted_text && no_selection &&
976 CreatedKeywordSearchByInsertingSpaceInMiddle(old_text, user_text_, 982 CreatedKeywordSearchByInsertingSpaceInMiddle(old_text, user_text_,
977 selection_start); 983 selection_start);
978 view_->UpdatePopup(); 984 view_->UpdatePopup();
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 } 1268 }
1263 1269
1264 void OmniboxEditModel::ClassifyStringForPasteAndGo( 1270 void OmniboxEditModel::ClassifyStringForPasteAndGo(
1265 const string16& text, 1271 const string16& text,
1266 AutocompleteMatch* match, 1272 AutocompleteMatch* match,
1267 GURL* alternate_nav_url) const { 1273 GURL* alternate_nav_url) const {
1268 DCHECK(match); 1274 DCHECK(match);
1269 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, 1275 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text,
1270 string16(), false, false, match, alternate_nav_url); 1276 string16(), false, false, match, alternate_nav_url);
1271 } 1277 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698