OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/omnibox/browser/base_search_provider.h" | 5 #include "components/omnibox/browser/base_search_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/i18n/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 static_cast<int>( | 225 static_cast<int>( |
226 suggestion.suggestion().length() - match.contents.length())); | 226 suggestion.suggestion().length() - match.contents.length())); |
227 } | 227 } |
228 | 228 |
229 if (!suggestion.annotation().empty()) { | 229 if (!suggestion.annotation().empty()) { |
230 match.description = suggestion.annotation(); | 230 match.description = suggestion.annotation(); |
231 AutocompleteMatch::AddLastClassificationIfNecessary( | 231 AutocompleteMatch::AddLastClassificationIfNecessary( |
232 &match.description_class, 0, ACMatchClassification::NONE); | 232 &match.description_class, 0, ACMatchClassification::NONE); |
233 } | 233 } |
234 | 234 |
| 235 const base::string16 input_lower = base::i18n::ToLower(input.text()); |
235 // suggestion.match_contents() should have already been collapsed. | 236 // suggestion.match_contents() should have already been collapsed. |
236 match.allowed_to_be_default_match = | 237 match.allowed_to_be_default_match = |
237 (!in_keyword_mode || suggestion.from_keyword_provider()) && | 238 (!in_keyword_mode || suggestion.from_keyword_provider()) && |
238 (base::CollapseWhitespace(input.text(), false) == | 239 (base::CollapseWhitespace(input_lower, false) == |
239 suggestion.match_contents()); | 240 base::i18n::ToLower(suggestion.match_contents())); |
240 | 241 |
241 // When the user forced a query, we need to make sure all the fill_into_edit | 242 // When the user forced a query, we need to make sure all the fill_into_edit |
242 // values preserve that property. Otherwise, if the user starts editing a | 243 // values preserve that property. Otherwise, if the user starts editing a |
243 // suggestion, non-Search results will suddenly appear. | 244 // suggestion, non-Search results will suddenly appear. |
244 if (input.type() == metrics::OmniboxInputType::FORCED_QUERY) | 245 if (input.type() == metrics::OmniboxInputType::FORCED_QUERY) |
245 match.fill_into_edit.assign(base::ASCIIToUTF16("?")); | 246 match.fill_into_edit.assign(base::ASCIIToUTF16("?")); |
246 if (suggestion.from_keyword_provider()) | 247 if (suggestion.from_keyword_provider()) |
247 match.fill_into_edit.append(match.keyword + base::char16(' ')); | 248 match.fill_into_edit.append(match.keyword + base::char16(' ')); |
248 // We only allow inlinable navsuggestions that were received before the | 249 // We only allow inlinable navsuggestions that were received before the |
249 // last keystroke because we don't want asynchronous inline autocompletions. | 250 // last keystroke because we don't want asynchronous inline autocompletions. |
250 if (!input.prevent_inline_autocomplete() && | 251 if (!input.prevent_inline_autocomplete() && |
251 !suggestion.received_after_last_keystroke() && | 252 !suggestion.received_after_last_keystroke() && |
252 (!in_keyword_mode || suggestion.from_keyword_provider()) && | 253 (!in_keyword_mode || suggestion.from_keyword_provider()) && |
253 base::StartsWith( | 254 base::StartsWith( |
254 base::i18n::ToLower(suggestion.suggestion()), | 255 base::i18n::ToLower(suggestion.suggestion()), input_lower, |
255 base::i18n::ToLower(input.text()), base::CompareCase::SENSITIVE)) { | 256 base::CompareCase::SENSITIVE)) { |
256 match.inline_autocompletion = | 257 match.inline_autocompletion = |
257 suggestion.suggestion().substr(input.text().length()); | 258 suggestion.suggestion().substr(input.text().length()); |
258 match.allowed_to_be_default_match = true; | 259 match.allowed_to_be_default_match = true; |
259 } | 260 } |
260 match.fill_into_edit.append(suggestion.suggestion()); | 261 match.fill_into_edit.append(suggestion.suggestion()); |
261 | 262 |
262 const TemplateURLRef& search_url = template_url->url_ref(); | 263 const TemplateURLRef& search_url = template_url->url_ref(); |
263 DCHECK(search_url.SupportsReplacement(search_terms_data)); | 264 DCHECK(search_url.SupportsReplacement(search_terms_data)); |
264 match.search_terms_args.reset( | 265 match.search_terms_args.reset( |
265 new TemplateURLRef::SearchTermsArgs(suggestion.suggestion())); | 266 new TemplateURLRef::SearchTermsArgs(suggestion.suggestion())); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 | 482 |
482 void BaseSearchProvider::OnDeletionComplete( | 483 void BaseSearchProvider::OnDeletionComplete( |
483 bool success, SuggestionDeletionHandler* handler) { | 484 bool success, SuggestionDeletionHandler* handler) { |
484 RecordDeletionResult(success); | 485 RecordDeletionResult(success); |
485 deletion_handlers_.erase(std::remove_if( | 486 deletion_handlers_.erase(std::remove_if( |
486 deletion_handlers_.begin(), deletion_handlers_.end(), | 487 deletion_handlers_.begin(), deletion_handlers_.end(), |
487 [handler](const scoped_ptr<SuggestionDeletionHandler>& elem) { | 488 [handler](const scoped_ptr<SuggestionDeletionHandler>& elem) { |
488 return elem.get() == handler; | 489 return elem.get() == handler; |
489 })); | 490 })); |
490 } | 491 } |
OLD | NEW |