| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/ui/elide_url.h" | 5 #include "chrome/browser/ui/elide_url.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "components/url_formatter/url_formatter.h" |
| 10 #include "net/base/escape.h" | 11 #include "net/base/escape.h" |
| 11 #include "net/base/net_util.h" | |
| 12 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 12 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 13 #include "ui/gfx/text_elider.h" | 13 #include "ui/gfx/text_elider.h" |
| 14 #include "ui/gfx/text_utils.h" | 14 #include "ui/gfx/text_utils.h" |
| 15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 16 #include "url/url_constants.h" | 16 #include "url/url_constants.h" |
| 17 | 17 |
| 18 using base::UTF8ToUTF16; | 18 using base::UTF8ToUTF16; |
| 19 using gfx::ElideText; | 19 using gfx::ElideText; |
| 20 using gfx::GetStringWidthF; | 20 using gfx::GetStringWidthF; |
| 21 using gfx::kEllipsisUTF16; | 21 using gfx::kEllipsisUTF16; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // TODO(pkasting): http://crbug.com/77883 This whole function gets | 109 // TODO(pkasting): http://crbug.com/77883 This whole function gets |
| 110 // kerning/ligatures/etc. issues potentially wrong by assuming that the width of | 110 // kerning/ligatures/etc. issues potentially wrong by assuming that the width of |
| 111 // a rendered string is always the sum of the widths of its substrings. Also I | 111 // a rendered string is always the sum of the widths of its substrings. Also I |
| 112 // suspect it could be made simpler. | 112 // suspect it could be made simpler. |
| 113 base::string16 ElideUrl(const GURL& url, | 113 base::string16 ElideUrl(const GURL& url, |
| 114 const gfx::FontList& font_list, | 114 const gfx::FontList& font_list, |
| 115 float available_pixel_width, | 115 float available_pixel_width, |
| 116 const std::string& languages) { | 116 const std::string& languages) { |
| 117 // Get a formatted string and corresponding parsing of the url. | 117 // Get a formatted string and corresponding parsing of the url. |
| 118 url::Parsed parsed; | 118 url::Parsed parsed; |
| 119 const base::string16 url_string = | 119 const base::string16 url_string = url_formatter::FormatUrl( |
| 120 net::FormatUrl(url, languages, net::kFormatUrlOmitAll, | 120 url, languages, url_formatter::kFormatUrlOmitAll, |
| 121 net::UnescapeRule::SPACES, &parsed, NULL, NULL); | 121 net::UnescapeRule::SPACES, &parsed, nullptr, nullptr); |
| 122 if (available_pixel_width <= 0) | 122 if (available_pixel_width <= 0) |
| 123 return url_string; | 123 return url_string; |
| 124 | 124 |
| 125 // If non-standard, return plain eliding. | 125 // If non-standard, return plain eliding. |
| 126 if (!url.IsStandard()) | 126 if (!url.IsStandard()) |
| 127 return ElideText(url_string, font_list, available_pixel_width, | 127 return ElideText(url_string, font_list, available_pixel_width, |
| 128 gfx::ELIDE_TAIL); | 128 gfx::ELIDE_TAIL); |
| 129 | 129 |
| 130 // Now start eliding url_string to fit within available pixel width. | 130 // Now start eliding url_string to fit within available pixel width. |
| 131 // Fist pass - check to see whether entire url_string fits. | 131 // Fist pass - check to see whether entire url_string fits. |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 return base::string16(kEllipsisUTF16) + kDot + url_domain; | 299 return base::string16(kEllipsisUTF16) + kDot + url_domain; |
| 300 | 300 |
| 301 const base::string16 elided_subdomain = ElideText( | 301 const base::string16 elided_subdomain = ElideText( |
| 302 url_subdomain, font_list, subdomain_width, gfx::ELIDE_HEAD); | 302 url_subdomain, font_list, subdomain_width, gfx::ELIDE_HEAD); |
| 303 return elided_subdomain + url_domain; | 303 return elided_subdomain + url_domain; |
| 304 } | 304 } |
| 305 | 305 |
| 306 base::string16 FormatUrlForSecurityDisplay(const GURL& url, | 306 base::string16 FormatUrlForSecurityDisplay(const GURL& url, |
| 307 const std::string& languages) { | 307 const std::string& languages) { |
| 308 if (!url.is_valid() || url.is_empty() || !url.IsStandard()) | 308 if (!url.is_valid() || url.is_empty() || !url.IsStandard()) |
| 309 return net::FormatUrl(url, languages); | 309 return url_formatter::FormatUrl(url, languages); |
| 310 | 310 |
| 311 const base::string16 colon(base::ASCIIToUTF16(":")); | 311 const base::string16 colon(base::ASCIIToUTF16(":")); |
| 312 const base::string16 scheme_separator( | 312 const base::string16 scheme_separator( |
| 313 base::ASCIIToUTF16(url::kStandardSchemeSeparator)); | 313 base::ASCIIToUTF16(url::kStandardSchemeSeparator)); |
| 314 | 314 |
| 315 if (url.SchemeIsFile()) { | 315 if (url.SchemeIsFile()) { |
| 316 return base::ASCIIToUTF16(url::kFileScheme) + scheme_separator + | 316 return base::ASCIIToUTF16(url::kFileScheme) + scheme_separator + |
| 317 base::UTF8ToUTF16(url.path()); | 317 base::UTF8ToUTF16(url.path()); |
| 318 } | 318 } |
| 319 | 319 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 337 result += base::UTF8ToUTF16(host); | 337 result += base::UTF8ToUTF16(host); |
| 338 | 338 |
| 339 const int port = origin.IntPort(); | 339 const int port = origin.IntPort(); |
| 340 const int default_port = url::DefaultPortForScheme(origin.scheme().c_str(), | 340 const int default_port = url::DefaultPortForScheme(origin.scheme().c_str(), |
| 341 origin.scheme().length()); | 341 origin.scheme().length()); |
| 342 if (port != url::PORT_UNSPECIFIED && port != default_port) | 342 if (port != url::PORT_UNSPECIFIED && port != default_port) |
| 343 result += colon + base::UTF8ToUTF16(origin.port()); | 343 result += colon + base::UTF8ToUTF16(origin.port()); |
| 344 | 344 |
| 345 return result; | 345 return result; |
| 346 } | 346 } |
| OLD | NEW |