• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_gesture.h"
6 
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"
12 
13 namespace content {
14 namespace {
15 
16 template <typename GestureType, typename GestureParamsType>
CreateGesture(const SyntheticGestureParams & gesture_params)17 static scoped_ptr<SyntheticGesture> CreateGesture(
18     const SyntheticGestureParams& gesture_params) {
19   return scoped_ptr<SyntheticGesture>(
20       new GestureType(*GestureParamsType::Cast(&gesture_params)));
21 }
22 
23 }  // namespace
24 
SyntheticGesture()25 SyntheticGesture::SyntheticGesture() {}
26 
~SyntheticGesture()27 SyntheticGesture::~SyntheticGesture() {}
28 
Create(const SyntheticGestureParams & gesture_params)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);
41   }
42   NOTREACHED() << "Invalid synthetic gesture type";
43   return scoped_ptr<SyntheticGesture>();
44 }
45 
46 // static
ConvertTimestampToSeconds(const base::TimeTicks & timestamp)47 double SyntheticGesture::ConvertTimestampToSeconds(
48     const base::TimeTicks& timestamp) {
49   return (timestamp - base::TimeTicks()).InSecondsF();
50 }
51 
52 }  // namespace content
53