OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/font.h" | 5 #include "app/gfx/font.h" |
6 #include "app/gfx/text_elider.h" | 6 #include "app/gfx/text_elider.h" |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
(...skipping 14 matching lines...) Expand all Loading... |
26 // TODO(pkasting): http://b/119635 This whole function gets | 26 // TODO(pkasting): http://b/119635 This whole function gets |
27 // kerning/ligatures/etc. issues potentially wrong by assuming that the width of | 27 // kerning/ligatures/etc. issues potentially wrong by assuming that the width of |
28 // a rendered string is always the sum of the widths of its substrings. Also I | 28 // a rendered string is always the sum of the widths of its substrings. Also I |
29 // suspect it could be made simpler. | 29 // suspect it could be made simpler. |
30 std::wstring ElideUrl(const GURL& url, | 30 std::wstring ElideUrl(const GURL& url, |
31 const gfx::Font& font, | 31 const gfx::Font& font, |
32 int available_pixel_width, | 32 int available_pixel_width, |
33 const std::wstring& languages) { | 33 const std::wstring& languages) { |
34 // Get a formatted string and corresponding parsing of the url. | 34 // Get a formatted string and corresponding parsing of the url. |
35 url_parse::Parsed parsed; | 35 url_parse::Parsed parsed; |
36 std::wstring url_string = | 36 std::wstring url_string = net::FormatUrl(url, languages, true, |
37 net::FormatUrl(url, languages, true, UnescapeRule::SPACES, &parsed, NULL); | 37 UnescapeRule::SPACES, &parsed, NULL, NULL); |
38 if (available_pixel_width <= 0) | 38 if (available_pixel_width <= 0) |
39 return url_string; | 39 return url_string; |
40 | 40 |
41 // If non-standard or not file type, return plain eliding. | 41 // If non-standard or not file type, return plain eliding. |
42 if (!(url.SchemeIsFile() || url.IsStandard())) | 42 if (!(url.SchemeIsFile() || url.IsStandard())) |
43 return ElideText(url_string, font, available_pixel_width); | 43 return ElideText(url_string, font, available_pixel_width); |
44 | 44 |
45 // Now start eliding url_string to fit within available pixel width. | 45 // Now start eliding url_string to fit within available pixel width. |
46 // Fist pass - check to see whether entire url_string fits. | 46 // Fist pass - check to see whether entire url_string fits. |
47 int pixel_width_url_string = font.GetStringWidth(url_string); | 47 int pixel_width_url_string = font.GetStringWidth(url_string); |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 } | 327 } |
328 guess = (lo + hi) / 2; | 328 guess = (lo + hi) / 2; |
329 } | 329 } |
330 | 330 |
331 return text.substr(0, lo) + kEllipsis; | 331 return text.substr(0, lo) + kEllipsis; |
332 } | 332 } |
333 | 333 |
334 SortedDisplayURL::SortedDisplayURL(const GURL& url, | 334 SortedDisplayURL::SortedDisplayURL(const GURL& url, |
335 const std::wstring& languages) { | 335 const std::wstring& languages) { |
336 std::wstring host; | 336 std::wstring host; |
337 net::AppendFormattedHost(url, languages, &host, NULL); | 337 net::AppendFormattedHost(url, languages, &host, NULL, NULL); |
338 sort_host_ = WideToUTF16Hack(host); | 338 sort_host_ = WideToUTF16Hack(host); |
339 string16 host_minus_www = WideToUTF16Hack(net::StripWWW(host)); | 339 string16 host_minus_www = WideToUTF16Hack(net::StripWWW(host)); |
340 url_parse::Parsed parsed; | 340 url_parse::Parsed parsed; |
341 display_url_ = WideToUTF16Hack(net::FormatUrl(url, languages, | 341 display_url_ = WideToUTF16Hack(net::FormatUrl(url, languages, |
342 true, UnescapeRule::SPACES, &parsed, &prefix_end_)); | 342 true, UnescapeRule::SPACES, &parsed, &prefix_end_, NULL)); |
343 if (sort_host_.length() > host_minus_www.length()) { | 343 if (sort_host_.length() > host_minus_www.length()) { |
344 prefix_end_ += sort_host_.length() - host_minus_www.length(); | 344 prefix_end_ += sort_host_.length() - host_minus_www.length(); |
345 sort_host_.swap(host_minus_www); | 345 sort_host_.swap(host_minus_www); |
346 } | 346 } |
347 } | 347 } |
348 | 348 |
349 int SortedDisplayURL::Compare(const SortedDisplayURL& other, | 349 int SortedDisplayURL::Compare(const SortedDisplayURL& other, |
350 icu::Collator* collator) const { | 350 icu::Collator* collator) const { |
351 // Compare on hosts first. The host won't contain 'www.'. | 351 // Compare on hosts first. The host won't contain 'www.'. |
352 UErrorCode compare_status = U_ZERO_ERROR; | 352 UErrorCode compare_status = U_ZERO_ERROR; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 string16 SortedDisplayURL::AfterHost() const { | 390 string16 SortedDisplayURL::AfterHost() const { |
391 size_t slash_index = display_url_.find(sort_host_, prefix_end_); | 391 size_t slash_index = display_url_.find(sort_host_, prefix_end_); |
392 if (slash_index == string16::npos) { | 392 if (slash_index == string16::npos) { |
393 NOTREACHED(); | 393 NOTREACHED(); |
394 return string16(); | 394 return string16(); |
395 } | 395 } |
396 return display_url_.substr(slash_index + sort_host_.length()); | 396 return display_url_.substr(slash_index + sort_host_.length()); |
397 } | 397 } |
398 | 398 |
399 } // namespace gfx. | 399 } // namespace gfx. |
OLD | NEW |