OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 APP_TEXT_ELIDER_H_ | 5 #ifndef APP_TEXT_ELIDER_H_ |
6 #define APP_TEXT_ELIDER_H_ | 6 #define APP_TEXT_ELIDER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <unicode/coll.h> | 9 #include <unicode/coll.h> |
10 #include <unicode/uchar.h> | 10 #include <unicode/uchar.h> |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 // Host name minus 'www.'. Used by Compare. | 82 // Host name minus 'www.'. Used by Compare. |
83 string16 sort_host_; | 83 string16 sort_host_; |
84 | 84 |
85 // End of the prefix (spec and separator) in display_url_. | 85 // End of the prefix (spec and separator) in display_url_. |
86 size_t prefix_end_; | 86 size_t prefix_end_; |
87 | 87 |
88 string16 display_url_; | 88 string16 display_url_; |
89 }; | 89 }; |
90 | 90 |
91 // Function to elide strings when the font information is unknown. As | 91 // Functions to elide strings when the font information is unknown. As |
92 // opposed to the above functions, the ElideString() function operates | 92 // opposed to the above functions, the ElideString() and |
93 // in terms of character units, not pixels. | 93 // ElideRectangleString() functions operate in terms of character units, |
| 94 // not pixels. |
| 95 |
94 // If the size of |input| is more than |max_len|, this function returns | 96 // If the size of |input| is more than |max_len|, this function returns |
95 // true and |input| is shortened into |output| by removing chars in the | 97 // true and |input| is shortened into |output| by removing chars in the |
96 // middle (they are replaced with up to 3 dots, as size permits). | 98 // middle (they are replaced with up to 3 dots, as size permits). |
97 // Ex: ElideString(L"Hello", 10, &str) puts Hello in str and returns false. | 99 // Ex: ElideString(L"Hello", 10, &str) puts Hello in str and returns false. |
98 // ElideString(L"Hello my name is Tom", 10, &str) puts "Hell...Tom" in str | 100 // ElideString(L"Hello my name is Tom", 10, &str) puts "Hell...Tom" in str |
99 // and returns true. | 101 // and returns true. |
100 // TODO(tsepez): Doesn't handle UTF-16 surrogate pairs properly. | 102 // TODO(tsepez): Doesn't handle UTF-16 surrogate pairs properly. |
101 // TODO(tsepez): Doesn't handle bidi properly | 103 // TODO(tsepez): Doesn't handle bidi properly |
102 bool ElideString(const std::wstring& input, int max_len, std::wstring* output); | 104 bool ElideString(const std::wstring& input, int max_len, std::wstring* output); |
103 | 105 |
| 106 // Reformat |input| into |output| so that it fits into a |max_rows| by |
| 107 // |max_cols| rectangle of characters. Input newlines are respected, but |
| 108 // lines that are too long are broken into pieces, first at naturally |
| 109 // occuring whitespace boundaries, and then intra-word (respecting UTF-16 |
| 110 // surrogate pairs) as necssary. Truncation (indicated by an added 3 dots) |
| 111 // occurs if the result is still too long. Returns true if the input had |
| 112 // to be truncated (and not just reformatted). |
| 113 bool ElideRectangleString(const string16& input, size_t max_rows, |
| 114 size_t max_cols, string16* output); |
| 115 |
| 116 |
104 } // namespace gfx. | 117 } // namespace gfx. |
105 | 118 |
106 #endif // APP_TEXT_ELIDER_H_ | 119 #endif // APP_TEXT_ELIDER_H_ |
OLD | NEW |