OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "app/text_elider.h" | 7 #include "app/text_elider.h" |
8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
(...skipping 18 matching lines...) Expand all Loading... |
30 // TODO(pkasting): http://b/119635 This whole function gets | 30 // TODO(pkasting): http://b/119635 This whole function gets |
31 // kerning/ligatures/etc. issues potentially wrong by assuming that the width of | 31 // kerning/ligatures/etc. issues potentially wrong by assuming that the width of |
32 // a rendered string is always the sum of the widths of its substrings. Also I | 32 // a rendered string is always the sum of the widths of its substrings. Also I |
33 // suspect it could be made simpler. | 33 // suspect it could be made simpler. |
34 std::wstring ElideUrl(const GURL& url, | 34 std::wstring ElideUrl(const GURL& url, |
35 const gfx::Font& font, | 35 const gfx::Font& font, |
36 int available_pixel_width, | 36 int available_pixel_width, |
37 const std::wstring& languages) { | 37 const std::wstring& languages) { |
38 // Get a formatted string and corresponding parsing of the url. | 38 // Get a formatted string and corresponding parsing of the url. |
39 url_parse::Parsed parsed; | 39 url_parse::Parsed parsed; |
40 std::wstring url_string = net::FormatUrl(url, languages, true, | 40 std::wstring url_string = net::FormatUrl(url, languages, |
41 UnescapeRule::SPACES, &parsed, NULL, NULL); | 41 net::kFormatUrlOmitAll, UnescapeRule::SPACES, &parsed, NULL, NULL); |
42 if (available_pixel_width <= 0) | 42 if (available_pixel_width <= 0) |
43 return url_string; | 43 return url_string; |
44 | 44 |
45 // If non-standard or not file type, return plain eliding. | 45 // If non-standard or not file type, return plain eliding. |
46 if (!(url.SchemeIsFile() || url.IsStandard())) | 46 if (!(url.SchemeIsFile() || url.IsStandard())) |
47 return ElideText(url_string, font, available_pixel_width); | 47 return ElideText(url_string, font, available_pixel_width); |
48 | 48 |
49 // Now start eliding url_string to fit within available pixel width. | 49 // Now start eliding url_string to fit within available pixel width. |
50 // Fist pass - check to see whether entire url_string fits. | 50 // Fist pass - check to see whether entire url_string fits. |
51 int pixel_width_url_string = font.GetStringWidth(url_string); | 51 int pixel_width_url_string = font.GetStringWidth(url_string); |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 } | 356 } |
357 | 357 |
358 SortedDisplayURL::SortedDisplayURL(const GURL& url, | 358 SortedDisplayURL::SortedDisplayURL(const GURL& url, |
359 const std::wstring& languages) { | 359 const std::wstring& languages) { |
360 std::wstring host; | 360 std::wstring host; |
361 net::AppendFormattedHost(url, languages, &host, NULL, NULL); | 361 net::AppendFormattedHost(url, languages, &host, NULL, NULL); |
362 sort_host_ = WideToUTF16Hack(host); | 362 sort_host_ = WideToUTF16Hack(host); |
363 string16 host_minus_www = WideToUTF16Hack(net::StripWWW(host)); | 363 string16 host_minus_www = WideToUTF16Hack(net::StripWWW(host)); |
364 url_parse::Parsed parsed; | 364 url_parse::Parsed parsed; |
365 display_url_ = WideToUTF16Hack(net::FormatUrl(url, languages, | 365 display_url_ = WideToUTF16Hack(net::FormatUrl(url, languages, |
366 true, UnescapeRule::SPACES, &parsed, &prefix_end_, NULL)); | 366 net::kFormatUrlOmitAll, UnescapeRule::SPACES, &parsed, &prefix_end_, |
| 367 NULL)); |
367 if (sort_host_.length() > host_minus_www.length()) { | 368 if (sort_host_.length() > host_minus_www.length()) { |
368 prefix_end_ += sort_host_.length() - host_minus_www.length(); | 369 prefix_end_ += sort_host_.length() - host_minus_www.length(); |
369 sort_host_.swap(host_minus_www); | 370 sort_host_.swap(host_minus_www); |
370 } | 371 } |
371 } | 372 } |
372 | 373 |
373 int SortedDisplayURL::Compare(const SortedDisplayURL& other, | 374 int SortedDisplayURL::Compare(const SortedDisplayURL& other, |
374 icu::Collator* collator) const { | 375 icu::Collator* collator) const { |
375 // Compare on hosts first. The host won't contain 'www.'. | 376 // Compare on hosts first. The host won't contain 'www.'. |
376 UErrorCode compare_status = U_ZERO_ERROR; | 377 UErrorCode compare_status = U_ZERO_ERROR; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 string16 SortedDisplayURL::AfterHost() const { | 415 string16 SortedDisplayURL::AfterHost() const { |
415 size_t slash_index = display_url_.find(sort_host_, prefix_end_); | 416 size_t slash_index = display_url_.find(sort_host_, prefix_end_); |
416 if (slash_index == string16::npos) { | 417 if (slash_index == string16::npos) { |
417 NOTREACHED(); | 418 NOTREACHED(); |
418 return string16(); | 419 return string16(); |
419 } | 420 } |
420 return display_url_.substr(slash_index + sort_host_.length()); | 421 return display_url_.substr(slash_index + sort_host_.length()); |
421 } | 422 } |
422 | 423 |
423 } // namespace gfx. | 424 } // namespace gfx. |
OLD | NEW |