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

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

Issue 6334017: Always allow exact match non-substituting keywords. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 } else { 358 } else {
359 // See comments on an identical NOTREACHED() in search_provider.cc. 359 // See comments on an identical NOTREACHED() in search_provider.cc.
360 NOTREACHED(); 360 NOTREACHED();
361 } 361 }
362 } 362 }
363 } 363 }
364 364
365 // static 365 // static
366 int KeywordProvider::CalculateRelevance(AutocompleteInput::Type type, 366 int KeywordProvider::CalculateRelevance(AutocompleteInput::Type type,
367 bool complete, 367 bool complete,
368 bool no_query_text_needed, 368 bool prefer_keyword,
369 bool supports_replacement,
369 bool allow_exact_keyword_match) { 370 bool allow_exact_keyword_match) {
370 if (!complete) 371 if (!complete)
371 return (type == AutocompleteInput::URL) ? 700 : 450; 372 return (type == AutocompleteInput::URL) ? 700 : 450;
372 if (!allow_exact_keyword_match) 373 if (!allow_exact_keyword_match && supports_replacement)
Peter Kasting 2011/01/25 23:20:44 Nit: This is minor, but I wonder if it might not b
James Su 2011/01/26 00:53:31 Done.
373 return 1100; 374 return 1100;
374 if (no_query_text_needed) 375 if (prefer_keyword || !supports_replacement)
375 return 1500; 376 return 1500;
376 return (type == AutocompleteInput::QUERY) ? 1450 : 1100; 377 return (type == AutocompleteInput::QUERY) ? 1450 : 1100;
377 } 378 }
378 379
379 AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( 380 AutocompleteMatch KeywordProvider::CreateAutocompleteMatch(
380 TemplateURLModel* model, 381 TemplateURLModel* model,
381 const string16& keyword, 382 const string16& keyword,
382 const AutocompleteInput& input, 383 const AutocompleteInput& input,
383 size_t prefix_length, 384 size_t prefix_length,
384 const string16& remaining_input, 385 const string16& remaining_input,
385 int relevance) { 386 int relevance) {
386 DCHECK(model); 387 DCHECK(model);
387 // Get keyword data from data store. 388 // Get keyword data from data store.
388 const TemplateURL* element( 389 const TemplateURL* element(
389 model->GetTemplateURLForKeyword(keyword)); 390 model->GetTemplateURLForKeyword(keyword));
390 DCHECK(element && element->url()); 391 DCHECK(element && element->url());
391 const bool supports_replacement = element->url()->SupportsReplacement(); 392 const bool supports_replacement = element->url()->SupportsReplacement();
392 393
393 // Create an edit entry of "[keyword] [remaining input]". This is helpful 394 // Create an edit entry of "[keyword] [remaining input]". This is helpful
394 // even when [remaining input] is empty, as the user can select the popup 395 // even when [remaining input] is empty, as the user can select the popup
395 // choice and immediately begin typing in query input. 396 // choice and immediately begin typing in query input.
396 const bool keyword_complete = (prefix_length == keyword.length()); 397 const bool keyword_complete = (prefix_length == keyword.length());
397 if (relevance < 0) { 398 if (relevance < 0) {
398 relevance = 399 relevance =
399 CalculateRelevance(input.type(), keyword_complete, 400 CalculateRelevance(input.type(), keyword_complete,
400 // When the user wants keyword matches to take 401 // When the user wants keyword matches to take
401 // preference, score them highly regardless of 402 // preference, score them highly regardless of
402 // whether the input provides query text. 403 // whether the input provides query text.
403 input.prefer_keyword() || !supports_replacement, 404 input.prefer_keyword(), supports_replacement,
404 input.allow_exact_keyword_match()); 405 input.allow_exact_keyword_match());
405 } 406 }
406 AutocompleteMatch result(this, relevance, false, 407 AutocompleteMatch result(this, relevance, false,
407 supports_replacement ? AutocompleteMatch::SEARCH_OTHER_ENGINE : 408 supports_replacement ? AutocompleteMatch::SEARCH_OTHER_ENGINE :
408 AutocompleteMatch::HISTORY_KEYWORD); 409 AutocompleteMatch::HISTORY_KEYWORD);
409 result.fill_into_edit.assign(keyword); 410 result.fill_into_edit.assign(keyword);
410 if (!remaining_input.empty() || !keyword_complete || supports_replacement) 411 if (!remaining_input.empty() || !keyword_complete || supports_replacement)
411 result.fill_into_edit.push_back(L' '); 412 result.fill_into_edit.push_back(L' ');
412 result.fill_into_edit.append(remaining_input); 413 result.fill_into_edit.append(remaining_input);
413 // If we wanted to set |result.inline_autocomplete_offset| correctly, we'd 414 // If we wanted to set |result.inline_autocomplete_offset| correctly, we'd
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 // AutocompleteProvider::kMaxMatches. 489 // AutocompleteProvider::kMaxMatches.
489 for (size_t i = 0; i < suggestions.suggestions.size(); ++i) { 490 for (size_t i = 0; i < suggestions.suggestions.size(); ++i) {
490 const ExtensionOmniboxSuggestion& suggestion = 491 const ExtensionOmniboxSuggestion& suggestion =
491 suggestions.suggestions[i]; 492 suggestions.suggestions[i];
492 // We want to order these suggestions in descending order, so start with 493 // We want to order these suggestions in descending order, so start with
493 // the relevance of the first result (added synchronously in Start()), 494 // the relevance of the first result (added synchronously in Start()),
494 // and subtract 1 for each subsequent suggestion from the extension. 495 // and subtract 1 for each subsequent suggestion from the extension.
495 // We know that |complete| is true, because we wouldn't get results from 496 // We know that |complete| is true, because we wouldn't get results from
496 // the extension unless the full keyword had been typed. 497 // the extension unless the full keyword had been typed.
497 int first_relevance = CalculateRelevance(input.type(), true, 498 int first_relevance = CalculateRelevance(input.type(), true,
498 input.prefer_keyword(), input.allow_exact_keyword_match()); 499 input.prefer_keyword(), true, input.allow_exact_keyword_match());
499 extension_suggest_matches_.push_back(CreateAutocompleteMatch( 500 extension_suggest_matches_.push_back(CreateAutocompleteMatch(
500 model, keyword, input, keyword.length(), 501 model, keyword, input, keyword.length(),
501 suggestion.content, first_relevance - (i + 1))); 502 suggestion.content, first_relevance - (i + 1)));
502 503
503 AutocompleteMatch* match = &extension_suggest_matches_.back(); 504 AutocompleteMatch* match = &extension_suggest_matches_.back();
504 match->contents.assign(suggestion.description); 505 match->contents.assign(suggestion.description);
505 match->contents_class = suggestion.description_styles; 506 match->contents_class = suggestion.description_styles;
506 match->description.clear(); 507 match->description.clear();
507 match->description_class.clear(); 508 match->description_class.clear();
508 } 509 }
(...skipping 21 matching lines...) Expand all
530 } 531 }
531 532
532 void KeywordProvider::MaybeEndExtensionKeywordMode() { 533 void KeywordProvider::MaybeEndExtensionKeywordMode() {
533 if (!current_keyword_extension_id_.empty()) { 534 if (!current_keyword_extension_id_.empty()) {
534 ExtensionOmniboxEventRouter::OnInputCancelled( 535 ExtensionOmniboxEventRouter::OnInputCancelled(
535 profile_, current_keyword_extension_id_); 536 profile_, current_keyword_extension_id_);
536 537
537 current_keyword_extension_id_.clear(); 538 current_keyword_extension_id_.clear();
538 } 539 }
539 } 540 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698