| 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/events/event.h" | 9 #include "ui/base/events/event.h" |
| 10 #include "ui/base/keycodes/keyboard_codes.h" | 10 #include "ui/base/keycodes/keyboard_codes.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 SetState(STATE_NORMAL); | 200 SetState(STATE_NORMAL); |
| 201 // TODO(beng): remove once NotifyClick takes ui::Event. | 201 // TODO(beng): remove once NotifyClick takes ui::Event. |
| 202 ui::MouseEvent synthetic_event(ui::ET_MOUSE_RELEASED, | 202 ui::MouseEvent synthetic_event(ui::ET_MOUSE_RELEASED, |
| 203 gfx::Point(), | 203 gfx::Point(), |
| 204 gfx::Point(), | 204 gfx::Point(), |
| 205 ui::EF_LEFT_MOUSE_BUTTON); | 205 ui::EF_LEFT_MOUSE_BUTTON); |
| 206 NotifyClick(synthetic_event); | 206 NotifyClick(synthetic_event); |
| 207 return true; | 207 return true; |
| 208 } | 208 } |
| 209 | 209 |
| 210 ui::EventResult CustomButton::OnGestureEvent(ui::GestureEvent* event) { | 210 void CustomButton::OnGestureEvent(ui::GestureEvent* event) { |
| 211 if (state_ == STATE_DISABLED) | 211 if (state_ == STATE_DISABLED) { |
| 212 return Button::OnGestureEvent(event); | 212 Button::OnGestureEvent(event); |
| 213 return; |
| 214 } |
| 213 | 215 |
| 214 if (event->type() == ui::ET_GESTURE_TAP && IsTriggerableEvent(*event)) { | 216 if (event->type() == ui::ET_GESTURE_TAP && IsTriggerableEvent(*event)) { |
| 215 // Set the button state to hot and start the animation fully faded in. The | 217 // Set the button state to hot and start the animation fully faded in. The |
| 216 // TAP_UP event issued immediately after will set the state to STATE_NORMAL | 218 // TAP_UP event issued immediately after will set the state to STATE_NORMAL |
| 217 // beginning the fade out animation. See http://crbug.com/131184. | 219 // beginning the fade out animation. See http://crbug.com/131184. |
| 218 SetState(STATE_HOVERED); | 220 SetState(STATE_HOVERED); |
| 219 hover_animation_->Reset(1.0); | 221 hover_animation_->Reset(1.0); |
| 220 NotifyClick(*event); | 222 NotifyClick(*event); |
| 221 return ui::ER_CONSUMED; | 223 event->StopPropagation(); |
| 222 } else if (event->type() == ui::ET_GESTURE_TAP_DOWN && | 224 } else if (event->type() == ui::ET_GESTURE_TAP_DOWN && |
| 223 ShouldEnterPushedState(*event)) { | 225 ShouldEnterPushedState(*event)) { |
| 224 SetState(STATE_PRESSED); | 226 SetState(STATE_PRESSED); |
| 225 if (request_focus_on_press_) | 227 if (request_focus_on_press_) |
| 226 RequestFocus(); | 228 RequestFocus(); |
| 227 return ui::ER_CONSUMED; | 229 event->StopPropagation(); |
| 228 } else { | 230 } else { |
| 229 SetState(STATE_NORMAL); | 231 SetState(STATE_NORMAL); |
| 230 } | 232 } |
| 231 return Button::OnGestureEvent(event); | 233 if (!event->handled()) |
| 234 Button::OnGestureEvent(event); |
| 232 } | 235 } |
| 233 | 236 |
| 234 bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) { | 237 bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) { |
| 235 SetState(STATE_NORMAL); | 238 SetState(STATE_NORMAL); |
| 236 /* | 239 /* |
| 237 ui::KeyEvent key_event(ui::ET_KEY_RELEASED, accelerator.key_code(), | 240 ui::KeyEvent key_event(ui::ET_KEY_RELEASED, accelerator.key_code(), |
| 238 accelerator.modifiers()); | 241 accelerator.modifiers()); |
| 239 */ | 242 */ |
| 240 // TODO(beng): remove once NotifyClick takes ui::Event. | 243 // TODO(beng): remove once NotifyClick takes ui::Event. |
| 241 ui::MouseEvent synthetic_event(ui::ET_MOUSE_RELEASED, | 244 ui::MouseEvent synthetic_event(ui::ET_MOUSE_RELEASED, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 if (!is_add && state_ != STATE_DISABLED) | 327 if (!is_add && state_ != STATE_DISABLED) |
| 325 SetState(STATE_NORMAL); | 328 SetState(STATE_NORMAL); |
| 326 } | 329 } |
| 327 | 330 |
| 328 void CustomButton::OnBlur() { | 331 void CustomButton::OnBlur() { |
| 329 if (IsHotTracked()) | 332 if (IsHotTracked()) |
| 330 SetState(STATE_NORMAL); | 333 SetState(STATE_NORMAL); |
| 331 } | 334 } |
| 332 | 335 |
| 333 } // namespace views | 336 } // namespace views |
| OLD | NEW |