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.
5 #include "content/browser/renderer_host/input/synthetic_gesture.h"
7 #include "base/logging.h"
8 #include "content/browser/renderer_host/input/synthetic_gesture_target.h"
9 #include "content/browser/renderer_host/input/synthetic_pinch_gesture.h"
10 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h"
11 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h"
16 template <typename GestureType
, typename GestureParamsType
>
17 static scoped_ptr
<SyntheticGesture
> CreateGesture(
18 const SyntheticGestureParams
& gesture_params
) {
19 return scoped_ptr
<SyntheticGesture
>(
20 new GestureType(*GestureParamsType::Cast(&gesture_params
)));
25 SyntheticGesture::SyntheticGesture() {}
27 SyntheticGesture::~SyntheticGesture() {}
29 scoped_ptr
<SyntheticGesture
> SyntheticGesture::Create(
30 const SyntheticGestureParams
& gesture_params
) {
31 switch (gesture_params
.GetGestureType()) {
32 case SyntheticGestureParams::SMOOTH_SCROLL_GESTURE
:
33 return CreateGesture
<SyntheticSmoothScrollGesture
,
34 SyntheticSmoothScrollGestureParams
>(gesture_params
);
35 case SyntheticGestureParams::PINCH_GESTURE
:
36 return CreateGesture
<SyntheticPinchGesture
,
37 SyntheticPinchGestureParams
>(gesture_params
);
38 case SyntheticGestureParams::TAP_GESTURE
:
39 return CreateGesture
<SyntheticTapGesture
,
40 SyntheticTapGestureParams
>(gesture_params
);
42 NOTREACHED() << "Invalid synthetic gesture type";
43 return scoped_ptr
<SyntheticGesture
>();
47 double SyntheticGesture::ConvertTimestampToSeconds(
48 const base::TimeTicks
& timestamp
) {
49 return (timestamp
- base::TimeTicks()).InSecondsF();
52 } // namespace content