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

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

Issue 10824261: Fix handling of inline autocomplete text vis-a-vis Instant. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated comment Created 8 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 is_keyword_hint_ = false; 642 is_keyword_hint_ = false;
643 643
644 if (popup_->IsOpen()) 644 if (popup_->IsOpen())
645 popup_->SetSelectedLineState(OmniboxPopupModel::KEYWORD); 645 popup_->SetSelectedLineState(OmniboxPopupModel::KEYWORD);
646 else 646 else
647 StartAutocomplete(false, true); 647 StartAutocomplete(false, true);
648 648
649 // Ensure the current selection is saved before showing keyword mode 649 // Ensure the current selection is saved before showing keyword mode
650 // so that moving to another line and then reverting the text will restore 650 // so that moving to another line and then reverting the text will restore
651 // the current state properly. 651 // the current state properly.
652 bool save_original_selection = !has_temporary_text_;
653 has_temporary_text_ = true;
652 view_->OnTemporaryTextMaybeChanged( 654 view_->OnTemporaryTextMaybeChanged(
653 DisplayTextFromUserText(CurrentMatch().fill_into_edit), 655 DisplayTextFromUserText(CurrentMatch().fill_into_edit),
654 !has_temporary_text_); 656 save_original_selection);
655 has_temporary_text_ = true;
656 657
657 content::RecordAction(UserMetricsAction("AcceptedKeywordHint")); 658 content::RecordAction(UserMetricsAction("AcceptedKeywordHint"));
658 return true; 659 return true;
659 } 660 }
660 661
661 void OmniboxEditModel::ClearKeyword(const string16& visible_text) { 662 void OmniboxEditModel::ClearKeyword(const string16& visible_text) {
662 autocomplete_controller_->Stop(false); 663 autocomplete_controller_->Stop(false);
663 ClearPopupKeywordMode(); 664 ClearPopupKeywordMode();
664 665
665 const string16 window_text(keyword_ + visible_text); 666 const string16 window_text(keyword_ + visible_text);
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
1113 1114
1114 if (in_revert_) 1115 if (in_revert_)
1115 return false; 1116 return false;
1116 1117
1117 InstantController* instant = controller_->GetInstant(); 1118 InstantController* instant = controller_->GetInstant();
1118 1119
1119 if (!instant) 1120 if (!instant)
1120 return false; 1121 return false;
1121 1122
1122 if (user_input_in_progress_ && popup_->IsOpen()) { 1123 if (user_input_in_progress_ && popup_->IsOpen()) {
1123 string16 text = view_->GetText(); 1124 // The two pieces of text we want to send Instant, viz., what the user has
1124 AutocompleteInput::RemoveForcedQueryStringIfNecessary( 1125 // typed, and any inline autocomplete suggestion.
1125 autocomplete_controller_->input().type(), &text); 1126 string16 user_text = user_text_;
1127 *suggested_text = inline_autocomplete_text_;
1126 1128
1127 // If there's any inline autocompletion, split it out from |text|. 1129 // If there's temporary text, that overrides the user_text. In this case, we
1128 if (!inline_autocomplete_text_.empty()) { 1130 // should ignore any inline_autocomplete_text_, because it won't be visible.
1129 DCHECK_GE(text.size(), inline_autocomplete_text_.size()); 1131 if (has_temporary_text_) {
1130 text.resize(text.size() - inline_autocomplete_text_.size()); 1132 user_text = CurrentMatch().fill_into_edit;
1131 *suggested_text = inline_autocomplete_text_; 1133 suggested_text->clear();
1132 } 1134 }
1133 1135
1134 return instant->Update(match, text, UseVerbatimInstant(), suggested_text, 1136 // Remove any keywords and "?" prefix.
1135 complete_behavior); 1137 user_text = DisplayTextFromUserText(user_text);
1138 AutocompleteInput::RemoveForcedQueryStringIfNecessary(
1139 autocomplete_controller_->input().type(), &user_text);
1140
1141 return instant->Update(match, user_text, UseVerbatimInstant(),
1142 suggested_text, complete_behavior);
1136 } 1143 }
1137 1144
1138 // It's possible DoInstant() was called due to an OnChanged() event from the 1145 // It's possible DoInstant() was called due to an OnChanged() event from the
1139 // omnibox view if the user clicked the renderer while IME composition was 1146 // omnibox view if the user clicked the renderer while IME composition was
1140 // active. In that case we still want to commit on mouse up, so don't call 1147 // active. In that case we still want to commit on mouse up, so don't call
1141 // Hide(). 1148 // Hide().
1142 if (!instant->commit_on_pointer_release()) 1149 if (!instant->commit_on_pointer_release())
1143 instant->Hide(); 1150 instant->Hide();
1144 return false; 1151 return false;
1145 } 1152 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 } 1212 }
1206 1213
1207 void OmniboxEditModel::ClassifyStringForPasteAndGo( 1214 void OmniboxEditModel::ClassifyStringForPasteAndGo(
1208 const string16& text, 1215 const string16& text,
1209 AutocompleteMatch* match, 1216 AutocompleteMatch* match,
1210 GURL* alternate_nav_url) const { 1217 GURL* alternate_nav_url) const {
1211 DCHECK(match); 1218 DCHECK(match);
1212 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, 1219 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text,
1213 string16(), false, false, match, alternate_nav_url); 1220 string16(), false, false, match, alternate_nav_url);
1214 } 1221 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698