Chromium Code Reviews| 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 int available_pixel_width, | 164 int available_pixel_width, |
| 165 const std::string& languages) { | 165 const std::string& languages) { |
| 166 // Get a formatted string and corresponding parsing of the url. | 166 // Get a formatted string and corresponding parsing of the url. |
| 167 url_parse::Parsed parsed; | 167 url_parse::Parsed parsed; |
| 168 const string16 url_string = | 168 const string16 url_string = |
| 169 net::FormatUrl(url, languages, net::kFormatUrlOmitAll, | 169 net::FormatUrl(url, languages, net::kFormatUrlOmitAll, |
| 170 net::UnescapeRule::SPACES, &parsed, NULL, NULL); | 170 net::UnescapeRule::SPACES, &parsed, NULL, NULL); |
| 171 if (available_pixel_width <= 0) | 171 if (available_pixel_width <= 0) |
| 172 return url_string; | 172 return url_string; |
| 173 | 173 |
| 174 // If non-standard or not file type, return plain eliding. | 174 // If non-standard, return plain eliding. |
| 175 if (!(url.SchemeIsFile() || url.IsStandard())) | 175 if (!url.IsStandard()) |
|
sky
2012/02/15 16:17:28
nit: I prefer !foo && !foo. Easier to parse.
ericu
2012/02/15 22:32:10
Actually, you're commenting on the "before" code,
| |
| 176 return ElideText(url_string, font, available_pixel_width, ELIDE_AT_END); | 176 return ElideText(url_string, font, available_pixel_width, ELIDE_AT_END); |
| 177 | 177 |
| 178 // Now start eliding url_string to fit within available pixel width. | 178 // Now start eliding url_string to fit within available pixel width. |
| 179 // Fist pass - check to see whether entire url_string fits. | 179 // Fist pass - check to see whether entire url_string fits. |
| 180 const int pixel_width_url_string = font.GetStringWidth(url_string); | 180 const int pixel_width_url_string = font.GetStringWidth(url_string); |
| 181 if (available_pixel_width >= pixel_width_url_string) | 181 if (available_pixel_width >= pixel_width_url_string) |
| 182 return url_string; | 182 return url_string; |
| 183 | 183 |
| 184 // Get the path substring, including query and reference. | 184 // Get the path substring, including query and reference. |
| 185 const size_t path_start_index = parsed.path.begin; | 185 const size_t path_start_index = parsed.path.begin; |
| (...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1061 index = char_iterator.getIndex(); | 1061 index = char_iterator.getIndex(); |
| 1062 } else { | 1062 } else { |
| 1063 // String has leading whitespace, return the elide string. | 1063 // String has leading whitespace, return the elide string. |
| 1064 return kElideString; | 1064 return kElideString; |
| 1065 } | 1065 } |
| 1066 } | 1066 } |
| 1067 return string.substr(0, index) + kElideString; | 1067 return string.substr(0, index) + kElideString; |
| 1068 } | 1068 } |
| 1069 | 1069 |
| 1070 } // namespace ui | 1070 } // namespace ui |
| OLD | NEW |