| 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) |
| 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 } | |
| 83 #endif | 74 #endif |
| 84 if (chrome::IsInstantExtendedAPIEnabled()) { | 75 if (chrome::IsInstantExtendedAPIEnabled()) { |
| 85 autocomplete_controller_->search_provider()-> | 76 autocomplete_controller_->search_provider()-> |
| 86 SetOmniboxStartMargin(omnibox_start_margin); | 77 SetOmniboxStartMargin(omnibox_start_margin); |
| 87 } | 78 } |
| 88 | 79 |
| 89 // We don't explicitly clear OmniboxPopupModel::manually_selected_match, as | 80 // We don't explicitly clear OmniboxPopupModel::manually_selected_match, as |
| 90 // Start ends up invoking OmniboxPopupModel::OnResultChanged which clears it. | 81 // Start ends up invoking OmniboxPopupModel::OnResultChanged which clears it. |
| 91 autocomplete_controller_->Start(AutocompleteInput( | 82 autocomplete_controller_->Start(AutocompleteInput( |
| 92 user_text, cursor_position, string16(), current_url, | 83 user_text, cursor_position, string16(), current_url, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 autocomplete_controller_->input().type(), &full_text); | 168 autocomplete_controller_->input().type(), &full_text); |
| 178 return instant_controller->Update( | 169 return instant_controller->Update( |
| 179 match, user_text, full_text, selection_start, selection_end, | 170 match, user_text, full_text, selection_start, selection_end, |
| 180 UseVerbatimInstant(just_deleted_text), user_input_in_progress, | 171 UseVerbatimInstant(just_deleted_text), user_input_in_progress, |
| 181 popup_->IsOpen(), in_escape_handler, keyword_is_selected); | 172 popup_->IsOpen(), in_escape_handler, keyword_is_selected); |
| 182 #else | 173 #else |
| 183 return false; | 174 return false; |
| 184 #endif | 175 #endif |
| 185 } | 176 } |
| 186 | 177 |
| 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( | 178 void OmniboxController::SetInstantSuggestion( |
| 207 const InstantSuggestion& suggestion) { | 179 const InstantSuggestion& suggestion) { |
| 208 // Should only get called for the HTML popup. | 180 // Should only get called for the HTML popup. |
| 209 #if defined(HTML_INSTANT_EXTENDED_POPUP) | 181 #if defined(HTML_INSTANT_EXTENDED_POPUP) |
| 210 switch (suggestion.behavior) { | 182 switch (suggestion.behavior) { |
| 211 case INSTANT_COMPLETE_NOW: | 183 case INSTANT_COMPLETE_NOW: |
| 212 // Set blue suggestion text. | 184 // Set blue suggestion text. |
| 213 // TODO(beaudoin): This currently goes to the SearchProvider. Instead we | 185 // TODO(beaudoin): Create a valid current_match_ and call |
| 214 // should just create a valid current_match_ and call | 186 // 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; | 187 return; |
| 220 | 188 |
| 221 case INSTANT_COMPLETE_NEVER: { | 189 case INSTANT_COMPLETE_NEVER: { |
| 222 DCHECK_EQ(INSTANT_SUGGESTION_SEARCH, suggestion.type); | 190 DCHECK_EQ(INSTANT_SUGGESTION_SEARCH, suggestion.type); |
| 223 | 191 |
| 224 // Set gray suggestion text. | 192 // Set gray suggestion text. |
| 225 // Remove "?" if we're in forced query mode. | 193 // Remove "?" if we're in forced query mode. |
| 226 gray_suggestion_ = suggestion.text; | 194 gray_suggestion_ = suggestion.text; |
| 227 | 195 |
| 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(); | 196 omnibox_edit_model_->OnGrayTextChanged(); |
| 236 return; | 197 return; |
| 237 } | 198 } |
| 238 | 199 |
| 239 case INSTANT_COMPLETE_REPLACE: | 200 case INSTANT_COMPLETE_REPLACE: |
| 240 // Replace the entire omnibox text by the suggestion the user just arrowed | 201 // Replace the entire omnibox text by the suggestion the user just arrowed |
| 241 // to. | 202 // to. |
| 242 CreateAndSetInstantMatch(suggestion.text, suggestion.text, | 203 CreateAndSetInstantMatch(suggestion.text, suggestion.text, |
| 243 suggestion.type == INSTANT_SUGGESTION_SEARCH ? | 204 suggestion.type == INSTANT_SUGGESTION_SEARCH ? |
| 244 AutocompleteMatchType::SEARCH_SUGGEST : | 205 AutocompleteMatchType::SEARCH_SUGGEST : |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 string16 input_text, | 272 string16 input_text, |
| 312 AutocompleteMatchType::Type match_type) { | 273 AutocompleteMatchType::Type match_type) { |
| 313 string16 keyword = GetDefaultSearchProviderKeyword(profile_); | 274 string16 keyword = GetDefaultSearchProviderKeyword(profile_); |
| 314 if (keyword.empty()) | 275 if (keyword.empty()) |
| 315 return; // CreateSearchSuggestion needs a keyword. | 276 return; // CreateSearchSuggestion needs a keyword. |
| 316 | 277 |
| 317 current_match_ = SearchProvider::CreateSearchSuggestion( | 278 current_match_ = SearchProvider::CreateSearchSuggestion( |
| 318 profile_, NULL, AutocompleteInput(), query_string, input_text, 0, | 279 profile_, NULL, AutocompleteInput(), query_string, input_text, 0, |
| 319 match_type, 0, false, keyword, -1); | 280 match_type, 0, false, keyword, -1); |
| 320 } | 281 } |
| OLD | NEW |