Chromium Code Reviews| Index: ui/views/controls/styled_label.cc |
| diff --git a/ui/views/controls/styled_label.cc b/ui/views/controls/styled_label.cc |
| index e7ee56c0b44de2b806803fd4da900308c5ade9d4..6389b0395f3979c504026921617e6f7fcac6594f 100644 |
| --- a/ui/views/controls/styled_label.cc |
| +++ b/ui/views/controls/styled_label.cc |
| @@ -94,7 +94,8 @@ bool StyledLabel::StyleRange::operator<( |
| StyledLabel::StyledLabel(const base::string16& text, |
| StyledLabelListener* listener) |
| - : listener_(listener), |
| + : line_height_multiplier_(1.0), |
| + listener_(listener), |
| displayed_on_background_color_set_(false), |
| auto_color_readability_enabled_(true) { |
| base::TrimWhitespace(text, base::TRIM_TRAILING, &text_); |
| @@ -133,6 +134,14 @@ void StyledLabel::SetDefaultStyle(const RangeStyleInfo& style_info) { |
| PreferredSizeChanged(); |
| } |
| +void StyledLabel::SetLineHeightMultiplier(double multiplier) { |
| + if (multiplier < 1.0) |
|
sky
2014/06/25 23:29:09
DCHECK
Garrett Casto
2014/06/25 23:47:25
Done.
|
| + return; |
| + |
| + line_height_multiplier_ = multiplier; |
| + PreferredSizeChanged(); |
| +} |
| + |
| void StyledLabel::SetDisplayedOnBackgroundColor(SkColor color) { |
| displayed_on_background_color_ = color; |
| displayed_on_background_color_set_ = true; |
| @@ -193,7 +202,7 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) { |
| if (width <= 0 || text_.empty()) |
| return gfx::Size(); |
| - const int line_height = CalculateLineHeight(font_list_); |
| + const int line_height = GetLineHeight(); |
| // The index of the line we're on. |
| int line = 0; |
| // The x position (in pixels) of the line we're on, relative to content |
| @@ -295,11 +304,10 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) { |
| gfx::Insets focus_border_insets(label->GetInsets()); |
| focus_border_insets += -label->View::GetInsets(); |
| const gfx::Size view_size = label->GetPreferredSize(); |
| - DCHECK_EQ(line_height, view_size.height() - focus_border_insets.height()); |
| if (!dry_run) { |
| label->SetBoundsRect(gfx::Rect( |
| gfx::Point(GetInsets().left() + x - focus_border_insets.left(), |
| - GetInsets().top() + line * line_height - |
| + GetInsets().top() + GetOffsetForLine(line) - |
| focus_border_insets.top()), |
| view_size)); |
| AddChildView(label.release()); |
| @@ -309,7 +317,22 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) { |
| remaining_string = remaining_string.substr(chunk.size()); |
| } |
| - return gfx::Size(width, (line + 1) * line_height + GetInsets().height()); |
| + return gfx::Size( |
| + width, |
| + (line + 1) * line_height + GetInsets().height()); |
| +} |
| + |
| +int StyledLabel::GetLineHeight() const { |
| + return CalculateLineHeight(font_list_) * line_height_multiplier_; |
| +} |
| + |
| +int StyledLabel::GetOffsetForLine(int line) const { |
| + int default_line_height = CalculateLineHeight(font_list_); |
| + int line_height = GetLineHeight(); |
| + |
| + // Center text in the space available. |
| + int interline_offset = (line_height - default_line_height) / 2; |
| + return line_height * line + interline_offset; |
| } |
| } // namespace views |