| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/renderer_host/input/synthetic_pinch_gesture_new.h" | |
| 6 | |
| 7 #include "content/common/input/input_event.h" | |
| 8 #include "ui/events/latency_info.h" | |
| 9 | |
| 10 namespace content { | |
| 11 namespace { | |
| 12 | |
| 13 // TODO(dominikg): Use touch slop to compute this value. | |
| 14 const float kMinPointerDistance = 40.0f; | |
| 15 | |
| 16 } | |
| 17 | |
| 18 SyntheticPinchGestureNew::SyntheticPinchGestureNew( | |
| 19 const SyntheticPinchGestureParams& params) | |
| 20 : params_(params), started_(false) { | |
| 21 DCHECK_GE(params_.total_num_pixels_covered, 0); | |
| 22 | |
| 23 float inner_distance_to_anchor = kMinPointerDistance / 2; | |
| 24 float outer_distance_to_anchor = | |
| 25 inner_distance_to_anchor + params_.total_num_pixels_covered / 2; | |
| 26 | |
| 27 // Move pointers away from each other to zoom in | |
| 28 // or towards each other to zoom out. | |
| 29 if (params_.zoom_in) { | |
| 30 current_y_0_ = params_.anchor.y() - inner_distance_to_anchor; | |
| 31 current_y_1_ = params_.anchor.y() + inner_distance_to_anchor; | |
| 32 target_y_0_ = params_.anchor.y() - outer_distance_to_anchor; | |
| 33 target_y_1_ = params_.anchor.y() + outer_distance_to_anchor; | |
| 34 } else { | |
| 35 current_y_0_ = params_.anchor.y() - outer_distance_to_anchor; | |
| 36 current_y_1_ = params_.anchor.y() + outer_distance_to_anchor; | |
| 37 target_y_0_ = params_.anchor.y() - inner_distance_to_anchor; | |
| 38 target_y_1_ = params_.anchor.y() + inner_distance_to_anchor; | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 SyntheticPinchGestureNew::~SyntheticPinchGestureNew() {} | |
| 43 | |
| 44 SyntheticGestureNew::Result SyntheticPinchGestureNew::ForwardInputEvents( | |
| 45 const base::TimeDelta& interval, SyntheticGestureTarget* target) { | |
| 46 | |
| 47 SyntheticGestureParams::GestureSourceType source = | |
| 48 params_.gesture_source_type; | |
| 49 if (source == SyntheticGestureParams::DEFAULT_INPUT) | |
| 50 source = target->GetDefaultSyntheticGestureSourceType(); | |
| 51 | |
| 52 if (!target->SupportsSyntheticGestureSourceType(source)) | |
| 53 return SyntheticGestureNew::GESTURE_SOURCE_TYPE_NOT_SUPPORTED_BY_PLATFORM; | |
| 54 | |
| 55 if (source == SyntheticGestureParams::TOUCH_INPUT) | |
| 56 return ForwardTouchInputEvents(interval, target); | |
| 57 else | |
| 58 return SyntheticGestureNew::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED; | |
| 59 } | |
| 60 | |
| 61 SyntheticGestureNew::Result SyntheticPinchGestureNew::ForwardTouchInputEvents( | |
| 62 const base::TimeDelta& interval, SyntheticGestureTarget* target) { | |
| 63 if (HasFinished()) | |
| 64 return SyntheticGestureNew::GESTURE_FINISHED; | |
| 65 | |
| 66 if (!started_) { | |
| 67 touch_event_.PressPoint(params_.anchor.x(), current_y_0_); | |
| 68 touch_event_.PressPoint(params_.anchor.x(), current_y_1_); | |
| 69 ForwardTouchEvent(target); | |
| 70 started_ = true; | |
| 71 } | |
| 72 | |
| 73 float delta = GetPositionDelta(interval) / 2; | |
| 74 if (params_.zoom_in) { | |
| 75 current_y_0_ -= delta; | |
| 76 current_y_1_ += delta; | |
| 77 } else { | |
| 78 current_y_0_ += delta; | |
| 79 current_y_1_ -= delta; | |
| 80 } | |
| 81 touch_event_.MovePoint(0, params_.anchor.x(), current_y_0_); | |
| 82 touch_event_.MovePoint(1, params_.anchor.x(), current_y_1_); | |
| 83 ForwardTouchEvent(target); | |
| 84 | |
| 85 if (HasFinished()) { | |
| 86 touch_event_.ReleasePoint(0); | |
| 87 touch_event_.ReleasePoint(1); | |
| 88 ForwardTouchEvent(target); | |
| 89 return SyntheticGestureNew::GESTURE_FINISHED; | |
| 90 } | |
| 91 | |
| 92 return SyntheticGestureNew::GESTURE_RUNNING; | |
| 93 } | |
| 94 | |
| 95 void SyntheticPinchGestureNew::ForwardTouchEvent( | |
| 96 SyntheticGestureTarget* target) { | |
| 97 target->DispatchInputEventToPlatform( | |
| 98 InputEvent(touch_event_, ui::LatencyInfo(), false)); | |
| 99 } | |
| 100 | |
| 101 float SyntheticPinchGestureNew::GetPositionDelta( | |
| 102 const base::TimeDelta& interval) { | |
| 103 return params_.relative_pointer_speed_in_pixels_s * interval.InSecondsF(); | |
| 104 } | |
| 105 | |
| 106 bool SyntheticPinchGestureNew::HasFinished() { | |
| 107 return params_.zoom_in ? (current_y_0_ <= target_y_0_) | |
| 108 : (current_y_0_ >= target_y_0_); | |
| 109 } | |
| 110 | |
| 111 } // namespace content | |
| OLD | NEW |