Chromium Code Reviews| 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); |
|
Peter Kasting
2013/02/11 19:54:54
Why false here?
Peter Kasting
2013/02/11 23:53:09
Didn't answer this.
beaudoin
2013/02/12 00:24:37
I've switched it back to true. I thought using fal
| |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 if (revert_popup) | 1182 |
| 1183 InstantController* instant = controller_->GetInstant(); | |
| 1184 if (instant) { | |
| 1185 // Update the view text, but ensure | |
|
Peter Kasting
2013/02/11 19:54:54
Comment deadends
beaudoin
2013/02/11 23:38:22
Done.
Peter Kasting
2013/02/11 23:53:09
No, it wasn't.
beaudoin
2013/02/12 00:24:37
Sorry. Fell through the cracks. Done now, for real
| |
| 1186 view_->OnTemporaryTextMaybeChanged(user_text_, false, false); | |
| 1187 instant->OnCancel(); | |
| 1188 } else if (revert_popup) { | |
| 1183 popup_->ResetToDefaultMatch(); | 1189 popup_->ResetToDefaultMatch(); |
| 1190 } | |
| 1184 view_->OnRevertTemporaryText(); | 1191 view_->OnRevertTemporaryText(); |
| 1185 } | 1192 } |
| 1186 | 1193 |
| 1187 bool OmniboxEditModel::MaybeAcceptKeywordBySpace(const string16& new_text) { | 1194 bool OmniboxEditModel::MaybeAcceptKeywordBySpace(const string16& new_text) { |
| 1188 size_t keyword_length = new_text.length() - 1; | 1195 size_t keyword_length = new_text.length() - 1; |
| 1189 return (paste_state_ == NONE) && is_keyword_hint_ && !keyword_.empty() && | 1196 return (paste_state_ == NONE) && is_keyword_hint_ && !keyword_.empty() && |
| 1190 inline_autocomplete_text_.empty() && | 1197 inline_autocomplete_text_.empty() && |
| 1191 (keyword_.length() == keyword_length) && | 1198 (keyword_.length() == keyword_length) && |
| 1192 IsSpaceCharForAcceptingKeyword(new_text[keyword_length]) && | 1199 IsSpaceCharForAcceptingKeyword(new_text[keyword_length]) && |
| 1193 !new_text.compare(0, keyword_length, keyword_, 0, keyword_length) && | 1200 !new_text.compare(0, keyword_length, keyword_, 0, keyword_length) && |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1231 controller_->GetWebContents())-> | 1238 controller_->GetWebContents())-> |
| 1232 OmniboxEditModelChanged(user_input_in_progress_, !in_revert_); | 1239 OmniboxEditModelChanged(user_input_in_progress_, !in_revert_); |
| 1233 } | 1240 } |
| 1234 } | 1241 } |
| 1235 | 1242 |
| 1236 bool OmniboxEditModel::DoInstant(const AutocompleteMatch& match) { | 1243 bool OmniboxEditModel::DoInstant(const AutocompleteMatch& match) { |
| 1237 InstantController* instant = controller_->GetInstant(); | 1244 InstantController* instant = controller_->GetInstant(); |
| 1238 if (!instant || in_revert_) | 1245 if (!instant || in_revert_) |
| 1239 return false; | 1246 return false; |
| 1240 | 1247 |
| 1241 // Don't call Update() if the change is a result of a | |
| 1242 // INSTANT_COMPLETE_REPLACE instant suggestion. | |
| 1243 if (has_temporary_text_ && is_temporary_text_set_by_instant_) | |
| 1244 return false; | |
|
Alexei Svitkine (slow)
2013/02/11 17:54:43
On my CL that added this block, Sreeram expressed
beaudoin
2013/02/11 23:38:22
See comment in main thread.
beaudoin
2013/02/12 00:24:37
After some testing it reintroduced the bug I origi
| |
| 1245 | |
| 1246 // The two pieces of text we want to send Instant, viz., what the user has | 1248 // The two pieces of text we want to send Instant, viz., what the user has |
| 1247 // typed, and the full omnibox text including any inline autocompletion. | 1249 // typed, and the full omnibox text including any inline autocompletion. |
| 1248 string16 user_text = has_temporary_text_ ? | 1250 string16 user_text = has_temporary_text_ ? |
| 1249 match.fill_into_edit : DisplayTextFromUserText(user_text_); | 1251 match.fill_into_edit : DisplayTextFromUserText(user_text_); |
| 1250 string16 full_text = view_->GetText(); | 1252 string16 full_text = view_->GetText(); |
| 1251 | 1253 |
| 1252 // Remove "?" if we're in forced query mode. | 1254 // Remove "?" if we're in forced query mode. |
| 1253 AutocompleteInput::RemoveForcedQueryStringIfNecessary( | 1255 AutocompleteInput::RemoveForcedQueryStringIfNecessary( |
| 1254 autocomplete_controller_->input().type(), &user_text); | 1256 autocomplete_controller_->input().type(), &user_text); |
| 1255 AutocompleteInput::RemoveForcedQueryStringIfNecessary( | 1257 AutocompleteInput::RemoveForcedQueryStringIfNecessary( |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1341 instant->OmniboxFocusChanged(state, reason, NULL); | 1343 instant->OmniboxFocusChanged(state, reason, NULL); |
| 1342 | 1344 |
| 1343 // Update state and notify view if the omnibox has focus and the caret | 1345 // Update state and notify view if the omnibox has focus and the caret |
| 1344 // visibility changed. | 1346 // visibility changed. |
| 1345 const bool was_caret_visible = is_caret_visible(); | 1347 const bool was_caret_visible = is_caret_visible(); |
| 1346 focus_state_ = state; | 1348 focus_state_ = state; |
| 1347 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1349 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
| 1348 is_caret_visible() != was_caret_visible) | 1350 is_caret_visible() != was_caret_visible) |
| 1349 view_->ApplyCaretVisibility(); | 1351 view_->ApplyCaretVisibility(); |
| 1350 } | 1352 } |
| OLD | NEW |