| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/button/label_button.h" | 5 #include "ui/views/controls/button/label_button.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 242 |
| 243 void LabelButton::SetFocusPainter(std::unique_ptr<Painter> focus_painter) { | 243 void LabelButton::SetFocusPainter(std::unique_ptr<Painter> focus_painter) { |
| 244 focus_painter_ = std::move(focus_painter); | 244 focus_painter_ = std::move(focus_painter); |
| 245 } | 245 } |
| 246 | 246 |
| 247 gfx::Size LabelButton::GetPreferredSize() const { | 247 gfx::Size LabelButton::GetPreferredSize() const { |
| 248 if (cached_preferred_size_valid_) | 248 if (cached_preferred_size_valid_) |
| 249 return cached_preferred_size_; | 249 return cached_preferred_size_; |
| 250 | 250 |
| 251 // Use a temporary label copy for sizing to avoid calculation side-effects. | 251 // Use a temporary label copy for sizing to avoid calculation side-effects. |
| 252 Label label(GetText(), cached_normal_font_list_); | 252 Label label(GetText(), label_->font_list()); |
| 253 label.SetShadows(label_->shadows()); | 253 label.SetShadows(label_->shadows()); |
| 254 | 254 |
| 255 if (style_ == STYLE_BUTTON && PlatformStyle::kDefaultLabelButtonHasBoldFont) { | 255 if (style_ == STYLE_BUTTON && PlatformStyle::kDefaultLabelButtonHasBoldFont) { |
| 256 // Some text appears wider when rendered normally than when rendered bold. | 256 // Some text appears wider when rendered normally than when rendered bold. |
| 257 // Accommodate the widest, as buttons may show bold and shouldn't resize. | 257 // Accommodate the widest, as buttons may show bold and shouldn't resize. |
| 258 const int current_width = label.GetPreferredSize().width(); | 258 const int current_width = label.GetPreferredSize().width(); |
| 259 label.SetFontList(cached_bold_font_list_); | 259 label.SetFontList(cached_bold_font_list_); |
| 260 if (label.GetPreferredSize().width() < current_width) | 260 if (label.GetPreferredSize().width() < current_width) |
| 261 label.SetFontList(cached_normal_font_list_); | 261 label.SetFontList(label_->font_list()); |
| 262 } | 262 } |
| 263 | 263 |
| 264 // Calculate the required size. | 264 // Calculate the required size. |
| 265 const gfx::Size image_size(image_->GetPreferredSize()); | 265 const gfx::Size image_size(image_->GetPreferredSize()); |
| 266 gfx::Size size(label.GetPreferredSize()); | 266 gfx::Size size(label.GetPreferredSize()); |
| 267 if (image_size.width() > 0 && size.width() > 0) | 267 if (image_size.width() > 0 && size.width() > 0) |
| 268 size.Enlarge(image_label_spacing_, 0); | 268 size.Enlarge(image_label_spacing_, 0); |
| 269 size.SetToMax(gfx::Size(0, image_size.height())); | 269 size.SetToMax(gfx::Size(0, image_size.height())); |
| 270 const gfx::Insets insets(GetInsets()); | 270 const gfx::Insets insets(GetInsets()); |
| 271 size.Enlarge(image_size.width() + insets.width(), insets.height()); | 271 size.Enlarge(image_size.width() + insets.width(), insets.height()); |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 : PlatformStyle::TextColorForButton(button_state_colors_, *this); | 603 : PlatformStyle::TextColorForButton(button_state_colors_, *this); |
| 604 if (state() != STATE_DISABLED && label_->enabled_color() != color) | 604 if (state() != STATE_DISABLED && label_->enabled_color() != color) |
| 605 label_->SetEnabledColor(color); | 605 label_->SetEnabledColor(color); |
| 606 } | 606 } |
| 607 | 607 |
| 608 bool LabelButton::UseFloodFillInkDrop() const { | 608 bool LabelButton::UseFloodFillInkDrop() const { |
| 609 return !GetText().empty(); | 609 return !GetText().empty(); |
| 610 } | 610 } |
| 611 | 611 |
| 612 } // namespace views | 612 } // namespace views |
| OLD | NEW |