| 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/autocomplete_controller.h" | 5 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 last_time_default_match_changed_ = base::TimeTicks::Now(); | 497 last_time_default_match_changed_ = base::TimeTicks::Now(); |
| 498 | 498 |
| 499 NotifyChanged(force_notify_default_match_changed || notify_default_match); | 499 NotifyChanged(force_notify_default_match_changed || notify_default_match); |
| 500 } | 500 } |
| 501 | 501 |
| 502 void AutocompleteController::UpdateAssociatedKeywords( | 502 void AutocompleteController::UpdateAssociatedKeywords( |
| 503 AutocompleteResult* result) { | 503 AutocompleteResult* result) { |
| 504 if (!keyword_provider_) | 504 if (!keyword_provider_) |
| 505 return; | 505 return; |
| 506 | 506 |
| 507 // Determine if the user's input is an exact keyword match. |
| 508 base::string16 exact_keyword = keyword_provider_->GetKeywordForText( |
| 509 TemplateURLService::CleanUserInputKeyword(input_.text())); |
| 510 |
| 507 std::set<base::string16> keywords; | 511 std::set<base::string16> keywords; |
| 508 for (ACMatches::iterator match(result->begin()); match != result->end(); | 512 for (ACMatches::iterator match(result->begin()); match != result->end(); |
| 509 ++match) { | 513 ++match) { |
| 510 base::string16 keyword( | 514 base::string16 keyword( |
| 511 match->GetSubstitutingExplicitlyInvokedKeyword(template_url_service_)); | 515 match->GetSubstitutingExplicitlyInvokedKeyword(template_url_service_)); |
| 512 if (!keyword.empty()) { | 516 if (!keyword.empty()) { |
| 513 keywords.insert(keyword); | 517 keywords.insert(keyword); |
| 514 continue; | 518 continue; |
| 515 } | 519 } |
| 516 | 520 |
| 521 // When the user has typed an exact keyword, we want tab-to-search on the |
| 522 // default match to select that keyword, even if the match |
| 523 // inline-autocompletes to a different keyword. (This prevents inline |
| 524 // autocompletions from blocking a user's attempts to use an explicitly-set |
| 525 // keyword of their own creation.) So use |exact_keyword| if it's |
| 526 // available. |
| 527 if (!exact_keyword.empty() && !keywords.count(exact_keyword)) { |
| 528 keywords.insert(exact_keyword); |
| 529 match->associated_keyword.reset(new AutocompleteMatch( |
| 530 keyword_provider_->CreateVerbatimMatch(exact_keyword, |
| 531 exact_keyword, input_))); |
| 532 continue; |
| 533 } |
| 534 |
| 535 // Otherwise, set a match's associated keyword based on the match's |
| 536 // fill_into_edit, which should take inline autocompletions into account. |
| 537 keyword = keyword_provider_->GetKeywordForText(match->fill_into_edit); |
| 538 |
| 517 // Only add the keyword if the match does not have a duplicate keyword with | 539 // Only add the keyword if the match does not have a duplicate keyword with |
| 518 // a more relevant match. | 540 // a more relevant match. |
| 519 keyword = match->associated_keyword.get() ? | |
| 520 match->associated_keyword->keyword : | |
| 521 keyword_provider_->GetKeywordForText(match->fill_into_edit); | |
| 522 if (!keyword.empty() && !keywords.count(keyword)) { | 541 if (!keyword.empty() && !keywords.count(keyword)) { |
| 523 keywords.insert(keyword); | 542 keywords.insert(keyword); |
| 524 | 543 match->associated_keyword.reset(new AutocompleteMatch( |
| 525 if (!match->associated_keyword.get()) | 544 keyword_provider_->CreateVerbatimMatch(match->fill_into_edit, |
| 526 match->associated_keyword.reset(new AutocompleteMatch( | 545 keyword, input_))); |
| 527 keyword_provider_->CreateVerbatimMatch(match->fill_into_edit, | |
| 528 keyword, input_))); | |
| 529 } else { | 546 } else { |
| 530 match->associated_keyword.reset(); | 547 match->associated_keyword.reset(); |
| 531 } | 548 } |
| 532 } | 549 } |
| 533 } | 550 } |
| 534 | 551 |
| 535 void AutocompleteController::UpdateKeywordDescriptions( | 552 void AutocompleteController::UpdateKeywordDescriptions( |
| 536 AutocompleteResult* result) { | 553 AutocompleteResult* result) { |
| 537 base::string16 last_keyword; | 554 base::string16 last_keyword; |
| 538 for (AutocompleteResult::iterator i(result->begin()); i != result->end(); | 555 for (AutocompleteResult::iterator i(result->begin()); i != result->end(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 this, &AutocompleteController::ExpireCopiedEntries); | 667 this, &AutocompleteController::ExpireCopiedEntries); |
| 651 } | 668 } |
| 652 | 669 |
| 653 void AutocompleteController::StartStopTimer() { | 670 void AutocompleteController::StartStopTimer() { |
| 654 stop_timer_.Start(FROM_HERE, | 671 stop_timer_.Start(FROM_HERE, |
| 655 stop_timer_duration_, | 672 stop_timer_duration_, |
| 656 base::Bind(&AutocompleteController::Stop, | 673 base::Bind(&AutocompleteController::Stop, |
| 657 base::Unretained(this), | 674 base::Unretained(this), |
| 658 false)); | 675 false)); |
| 659 } | 676 } |
| OLD | NEW |