OLD | NEW |
---|---|
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 Loading... | |
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, false); |
beaudoin
2013/02/07 22:34:59
This is my new way of fixing the problem Alexei so
| |
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 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
710 StartAutocomplete(false, true); | 710 StartAutocomplete(false, true); |
711 | 711 |
712 // Ensure the current selection is saved before showing keyword mode | 712 // Ensure the current selection is saved before showing keyword mode |
713 // so that moving to another line and then reverting the text will restore | 713 // so that moving to another line and then reverting the text will restore |
714 // the current state properly. | 714 // the current state properly. |
715 bool save_original_selection = !has_temporary_text_; | 715 bool save_original_selection = !has_temporary_text_; |
716 has_temporary_text_ = true; | 716 has_temporary_text_ = true; |
717 is_temporary_text_set_by_instant_ = false; | 717 is_temporary_text_set_by_instant_ = false; |
718 view_->OnTemporaryTextMaybeChanged( | 718 view_->OnTemporaryTextMaybeChanged( |
719 DisplayTextFromUserText(CurrentMatch().fill_into_edit), | 719 DisplayTextFromUserText(CurrentMatch().fill_into_edit), |
720 save_original_selection); | 720 save_original_selection, true); |
721 | 721 |
722 content::RecordAction(UserMetricsAction("AcceptedKeywordHint")); | 722 content::RecordAction(UserMetricsAction("AcceptedKeywordHint")); |
723 return true; | 723 return true; |
724 } | 724 } |
725 | 725 |
726 void OmniboxEditModel::ClearKeyword(const string16& visible_text) { | 726 void OmniboxEditModel::ClearKeyword(const string16& visible_text) { |
727 autocomplete_controller_->Stop(false); | 727 autocomplete_controller_->Stop(false); |
728 ClearPopupKeywordMode(); | 728 ClearPopupKeywordMode(); |
729 | 729 |
730 const string16 window_text(keyword_ + visible_text); | 730 const string16 window_text(keyword_ + visible_text); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
800 void OmniboxEditModel::OnKillFocus() { | 800 void OmniboxEditModel::OnKillFocus() { |
801 // TODO(samarth): determine if it is safe to move the call to | 801 // TODO(samarth): determine if it is safe to move the call to |
802 // OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us | 802 // OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us |
803 // just call SetFocusState() to handle the state change. | 803 // just call SetFocusState() to handle the state change. |
804 focus_state_ = OMNIBOX_FOCUS_NONE; | 804 focus_state_ = OMNIBOX_FOCUS_NONE; |
805 control_key_state_ = UP; | 805 control_key_state_ = UP; |
806 paste_state_ = NONE; | 806 paste_state_ = NONE; |
807 } | 807 } |
808 | 808 |
809 bool OmniboxEditModel::OnEscapeKeyPressed() { | 809 bool OmniboxEditModel::OnEscapeKeyPressed() { |
810 if (has_temporary_text_ && !is_temporary_text_set_by_instant_) { | 810 if (has_temporary_text_) { |
811 AutocompleteMatch match; | 811 AutocompleteMatch match; |
812 InfoForCurrentSelection(&match, NULL); | 812 InfoForCurrentSelection(&match, NULL); |
813 if (match.destination_url != original_url_) { | 813 if (match.destination_url != original_url_) { |
814 RevertTemporaryText(true); | 814 RevertTemporaryText(true); |
815 return true; | 815 return true; |
816 } | 816 } |
817 } | 817 } |
818 | 818 |
819 // We do not clear the pending entry from the omnibox when a load is first | 819 // We do not clear the pending entry from the omnibox when a load is first |
820 // stopped. If the user presses Escape while stopped, we clear it. | 820 // stopped. If the user presses Escape while stopped, we clear it. |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
925 // Arrowing around the popup cancels control-enter. | 925 // Arrowing around the popup cancels control-enter. |
926 control_key_state_ = DOWN_WITH_CHANGE; | 926 control_key_state_ = DOWN_WITH_CHANGE; |
927 // Now things are a bit screwy: the desired_tld has changed, but if we | 927 // Now things are a bit screwy: the desired_tld has changed, but if we |
928 // update the popup, the new order of entries won't match the old, so the | 928 // update the popup, the new order of entries won't match the old, so the |
929 // user's selection gets screwy; and if we don't update the popup, and the | 929 // user's selection gets screwy; and if we don't update the popup, and the |
930 // user reverts, then the selected item will be as if control is still | 930 // user reverts, then the selected item will be as if control is still |
931 // pressed, even though maybe it isn't any more. There is no obvious | 931 // pressed, even though maybe it isn't any more. There is no obvious |
932 // right answer here :( | 932 // right answer here :( |
933 } | 933 } |
934 view_->OnTemporaryTextMaybeChanged(DisplayTextFromUserText(text), | 934 view_->OnTemporaryTextMaybeChanged(DisplayTextFromUserText(text), |
935 save_original_selection); | 935 save_original_selection, true); |
936 return; | 936 return; |
937 } | 937 } |
938 | 938 |
939 bool call_controller_onchanged = true; | 939 bool call_controller_onchanged = true; |
940 inline_autocomplete_text_ = text; | 940 inline_autocomplete_text_ = text; |
941 | 941 |
942 if (keyword_state_changed && KeywordIsSelected()) { | 942 if (keyword_state_changed && KeywordIsSelected()) { |
943 // If we reach here, the user most likely entered keyword mode by inserting | 943 // If we reach here, the user most likely entered keyword mode by inserting |
944 // a space between a keyword name and a search string (as pressing space or | 944 // a space between a keyword name and a search string (as pressing space or |
945 // tab after the keyword name alone would have been be handled in | 945 // tab after the keyword name alone would have been be handled in |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1184 } | 1184 } |
1185 } | 1185 } |
1186 | 1186 |
1187 void OmniboxEditModel::RevertTemporaryText(bool revert_popup) { | 1187 void OmniboxEditModel::RevertTemporaryText(bool revert_popup) { |
1188 // The user typed something, then selected a different item. Restore the | 1188 // The user typed something, then selected a different item. Restore the |
1189 // text they typed and change back to the default item. | 1189 // text they typed and change back to the default item. |
1190 // NOTE: This purposefully does not reset paste_state_. | 1190 // NOTE: This purposefully does not reset paste_state_. |
1191 just_deleted_text_ = false; | 1191 just_deleted_text_ = false; |
1192 has_temporary_text_ = false; | 1192 has_temporary_text_ = false; |
1193 is_temporary_text_set_by_instant_ = false; | 1193 is_temporary_text_set_by_instant_ = false; |
1194 if (revert_popup) | 1194 |
1195 InstantController* instant = controller_->GetInstant(); | |
1196 if (instant) { | |
1197 // Update the view text, but ensure | |
1198 view_->OnTemporaryTextMaybeChanged(user_text_, false, false); | |
1199 instant->OnCancel(); | |
1200 } else if (revert_popup) { | |
1195 popup_->ResetToDefaultMatch(); | 1201 popup_->ResetToDefaultMatch(); |
1202 } | |
1196 view_->OnRevertTemporaryText(); | 1203 view_->OnRevertTemporaryText(); |
1197 } | 1204 } |
1198 | 1205 |
1199 bool OmniboxEditModel::MaybeAcceptKeywordBySpace(const string16& new_text) { | 1206 bool OmniboxEditModel::MaybeAcceptKeywordBySpace(const string16& new_text) { |
1200 size_t keyword_length = new_text.length() - 1; | 1207 size_t keyword_length = new_text.length() - 1; |
1201 return (paste_state_ == NONE) && is_keyword_hint_ && !keyword_.empty() && | 1208 return (paste_state_ == NONE) && is_keyword_hint_ && !keyword_.empty() && |
1202 inline_autocomplete_text_.empty() && | 1209 inline_autocomplete_text_.empty() && |
1203 (keyword_.length() == keyword_length) && | 1210 (keyword_.length() == keyword_length) && |
1204 IsSpaceCharForAcceptingKeyword(new_text[keyword_length]) && | 1211 IsSpaceCharForAcceptingKeyword(new_text[keyword_length]) && |
1205 !new_text.compare(0, keyword_length, keyword_, 0, keyword_length) && | 1212 !new_text.compare(0, keyword_length, keyword_, 0, keyword_length) && |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1243 controller_->GetWebContents())-> | 1250 controller_->GetWebContents())-> |
1244 OmniboxEditModelChanged(user_input_in_progress_, !in_revert_); | 1251 OmniboxEditModelChanged(user_input_in_progress_, !in_revert_); |
1245 } | 1252 } |
1246 } | 1253 } |
1247 | 1254 |
1248 bool OmniboxEditModel::DoInstant(const AutocompleteMatch& match) { | 1255 bool OmniboxEditModel::DoInstant(const AutocompleteMatch& match) { |
1249 InstantController* instant = controller_->GetInstant(); | 1256 InstantController* instant = controller_->GetInstant(); |
1250 if (!instant || in_revert_) | 1257 if (!instant || in_revert_) |
1251 return false; | 1258 return false; |
1252 | 1259 |
1253 // Don't call Update() if the change is a result of a | |
1254 // INSTANT_COMPLETE_REPLACE instant suggestion. | |
1255 if (has_temporary_text_ && is_temporary_text_set_by_instant_) | |
1256 return false; | |
1257 | |
beaudoin
2013/02/07 22:34:59
This basically reverts Alexei's fix of crbug.com/1
| |
1258 // The two pieces of text we want to send Instant, viz., what the user has | 1260 // The two pieces of text we want to send Instant, viz., what the user has |
1259 // typed, and the full omnibox text including any inline autocompletion. | 1261 // typed, and the full omnibox text including any inline autocompletion. |
1260 string16 user_text = has_temporary_text_ ? | 1262 string16 user_text = has_temporary_text_ ? |
1261 match.fill_into_edit : DisplayTextFromUserText(user_text_); | 1263 match.fill_into_edit : DisplayTextFromUserText(user_text_); |
1262 string16 full_text = view_->GetText(); | 1264 string16 full_text = view_->GetText(); |
1263 | 1265 |
1264 // Remove "?" if we're in forced query mode. | 1266 // Remove "?" if we're in forced query mode. |
1265 AutocompleteInput::RemoveForcedQueryStringIfNecessary( | 1267 AutocompleteInput::RemoveForcedQueryStringIfNecessary( |
1266 autocomplete_controller_->input().type(), &user_text); | 1268 autocomplete_controller_->input().type(), &user_text); |
1267 AutocompleteInput::RemoveForcedQueryStringIfNecessary( | 1269 AutocompleteInput::RemoveForcedQueryStringIfNecessary( |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1353 instant->OmniboxFocusChanged(state, reason, NULL); | 1355 instant->OmniboxFocusChanged(state, reason, NULL); |
1354 | 1356 |
1355 // Update state and notify view if the omnibox has focus and the caret | 1357 // Update state and notify view if the omnibox has focus and the caret |
1356 // visibility changed. | 1358 // visibility changed. |
1357 const bool was_caret_visible = is_caret_visible(); | 1359 const bool was_caret_visible = is_caret_visible(); |
1358 focus_state_ = state; | 1360 focus_state_ = state; |
1359 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1361 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
1360 is_caret_visible() != was_caret_visible) | 1362 is_caret_visible() != was_caret_visible) |
1361 view_->ApplyCaretVisibility(); | 1363 view_->ApplyCaretVisibility(); |
1362 } | 1364 } |
OLD | NEW |