| 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_smooth_move_gesture.h" | 5 #include "content/browser/renderer_host/input/synthetic_smooth_move_gesture.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ui/gfx/geometry/point_f.h" | 10 #include "ui/gfx/geometry/point_f.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 double ConvertTimestampToSeconds(const base::TimeTicks& timestamp) { | 32 double ConvertTimestampToSeconds(const base::TimeTicks& timestamp) { |
| 33 return (timestamp - base::TimeTicks()).InSecondsF(); | 33 return (timestamp - base::TimeTicks()).InSecondsF(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 const int kDefaultSpeedInPixelsPerSec = 800; | 36 const int kDefaultSpeedInPixelsPerSec = 800; |
| 37 | 37 |
| 38 } // namespace | 38 } // namespace |
| 39 | 39 |
| 40 SyntheticSmoothMoveGestureParams::SyntheticSmoothMoveGestureParams() | 40 SyntheticSmoothMoveGestureParams::SyntheticSmoothMoveGestureParams() |
| 41 : speed_in_pixels_s(kDefaultSpeedInPixelsPerSec), | 41 : velocity(gfx::Vector2dF(0, 0)), |
| 42 speed_in_pixels_s(kDefaultSpeedInPixelsPerSec), |
| 42 prevent_fling(true), | 43 prevent_fling(true), |
| 43 add_slop(true) {} | 44 add_slop(true) {} |
| 44 | 45 |
| 45 SyntheticSmoothMoveGestureParams::SyntheticSmoothMoveGestureParams( | 46 SyntheticSmoothMoveGestureParams::SyntheticSmoothMoveGestureParams( |
| 46 const SyntheticSmoothMoveGestureParams& other) = default; | 47 const SyntheticSmoothMoveGestureParams& other) = default; |
| 47 | 48 |
| 48 SyntheticSmoothMoveGestureParams::~SyntheticSmoothMoveGestureParams() {} | 49 SyntheticSmoothMoveGestureParams::~SyntheticSmoothMoveGestureParams() {} |
| 49 | 50 |
| 50 SyntheticSmoothMoveGesture::SyntheticSmoothMoveGesture( | 51 SyntheticSmoothMoveGesture::SyntheticSmoothMoveGesture( |
| 51 SyntheticSmoothMoveGestureParams params) | 52 SyntheticSmoothMoveGestureParams params) |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 gfx::Vector2d delta_discrete = | 171 gfx::Vector2d delta_discrete = |
| 171 FloorTowardZero(current_move_segment_total_delta - | 172 FloorTowardZero(current_move_segment_total_delta - |
| 172 current_move_segment_total_delta_discrete_); | 173 current_move_segment_total_delta_discrete_); |
| 173 ForwardMouseWheelEvent(target, delta_discrete, event_timestamp); | 174 ForwardMouseWheelEvent(target, delta_discrete, event_timestamp); |
| 174 current_move_segment_total_delta_discrete_ += delta_discrete; | 175 current_move_segment_total_delta_discrete_ += delta_discrete; |
| 175 | 176 |
| 176 if (FinishedCurrentMoveSegment(event_timestamp)) { | 177 if (FinishedCurrentMoveSegment(event_timestamp)) { |
| 177 if (!IsLastMoveSegment()) { | 178 if (!IsLastMoveSegment()) { |
| 178 current_move_segment_total_delta_discrete_ = gfx::Vector2d(); | 179 current_move_segment_total_delta_discrete_ = gfx::Vector2d(); |
| 179 ComputeNextMoveSegment(); | 180 ComputeNextMoveSegment(); |
| 180 ForwardMouseWheelInputEvents(timestamp, target); | 181 } else if (params_.prevent_fling) { |
| 182 state_ = DONE; |
| 181 } else { | 183 } else { |
| 182 state_ = DONE; | 184 state_ = STOPPING; |
| 183 } | 185 } |
| 184 } | 186 } |
| 185 } break; | 187 } break; |
| 188 case STOPPING: { |
| 189 gfx::Vector2d velocity_discrete = FloorTowardZero(params_.velocity); |
| 190 ForwardTouchpadFlingEvent(target, velocity_discrete, timestamp); |
| 191 state_ = DONE; |
| 192 } break; |
| 186 case SETUP: | 193 case SETUP: |
| 187 NOTREACHED() << "State SETUP invalid for synthetic scroll using mouse " | 194 NOTREACHED() << "State SETUP invalid for synthetic scroll using mouse " |
| 188 "wheel input."; | 195 "wheel input."; |
| 189 case STOPPING: | |
| 190 NOTREACHED() << "State STOPPING invalid for synthetic scroll using mouse " | |
| 191 "wheel input."; | |
| 192 case DONE: | 196 case DONE: |
| 193 NOTREACHED() | 197 NOTREACHED() |
| 194 << "State DONE invalid for synthetic scroll using mouse wheel input."; | 198 << "State DONE invalid for synthetic scroll using mouse wheel input."; |
| 195 } | 199 } |
| 196 } | 200 } |
| 197 | 201 |
| 198 void SyntheticSmoothMoveGesture::ForwardMouseClickInputEvents( | 202 void SyntheticSmoothMoveGesture::ForwardMouseClickInputEvents( |
| 199 const base::TimeTicks& timestamp, | 203 const base::TimeTicks& timestamp, |
| 200 SyntheticGestureTarget* target) { | 204 SyntheticGestureTarget* target) { |
| 201 base::TimeTicks event_timestamp = timestamp; | 205 base::TimeTicks event_timestamp = timestamp; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 false); | 250 false); |
| 247 | 251 |
| 248 mouse_wheel_event.x = current_move_segment_start_position_.x(); | 252 mouse_wheel_event.x = current_move_segment_start_position_.x(); |
| 249 mouse_wheel_event.y = current_move_segment_start_position_.y(); | 253 mouse_wheel_event.y = current_move_segment_start_position_.y(); |
| 250 | 254 |
| 251 mouse_wheel_event.setTimeStampSeconds(ConvertTimestampToSeconds(timestamp)); | 255 mouse_wheel_event.setTimeStampSeconds(ConvertTimestampToSeconds(timestamp)); |
| 252 | 256 |
| 253 target->DispatchInputEventToPlatform(mouse_wheel_event); | 257 target->DispatchInputEventToPlatform(mouse_wheel_event); |
| 254 } | 258 } |
| 255 | 259 |
| 260 void SyntheticSmoothMoveGesture::ForwardTouchpadFlingEvent( |
| 261 SyntheticGestureTarget* target, |
| 262 const gfx::Vector2dF& velocity, |
| 263 const base::TimeTicks& timestamp) const { |
| 264 blink::WebGestureEvent fling_event = |
| 265 SyntheticWebGestureEventBuilder::BuildFling( |
| 266 velocity.x(), velocity.y(), |
| 267 blink::WebGestureDevice::WebGestureDeviceTouchpad); |
| 268 |
| 269 fling_event.x = current_move_segment_start_position_.x(); |
| 270 fling_event.y = current_move_segment_start_position_.y(); |
| 271 |
| 272 fling_event.setTimeStampSeconds(ConvertTimestampToSeconds(timestamp)); |
| 273 |
| 274 target->DispatchInputEventToPlatform(fling_event); |
| 275 } |
| 276 |
| 256 void SyntheticSmoothMoveGesture::PressPoint(SyntheticGestureTarget* target, | 277 void SyntheticSmoothMoveGesture::PressPoint(SyntheticGestureTarget* target, |
| 257 const base::TimeTicks& timestamp) { | 278 const base::TimeTicks& timestamp) { |
| 258 DCHECK_EQ(current_move_segment_, 0); | 279 DCHECK_EQ(current_move_segment_, 0); |
| 259 synthetic_pointer_driver_->Press(current_move_segment_start_position_.x(), | 280 synthetic_pointer_driver_->Press(current_move_segment_start_position_.x(), |
| 260 current_move_segment_start_position_.y()); | 281 current_move_segment_start_position_.y()); |
| 261 synthetic_pointer_driver_->DispatchEvent(target, timestamp); | 282 synthetic_pointer_driver_->DispatchEvent(target, timestamp); |
| 262 } | 283 } |
| 263 | 284 |
| 264 void SyntheticSmoothMoveGesture::MovePoint(SyntheticGestureTarget* target, | 285 void SyntheticSmoothMoveGesture::MovePoint(SyntheticGestureTarget* target, |
| 265 const gfx::Vector2dF& delta, | 286 const gfx::Vector2dF& delta, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 DCHECK_LT(current_move_segment_, static_cast<int>(params_.distances.size())); | 357 DCHECK_LT(current_move_segment_, static_cast<int>(params_.distances.size())); |
| 337 return current_move_segment_ == | 358 return current_move_segment_ == |
| 338 static_cast<int>(params_.distances.size()) - 1; | 359 static_cast<int>(params_.distances.size()) - 1; |
| 339 } | 360 } |
| 340 | 361 |
| 341 bool SyntheticSmoothMoveGesture::MoveIsNoOp() const { | 362 bool SyntheticSmoothMoveGesture::MoveIsNoOp() const { |
| 342 return params_.distances.size() == 0 || params_.distances[0].IsZero(); | 363 return params_.distances.size() == 0 || params_.distances[0].IsZero(); |
| 343 } | 364 } |
| 344 | 365 |
| 345 } // namespace content | 366 } // namespace content |
| OLD | NEW |