Chromium Code Reviews| Index: ui/views/controls/button/label_button.cc |
| diff --git a/ui/views/controls/button/label_button.cc b/ui/views/controls/button/label_button.cc |
| index 5ee97918dc9f794c1d1189ffa3e570449e6c16f7..5f0e78c2d6920c6b87f1936d2b7d733abc2a9257 100644 |
| --- a/ui/views/controls/button/label_button.cc |
| +++ b/ui/views/controls/button/label_button.cc |
| @@ -89,6 +89,7 @@ const base::string16& LabelButton::GetText() const { |
| void LabelButton::SetText(const base::string16& text) { |
| SetAccessibleName(text); |
| label_->SetText(text); |
| + ResetCachedSize(); |
| } |
| void LabelButton::SetTextColor(ButtonState for_state, SkColor color) { |
| @@ -114,6 +115,7 @@ bool LabelButton::GetTextMultiLine() const { |
| void LabelButton::SetTextMultiLine(bool text_multi_line) { |
| label_->SetMultiLine(text_multi_line); |
| + ResetCachedSize(); |
| } |
| const gfx::FontList& LabelButton::GetFontList() const { |
| @@ -129,10 +131,12 @@ void LabelButton::SetFontList(const gfx::FontList& font_list) { |
| label_->SetFontList( |
| style_ == STYLE_BUTTON && is_default_ ? |
| cached_bold_font_list_ : cached_normal_font_list_); |
| + ResetCachedSize(); |
| } |
| void LabelButton::SetElideBehavior(gfx::ElideBehavior elide_behavior) { |
| label_->SetElideBehavior(elide_behavior); |
| + ResetCachedSize(); |
| } |
| gfx::HorizontalAlignment LabelButton::GetHorizontalAlignment() const { |
| @@ -141,6 +145,7 @@ gfx::HorizontalAlignment LabelButton::GetHorizontalAlignment() const { |
| void LabelButton::SetHorizontalAlignment(gfx::HorizontalAlignment alignment) { |
| label_->SetHorizontalAlignment(alignment); |
| + ResetCachedSize(); |
| InvalidateLayout(); |
| } |
| @@ -173,7 +178,7 @@ void LabelButton::SetStyle(ButtonStyle style) { |
| } |
| if (style == STYLE_BUTTON) |
| set_min_size(gfx::Size(70, 33)); |
| - |
| + ResetCachedSize(); |
|
msw
2014/07/21 16:28:26
Call this after OnNativeThemeChanged.
noms (inactive)
2014/07/21 17:18:51
Done.
|
| OnNativeThemeChanged(GetNativeTheme()); |
| } |
| @@ -182,6 +187,9 @@ void LabelButton::SetFocusPainter(scoped_ptr<Painter> focus_painter) { |
| } |
| gfx::Size LabelButton::GetPreferredSize() const { |
| + if (button_size_valid_) |
| + return button_size_; |
| + |
| // Use a temporary label copy for sizing to avoid calculation side-effects. |
| Label label(GetText(), cached_normal_font_list_); |
| label.SetShadows(label_->shadows()); |
| @@ -217,7 +225,11 @@ gfx::Size LabelButton::GetPreferredSize() const { |
| size.set_width(std::min(max_size_.width(), size.width())); |
| if (max_size_.height() > 0) |
| size.set_height(std::min(max_size_.height(), size.height())); |
| - return size; |
| + |
| + // Cache this computed size, as recomputing it is an expensive operation. |
| + button_size_valid_ = true; |
| + button_size_ = size; |
| + return button_size_; |
| } |
| int LabelButton::GetHeightForWidth(int w) const { |
| @@ -292,6 +304,7 @@ scoped_ptr<LabelButtonBorder> LabelButton::CreateDefaultBorder() const { |
| void LabelButton::SetBorder(scoped_ptr<Border> border) { |
| border_is_themed_border_ = false; |
| View::SetBorder(border.Pass()); |
| + ResetCachedSize(); |
| } |
| gfx::Rect LabelButton::GetChildAreaBounds() { |
| @@ -411,6 +424,7 @@ void LabelButton::StateChanged() { |
| } |
| void LabelButton::ChildPreferredSizeChanged(View* child) { |
| + ResetCachedSize(); |
| PreferredSizeChanged(); |
| } |
| @@ -458,4 +472,9 @@ ui::NativeTheme::State LabelButton::GetForegroundThemeState( |
| return ui::NativeTheme::kHovered; |
| } |
| +void LabelButton::ResetCachedSize() { |
| + button_size_valid_ = false; |
| + button_size_= gfx::Size(); |
| +} |
| + |
| } // namespace views |