| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/renderer_host/input/synthetic_tap_gesture.h" | 5 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 8 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 9 #include "ui/events/latency_info.h" | 9 #include "ui/events/latency_info.h" |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 if (state_ == SETUP) { | 25 if (state_ == SETUP) { |
| 26 gesture_source_type_ = params_.gesture_source_type; | 26 gesture_source_type_ = params_.gesture_source_type; |
| 27 if (gesture_source_type_ == SyntheticGestureParams::DEFAULT_INPUT) | 27 if (gesture_source_type_ == SyntheticGestureParams::DEFAULT_INPUT) |
| 28 gesture_source_type_ = target->GetDefaultSyntheticGestureSourceType(); | 28 gesture_source_type_ = target->GetDefaultSyntheticGestureSourceType(); |
| 29 | 29 |
| 30 state_ = PRESS; | 30 state_ = PRESS; |
| 31 } | 31 } |
| 32 | 32 |
| 33 DCHECK_NE(gesture_source_type_, SyntheticGestureParams::DEFAULT_INPUT); | 33 DCHECK_NE(gesture_source_type_, SyntheticGestureParams::DEFAULT_INPUT); |
| 34 | 34 |
| 35 if (!synthetic_pointer_) | 35 if (!synthetic_pointer_driver_) |
| 36 synthetic_pointer_ = SyntheticPointer::Create(gesture_source_type_); | 36 synthetic_pointer_driver_ = |
| 37 SyntheticPointerDriver::Create(gesture_source_type_); |
| 37 | 38 |
| 38 if (gesture_source_type_ == SyntheticGestureParams::TOUCH_INPUT || | 39 if (gesture_source_type_ == SyntheticGestureParams::TOUCH_INPUT || |
| 39 gesture_source_type_ == SyntheticGestureParams::MOUSE_INPUT) | 40 gesture_source_type_ == SyntheticGestureParams::MOUSE_INPUT) |
| 40 ForwardTouchOrMouseInputEvents(timestamp, target); | 41 ForwardTouchOrMouseInputEvents(timestamp, target); |
| 41 else | 42 else |
| 42 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED; | 43 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED; |
| 43 | 44 |
| 44 return (state_ == DONE) ? SyntheticGesture::GESTURE_FINISHED | 45 return (state_ == DONE) ? SyntheticGesture::GESTURE_FINISHED |
| 45 : SyntheticGesture::GESTURE_RUNNING; | 46 : SyntheticGesture::GESTURE_RUNNING; |
| 46 } | 47 } |
| 47 | 48 |
| 48 void SyntheticTapGesture::ForwardTouchOrMouseInputEvents( | 49 void SyntheticTapGesture::ForwardTouchOrMouseInputEvents( |
| 49 const base::TimeTicks& timestamp, SyntheticGestureTarget* target) { | 50 const base::TimeTicks& timestamp, SyntheticGestureTarget* target) { |
| 50 switch (state_) { | 51 switch (state_) { |
| 51 case PRESS: | 52 case PRESS: |
| 52 synthetic_pointer_->Press(params_.position.x(), params_.position.y(), | 53 synthetic_pointer_driver_->Press(params_.position.x(), |
| 53 target, timestamp); | 54 params_.position.y()); |
| 54 synthetic_pointer_->DispatchEvent(target, timestamp); | 55 synthetic_pointer_driver_->DispatchEvent(target, timestamp); |
| 55 // Release immediately if duration is 0. | 56 // Release immediately if duration is 0. |
| 56 if (params_.duration_ms == 0) { | 57 if (params_.duration_ms == 0) { |
| 57 synthetic_pointer_->Release(0, target, timestamp); | 58 synthetic_pointer_driver_->Release(); |
| 58 synthetic_pointer_->DispatchEvent(target, timestamp); | 59 synthetic_pointer_driver_->DispatchEvent(target, timestamp); |
| 59 state_ = DONE; | 60 state_ = DONE; |
| 60 } else { | 61 } else { |
| 61 start_time_ = timestamp; | 62 start_time_ = timestamp; |
| 62 state_ = WAITING_TO_RELEASE; | 63 state_ = WAITING_TO_RELEASE; |
| 63 } | 64 } |
| 64 break; | 65 break; |
| 65 case WAITING_TO_RELEASE: | 66 case WAITING_TO_RELEASE: |
| 66 if (timestamp - start_time_ >= GetDuration()) { | 67 if (timestamp - start_time_ >= GetDuration()) { |
| 67 synthetic_pointer_->Release(0, target, start_time_ + GetDuration()); | 68 synthetic_pointer_driver_->Release(); |
| 68 synthetic_pointer_->DispatchEvent(target, start_time_ + GetDuration()); | 69 synthetic_pointer_driver_->DispatchEvent(target, |
| 70 start_time_ + GetDuration()); |
| 69 state_ = DONE; | 71 state_ = DONE; |
| 70 } | 72 } |
| 71 break; | 73 break; |
| 72 case SETUP: | 74 case SETUP: |
| 73 NOTREACHED() << "State SETUP invalid for synthetic tap gesture."; | 75 NOTREACHED() << "State SETUP invalid for synthetic tap gesture."; |
| 74 case DONE: | 76 case DONE: |
| 75 NOTREACHED() << "State DONE invalid for synthetic tap gesture."; | 77 NOTREACHED() << "State DONE invalid for synthetic tap gesture."; |
| 76 } | 78 } |
| 77 } | 79 } |
| 78 | 80 |
| 79 base::TimeDelta SyntheticTapGesture::GetDuration() const { | 81 base::TimeDelta SyntheticTapGesture::GetDuration() const { |
| 80 return base::TimeDelta::FromMilliseconds(params_.duration_ms); | 82 return base::TimeDelta::FromMilliseconds(params_.duration_ms); |
| 81 } | 83 } |
| 82 | 84 |
| 83 } // namespace content | 85 } // namespace content |
| OLD | NEW |