| 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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 } | 484 } |
| 488 | 485 |
| 489 for (size_t state = STATE_NORMAL; state < STATE_COUNT; ++state) { | 486 for (size_t state = STATE_NORMAL; state < STATE_COUNT; ++state) { |
| 490 if (!explicitly_set_colors_[state]) { | 487 if (!explicitly_set_colors_[state]) { |
| 491 SetTextColor(static_cast<ButtonState>(state), colors[state]); | 488 SetTextColor(static_cast<ButtonState>(state), colors[state]); |
| 492 explicitly_set_colors_[state] = false; | 489 explicitly_set_colors_[state] = false; |
| 493 } | 490 } |
| 494 } | 491 } |
| 495 } | 492 } |
| 496 | 493 |
| 494 void LabelButton::UpdateStyleForDefaultness() { |
| 495 const bool bold = |
| 496 PlatformStyle::kDefaultLabelButtonHasBoldFont && is_default_; |
| 497 label_->SetFontList(bold ? cached_bold_font_list_ : cached_normal_font_list_); |
| 498 InvalidateLayout(); |
| 499 ResetLabelEnabledColor(); |
| 500 } |
| 501 |
| 497 void LabelButton::UpdateImage() { | 502 void LabelButton::UpdateImage() { |
| 498 image_->SetImage(GetImage(state())); | 503 image_->SetImage(GetImage(state())); |
| 499 ResetCachedPreferredSize(); | 504 ResetCachedPreferredSize(); |
| 500 } | 505 } |
| 501 | 506 |
| 502 void LabelButton::UpdateThemedBorder() { | 507 void LabelButton::UpdateThemedBorder() { |
| 503 // Don't override borders set by others. | 508 // Don't override borders set by others. |
| 504 if (!border_is_themed_border_) | 509 if (!border_is_themed_border_) |
| 505 return; | 510 return; |
| 506 | 511 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 void LabelButton::ResetLabelEnabledColor() { | 568 void LabelButton::ResetLabelEnabledColor() { |
| 564 const SkColor color = | 569 const SkColor color = |
| 565 explicitly_set_colors_[state()] | 570 explicitly_set_colors_[state()] |
| 566 ? button_state_colors_[state()] | 571 ? button_state_colors_[state()] |
| 567 : PlatformStyle::TextColorForButton(button_state_colors_, *this); | 572 : PlatformStyle::TextColorForButton(button_state_colors_, *this); |
| 568 if (state() != STATE_DISABLED && label_->enabled_color() != color) | 573 if (state() != STATE_DISABLED && label_->enabled_color() != color) |
| 569 label_->SetEnabledColor(color); | 574 label_->SetEnabledColor(color); |
| 570 } | 575 } |
| 571 | 576 |
| 572 } // namespace views | 577 } // namespace views |
| OLD | NEW |