 Chromium Code Reviews
 Chromium Code Reviews Issue 13141002:
  Use Instant suggested match type for Instant temporary text.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 13141002:
  Use Instant suggested match type for Instant temporary text.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| Index: chrome/browser/autocomplete/search_provider.cc | 
| diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc | 
| index 6b92d82f0f7b28268549197391eac64eb54b2698..43301eaa8cfc31d727d990ea6a44b154e6fabd9a 100644 | 
| --- a/chrome/browser/autocomplete/search_provider.cc | 
| +++ b/chrome/browser/autocomplete/search_provider.cc | 
| @@ -220,6 +220,52 @@ void SearchProvider::ClearInstantSuggestion() { | 
| listener_->OnProviderUpdate(true); | 
| } | 
| +bool SearchProvider::GetSearchWhatYouTypedMatch(const string16& query, | 
| + const string16& original_query, | 
| + int relevance, | 
| + int accepted_suggestion, | 
| + bool is_keyword, | 
| + AutocompleteMatch* match) { | 
| + // Bail out now if we don't actually have a valid provider. | 
| + match->keyword = is_keyword ? providers_.keyword_provider() : | 
| 
Peter Kasting
2013/04/12 00:29:01
Nit: Wrap this like the old code (break after '?'
 
sreeram
2013/04/12 22:36:18
Done.
 | 
| + providers_.default_provider(); | 
| + const TemplateURL* provider_url = match->GetTemplateURL(profile_, false); | 
| + if (provider_url == NULL) | 
| + return false; | 
| + | 
| + match->provider = this; | 
| + match->relevance = relevance; | 
| + match->contents = query; | 
| + // We're dealing with the "default search" result which has no completion. | 
| + match->contents_class.push_back( | 
| + ACMatchClassification(0, ACMatchClassification::NONE)); | 
| + | 
| + if (is_keyword) { | 
| + match->fill_into_edit = match->keyword + char16(' ') + query; | 
| + match->transition = content::PAGE_TRANSITION_KEYWORD; | 
| + match->type = AutocompleteMatch::SEARCH_OTHER_ENGINE; | 
| + } else { | 
| + match->fill_into_edit = query; | 
| + match->transition = content::PAGE_TRANSITION_GENERATED; | 
| + match->type = AutocompleteMatch::SEARCH_WHAT_YOU_TYPED; | 
| + } | 
| + | 
| + const TemplateURLRef& search_url = provider_url->url_ref(); | 
| + DCHECK(search_url.SupportsReplacement()); | 
| + | 
| + match->search_terms_args.reset(new TemplateURLRef::SearchTermsArgs(query)); | 
| + match->search_terms_args->original_query = original_query; | 
| + match->search_terms_args->accepted_suggestion = accepted_suggestion; | 
| + | 
| + // This is the destination URL sans assisted query stats. This must be set so | 
| + // the AutocompleteController can properly de-dupe; the controller will | 
| + // eventually overwrite it before it reaches the user. | 
| + match->destination_url = | 
| + GURL(search_url.ReplaceSearchTerms(*match->search_terms_args.get())); | 
| + | 
| + return true; | 
| +} | 
| + | 
| void SearchProvider::Start(const AutocompleteInput& input, | 
| bool minimal_changes) { | 
| // Do our best to load the model as early as possible. This will reduce | 
| @@ -1325,20 +1371,21 @@ void SearchProvider::AddMatchToMap(const string16& query_string, | 
| int accepted_suggestion, | 
| bool is_keyword, | 
| MatchMap* map) { | 
| - AutocompleteMatch match(this, relevance, false, type); | 
| - std::vector<size_t> content_param_offsets; | 
| - // Bail out now if we don't actually have a valid provider. | 
| - match.keyword = is_keyword ? | 
| - providers_.keyword_provider() : providers_.default_provider(); | 
| - const TemplateURL* provider_url = match.GetTemplateURL(profile_, false); | 
| - if (provider_url == NULL) | 
| + AutocompleteMatch match; | 
| + // We start with a "what you typed" match (even if it's not the correct type) | 
| + // so that we get the benefit of common fields being filled in. We override | 
| + // fields below if the "what you typed" values for them are inappropriate. | 
| + if (!GetSearchWhatYouTypedMatch(query_string, input_text, relevance, | 
| + accepted_suggestion, is_keyword, &match)) | 
| return; | 
| - match.contents.assign(query_string); | 
| + match.type = type; | 
| 
Peter Kasting
2013/04/12 00:29:01
Can we eliminate this, or the fill_into_edit mucki
 
sreeram
2013/04/12 22:36:18
I don't think it makes sense for "SuggestExactInpu
 
Peter Kasting
2013/04/12 22:50:59
Hmm.  Maybe I shouldn't have been so hasty to sugg
 | 
| + | 
| // We do intra-string highlighting for suggestions - the suggested segment | 
| // will be highlighted, e.g. for input_text = "you" the suggestion may be | 
| // "youtube", so we'll bold the "tube" section: you*tube*. | 
| if (input_text != query_string) { | 
| + match.contents_class.clear(); | 
| size_t input_position = match.contents.find(input_text); | 
| if (input_position == string16::npos) { | 
| // The input text is not a substring of the query string, e.g. input | 
| @@ -1367,16 +1414,12 @@ void SearchProvider::AddMatchToMap(const string16& query_string, | 
| ACMatchClassification::NONE)); | 
| } | 
| } | 
| - } else { | 
| - // Otherwise, we're dealing with the "default search" result which has no | 
| - // completion. | 
| - match.contents_class.push_back( | 
| - ACMatchClassification(0, ACMatchClassification::NONE)); | 
| } | 
| // When the user forced a query, we need to make sure all the fill_into_edit | 
| // values preserve that property. Otherwise, if the user starts editing a | 
| // suggestion, non-Search results will suddenly appear. | 
| + match.fill_into_edit.clear(); | 
| if (input_.type() == AutocompleteInput::FORCED_QUERY) | 
| match.fill_into_edit.assign(ASCIIToUTF16("?")); | 
| if (is_keyword) | 
| @@ -1388,22 +1431,6 @@ void SearchProvider::AddMatchToMap(const string16& query_string, | 
| } | 
| match.fill_into_edit.append(query_string); | 
| - const TemplateURLRef& search_url = provider_url->url_ref(); | 
| - DCHECK(search_url.SupportsReplacement()); | 
| - match.search_terms_args.reset( | 
| - new TemplateURLRef::SearchTermsArgs(query_string)); | 
| - match.search_terms_args->original_query = input_text; | 
| - match.search_terms_args->accepted_suggestion = accepted_suggestion; | 
| - // This is the destination URL sans assisted query stats. This must be set | 
| - // so the AutocompleteController can properly de-dupe; the controller will | 
| - // eventually overwrite it before it reaches the user. | 
| - match.destination_url = | 
| - GURL(search_url.ReplaceSearchTerms(*match.search_terms_args.get())); | 
| - | 
| - // Search results don't look like URLs. | 
| - match.transition = is_keyword ? | 
| - content::PAGE_TRANSITION_KEYWORD : content::PAGE_TRANSITION_GENERATED; | 
| - | 
| // Try to add |match| to |map|. If a match for |query_string| is already in | 
| // |map|, replace it if |match| is more relevant. | 
| // NOTE: Keep this ToLower() call in sync with url_database.cc. |