| 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 f5b07e474368a2d8484444a0ed37887ddf5a3ff0..02fa585de16d472b26013dc1d7cbea35e5f1f3ad 100644
|
| --- a/ui/views/controls/button/label_button.cc
|
| +++ b/ui/views/controls/button/label_button.cc
|
| @@ -30,12 +30,6 @@ namespace {
|
| // The default spacing between the icon and text.
|
| const int kSpacing = 5;
|
|
|
| -#if !(defined(OS_LINUX) && !defined(OS_CHROMEOS))
|
| -// Default text and shadow colors for STYLE_BUTTON.
|
| -const SkColor kStyleButtonTextColor = SK_ColorBLACK;
|
| -const SkColor kStyleButtonShadowColor = SK_ColorWHITE;
|
| -#endif
|
| -
|
| const gfx::FontList& GetDefaultNormalFontList() {
|
| static base::LazyInstance<gfx::FontList>::Leaky font_list =
|
| LAZY_INSTANCE_INITIALIZER;
|
| @@ -43,6 +37,9 @@ const gfx::FontList& GetDefaultNormalFontList() {
|
| }
|
|
|
| const gfx::FontList& GetDefaultBoldFontList() {
|
| + if (!views::PlatformStyle::kDefaultLabelButtonHasBoldFont)
|
| + return GetDefaultNormalFontList();
|
| +
|
| static base::LazyInstance<gfx::FontList>::Leaky font_list =
|
| LAZY_INSTANCE_INITIALIZER;
|
| if ((font_list.Get().GetFontStyle() & gfx::Font::BOLD) == 0) {
|
| @@ -163,10 +160,15 @@ const gfx::FontList& LabelButton::GetFontList() const {
|
|
|
| void LabelButton::SetFontList(const gfx::FontList& font_list) {
|
| cached_normal_font_list_ = font_list;
|
| - cached_bold_font_list_ = font_list.DeriveWithStyle(
|
| - font_list.GetFontStyle() | gfx::Font::BOLD);
|
| - label_->SetFontList(is_default_ ?
|
| - cached_bold_font_list_ : cached_normal_font_list_);
|
| + if (PlatformStyle::kDefaultLabelButtonHasBoldFont) {
|
| + cached_bold_font_list_ =
|
| + font_list.DeriveWithStyle(font_list.GetFontStyle() | gfx::Font::BOLD);
|
| + if (is_default_) {
|
| + label_->SetFontList(cached_bold_font_list_);
|
| + return;
|
| + }
|
| + }
|
| + label_->SetFontList(cached_normal_font_list_);
|
| }
|
|
|
| void LabelButton::SetElideBehavior(gfx::ElideBehavior elide_behavior) {
|
| @@ -198,9 +200,10 @@ void LabelButton::SetIsDefault(bool is_default) {
|
| ui::Accelerator accel(ui::VKEY_RETURN, ui::EF_NONE);
|
| is_default_ ? AddAccelerator(accel) : RemoveAccelerator(accel);
|
|
|
| - label_->SetFontList(
|
| - is_default ? cached_bold_font_list_ : cached_normal_font_list_);
|
| + const bool bold = PlatformStyle::kDefaultLabelButtonHasBoldFont && is_default;
|
| + label_->SetFontList(bold ? cached_bold_font_list_ : cached_normal_font_list_);
|
| InvalidateLayout();
|
| + ResetLabelEnabledColor();
|
| }
|
|
|
| void LabelButton::SetStyle(ButtonStyle style) {
|
| @@ -215,7 +218,8 @@ void LabelButton::SetStyle(ButtonStyle style) {
|
| SetFocusPainter(nullptr);
|
| SetHorizontalAlignment(gfx::ALIGN_CENTER);
|
| SetFocusable(true);
|
| - SetMinSize(gfx::Size(70, 33));
|
| + SetMinSize(gfx::Size(PlatformStyle::kMinLabelButtonWidth,
|
| + PlatformStyle::kMinLabelButtonHeight));
|
|
|
| // Themed borders will be set once the button is added to a Widget, since that
|
| // provides the value of GetNativeTheme().
|
| @@ -241,7 +245,7 @@ gfx::Size LabelButton::GetPreferredSize() const {
|
| Label label(GetText(), cached_normal_font_list_);
|
| label.SetShadows(label_->shadows());
|
|
|
| - if (style() == STYLE_BUTTON) {
|
| + if (style_ == STYLE_BUTTON && PlatformStyle::kDefaultLabelButtonHasBoldFont) {
|
| // Some text appears wider when rendered normally than when rendered bold.
|
| // Accommodate the widest, as buttons may show bold and shouldn't resize.
|
| const int current_width = label.GetPreferredSize().width();
|
| @@ -396,6 +400,7 @@ void LabelButton::OnBlur() {
|
| void LabelButton::OnNativeThemeChanged(const ui::NativeTheme* theme) {
|
| ResetColorsFromNativeTheme();
|
| UpdateThemedBorder();
|
| + ResetLabelEnabledColor();
|
| // Invalidate the layout to pickup the new insets from the border.
|
| InvalidateLayout();
|
| }
|
| @@ -440,9 +445,7 @@ gfx::Point LabelButton::GetInkDropCenter() const {
|
| void LabelButton::StateChanged() {
|
| const gfx::Size previous_image_size(image_->GetPreferredSize());
|
| UpdateImage();
|
| - const SkColor color = button_state_colors_[state()];
|
| - if (state() != STATE_DISABLED && label_->enabled_color() != color)
|
| - label_->SetEnabledColor(color);
|
| + ResetLabelEnabledColor();
|
| label_->SetEnabled(state() != STATE_DISABLED);
|
| if (image_->GetPreferredSize() != previous_image_size)
|
| Layout();
|
| @@ -467,38 +470,21 @@ void LabelButton::ResetColorsFromNativeTheme() {
|
| theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonDisabledColor),
|
| };
|
|
|
| - // Certain styles do not change text color when hovered or pressed.
|
| - bool constant_text_color = false;
|
| // Use hardcoded colors for inverted color scheme support and STYLE_BUTTON.
|
| if (color_utils::IsInvertedColorScheme()) {
|
| - constant_text_color = true;
|
| - colors[STATE_NORMAL] = SK_ColorWHITE;
|
| + colors[STATE_NORMAL] = colors[STATE_HOVERED] = colors[STATE_PRESSED] =
|
| + SK_ColorWHITE;
|
| label_->SetBackgroundColor(SK_ColorBLACK);
|
| label_->set_background(Background::CreateSolidBackground(SK_ColorBLACK));
|
| label_->SetAutoColorReadabilityEnabled(true);
|
| label_->SetShadows(gfx::ShadowValues());
|
| } else if (style() == STYLE_BUTTON) {
|
| - // TODO(erg): This is disabled on desktop linux because of the binary asset
|
| - // confusion. These details should either be pushed into ui::NativeThemeWin
|
| - // or should be obsoleted by rendering buttons with paint calls instead of
|
| - // with static assets. http://crbug.com/350498
|
| -#if !(defined(OS_LINUX) && !defined(OS_CHROMEOS))
|
| - constant_text_color = true;
|
| - colors[STATE_NORMAL] = kStyleButtonTextColor;
|
| - label_->SetBackgroundColor(theme->GetSystemColor(
|
| - ui::NativeTheme::kColorId_ButtonBackgroundColor));
|
| - label_->SetAutoColorReadabilityEnabled(false);
|
| - label_->SetShadows(gfx::ShadowValues(
|
| - 1, gfx::ShadowValue(gfx::Vector2d(0, 1), 0, kStyleButtonShadowColor)));
|
| -#endif
|
| - label_->set_background(NULL);
|
| + PlatformStyle::ApplyLabelButtonTextStyle(label_, &colors);
|
| + label_->set_background(nullptr);
|
| } else {
|
| - label_->set_background(NULL);
|
| + label_->set_background(nullptr);
|
| }
|
|
|
| - if (constant_text_color)
|
| - colors[STATE_HOVERED] = colors[STATE_PRESSED] = colors[STATE_NORMAL];
|
| -
|
| for (size_t state = STATE_NORMAL; state < STATE_COUNT; ++state) {
|
| if (!explicitly_set_colors_[state]) {
|
| SetTextColor(static_cast<ButtonState>(state), colors[state]);
|
| @@ -573,4 +559,13 @@ void LabelButton::ResetCachedPreferredSize() {
|
| cached_preferred_size_ = gfx::Size();
|
| }
|
|
|
| +void LabelButton::ResetLabelEnabledColor() {
|
| + const SkColor color =
|
| + explicitly_set_colors_[state()]
|
| + ? button_state_colors_[state()]
|
| + : PlatformStyle::TextColorForButton(button_state_colors_, *this);
|
| + if (state() != STATE_DISABLED && label_->enabled_color() != color)
|
| + label_->SetEnabledColor(color);
|
| +}
|
| +
|
| } // namespace views
|
|
|