| 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 194 |
| 195 void LabelButton::SetIsDefault(bool is_default) { | 195 void LabelButton::SetIsDefault(bool is_default) { |
| 196 DCHECK_EQ(STYLE_BUTTON, style_); | 196 DCHECK_EQ(STYLE_BUTTON, style_); |
| 197 if (is_default == is_default_) | 197 if (is_default == is_default_) |
| 198 return; | 198 return; |
| 199 | 199 |
| 200 is_default_ = is_default; | 200 is_default_ = is_default; |
| 201 ui::Accelerator accel(ui::VKEY_RETURN, ui::EF_NONE); | 201 ui::Accelerator accel(ui::VKEY_RETURN, ui::EF_NONE); |
| 202 is_default_ ? AddAccelerator(accel) : RemoveAccelerator(accel); | 202 is_default_ ? AddAccelerator(accel) : RemoveAccelerator(accel); |
| 203 | 203 |
| 204 const bool bold = PlatformStyle::kDefaultLabelButtonHasBoldFont && is_default; | 204 UpdateStyleForDefaultness(); |
| 205 label_->SetFontList(bold ? cached_bold_font_list_ : cached_normal_font_list_); | |
| 206 InvalidateLayout(); | |
| 207 ResetLabelEnabledColor(); | |
| 208 } | 205 } |
| 209 | 206 |
| 210 void LabelButton::SetStyle(ButtonStyle style) { | 207 void LabelButton::SetStyle(ButtonStyle style) { |
| 211 // All callers currently pass STYLE_BUTTON, and should only call this once, to | 208 // All callers currently pass STYLE_BUTTON, and should only call this once, to |
| 212 // change from the default style. | 209 // change from the default style. |
| 213 DCHECK_EQ(style, STYLE_BUTTON); | 210 DCHECK_EQ(style, STYLE_BUTTON); |
| 214 DCHECK_EQ(style_, STYLE_TEXTBUTTON); | 211 DCHECK_EQ(style_, STYLE_TEXTBUTTON); |
| 215 DCHECK(!GetWidget()) << "Can't change button style after adding to a Widget."; | 212 DCHECK(!GetWidget()) << "Can't change button style after adding to a Widget."; |
| 216 | 213 |
| 217 style_ = style; | 214 style_ = style; |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 } | 483 } |
| 487 | 484 |
| 488 for (size_t state = STATE_NORMAL; state < STATE_COUNT; ++state) { | 485 for (size_t state = STATE_NORMAL; state < STATE_COUNT; ++state) { |
| 489 if (!explicitly_set_colors_[state]) { | 486 if (!explicitly_set_colors_[state]) { |
| 490 SetTextColor(static_cast<ButtonState>(state), colors[state]); | 487 SetTextColor(static_cast<ButtonState>(state), colors[state]); |
| 491 explicitly_set_colors_[state] = false; | 488 explicitly_set_colors_[state] = false; |
| 492 } | 489 } |
| 493 } | 490 } |
| 494 } | 491 } |
| 495 | 492 |
| 493 void LabelButton::UpdateStyleForDefaultness() { |
| 494 const bool bold = |
| 495 PlatformStyle::kDefaultLabelButtonHasBoldFont && is_default_; |
| 496 label_->SetFontList(bold ? cached_bold_font_list_ : cached_normal_font_list_); |
| 497 InvalidateLayout(); |
| 498 ResetLabelEnabledColor(); |
| 499 } |
| 500 |
| 496 void LabelButton::UpdateImage() { | 501 void LabelButton::UpdateImage() { |
| 497 image_->SetImage(GetImage(state())); | 502 image_->SetImage(GetImage(state())); |
| 498 ResetCachedPreferredSize(); | 503 ResetCachedPreferredSize(); |
| 499 } | 504 } |
| 500 | 505 |
| 501 void LabelButton::UpdateThemedBorder() { | 506 void LabelButton::UpdateThemedBorder() { |
| 502 // Don't override borders set by others. | 507 // Don't override borders set by others. |
| 503 if (!border_is_themed_border_) | 508 if (!border_is_themed_border_) |
| 504 return; | 509 return; |
| 505 | 510 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 void LabelButton::ResetLabelEnabledColor() { | 567 void LabelButton::ResetLabelEnabledColor() { |
| 563 const SkColor color = | 568 const SkColor color = |
| 564 explicitly_set_colors_[state()] | 569 explicitly_set_colors_[state()] |
| 565 ? button_state_colors_[state()] | 570 ? button_state_colors_[state()] |
| 566 : PlatformStyle::TextColorForButton(button_state_colors_, *this); | 571 : PlatformStyle::TextColorForButton(button_state_colors_, *this); |
| 567 if (state() != STATE_DISABLED && label_->enabled_color() != color) | 572 if (state() != STATE_DISABLED && label_->enabled_color() != color) |
| 568 label_->SetEnabledColor(color); | 573 label_->SetEnabledColor(color); |
| 569 } | 574 } |
| 570 | 575 |
| 571 } // namespace views | 576 } // namespace views |
| OLD | NEW |