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 21707e8ae7436b952450af691da4c8b88b470dc2..7cbf09a6296d7d07f490cefbad62564c6ae07a86 100644 |
| --- a/ui/views/controls/button/label_button.cc |
| +++ b/ui/views/controls/button/label_button.cc |
| @@ -31,61 +31,23 @@ |
| #include "ui/views/views_delegate.h" |
| #include "ui/views/window/dialog_delegate.h" |
| -namespace { |
| - |
| -gfx::Font::Weight GetValueBolderThan(gfx::Font::Weight weight) { |
| - if (weight < gfx::Font::Weight::BOLD) |
| - return gfx::Font::Weight::BOLD; |
| - switch (weight) { |
| - case gfx::Font::Weight::BOLD: |
| - return gfx::Font::Weight::EXTRA_BOLD; |
| - case gfx::Font::Weight::EXTRA_BOLD: |
| - case gfx::Font::Weight::BLACK: |
| - return gfx::Font::Weight::BLACK; |
| - default: |
| - NOTREACHED(); |
| - } |
| - return gfx::Font::Weight::INVALID; |
| -} |
| - |
| -const gfx::FontList& GetDefaultNormalFontList() { |
| - static base::LazyInstance<gfx::FontList>::Leaky font_list = |
| - LAZY_INSTANCE_INITIALIZER; |
| - return font_list.Get(); |
| -} |
| - |
| -const gfx::FontList& GetDefaultBoldFontList() { |
| - if (!views::PlatformStyle::kDefaultLabelButtonHasBoldFont) |
| - return GetDefaultNormalFontList(); |
| - |
| - static base::LazyInstance<gfx::FontList>::Leaky font_list = |
| - LAZY_INSTANCE_INITIALIZER; |
| - |
| - static const gfx::Font::Weight default_bold_weight = |
| - font_list.Get().GetFontWeight(); |
| - |
| - font_list.Get() = font_list.Get().DeriveWithWeight( |
| - GetValueBolderThan(default_bold_weight)); |
| - DCHECK_GE(font_list.Get().GetFontWeight(), gfx::Font::Weight::BOLD); |
| - |
| - return font_list.Get(); |
| -} |
| - |
| -} // namespace |
| - |
| namespace views { |
| // static |
| const int LabelButton::kHoverAnimationDurationMs = 170; |
| const char LabelButton::kViewClassName[] = "LabelButton"; |
| -LabelButton::LabelButton(ButtonListener* listener, const base::string16& text) |
| +LabelButton::LabelButton(ButtonListener* listener, |
| + const base::string16& text, |
| + int button_context) |
| : CustomButton(listener), |
| image_(new ImageView()), |
| - label_(new Label()), |
| + label_(new Label(text, button_context, style::STYLE_PRIMARY)), |
| ink_drop_container_(new InkDropContainerView()), |
| - cached_normal_font_list_(GetDefaultNormalFontList()), |
| - cached_bold_font_list_(GetDefaultBoldFontList()), |
| + cached_normal_font_list_( |
| + style::GetFont(button_context, style::STYLE_PRIMARY)), |
| + cached_bold_font_list_( |
| + style::GetFont(button_context, style::STYLE_DEFAULT_DIALOG_BUTTON)), |
|
Peter Kasting
2017/04/08 01:38:54
This isn't always bold, so does naming the variabl
tapted
2017/04/10 12:27:33
Done.
|
| button_state_images_(), |
| button_state_colors_(), |
| explicitly_set_colors_(), |
| @@ -96,7 +58,7 @@ LabelButton::LabelButton(ButtonListener* listener, const base::string16& text) |
| DistanceMetric::RELATED_CONTROL_HORIZONTAL)), |
| horizontal_alignment_(gfx::ALIGN_LEFT) { |
| SetAnimationDuration(kHoverAnimationDurationMs); |
| - SetTextInternal(text); |
| + SetAccessibleName(text); |
| AddChildView(ink_drop_container_); |
| ink_drop_container_->SetPaintToLayer(); |
| @@ -107,7 +69,6 @@ LabelButton::LabelButton(ButtonListener* listener, const base::string16& text) |
| image_->set_can_process_events_within_subtree(false); |
| AddChildView(label_); |
| - label_->SetFontList(cached_normal_font_list_); |
| label_->SetAutoColorReadabilityEnabled(false); |
| label_->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); |
| @@ -159,11 +120,6 @@ void LabelButton::SetTextSubpixelRenderingEnabled(bool enabled) { |
| label_->SetSubpixelRenderingEnabled(enabled); |
| } |
| -void LabelButton::AdjustFontSize(int font_size_delta) { |
| - LabelButton::SetFontList( |
| - label()->font_list().DeriveWithSizeDelta(font_size_delta)); |
| -} |
| - |
| void LabelButton::SetElideBehavior(gfx::ElideBehavior elide_behavior) { |
| label_->SetElideBehavior(elide_behavior); |
| } |
| @@ -378,19 +334,6 @@ gfx::Rect LabelButton::GetChildAreaBounds() { |
| return GetLocalBounds(); |
| } |
| -void LabelButton::SetFontList(const gfx::FontList& font_list) { |
| - cached_normal_font_list_ = font_list; |
| - if (PlatformStyle::kDefaultLabelButtonHasBoldFont) { |
| - cached_bold_font_list_ = font_list.DeriveWithWeight( |
| - GetValueBolderThan(font_list.GetFontWeight())); |
| - if (is_default_) { |
| - label_->SetFontList(cached_bold_font_list_); |
| - return; |
| - } |
| - } |
| - label_->SetFontList(cached_normal_font_list_); |
| -} |
| - |
| void LabelButton::OnPaint(gfx::Canvas* canvas) { |
| View::OnPaint(canvas); |
| Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); |
| @@ -520,8 +463,15 @@ void LabelButton::ResetColorsFromNativeTheme() { |
| } |
| void LabelButton::UpdateStyleToIndicateDefaultStatus() { |
| + // Check that a subclass hasn't replaced the Label font. These buttons may |
| + // never be given default status. |
| + DCHECK_EQ(label()->font_list().GetFontSize(), |
| + cached_normal_font_list_.GetFontSize()); |
|
Peter Kasting
2017/04/08 01:38:54
Nit: (expected, actual)
tapted
2017/04/10 12:27:33
Done.
|
| const bool bold = |
| PlatformStyle::kDefaultLabelButtonHasBoldFont && is_default_; |
| + // TODO(tapted): This should use style::GetFont(), but this part can just be |
| + // deleted when default buttons no longer go bold. Colors will need updating |
| + // still. |
| label_->SetFontList(bold ? cached_bold_font_list_ : cached_normal_font_list_); |
| InvalidateLayout(); |
| ResetLabelEnabledColor(); |