summaryrefslogtreecommitdiffstats
path: root/content/browser/renderer_host/input/synthetic_gesture.cc
blob: 2e25288dc1359d729aa835a63c965230360865ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/renderer_host/input/synthetic_gesture.h"

#include "base/logging.h"
#include "content/browser/renderer_host/input/synthetic_gesture_target.h"
#include "content/browser/renderer_host/input/synthetic_pinch_gesture.h"
#include "content/browser/renderer_host/input/synthetic_smooth_drag_gesture.h"
#include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h"
#include "content/browser/renderer_host/input/synthetic_tap_gesture.h"

namespace content {
namespace {

template <typename GestureType, typename GestureParamsType>
static scoped_ptr<SyntheticGesture> CreateGesture(
    const SyntheticGestureParams& gesture_params) {
  return scoped_ptr<SyntheticGesture>(
      new GestureType(*GestureParamsType::Cast(&gesture_params)));
}

}  // namespace

SyntheticGesture::SyntheticGesture() {}

SyntheticGesture::~SyntheticGesture() {}

scoped_ptr<SyntheticGesture> SyntheticGesture::Create(
    const SyntheticGestureParams& gesture_params) {
  switch (gesture_params.GetGestureType()) {
    case SyntheticGestureParams::SMOOTH_SCROLL_GESTURE:
      return CreateGesture<SyntheticSmoothScrollGesture,
                           SyntheticSmoothScrollGestureParams>(gesture_params);
    case SyntheticGestureParams::SMOOTH_DRAG_GESTURE:
      return CreateGesture<SyntheticSmoothDragGesture,
                           SyntheticSmoothDragGestureParams>(gesture_params);
    case SyntheticGestureParams::PINCH_GESTURE:
      return CreateGesture<SyntheticPinchGesture,
                           SyntheticPinchGestureParams>(gesture_params);
    case SyntheticGestureParams::TAP_GESTURE:
      return CreateGesture<SyntheticTapGesture,
                           SyntheticTapGestureParams>(gesture_params);
  }
  NOTREACHED() << "Invalid synthetic gesture type";
  return scoped_ptr<SyntheticGesture>();
}

// static
double SyntheticGesture::ConvertTimestampToSeconds(
    const base::TimeTicks& timestamp) {
  return (timestamp - base::TimeTicks()).InSecondsF();
}

}  // namespace content