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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 OmniboxEditController* controller, | 120 OmniboxEditController* controller, |
| 121 Profile* profile) | 121 Profile* profile) |
| 122 : view_(view), | 122 : view_(view), |
| 123 popup_(NULL), | 123 popup_(NULL), |
| 124 controller_(controller), | 124 controller_(controller), |
| 125 focus_state_(OMNIBOX_FOCUS_NONE), | 125 focus_state_(OMNIBOX_FOCUS_NONE), |
| 126 user_input_in_progress_(false), | 126 user_input_in_progress_(false), |
| 127 just_deleted_text_(false), | 127 just_deleted_text_(false), |
| 128 has_temporary_text_(false), | 128 has_temporary_text_(false), |
| 129 is_temporary_text_set_by_instant_(false), | 129 is_temporary_text_set_by_instant_(false), |
| 130 is_instant_temporary_text_a_search_query_(false), | |
| 130 paste_state_(NONE), | 131 paste_state_(NONE), |
| 131 control_key_state_(UP), | 132 control_key_state_(UP), |
| 132 is_keyword_hint_(false), | 133 is_keyword_hint_(false), |
| 133 profile_(profile), | 134 profile_(profile), |
| 134 in_revert_(false), | 135 in_revert_(false), |
| 135 in_escape_handler_(false), | 136 in_escape_handler_(false), |
| 136 allow_exact_keyword_match_(false) { | 137 allow_exact_keyword_match_(false) { |
| 137 omnibox_controller_.reset(new OmniboxController(this, profile)); | 138 omnibox_controller_.reset(new OmniboxController(this, profile)); |
| 138 delegate_.reset(new OmniboxCurrentPageDelegateImpl(controller, profile)); | 139 delegate_.reset(new OmniboxCurrentPageDelegateImpl(controller, profile)); |
| 139 } | 140 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 GURL OmniboxEditModel::PermanentURL() { | 214 GURL OmniboxEditModel::PermanentURL() { |
| 214 return URLFixerUpper::FixupURL(UTF16ToUTF8(permanent_text_), std::string()); | 215 return URLFixerUpper::FixupURL(UTF16ToUTF8(permanent_text_), std::string()); |
| 215 } | 216 } |
| 216 | 217 |
| 217 void OmniboxEditModel::SetUserText(const string16& text) { | 218 void OmniboxEditModel::SetUserText(const string16& text) { |
| 218 SetInputInProgress(true); | 219 SetInputInProgress(true); |
| 219 InternalSetUserText(text); | 220 InternalSetUserText(text); |
| 220 paste_state_ = NONE; | 221 paste_state_ = NONE; |
| 221 has_temporary_text_ = false; | 222 has_temporary_text_ = false; |
| 222 is_temporary_text_set_by_instant_ = false; | 223 is_temporary_text_set_by_instant_ = false; |
| 224 is_instant_temporary_text_a_search_query_ = false; | |
| 223 } | 225 } |
| 224 | 226 |
| 225 void OmniboxEditModel::FinalizeInstantQuery(const string16& input_text, | 227 void OmniboxEditModel::FinalizeInstantQuery(const string16& input_text, |
| 226 const InstantSuggestion& suggestion, | 228 const InstantSuggestion& suggestion, |
| 227 bool skip_inline_autocomplete) { | 229 bool skip_inline_autocomplete) { |
| 228 if (skip_inline_autocomplete) { | 230 if (skip_inline_autocomplete) { |
| 229 const string16 final_text = input_text + suggestion.text; | 231 const string16 final_text = input_text + suggestion.text; |
| 230 view_->OnBeforePossibleChange(); | 232 view_->OnBeforePossibleChange(); |
| 231 view_->SetWindowTextAndCaretPos(final_text, final_text.length(), false, | 233 view_->SetWindowTextAndCaretPos(final_text, final_text.length(), false, |
| 232 false); | 234 false); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 245 switch (suggestion.behavior) { | 247 switch (suggestion.behavior) { |
| 246 case INSTANT_COMPLETE_NOW: | 248 case INSTANT_COMPLETE_NOW: |
| 247 view_->SetInstantSuggestion(string16()); | 249 view_->SetInstantSuggestion(string16()); |
| 248 if (!suggestion.text.empty()) | 250 if (!suggestion.text.empty()) |
| 249 FinalizeInstantQuery(view_->GetText(), suggestion, false); | 251 FinalizeInstantQuery(view_->GetText(), suggestion, false); |
| 250 break; | 252 break; |
| 251 | 253 |
| 252 case INSTANT_COMPLETE_NEVER: { | 254 case INSTANT_COMPLETE_NEVER: { |
| 253 DCHECK_EQ(INSTANT_SUGGESTION_SEARCH, suggestion.type); | 255 DCHECK_EQ(INSTANT_SUGGESTION_SEARCH, suggestion.type); |
| 254 view_->SetInstantSuggestion(suggestion.text); | 256 view_->SetInstantSuggestion(suggestion.text); |
| 255 SearchProvider* search_provider = | 257 autocomplete_controller()->search_provider()->ClearInstantSuggestion(); |
| 256 autocomplete_controller()->search_provider(); | |
| 257 if (search_provider) | |
| 258 search_provider->ClearInstantSuggestion(); | |
| 259 break; | 258 break; |
| 260 } | 259 } |
| 261 | 260 |
| 262 case INSTANT_COMPLETE_REPLACE: { | 261 case INSTANT_COMPLETE_REPLACE: { |
| 263 const bool save_original_selection = !has_temporary_text_; | 262 const bool save_original_selection = !has_temporary_text_; |
| 264 view_->SetInstantSuggestion(string16()); | 263 view_->SetInstantSuggestion(string16()); |
| 265 has_temporary_text_ = true; | 264 has_temporary_text_ = true; |
| 266 is_temporary_text_set_by_instant_ = true; | 265 is_temporary_text_set_by_instant_ = true; |
| 266 is_instant_temporary_text_a_search_query_ = | |
| 267 suggestion.type == INSTANT_SUGGESTION_SEARCH; | |
| 267 // Instant suggestions are never a keyword. | 268 // Instant suggestions are never a keyword. |
| 268 keyword_ = string16(); | 269 keyword_ = string16(); |
| 269 is_keyword_hint_ = false; | 270 is_keyword_hint_ = false; |
| 270 view_->OnTemporaryTextMaybeChanged(suggestion.text, | 271 view_->OnTemporaryTextMaybeChanged(suggestion.text, |
| 271 save_original_selection, true); | 272 save_original_selection, true); |
| 272 break; | 273 break; |
| 273 } | 274 } |
| 274 } | 275 } |
| 275 } | 276 } |
| 276 | 277 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 } | 472 } |
| 472 | 473 |
| 473 void OmniboxEditModel::Revert() { | 474 void OmniboxEditModel::Revert() { |
| 474 SetInputInProgress(false); | 475 SetInputInProgress(false); |
| 475 paste_state_ = NONE; | 476 paste_state_ = NONE; |
| 476 InternalSetUserText(string16()); | 477 InternalSetUserText(string16()); |
| 477 keyword_.clear(); | 478 keyword_.clear(); |
| 478 is_keyword_hint_ = false; | 479 is_keyword_hint_ = false; |
| 479 has_temporary_text_ = false; | 480 has_temporary_text_ = false; |
| 480 is_temporary_text_set_by_instant_ = false; | 481 is_temporary_text_set_by_instant_ = false; |
| 482 is_instant_temporary_text_a_search_query_ = false; | |
| 481 view_->SetWindowTextAndCaretPos(permanent_text_, | 483 view_->SetWindowTextAndCaretPos(permanent_text_, |
| 482 has_focus() ? permanent_text_.length() : 0, | 484 has_focus() ? permanent_text_.length() : 0, |
| 483 false, true); | 485 false, true); |
| 484 AutocompleteActionPredictor* action_predictor = | 486 AutocompleteActionPredictor* action_predictor = |
| 485 AutocompleteActionPredictorFactory::GetForProfile(profile_); | 487 AutocompleteActionPredictorFactory::GetForProfile(profile_); |
| 486 if (action_predictor) | 488 if (action_predictor) |
| 487 action_predictor->ClearTransitionalMatches(); | 489 action_predictor->ClearTransitionalMatches(); |
| 488 } | 490 } |
| 489 | 491 |
| 490 void OmniboxEditModel::StartAutocomplete( | 492 void OmniboxEditModel::StartAutocomplete( |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 765 popup_->SetSelectedLineState(OmniboxPopupModel::KEYWORD); | 767 popup_->SetSelectedLineState(OmniboxPopupModel::KEYWORD); |
| 766 else | 768 else |
| 767 StartAutocomplete(false, true); | 769 StartAutocomplete(false, true); |
| 768 | 770 |
| 769 // Ensure the current selection is saved before showing keyword mode | 771 // Ensure the current selection is saved before showing keyword mode |
| 770 // so that moving to another line and then reverting the text will restore | 772 // so that moving to another line and then reverting the text will restore |
| 771 // the current state properly. | 773 // the current state properly. |
| 772 bool save_original_selection = !has_temporary_text_; | 774 bool save_original_selection = !has_temporary_text_; |
| 773 has_temporary_text_ = true; | 775 has_temporary_text_ = true; |
| 774 is_temporary_text_set_by_instant_ = false; | 776 is_temporary_text_set_by_instant_ = false; |
| 777 is_instant_temporary_text_a_search_query_ = false; | |
| 775 view_->OnTemporaryTextMaybeChanged( | 778 view_->OnTemporaryTextMaybeChanged( |
| 776 DisplayTextFromUserText(CurrentMatch().fill_into_edit), | 779 DisplayTextFromUserText(CurrentMatch().fill_into_edit), |
| 777 save_original_selection, true); | 780 save_original_selection, true); |
| 778 | 781 |
| 779 content::RecordAction(UserMetricsAction("AcceptedKeywordHint")); | 782 content::RecordAction(UserMetricsAction("AcceptedKeywordHint")); |
| 780 UMA_HISTOGRAM_ENUMERATION(kEnteredKeywordModeHistogram, entered_method, | 783 UMA_HISTOGRAM_ENUMERATION(kEnteredKeywordModeHistogram, entered_method, |
| 781 ENTERED_KEYWORD_MODE_NUM_ITEMS); | 784 ENTERED_KEYWORD_MODE_NUM_ITEMS); |
| 782 | 785 |
| 783 return true; | 786 return true; |
| 784 } | 787 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 904 // Don't change anything unless the key state is actually toggling. | 907 // Don't change anything unless the key state is actually toggling. |
| 905 if (pressed == (control_key_state_ == UP)) { | 908 if (pressed == (control_key_state_ == UP)) { |
| 906 ControlKeyState old_state = control_key_state_; | 909 ControlKeyState old_state = control_key_state_; |
| 907 control_key_state_ = pressed ? DOWN_WITHOUT_CHANGE : UP; | 910 control_key_state_ = pressed ? DOWN_WITHOUT_CHANGE : UP; |
| 908 if ((control_key_state_ == DOWN_WITHOUT_CHANGE) && has_temporary_text_) { | 911 if ((control_key_state_ == DOWN_WITHOUT_CHANGE) && has_temporary_text_) { |
| 909 // Arrowing down and then hitting control accepts the temporary text as | 912 // Arrowing down and then hitting control accepts the temporary text as |
| 910 // the input text. | 913 // the input text. |
| 911 InternalSetUserText(UserTextFromDisplayText(view_->GetText())); | 914 InternalSetUserText(UserTextFromDisplayText(view_->GetText())); |
| 912 has_temporary_text_ = false; | 915 has_temporary_text_ = false; |
| 913 is_temporary_text_set_by_instant_ = false; | 916 is_temporary_text_set_by_instant_ = false; |
| 917 is_instant_temporary_text_a_search_query_ = false; | |
| 914 } | 918 } |
| 915 if ((old_state != DOWN_WITH_CHANGE) && popup_->IsOpen()) { | 919 if ((old_state != DOWN_WITH_CHANGE) && popup_->IsOpen()) { |
| 916 // Autocomplete history provider results may change, so refresh the | 920 // Autocomplete history provider results may change, so refresh the |
| 917 // popup. This will force user_input_in_progress_ to true, but if the | 921 // popup. This will force user_input_in_progress_ to true, but if the |
| 918 // popup is open, that should have already been the case. | 922 // popup is open, that should have already been the case. |
| 919 view_->UpdatePopup(); | 923 view_->UpdatePopup(); |
| 920 } | 924 } |
| 921 } | 925 } |
| 922 } | 926 } |
| 923 | 927 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 972 DCHECK(!keyword_.empty() || !is_keyword_hint_); | 976 DCHECK(!keyword_.empty() || !is_keyword_hint_); |
| 973 } | 977 } |
| 974 | 978 |
| 975 // Handle changes to temporary text. | 979 // Handle changes to temporary text. |
| 976 if (destination_for_temporary_text_change != NULL) { | 980 if (destination_for_temporary_text_change != NULL) { |
| 977 const bool save_original_selection = !has_temporary_text_; | 981 const bool save_original_selection = !has_temporary_text_; |
| 978 if (save_original_selection) { | 982 if (save_original_selection) { |
| 979 // Save the original selection and URL so it can be reverted later. | 983 // Save the original selection and URL so it can be reverted later. |
| 980 has_temporary_text_ = true; | 984 has_temporary_text_ = true; |
| 981 is_temporary_text_set_by_instant_ = false; | 985 is_temporary_text_set_by_instant_ = false; |
| 986 is_instant_temporary_text_a_search_query_ = false; | |
| 982 original_url_ = *destination_for_temporary_text_change; | 987 original_url_ = *destination_for_temporary_text_change; |
| 983 inline_autocomplete_text_.clear(); | 988 inline_autocomplete_text_.clear(); |
| 984 } | 989 } |
| 985 if (control_key_state_ == DOWN_WITHOUT_CHANGE) { | 990 if (control_key_state_ == DOWN_WITHOUT_CHANGE) { |
| 986 // Arrowing around the popup cancels control-enter. | 991 // Arrowing around the popup cancels control-enter. |
| 987 control_key_state_ = DOWN_WITH_CHANGE; | 992 control_key_state_ = DOWN_WITH_CHANGE; |
| 988 // Now things are a bit screwy: the desired_tld has changed, but if we | 993 // Now things are a bit screwy: the desired_tld has changed, but if we |
| 989 // update the popup, the new order of entries won't match the old, so the | 994 // update the popup, the new order of entries won't match the old, so the |
| 990 // user's selection gets screwy; and if we don't update the popup, and the | 995 // user's selection gets screwy; and if we don't update the popup, and the |
| 991 // user reverts, then the selected item will be as if control is still | 996 // user reverts, then the selected item will be as if control is still |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1077 return false; | 1082 return false; |
| 1078 } | 1083 } |
| 1079 | 1084 |
| 1080 // If the user text has not changed, we do not want to change the model's | 1085 // If the user text has not changed, we do not want to change the model's |
| 1081 // state associated with the text. Otherwise, we can get surprising behavior | 1086 // state associated with the text. Otherwise, we can get surprising behavior |
| 1082 // where the autocompleted text unexpectedly reappears, e.g. crbug.com/55983 | 1087 // where the autocompleted text unexpectedly reappears, e.g. crbug.com/55983 |
| 1083 if (user_text_changed) { | 1088 if (user_text_changed) { |
| 1084 InternalSetUserText(UserTextFromDisplayText(new_text)); | 1089 InternalSetUserText(UserTextFromDisplayText(new_text)); |
| 1085 has_temporary_text_ = false; | 1090 has_temporary_text_ = false; |
| 1086 is_temporary_text_set_by_instant_ = false; | 1091 is_temporary_text_set_by_instant_ = false; |
| 1092 is_instant_temporary_text_a_search_query_ = false; | |
| 1087 | 1093 |
| 1088 // Track when the user has deleted text so we won't allow inline | 1094 // Track when the user has deleted text so we won't allow inline |
| 1089 // autocomplete. | 1095 // autocomplete. |
| 1090 just_deleted_text_ = just_deleted_text; | 1096 just_deleted_text_ = just_deleted_text; |
| 1091 | 1097 |
| 1092 if (user_input_in_progress_ && user_text_.empty()) { | 1098 if (user_input_in_progress_ && user_text_.empty()) { |
| 1093 // Log cases where the user started editing and then subsequently cleared | 1099 // Log cases where the user started editing and then subsequently cleared |
| 1094 // all the text. Note that this explicitly doesn't catch cases like | 1100 // all the text. Note that this explicitly doesn't catch cases like |
| 1095 // "hit ctrl-l to select whole edit contents, then hit backspace", because | 1101 // "hit ctrl-l to select whole edit contents, then hit backspace", because |
| 1096 // in such cases, |user_input_in_progress| won't be true here. | 1102 // in such cases, |user_input_in_progress| won't be true here. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1181 if (instant && !in_revert_) { | 1187 if (instant && !in_revert_) { |
| 1182 instant->HandleAutocompleteResults( | 1188 instant->HandleAutocompleteResults( |
| 1183 *autocomplete_controller()->providers()); | 1189 *autocomplete_controller()->providers()); |
| 1184 } | 1190 } |
| 1185 } else if (was_open) { | 1191 } else if (was_open) { |
| 1186 // Accepts the temporary text as the user text, because it makes little | 1192 // Accepts the temporary text as the user text, because it makes little |
| 1187 // sense to have temporary text when the popup is closed. | 1193 // sense to have temporary text when the popup is closed. |
| 1188 InternalSetUserText(UserTextFromDisplayText(view_->GetText())); | 1194 InternalSetUserText(UserTextFromDisplayText(view_->GetText())); |
| 1189 has_temporary_text_ = false; | 1195 has_temporary_text_ = false; |
| 1190 is_temporary_text_set_by_instant_ = false; | 1196 is_temporary_text_set_by_instant_ = false; |
| 1197 is_instant_temporary_text_a_search_query_ = false; | |
| 1191 OnPopupBoundsChanged(gfx::Rect()); | 1198 OnPopupBoundsChanged(gfx::Rect()); |
| 1192 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_); | 1199 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_); |
| 1193 } | 1200 } |
| 1194 } | 1201 } |
| 1195 | 1202 |
| 1196 bool OmniboxEditModel::query_in_progress() const { | 1203 bool OmniboxEditModel::query_in_progress() const { |
| 1197 return !autocomplete_controller()->done(); | 1204 return !autocomplete_controller()->done(); |
| 1198 } | 1205 } |
| 1199 | 1206 |
| 1200 void OmniboxEditModel::InternalSetUserText(const string16& text) { | 1207 void OmniboxEditModel::InternalSetUserText(const string16& text) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1244 CHECK(popup_->selected_line() < result.size()); | 1251 CHECK(popup_->selected_line() < result.size()); |
| 1245 *match = result.match_at(popup_->selected_line()); | 1252 *match = result.match_at(popup_->selected_line()); |
| 1246 } | 1253 } |
| 1247 if (alternate_nav_url && popup_->manually_selected_match().empty()) | 1254 if (alternate_nav_url && popup_->manually_selected_match().empty()) |
| 1248 *alternate_nav_url = result.alternate_nav_url(); | 1255 *alternate_nav_url = result.alternate_nav_url(); |
| 1249 } | 1256 } |
| 1250 | 1257 |
| 1251 void OmniboxEditModel::GetInfoForCurrentText(AutocompleteMatch* match, | 1258 void OmniboxEditModel::GetInfoForCurrentText(AutocompleteMatch* match, |
| 1252 GURL* alternate_nav_url) const { | 1259 GURL* alternate_nav_url) const { |
| 1253 // If there's temporary text and it has been set by Instant, we won't find it | 1260 // If there's temporary text and it has been set by Instant, we won't find it |
| 1254 // in the popup model, so classify the text anew. | 1261 // in the popup model, so create the match based on the type Instant told us |
| 1255 if ((popup_->IsOpen() || query_in_progress()) && | 1262 // (SWYT for queries and UWYT for URLs). We do this instead of classifying the |
| 1256 !is_temporary_text_set_by_instant_) { | 1263 // text ourselves because the text may look like a URL, but Instant may expect |
| 1264 // it to be a search (e.g.: a query for "amazon.com"). | |
| 1265 if (is_temporary_text_set_by_instant_) { | |
| 1266 const string16& text = view_->GetText(); | |
| 1267 AutocompleteInput input(text, string16::npos, string16(), GURL(), false, | |
| 1268 false, false, AutocompleteInput::BEST_MATCH); | |
| 1269 // Only the destination_url and the transition of the match will be be used | |
| 1270 // (to either navigate to the URL or let Instant commit its preview). The | |
| 1271 // match won't be used for logging, displaying in the dropdown, etc. So, | |
| 1272 // it's okay to pass in mostly bogus params (such as relevance = 0). | |
| 1273 // TODO(sreeram): Always using NO_SUGGESTIONS_AVAILABLE is wrong when | |
| 1274 // Instant is using the local fallback overlay. Fix. | |
| 1275 if (is_instant_temporary_text_a_search_query_) { | |
| 1276 const TemplateURL* default_provider = | |
| 1277 TemplateURLServiceFactory::GetForProfile(profile_)-> | |
| 1278 GetDefaultSearchProvider(); | |
| 1279 DCHECK(default_provider); | |
| 1280 DCHECK(default_provider->SupportsReplacement()); | |
|
Peter Kasting
2013/04/27 02:15:26
I'm nervous about these two DCHECKs. I think they
sreeram
2013/04/27 02:21:56
Done. I had added the DCHECK because Instant now l
| |
| 1281 *match = SearchProvider::CreateSearchSuggestion(profile_, | |
| 1282 autocomplete_controller()->search_provider(), input, text, text, 0, | |
| 1283 AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, | |
| 1284 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, false, | |
| 1285 default_provider->keyword()); | |
| 1286 } else { | |
| 1287 *match = HistoryURLProvider::SuggestExactInput( | |
| 1288 autocomplete_controller()->history_url_provider(), input, false); | |
| 1289 } | |
| 1290 } else if (popup_->IsOpen() || query_in_progress()) { | |
| 1257 InfoForCurrentSelection(match, alternate_nav_url); | 1291 InfoForCurrentSelection(match, alternate_nav_url); |
| 1258 } else { | 1292 } else { |
| 1259 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify( | 1293 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify( |
| 1260 UserTextFromDisplayText(view_->GetText()), KeywordIsSelected(), true, | 1294 UserTextFromDisplayText(view_->GetText()), KeywordIsSelected(), true, |
| 1261 match, alternate_nav_url); | 1295 match, alternate_nav_url); |
| 1262 } | 1296 } |
| 1263 } | 1297 } |
| 1264 | 1298 |
| 1265 void OmniboxEditModel::RevertTemporaryText(bool revert_popup) { | 1299 void OmniboxEditModel::RevertTemporaryText(bool revert_popup) { |
| 1266 // The user typed something, then selected a different item. Restore the | 1300 // The user typed something, then selected a different item. Restore the |
| 1267 // text they typed and change back to the default item. | 1301 // text they typed and change back to the default item. |
| 1268 // NOTE: This purposefully does not reset paste_state_. | 1302 // NOTE: This purposefully does not reset paste_state_. |
| 1269 bool notify_instant = is_temporary_text_set_by_instant_; | 1303 bool notify_instant = is_temporary_text_set_by_instant_; |
| 1270 just_deleted_text_ = false; | 1304 just_deleted_text_ = false; |
| 1271 has_temporary_text_ = false; | 1305 has_temporary_text_ = false; |
| 1272 is_temporary_text_set_by_instant_ = false; | 1306 is_temporary_text_set_by_instant_ = false; |
| 1307 is_instant_temporary_text_a_search_query_ = false; | |
| 1273 | 1308 |
| 1274 InstantController* instant = controller_->GetInstant(); | 1309 InstantController* instant = controller_->GetInstant(); |
| 1275 if (instant && notify_instant) { | 1310 if (instant && notify_instant) { |
| 1276 // Normally, popup_->ResetToDefaultMatch() will cause the view text to be | 1311 // Normally, popup_->ResetToDefaultMatch() will cause the view text to be |
| 1277 // updated. In Instant Extended mode however, the popup_ is not used, so it | 1312 // updated. In Instant Extended mode however, the popup_ is not used, so it |
| 1278 // won't do anything. So, update the view ourselves. Even if Instant is not | 1313 // won't do anything. So, update the view ourselves. Even if Instant is not |
| 1279 // in extended mode (i.e., it's enabled in non-extended mode, or disabled | 1314 // in extended mode (i.e., it's enabled in non-extended mode, or disabled |
| 1280 // altogether), this is okay to do, since the call to | 1315 // altogether), this is okay to do, since the call to |
| 1281 // popup_->ResetToDefaultMatch() will just override whatever we do here. | 1316 // popup_->ResetToDefaultMatch() will just override whatever we do here. |
| 1282 // | 1317 // |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1333 return !keyword.empty() && autocomplete_controller()->keyword_provider() && | 1368 return !keyword.empty() && autocomplete_controller()->keyword_provider() && |
| 1334 !autocomplete_controller()->keyword_provider()-> | 1369 !autocomplete_controller()->keyword_provider()-> |
| 1335 GetKeywordForText(keyword).empty(); | 1370 GetKeywordForText(keyword).empty(); |
| 1336 } | 1371 } |
| 1337 | 1372 |
| 1338 bool OmniboxEditModel::DoInstant(const AutocompleteMatch& match) { | 1373 bool OmniboxEditModel::DoInstant(const AutocompleteMatch& match) { |
| 1339 InstantController* instant = controller_->GetInstant(); | 1374 InstantController* instant = controller_->GetInstant(); |
| 1340 if (!instant || in_revert_) | 1375 if (!instant || in_revert_) |
| 1341 return false; | 1376 return false; |
| 1342 | 1377 |
| 1343 // Don't call Update() if the change is a result of a | 1378 // Don't call Update() if the change is the result of an |
| 1344 // INSTANT_COMPLETE_REPLACE instant suggestion. | 1379 // INSTANT_COMPLETE_REPLACE instant suggestion. |
| 1345 if (has_temporary_text_ && is_temporary_text_set_by_instant_) | 1380 if (is_temporary_text_set_by_instant_) |
| 1346 return false; | 1381 return false; |
| 1347 | 1382 |
| 1348 // The two pieces of text we want to send Instant, viz., what the user has | 1383 // The two pieces of text we want to send Instant, viz., what the user has |
| 1349 // typed, and the full omnibox text including any inline autocompletion. | 1384 // typed, and the full omnibox text including any inline autocompletion. |
| 1350 string16 user_text = has_temporary_text_ ? | 1385 string16 user_text = has_temporary_text_ ? |
| 1351 match.fill_into_edit : DisplayTextFromUserText(user_text_); | 1386 match.fill_into_edit : DisplayTextFromUserText(user_text_); |
| 1352 string16 full_text = view_->GetText(); | 1387 string16 full_text = view_->GetText(); |
| 1353 | 1388 |
| 1354 // Remove "?" if we're in forced query mode. | 1389 // Remove "?" if we're in forced query mode. |
| 1355 AutocompleteInput::RemoveForcedQueryStringIfNecessary( | 1390 AutocompleteInput::RemoveForcedQueryStringIfNecessary( |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1425 instant->OmniboxFocusChanged(state, reason, NULL); | 1460 instant->OmniboxFocusChanged(state, reason, NULL); |
| 1426 | 1461 |
| 1427 // Update state and notify view if the omnibox has focus and the caret | 1462 // Update state and notify view if the omnibox has focus and the caret |
| 1428 // visibility changed. | 1463 // visibility changed. |
| 1429 const bool was_caret_visible = is_caret_visible(); | 1464 const bool was_caret_visible = is_caret_visible(); |
| 1430 focus_state_ = state; | 1465 focus_state_ = state; |
| 1431 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1466 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
| 1432 is_caret_visible() != was_caret_visible) | 1467 is_caret_visible() != was_caret_visible) |
| 1433 view_->ApplyCaretVisibility(); | 1468 view_->ApplyCaretVisibility(); |
| 1434 } | 1469 } |
| OLD | NEW |