Commit ee6110b8 authored by mpearson@chromium.org's avatar mpearson@chromium.org

Omnibox: Reduce Bolding Flicker in SearchProvider

Do this by computing bolding at the time results are fetched from the
suggest server and keeping that same bolding regardless of what
keys the user presses later.

At the moment, this change only affects query suggestions, not
navsuggestions.

BUG=259486

Review URL: https://codereview.chromium.org/23164011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243998 0039d316-1c4b-4281-b951-d872f2087c98
parent 5584eab1
......@@ -215,12 +215,16 @@ class SearchProvider : public AutocompleteProvider,
bool from_keyword_provider,
int relevance,
bool relevance_from_server,
bool should_prefetch);
bool should_prefetch,
const base::string16& input_text);
virtual ~SuggestResult();
const base::string16& suggestion() const { return suggestion_; }
AutocompleteMatchType::Type type() const { return type_; }
const base::string16& match_contents() const { return match_contents_; }
const ACMatchClassifications& match_contents_class() const {
return match_contents_class_;
}
const base::string16& annotation() const { return annotation_; }
const std::string& suggest_query_params() const {
return suggest_query_params_;
......@@ -228,6 +232,13 @@ class SearchProvider : public AutocompleteProvider,
const std::string& deletion_url() const { return deletion_url_; }
bool should_prefetch() const { return should_prefetch_; }
// Fills in |match_contents_class| to reflect how |match_contents_| should
// be displayed and bolded against the current |input_text|. If
// |allow_bolding_all| is false and |match_contents_class_| would have all
// of |match_contents_| bolded, do nothing.
void ClassifyMatchContents(const bool allow_bolding_all,
const base::string16& input_text);
// Result:
virtual bool IsInlineable(const base::string16& input) const OVERRIDE;
virtual int CalculateRelevance(
......@@ -240,8 +251,9 @@ class SearchProvider : public AutocompleteProvider,
AutocompleteMatchType::Type type_;
// The contents to be displayed in the autocomplete match.
// The contents to be displayed and its style info.
base::string16 match_contents_;
ACMatchClassifications match_contents_class_;
// Optional annotation for the |match_contents_| for disambiguation.
// This may be displayed in the autocomplete match contents, but is defined
......@@ -370,6 +382,11 @@ class SearchProvider : public AutocompleteProvider,
SuggestResults* suggest_results,
NavigationResults* navigation_results);
// Recalculates the match contents class of |suggest_results| to better
// display against the current input.
static void UpdateMatchContentsClass(const base::string16& input_text,
SuggestResults* suggest_results);
// Calculates the relevance score for the keyword verbatim result (if the
// input matches one of the profile's keyword).
static int CalculateRelevanceForKeywordVerbatim(AutocompleteInput::Type type,
......
......@@ -3390,9 +3390,9 @@ TEST_F(SearchProviderTest, RemoveStaleResultsTest) {
provider_->default_results_.suggest_results.push_back(
SearchProvider::SuggestResult(
ASCIIToUTF16(suggestion), AutocompleteMatchType::SEARCH_SUGGEST,
base::string16(), base::string16(), std::string(),
ASCIIToUTF16(suggestion), base::string16(), std::string(),
std::string(), false, cases[i].results[j].relevance, false,
false));
false, ASCIIToUTF16(cases[i].omnibox_input)));
}
}
......
......@@ -245,6 +245,8 @@ void ZeroSuggestProvider::FillResults(
base::string16 result, title;
std::string type;
const base::string16 current_query_string16 =
base::ASCIIToUTF16(current_query_);
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.
......@@ -270,7 +272,7 @@ void ZeroSuggestProvider::FillResults(
suggest_results->push_back(SearchProvider::SuggestResult(
result, AutocompleteMatchType::SEARCH_SUGGEST, result,
base::string16(), std::string(), std::string(), false, relevance,
relevances != NULL, false));
relevances != NULL, false, current_query_string16));
}
}
}
......@@ -291,10 +293,10 @@ void ZeroSuggestProvider::AddMatchToMap(int relevance,
const base::string16& query_string,
int accepted_suggestion,
SearchProvider::MatchMap* map) {
// Pass in query_string as the input_text to avoid bolding.
SearchProvider::SuggestResult suggestion(
query_string, type, query_string, base::string16(), std::string(),
std::string(), false, relevance, true, false);
// Pass in query_string as the input_text since we don't want any bolding.
std::string(), false, relevance, true, false, query_string);
// TODO(samarth|melevin): use the actual omnibox margin here as well instead
// of passing in -1.
AutocompleteMatch match = SearchProvider::CreateSearchSuggestion(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment