Chromium Code Reviews| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
| 9 #include "ui/base/animation/throb_animation.h" | 9 #include "ui/base/animation/throb_animation.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 } // namespace | 28 } // namespace |
| 29 | 29 |
| 30 namespace views { | 30 namespace views { |
| 31 | 31 |
| 32 // static | 32 // static |
| 33 const char LabelButton::kViewClassName[] = "views/LabelButton"; | 33 const char LabelButton::kViewClassName[] = "views/LabelButton"; |
| 34 | 34 |
| 35 LabelButton::LabelButton(ButtonListener* listener, const string16& text) | 35 LabelButton::LabelButton(ButtonListener* listener, const string16& text) |
| 36 : CustomButton(listener), | 36 : CustomButton(listener), |
| 37 image_(new ImageView()), | 37 image_(new ImageView()), |
| 38 label_(new Label(text)), | 38 label_(new Label()), |
| 39 button_state_images_(), | 39 button_state_images_(), |
| 40 button_state_colors_(), | 40 button_state_colors_(), |
| 41 explicitly_set_colors_(), | 41 explicitly_set_colors_(), |
| 42 is_default_(false), | 42 is_default_(false), |
| 43 style_(STYLE_TEXTBUTTON) { | 43 style_(STYLE_TEXTBUTTON) { |
| 44 SetAnimationDuration(kHoverAnimationDurationMs); | 44 SetAnimationDuration(kHoverAnimationDurationMs); |
| 45 SetText(text); | |
| 45 | 46 |
| 46 AddChildView(image_); | 47 AddChildView(image_); |
| 47 image_->set_interactive(false); | 48 image_->set_interactive(false); |
| 48 | 49 |
| 49 AddChildView(label_); | 50 AddChildView(label_); |
| 50 label_->SetAutoColorReadabilityEnabled(false); | 51 label_->SetAutoColorReadabilityEnabled(false); |
| 51 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 52 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 52 | 53 |
| 53 // Initialize the colors, border, and layout. | 54 // Initialize the colors, border, and layout. |
| 54 SetStyle(style_); | 55 SetStyle(style_); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 65 void LabelButton::SetImage(ButtonState for_state, const gfx::ImageSkia& image) { | 66 void LabelButton::SetImage(ButtonState for_state, const gfx::ImageSkia& image) { |
| 66 button_state_images_[for_state] = image; | 67 button_state_images_[for_state] = image; |
| 67 image_->SetImage(GetImage(state())); | 68 image_->SetImage(GetImage(state())); |
| 68 } | 69 } |
| 69 | 70 |
| 70 const string16& LabelButton::GetText() const { | 71 const string16& LabelButton::GetText() const { |
| 71 return label_->text(); | 72 return label_->text(); |
| 72 } | 73 } |
| 73 | 74 |
| 74 void LabelButton::SetText(const string16& text) { | 75 void LabelButton::SetText(const string16& text) { |
| 76 SetAccessibleName(text); | |
| 75 label_->SetText(text); | 77 label_->SetText(text); |
| 76 } | 78 } |
| 77 | 79 |
| 78 void LabelButton::SetTextColor(ButtonState for_state, SkColor color) { | 80 void LabelButton::SetTextColor(ButtonState for_state, SkColor color) { |
| 79 button_state_colors_[for_state] = color; | 81 button_state_colors_[for_state] = color; |
| 80 if (for_state == STATE_DISABLED) | 82 if (for_state == STATE_DISABLED) |
| 81 label_->SetDisabledColor(color); | 83 label_->SetDisabledColor(color); |
| 82 else if (for_state == state()) | 84 else if (for_state == state()) |
| 83 label_->SetEnabledColor(color); | 85 label_->SetEnabledColor(color); |
| 84 explicitly_set_colors_[for_state] = true; | 86 explicitly_set_colors_[for_state] = true; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 } | 120 } |
| 119 | 121 |
| 120 void LabelButton::SetStyle(ButtonStyle style) { | 122 void LabelButton::SetStyle(ButtonStyle style) { |
| 121 style_ = style; | 123 style_ = style; |
| 122 set_border(new LabelButtonBorder(style)); | 124 set_border(new LabelButtonBorder(style)); |
| 123 // Inset the button focus rect from the actual border; roughly match Windows. | 125 // Inset the button focus rect from the actual border; roughly match Windows. |
| 124 if (style == STYLE_TEXTBUTTON || style == STYLE_NATIVE_TEXTBUTTON) | 126 if (style == STYLE_TEXTBUTTON || style == STYLE_NATIVE_TEXTBUTTON) |
| 125 set_focus_border(FocusBorder::CreateDashedFocusBorder(3, 3, 3, 3)); | 127 set_focus_border(FocusBorder::CreateDashedFocusBorder(3, 3, 3, 3)); |
| 126 if (style == STYLE_BUTTON || style_ == STYLE_NATIVE_TEXTBUTTON) | 128 if (style == STYLE_BUTTON || style_ == STYLE_NATIVE_TEXTBUTTON) |
| 127 label_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 129 label_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 130 if (style == STYLE_NATIVE_TEXTBUTTON) | |
|
msw
2013/04/05 01:06:18
This CL depends on this change from:
https://coder
| |
| 131 set_focusable(true); | |
| 128 if (style == STYLE_BUTTON) { | 132 if (style == STYLE_BUTTON) { |
| 129 set_min_size(gfx::Size(70, 31)); | 133 set_min_size(gfx::Size(70, 31)); |
| 130 const SkColor color = GetNativeTheme()->GetSystemColor( | 134 const SkColor color = GetNativeTheme()->GetSystemColor( |
| 131 ui::NativeTheme::kColorId_WindowBackground); | 135 ui::NativeTheme::kColorId_WindowBackground); |
| 132 label_->SetShadowColors(color, color); | 136 label_->SetShadowColors(color, color); |
| 133 label_->SetShadowOffset(0, 1); | 137 label_->SetShadowOffset(0, 1); |
| 134 } | 138 } |
| 135 // Invalidate the layout to pickup the new insets from the border. | 139 // Invalidate the layout to pickup the new insets from the border. |
| 136 InvalidateLayout(); | 140 InvalidateLayout(); |
| 137 ResetColorsFromNativeTheme(); | 141 ResetColorsFromNativeTheme(); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 params->button.indeterminate = false; | 309 params->button.indeterminate = false; |
| 306 params->button.is_default = is_default_; | 310 params->button.is_default = is_default_; |
| 307 params->button.is_focused = HasFocus() && IsAccessibilityFocusable(); | 311 params->button.is_focused = HasFocus() && IsAccessibilityFocusable(); |
| 308 params->button.has_border = style() == STYLE_NATIVE_TEXTBUTTON; | 312 params->button.has_border = style() == STYLE_NATIVE_TEXTBUTTON; |
| 309 params->button.classic_state = 0; | 313 params->button.classic_state = 0; |
| 310 params->button.background_color = GetNativeTheme()->GetSystemColor( | 314 params->button.background_color = GetNativeTheme()->GetSystemColor( |
| 311 ui::NativeTheme::kColorId_TextButtonBackgroundColor); | 315 ui::NativeTheme::kColorId_TextButtonBackgroundColor); |
| 312 } | 316 } |
| 313 | 317 |
| 314 } // namespace views | 318 } // namespace views |
| OLD | NEW |