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 defines utility functions for eliding and formatting UI text. | 5 // This file defines utility functions for eliding and formatting UI text. |
6 | 6 |
7 #ifndef UI_BASE_TEXT_TEXT_ELIDER_H_ | 7 #ifndef UI_BASE_TEXT_TEXT_ELIDER_H_ |
8 #define UI_BASE_TEXT_TEXT_ELIDER_H_ | 8 #define UI_BASE_TEXT_TEXT_ELIDER_H_ |
9 #pragma once | 9 #pragma once |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/string16.h" | 15 #include "base/string16.h" |
16 #include "ui/base/ui_export.h" | 16 #include "ui/base/ui_export.h" |
17 #include "ui/gfx/font.h" | 17 #include "ui/gfx/font.h" |
18 #include "unicode/coll.h" | 18 #include "unicode/coll.h" |
19 #include "unicode/uchar.h" | 19 #include "unicode/uchar.h" |
20 | 20 |
21 class FilePath; | 21 class FilePath; |
22 class GURL; | 22 class GURL; |
23 | 23 |
24 namespace ui { | 24 namespace ui { |
25 | 25 |
26 UI_EXPORT extern const char kEllipsis[]; | 26 UI_EXPORT extern const char kEllipsis[]; |
27 | 27 |
28 // Elides an email address to fit into |available_pixel_width| using the | |
29 // specified |font|. | |
30 // This function guarantees that the string returned will contain at least one | |
31 // character, other than the ellipsis-es, on either side of the '@'. If it is | |
asvitkine_google
2012/03/01 22:10:56
ellipsis-es => ellipses
gab
2012/03/01 23:03:46
Ya, saw this form around the web to indicate the p
| |
32 // impossible to achieve these requirements: only an ellipsis will be returned. | |
33 // If possible: this elides only the username portion of the |email|. Otherwise, | |
34 // the domain is elided in the middle so that it splits the available width | |
35 // equally with the elided username (should the username be short enough that it | |
36 // doesn't need half the available width: the elided domain will occupy that | |
37 // extra width). | |
38 UI_EXPORT string16 ElideEmail(const string16& email, | |
39 const gfx::Font& font, | |
40 int available_pixel_width); | |
41 | |
28 // This function takes a GURL object and elides it. It returns a string | 42 // This function takes a GURL object and elides it. It returns a string |
29 // which composed of parts from subdomain, domain, path, filename and query. | 43 // which composed of parts from subdomain, domain, path, filename and query. |
30 // A "..." is added automatically at the end if the elided string is bigger | 44 // A "..." is added automatically at the end if the elided string is bigger |
31 // than the available pixel width. For available pixel width = 0, empty | 45 // than the |available_pixel_width|. For |available_pixel_width| == 0, a |
32 // string is returned. |languages| is a comma separated list of ISO 639 | 46 // formatted, but un-elided, string is returned. |languages| is a comma |
33 // language codes and is used to determine what characters are understood | 47 // separated list of ISO 639 language codes and is used to determine what |
34 // by a user. It should come from |prefs::kAcceptLanguages|. | 48 // characters are understood by a user. It should come from |
49 // |prefs::kAcceptLanguages|. | |
35 // | 50 // |
36 // Note: in RTL locales, if the URL returned by this function is going to be | 51 // Note: in RTL locales, if the URL returned by this function is going to be |
37 // displayed in the UI, then it is likely that the string needs to be marked | 52 // displayed in the UI, then it is likely that the string needs to be marked |
38 // as an LTR string (using base::i18n::WrapStringWithLTRFormatting()) so that it | 53 // as an LTR string (using base::i18n::WrapStringWithLTRFormatting()) so that it |
39 // is displayed properly in an RTL context. Please refer to | 54 // is displayed properly in an RTL context. Please refer to |
40 // http://crbug.com/6487 for more information. | 55 // http://crbug.com/6487 for more information. |
41 UI_EXPORT string16 ElideUrl(const GURL& url, | 56 UI_EXPORT string16 ElideUrl(const GURL& url, |
42 const gfx::Font& font, | 57 const gfx::Font& font, |
43 int available_pixel_width, | 58 int available_pixel_width, |
44 const std::string& languages); | 59 const std::string& languages); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 // Truncates the string to length characters. This breaks the string at | 184 // Truncates the string to length characters. This breaks the string at |
170 // the first word break before length, adding the horizontal ellipsis | 185 // the first word break before length, adding the horizontal ellipsis |
171 // character (unicode character 0x2026) to render ... | 186 // character (unicode character 0x2026) to render ... |
172 // The supplied string is returned if the string has length characters or | 187 // The supplied string is returned if the string has length characters or |
173 // less. | 188 // less. |
174 UI_EXPORT string16 TruncateString(const string16& string, size_t length); | 189 UI_EXPORT string16 TruncateString(const string16& string, size_t length); |
175 | 190 |
176 } // namespace ui | 191 } // namespace ui |
177 | 192 |
178 #endif // UI_BASE_TEXT_TEXT_ELIDER_H_ | 193 #endif // UI_BASE_TEXT_TEXT_ELIDER_H_ |
OLD | NEW |