• 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_GESTURE_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_GESTURE_H_
7 
8 #include "base/memory/scoped_ptr.h"
9 #include "base/time/time.h"
10 #include "content/common/content_export.h"
11 #include "content/common/input/synthetic_gesture_params.h"
12 
13 namespace content {
14 
15 class SyntheticGestureTarget;
16 
17 // Base class for synthetic gesture implementations. A synthetic gesture class
18 // is responsible for forwaring InputEvents, simulating the gesture, to a
19 // SyntheticGestureTarget.
20 //
21 // Adding new gesture types involved the following steps:
22 //   1) Create a sub-type of SyntheticGesture that implements the gesture.
23 //   2) Extend SyntheticGesture::Create with the new class.
24 //   3) Add at least one unit test per supported input source type (touch,
25 //      mouse, etc) to SyntheticGestureController unit tests. The unit tests
26 //      only checks basic functionality and termination. If the gesture is
27 //      hooked up to Telemetry its correctness can additionally be tested there.
28 class CONTENT_EXPORT SyntheticGesture {
29  public:
30   SyntheticGesture();
31   virtual ~SyntheticGesture();
32 
33   static scoped_ptr<SyntheticGesture> Create(
34       const SyntheticGestureParams& gesture_params);
35 
36   enum Result {
37     GESTURE_RUNNING,
38     GESTURE_FINISHED,
39     GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED,
40     GESTURE_RESULT_MAX = GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED
41   };
42 
43   // Update the state of the gesture and forward the appropriate events to the
44   // platform. This function is called repeatedly by the synthetic gesture
45   // controller until it stops returning GESTURE_RUNNING.
46   virtual Result ForwardInputEvents(
47       const base::TimeTicks& timestamp, SyntheticGestureTarget* target) = 0;
48 
49  protected:
50   static double ConvertTimestampToSeconds(const base::TimeTicks& timestamp);
51 
52   DISALLOW_COPY_AND_ASSIGN(SyntheticGesture);
53 };
54 
55 }  // namespace content
56 
57 #endif  // CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_GESTURE_H_
58