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/animation/ink_drop_state.h" |
11 #include "ui/views/controls/button/button.h" | 12 #include "ui/views/controls/button/button.h" |
12 | 13 |
13 namespace gfx { | 14 namespace gfx { |
14 class ThrobAnimation; | 15 class ThrobAnimation; |
15 } | 16 } |
16 | 17 |
17 namespace views { | 18 namespace views { |
18 | 19 |
19 class InkDropDelegate; | 20 class InkDropDelegate; |
20 | 21 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 114 |
114 // Returns true if the event is one that can trigger notifying the listener. | 115 // Returns true if the event is one that can trigger notifying the listener. |
115 // This implementation returns true if the left mouse button is down. | 116 // This implementation returns true if the left mouse button is down. |
116 virtual bool IsTriggerableEvent(const ui::Event& event); | 117 virtual bool IsTriggerableEvent(const ui::Event& event); |
117 | 118 |
118 // Returns true if the button should become pressed when the user | 119 // Returns true if the button should become pressed when the user |
119 // holds the mouse down over the button. For this implementation, | 120 // holds the mouse down over the button. For this implementation, |
120 // we simply return IsTriggerableEvent(event). | 121 // we simply return IsTriggerableEvent(event). |
121 virtual bool ShouldEnterPushedState(const ui::Event& event); | 122 virtual bool ShouldEnterPushedState(const ui::Event& event); |
122 | 123 |
| 124 void set_has_ink_drop_action_on_click(bool has_ink_drop_action_on_click) { |
| 125 has_ink_drop_action_on_click_ = has_ink_drop_action_on_click; |
| 126 } |
| 127 |
| 128 void set_ink_drop_action_on_click(InkDropState ink_drop_state) { |
| 129 ink_drop_action_on_click_ = ink_drop_state; |
| 130 } |
| 131 |
123 // Returns true if the button should enter hovered state; that is, if the | 132 // Returns true if the button should enter hovered state; that is, if the |
124 // mouse is over the button, and no other window has capture (which would | 133 // mouse is over the button, and no other window has capture (which would |
125 // prevent the button from receiving MouseExited events and updating its | 134 // prevent the button from receiving MouseExited events and updating its |
126 // state). This does not take into account enabled state. | 135 // state). This does not take into account enabled state. |
127 bool ShouldEnterHoveredState(); | 136 bool ShouldEnterHoveredState(); |
128 | 137 |
129 InkDropDelegate* ink_drop_delegate() const { return ink_drop_delegate_; } | 138 InkDropDelegate* ink_drop_delegate() const { return ink_drop_delegate_; } |
130 void set_ink_drop_delegate(InkDropDelegate* ink_drop_delegate) { | 139 void set_ink_drop_delegate(InkDropDelegate* ink_drop_delegate) { |
131 ink_drop_delegate_ = ink_drop_delegate; | 140 ink_drop_delegate_ = ink_drop_delegate; |
132 } | 141 } |
133 | 142 |
134 // Overridden from View: | 143 // Overridden from View: |
135 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; | 144 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; |
136 void ViewHierarchyChanged( | 145 void ViewHierarchyChanged( |
137 const ViewHierarchyChangedDetails& details) override; | 146 const ViewHierarchyChangedDetails& details) override; |
138 void OnBlur() override; | 147 void OnBlur() override; |
139 | 148 |
| 149 // Overridden from Button: |
| 150 void NotifyClick(const ui::Event& event) override; |
| 151 void OnClickCanceled(const ui::Event& event) override; |
| 152 |
140 // The button state (defined in implementation) | 153 // The button state (defined in implementation) |
141 ButtonState state_; | 154 ButtonState state_; |
142 | 155 |
143 // Hover animation. | 156 // Hover animation. |
144 scoped_ptr<gfx::ThrobAnimation> hover_animation_; | 157 scoped_ptr<gfx::ThrobAnimation> hover_animation_; |
145 | 158 |
146 private: | 159 private: |
147 // Returns true if this is not a top level widget. Virtual for tests. | 160 // Returns true if this is not a top level widget. Virtual for tests. |
148 virtual bool IsChildWidget() const; | 161 virtual bool IsChildWidget() const; |
149 // Returns true if the focus is not in a top level widget. Virtual for tests. | 162 // Returns true if the focus is not in a top level widget. Virtual for tests. |
(...skipping 12 matching lines...) Expand all Loading... |
162 bool request_focus_on_press_; | 175 bool request_focus_on_press_; |
163 | 176 |
164 // Animation delegate for the ink drop ripple effect. It is owned by a | 177 // Animation delegate for the ink drop ripple effect. It is owned by a |
165 // descendant class and needs to be reset before an instance of the concrete | 178 // descendant class and needs to be reset before an instance of the concrete |
166 // CustomButton is destroyed. | 179 // CustomButton is destroyed. |
167 InkDropDelegate* ink_drop_delegate_; | 180 InkDropDelegate* ink_drop_delegate_; |
168 | 181 |
169 // The event on which the button should notify its listener. | 182 // The event on which the button should notify its listener. |
170 NotifyAction notify_action_; | 183 NotifyAction notify_action_; |
171 | 184 |
| 185 // True when a button click should trigger an animation action on |
| 186 // |ink_drop_delegate_|. |
| 187 bool has_ink_drop_action_on_click_; |
| 188 |
| 189 // The animation action to trigger on the |ink_drop_delegate_| when the button |
| 190 // is clicked. |
| 191 InkDropState ink_drop_action_on_click_; |
| 192 |
172 DISALLOW_COPY_AND_ASSIGN(CustomButton); | 193 DISALLOW_COPY_AND_ASSIGN(CustomButton); |
173 }; | 194 }; |
174 | 195 |
175 } // namespace views | 196 } // namespace views |
176 | 197 |
177 #endif // UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ | 198 #endif // UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ |
OLD | NEW |