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

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: 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
517 // Only add the keyword if the match does not have a duplicate keyword with 521 // If the user has typed an exact keyword and we haven't yet associated
518 // a more relevant match. 522 // this keyword with some match, ignore whatever keyword (if any) is
523 // already associated with this particular match and let tab-to-search
524 // work for this exact keyword.
Peter Kasting 2014/08/04 21:54:22 Nit: This comment is a bit confusing. How about t
Mark P 2014/08/04 22:05:38 Done.
525 if (!exact_keyword.empty() && !keywords.count(exact_keyword)) {
526 keywords.insert(exact_keyword);
527 match->associated_keyword.reset(new AutocompleteMatch(
528 keyword_provider_->CreateVerbatimMatch(exact_keyword,
529 exact_keyword, input_)));
530 continue;
531 }
532
533 // Otherwise use the particular match's associated keyword, looking it up
534 // if necessary.
519 keyword = match->associated_keyword.get() ? 535 keyword = match->associated_keyword.get() ?
520 match->associated_keyword->keyword : 536 match->associated_keyword->keyword :
521 keyword_provider_->GetKeywordForText(match->fill_into_edit); 537 keyword_provider_->GetKeywordForText(match->fill_into_edit);
538
539 // Only add the keyword if the match does not have a duplicate keyword with
540 // a more relevant match.
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,
Peter Kasting 2014/08/04 21:54:22 What does removing this conditional do?
Mark P 2014/08/04 22:05:38 I was worried that the copy-old-match code will ke
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
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 }
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