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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // StyledLabel::StyleRange ---------------------------------------------------- | 85 // StyledLabel::StyleRange ---------------------------------------------------- |
86 | 86 |
87 bool StyledLabel::StyleRange::operator<( | 87 bool StyledLabel::StyleRange::operator<( |
88 const StyledLabel::StyleRange& other) const { | 88 const StyledLabel::StyleRange& other) const { |
89 return range.start() < other.range.start(); | 89 return range.start() < other.range.start(); |
90 } | 90 } |
91 | 91 |
92 | 92 |
93 // StyledLabel ---------------------------------------------------------------- | 93 // StyledLabel ---------------------------------------------------------------- |
94 | 94 |
| 95 // static |
| 96 const char StyledLabel::kViewClassName[] = "StyledLabel"; |
| 97 |
95 StyledLabel::StyledLabel(const base::string16& text, | 98 StyledLabel::StyledLabel(const base::string16& text, |
96 StyledLabelListener* listener) | 99 StyledLabelListener* listener) |
97 : specified_line_height_(0), | 100 : specified_line_height_(0), |
98 listener_(listener), | 101 listener_(listener), |
99 width_at_last_layout_(0), | 102 width_at_last_layout_(0), |
100 displayed_on_background_color_(SkColorSetRGB(0xFF, 0xFF, 0xFF)), | 103 displayed_on_background_color_(SkColorSetRGB(0xFF, 0xFF, 0xFF)), |
101 displayed_on_background_color_set_(false), | 104 displayed_on_background_color_set_(false), |
102 auto_color_readability_enabled_(true) { | 105 auto_color_readability_enabled_(true) { |
103 base::TrimWhitespace(text, base::TRIM_TRAILING, &text_); | 106 base::TrimWhitespace(text, base::TRIM_TRAILING, &text_); |
104 } | 107 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 displayed_on_background_color_ = color; | 152 displayed_on_background_color_ = color; |
150 displayed_on_background_color_set_ = true; | 153 displayed_on_background_color_set_ = true; |
151 | 154 |
152 for (int i = 0, count = child_count(); i < count; ++i) { | 155 for (int i = 0, count = child_count(); i < count; ++i) { |
153 DCHECK((child_at(i)->GetClassName() == Label::kViewClassName) || | 156 DCHECK((child_at(i)->GetClassName() == Label::kViewClassName) || |
154 (child_at(i)->GetClassName() == Link::kViewClassName)); | 157 (child_at(i)->GetClassName() == Link::kViewClassName)); |
155 static_cast<Label*>(child_at(i))->SetBackgroundColor(color); | 158 static_cast<Label*>(child_at(i))->SetBackgroundColor(color); |
156 } | 159 } |
157 } | 160 } |
158 | 161 |
| 162 const char* StyledLabel::GetClassName() const { |
| 163 return kViewClassName; |
| 164 } |
| 165 |
159 gfx::Insets StyledLabel::GetInsets() const { | 166 gfx::Insets StyledLabel::GetInsets() const { |
160 gfx::Insets insets = View::GetInsets(); | 167 gfx::Insets insets = View::GetInsets(); |
161 | 168 |
162 // We need a focus border iff we contain a link that will have a focus border. | 169 // We need a focus border iff we contain a link that will have a focus border. |
163 // That in turn will be true only if the link is non-empty. | 170 // That in turn will be true only if the link is non-empty. |
164 for (StyleRanges::const_iterator i(style_ranges_.begin()); | 171 for (StyleRanges::const_iterator i(style_ranges_.begin()); |
165 i != style_ranges_.end(); ++i) { | 172 i != style_ranges_.end(); ++i) { |
166 if (i->style_info.is_link && !i->range.is_empty()) { | 173 if (i->style_info.is_link && !i->range.is_empty()) { |
167 const gfx::Insets focus_border_padding( | 174 const gfx::Insets focus_border_padding( |
168 Label::kFocusBorderPadding, Label::kFocusBorderPadding, | 175 Label::kFocusBorderPadding, Label::kFocusBorderPadding, |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 } | 338 } |
332 | 339 |
333 // The user-specified line height only applies to interline spacing, so the | 340 // The user-specified line height only applies to interline spacing, so the |
334 // final line's height is unaffected. | 341 // final line's height is unaffected. |
335 int total_height = line * line_height + | 342 int total_height = line * line_height + |
336 CalculateLineHeight(font_list_) + GetInsets().height(); | 343 CalculateLineHeight(font_list_) + GetInsets().height(); |
337 return gfx::Size(width, total_height); | 344 return gfx::Size(width, total_height); |
338 } | 345 } |
339 | 346 |
340 } // namespace views | 347 } // namespace views |
OLD | NEW |