| 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_touchscreen_pinch_gestur
e.h" | 5 #include "content/browser/renderer_host/input/synthetic_touchscreen_pinch_gestur
e.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 gesture_source_type_ = params_.gesture_source_type; | 33 gesture_source_type_ = params_.gesture_source_type; |
| 34 if (gesture_source_type_ == SyntheticGestureParams::DEFAULT_INPUT) | 34 if (gesture_source_type_ == SyntheticGestureParams::DEFAULT_INPUT) |
| 35 gesture_source_type_ = target->GetDefaultSyntheticGestureSourceType(); | 35 gesture_source_type_ = target->GetDefaultSyntheticGestureSourceType(); |
| 36 | 36 |
| 37 state_ = STARTED; | 37 state_ = STARTED; |
| 38 start_time_ = timestamp; | 38 start_time_ = timestamp; |
| 39 } | 39 } |
| 40 | 40 |
| 41 DCHECK_NE(gesture_source_type_, SyntheticGestureParams::DEFAULT_INPUT); | 41 DCHECK_NE(gesture_source_type_, SyntheticGestureParams::DEFAULT_INPUT); |
| 42 | 42 |
| 43 if (!synthetic_pointer_) | 43 if (!synthetic_pointer_driver_) |
| 44 synthetic_pointer_ = SyntheticPointer::Create(gesture_source_type_); | 44 synthetic_pointer_driver_ = |
| 45 SyntheticPointerDriver::Create(gesture_source_type_); |
| 45 | 46 |
| 46 if (gesture_source_type_ == SyntheticGestureParams::TOUCH_INPUT) { | 47 if (gesture_source_type_ == SyntheticGestureParams::TOUCH_INPUT) { |
| 47 ForwardTouchInputEvents(timestamp, target); | 48 ForwardTouchInputEvents(timestamp, target); |
| 48 } else { | 49 } else { |
| 49 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED; | 50 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED; |
| 50 } | 51 } |
| 51 | 52 |
| 52 return (state_ == DONE) ? SyntheticGesture::GESTURE_FINISHED | 53 return (state_ == DONE) ? SyntheticGesture::GESTURE_FINISHED |
| 53 : SyntheticGesture::GESTURE_RUNNING; | 54 : SyntheticGesture::GESTURE_RUNNING; |
| 54 } | 55 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 79 case SETUP: | 80 case SETUP: |
| 80 NOTREACHED() << "State SETUP invalid for synthetic pinch."; | 81 NOTREACHED() << "State SETUP invalid for synthetic pinch."; |
| 81 case DONE: | 82 case DONE: |
| 82 NOTREACHED() << "State DONE invalid for synthetic pinch."; | 83 NOTREACHED() << "State DONE invalid for synthetic pinch."; |
| 83 } | 84 } |
| 84 } | 85 } |
| 85 | 86 |
| 86 void SyntheticTouchscreenPinchGesture::PressTouchPoints( | 87 void SyntheticTouchscreenPinchGesture::PressTouchPoints( |
| 87 SyntheticGestureTarget* target, | 88 SyntheticGestureTarget* target, |
| 88 const base::TimeTicks& timestamp) { | 89 const base::TimeTicks& timestamp) { |
| 89 synthetic_pointer_->Press(params_.anchor.x(), start_y_0_, target, timestamp); | 90 synthetic_pointer_driver_->Press(params_.anchor.x(), start_y_0_); |
| 90 synthetic_pointer_->Press(params_.anchor.x(), start_y_1_, target, timestamp); | 91 synthetic_pointer_driver_->Press(params_.anchor.x(), start_y_1_); |
| 91 synthetic_pointer_->DispatchEvent(target, timestamp); | 92 synthetic_pointer_driver_->DispatchEvent(target, timestamp); |
| 92 } | 93 } |
| 93 | 94 |
| 94 void SyntheticTouchscreenPinchGesture::MoveTouchPoints( | 95 void SyntheticTouchscreenPinchGesture::MoveTouchPoints( |
| 95 SyntheticGestureTarget* target, | 96 SyntheticGestureTarget* target, |
| 96 float delta, | 97 float delta, |
| 97 const base::TimeTicks& timestamp) { | 98 const base::TimeTicks& timestamp) { |
| 98 // The two pointers move in opposite directions. | 99 // The two pointers move in opposite directions. |
| 99 float current_y_0 = start_y_0_ + delta; | 100 float current_y_0 = start_y_0_ + delta; |
| 100 float current_y_1 = start_y_1_ - delta; | 101 float current_y_1 = start_y_1_ - delta; |
| 101 | 102 |
| 102 synthetic_pointer_->Move(0, params_.anchor.x(), current_y_0, target, | 103 synthetic_pointer_driver_->Move(params_.anchor.x(), current_y_0, 0); |
| 103 timestamp); | 104 synthetic_pointer_driver_->Move(params_.anchor.x(), current_y_1, 1); |
| 104 synthetic_pointer_->Move(1, params_.anchor.x(), current_y_1, target, | 105 synthetic_pointer_driver_->DispatchEvent(target, timestamp); |
| 105 timestamp); | |
| 106 synthetic_pointer_->DispatchEvent(target, timestamp); | |
| 107 } | 106 } |
| 108 | 107 |
| 109 void SyntheticTouchscreenPinchGesture::ReleaseTouchPoints( | 108 void SyntheticTouchscreenPinchGesture::ReleaseTouchPoints( |
| 110 SyntheticGestureTarget* target, | 109 SyntheticGestureTarget* target, |
| 111 const base::TimeTicks& timestamp) { | 110 const base::TimeTicks& timestamp) { |
| 112 synthetic_pointer_->Release(0, target, timestamp); | 111 synthetic_pointer_driver_->Release(0); |
| 113 synthetic_pointer_->Release(1, target, timestamp); | 112 synthetic_pointer_driver_->Release(1); |
| 114 synthetic_pointer_->DispatchEvent(target, timestamp); | 113 synthetic_pointer_driver_->DispatchEvent(target, timestamp); |
| 115 } | 114 } |
| 116 | 115 |
| 117 void SyntheticTouchscreenPinchGesture::SetupCoordinatesAndStopTime( | 116 void SyntheticTouchscreenPinchGesture::SetupCoordinatesAndStopTime( |
| 118 SyntheticGestureTarget* target) { | 117 SyntheticGestureTarget* target) { |
| 119 // To achieve the specified scaling factor, the ratio of the final to the | 118 // To achieve the specified scaling factor, the ratio of the final to the |
| 120 // initial span (distance between the pointers) has to be equal to the scaling | 119 // initial span (distance between the pointers) has to be equal to the scaling |
| 121 // factor. Since we're moving both pointers at the same speed, each pointer's | 120 // factor. Since we're moving both pointers at the same speed, each pointer's |
| 122 // distance to the anchor is half the span. | 121 // distance to the anchor is half the span. |
| 123 float initial_distance_to_anchor, final_distance_to_anchor; | 122 float initial_distance_to_anchor, final_distance_to_anchor; |
| 124 if (params_.scale_factor > 1.0f) { // zooming in | 123 if (params_.scale_factor > 1.0f) { // zooming in |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 const base::TimeTicks& timestamp) const { | 163 const base::TimeTicks& timestamp) const { |
| 165 return std::min(timestamp, stop_time_); | 164 return std::min(timestamp, stop_time_); |
| 166 } | 165 } |
| 167 | 166 |
| 168 bool SyntheticTouchscreenPinchGesture::HasReachedTarget( | 167 bool SyntheticTouchscreenPinchGesture::HasReachedTarget( |
| 169 const base::TimeTicks& timestamp) const { | 168 const base::TimeTicks& timestamp) const { |
| 170 return timestamp >= stop_time_; | 169 return timestamp >= stop_time_; |
| 171 } | 170 } |
| 172 | 171 |
| 173 } // namespace content | 172 } // namespace content |
| OLD | NEW |