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 "base/memory/scoped_ptr.h" |
9 #include "ui/events/event_constants.h" | 9 #include "ui/events/event_constants.h" |
10 #include "ui/gfx/animation/animation_delegate.h" | 10 #include "ui/gfx/animation/animation_delegate.h" |
11 #include "ui/views/controls/button/button.h" | 11 #include "ui/views/controls/button/button.h" |
12 | 12 |
13 namespace gfx { | 13 namespace gfx { |
14 class ThrobAnimation; | 14 class ThrobAnimation; |
15 } | 15 } |
16 | 16 |
17 namespace views { | 17 namespace views { |
18 | 18 |
| 19 class InkDropDelegate; |
| 20 |
19 // A button with custom rendering. The base of ImageButton and LabelButton. | 21 // A button with custom rendering. The base of ImageButton and LabelButton. |
20 // Note that this type of button is not focusable by default and will not be | 22 // Note that this type of button is not focusable by default and will not be |
21 // part of the focus chain. Call SetFocusable(true) to make it part of the | 23 // part of the focus chain. Call SetFocusable(true) to make it part of the |
22 // focus chain. | 24 // focus chain. |
23 class VIEWS_EXPORT CustomButton : public Button, | 25 class VIEWS_EXPORT CustomButton : public Button, |
24 public gfx::AnimationDelegate { | 26 public gfx::AnimationDelegate { |
25 public: | 27 public: |
26 // An enum describing the events on which a button should notify its listener. | 28 // An enum describing the events on which a button should notify its listener. |
27 enum NotifyAction { | 29 enum NotifyAction { |
28 NOTIFY_ON_PRESS, | 30 NOTIFY_ON_PRESS, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // holds the mouse down over the button. For this implementation, | 118 // holds the mouse down over the button. For this implementation, |
117 // we simply return IsTriggerableEvent(event). | 119 // we simply return IsTriggerableEvent(event). |
118 virtual bool ShouldEnterPushedState(const ui::Event& event); | 120 virtual bool ShouldEnterPushedState(const ui::Event& event); |
119 | 121 |
120 // Returns true if the button should enter hovered state; that is, if the | 122 // Returns true if the button should enter hovered state; that is, if the |
121 // mouse is over the button, and no other window has capture (which would | 123 // mouse is over the button, and no other window has capture (which would |
122 // prevent the button from receiving MouseExited events and updating its | 124 // prevent the button from receiving MouseExited events and updating its |
123 // state). This does not take into account enabled state. | 125 // state). This does not take into account enabled state. |
124 bool ShouldEnterHoveredState(); | 126 bool ShouldEnterHoveredState(); |
125 | 127 |
| 128 void set_ink_drop_delegate(InkDropDelegate* ink_drop_delegate); |
| 129 InkDropDelegate* ink_drop_delegate() const { |
| 130 return ink_drop_delegate_.get(); |
| 131 } |
| 132 |
126 // Overridden from View: | 133 // Overridden from View: |
| 134 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; |
127 void ViewHierarchyChanged( | 135 void ViewHierarchyChanged( |
128 const ViewHierarchyChangedDetails& details) override; | 136 const ViewHierarchyChangedDetails& details) override; |
129 void OnBlur() override; | 137 void OnBlur() override; |
130 | 138 |
131 // The button state (defined in implementation) | 139 // The button state (defined in implementation) |
132 ButtonState state_; | 140 ButtonState state_; |
133 | 141 |
134 // Hover animation. | 142 // Hover animation. |
135 scoped_ptr<gfx::ThrobAnimation> hover_animation_; | 143 scoped_ptr<gfx::ThrobAnimation> hover_animation_; |
136 | 144 |
137 private: | 145 private: |
138 // Returns true if this is not a top level widget. Virtual for tests. | 146 // Returns true if this is not a top level widget. Virtual for tests. |
139 virtual bool IsChildWidget() const; | 147 virtual bool IsChildWidget() const; |
140 // Returns true if the focus is not in a top level widget. Virtual for tests. | 148 // Returns true if the focus is not in a top level widget. Virtual for tests. |
141 virtual bool FocusInChildWidget() const; | 149 virtual bool FocusInChildWidget() const; |
142 | 150 |
143 // Should we animate when the state changes? Defaults to true. | 151 // Should we animate when the state changes? Defaults to true. |
144 bool animate_on_state_change_; | 152 bool animate_on_state_change_; |
145 | 153 |
146 // Is the hover animation running because StartThrob was invoked? | 154 // Is the hover animation running because StartThrob was invoked? |
147 bool is_throbbing_; | 155 bool is_throbbing_; |
148 | 156 |
149 // Mouse event flags which can trigger button actions. | 157 // Mouse event flags which can trigger button actions. |
150 int triggerable_event_flags_; | 158 int triggerable_event_flags_; |
151 | 159 |
152 // See description above setter. | 160 // See description above setter. |
153 bool request_focus_on_press_; | 161 bool request_focus_on_press_; |
154 | 162 |
| 163 // Animation delegate for the ink drop ripple effect. |
| 164 scoped_ptr<InkDropDelegate> ink_drop_delegate_; |
| 165 |
155 // The event on which the button should notify its listener. | 166 // The event on which the button should notify its listener. |
156 NotifyAction notify_action_; | 167 NotifyAction notify_action_; |
157 | 168 |
158 DISALLOW_COPY_AND_ASSIGN(CustomButton); | 169 DISALLOW_COPY_AND_ASSIGN(CustomButton); |
159 }; | 170 }; |
160 | 171 |
161 } // namespace views | 172 } // namespace views |
162 | 173 |
163 #endif // UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ | 174 #endif // UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ |
OLD | NEW |