Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_controller.h" | 5 #include "chrome/browser/ui/omnibox/omnibox_controller.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 8 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 9 #include "chrome/browser/autocomplete/autocomplete_match.h" | 9 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 10 #include "chrome/browser/autocomplete/search_provider.h" | 10 #include "chrome/browser/autocomplete/search_provider.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 const GURL& current_url, | 62 const GURL& current_url, |
| 63 bool prevent_inline_autocomplete, | 63 bool prevent_inline_autocomplete, |
| 64 bool prefer_keyword, | 64 bool prefer_keyword, |
| 65 bool allow_exact_keyword_match, | 65 bool allow_exact_keyword_match, |
| 66 int omnibox_start_margin) const { | 66 int omnibox_start_margin) const { |
| 67 ClearPopupKeywordMode(); | 67 ClearPopupKeywordMode(); |
| 68 popup_->SetHoveredLine(OmniboxPopupModel::kNoMatch); | 68 popup_->SetHoveredLine(OmniboxPopupModel::kNoMatch); |
| 69 | 69 |
| 70 #if defined(HTML_INSTANT_EXTENDED_POPUP) | 70 #if defined(HTML_INSTANT_EXTENDED_POPUP) |
| 71 InstantController* instant_controller = GetInstantController(); | 71 InstantController* instant_controller = GetInstantController(); |
| 72 if (instant_controller) { | 72 if (instant_controller) { |
|
kmadhusu
2013/06/25 23:30:33
nit: Remove {}.
Jered
2013/06/25 23:33:40
Done.
| |
| 73 instant_controller->OnAutocompleteStart(); | 73 instant_controller->OnAutocompleteStart(); |
| 74 // If the embedded page for InstantExtended is fetching its own suggestions, | |
| 75 // suppress search suggestions from SearchProvider. We still need | |
| 76 // SearchProvider to run for FinalizeInstantQuery. | |
| 77 // TODO(dcblack): Once we are done refactoring the omnibox so we don't need | |
| 78 // to use FinalizeInstantQuery anymore, we can take out this check and | |
| 79 // remove this provider from kInstantExtendedOmniboxProviders. | |
| 80 if (instant_controller->WillFetchCompletions()) | |
| 81 autocomplete_controller_->search_provider()->SuppressSearchSuggestions(); | |
| 82 } | 74 } |
| 83 #endif | 75 #endif |
| 84 if (chrome::IsInstantExtendedAPIEnabled()) { | 76 if (chrome::IsInstantExtendedAPIEnabled()) { |
| 85 autocomplete_controller_->search_provider()-> | 77 autocomplete_controller_->search_provider()-> |
| 86 SetOmniboxStartMargin(omnibox_start_margin); | 78 SetOmniboxStartMargin(omnibox_start_margin); |
| 87 } | 79 } |
| 88 | 80 |
| 89 // We don't explicitly clear OmniboxPopupModel::manually_selected_match, as | 81 // We don't explicitly clear OmniboxPopupModel::manually_selected_match, as |
| 90 // Start ends up invoking OmniboxPopupModel::OnResultChanged which clears it. | 82 // Start ends up invoking OmniboxPopupModel::OnResultChanged which clears it. |
| 91 autocomplete_controller_->Start(AutocompleteInput( | 83 autocomplete_controller_->Start(AutocompleteInput( |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 autocomplete_controller_->input().type(), &full_text); | 169 autocomplete_controller_->input().type(), &full_text); |
| 178 return instant_controller->Update( | 170 return instant_controller->Update( |
| 179 match, user_text, full_text, selection_start, selection_end, | 171 match, user_text, full_text, selection_start, selection_end, |
| 180 UseVerbatimInstant(just_deleted_text), user_input_in_progress, | 172 UseVerbatimInstant(just_deleted_text), user_input_in_progress, |
| 181 popup_->IsOpen(), in_escape_handler, keyword_is_selected); | 173 popup_->IsOpen(), in_escape_handler, keyword_is_selected); |
| 182 #else | 174 #else |
| 183 return false; | 175 return false; |
| 184 #endif | 176 #endif |
| 185 } | 177 } |
| 186 | 178 |
| 187 void OmniboxController::FinalizeInstantQuery( | |
| 188 const string16& input_text, | |
| 189 const InstantSuggestion& suggestion) { | |
| 190 // Should only get called for the HTML popup. | |
| 191 #if defined(HTML_INSTANT_EXTENDED_POPUP) | |
| 192 if (!popup_model()->result().empty()) { | |
| 193 // We need to finalize the instant query in all cases where the | |
| 194 // |popup_model| holds some result. It is not enough to check whether the | |
| 195 // popup is open, since when an IME is active the popup may be closed while | |
| 196 // |popup_model| contains a non-empty result. | |
| 197 SearchProvider* search_provider = | |
| 198 autocomplete_controller_->search_provider(); | |
| 199 // There may be no providers during testing; guard against that. | |
| 200 if (search_provider) | |
| 201 search_provider->FinalizeInstantQuery(input_text, suggestion); | |
| 202 } | |
| 203 #endif | |
| 204 } | |
| 205 | |
| 206 void OmniboxController::SetInstantSuggestion( | 179 void OmniboxController::SetInstantSuggestion( |
| 207 const InstantSuggestion& suggestion) { | 180 const InstantSuggestion& suggestion) { |
| 208 // Should only get called for the HTML popup. | 181 // Should only get called for the HTML popup. |
| 209 #if defined(HTML_INSTANT_EXTENDED_POPUP) | 182 #if defined(HTML_INSTANT_EXTENDED_POPUP) |
| 210 switch (suggestion.behavior) { | 183 switch (suggestion.behavior) { |
| 211 case INSTANT_COMPLETE_NOW: | 184 case INSTANT_COMPLETE_NOW: |
| 212 // Set blue suggestion text. | 185 // Set blue suggestion text. |
| 213 // TODO(beaudoin): This currently goes to the SearchProvider. Instead we | 186 // TODO(beaudoin): Create a valid current_match_ and call |
| 214 // should just create a valid current_match_ and call | 187 // omnibox_edit_model_->OnCurrentMatchChanged. |
| 215 // omnibox_edit_model_->OnCurrentMatchChanged. This way we can get rid of | |
| 216 // FinalizeInstantQuery entirely. | |
| 217 if (!suggestion.text.empty()) | |
| 218 FinalizeInstantQuery(omnibox_edit_model_->GetViewText(), suggestion); | |
| 219 return; | 188 return; |
| 220 | 189 |
| 221 case INSTANT_COMPLETE_NEVER: { | 190 case INSTANT_COMPLETE_NEVER: { |
| 222 DCHECK_EQ(INSTANT_SUGGESTION_SEARCH, suggestion.type); | 191 DCHECK_EQ(INSTANT_SUGGESTION_SEARCH, suggestion.type); |
| 223 | 192 |
| 224 // Set gray suggestion text. | 193 // Set gray suggestion text. |
| 225 // Remove "?" if we're in forced query mode. | 194 // Remove "?" if we're in forced query mode. |
| 226 gray_suggestion_ = suggestion.text; | 195 gray_suggestion_ = suggestion.text; |
| 227 | 196 |
| 228 // TODO(beaudoin): The following should no longer be needed once the | |
| 229 // instant suggestion no longer goes through the search provider. | |
| 230 SearchProvider* search_provider = | |
| 231 autocomplete_controller_->search_provider(); | |
| 232 if (search_provider) | |
| 233 search_provider->ClearInstantSuggestion(); | |
| 234 | |
| 235 omnibox_edit_model_->OnGrayTextChanged(); | 197 omnibox_edit_model_->OnGrayTextChanged(); |
| 236 return; | 198 return; |
| 237 } | 199 } |
| 238 | 200 |
| 239 case INSTANT_COMPLETE_REPLACE: | 201 case INSTANT_COMPLETE_REPLACE: |
| 240 // Replace the entire omnibox text by the suggestion the user just arrowed | 202 // Replace the entire omnibox text by the suggestion the user just arrowed |
| 241 // to. | 203 // to. |
| 242 CreateAndSetInstantMatch(suggestion.text, suggestion.text, | 204 CreateAndSetInstantMatch(suggestion.text, suggestion.text, |
| 243 suggestion.type == INSTANT_SUGGESTION_SEARCH ? | 205 suggestion.type == INSTANT_SUGGESTION_SEARCH ? |
| 244 AutocompleteMatchType::SEARCH_SUGGEST : | 206 AutocompleteMatchType::SEARCH_SUGGEST : |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 string16 input_text, | 273 string16 input_text, |
| 312 AutocompleteMatchType::Type match_type) { | 274 AutocompleteMatchType::Type match_type) { |
| 313 string16 keyword = GetDefaultSearchProviderKeyword(profile_); | 275 string16 keyword = GetDefaultSearchProviderKeyword(profile_); |
| 314 if (keyword.empty()) | 276 if (keyword.empty()) |
| 315 return; // CreateSearchSuggestion needs a keyword. | 277 return; // CreateSearchSuggestion needs a keyword. |
| 316 | 278 |
| 317 current_match_ = SearchProvider::CreateSearchSuggestion( | 279 current_match_ = SearchProvider::CreateSearchSuggestion( |
| 318 profile_, NULL, AutocompleteInput(), query_string, input_text, 0, | 280 profile_, NULL, AutocompleteInput(), query_string, input_text, 0, |
| 319 match_type, 0, false, keyword, -1); | 281 match_type, 0, false, keyword, -1); |
| 320 } | 282 } |
| OLD | NEW |