| 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/accessibility/ax_view_state.h" | 7 #include "ui/accessibility/ax_view_state.h" |
| 8 #include "ui/events/event.h" | 8 #include "ui/events/event.h" |
| 9 #include "ui/events/keycodes/keyboard_codes.h" | 9 #include "ui/events/keycodes/keyboard_codes.h" |
| 10 #include "ui/gfx/animation/throb_animation.h" | 10 #include "ui/gfx/animation/throb_animation.h" |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 return true; | 221 return true; |
| 222 } | 222 } |
| 223 | 223 |
| 224 void CustomButton::OnGestureEvent(ui::GestureEvent* event) { | 224 void CustomButton::OnGestureEvent(ui::GestureEvent* event) { |
| 225 if (state_ == STATE_DISABLED) { | 225 if (state_ == STATE_DISABLED) { |
| 226 Button::OnGestureEvent(event); | 226 Button::OnGestureEvent(event); |
| 227 return; | 227 return; |
| 228 } | 228 } |
| 229 | 229 |
| 230 if (event->type() == ui::ET_GESTURE_TAP && IsTriggerableEvent(*event)) { | 230 if (event->type() == ui::ET_GESTURE_TAP && IsTriggerableEvent(*event)) { |
| 231 // Set the button state to hot and start the animation fully faded in. The | 231 // In order to provide visual feedback that the user has tapped on |
| 232 // GESTURE_END event issued immediately after will set the state to | 232 // the button, show the hover state fully faded in immediately after |
| 233 // STATE_NORMAL beginning the fade out animation. See | 233 // a tap. Setting the state back to normal begins the fade-out animation. |
| 234 // http://crbug.com/131184. | |
| 235 SetState(STATE_HOVERED); | 234 SetState(STATE_HOVERED); |
| 236 hover_animation_->Reset(1.0); | 235 hover_animation_->Reset(1.0); |
| 237 NotifyClick(*event); | 236 NotifyClick(*event); |
| 238 event->StopPropagation(); | 237 event->StopPropagation(); |
| 238 SetState(STATE_NORMAL); |
| 239 } else if (event->type() == ui::ET_GESTURE_TAP_DOWN && | 239 } else if (event->type() == ui::ET_GESTURE_TAP_DOWN && |
| 240 ShouldEnterPushedState(*event)) { | 240 ShouldEnterPushedState(*event)) { |
| 241 SetState(STATE_PRESSED); | 241 SetState(STATE_PRESSED); |
| 242 if (request_focus_on_press_) | 242 if (request_focus_on_press_) |
| 243 RequestFocus(); | 243 RequestFocus(); |
| 244 event->StopPropagation(); | 244 event->StopPropagation(); |
| 245 } else if (event->type() == ui::ET_GESTURE_TAP_CANCEL || | 245 } else if (event->type() == ui::ET_GESTURE_TAP_CANCEL) { |
| 246 event->type() == ui::ET_GESTURE_END) { | |
| 247 SetState(STATE_NORMAL); | 246 SetState(STATE_NORMAL); |
| 248 } | 247 } |
| 249 if (!event->handled()) | 248 if (!event->handled()) |
| 250 Button::OnGestureEvent(event); | 249 Button::OnGestureEvent(event); |
| 251 } | 250 } |
| 252 | 251 |
| 253 bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) { | 252 bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) { |
| 254 SetState(STATE_NORMAL); | 253 SetState(STATE_NORMAL); |
| 255 /* | 254 /* |
| 256 ui::KeyEvent key_event(ui::ET_KEY_RELEASED, accelerator.key_code(), | 255 ui::KeyEvent key_event(ui::ET_KEY_RELEASED, accelerator.key_code(), |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 if (!details.is_add && state_ != STATE_DISABLED) | 349 if (!details.is_add && state_ != STATE_DISABLED) |
| 351 SetState(STATE_NORMAL); | 350 SetState(STATE_NORMAL); |
| 352 } | 351 } |
| 353 | 352 |
| 354 void CustomButton::OnBlur() { | 353 void CustomButton::OnBlur() { |
| 355 if (IsHotTracked()) | 354 if (IsHotTracked()) |
| 356 SetState(STATE_NORMAL); | 355 SetState(STATE_NORMAL); |
| 357 } | 356 } |
| 358 | 357 |
| 359 } // namespace views | 358 } // namespace views |
| OLD | NEW |