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/custom_button.h" | 5 #include "ui/views/controls/button/custom_button.h" |
6 | 6 |
7 #include "ui/base/accessibility/accessible_view_state.h" | 7 #include "ui/base/accessibility/accessible_view_state.h" |
8 #include "ui/events/event.h" | 8 #include "ui/events/event.h" |
9 #include "ui/events/keycodes/keyboard_codes.h" | 9 #include "ui/events/keycodes/keyboard_codes.h" |
10 #include "ui/gfx/animation/throb_animation.h" | 10 #include "ui/gfx/animation/throb_animation.h" |
11 #include "ui/gfx/screen.h" | 11 #include "ui/gfx/screen.h" |
| 12 #include "ui/views/controls/button/blue_button.h" |
| 13 #include "ui/views/controls/button/checkbox.h" |
| 14 #include "ui/views/controls/button/image_button.h" |
| 15 #include "ui/views/controls/button/label_button.h" |
| 16 #include "ui/views/controls/button/menu_button.h" |
| 17 #include "ui/views/controls/button/radio_button.h" |
| 18 #include "ui/views/controls/button/text_button.h" |
12 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
13 | 20 |
14 namespace views { | 21 namespace views { |
15 | 22 |
16 // How long the hover animation takes if uninterrupted. | 23 // How long the hover animation takes if uninterrupted. |
17 static const int kHoverFadeDurationMs = 150; | 24 static const int kHoverFadeDurationMs = 150; |
18 | 25 |
19 // static | 26 // static |
20 const char CustomButton::kViewClassName[] = "CustomButton"; | 27 const char CustomButton::kViewClassName[] = "CustomButton"; |
21 | 28 |
22 //////////////////////////////////////////////////////////////////////////////// | 29 //////////////////////////////////////////////////////////////////////////////// |
23 // CustomButton, public: | 30 // CustomButton, public: |
24 | 31 |
| 32 // static |
| 33 const CustomButton* CustomButton::AsCustomButton(const views::View* view) { |
| 34 return AsCustomButton(const_cast<views::View*>(view)); |
| 35 } |
| 36 |
| 37 CustomButton* CustomButton::AsCustomButton(views::View* view) { |
| 38 if (view) { |
| 39 const char* classname = view->GetClassName(); |
| 40 if (!strcmp(classname, Checkbox::kViewClassName) || |
| 41 !strcmp(classname, CustomButton::kViewClassName) || |
| 42 !strcmp(classname, ImageButton::kViewClassName) || |
| 43 !strcmp(classname, LabelButton::kViewClassName) || |
| 44 !strcmp(classname, RadioButton::kViewClassName) || |
| 45 !strcmp(classname, MenuButton::kViewClassName) || |
| 46 !strcmp(classname, TextButton::kViewClassName)) { |
| 47 return static_cast<CustomButton*>(view); |
| 48 } |
| 49 } |
| 50 return NULL; |
| 51 } |
| 52 |
25 CustomButton::~CustomButton() { | 53 CustomButton::~CustomButton() { |
26 } | 54 } |
27 | 55 |
28 void CustomButton::SetState(ButtonState state) { | 56 void CustomButton::SetState(ButtonState state) { |
29 if (state == state_) | 57 if (state == state_) |
30 return; | 58 return; |
31 | 59 |
32 if (animate_on_state_change_ && | 60 if (animate_on_state_change_ && |
33 (!is_throbbing_ || !hover_animation_->is_animating())) { | 61 (!is_throbbing_ || !hover_animation_->is_animating())) { |
34 is_throbbing_ = false; | 62 is_throbbing_ = false; |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 if (!details.is_add && state_ != STATE_DISABLED) | 347 if (!details.is_add && state_ != STATE_DISABLED) |
320 SetState(STATE_NORMAL); | 348 SetState(STATE_NORMAL); |
321 } | 349 } |
322 | 350 |
323 void CustomButton::OnBlur() { | 351 void CustomButton::OnBlur() { |
324 if (IsHotTracked()) | 352 if (IsHotTracked()) |
325 SetState(STATE_NORMAL); | 353 SetState(STATE_NORMAL); |
326 } | 354 } |
327 | 355 |
328 } // namespace views | 356 } // namespace views |
OLD | NEW |