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 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_GESTURE_CONTROLLER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_GESTURE_CONTROLLER_H_
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h"
14 #include "base/time/time.h"
15 #include "content/browser/renderer_host/input/synthetic_gesture.h"
16 #include "content/common/content_export.h"
17 #include "content/common/input/synthetic_gesture_params.h"
21 class SyntheticGestureTarget
;
23 // Controls a synthetic gesture.
24 // Repeatedly invokes the gesture object's ForwardInputEvent method to send
25 // input events to the platform until the gesture has finished.
26 class CONTENT_EXPORT SyntheticGestureController
{
28 explicit SyntheticGestureController(
29 scoped_ptr
<SyntheticGestureTarget
> gesture_target
);
30 virtual ~SyntheticGestureController();
32 typedef base::Callback
<void(SyntheticGesture::Result
)>
33 OnGestureCompleteCallback
;
34 void QueueSyntheticGesture(
35 scoped_ptr
<SyntheticGesture
> synthetic_gesture
,
36 const OnGestureCompleteCallback
& completion_callback
);
38 // Forward input events of the currently processed gesture.
39 void Flush(base::TimeTicks timestamp
);
41 // To be called when all events generated from the current gesture have been
42 // fully flushed from the input pipeline (i.e., sent, processed and ack'ed).
43 void OnDidFlushInput();
46 void StartGesture(const SyntheticGesture
& gesture
);
47 void StopGesture(const SyntheticGesture
& gesture
,
48 const OnGestureCompleteCallback
& completion_callback
,
49 SyntheticGesture::Result result
);
51 scoped_ptr
<SyntheticGestureTarget
> gesture_target_
;
52 scoped_ptr
<SyntheticGesture::Result
> pending_gesture_result_
;
54 // A queue of gesture/callback pairs. Implemented as two queues to
55 // simplify the ownership of SyntheticGesture pointers.
56 class GestureAndCallbackQueue
{
58 GestureAndCallbackQueue();
59 ~GestureAndCallbackQueue();
60 void Push(scoped_ptr
<SyntheticGesture
> gesture
,
61 const OnGestureCompleteCallback
& callback
) {
62 gestures_
.push_back(gesture
.release());
63 callbacks_
.push(callback
);
66 gestures_
.erase(gestures_
.begin());
69 SyntheticGesture
* FrontGesture() {
70 return gestures_
.front();
72 OnGestureCompleteCallback
& FrontCallback() {
73 return callbacks_
.front();
76 CHECK(gestures_
.empty() == callbacks_
.empty());
77 return gestures_
.empty();
80 ScopedVector
<SyntheticGesture
> gestures_
;
81 std::queue
<OnGestureCompleteCallback
> callbacks_
;
82 } pending_gesture_queue_
;
84 DISALLOW_COPY_AND_ASSIGN(SyntheticGestureController
);
87 } // namespace content
89 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_GESTURE_CONTROLLER_H_