OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "ui/views/controls/styled_label.h" | 5 #include "ui/views/controls/styled_label.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "ui/gfx/font_list.h" | 10 #include "ui/gfx/font_list.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 } | 90 } |
91 | 91 |
92 | 92 |
93 // StyledLabel ---------------------------------------------------------------- | 93 // StyledLabel ---------------------------------------------------------------- |
94 | 94 |
95 StyledLabel::StyledLabel(const base::string16& text, | 95 StyledLabel::StyledLabel(const base::string16& text, |
96 StyledLabelListener* listener) | 96 StyledLabelListener* listener) |
97 : listener_(listener), | 97 : listener_(listener), |
98 displayed_on_background_color_set_(false), | 98 displayed_on_background_color_set_(false), |
99 auto_color_readability_enabled_(true) { | 99 auto_color_readability_enabled_(true) { |
100 TrimWhitespace(text, TRIM_TRAILING, &text_); | 100 base::TrimWhitespace(text, base::TRIM_TRAILING, &text_); |
101 } | 101 } |
102 | 102 |
103 StyledLabel::~StyledLabel() {} | 103 StyledLabel::~StyledLabel() {} |
104 | 104 |
105 void StyledLabel::SetText(const base::string16& text) { | 105 void StyledLabel::SetText(const base::string16& text) { |
106 text_ = text; | 106 text_ = text; |
107 style_ranges_.clear(); | 107 style_ranges_.clear(); |
108 RemoveAllChildViews(true); | 108 RemoveAllChildViews(true); |
109 PreferredSizeChanged(); | 109 PreferredSizeChanged(); |
110 } | 110 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 int x = 0; | 195 int x = 0; |
196 | 196 |
197 base::string16 remaining_string = text_; | 197 base::string16 remaining_string = text_; |
198 StyleRanges::const_iterator current_range = style_ranges_.begin(); | 198 StyleRanges::const_iterator current_range = style_ranges_.begin(); |
199 | 199 |
200 // Iterate over the text, creating a bunch of labels and links and laying them | 200 // Iterate over the text, creating a bunch of labels and links and laying them |
201 // out in the appropriate positions. | 201 // out in the appropriate positions. |
202 while (!remaining_string.empty()) { | 202 while (!remaining_string.empty()) { |
203 // Don't put whitespace at beginning of a line with an exception for the | 203 // Don't put whitespace at beginning of a line with an exception for the |
204 // first line (so the text's leading whitespace is respected). | 204 // first line (so the text's leading whitespace is respected). |
205 if (x == 0 && line > 0) | 205 if (x == 0 && line > 0) { |
206 TrimWhitespace(remaining_string, TRIM_LEADING, &remaining_string); | 206 base::TrimWhitespace(remaining_string, base::TRIM_LEADING, |
| 207 &remaining_string); |
| 208 } |
207 | 209 |
208 gfx::Range range(gfx::Range::InvalidRange()); | 210 gfx::Range range(gfx::Range::InvalidRange()); |
209 if (current_range != style_ranges_.end()) | 211 if (current_range != style_ranges_.end()) |
210 range = current_range->range; | 212 range = current_range->range; |
211 | 213 |
212 const size_t position = text_.size() - remaining_string.size(); | 214 const size_t position = text_.size() - remaining_string.size(); |
213 | 215 |
214 const gfx::Rect chunk_bounds(x, 0, width - x, 2 * line_height); | 216 const gfx::Rect chunk_bounds(x, 0, width - x, 2 * line_height); |
215 std::vector<base::string16> substrings; | 217 std::vector<base::string16> substrings; |
216 gfx::FontList text_font_list = font_list_; | 218 gfx::FontList text_font_list = font_list_; |
(...skipping 13 matching lines...) Expand all Loading... |
230 | 232 |
231 DCHECK(!substrings.empty()); | 233 DCHECK(!substrings.empty()); |
232 base::string16 chunk = substrings[0]; | 234 base::string16 chunk = substrings[0]; |
233 if (chunk.empty()) { | 235 if (chunk.empty()) { |
234 // Nothing fits on this line. Start a new line. | 236 // Nothing fits on this line. Start a new line. |
235 // If x is 0, first line may have leading whitespace that doesn't fit in a | 237 // If x is 0, first line may have leading whitespace that doesn't fit in a |
236 // single line, so try trimming those. Otherwise there is no room for | 238 // single line, so try trimming those. Otherwise there is no room for |
237 // anything; abort. | 239 // anything; abort. |
238 if (x == 0) { | 240 if (x == 0) { |
239 if (line == 0) { | 241 if (line == 0) { |
240 TrimWhitespace(remaining_string, TRIM_LEADING, &remaining_string); | 242 base::TrimWhitespace(remaining_string, base::TRIM_LEADING, |
| 243 &remaining_string); |
241 continue; | 244 continue; |
242 } | 245 } |
243 break; | 246 break; |
244 } | 247 } |
245 | 248 |
246 x = 0; | 249 x = 0; |
247 line++; | 250 line++; |
248 continue; | 251 continue; |
249 } | 252 } |
250 | 253 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 } | 300 } |
298 x += view_size.width() - focus_border_insets.width(); | 301 x += view_size.width() - focus_border_insets.width(); |
299 | 302 |
300 remaining_string = remaining_string.substr(chunk.size()); | 303 remaining_string = remaining_string.substr(chunk.size()); |
301 } | 304 } |
302 | 305 |
303 return gfx::Size(width, (line + 1) * line_height + GetInsets().height()); | 306 return gfx::Size(width, (line + 1) * line_height + GetInsets().height()); |
304 } | 307 } |
305 | 308 |
306 } // namespace views | 309 } // namespace views |
OLD | NEW |