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 UI_EXPORT extern const size_t kMaxProfileUsernameLength; | |
28 | |
29 // Elides only the username portion of the |email|, if possible, so that the | |
30 // returned email is at most |max_email_length| characters (e.g. | |
31 // longusername@host.com --> longuser...@host.com for |max_email_length| == 20). | |
32 // If the domain name by itself already has more characters than available: | |
33 // it is elided in the middle so that only |max_email_length| / 2 characters | |
34 // remain; the username is then elided following the regular process described | |
35 // above. | |
36 // In any scenario: the string returned will never be longer than | |
37 // |max_email_length| including the inserted ellipses; and the elided strings | |
38 // will have at least one character remaining on either side of the '@'(other | |
39 // than the ellipsis-es). | |
40 // This function assumes |max_email_length| is >= 5. | |
41 UI_EXPORT string16 ElideEmail(const string16& email, | |
42 size_t max_email_length); | |
gab
2012/02/28 19:23:01
I moved this here as ElideEmail is above ElideUrl
| |
27 | 43 |
28 // This function takes a GURL object and elides it. It returns a string | 44 // 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. | 45 // 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 | 46 // 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 | 47 // than the available pixel width. For available pixel width = 0, empty |
32 // string is returned. |languages| is a comma separted list of ISO 639 | 48 // string is returned. |languages| is a comma separted list of ISO 639 |
33 // language codes and is used to determine what characters are understood | 49 // language codes and is used to determine what characters are understood |
34 // by a user. It should come from |prefs::kAcceptLanguages|. | 50 // by a user. It should come from |prefs::kAcceptLanguages|. |
35 // | 51 // |
36 // Note: in RTL locales, if the URL returned by this function is going to be | 52 // Note: in RTL locales, if the URL returned by this function is going to be |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 // Truncates the string to length characters. This breaks the string at | 185 // Truncates the string to length characters. This breaks the string at |
170 // the first word break before length, adding the horizontal ellipsis | 186 // the first word break before length, adding the horizontal ellipsis |
171 // character (unicode character 0x2026) to render ... | 187 // character (unicode character 0x2026) to render ... |
172 // The supplied string is returned if the string has length characters or | 188 // The supplied string is returned if the string has length characters or |
173 // less. | 189 // less. |
174 UI_EXPORT string16 TruncateString(const string16& string, size_t length); | 190 UI_EXPORT string16 TruncateString(const string16& string, size_t length); |
175 | 191 |
176 } // namespace ui | 192 } // namespace ui |
177 | 193 |
178 #endif // UI_BASE_TEXT_TEXT_ELIDER_H_ | 194 #endif // UI_BASE_TEXT_TEXT_ELIDER_H_ |
OLD | NEW |