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/autocomplete/keyword_provider.h" | 5 #include "chrome/browser/autocomplete/keyword_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 } | 278 } |
| 279 if (keyword_matches.empty()) | 279 if (keyword_matches.empty()) |
| 280 return; | 280 return; |
| 281 std::sort(keyword_matches.begin(), keyword_matches.end(), CompareQuality()); | 281 std::sort(keyword_matches.begin(), keyword_matches.end(), CompareQuality()); |
| 282 | 282 |
| 283 // Limit to one exact or three inexact matches, and mark them up for display | 283 // Limit to one exact or three inexact matches, and mark them up for display |
| 284 // in the autocomplete popup. | 284 // in the autocomplete popup. |
| 285 // Any exact match is going to be the highest quality match, and thus at the | 285 // Any exact match is going to be the highest quality match, and thus at the |
| 286 // front of our vector. | 286 // front of our vector. |
| 287 if (keyword_matches.front() == keyword) { | 287 if (keyword_matches.front() == keyword) { |
| 288 const TemplateURL* template_url(model->GetTemplateURLForKeyword(keyword)); | 288 const TemplateURL* template_url(model->GetTemplateURLForKeyword(keyword)); |
|
Bart N.
2013/01/29 18:50:42
That's a weird way of initializing. Why no simply
Mark P
2013/01/30 19:46:21
Done.
| |
| 289 // TODO(pkasting): We should probably check that if the user explicitly | 289 const bool is_extension_keyword = |
| 290 // typed a scheme, that scheme matches the one in |template_url|. | 290 profile_ && template_url->IsExtensionKeyword(); |
| 291 matches_.push_back(CreateAutocompleteMatch(model, keyword, input, | 291 if (remaining_input.empty() || is_extension_keyword) { |
|
Bart N.
2013/01/29 18:50:42
This is getting ugly (many nested ifs and not to m
Mark P
2013/01/30 19:46:21
Done.
| |
| 292 keyword.length(), | 292 // We only create an exact match if remaining_input is empty or |
| 293 remaining_input, -1)); | 293 // if this is an extension keyword; if remaining_input is a non-empty |
| 294 // non-extension keyword (i.e., we have a regular keyword that | |
| 295 // supports replacement and has extra text following it), then we | |
| 296 // let SearchProvider create the exact (a.k.a. verbatim) match. | |
| 294 | 297 |
| 295 if (profile_ && template_url->IsExtensionKeyword()) { | 298 // TODO(pkasting): We should probably check that if the user explicitly |
| 296 if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) { | 299 // typed a scheme, that scheme matches the one in |template_url|. |
| 297 if (template_url->GetExtensionId() != current_keyword_extension_id_) | 300 matches_.push_back(CreateAutocompleteMatch(model, keyword, input, |
| 298 MaybeEndExtensionKeywordMode(); | 301 keyword.length(), |
| 299 if (current_keyword_extension_id_.empty()) | 302 remaining_input, -1)); |
| 300 EnterExtensionKeywordMode(template_url->GetExtensionId()); | |
| 301 keyword_mode_toggle.StayInKeywordMode(); | |
| 302 } | |
| 303 | 303 |
| 304 extensions::ApplyDefaultSuggestionForExtensionKeyword( | 304 if (is_extension_keyword) { |
| 305 profile_, template_url, | 305 if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) { |
| 306 remaining_input, | 306 if (template_url->GetExtensionId() != current_keyword_extension_id_) |
| 307 &matches_[0]); | 307 MaybeEndExtensionKeywordMode(); |
| 308 if (current_keyword_extension_id_.empty()) | |
| 309 EnterExtensionKeywordMode(template_url->GetExtensionId()); | |
| 310 keyword_mode_toggle.StayInKeywordMode(); | |
| 311 } | |
| 308 | 312 |
| 309 if (minimal_changes && | 313 extensions::ApplyDefaultSuggestionForExtensionKeyword( |
| 310 (input.matches_requested() != AutocompleteInput::BEST_MATCH)) { | 314 profile_, template_url, |
| 311 // If the input hasn't significantly changed, we can just use the | 315 remaining_input, |
| 312 // suggestions from last time. We need to readjust the relevance to | 316 &matches_[0]); |
| 313 // ensure it is less than the main match's relevance. | 317 |
| 314 for (size_t i = 0; i < extension_suggest_matches_.size(); ++i) { | 318 if (minimal_changes && |
| 315 matches_.push_back(extension_suggest_matches_[i]); | 319 (input.matches_requested() != AutocompleteInput::BEST_MATCH)) { |
| 316 matches_.back().relevance = matches_[0].relevance - (i + 1); | 320 // If the input hasn't significantly changed, we can just use the |
| 321 // suggestions from last time. We need to readjust the relevance to | |
| 322 // ensure it is less than the main match's relevance. | |
| 323 for (size_t i = 0; i < extension_suggest_matches_.size(); ++i) { | |
| 324 matches_.push_back(extension_suggest_matches_[i]); | |
| 325 matches_.back().relevance = matches_[0].relevance - (i + 1); | |
| 326 } | |
| 327 } else if (input.matches_requested() == | |
| 328 AutocompleteInput::ALL_MATCHES) { | |
| 329 extension_suggest_last_input_ = input; | |
| 330 extension_suggest_matches_.clear(); | |
| 331 | |
| 332 bool have_listeners = | |
| 333 extensions::ExtensionOmniboxEventRouter::OnInputChanged( | |
| 334 profile_, template_url->GetExtensionId(), | |
| 335 UTF16ToUTF8(remaining_input), current_input_id_); | |
| 336 | |
| 337 // We only have to wait for suggest results if there are actually | |
| 338 // extensions listening for input changes. | |
| 339 if (have_listeners) | |
| 340 done_ = false; | |
| 317 } | 341 } |
| 318 } else if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) { | |
| 319 extension_suggest_last_input_ = input; | |
| 320 extension_suggest_matches_.clear(); | |
| 321 | |
| 322 bool have_listeners = | |
| 323 extensions::ExtensionOmniboxEventRouter::OnInputChanged( | |
| 324 profile_, template_url->GetExtensionId(), | |
| 325 UTF16ToUTF8(remaining_input), current_input_id_); | |
| 326 | |
| 327 // We only have to wait for suggest results if there are actually | |
| 328 // extensions listening for input changes. | |
| 329 if (have_listeners) | |
| 330 done_ = false; | |
| 331 } | 342 } |
| 332 } | 343 } |
| 333 } else { | 344 } else { // no exact keyword match |
| 334 if (keyword_matches.size() > kMaxMatches) { | 345 if (keyword_matches.size() > kMaxMatches) { |
| 335 keyword_matches.erase(keyword_matches.begin() + kMaxMatches, | 346 keyword_matches.erase(keyword_matches.begin() + kMaxMatches, |
| 336 keyword_matches.end()); | 347 keyword_matches.end()); |
| 337 } | 348 } |
| 338 for (std::vector<string16>::const_iterator i(keyword_matches.begin()); | 349 for (std::vector<string16>::const_iterator i(keyword_matches.begin()); |
| 339 i != keyword_matches.end(); ++i) { | 350 i != keyword_matches.end(); ++i) { |
| 340 matches_.push_back(CreateAutocompleteMatch(model, *i, | 351 matches_.push_back(CreateAutocompleteMatch(model, *i, |
| 341 input, keyword.length(), | 352 input, keyword.length(), |
| 342 remaining_input, -1)); | 353 remaining_input, -1)); |
| 343 } | 354 } |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 586 } | 597 } |
| 587 | 598 |
| 588 void KeywordProvider::MaybeEndExtensionKeywordMode() { | 599 void KeywordProvider::MaybeEndExtensionKeywordMode() { |
| 589 if (!current_keyword_extension_id_.empty()) { | 600 if (!current_keyword_extension_id_.empty()) { |
| 590 extensions::ExtensionOmniboxEventRouter::OnInputCancelled( | 601 extensions::ExtensionOmniboxEventRouter::OnInputCancelled( |
| 591 profile_, current_keyword_extension_id_); | 602 profile_, current_keyword_extension_id_); |
| 592 | 603 |
| 593 current_keyword_extension_id_.clear(); | 604 current_keyword_extension_id_.clear(); |
| 594 } | 605 } |
| 595 } | 606 } |
| OLD | NEW |