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

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: Reverted back to asvitkine's fix. REALLY answered PK's comments. :) 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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 StartAutocomplete(false, true); 698 StartAutocomplete(false, true);
699 699
700 // Ensure the current selection is saved before showing keyword mode 700 // Ensure the current selection is saved before showing keyword mode
701 // so that moving to another line and then reverting the text will restore 701 // so that moving to another line and then reverting the text will restore
702 // the current state properly. 702 // the current state properly.
703 bool save_original_selection = !has_temporary_text_; 703 bool save_original_selection = !has_temporary_text_;
704 has_temporary_text_ = true; 704 has_temporary_text_ = true;
705 is_temporary_text_set_by_instant_ = false; 705 is_temporary_text_set_by_instant_ = false;
706 view_->OnTemporaryTextMaybeChanged( 706 view_->OnTemporaryTextMaybeChanged(
707 DisplayTextFromUserText(CurrentMatch().fill_into_edit), 707 DisplayTextFromUserText(CurrentMatch().fill_into_edit),
708 save_original_selection); 708 save_original_selection, true);
709 709
710 content::RecordAction(UserMetricsAction("AcceptedKeywordHint")); 710 content::RecordAction(UserMetricsAction("AcceptedKeywordHint"));
711 return true; 711 return true;
712 } 712 }
713 713
714 void OmniboxEditModel::ClearKeyword(const string16& visible_text) { 714 void OmniboxEditModel::ClearKeyword(const string16& visible_text) {
715 autocomplete_controller_->Stop(false); 715 autocomplete_controller_->Stop(false);
716 ClearPopupKeywordMode(); 716 ClearPopupKeywordMode();
717 717
718 const string16 window_text(keyword_ + visible_text); 718 const string16 window_text(keyword_ + visible_text);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 void OmniboxEditModel::OnKillFocus() { 788 void OmniboxEditModel::OnKillFocus() {
789 // TODO(samarth): determine if it is safe to move the call to 789 // TODO(samarth): determine if it is safe to move the call to
790 // OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us 790 // OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us
791 // just call SetFocusState() to handle the state change. 791 // just call SetFocusState() to handle the state change.
792 focus_state_ = OMNIBOX_FOCUS_NONE; 792 focus_state_ = OMNIBOX_FOCUS_NONE;
793 control_key_state_ = UP; 793 control_key_state_ = UP;
794 paste_state_ = NONE; 794 paste_state_ = NONE;
795 } 795 }
796 796
797 bool OmniboxEditModel::OnEscapeKeyPressed() { 797 bool OmniboxEditModel::OnEscapeKeyPressed() {
798 if (has_temporary_text_ && !is_temporary_text_set_by_instant_) { 798 if (has_temporary_text_) {
799 AutocompleteMatch match; 799 AutocompleteMatch match;
800 InfoForCurrentSelection(&match, NULL); 800 InfoForCurrentSelection(&match, NULL);
801 if (match.destination_url != original_url_) { 801 if (match.destination_url != original_url_) {
802 RevertTemporaryText(true); 802 RevertTemporaryText(true);
803 return true; 803 return true;
804 } 804 }
805 } 805 }
806 806
807 // We do not clear the pending entry from the omnibox when a load is first 807 // We do not clear the pending entry from the omnibox when a load is first
808 // stopped. If the user presses Escape while stopped, we clear it. 808 // stopped. If the user presses Escape while stopped, we clear it.
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 // Arrowing around the popup cancels control-enter. 913 // Arrowing around the popup cancels control-enter.
914 control_key_state_ = DOWN_WITH_CHANGE; 914 control_key_state_ = DOWN_WITH_CHANGE;
915 // Now things are a bit screwy: the desired_tld has changed, but if we 915 // Now things are a bit screwy: the desired_tld has changed, but if we
916 // update the popup, the new order of entries won't match the old, so the 916 // update the popup, the new order of entries won't match the old, so the
917 // user's selection gets screwy; and if we don't update the popup, and the 917 // user's selection gets screwy; and if we don't update the popup, and the
918 // user reverts, then the selected item will be as if control is still 918 // user reverts, then the selected item will be as if control is still
919 // pressed, even though maybe it isn't any more. There is no obvious 919 // pressed, even though maybe it isn't any more. There is no obvious
920 // right answer here :( 920 // right answer here :(
921 } 921 }
922 view_->OnTemporaryTextMaybeChanged(DisplayTextFromUserText(text), 922 view_->OnTemporaryTextMaybeChanged(DisplayTextFromUserText(text),
923 save_original_selection); 923 save_original_selection, true);
924 return; 924 return;
925 } 925 }
926 926
927 bool call_controller_onchanged = true; 927 bool call_controller_onchanged = true;
928 inline_autocomplete_text_ = text; 928 inline_autocomplete_text_ = text;
929 929
930 if (keyword_state_changed && KeywordIsSelected()) { 930 if (keyword_state_changed && KeywordIsSelected()) {
931 // If we reach here, the user most likely entered keyword mode by inserting 931 // If we reach here, the user most likely entered keyword mode by inserting
932 // a space between a keyword name and a search string (as pressing space or 932 // a space between a keyword name and a search string (as pressing space or
933 // tab after the keyword name alone would have been be handled in 933 // tab after the keyword name alone would have been be handled in
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 } 1172 }
1173 } 1173 }
1174 1174
1175 void OmniboxEditModel::RevertTemporaryText(bool revert_popup) { 1175 void OmniboxEditModel::RevertTemporaryText(bool revert_popup) {
1176 // The user typed something, then selected a different item. Restore the 1176 // The user typed something, then selected a different item. Restore the
1177 // text they typed and change back to the default item. 1177 // text they typed and change back to the default item.
1178 // NOTE: This purposefully does not reset paste_state_. 1178 // NOTE: This purposefully does not reset paste_state_.
1179 just_deleted_text_ = false; 1179 just_deleted_text_ = false;
1180 has_temporary_text_ = false; 1180 has_temporary_text_ = false;
1181 is_temporary_text_set_by_instant_ = false; 1181 is_temporary_text_set_by_instant_ = false;
1182
1183 InstantController* instant = controller_->GetInstant();
1184 if (instant) {
1185 // Update the view text, do not notify the model in order not to trigger an
1186 // unwanted call to instant->Update().
1187 view_->OnTemporaryTextMaybeChanged(user_text_, false, false);
1188 instant->OnCancel(user_text_);
sreeram 2013/02/12 18:12:29 It took me some time to figure out what's going on
beaudoin 2013/02/12 20:27:30 Now using your comment. 1) --> discussed over chat
1189 }
1182 if (revert_popup) 1190 if (revert_popup)
1183 popup_->ResetToDefaultMatch(); 1191 popup_->ResetToDefaultMatch();
1184 view_->OnRevertTemporaryText(); 1192 view_->OnRevertTemporaryText();
1185 } 1193 }
1186 1194
1187 bool OmniboxEditModel::MaybeAcceptKeywordBySpace(const string16& new_text) { 1195 bool OmniboxEditModel::MaybeAcceptKeywordBySpace(const string16& new_text) {
1188 size_t keyword_length = new_text.length() - 1; 1196 size_t keyword_length = new_text.length() - 1;
1189 return (paste_state_ == NONE) && is_keyword_hint_ && !keyword_.empty() && 1197 return (paste_state_ == NONE) && is_keyword_hint_ && !keyword_.empty() &&
1190 inline_autocomplete_text_.empty() && 1198 inline_autocomplete_text_.empty() &&
1191 (keyword_.length() == keyword_length) && 1199 (keyword_.length() == keyword_length) &&
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 instant->OmniboxFocusChanged(state, reason, NULL); 1349 instant->OmniboxFocusChanged(state, reason, NULL);
1342 1350
1343 // Update state and notify view if the omnibox has focus and the caret 1351 // Update state and notify view if the omnibox has focus and the caret
1344 // visibility changed. 1352 // visibility changed.
1345 const bool was_caret_visible = is_caret_visible(); 1353 const bool was_caret_visible = is_caret_visible();
1346 focus_state_ = state; 1354 focus_state_ = state;
1347 if (focus_state_ != OMNIBOX_FOCUS_NONE && 1355 if (focus_state_ != OMNIBOX_FOCUS_NONE &&
1348 is_caret_visible() != was_caret_visible) 1356 is_caret_visible() != was_caret_visible)
1349 view_->ApplyCaretVisibility(); 1357 view_->ApplyCaretVisibility();
1350 } 1358 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698