| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 // equal-length pieces from the beginning and end of the string; otherwise, | 44 // equal-length pieces from the beginning and end of the string; otherwise, |
| 45 // the end of the string is removed and only the beginning remains. If | 45 // the end of the string is removed and only the beginning remains. If |
| 46 // |insert_ellipsis| is true, then an ellipsis character will be inserted at | 46 // |insert_ellipsis| is true, then an ellipsis character will be inserted at |
| 47 // the cut point (note that the ellipsis will does not count towards the | 47 // the cut point (note that the ellipsis will does not count towards the |
| 48 // |length| limit). | 48 // |length| limit). |
| 49 // Note: Characters may still be omitted even if |length| is the full string | 49 // Note: Characters may still be omitted even if |length| is the full string |
| 50 // length, if surrogate pairs fall on the split boundary. | 50 // length, if surrogate pairs fall on the split boundary. |
| 51 base::string16 CutString(size_t length, bool insert_ellipsis) const; | 51 base::string16 CutString(size_t length, bool insert_ellipsis) const; |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 // Returns a valid cut boundary at or before/after |index|. | |
| 55 size_t FindValidBoundaryBefore(size_t index) const; | |
| 56 size_t FindValidBoundaryAfter(size_t index) const; | |
| 57 | |
| 58 // The text to be sliced. | 54 // The text to be sliced. |
| 59 const base::string16& text_; | 55 const base::string16& text_; |
| 60 | 56 |
| 61 // Ellipsis string to use. | 57 // Ellipsis string to use. |
| 62 const base::string16& ellipsis_; | 58 const base::string16& ellipsis_; |
| 63 | 59 |
| 64 // If true, the middle of the string will be elided. | 60 // If true, the middle of the string will be elided. |
| 65 bool elide_in_middle_; | 61 bool elide_in_middle_; |
| 66 | 62 |
| 67 // If true, the beginning of the string will be elided. | 63 // If true, the beginning of the string will be elided. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 // CHARACTER_BREAK, and adds the horizontal ellipsis character (unicode | 140 // CHARACTER_BREAK, and adds the horizontal ellipsis character (unicode |
| 145 // character 0x2026) to render "...". The supplied string is returned if the | 141 // character 0x2026) to render "...". The supplied string is returned if the |
| 146 // string has |length| characters or less. | 142 // string has |length| characters or less. |
| 147 GFX_EXPORT base::string16 TruncateString(const base::string16& string, | 143 GFX_EXPORT base::string16 TruncateString(const base::string16& string, |
| 148 size_t length, | 144 size_t length, |
| 149 BreakType break_type); | 145 BreakType break_type); |
| 150 | 146 |
| 151 } // namespace gfx | 147 } // namespace gfx |
| 152 | 148 |
| 153 #endif // UI_GFX_TEXT_ELIDER_H_ | 149 #endif // UI_GFX_TEXT_ELIDER_H_ |
| OLD | NEW |