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

Unified Diff: chrome/browser/autocomplete/zero_suggest_provider.cc

Issue 23164011: Omnibox: Reduce Bolding Flicker in SearchProvider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleaned up zero suggest Created 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autocomplete/zero_suggest_provider.cc
diff --git a/chrome/browser/autocomplete/zero_suggest_provider.cc b/chrome/browser/autocomplete/zero_suggest_provider.cc
index f19b287574c83496553575720dec031fcca38ad9..8576202147b692cdfeea720c9a31320305fc20d6 100644
--- a/chrome/browser/autocomplete/zero_suggest_provider.cc
+++ b/chrome/browser/autocomplete/zero_suggest_provider.cc
@@ -274,6 +274,9 @@ void ZeroSuggestProvider::FillResults(
string16 result, title;
std::string type;
+ const string16 current_query_str16 = ASCIIToUTF16(current_query_);
msw 2013/08/26 22:57:15 Drop "_str16", use "_string" or "_string16" if you
+ const std::string languages =
+ profile_->GetPrefs()->GetString(prefs::kAcceptLanguages);
for (size_t index = 0; results->GetString(index, &result); ++index) {
// Google search may return empty suggestions for weird input characters,
// they make no sense at all and can cause problems in our code.
@@ -292,11 +295,12 @@ void ZeroSuggestProvider::FillResults(
if (descriptions != NULL)
descriptions->GetString(index, &title);
navigation_results->push_back(SearchProvider::NavigationResult(
- *this, url, title, false, relevance, relevances != NULL));
+ *this, url, title, false, relevance, relevances != NULL,
+ current_query_str16, languages));
}
} else {
suggest_results->push_back(SearchProvider::SuggestResult(
- result, false, relevance, relevances != NULL));
+ result, false, relevance, relevances != NULL, current_query_str16));
}
}
}
@@ -306,31 +310,32 @@ void ZeroSuggestProvider::AddSuggestResultsToMap(
const TemplateURL* template_url,
SearchProvider::MatchMap* map) {
for (size_t i = 0; i < results.size(); ++i) {
- AddMatchToMap(results[i].relevance(), AutocompleteMatchType::SEARCH_SUGGEST,
- template_url, results[i].suggestion(), i, map);
+ AddMatchToMap(results[i], AutocompleteMatchType::SEARCH_SUGGEST,
+ template_url, i, map);
}
}
-void ZeroSuggestProvider::AddMatchToMap(int relevance,
- AutocompleteMatch::Type type,
- const TemplateURL* template_url,
- const string16& query_string,
- int accepted_suggestion,
- SearchProvider::MatchMap* map) {
- // Pass in query_string as the input_text since we don't want any bolding.
+void ZeroSuggestProvider::AddMatchToMap(
+ const SearchProvider::SuggestResult& result,
+ AutocompleteMatch::Type type,
+ const TemplateURL* template_url,
+ int accepted_suggestion,
+ SearchProvider::MatchMap* map) {
+ // Pass in result.suggestion() as the input_text since we don't want any
msw 2013/08/26 22:57:15 nit: "to avoid bolding"
+ // bolding.
// TODO(samarth|melevin): use the actual omnibox margin here as well instead
// of passing in -1.
AutocompleteMatch match = SearchProvider::CreateSearchSuggestion(
- this, relevance, type, template_url, query_string, query_string,
- AutocompleteInput(), false, accepted_suggestion, -1, true);
+ this, result, type, template_url, result.suggestion(),
+ AutocompleteInput(), accepted_suggestion, -1, true);
if (!match.destination_url.is_valid())
return;
- // Try to add |match| to |map|. If a match for |query_string| is already in
- // |map|, replace it if |match| is more relevant.
+ // Try to add |match| to |map|. If a match for |result.suggestion()| is
+ // already in |map|, replace it if |match| is more relevant.
// NOTE: Keep this ToLower() call in sync with url_database.cc.
const std::pair<SearchProvider::MatchMap::iterator, bool> i(map->insert(
- std::make_pair(base::i18n::ToLower(query_string), match)));
+ std::make_pair(base::i18n::ToLower(result.suggestion()), match)));
// NOTE: We purposefully do a direct relevance comparison here instead of
// using AutocompleteMatch::MoreRelevant(), so that we'll prefer "items added
// first" rather than "items alphabetically first" when the scores are equal.
@@ -349,6 +354,12 @@ AutocompleteMatch ZeroSuggestProvider::NavigationToMatch(
AutocompleteMatchType::NAVSUGGEST);
match.destination_url = navigation.url();
+ // We ignore navigation.contents() and navigation.contents_class()
msw 2013/08/26 22:57:15 nit: "Zero suggest results should always omit prot
+ // and instead compute our own contents and contents_class
+ // because we want a uniform style of display in zero suggest:
+ // - no bolding of URLs (it doesn't matter if the URL shares a prefix with
+ // the current URL).
+ // - always omit the protocol.
const std::string languages(
profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
match.contents = net::FormatUrl(navigation.url(), languages,

Powered by Google App Engine
This is Rietveld 408576698