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/base/text/text_elider.h" | 10 #include "ui/base/text/text_elider.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 88 |
89 StyledLabel::~StyledLabel() {} | 89 StyledLabel::~StyledLabel() {} |
90 | 90 |
91 void StyledLabel::SetText(const string16& text) { | 91 void StyledLabel::SetText(const string16& text) { |
92 text_ = text; | 92 text_ = text; |
93 style_ranges_ = std::priority_queue<StyleRange>(); | 93 style_ranges_ = std::priority_queue<StyleRange>(); |
94 RemoveAllChildViews(true); | 94 RemoveAllChildViews(true); |
95 PreferredSizeChanged(); | 95 PreferredSizeChanged(); |
96 } | 96 } |
97 | 97 |
98 void StyledLabel::AddStyleRange(const ui::Range& range, | 98 void StyledLabel::AddStyleRange(const gfx::Range& range, |
99 const RangeStyleInfo& style_info) { | 99 const RangeStyleInfo& style_info) { |
100 DCHECK(!range.is_reversed()); | 100 DCHECK(!range.is_reversed()); |
101 DCHECK(!range.is_empty()); | 101 DCHECK(!range.is_empty()); |
102 DCHECK(ui::Range(0, text_.size()).Contains(range)); | 102 DCHECK(gfx::Range(0, text_.size()).Contains(range)); |
103 | 103 |
104 style_ranges_.push(StyleRange(range, style_info)); | 104 style_ranges_.push(StyleRange(range, style_info)); |
105 | 105 |
106 PreferredSizeChanged(); | 106 PreferredSizeChanged(); |
107 } | 107 } |
108 | 108 |
109 void StyledLabel::SetDefaultStyle(const RangeStyleInfo& style_info) { | 109 void StyledLabel::SetDefaultStyle(const RangeStyleInfo& style_info) { |
110 default_style_info_ = style_info; | 110 default_style_info_ = style_info; |
111 PreferredSizeChanged(); | 111 PreferredSizeChanged(); |
112 } | 112 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 std::priority_queue<StyleRange> style_ranges = style_ranges_; | 165 std::priority_queue<StyleRange> style_ranges = style_ranges_; |
166 | 166 |
167 // Iterate over the text, creating a bunch of labels and links and laying them | 167 // Iterate over the text, creating a bunch of labels and links and laying them |
168 // out in the appropriate positions. | 168 // out in the appropriate positions. |
169 while (!remaining_string.empty()) { | 169 while (!remaining_string.empty()) { |
170 // Don't put whitespace at beginning of a line with an exception for the | 170 // Don't put whitespace at beginning of a line with an exception for the |
171 // first line (so the text's leading whitespace is respected). | 171 // first line (so the text's leading whitespace is respected). |
172 if (x == 0 && line > 0) | 172 if (x == 0 && line > 0) |
173 TrimWhitespace(remaining_string, TRIM_LEADING, &remaining_string); | 173 TrimWhitespace(remaining_string, TRIM_LEADING, &remaining_string); |
174 | 174 |
175 ui::Range range(ui::Range::InvalidRange()); | 175 gfx::Range range(gfx::Range::InvalidRange()); |
176 if (!style_ranges.empty()) | 176 if (!style_ranges.empty()) |
177 range = style_ranges.top().range; | 177 range = style_ranges.top().range; |
178 | 178 |
179 const size_t position = text_.size() - remaining_string.size(); | 179 const size_t position = text_.size() - remaining_string.size(); |
180 | 180 |
181 const gfx::Rect chunk_bounds(x, 0, width - x, 2 * line_height); | 181 const gfx::Rect chunk_bounds(x, 0, width - x, 2 * line_height); |
182 std::vector<string16> substrings; | 182 std::vector<string16> substrings; |
183 gfx::Font text_font; | 183 gfx::Font text_font; |
184 // If the start of the remaining text is inside a styled range, the font | 184 // If the start of the remaining text is inside a styled range, the font |
185 // style may differ from the base font. The font specified by the range | 185 // style may differ from the base font. The font specified by the range |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 } | 261 } |
262 x += view_size.width() - 2 * overlap; | 262 x += view_size.width() - 2 * overlap; |
263 | 263 |
264 remaining_string = remaining_string.substr(chunk.size()); | 264 remaining_string = remaining_string.substr(chunk.size()); |
265 } | 265 } |
266 | 266 |
267 return (line + 1) * line_height + GetInsets().height(); | 267 return (line + 1) * line_height + GetInsets().height(); |
268 } | 268 } |
269 | 269 |
270 } // namespace views | 270 } // namespace views |
OLD | NEW |