diff options
Diffstat (limited to 'chrome/browser/autocomplete/search_provider.cc')
-rw-r--r-- | chrome/browser/autocomplete/search_provider.cc | 59 |
1 files changed, 45 insertions, 14 deletions
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc index ff49c8a..3f15f38 100644 --- a/chrome/browser/autocomplete/search_provider.cc +++ b/chrome/browser/autocomplete/search_provider.cc @@ -87,6 +87,16 @@ void SearchProvider::FinalizeInstantQuery(const std::wstring& input_text, // destination_url for comparison as it varies depending upon the index passed // to TemplateURL::ReplaceSearchTerms. for (ACMatches::iterator i = matches_.begin(); i != matches_.end();) { + // Reset the description/description_class of all searches. We'll set the + // description of the new first match in the call to + // UpdateFirstSearchMatchDescription() below. + if ((i->type == AutocompleteMatch::SEARCH_HISTORY) || + (i->type == AutocompleteMatch::SEARCH_SUGGEST) || + (i->type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED)) { + i->description.clear(); + i->description_class.clear(); + } + if (((i->type == AutocompleteMatch::SEARCH_HISTORY) || (i->type == AutocompleteMatch::SEARCH_SUGGEST)) && (i->fill_into_edit == text)) { @@ -109,6 +119,10 @@ void SearchProvider::FinalizeInstantQuery(const std::wstring& input_text, input_.initial_prevent_inline_autocomplete(), &match_map); DCHECK_EQ(1u, match_map.size()); matches_.push_back(match_map.begin()->second); + // Sort the results so that UpdateFirstSearchDescription does the right thing. + std::sort(matches_.begin(), matches_.end(), &AutocompleteMatch::MoreRelevant); + + UpdateFirstSearchMatchDescription(); listener_->OnProviderUpdate(true); } @@ -165,13 +179,8 @@ void SearchProvider::Start(const AutocompleteInput& input, l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE))); match.contents_class.push_back( ACMatchClassification(0, ACMatchClassification::NONE)); - match.description.assign(UTF16ToWideHack(l10n_util::GetStringFUTF16( - IDS_AUTOCOMPLETE_SEARCH_DESCRIPTION, - WideToUTF16Hack( - default_provider->AdjustedShortNameForLocaleDirection())))); - match.description_class.push_back( - ACMatchClassification(0, ACMatchClassification::DIM)); matches_.push_back(match); + UpdateFirstSearchMatchDescription(); } Stop(); return; @@ -549,6 +558,8 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() { if (matches_.size() > max_total_matches) matches_.erase(matches_.begin() + max_total_matches, matches_.end()); + UpdateFirstSearchMatchDescription(); + UpdateStarredStateOfMatches(); UpdateDone(); @@ -692,11 +703,11 @@ void SearchProvider::AddMatchToMap(const std::wstring& query_string, std::vector<size_t> content_param_offsets; const TemplateURL& provider = is_keyword ? providers_.keyword_provider() : providers_.default_provider(); + match.contents.assign(query_string); // 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.assign(query_string); size_t input_position = match.contents.find(input_text); if (input_position == std::wstring::npos) { // The input text is not a substring of the query string, e.g. input @@ -727,15 +738,9 @@ void SearchProvider::AddMatchToMap(const std::wstring& query_string, } } else { // Otherwise, we're dealing with the "default search" result which has no - // completion, but has the search provider name as the description. - match.contents.assign(query_string); + // completion. match.contents_class.push_back( ACMatchClassification(0, ACMatchClassification::NONE)); - match.description.assign(UTF16ToWideHack(l10n_util::GetStringFUTF16( - IDS_AUTOCOMPLETE_SEARCH_DESCRIPTION, - WideToUTF16Hack(provider.AdjustedShortNameForLocaleDirection())))); - match.description_class.push_back( - ACMatchClassification(0, ACMatchClassification::DIM)); } // When the user forced a query, we need to make sure all the fill_into_edit @@ -827,3 +832,29 @@ void SearchProvider::UpdateDone() { done_ = ((suggest_results_pending_ == 0) && (instant_finalized_ || !InstantController::IsEnabled(profile_))); } + +void SearchProvider::UpdateFirstSearchMatchDescription() { + if (!providers_.valid_default_provider() || matches_.empty()) + return; + + for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) { + AutocompleteMatch& match = *i; + switch (match.type) { + case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: + case AutocompleteMatch::SEARCH_HISTORY: + case AutocompleteMatch::SEARCH_SUGGEST: + match.description.assign( + UTF16ToWideHack(l10n_util::GetStringFUTF16( + IDS_AUTOCOMPLETE_SEARCH_DESCRIPTION, + WideToUTF16Hack(providers_.default_provider(). + AdjustedShortNameForLocaleDirection())))); + match.description_class.push_back( + ACMatchClassification(0, ACMatchClassification::DIM)); + // Only the first search match gets a description. + return; + + default: + break; + } + } +} |