OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file implements utility functions for eliding and formatting UI text. | 5 // This file implements utility functions for eliding and formatting UI text. |
6 // | 6 // |
7 // Note that several of the functions declared in text_elider.h are implemented | 7 // Note that several of the functions declared in text_elider.h are implemented |
8 // in this file using helper classes in the anonymous namespace. | 8 // in this file using helper classes in the anonymous namespace. |
9 | 9 |
10 #include "ui/base/text/text_elider.h" | 10 #include "ui/base/text/text_elider.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 int available_pixel_width, | 218 int available_pixel_width, |
219 const std::string& languages) { | 219 const std::string& languages) { |
220 // Get a formatted string and corresponding parsing of the url. | 220 // Get a formatted string and corresponding parsing of the url. |
221 url_parse::Parsed parsed; | 221 url_parse::Parsed parsed; |
222 const string16 url_string = | 222 const string16 url_string = |
223 net::FormatUrl(url, languages, net::kFormatUrlOmitAll, | 223 net::FormatUrl(url, languages, net::kFormatUrlOmitAll, |
224 net::UnescapeRule::SPACES, &parsed, NULL, NULL); | 224 net::UnescapeRule::SPACES, &parsed, NULL, NULL); |
225 if (available_pixel_width <= 0) | 225 if (available_pixel_width <= 0) |
226 return url_string; | 226 return url_string; |
227 | 227 |
228 // If non-standard or not file type, return plain eliding. | 228 // If non-standard, return plain eliding. |
229 if (!(url.SchemeIsFile() || url.IsStandard())) | 229 if (!url.IsStandard()) |
230 return ElideText(url_string, font, available_pixel_width, ELIDE_AT_END); | 230 return ElideText(url_string, font, available_pixel_width, ELIDE_AT_END); |
231 | 231 |
232 // Now start eliding url_string to fit within available pixel width. | 232 // Now start eliding url_string to fit within available pixel width. |
233 // Fist pass - check to see whether entire url_string fits. | 233 // Fist pass - check to see whether entire url_string fits. |
234 const int pixel_width_url_string = font.GetStringWidth(url_string); | 234 const int pixel_width_url_string = font.GetStringWidth(url_string); |
235 if (available_pixel_width >= pixel_width_url_string) | 235 if (available_pixel_width >= pixel_width_url_string) |
236 return url_string; | 236 return url_string; |
237 | 237 |
238 // Get the path substring, including query and reference. | 238 // Get the path substring, including query and reference. |
239 const size_t path_start_index = parsed.path.begin; | 239 const size_t path_start_index = parsed.path.begin; |
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 index = char_iterator.getIndex(); | 1113 index = char_iterator.getIndex(); |
1114 } else { | 1114 } else { |
1115 // String has leading whitespace, return the elide string. | 1115 // String has leading whitespace, return the elide string. |
1116 return kElideString; | 1116 return kElideString; |
1117 } | 1117 } |
1118 } | 1118 } |
1119 return string.substr(0, index) + kElideString; | 1119 return string.substr(0, index) + kElideString; |
1120 } | 1120 } |
1121 | 1121 |
1122 } // namespace ui | 1122 } // namespace ui |
OLD | NEW |