OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef UI_BASE_TEXT_TEXT_ELIDER_H_ | 5 #ifndef UI_BASE_TEXT_TEXT_ELIDER_H_ |
6 #define UI_BASE_TEXT_TEXT_ELIDER_H_ | 6 #define UI_BASE_TEXT_TEXT_ELIDER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 // Note: in RTL locales, if the URL returned by this function is going to be | 33 // Note: in RTL locales, if the URL returned by this function is going to be |
34 // displayed in the UI, then it is likely that the string needs to be marked | 34 // displayed in the UI, then it is likely that the string needs to be marked |
35 // as an LTR string (using base::i18n::WrapStringWithLTRFormatting()) so that it | 35 // as an LTR string (using base::i18n::WrapStringWithLTRFormatting()) so that it |
36 // is displayed properly in an RTL context. Please refer to | 36 // is displayed properly in an RTL context. Please refer to |
37 // http://crbug.com/6487 for more information. | 37 // http://crbug.com/6487 for more information. |
38 UI_EXPORT string16 ElideUrl(const GURL& url, | 38 UI_EXPORT string16 ElideUrl(const GURL& url, |
39 const gfx::Font& font, | 39 const gfx::Font& font, |
40 int available_pixel_width, | 40 int available_pixel_width, |
41 const std::string& languages); | 41 const std::string& languages); |
42 | 42 |
43 // Elides |text| to fit in |available_pixel_width|. If |elide_in_middle| is | 43 enum ElideBehavior { |
44 // set the ellipsis is placed in the middle of the string; otherwise it is | 44 // Add ellipsis at the end of the string. |
45 // placed at the end. | 45 ELIDE_AT_END, |
| 46 // Add ellipsis in the middle of the string. |
| 47 ELIDE_IN_MIDDLE, |
| 48 // Truncate the end of the string. |
| 49 TRUNCATE_AT_END |
| 50 }; |
| 51 |
| 52 // Elides |text| to fit in |available_pixel_width| according to the specified |
| 53 // |elide_behavior|. |
46 UI_EXPORT string16 ElideText(const string16& text, | 54 UI_EXPORT string16 ElideText(const string16& text, |
47 const gfx::Font& font, | 55 const gfx::Font& font, |
48 int available_pixel_width, | 56 int available_pixel_width, |
49 bool elide_in_middle); | 57 ElideBehavior elide_behavior); |
50 | 58 |
51 // Elide a filename to fit a given pixel width, with an emphasis on not hiding | 59 // Elide a filename to fit a given pixel width, with an emphasis on not hiding |
52 // the extension unless we have to. If filename contains a path, the path will | 60 // the extension unless we have to. If filename contains a path, the path will |
53 // be removed if filename doesn't fit into available_pixel_width. The elided | 61 // be removed if filename doesn't fit into available_pixel_width. The elided |
54 // filename is forced to have LTR directionality, which means that in RTL UI | 62 // filename is forced to have LTR directionality, which means that in RTL UI |
55 // the elided filename is wrapped with LRE (Left-To-Right Embedding) mark and | 63 // the elided filename is wrapped with LRE (Left-To-Right Embedding) mark and |
56 // PDF (Pop Directional Formatting) mark. | 64 // PDF (Pop Directional Formatting) mark. |
57 UI_EXPORT string16 ElideFilename(const FilePath& filename, | 65 UI_EXPORT string16 ElideFilename(const FilePath& filename, |
58 const gfx::Font& font, | 66 const gfx::Font& font, |
59 int available_pixel_width); | 67 int available_pixel_width); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // Truncates the string to length characters. This breaks the string at | 131 // Truncates the string to length characters. This breaks the string at |
124 // the first word break before length, adding the horizontal ellipsis | 132 // the first word break before length, adding the horizontal ellipsis |
125 // character (unicode character 0x2026) to render ... | 133 // character (unicode character 0x2026) to render ... |
126 // The supplied string is returned if the string has length characters or | 134 // The supplied string is returned if the string has length characters or |
127 // less. | 135 // less. |
128 UI_EXPORT string16 TruncateString(const string16& string, size_t length); | 136 UI_EXPORT string16 TruncateString(const string16& string, size_t length); |
129 | 137 |
130 } // namespace ui | 138 } // namespace ui |
131 | 139 |
132 #endif // UI_BASE_TEXT_TEXT_ELIDER_H_ | 140 #endif // UI_BASE_TEXT_TEXT_ELIDER_H_ |
OLD | NEW |