| 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 14 matching lines...) Expand all Loading... |
| 25 #include "ui/views/controls/button/label_button_border.h" | 25 #include "ui/views/controls/button/label_button_border.h" |
| 26 #include "ui/views/painter.h" | 26 #include "ui/views/painter.h" |
| 27 #include "ui/views/style/platform_style.h" | 27 #include "ui/views/style/platform_style.h" |
| 28 #include "ui/views/window/dialog_delegate.h" | 28 #include "ui/views/window/dialog_delegate.h" |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // The default spacing between the icon and text. | 32 // The default spacing between the icon and text. |
| 33 const int kSpacing = 5; | 33 const int kSpacing = 5; |
| 34 | 34 |
| 35 gfx::Font::Weight GetValueBolderThan(gfx::Font::Weight weight) { |
| 36 if (weight < gfx::Font::Weight::BOLD) |
| 37 return gfx::Font::Weight::BOLD; |
| 38 switch (weight) { |
| 39 case gfx::Font::Weight::BOLD: |
| 40 return gfx::Font::Weight::EXTRA_BOLD; |
| 41 case gfx::Font::Weight::EXTRA_BOLD: |
| 42 case gfx::Font::Weight::BLACK: |
| 43 return gfx::Font::Weight::BLACK; |
| 44 default: |
| 45 NOTREACHED(); |
| 46 } |
| 47 return gfx::Font::Weight::INVALID; |
| 48 } |
| 49 |
| 35 const gfx::FontList& GetDefaultNormalFontList() { | 50 const gfx::FontList& GetDefaultNormalFontList() { |
| 36 static base::LazyInstance<gfx::FontList>::Leaky font_list = | 51 static base::LazyInstance<gfx::FontList>::Leaky font_list = |
| 37 LAZY_INSTANCE_INITIALIZER; | 52 LAZY_INSTANCE_INITIALIZER; |
| 38 return font_list.Get(); | 53 return font_list.Get(); |
| 39 } | 54 } |
| 40 | 55 |
| 41 const gfx::FontList& GetDefaultBoldFontList() { | 56 const gfx::FontList& GetDefaultBoldFontList() { |
| 42 if (!views::PlatformStyle::kDefaultLabelButtonHasBoldFont) | 57 if (!views::PlatformStyle::kDefaultLabelButtonHasBoldFont) |
| 43 return GetDefaultNormalFontList(); | 58 return GetDefaultNormalFontList(); |
| 44 | 59 |
| 45 static base::LazyInstance<gfx::FontList>::Leaky font_list = | 60 static base::LazyInstance<gfx::FontList>::Leaky font_list = |
| 46 LAZY_INSTANCE_INITIALIZER; | 61 LAZY_INSTANCE_INITIALIZER; |
| 47 if ((font_list.Get().GetFontStyle() & gfx::Font::BOLD) == 0) { | 62 |
| 48 font_list.Get() = font_list.Get(). | 63 static const gfx::Font::Weight default_bold_weight = |
| 49 DeriveWithStyle(font_list.Get().GetFontStyle() | gfx::Font::BOLD); | 64 font_list.Get().GetFontWeight(); |
| 50 DCHECK_NE(font_list.Get().GetFontStyle() & gfx::Font::BOLD, 0); | 65 |
| 51 } | 66 font_list.Get() = font_list.Get().DeriveWithWeight( |
| 67 GetValueBolderThan(default_bold_weight)); |
| 68 DCHECK_GE(font_list.Get().GetFontWeight(), gfx::Font::Weight::BOLD); |
| 69 |
| 52 return font_list.Get(); | 70 return font_list.Get(); |
| 53 } | 71 } |
| 54 | 72 |
| 55 // Ink drop container view that does not capture any events. | 73 // Ink drop container view that does not capture any events. |
| 56 class InkDropContainerView : public views::View { | 74 class InkDropContainerView : public views::View { |
| 57 public: | 75 public: |
| 58 InkDropContainerView() {} | 76 InkDropContainerView() {} |
| 59 | 77 |
| 60 // View: | 78 // View: |
| 61 bool CanProcessEventsWithinSubtree() const override { | 79 bool CanProcessEventsWithinSubtree() const override { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 label_->SetSubpixelRenderingEnabled(enabled); | 176 label_->SetSubpixelRenderingEnabled(enabled); |
| 159 } | 177 } |
| 160 | 178 |
| 161 const gfx::FontList& LabelButton::GetFontList() const { | 179 const gfx::FontList& LabelButton::GetFontList() const { |
| 162 return label_->font_list(); | 180 return label_->font_list(); |
| 163 } | 181 } |
| 164 | 182 |
| 165 void LabelButton::SetFontList(const gfx::FontList& font_list) { | 183 void LabelButton::SetFontList(const gfx::FontList& font_list) { |
| 166 cached_normal_font_list_ = font_list; | 184 cached_normal_font_list_ = font_list; |
| 167 if (PlatformStyle::kDefaultLabelButtonHasBoldFont) { | 185 if (PlatformStyle::kDefaultLabelButtonHasBoldFont) { |
| 168 cached_bold_font_list_ = | 186 cached_bold_font_list_ = font_list.DeriveWithWeight( |
| 169 font_list.DeriveWithStyle(font_list.GetFontStyle() | gfx::Font::BOLD); | 187 GetValueBolderThan(font_list.GetFontWeight())); |
| 170 if (is_default_) { | 188 if (is_default_) { |
| 171 label_->SetFontList(cached_bold_font_list_); | 189 label_->SetFontList(cached_bold_font_list_); |
| 172 return; | 190 return; |
| 173 } | 191 } |
| 174 } | 192 } |
| 175 label_->SetFontList(cached_normal_font_list_); | 193 label_->SetFontList(cached_normal_font_list_); |
| 176 } | 194 } |
| 177 | 195 |
| 178 void LabelButton::SetElideBehavior(gfx::ElideBehavior elide_behavior) { | 196 void LabelButton::SetElideBehavior(gfx::ElideBehavior elide_behavior) { |
| 179 label_->SetElideBehavior(elide_behavior); | 197 label_->SetElideBehavior(elide_behavior); |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 void LabelButton::ResetLabelEnabledColor() { | 589 void LabelButton::ResetLabelEnabledColor() { |
| 572 const SkColor color = | 590 const SkColor color = |
| 573 explicitly_set_colors_[state()] | 591 explicitly_set_colors_[state()] |
| 574 ? button_state_colors_[state()] | 592 ? button_state_colors_[state()] |
| 575 : PlatformStyle::TextColorForButton(button_state_colors_, *this); | 593 : PlatformStyle::TextColorForButton(button_state_colors_, *this); |
| 576 if (state() != STATE_DISABLED && label_->enabled_color() != color) | 594 if (state() != STATE_DISABLED && label_->enabled_color() != color) |
| 577 label_->SetEnabledColor(color); | 595 label_->SetEnabledColor(color); |
| 578 } | 596 } |
| 579 | 597 |
| 580 } // namespace views | 598 } // namespace views |
| OLD | NEW |