Chromium Code Reviews| Index: chrome/browser/autocomplete/search_provider.cc |
| diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc |
| index 6aef751433c12f285b2a25af84a096ec10df3f5c..8c9c7d0410913d7684912a522cb95a68cb1f8e10 100644 |
| --- a/chrome/browser/autocomplete/search_provider.cc |
| +++ b/chrome/browser/autocomplete/search_provider.cc |
| @@ -107,41 +107,21 @@ bool HasMultipleWords(const base::string16& text) { |
| void SetAndClassifyMatchContents(const base::string16& query_string, |
| const base::string16& input_text, |
| const base::string16& match_contents, |
| - const base::string16& annotation, |
| AutocompleteMatch* match) { |
| - size_t match_contents_start = 0; |
| - size_t annotation_start = match_contents.size(); |
| - // Append annotation if present. |
| - if (annotation.empty()) { |
| - match->contents = match_contents; |
| - } else { |
| - std::vector<size_t> positions; |
| - match->contents = l10n_util::GetStringFUTF16( |
| - IDS_ANNOTATED_SUGGESTION, match_contents, annotation, &positions); |
|
Peter Kasting
2013/12/10 03:52:30
If we're removing the only reference to IDS_ANNOTA
Anuj
2013/12/10 23:08:09
Done.
|
| - match_contents_start = positions[0]; |
| - annotation_start = positions[1]; |
| - } |
| - size_t match_contents_end = match_contents_start + match_contents.size(); |
| - |
| - if (!annotation.empty() && (annotation_start < match_contents_start)) |
| - match->contents_class.push_back(ACMatchClassification( |
| - annotation_start, ACMatchClassification::DIM)); |
| + match->contents = match_contents.empty() ? query_string : match_contents; |
| // 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 != match_contents) { |
| - size_t input_position = match->contents.substr( |
| - match_contents_start, match_contents.length()).find(input_text); |
| + size_t input_position = match->contents.find(input_text); |
| if (input_position == base::string16::npos) { |
| // The input text is not a substring of the query string, e.g. input |
| // text is "slasdot" and the query string is "slashdot", so we bold the |
| // whole thing. |
| match->contents_class.push_back(ACMatchClassification( |
| - match_contents_start, ACMatchClassification::MATCH)); |
| + 0, ACMatchClassification::MATCH)); |
| } else { |
| - input_position += match_contents_start; |
| - |
| // TODO(beng): ACMatchClassification::MATCH now seems to just mean |
| // "bold" this. Consider modifying the terminology. |
| // We don't iterate over the string here annotating all matches because |
| @@ -149,9 +129,9 @@ void SetAndClassifyMatchContents(const base::string16& query_string, |
| // short as a single character highlighted in a query suggestion result, |
| // e.g. for input text "s" and query string "southwest airlines", it |
| // looks odd if both the first and last s are highlighted. |
| - if (input_position != match_contents_start) { |
| + if (input_position != 0) { |
| match->contents_class.push_back(ACMatchClassification( |
| - match_contents_start, ACMatchClassification::MATCH)); |
| + 0, ACMatchClassification::MATCH)); |
| } |
| match->contents_class.push_back( |
| ACMatchClassification(input_position, ACMatchClassification::NONE)); |
| @@ -165,12 +145,20 @@ void SetAndClassifyMatchContents(const base::string16& query_string, |
| // Otherwise, |match| is a verbatim (what-you-typed) match, either for the |
| // default provider or a keyword search provider. |
| match->contents_class.push_back(ACMatchClassification( |
| - match_contents_start, ACMatchClassification::NONE)); |
| + 0, ACMatchClassification::NONE)); |
| } |
| +} |
| - if (!annotation.empty() && (annotation_start >= match_contents_start)) |
| - match->contents_class.push_back(ACMatchClassification( |
| - match_contents_end, ACMatchClassification::DIM)); |
| +AutocompleteMatchType::Type GetAutocompleteMatchType(const std::string& type) { |
| + if (type == "ENTITY") |
| + return AutocompleteMatchType::SEARCH_SUGGEST_ENTITY; |
| + if (type == "INFINITE") |
| + return AutocompleteMatchType::SEARCH_SUGGEST_INFINITE; |
| + if (type == "PERSONALIZED") |
| + return AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED; |
| + if (type == "PROFILE") |
| + return AutocompleteMatchType::SEARCH_SUGGEST_PROFILE; |
| + return AutocompleteMatchType::SEARCH_SUGGEST; |
| } |
| } // namespace |
| @@ -266,6 +254,7 @@ SearchProvider::Result::~Result() { |
| SearchProvider::SuggestResult::SuggestResult( |
| const base::string16& suggestion, |
| + AutocompleteMatchType::Type type, |
| const base::string16& match_contents, |
| const base::string16& annotation, |
| const std::string& suggest_query_params, |
| @@ -276,6 +265,7 @@ SearchProvider::SuggestResult::SuggestResult( |
| bool should_prefetch) |
| : Result(from_keyword_provider, relevance, relevance_from_server), |
| suggestion_(suggestion), |
| + type_(type), |
| match_contents_(match_contents), |
| annotation_(annotation), |
| suggest_query_params_(suggest_query_params), |
| @@ -426,8 +416,10 @@ AutocompleteMatch SearchProvider::CreateSearchSuggestion( |
| return match; |
| match.keyword = template_url->keyword(); |
| - SetAndClassifyMatchContents( |
| - query_string, input_text, match_contents, annotation, &match); |
| + SetAndClassifyMatchContents(query_string, input_text, match_contents, &match); |
| + |
| + if (!annotation.empty()) |
| + match.description = annotation; |
| match.allowed_to_be_default_match = (input_text == match_contents); |
| @@ -1179,6 +1171,7 @@ bool SearchProvider::ParseSuggestResults(Value* root_val, bool is_keyword) { |
| *this, url, title, is_keyword, relevance, true)); |
| } |
| } else { |
| + AutocompleteMatchType::Type match_type = GetAutocompleteMatchType(type); |
| bool should_prefetch = static_cast<int>(index) == prefetch_index; |
| DictionaryValue* suggestion_detail = NULL; |
| base::string16 match_contents = suggestion; |
| @@ -1190,24 +1183,20 @@ bool SearchProvider::ParseSuggestResults(Value* root_val, bool is_keyword) { |
| suggestion_details->GetDictionary(index, &suggestion_detail); |
| if (suggestion_detail) { |
| suggestion_detail->GetString("du", &deletion_url); |
| - |
| - if (type == "ENTITY") { |
| - suggestion_detail->GetString("a", &annotation); |
| - |
| - base::string16 disambiguating_query; |
| - if (suggestion_detail->GetString("dq", &disambiguating_query) && |
| - !disambiguating_query.empty()) |
| - suggestion = disambiguating_query; |
| - |
| - suggestion_detail->GetString("q", &suggest_query_params); |
| - } |
| + suggestion_detail->GetString("title", &match_contents) || |
| + suggestion_detail->GetString("t", &match_contents); |
| + suggestion_detail->GetString("annotation", &annotation) || |
| + suggestion_detail->GetString("a", &annotation); |
| + suggestion_detail->GetString("query_params", &suggest_query_params) || |
| + suggestion_detail->GetString("q", &suggest_query_params); |
| } |
| } |
| // TODO(kochi): Improve calculator suggestion presentation. |
| results->suggest_results.push_back(SuggestResult( |
| - suggestion, match_contents, annotation, suggest_query_params, |
| - deletion_url, is_keyword, relevance, true, should_prefetch)); |
| + suggestion, match_type, match_contents, annotation, |
| + suggest_query_params, deletion_url, is_keyword, relevance, true, |
| + should_prefetch)); |
| } |
| } |
| @@ -1654,10 +1643,10 @@ SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults( |
| int relevance = CalculateRelevanceForHistory( |
| i->time, is_keyword, !prevent_inline_autocomplete, |
| prevent_search_history_inlining); |
| - scored_results.push_back( |
| - SuggestResult(i->term, base::string16(), base::string16(), |
| - std::string(), std::string(), is_keyword, relevance, |
| - false, false)); |
| + scored_results.push_back(SuggestResult( |
| + i->term, AutocompleteMatchType::SEARCH_HISTORY, base::string16(), |
| + base::string16(), std::string(), std::string(), is_keyword, relevance, |
| + false, false)); |
| } |
| // History returns results sorted for us. However, we may have docked some |
| @@ -1690,7 +1679,7 @@ void SearchProvider::AddSuggestResultsToMap(const SuggestResults& results, |
| results[i].relevance_from_server(), |
| results[i].should_prefetch(), |
| metadata, |
| - AutocompleteMatchType::SEARCH_SUGGEST, |
| + results[i].type(), |
| is_keyword, |
| results[i].match_contents(), |
| results[i].annotation(), |