| 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 <algorithm> |
| 9 #include <cmath> | 10 #include <cmath> |
| 10 | 11 |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "ui/events/latency_info.h" | 13 #include "ui/events/latency_info.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| 16 SyntheticTouchscreenPinchGesture::SyntheticTouchscreenPinchGesture( | 17 SyntheticTouchscreenPinchGesture::SyntheticTouchscreenPinchGesture( |
| 17 const SyntheticPinchGestureParams& params) | 18 const SyntheticPinchGestureParams& params) |
| 18 : params_(params), | 19 : params_(params), |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 const base::TimeTicks& timestamp) { | 90 const base::TimeTicks& timestamp) { |
| 90 synthetic_pointer_driver_->Press(params_.anchor.x(), start_y_0_, 0); | 91 synthetic_pointer_driver_->Press(params_.anchor.x(), start_y_0_, 0); |
| 91 synthetic_pointer_driver_->Press(params_.anchor.x(), start_y_1_, 1); | 92 synthetic_pointer_driver_->Press(params_.anchor.x(), start_y_1_, 1); |
| 92 synthetic_pointer_driver_->DispatchEvent(target, timestamp); | 93 synthetic_pointer_driver_->DispatchEvent(target, timestamp); |
| 93 } | 94 } |
| 94 | 95 |
| 95 void SyntheticTouchscreenPinchGesture::MoveTouchPoints( | 96 void SyntheticTouchscreenPinchGesture::MoveTouchPoints( |
| 96 SyntheticGestureTarget* target, | 97 SyntheticGestureTarget* target, |
| 97 float delta, | 98 float delta, |
| 98 const base::TimeTicks& timestamp) { | 99 const base::TimeTicks& timestamp) { |
| 100 gfx::Size view_size = target->GetViewSize(); |
| 99 // The two pointers move in opposite directions. | 101 // The two pointers move in opposite directions. |
| 100 float current_y_0 = start_y_0_ + delta; | 102 float current_y_0 = std::max(start_y_0_ + delta, 0.f); |
| 101 float current_y_1 = start_y_1_ - delta; | 103 float current_y_1 = |
| 104 std::min(start_y_1_ - delta, static_cast<float>(view_size.height() - 1)); |
| 102 | 105 |
| 103 synthetic_pointer_driver_->Move(params_.anchor.x(), current_y_0, 0); | 106 synthetic_pointer_driver_->Move(params_.anchor.x(), current_y_0, 0); |
| 104 synthetic_pointer_driver_->Move(params_.anchor.x(), current_y_1, 1); | 107 synthetic_pointer_driver_->Move(params_.anchor.x(), current_y_1, 1); |
| 105 synthetic_pointer_driver_->DispatchEvent(target, timestamp); | 108 synthetic_pointer_driver_->DispatchEvent(target, timestamp); |
| 106 } | 109 } |
| 107 | 110 |
| 108 void SyntheticTouchscreenPinchGesture::ReleaseTouchPoints( | 111 void SyntheticTouchscreenPinchGesture::ReleaseTouchPoints( |
| 109 SyntheticGestureTarget* target, | 112 SyntheticGestureTarget* target, |
| 110 const base::TimeTicks& timestamp) { | 113 const base::TimeTicks& timestamp) { |
| 111 synthetic_pointer_driver_->Release(0); | 114 synthetic_pointer_driver_->Release(0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 125 final_distance_to_anchor = | 128 final_distance_to_anchor = |
| 126 (initial_distance_to_anchor + target->GetTouchSlopInDips()) * | 129 (initial_distance_to_anchor + target->GetTouchSlopInDips()) * |
| 127 params_.scale_factor; | 130 params_.scale_factor; |
| 128 } else { // zooming out | 131 } else { // zooming out |
| 129 final_distance_to_anchor = target->GetMinScalingSpanInDips() / 2.0f; | 132 final_distance_to_anchor = target->GetMinScalingSpanInDips() / 2.0f; |
| 130 initial_distance_to_anchor = | 133 initial_distance_to_anchor = |
| 131 (final_distance_to_anchor / params_.scale_factor) + | 134 (final_distance_to_anchor / params_.scale_factor) + |
| 132 target->GetTouchSlopInDips(); | 135 target->GetTouchSlopInDips(); |
| 133 } | 136 } |
| 134 | 137 |
| 135 start_y_0_ = params_.anchor.y() - initial_distance_to_anchor; | 138 gfx::Size view_size = target->GetViewSize(); |
| 136 start_y_1_ = params_.anchor.y() + initial_distance_to_anchor; | 139 start_y_0_ = std::max(params_.anchor.y() - initial_distance_to_anchor, 0.f); |
| 140 start_y_1_ = std::min(params_.anchor.y() + initial_distance_to_anchor, |
| 141 static_cast<float>(view_size.height() - 1)); |
| 137 | 142 |
| 138 max_pointer_delta_0_ = initial_distance_to_anchor - final_distance_to_anchor; | 143 max_pointer_delta_0_ = initial_distance_to_anchor - final_distance_to_anchor; |
| 139 | 144 |
| 140 int64_t total_duration_in_us = static_cast<int64_t>( | 145 int64_t total_duration_in_us = static_cast<int64_t>( |
| 141 1e6 * (static_cast<double>(std::abs(2 * max_pointer_delta_0_)) / | 146 1e6 * (static_cast<double>(std::abs(2 * max_pointer_delta_0_)) / |
| 142 params_.relative_pointer_speed_in_pixels_s)); | 147 params_.relative_pointer_speed_in_pixels_s)); |
| 143 DCHECK_GT(total_duration_in_us, 0); | 148 DCHECK_GT(total_duration_in_us, 0); |
| 144 stop_time_ = | 149 stop_time_ = |
| 145 start_time_ + base::TimeDelta::FromMicroseconds(total_duration_in_us); | 150 start_time_ + base::TimeDelta::FromMicroseconds(total_duration_in_us); |
| 146 } | 151 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 163 const base::TimeTicks& timestamp) const { | 168 const base::TimeTicks& timestamp) const { |
| 164 return std::min(timestamp, stop_time_); | 169 return std::min(timestamp, stop_time_); |
| 165 } | 170 } |
| 166 | 171 |
| 167 bool SyntheticTouchscreenPinchGesture::HasReachedTarget( | 172 bool SyntheticTouchscreenPinchGesture::HasReachedTarget( |
| 168 const base::TimeTicks& timestamp) const { | 173 const base::TimeTicks& timestamp) const { |
| 169 return timestamp >= stop_time_; | 174 return timestamp >= stop_time_; |
| 170 } | 175 } |
| 171 | 176 |
| 172 } // namespace content | 177 } // namespace content |
| OLD | NEW |