Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/ptr_util.h" | 5 #include "base/memory/ptr_util.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "components/omnibox/browser/autocomplete_provider_client.h" | 8 #include "components/omnibox/browser/autocomplete_provider_client.h" |
| 9 #include "components/omnibox/browser/autocomplete_provider_listener.h" | 9 #include "components/omnibox/browser/autocomplete_provider_listener.h" |
| 10 #include "components/omnibox/browser/history_url_provider.h" | 10 #include "components/omnibox/browser/history_url_provider.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 // suggestion will be the overflow item which navigates to the WebUI when | 29 // suggestion will be the overflow item which navigates to the WebUI when |
| 30 // tapped. | 30 // tapped. |
| 31 static const size_t kPhysicalWebMaxMatches = 1; | 31 static const size_t kPhysicalWebMaxMatches = 1; |
| 32 | 32 |
| 33 // Relevance score of the first Physical Web URL autocomplete match. This score | 33 // Relevance score of the first Physical Web URL autocomplete match. This score |
| 34 // is intended to be between ClipboardURLProvider and ZeroSuggestProvider. | 34 // is intended to be between ClipboardURLProvider and ZeroSuggestProvider. |
| 35 // Subsequent matches should decrease in relevance to preserve the ordering | 35 // Subsequent matches should decrease in relevance to preserve the ordering |
| 36 // in the metadata list. | 36 // in the metadata list. |
| 37 static const int kPhysicalWebUrlBaseRelevance = 700; | 37 static const int kPhysicalWebUrlBaseRelevance = 700; |
| 38 | 38 |
| 39 // The maximum length of the page title in the overflow item. Longer titles will | |
|
Mark P
2016/09/08 18:49:50
nit: consider:
"page title in the overflow item"
-
mattreynolds
2016/09/09 21:24:54
Done.
| |
| 40 // be truncated to this length. | |
| 41 static const size_t kMaxTitleLength = 15; | |
|
Mark P
2016/09/08 18:49:49
Where did you get this number from? Calculations
mattreynolds
2016/09/09 21:24:54
I found the longest string of "m"s that would fit
Mark P
2016/09/13 23:34:42
Is this the number of "m"s that would fit, or the
mattreynolds
2016/09/14 19:04:41
It's the number of "m"s that would fit once the re
| |
| 42 | |
| 39 } | 43 } |
| 40 | 44 |
| 41 // static | 45 // static |
| 42 PhysicalWebProvider* PhysicalWebProvider::Create( | 46 PhysicalWebProvider* PhysicalWebProvider::Create( |
| 43 AutocompleteProviderClient* client, | 47 AutocompleteProviderClient* client, |
| 44 HistoryURLProvider* history_url_provider) { | 48 HistoryURLProvider* history_url_provider) { |
| 45 return new PhysicalWebProvider(client, history_url_provider); | 49 return new PhysicalWebProvider(client, history_url_provider); |
| 46 } | 50 } |
| 47 | 51 |
| 48 void PhysicalWebProvider::Start(const AutocompleteInput& input, | 52 void PhysicalWebProvider::Start(const AutocompleteInput& input, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 | 119 |
| 116 // Add match items with decreasing relevance to preserve the ordering in | 120 // Add match items with decreasing relevance to preserve the ordering in |
| 117 // the metadata list. | 121 // the metadata list. |
| 118 int relevance = kPhysicalWebUrlBaseRelevance - used_slots; | 122 int relevance = kPhysicalWebUrlBaseRelevance - used_slots; |
| 119 | 123 |
| 120 // Append an overflow item if creating a match for each metadata item would | 124 // Append an overflow item if creating a match for each metadata item would |
| 121 // exceed the match limit. | 125 // exceed the match limit. |
| 122 const size_t remaining_slots = kPhysicalWebMaxMatches - used_slots; | 126 const size_t remaining_slots = kPhysicalWebMaxMatches - used_slots; |
| 123 const size_t remaining_metadata = metadata_count - i; | 127 const size_t remaining_metadata = metadata_count - i; |
| 124 if ((remaining_slots == 1) && (remaining_metadata > remaining_slots)) { | 128 if ((remaining_slots == 1) && (remaining_metadata > remaining_slots)) { |
| 125 AppendOverflowItem(remaining_metadata, relevance); | 129 AppendOverflowItem(remaining_metadata, relevance, title_string); |
| 126 return; | 130 return; |
| 127 } | 131 } |
| 128 | 132 |
| 129 GURL url(url_string); | 133 GURL url(url_string); |
| 130 base::string16 title = base::UTF8ToUTF16(title_string); | 134 base::string16 title = base::UTF8ToUTF16(title_string); |
| 131 | 135 |
| 132 AutocompleteMatch match(this, relevance, false, | 136 AutocompleteMatch match(this, relevance, false, |
| 133 AutocompleteMatchType::PHYSICAL_WEB); | 137 AutocompleteMatchType::PHYSICAL_WEB); |
| 134 match.destination_url = url; | 138 match.destination_url = url; |
| 135 | 139 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 148 match.description = AutocompleteMatch::SanitizeString(title); | 152 match.description = AutocompleteMatch::SanitizeString(title); |
| 149 match.description_class.push_back( | 153 match.description_class.push_back( |
| 150 ACMatchClassification(0, ACMatchClassification::NONE)); | 154 ACMatchClassification(0, ACMatchClassification::NONE)); |
| 151 | 155 |
| 152 matches_.push_back(match); | 156 matches_.push_back(match); |
| 153 ++used_slots; | 157 ++used_slots; |
| 154 } | 158 } |
| 155 } | 159 } |
| 156 | 160 |
| 157 void PhysicalWebProvider::AppendOverflowItem(int additional_url_count, | 161 void PhysicalWebProvider::AppendOverflowItem(int additional_url_count, |
| 158 int relevance) { | 162 int relevance, |
| 163 const std::string& title) { | |
| 159 std::string url_string = "chrome://physical-web"; | 164 std::string url_string = "chrome://physical-web"; |
| 160 GURL url(url_string); | 165 GURL url(url_string); |
| 161 | 166 |
| 162 AutocompleteMatch match(this, relevance, false, | 167 AutocompleteMatch match(this, relevance, false, |
| 163 AutocompleteMatchType::PHYSICAL_WEB_OVERFLOW); | 168 AutocompleteMatchType::PHYSICAL_WEB_OVERFLOW); |
| 164 match.destination_url = url; | 169 match.destination_url = url; |
| 165 | 170 |
| 166 // Don't omit the chrome:// scheme when displaying the WebUI URL. | 171 std::string contents_title; |
| 167 match.contents = url_formatter::FormatUrl(url, | 172 if (title.length() > kMaxTitleLength) { |
|
Mark P
2016/09/08 18:49:49
This is slightly wrong if indeed as you say above
mattreynolds
2016/09/09 21:24:54
I'm now using gfx::TruncateString which ensures th
| |
| 168 url_formatter::kFormatUrlOmitNothing, net::UnescapeRule::SPACES, | 173 contents_title = title.substr(0, kMaxTitleLength) + "... "; |
|
Mark P
2016/09/08 18:49:49
You probably should be using one of the standard c
mattreynolds
2016/09/09 21:24:54
I switched to using gfx::TruncateString, which aut
| |
| 169 nullptr, nullptr, nullptr); | 174 } else { |
| 175 contents_title = title + " "; | |
| 176 } | |
|
Mark P
2016/09/08 18:49:49
Please also consider what happens with non-latin c
Mark P
2016/09/08 18:49:49
Please consider what happens with empty titles.
mattreynolds
2016/09/09 21:24:54
I'm not sure what the best practices are for RTL i
mattreynolds
2016/09/09 21:24:54
I added an alternate string to use when the title
Mark P
2016/09/13 23:34:42
Good enough for now I think. You may want to brin
mattreynolds
2016/09/14 19:04:41
Acknowledged.
| |
| 177 base::string16 contents_suffix = l10n_util::GetPluralStringFUTF16( | |
| 178 IDS_PHYSICAL_WEB_OVERFLOW, additional_url_count - 1); | |
| 179 base::string16 contents_string = base::UTF8ToUTF16(contents_title) + | |
| 180 contents_suffix; | |
| 181 | |
| 182 match.contents = contents_string; | |
| 170 match.contents_class.push_back( | 183 match.contents_class.push_back( |
| 171 ACMatchClassification(0, ACMatchClassification::URL)); | 184 ACMatchClassification(0, ACMatchClassification::DIM)); |
| 172 | 185 |
| 173 match.fill_into_edit = | 186 match.fill_into_edit = |
| 174 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 187 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
| 175 url, match.contents, client_->GetSchemeClassifier()); | 188 url, match.contents, client_->GetSchemeClassifier()); |
| 176 | 189 |
| 177 match.description = l10n_util::GetPluralStringFUTF16( | 190 match.description = l10n_util::GetStringUTF16( |
| 178 IDS_PHYSICAL_WEB_OVERFLOW, additional_url_count); | 191 IDS_PHYSICAL_WEB_OVERFLOW_DESCRIPTION); |
| 179 match.description_class.push_back( | 192 match.description_class.push_back( |
| 180 ACMatchClassification(0, ACMatchClassification::NONE)); | 193 ACMatchClassification(0, ACMatchClassification::NONE)); |
| 181 | 194 |
| 182 matches_.push_back(match); | 195 matches_.push_back(match); |
| 183 } | 196 } |
| OLD | NEW |