Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_controller.cc

Issue 440753003: Omnibox: Make Exact Match Tab-to-Search Work (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: peter's comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/autocomplete/autocomplete_provider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 use the particular match's associated keyword.
Peter Kasting 2014/08/04 22:53:11 Nit: This comment is now somewhat misleading as yo
Mark P 2014/08/04 22:58:24 Done. I see why it's better. Thank you for rewri
536 keyword = keyword_provider_->GetKeywordForText(match->fill_into_edit);
537
517 // Only add the keyword if the match does not have a duplicate keyword with 538 // Only add the keyword if the match does not have a duplicate keyword with
518 // a more relevant match. 539 // 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)) { 540 if (!keyword.empty() && !keywords.count(keyword)) {
523 keywords.insert(keyword); 541 keywords.insert(keyword);
524 542 match->associated_keyword.reset(new AutocompleteMatch(
525 if (!match->associated_keyword.get()) 543 keyword_provider_->CreateVerbatimMatch(match->fill_into_edit,
526 match->associated_keyword.reset(new AutocompleteMatch( 544 keyword, input_)));
527 keyword_provider_->CreateVerbatimMatch(match->fill_into_edit,
528 keyword, input_)));
529 } else { 545 } else {
530 match->associated_keyword.reset(); 546 match->associated_keyword.reset();
531 } 547 }
532 } 548 }
533 } 549 }
534 550
535 void AutocompleteController::UpdateKeywordDescriptions( 551 void AutocompleteController::UpdateKeywordDescriptions(
536 AutocompleteResult* result) { 552 AutocompleteResult* result) {
537 base::string16 last_keyword; 553 base::string16 last_keyword;
538 for (AutocompleteResult::iterator i(result->begin()); i != result->end(); 554 for (AutocompleteResult::iterator i(result->begin()); i != result->end();
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 this, &AutocompleteController::ExpireCopiedEntries); 666 this, &AutocompleteController::ExpireCopiedEntries);
651 } 667 }
652 668
653 void AutocompleteController::StartStopTimer() { 669 void AutocompleteController::StartStopTimer() {
654 stop_timer_.Start(FROM_HERE, 670 stop_timer_.Start(FROM_HERE,
655 stop_timer_duration_, 671 stop_timer_duration_,
656 base::Bind(&AutocompleteController::Stop, 672 base::Bind(&AutocompleteController::Stop,
657 base::Unretained(this), 673 base::Unretained(this),
658 false)); 674 false));
659 } 675 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autocomplete/autocomplete_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698