Chromium Code Reviews| Index: components/omnibox/browser/physical_web_provider.cc |
| diff --git a/components/omnibox/browser/physical_web_provider.cc b/components/omnibox/browser/physical_web_provider.cc |
| index caac80699f9eb5b5d6fc59fc55ad2c0eea390ffb..df714c19e0cafeeee0b01d4c09084a6066fdc3de 100644 |
| --- a/components/omnibox/browser/physical_web_provider.cc |
| +++ b/components/omnibox/browser/physical_web_provider.cc |
| @@ -14,6 +14,7 @@ |
| #include "components/url_formatter/url_formatter.h" |
| #include "grit/components_strings.h" |
| #include "ui/base/l10n/l10n_util.h" |
| +#include "ui/gfx/text_elider.h" |
| #include "url/gurl.h" |
| namespace { |
| @@ -36,6 +37,11 @@ static const size_t kPhysicalWebMaxMatches = 1; |
| // in the metadata list. |
| static const int kPhysicalWebUrlBaseRelevance = 700; |
| +// The maximum length of the page title's part of the overflow item's |
| +// description. Longer titles will be truncated to this length. In a normal |
| +// Physical Web match item (non-overflow item) we allow the omnibox display to |
| +// truncate the title instead. |
| +static const size_t kMaxTitleLength = 15; |
|
Mark P
2016/09/13 23:34:42
Please put overflow in the name somewhere here.
mattreynolds
2016/09/14 19:04:41
Done.
|
| } |
| // static |
| @@ -117,17 +123,19 @@ void PhysicalWebProvider::ConstructMatches(base::ListValue* metadata_list) { |
| // the metadata list. |
| int relevance = kPhysicalWebUrlBaseRelevance - used_slots; |
| + base::string16 title = |
|
Mark P
2016/09/13 23:34:43
nit: This goes best right after line 120.
mattreynolds
2016/09/14 19:04:41
Done.
|
| + AutocompleteMatch::SanitizeString(base::UTF8ToUTF16(title_string)); |
| + |
| // Append an overflow item if creating a match for each metadata item would |
| // exceed the match limit. |
| const size_t remaining_slots = kPhysicalWebMaxMatches - used_slots; |
| const size_t remaining_metadata = metadata_count - i; |
| if ((remaining_slots == 1) && (remaining_metadata > remaining_slots)) { |
| - AppendOverflowItem(remaining_metadata, relevance); |
| + AppendOverflowItem(remaining_metadata, relevance, title); |
| return; |
| } |
| GURL url(url_string); |
| - base::string16 title = base::UTF8ToUTF16(title_string); |
| AutocompleteMatch match(this, relevance, false, |
| AutocompleteMatchType::PHYSICAL_WEB); |
| @@ -145,7 +153,7 @@ void PhysicalWebProvider::ConstructMatches(base::ListValue* metadata_list) { |
| AutocompleteInput::FormattedStringWithEquivalentMeaning( |
| url, match.contents, client_->GetSchemeClassifier()); |
| - match.description = AutocompleteMatch::SanitizeString(title); |
| + match.description = title; |
| match.description_class.push_back( |
| ACMatchClassification(0, ACMatchClassification::NONE)); |
| @@ -155,7 +163,8 @@ void PhysicalWebProvider::ConstructMatches(base::ListValue* metadata_list) { |
| } |
| void PhysicalWebProvider::AppendOverflowItem(int additional_url_count, |
| - int relevance) { |
| + int relevance, |
| + const base::string16& title) { |
| std::string url_string = "chrome://physical-web"; |
| GURL url(url_string); |
| @@ -163,19 +172,28 @@ void PhysicalWebProvider::AppendOverflowItem(int additional_url_count, |
| AutocompleteMatchType::PHYSICAL_WEB_OVERFLOW); |
| match.destination_url = url; |
| - // Don't omit the chrome:// scheme when displaying the WebUI URL. |
| - match.contents = url_formatter::FormatUrl(url, |
| - url_formatter::kFormatUrlOmitNothing, net::UnescapeRule::SPACES, |
| - nullptr, nullptr, nullptr); |
| + base::string16 contents_title = |
| + gfx::TruncateString(title, kMaxTitleLength, gfx::CHARACTER_BREAK); |
| + base::string16 contents; |
|
Mark P
2016/09/13 23:34:42
nit: consider setting match.contents directly in t
mattreynolds
2016/09/14 19:04:41
Done.
|
| + if (contents_title.empty()) { |
| + contents = l10n_util::GetPluralStringFUTF16( |
| + IDS_PHYSICAL_WEB_OVERFLOW_EMPTY_TITLE, additional_url_count); |
| + } else { |
| + base::string16 contents_suffix = l10n_util::GetPluralStringFUTF16( |
| + IDS_PHYSICAL_WEB_OVERFLOW, additional_url_count - 1); |
| + contents = contents_title + base::UTF8ToUTF16(" ") + contents_suffix; |
| + } |
| + |
| + match.contents = contents; |
| match.contents_class.push_back( |
| - ACMatchClassification(0, ACMatchClassification::URL)); |
| + ACMatchClassification(0, ACMatchClassification::DIM)); |
| match.fill_into_edit = |
| AutocompleteInput::FormattedStringWithEquivalentMeaning( |
| url, match.contents, client_->GetSchemeClassifier()); |
| - match.description = l10n_util::GetPluralStringFUTF16( |
| - IDS_PHYSICAL_WEB_OVERFLOW, additional_url_count); |
| + match.description = |
| + l10n_util::GetStringUTF16(IDS_PHYSICAL_WEB_OVERFLOW_DESCRIPTION); |
| match.description_class.push_back( |
| ACMatchClassification(0, ACMatchClassification::NONE)); |