| 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_GFX_TEXT_ELIDER_H_ | 7 #ifndef UI_GFX_TEXT_ELIDER_H_ |
| 8 #define UI_GFX_TEXT_ELIDER_H_ | 8 #define UI_GFX_TEXT_ELIDER_H_ |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // spot after the fact. If the word itself is too long, we always break | 102 // spot after the fact. If the word itself is too long, we always break |
| 103 // intra-word (respecting UTF-16 surrogate pairs) as necssary. Truncation | 103 // intra-word (respecting UTF-16 surrogate pairs) as necssary. Truncation |
| 104 // (indicated by an added 3 dots) occurs if the result is still too long. | 104 // (indicated by an added 3 dots) occurs if the result is still too long. |
| 105 // Returns true if the input had to be truncated (and not just reformatted). | 105 // Returns true if the input had to be truncated (and not just reformatted). |
| 106 GFX_EXPORT bool ElideRectangleString(const base::string16& input, | 106 GFX_EXPORT bool ElideRectangleString(const base::string16& input, |
| 107 size_t max_rows, | 107 size_t max_rows, |
| 108 size_t max_cols, | 108 size_t max_cols, |
| 109 bool strict, | 109 bool strict, |
| 110 base::string16* output); | 110 base::string16* output); |
| 111 | 111 |
| 112 // Specifies the word wrapping behavior of |ElideRectangleText()| when a word | |
| 113 // would exceed the available width. | |
| 114 enum WordWrapBehavior { | |
| 115 // Words that are too wide will be put on a new line, but will not be | |
| 116 // truncated or elided. | |
| 117 IGNORE_LONG_WORDS, | |
| 118 | |
| 119 // Words that are too wide will be put on a new line and will be truncated to | |
| 120 // the available width. | |
| 121 TRUNCATE_LONG_WORDS, | |
| 122 | |
| 123 // Words that are too wide will be put on a new line and will be elided to the | |
| 124 // available width. | |
| 125 ELIDE_LONG_WORDS, | |
| 126 | |
| 127 // Words that are too wide will be put on a new line and will be wrapped over | |
| 128 // multiple lines. | |
| 129 WRAP_LONG_WORDS, | |
| 130 }; | |
| 131 | |
| 132 // Indicates whether the |available_pixel_width| by |available_pixel_height| | 112 // Indicates whether the |available_pixel_width| by |available_pixel_height| |
| 133 // rectangle passed to |ElideRectangleText()| had insufficient space to | 113 // rectangle passed to |ElideRectangleText()| had insufficient space to |
| 134 // accommodate the given |text|, leading to elision or truncation. | 114 // accommodate the given |text|, leading to elision or truncation. |
| 135 enum ReformattingResultFlags { | 115 enum ReformattingResultFlags { |
| 136 INSUFFICIENT_SPACE_HORIZONTAL = 1 << 0, | 116 INSUFFICIENT_SPACE_HORIZONTAL = 1 << 0, |
| 137 INSUFFICIENT_SPACE_VERTICAL = 1 << 1, | 117 INSUFFICIENT_SPACE_VERTICAL = 1 << 1, |
| 138 }; | 118 }; |
| 139 | 119 |
| 140 // Reformats |text| into output vector |lines| so that the resulting text fits | 120 // Reformats |text| into output vector |lines| so that the resulting text fits |
| 141 // into an |available_pixel_width| by |available_pixel_height| rectangle with | 121 // into an |available_pixel_width| by |available_pixel_height| rectangle with |
| (...skipping 15 matching lines...) Expand all Loading... |
| 157 // CHARACTER_BREAK, and adds the horizontal ellipsis character (unicode | 137 // CHARACTER_BREAK, and adds the horizontal ellipsis character (unicode |
| 158 // character 0x2026) to render "...". The supplied string is returned if the | 138 // character 0x2026) to render "...". The supplied string is returned if the |
| 159 // string has |length| characters or less. | 139 // string has |length| characters or less. |
| 160 GFX_EXPORT base::string16 TruncateString(const base::string16& string, | 140 GFX_EXPORT base::string16 TruncateString(const base::string16& string, |
| 161 size_t length, | 141 size_t length, |
| 162 BreakType break_type); | 142 BreakType break_type); |
| 163 | 143 |
| 164 } // namespace gfx | 144 } // namespace gfx |
| 165 | 145 |
| 166 #endif // UI_GFX_TEXT_ELIDER_H_ | 146 #endif // UI_GFX_TEXT_ELIDER_H_ |
| OLD | NEW |