Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 view_->OnAfterPossibleChange(); | 176 view_->OnAfterPossibleChange(); |
| 177 } else if (popup_->IsOpen()) { | 177 } else if (popup_->IsOpen()) { |
| 178 SearchProvider* search_provider = | 178 SearchProvider* search_provider = |
| 179 autocomplete_controller_->search_provider(); | 179 autocomplete_controller_->search_provider(); |
| 180 // There may be no providers during testing; guard against that. | 180 // There may be no providers during testing; guard against that. |
| 181 if (search_provider) | 181 if (search_provider) |
| 182 search_provider->FinalizeInstantQuery(input_text, suggest_text); | 182 search_provider->FinalizeInstantQuery(input_text, suggest_text); |
| 183 } | 183 } |
| 184 } | 184 } |
| 185 | 185 |
| 186 void OmniboxEditModel::SetSuggestedText(const string16& text, | 186 void OmniboxEditModel::SetSuggestedText(const string16& text, |
|
Peter Kasting
2012/08/24 23:13:08
Is this function now only called from OnWillKillFo
sreeram
2012/08/24 23:22:33
No, it's called from the UI code as well. When Ins
| |
| 187 InstantCompleteBehavior behavior) { | 187 InstantCompleteBehavior behavior) { |
| 188 if (behavior == INSTANT_COMPLETE_NOW) { | 188 if (behavior == INSTANT_COMPLETE_NOW) { |
| 189 if (!text.empty()) | 189 if (!text.empty()) |
| 190 FinalizeInstantQuery(view_->GetText(), text, false); | 190 FinalizeInstantQuery(view_->GetText(), text, false); |
| 191 else | 191 else |
| 192 view_->SetInstantSuggestion(text, false); | 192 view_->SetInstantSuggestion(text, false); |
| 193 } else { | 193 } else { |
| 194 DCHECK((behavior == INSTANT_COMPLETE_DELAYED) || | 194 DCHECK((behavior == INSTANT_COMPLETE_DELAYED) || |
| 195 (behavior == INSTANT_COMPLETE_NEVER)); | 195 (behavior == INSTANT_COMPLETE_NEVER)); |
| 196 view_->SetInstantSuggestion(text, behavior == INSTANT_COMPLETE_DELAYED); | 196 view_->SetInstantSuggestion(text, behavior == INSTANT_COMPLETE_DELAYED); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 // before it's needed. Note: This event is triggered as part of startup when | 236 // before it's needed. Note: This event is triggered as part of startup when |
| 237 // the initial tab transitions to the start page. | 237 // the initial tab transitions to the start page. |
| 238 recommended_action = | 238 recommended_action = |
| 239 action_predictor->RecommendAction(user_text_, current_match); | 239 action_predictor->RecommendAction(user_text_, current_match); |
| 240 } | 240 } |
| 241 | 241 |
| 242 UMA_HISTOGRAM_ENUMERATION("AutocompleteActionPredictor.Action", | 242 UMA_HISTOGRAM_ENUMERATION("AutocompleteActionPredictor.Action", |
| 243 recommended_action, | 243 recommended_action, |
| 244 AutocompleteActionPredictor::LAST_PREDICT_ACTION); | 244 AutocompleteActionPredictor::LAST_PREDICT_ACTION); |
| 245 | 245 |
| 246 string16 suggested_text; | 246 if (!DoInstant(current_match)) { |
| 247 InstantCompleteBehavior complete_behavior = INSTANT_COMPLETE_NOW; | |
| 248 | |
| 249 if (DoInstant(current_match, &suggested_text, &complete_behavior)) { | |
| 250 SetSuggestedText(suggested_text, complete_behavior); | |
| 251 } else { | |
| 252 switch (recommended_action) { | 247 switch (recommended_action) { |
| 253 case AutocompleteActionPredictor::ACTION_PRERENDER: | 248 case AutocompleteActionPredictor::ACTION_PRERENDER: |
| 254 DoPrerender(current_match); | 249 DoPrerender(current_match); |
| 255 break; | 250 break; |
| 256 case AutocompleteActionPredictor::ACTION_PRECONNECT: | 251 case AutocompleteActionPredictor::ACTION_PRECONNECT: |
| 257 DoPreconnect(current_match); | 252 DoPreconnect(current_match); |
| 258 break; | 253 break; |
| 259 case AutocompleteActionPredictor::ACTION_NONE: | 254 case AutocompleteActionPredictor::ACTION_NONE: |
| 260 break; | 255 break; |
| 261 default: | 256 default: |
| (...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1102 GetKeywordForText(keyword).empty(); | 1097 GetKeywordForText(keyword).empty(); |
| 1103 } | 1098 } |
| 1104 | 1099 |
| 1105 void OmniboxEditModel::NotifySearchTabHelper() { | 1100 void OmniboxEditModel::NotifySearchTabHelper() { |
| 1106 if (controller_->GetTabContents()) { | 1101 if (controller_->GetTabContents()) { |
| 1107 controller_->GetTabContents()->search_tab_helper()-> | 1102 controller_->GetTabContents()->search_tab_helper()-> |
| 1108 OmniboxEditModelChanged(user_input_in_progress_, !in_revert_); | 1103 OmniboxEditModelChanged(user_input_in_progress_, !in_revert_); |
| 1109 } | 1104 } |
| 1110 } | 1105 } |
| 1111 | 1106 |
| 1112 bool OmniboxEditModel::DoInstant( | 1107 bool OmniboxEditModel::DoInstant(const AutocompleteMatch& match) { |
| 1113 const AutocompleteMatch& match, | |
| 1114 string16* suggested_text, | |
| 1115 InstantCompleteBehavior* complete_behavior) { | |
| 1116 DCHECK(suggested_text); | |
| 1117 DCHECK(complete_behavior); | |
| 1118 | |
| 1119 if (in_revert_) | 1108 if (in_revert_) |
| 1120 return false; | 1109 return false; |
| 1121 | 1110 |
| 1122 InstantController* instant = controller_->GetInstant(); | 1111 InstantController* instant = controller_->GetInstant(); |
| 1123 | 1112 |
| 1124 if (!instant) | 1113 if (!instant) |
| 1125 return false; | 1114 return false; |
| 1126 | 1115 |
| 1127 if (user_input_in_progress_ && popup_->IsOpen()) { | 1116 if (user_input_in_progress_ && popup_->IsOpen()) { |
| 1128 // The two pieces of text we want to send Instant, viz., what the user has | 1117 // The two pieces of text we want to send Instant, viz., what the user has |
| 1129 // typed, and any inline autocomplete suggestion. | 1118 // typed, and the full omnibox text including any inline autocompletion. |
| 1130 string16 user_text = user_text_; | 1119 string16 user_text = user_text_; |
| 1131 *suggested_text = inline_autocomplete_text_; | 1120 string16 full_text = user_text_ + inline_autocomplete_text_; |
| 1132 | 1121 |
| 1133 // If there's temporary text, that overrides the user_text. In this case, we | 1122 // If there's temporary text, that overrides the user_text. In this case, we |
| 1134 // should ignore any inline_autocomplete_text_, because it won't be visible. | 1123 // should ignore any inline_autocomplete_text_, because it won't be visible. |
| 1135 if (has_temporary_text_) { | 1124 if (has_temporary_text_) |
| 1136 user_text = CurrentMatch().fill_into_edit; | 1125 user_text = full_text = CurrentMatch().fill_into_edit; |
| 1137 suggested_text->clear(); | |
| 1138 } | |
| 1139 | 1126 |
| 1140 // Remove any keywords and "?" prefix. | 1127 // Remove keyword if we're in keyword mode. |
| 1141 user_text = DisplayTextFromUserText(user_text); | 1128 user_text = DisplayTextFromUserText(user_text); |
| 1129 full_text = DisplayTextFromUserText(full_text); | |
| 1130 | |
| 1131 // Remove "?" if we're in forced query mode. | |
| 1142 AutocompleteInput::RemoveForcedQueryStringIfNecessary( | 1132 AutocompleteInput::RemoveForcedQueryStringIfNecessary( |
| 1143 autocomplete_controller_->input().type(), &user_text); | 1133 autocomplete_controller_->input().type(), &user_text); |
| 1134 AutocompleteInput::RemoveForcedQueryStringIfNecessary( | |
| 1135 autocomplete_controller_->input().type(), &full_text); | |
| 1144 | 1136 |
| 1145 return instant->Update(match, user_text, UseVerbatimInstant(), | 1137 return instant->Update(match, user_text, full_text, UseVerbatimInstant()); |
| 1146 suggested_text, complete_behavior); | |
| 1147 } | 1138 } |
| 1148 | 1139 |
| 1149 // It's possible DoInstant() was called due to an OnChanged() event from the | 1140 // It's possible DoInstant() was called due to an OnChanged() event from the |
| 1150 // omnibox view if the user clicked the renderer while IME composition was | 1141 // omnibox view if the user clicked the renderer while IME composition was |
| 1151 // active. In that case we still want to commit on mouse up, so don't call | 1142 // active. In that case we still want to commit on mouse up, so don't call |
| 1152 // Hide(). | 1143 // Hide(). |
| 1153 if (!instant->commit_on_pointer_release()) | 1144 if (!instant->commit_on_pointer_release()) |
| 1154 instant->Hide(); | 1145 instant->Hide(); |
| 1155 return false; | 1146 return false; |
| 1156 } | 1147 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1216 } | 1207 } |
| 1217 | 1208 |
| 1218 void OmniboxEditModel::ClassifyStringForPasteAndGo( | 1209 void OmniboxEditModel::ClassifyStringForPasteAndGo( |
| 1219 const string16& text, | 1210 const string16& text, |
| 1220 AutocompleteMatch* match, | 1211 AutocompleteMatch* match, |
| 1221 GURL* alternate_nav_url) const { | 1212 GURL* alternate_nav_url) const { |
| 1222 DCHECK(match); | 1213 DCHECK(match); |
| 1223 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, | 1214 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, |
| 1224 string16(), false, false, match, alternate_nav_url); | 1215 string16(), false, false, match, alternate_nav_url); |
| 1225 } | 1216 } |
| OLD | NEW |