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

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

Issue 11889003: Fixing ESC in instant-extended. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 10 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 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/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 213
214 case INSTANT_COMPLETE_REPLACE: { 214 case INSTANT_COMPLETE_REPLACE: {
215 const bool save_original_selection = !has_temporary_text_; 215 const bool save_original_selection = !has_temporary_text_;
216 view_->SetInstantSuggestion(string16()); 216 view_->SetInstantSuggestion(string16());
217 has_temporary_text_ = true; 217 has_temporary_text_ = true;
218 is_temporary_text_set_by_instant_ = true; 218 is_temporary_text_set_by_instant_ = true;
219 // Instant suggestions are never a keyword. 219 // Instant suggestions are never a keyword.
220 keyword_ = string16(); 220 keyword_ = string16();
221 is_keyword_hint_ = false; 221 is_keyword_hint_ = false;
222 view_->OnTemporaryTextMaybeChanged(suggestion.text, 222 view_->OnTemporaryTextMaybeChanged(suggestion.text,
223 save_original_selection); 223 save_original_selection, true);
224 break; 224 break;
225 } 225 }
226 } 226 }
227 } 227 }
228 228
229 bool OmniboxEditModel::CommitSuggestedText(bool skip_inline_autocomplete) { 229 bool OmniboxEditModel::CommitSuggestedText(bool skip_inline_autocomplete) {
230 if (!controller_->GetInstant()) 230 if (!controller_->GetInstant())
231 return false; 231 return false;
232 232
233 const string16 suggestion = view_->GetInstantSuggestion(); 233 const string16 suggestion = view_->GetInstantSuggestion();
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 StartAutocomplete(false, true); 700 StartAutocomplete(false, true);
701 701
702 // Ensure the current selection is saved before showing keyword mode 702 // Ensure the current selection is saved before showing keyword mode
703 // so that moving to another line and then reverting the text will restore 703 // so that moving to another line and then reverting the text will restore
704 // the current state properly. 704 // the current state properly.
705 bool save_original_selection = !has_temporary_text_; 705 bool save_original_selection = !has_temporary_text_;
706 has_temporary_text_ = true; 706 has_temporary_text_ = true;
707 is_temporary_text_set_by_instant_ = false; 707 is_temporary_text_set_by_instant_ = false;
708 view_->OnTemporaryTextMaybeChanged( 708 view_->OnTemporaryTextMaybeChanged(
709 DisplayTextFromUserText(CurrentMatch().fill_into_edit), 709 DisplayTextFromUserText(CurrentMatch().fill_into_edit),
710 save_original_selection); 710 save_original_selection, true);
711 711
712 content::RecordAction(UserMetricsAction("AcceptedKeywordHint")); 712 content::RecordAction(UserMetricsAction("AcceptedKeywordHint"));
713 return true; 713 return true;
714 } 714 }
715 715
716 void OmniboxEditModel::ClearKeyword(const string16& visible_text) { 716 void OmniboxEditModel::ClearKeyword(const string16& visible_text) {
717 autocomplete_controller_->Stop(false); 717 autocomplete_controller_->Stop(false);
718 ClearPopupKeywordMode(); 718 ClearPopupKeywordMode();
719 719
720 const string16 window_text(keyword_ + visible_text); 720 const string16 window_text(keyword_ + visible_text);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 void OmniboxEditModel::OnKillFocus() { 790 void OmniboxEditModel::OnKillFocus() {
791 // TODO(samarth): determine if it is safe to move the call to 791 // TODO(samarth): determine if it is safe to move the call to
792 // OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us 792 // OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us
793 // just call SetFocusState() to handle the state change. 793 // just call SetFocusState() to handle the state change.
794 focus_state_ = OMNIBOX_FOCUS_NONE; 794 focus_state_ = OMNIBOX_FOCUS_NONE;
795 control_key_state_ = UP; 795 control_key_state_ = UP;
796 paste_state_ = NONE; 796 paste_state_ = NONE;
797 } 797 }
798 798
799 bool OmniboxEditModel::OnEscapeKeyPressed() { 799 bool OmniboxEditModel::OnEscapeKeyPressed() {
800 if (has_temporary_text_ && !is_temporary_text_set_by_instant_) { 800 if (has_temporary_text_) {
801 AutocompleteMatch match; 801 AutocompleteMatch match;
802 InfoForCurrentSelection(&match, NULL); 802 InfoForCurrentSelection(&match, NULL);
803 if (match.destination_url != original_url_) { 803 if (match.destination_url != original_url_) {
804 RevertTemporaryText(true); 804 RevertTemporaryText(true);
805 return true; 805 return true;
806 } 806 }
807 } 807 }
808 808
809 // We do not clear the pending entry from the omnibox when a load is first 809 // We do not clear the pending entry from the omnibox when a load is first
810 // stopped. If the user presses Escape while stopped, we clear it. 810 // stopped. If the user presses Escape while stopped, we clear it.
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 // Arrowing around the popup cancels control-enter. 915 // Arrowing around the popup cancels control-enter.
916 control_key_state_ = DOWN_WITH_CHANGE; 916 control_key_state_ = DOWN_WITH_CHANGE;
917 // Now things are a bit screwy: the desired_tld has changed, but if we 917 // Now things are a bit screwy: the desired_tld has changed, but if we
918 // update the popup, the new order of entries won't match the old, so the 918 // update the popup, the new order of entries won't match the old, so the
919 // user's selection gets screwy; and if we don't update the popup, and the 919 // user's selection gets screwy; and if we don't update the popup, and the
920 // user reverts, then the selected item will be as if control is still 920 // user reverts, then the selected item will be as if control is still
921 // pressed, even though maybe it isn't any more. There is no obvious 921 // pressed, even though maybe it isn't any more. There is no obvious
922 // right answer here :( 922 // right answer here :(
923 } 923 }
924 view_->OnTemporaryTextMaybeChanged(DisplayTextFromUserText(text), 924 view_->OnTemporaryTextMaybeChanged(DisplayTextFromUserText(text),
925 save_original_selection); 925 save_original_selection, true);
926 return; 926 return;
927 } 927 }
928 928
929 bool call_controller_onchanged = true; 929 bool call_controller_onchanged = true;
930 inline_autocomplete_text_ = text; 930 inline_autocomplete_text_ = text;
931 931
932 if (keyword_state_changed && KeywordIsSelected()) { 932 if (keyword_state_changed && KeywordIsSelected()) {
933 // If we reach here, the user most likely entered keyword mode by inserting 933 // If we reach here, the user most likely entered keyword mode by inserting
934 // a space between a keyword name and a search string (as pressing space or 934 // a space between a keyword name and a search string (as pressing space or
935 // tab after the keyword name alone would have been be handled in 935 // tab after the keyword name alone would have been be handled in
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify( 1171 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(
1172 UserTextFromDisplayText(view_->GetText()), GetDesiredTLD(), 1172 UserTextFromDisplayText(view_->GetText()), GetDesiredTLD(),
1173 KeywordIsSelected(), true, match, alternate_nav_url); 1173 KeywordIsSelected(), true, match, alternate_nav_url);
1174 } 1174 }
1175 } 1175 }
1176 1176
1177 void OmniboxEditModel::RevertTemporaryText(bool revert_popup) { 1177 void OmniboxEditModel::RevertTemporaryText(bool revert_popup) {
1178 // The user typed something, then selected a different item. Restore the 1178 // The user typed something, then selected a different item. Restore the
1179 // text they typed and change back to the default item. 1179 // text they typed and change back to the default item.
1180 // NOTE: This purposefully does not reset paste_state_. 1180 // NOTE: This purposefully does not reset paste_state_.
1181 bool notify_instant = is_temporary_text_set_by_instant_;
1181 just_deleted_text_ = false; 1182 just_deleted_text_ = false;
1182 has_temporary_text_ = false; 1183 has_temporary_text_ = false;
1183 is_temporary_text_set_by_instant_ = false; 1184 is_temporary_text_set_by_instant_ = false;
1185
1186 InstantController* instant = controller_->GetInstant();
1187 if (instant && notify_instant) {
1188 // Normally, popup_->ResetToDefaultMatch() will cause the view text to be
1189 // updated. In Instant Extended mode however, the popup_ is not used, so it
1190 // won't do anything. So, update the view ourselves. Even if Instant is not
1191 // in extended mode (i.e., it's enabled in non-extended mode, or disabled
1192 // altogether), this is okay to do, since the call to
1193 // popup_->ResetToDefaultMatch() will just override whatever we do here.
1194 //
1195 // The two "false" arguments make sure that our shenanigans don't cause any
1196 // previously saved selection to be erased nor OnChanged() to be called.
1197 view_->OnTemporaryTextMaybeChanged(user_text_ + inline_autocomplete_text_,
1198 false, false);
1199 AutocompleteResult::const_iterator match(result().default_match());
1200 instant->OnCancel(match != result().end() ? *match : AutocompleteMatch(),
1201 user_text_ + inline_autocomplete_text_);
1202 }
1184 if (revert_popup) 1203 if (revert_popup)
1185 popup_->ResetToDefaultMatch(); 1204 popup_->ResetToDefaultMatch();
1186 view_->OnRevertTemporaryText(); 1205 view_->OnRevertTemporaryText();
1187 } 1206 }
1188 1207
1189 bool OmniboxEditModel::MaybeAcceptKeywordBySpace(const string16& new_text) { 1208 bool OmniboxEditModel::MaybeAcceptKeywordBySpace(const string16& new_text) {
1190 size_t keyword_length = new_text.length() - 1; 1209 size_t keyword_length = new_text.length() - 1;
1191 return (paste_state_ == NONE) && is_keyword_hint_ && !keyword_.empty() && 1210 return (paste_state_ == NONE) && is_keyword_hint_ && !keyword_.empty() &&
1192 inline_autocomplete_text_.empty() && 1211 inline_autocomplete_text_.empty() &&
1193 (keyword_.length() == keyword_length) && 1212 (keyword_.length() == keyword_length) &&
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1343 instant->OmniboxFocusChanged(state, reason, NULL); 1362 instant->OmniboxFocusChanged(state, reason, NULL);
1344 1363
1345 // Update state and notify view if the omnibox has focus and the caret 1364 // Update state and notify view if the omnibox has focus and the caret
1346 // visibility changed. 1365 // visibility changed.
1347 const bool was_caret_visible = is_caret_visible(); 1366 const bool was_caret_visible = is_caret_visible();
1348 focus_state_ = state; 1367 focus_state_ = state;
1349 if (focus_state_ != OMNIBOX_FOCUS_NONE && 1368 if (focus_state_ != OMNIBOX_FOCUS_NONE &&
1350 is_caret_visible() != was_caret_visible) 1369 is_caret_visible() != was_caret_visible)
1351 view_->ApplyCaretVisibility(); 1370 view_->ApplyCaretVisibility();
1352 } 1371 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_edit_model.h ('k') | chrome/browser/ui/omnibox/omnibox_edit_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698