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 #ifndef UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ | 5 #ifndef UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ |
6 #define UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ | 6 #define UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ |
7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" |
8 #include "ui/base/animation/animation_delegate.h" | 9 #include "ui/base/animation/animation_delegate.h" |
9 #include "ui/base/events/event_constants.h" | 10 #include "ui/base/events/event_constants.h" |
10 #include "ui/views/controls/button/button.h" | 11 #include "ui/views/controls/button/button.h" |
11 | 12 |
12 namespace ui { | 13 namespace ui { |
13 class ThrobAnimation; | 14 class ThrobAnimation; |
14 } | 15 } |
15 | 16 |
16 namespace views { | 17 namespace views { |
17 | 18 |
| 19 class CustomButtonStateChangedDelegate; |
| 20 |
18 // A button with custom rendering. The common base class of ImageButton and | 21 // A button with custom rendering. The common base class of ImageButton and |
19 // TextButton. | 22 // TextButton. |
20 // Note that this type of button is not focusable by default and will not be | 23 // Note that this type of button is not focusable by default and will not be |
21 // part of the focus chain. Call set_focusable(true) to make it part of the | 24 // part of the focus chain. Call set_focusable(true) to make it part of the |
22 // focus chain. | 25 // focus chain. |
23 class VIEWS_EXPORT CustomButton : public Button, | 26 class VIEWS_EXPORT CustomButton : public Button, |
24 public ui::AnimationDelegate { | 27 public ui::AnimationDelegate { |
25 public: | 28 public: |
26 // The menu button's class name. | 29 // The menu button's class name. |
27 static const char kViewClassName[]; | 30 static const char kViewClassName[]; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 const ui::GestureEvent& event) OVERRIDE; | 94 const ui::GestureEvent& event) OVERRIDE; |
92 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | 95 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
93 virtual void ShowContextMenu(const gfx::Point& p, | 96 virtual void ShowContextMenu(const gfx::Point& p, |
94 bool is_mouse_gesture) OVERRIDE; | 97 bool is_mouse_gesture) OVERRIDE; |
95 virtual void OnDragDone() OVERRIDE; | 98 virtual void OnDragDone() OVERRIDE; |
96 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 99 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
97 | 100 |
98 // Overridden from ui::AnimationDelegate: | 101 // Overridden from ui::AnimationDelegate: |
99 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; | 102 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; |
100 | 103 |
| 104 // Takes ownership of the delegate. |
| 105 void set_state_changed_delegate(CustomButtonStateChangedDelegate* delegate) { |
| 106 state_changed_delegate_.reset(delegate); |
| 107 } |
| 108 |
101 protected: | 109 protected: |
102 // Construct the Button with a Listener. See comment for Button's ctor. | 110 // Construct the Button with a Listener. See comment for Button's ctor. |
103 explicit CustomButton(ButtonListener* listener); | 111 explicit CustomButton(ButtonListener* listener); |
104 | 112 |
105 // Invoked from SetState() when SetState() is passed a value that differs from | 113 // Invoked from SetState() when SetState() is passed a value that differs from |
106 // the current state. CustomButton's implementation of StateChanged() does | 114 // the current state. CustomButton's implementation of StateChanged() does |
107 // nothing; this method is provided for subclasses that wish to do something | 115 // nothing; this method is provided for subclasses that wish to do something |
108 // on state changes. | 116 // on state changes. |
109 virtual void StateChanged(); | 117 virtual void StateChanged(); |
110 | 118 |
(...skipping 24 matching lines...) Expand all Loading... |
135 | 143 |
136 // Is the hover animation running because StartThrob was invoked? | 144 // Is the hover animation running because StartThrob was invoked? |
137 bool is_throbbing_; | 145 bool is_throbbing_; |
138 | 146 |
139 // Mouse event flags which can trigger button actions. | 147 // Mouse event flags which can trigger button actions. |
140 int triggerable_event_flags_; | 148 int triggerable_event_flags_; |
141 | 149 |
142 // See description above setter. | 150 // See description above setter. |
143 bool request_focus_on_press_; | 151 bool request_focus_on_press_; |
144 | 152 |
| 153 scoped_ptr<CustomButtonStateChangedDelegate> state_changed_delegate_; |
| 154 |
145 DISALLOW_COPY_AND_ASSIGN(CustomButton); | 155 DISALLOW_COPY_AND_ASSIGN(CustomButton); |
146 }; | 156 }; |
147 | 157 |
| 158 // Delegate for actions taken on state changes by CustomButton. |
| 159 class VIEWS_EXPORT CustomButtonStateChangedDelegate { |
| 160 public: |
| 161 virtual ~CustomButtonStateChangedDelegate() {} |
| 162 virtual void StateChanged(CustomButton::ButtonState state) = 0; |
| 163 |
| 164 protected: |
| 165 CustomButtonStateChangedDelegate() {} |
| 166 |
| 167 private: |
| 168 DISALLOW_COPY_AND_ASSIGN(CustomButtonStateChangedDelegate); |
| 169 }; |
| 170 |
148 } // namespace views | 171 } // namespace views |
149 | 172 |
150 #endif // UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ | 173 #endif // UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ |
OLD | NEW |