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/base/animation/throb_animation.h" | 8 #include "ui/base/animation/throb_animation.h" |
9 #include "ui/base/keycodes/keyboard_codes.h" | 9 #include "ui/base/keycodes/keyboard_codes.h" |
10 #include "ui/gfx/screen.h" | 10 #include "ui/gfx/screen.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 190 |
191 SetState(BS_NORMAL); | 191 SetState(BS_NORMAL); |
192 NotifyClick(event); | 192 NotifyClick(event); |
193 return true; | 193 return true; |
194 } | 194 } |
195 | 195 |
196 ui::GestureStatus CustomButton::OnGestureEvent(const GestureEvent& event) { | 196 ui::GestureStatus CustomButton::OnGestureEvent(const GestureEvent& event) { |
197 if (state_ == BS_DISABLED) | 197 if (state_ == BS_DISABLED) |
198 return ui::GESTURE_STATUS_UNKNOWN; | 198 return ui::GESTURE_STATUS_UNKNOWN; |
199 | 199 |
200 if (event.type() == ui::ET_GESTURE_TAP) { | 200 if (event.type() == ui::ET_GESTURE_TAP && IsTriggerableEvent(event)) { |
201 // Set the button state to hot and start the animation fully faded in. The | 201 // Set the button state to hot and start the animation fully faded in. The |
202 // TAP_UP event issued immediately after will set the state to BS_NORMAL | 202 // TAP_UP event issued immediately after will set the state to BS_NORMAL |
203 // beginning the fade out animation. See http://crbug.com/131184. | 203 // beginning the fade out animation. See http://crbug.com/131184. |
204 SetState(BS_HOT); | 204 SetState(BS_HOT); |
205 hover_animation_->Reset(1.0); | 205 hover_animation_->Reset(1.0); |
206 NotifyClick(event); | 206 NotifyClick(event); |
207 return ui::GESTURE_STATUS_CONSUMED; | 207 return ui::GESTURE_STATUS_CONSUMED; |
208 } else if (event.type() == ui::ET_GESTURE_TAP_DOWN) { | 208 } else if (event.type() == ui::ET_GESTURE_TAP_DOWN && |
| 209 ShouldEnterPushedState(event)) { |
209 SetState(BS_PUSHED); | 210 SetState(BS_PUSHED); |
210 if (request_focus_on_press_) | 211 if (request_focus_on_press_) |
211 RequestFocus(); | 212 RequestFocus(); |
212 return ui::GESTURE_STATUS_CONSUMED; | 213 return ui::GESTURE_STATUS_CONSUMED; |
213 } else { | 214 } else { |
214 SetState(BS_NORMAL); | 215 SetState(BS_NORMAL); |
215 } | 216 } |
216 return Button::OnGestureEvent(event); | 217 return Button::OnGestureEvent(event); |
217 } | 218 } |
218 | 219 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 is_throbbing_(false), | 276 is_throbbing_(false), |
276 triggerable_event_flags_(ui::EF_LEFT_MOUSE_BUTTON), | 277 triggerable_event_flags_(ui::EF_LEFT_MOUSE_BUTTON), |
277 request_focus_on_press_(true) { | 278 request_focus_on_press_(true) { |
278 hover_animation_.reset(new ui::ThrobAnimation(this)); | 279 hover_animation_.reset(new ui::ThrobAnimation(this)); |
279 hover_animation_->SetSlideDuration(kHoverFadeDurationMs); | 280 hover_animation_->SetSlideDuration(kHoverFadeDurationMs); |
280 } | 281 } |
281 | 282 |
282 void CustomButton::StateChanged() { | 283 void CustomButton::StateChanged() { |
283 } | 284 } |
284 | 285 |
285 bool CustomButton::IsTriggerableEvent(const MouseEvent& event) { | 286 bool CustomButton::IsTriggerableEvent(const Event& event) { |
286 return (triggerable_event_flags_ & event.flags()) != 0; | 287 return event.type() == ui::ET_GESTURE_TAP_DOWN || |
| 288 event.type() == ui::ET_GESTURE_TAP || |
| 289 (event.IsMouseEvent() && |
| 290 (triggerable_event_flags_ & event.flags()) != 0); |
287 } | 291 } |
288 | 292 |
289 bool CustomButton::ShouldEnterPushedState(const MouseEvent& event) { | 293 bool CustomButton::ShouldEnterPushedState(const Event& event) { |
290 return IsTriggerableEvent(event); | 294 return IsTriggerableEvent(event); |
291 } | 295 } |
292 | 296 |
293 //////////////////////////////////////////////////////////////////////////////// | 297 //////////////////////////////////////////////////////////////////////////////// |
294 // CustomButton, View overrides (protected): | 298 // CustomButton, View overrides (protected): |
295 | 299 |
296 void CustomButton::ViewHierarchyChanged(bool is_add, View *parent, | 300 void CustomButton::ViewHierarchyChanged(bool is_add, View *parent, |
297 View *child) { | 301 View *child) { |
298 if (!is_add && state_ != BS_DISABLED) | 302 if (!is_add && state_ != BS_DISABLED) |
299 SetState(BS_NORMAL); | 303 SetState(BS_NORMAL); |
300 } | 304 } |
301 | 305 |
302 void CustomButton::OnBlur() { | 306 void CustomButton::OnBlur() { |
303 if (IsHotTracked()) | 307 if (IsHotTracked()) |
304 SetState(BS_NORMAL); | 308 SetState(BS_NORMAL); |
305 } | 309 } |
306 | 310 |
307 } // namespace views | 311 } // namespace views |
OLD | NEW |