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 |
123 // Returns true if the button should enter hovered state; that is, if the | 128 // 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 | 129 // mouse is over the button, and no other window has capture (which would |
125 // prevent the button from receiving MouseExited events and updating its | 130 // prevent the button from receiving MouseExited events and updating its |
126 // state). This does not take into account enabled state. | 131 // state). This does not take into account enabled state. |
127 bool ShouldEnterHoveredState(); | 132 bool ShouldEnterHoveredState(); |
128 | 133 |
129 InkDropDelegate* ink_drop_delegate() const { return ink_drop_delegate_; } | 134 InkDropDelegate* ink_drop_delegate() const { return ink_drop_delegate_; } |
130 void set_ink_drop_delegate(InkDropDelegate* ink_drop_delegate) { | 135 void set_ink_drop_delegate(InkDropDelegate* ink_drop_delegate) { |
131 ink_drop_delegate_ = ink_drop_delegate; | 136 ink_drop_delegate_ = ink_drop_delegate; |
132 } | 137 } |
133 | 138 |
134 // Overridden from View: | 139 // Overridden from View: |
135 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; | 140 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; |
136 void ViewHierarchyChanged( | 141 void ViewHierarchyChanged( |
137 const ViewHierarchyChangedDetails& details) override; | 142 const ViewHierarchyChangedDetails& details) override; |
138 void OnBlur() override; | 143 void OnBlur() override; |
139 | 144 |
| 145 // Overridden from Button: |
| 146 void NotifyClick(const ui::Event& event) override; |
| 147 void OnClickCanceled(const ui::Event& event) override; |
| 148 |
140 // The button state (defined in implementation) | 149 // The button state (defined in implementation) |
141 ButtonState state_; | 150 ButtonState state_; |
142 | 151 |
143 // Hover animation. | 152 // Hover animation. |
144 scoped_ptr<gfx::ThrobAnimation> hover_animation_; | 153 scoped_ptr<gfx::ThrobAnimation> hover_animation_; |
145 | 154 |
146 private: | 155 private: |
147 // Returns true if this is not a top level widget. Virtual for tests. | 156 // Returns true if this is not a top level widget. Virtual for tests. |
148 virtual bool IsChildWidget() const; | 157 virtual bool IsChildWidget() const; |
149 // Returns true if the focus is not in a top level widget. Virtual for tests. | 158 // 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_; | 171 bool request_focus_on_press_; |
163 | 172 |
164 // Animation delegate for the ink drop ripple effect. It is owned by a | 173 // 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 | 174 // descendant class and needs to be reset before an instance of the concrete |
166 // CustomButton is destroyed. | 175 // CustomButton is destroyed. |
167 InkDropDelegate* ink_drop_delegate_; | 176 InkDropDelegate* ink_drop_delegate_; |
168 | 177 |
169 // The event on which the button should notify its listener. | 178 // The event on which the button should notify its listener. |
170 NotifyAction notify_action_; | 179 NotifyAction notify_action_; |
171 | 180 |
| 181 // True when a button click should trigger an animation action on |
| 182 // |ink_drop_delegate_|. |
| 183 // TODO(bruthig): Use an InkDropAction enum and drop the flag. |
| 184 bool has_ink_drop_action_on_click_; |
| 185 |
| 186 // The animation action to trigger on the |ink_drop_delegate_| when the button |
| 187 // is clicked. |
| 188 InkDropState ink_drop_action_on_click_; |
| 189 |
172 DISALLOW_COPY_AND_ASSIGN(CustomButton); | 190 DISALLOW_COPY_AND_ASSIGN(CustomButton); |
173 }; | 191 }; |
174 | 192 |
175 } // namespace views | 193 } // namespace views |
176 | 194 |
177 #endif // UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ | 195 #endif // UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ |
OLD | NEW |