| 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_gesture.h" | 5 #include "content/browser/renderer_host/input/synthetic_gesture.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" | 8 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" |
| 9 #include "content/browser/renderer_host/input/synthetic_pinch_gesture.h" | 9 #include "content/browser/renderer_host/input/synthetic_pinch_gesture.h" |
| 10 #include "content/browser/renderer_host/input/synthetic_smooth_drag_gesture.h" |
| 10 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h" | 11 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h" |
| 11 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h" | 12 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h" |
| 12 | 13 |
| 13 namespace content { | 14 namespace content { |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 template <typename GestureType, typename GestureParamsType> | 17 template <typename GestureType, typename GestureParamsType> |
| 17 static scoped_ptr<SyntheticGesture> CreateGesture( | 18 static scoped_ptr<SyntheticGesture> CreateGesture( |
| 18 const SyntheticGestureParams& gesture_params) { | 19 const SyntheticGestureParams& gesture_params) { |
| 19 return scoped_ptr<SyntheticGesture>( | 20 return scoped_ptr<SyntheticGesture>( |
| 20 new GestureType(*GestureParamsType::Cast(&gesture_params))); | 21 new GestureType(*GestureParamsType::Cast(&gesture_params))); |
| 21 } | 22 } |
| 22 | 23 |
| 23 } // namespace | 24 } // namespace |
| 24 | 25 |
| 25 SyntheticGesture::SyntheticGesture() {} | 26 SyntheticGesture::SyntheticGesture() {} |
| 26 | 27 |
| 27 SyntheticGesture::~SyntheticGesture() {} | 28 SyntheticGesture::~SyntheticGesture() {} |
| 28 | 29 |
| 29 scoped_ptr<SyntheticGesture> SyntheticGesture::Create( | 30 scoped_ptr<SyntheticGesture> SyntheticGesture::Create( |
| 30 const SyntheticGestureParams& gesture_params) { | 31 const SyntheticGestureParams& gesture_params) { |
| 31 switch (gesture_params.GetGestureType()) { | 32 switch (gesture_params.GetGestureType()) { |
| 32 case SyntheticGestureParams::SMOOTH_SCROLL_GESTURE: | 33 case SyntheticGestureParams::SMOOTH_SCROLL_GESTURE: |
| 33 return CreateGesture<SyntheticSmoothScrollGesture, | 34 return CreateGesture<SyntheticSmoothScrollGesture, |
| 34 SyntheticSmoothScrollGestureParams>(gesture_params); | 35 SyntheticSmoothScrollGestureParams>(gesture_params); |
| 36 case SyntheticGestureParams::SMOOTH_DRAG_GESTURE: |
| 37 return CreateGesture<SyntheticSmoothDragGesture, |
| 38 SyntheticSmoothDragGestureParams>(gesture_params); |
| 35 case SyntheticGestureParams::PINCH_GESTURE: | 39 case SyntheticGestureParams::PINCH_GESTURE: |
| 36 return CreateGesture<SyntheticPinchGesture, | 40 return CreateGesture<SyntheticPinchGesture, |
| 37 SyntheticPinchGestureParams>(gesture_params); | 41 SyntheticPinchGestureParams>(gesture_params); |
| 38 case SyntheticGestureParams::TAP_GESTURE: | 42 case SyntheticGestureParams::TAP_GESTURE: |
| 39 return CreateGesture<SyntheticTapGesture, | 43 return CreateGesture<SyntheticTapGesture, |
| 40 SyntheticTapGestureParams>(gesture_params); | 44 SyntheticTapGestureParams>(gesture_params); |
| 41 } | 45 } |
| 42 NOTREACHED() << "Invalid synthetic gesture type"; | 46 NOTREACHED() << "Invalid synthetic gesture type"; |
| 43 return scoped_ptr<SyntheticGesture>(); | 47 return scoped_ptr<SyntheticGesture>(); |
| 44 } | 48 } |
| 45 | 49 |
| 46 // static | 50 // static |
| 47 double SyntheticGesture::ConvertTimestampToSeconds( | 51 double SyntheticGesture::ConvertTimestampToSeconds( |
| 48 const base::TimeTicks& timestamp) { | 52 const base::TimeTicks& timestamp) { |
| 49 return (timestamp - base::TimeTicks()).InSecondsF(); | 53 return (timestamp - base::TimeTicks()).InSecondsF(); |
| 50 } | 54 } |
| 51 | 55 |
| 52 } // namespace content | 56 } // namespace content |
| OLD | NEW |