OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "app/gfx/chrome_font.h" | 5 #include "app/gfx/chrome_font.h" |
6 #include "app/gfx/text_elider.h" | 6 #include "app/gfx/text_elider.h" |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 // which composed of parts from subdomain, domain, path, filename and query. | 37 // which composed of parts from subdomain, domain, path, filename and query. |
38 // A "..." is added automatically at the end if the elided string is bigger | 38 // A "..." is added automatically at the end if the elided string is bigger |
39 // than the available pixel width. For available pixel width = 0, a formatted, | 39 // than the available pixel width. For available pixel width = 0, a formatted, |
40 // but un-elided, string is returned. | 40 // but un-elided, string is returned. |
41 // | 41 // |
42 // TODO(pkasting): http://b/119635 This whole function gets | 42 // TODO(pkasting): http://b/119635 This whole function gets |
43 // kerning/ligatures/etc. issues potentially wrong by assuming that the width of | 43 // kerning/ligatures/etc. issues potentially wrong by assuming that the width of |
44 // a rendered string is always the sum of the widths of its substrings. Also I | 44 // a rendered string is always the sum of the widths of its substrings. Also I |
45 // suspect it could be made simpler. | 45 // suspect it could be made simpler. |
46 std::wstring ElideUrl(const GURL& url, | 46 std::wstring ElideUrl(const GURL& url, |
47 const ChromeFont& font, | 47 const gfx::Font& font, |
48 int available_pixel_width, | 48 int available_pixel_width, |
49 const std::wstring& languages) { | 49 const std::wstring& languages) { |
50 // Get a formatted string and corresponding parsing of the url. | 50 // Get a formatted string and corresponding parsing of the url. |
51 url_parse::Parsed parsed; | 51 url_parse::Parsed parsed; |
52 std::wstring url_string = GetCleanStringFromUrl(url, languages, &parsed, | 52 std::wstring url_string = GetCleanStringFromUrl(url, languages, &parsed, |
53 NULL); | 53 NULL); |
54 if (available_pixel_width <= 0) | 54 if (available_pixel_width <= 0) |
55 return url_string; | 55 return url_string; |
56 | 56 |
57 // If non-standard or not file type, return plain eliding. | 57 // If non-standard or not file type, return plain eliding. |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 pixel_width_dot_dot_slash + pixel_width_dots_trailer + | 264 pixel_width_dot_dot_slash + pixel_width_dots_trailer + |
265 font.GetStringWidth(L"UV")) // A hack to prevent trailing "../...". | 265 font.GetStringWidth(L"UV")) // A hack to prevent trailing "../...". |
266 final_elided_url_string += elided_path; | 266 final_elided_url_string += elided_path; |
267 else | 267 else |
268 final_elided_url_string += url_path; | 268 final_elided_url_string += url_path; |
269 | 269 |
270 return ElideText(final_elided_url_string, font, available_pixel_width); | 270 return ElideText(final_elided_url_string, font, available_pixel_width); |
271 } | 271 } |
272 | 272 |
273 std::wstring ElideFilename(const FilePath& filename, | 273 std::wstring ElideFilename(const FilePath& filename, |
274 const ChromeFont& font, | 274 const gfx::Font& font, |
275 int available_pixel_width) { | 275 int available_pixel_width) { |
276 int full_width = font.GetStringWidth(filename.ToWStringHack()); | 276 int full_width = font.GetStringWidth(filename.ToWStringHack()); |
277 if (full_width <= available_pixel_width) | 277 if (full_width <= available_pixel_width) |
278 return filename.ToWStringHack(); | 278 return filename.ToWStringHack(); |
279 | 279 |
280 #if defined(OS_WIN) | 280 #if defined(OS_WIN) |
281 std::wstring extension = filename.Extension(); | 281 std::wstring extension = filename.Extension(); |
282 #elif defined(OS_POSIX) | 282 #elif defined(OS_POSIX) |
283 std::wstring extension = base::SysNativeMBToWide(filename.Extension()); | 283 std::wstring extension = base::SysNativeMBToWide(filename.Extension()); |
284 #endif | 284 #endif |
(...skipping 10 matching lines...) Expand all Loading... |
295 if (root_width + ext_width <= available_pixel_width) | 295 if (root_width + ext_width <= available_pixel_width) |
296 return rootname + extension; | 296 return rootname + extension; |
297 | 297 |
298 int available_root_width = available_pixel_width - ext_width; | 298 int available_root_width = available_pixel_width - ext_width; |
299 return ElideText(rootname, font, available_root_width) + extension; | 299 return ElideText(rootname, font, available_root_width) + extension; |
300 } | 300 } |
301 | 301 |
302 // This function adds an ellipsis at the end of the text if the text | 302 // This function adds an ellipsis at the end of the text if the text |
303 // does not fit the given pixel width. | 303 // does not fit the given pixel width. |
304 std::wstring ElideText(const std::wstring& text, | 304 std::wstring ElideText(const std::wstring& text, |
305 const ChromeFont& font, | 305 const gfx::Font& font, |
306 int available_pixel_width){ | 306 int available_pixel_width){ |
307 if (text.empty()) | 307 if (text.empty()) |
308 return text; | 308 return text; |
309 | 309 |
310 int current_text_pixel_width = font.GetStringWidth(text); | 310 int current_text_pixel_width = font.GetStringWidth(text); |
311 if (current_text_pixel_width <= available_pixel_width) | 311 if (current_text_pixel_width <= available_pixel_width) |
312 return text; | 312 return text; |
313 | 313 |
314 if (font.GetStringWidth(kEllipsis) > available_pixel_width) | 314 if (font.GetStringWidth(kEllipsis) > available_pixel_width) |
315 return std::wstring(); | 315 return std::wstring(); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 string16 SortedDisplayURL::AfterHost() const { | 506 string16 SortedDisplayURL::AfterHost() const { |
507 size_t slash_index = display_url_.find(sort_host_, prefix_end_); | 507 size_t slash_index = display_url_.find(sort_host_, prefix_end_); |
508 if (slash_index == string16::npos) { | 508 if (slash_index == string16::npos) { |
509 NOTREACHED(); | 509 NOTREACHED(); |
510 return string16(); | 510 return string16(); |
511 } | 511 } |
512 return display_url_.substr(slash_index + sort_host_.length()); | 512 return display_url_.substr(slash_index + sort_host_.length()); |
513 } | 513 } |
514 | 514 |
515 } // namespace gfx. | 515 } // namespace gfx. |
OLD | NEW |