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()), |
tfarina
2013/04/05 12:44:27
you don't pass it through constructor anymore, bec
msw
2013/04/05 15:04:17
yes
| |
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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
305 params->button.indeterminate = false; | 307 params->button.indeterminate = false; |
306 params->button.is_default = is_default_; | 308 params->button.is_default = is_default_; |
307 params->button.is_focused = HasFocus() && IsAccessibilityFocusable(); | 309 params->button.is_focused = HasFocus() && IsAccessibilityFocusable(); |
308 params->button.has_border = style() == STYLE_NATIVE_TEXTBUTTON; | 310 params->button.has_border = style() == STYLE_NATIVE_TEXTBUTTON; |
309 params->button.classic_state = 0; | 311 params->button.classic_state = 0; |
310 params->button.background_color = GetNativeTheme()->GetSystemColor( | 312 params->button.background_color = GetNativeTheme()->GetSystemColor( |
311 ui::NativeTheme::kColorId_TextButtonBackgroundColor); | 313 ui::NativeTheme::kColorId_TextButtonBackgroundColor); |
312 } | 314 } |
313 | 315 |
314 } // namespace views | 316 } // namespace views |
OLD | NEW |