OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_GESTURE_CONTROLLER_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_GESTURE_CONTROLLER_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_GESTURE_CONTROLLER_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_GESTURE_CONTROLLER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <queue> | 9 #include <queue> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "content/browser/renderer_host/input/synthetic_gesture.h" | 17 #include "content/browser/renderer_host/input/synthetic_gesture.h" |
17 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
18 #include "content/common/input/synthetic_gesture_params.h" | 19 #include "content/common/input/synthetic_gesture_params.h" |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 | 22 |
22 class SyntheticGestureTarget; | 23 class SyntheticGestureTarget; |
23 | 24 |
24 // Controls a synthetic gesture. | 25 // Controls a synthetic gesture. |
25 // Repeatedly invokes the gesture object's ForwardInputEvent method to send | 26 // Repeatedly invokes the gesture object's ForwardInputEvent method to send |
26 // input events to the platform until the gesture has finished. | 27 // input events to the platform until the gesture has finished. |
27 class CONTENT_EXPORT SyntheticGestureController { | 28 class CONTENT_EXPORT SyntheticGestureController { |
28 public: | 29 public: |
29 explicit SyntheticGestureController( | 30 using BeginFrameCallback = base::OnceClosure; |
30 std::unique_ptr<SyntheticGestureTarget> gesture_target); | 31 using BeginFrameRequestCallback = |
| 32 base::RepeatingCallback<void(BeginFrameCallback)>; |
| 33 SyntheticGestureController( |
| 34 std::unique_ptr<SyntheticGestureTarget> gesture_target, |
| 35 BeginFrameRequestCallback begin_frame_callback); |
31 virtual ~SyntheticGestureController(); | 36 virtual ~SyntheticGestureController(); |
32 | 37 |
33 typedef base::Callback<void(SyntheticGesture::Result)> | 38 typedef base::Callback<void(SyntheticGesture::Result)> |
34 OnGestureCompleteCallback; | 39 OnGestureCompleteCallback; |
35 void QueueSyntheticGesture( | 40 void QueueSyntheticGesture( |
36 std::unique_ptr<SyntheticGesture> synthetic_gesture, | 41 std::unique_ptr<SyntheticGesture> synthetic_gesture, |
37 const OnGestureCompleteCallback& completion_callback); | 42 const OnGestureCompleteCallback& completion_callback); |
38 | 43 |
39 // Forward input events of the currently processed gesture. | 44 bool DispatchNextEvent(base::TimeTicks = base::TimeTicks::Now()); |
40 void Flush(base::TimeTicks timestamp); | |
41 | |
42 // To be called when all events generated from the current gesture have been | |
43 // fully flushed from the input pipeline (i.e., sent, processed and ack'ed). | |
44 void OnDidFlushInput(); | |
45 | 45 |
46 private: | 46 private: |
| 47 void OnBeginFrame(); |
| 48 |
47 void StartGesture(const SyntheticGesture& gesture); | 49 void StartGesture(const SyntheticGesture& gesture); |
48 void StopGesture(const SyntheticGesture& gesture, | 50 void StopGesture(const SyntheticGesture& gesture, |
49 const OnGestureCompleteCallback& completion_callback, | 51 const OnGestureCompleteCallback& completion_callback, |
50 SyntheticGesture::Result result); | 52 SyntheticGesture::Result result); |
51 | 53 |
52 std::unique_ptr<SyntheticGestureTarget> gesture_target_; | 54 std::unique_ptr<SyntheticGestureTarget> gesture_target_; |
53 std::unique_ptr<SyntheticGesture::Result> pending_gesture_result_; | |
54 | 55 |
55 // A queue of gesture/callback pairs. Implemented as two queues to | 56 // A queue of gesture/callback pairs. Implemented as two queues to |
56 // simplify the ownership of SyntheticGesture pointers. | 57 // simplify the ownership of SyntheticGesture pointers. |
57 class GestureAndCallbackQueue { | 58 class GestureAndCallbackQueue { |
58 public: | 59 public: |
59 GestureAndCallbackQueue(); | 60 GestureAndCallbackQueue(); |
60 ~GestureAndCallbackQueue(); | 61 ~GestureAndCallbackQueue(); |
61 void Push(std::unique_ptr<SyntheticGesture> gesture, | 62 void Push(std::unique_ptr<SyntheticGesture> gesture, |
62 const OnGestureCompleteCallback& callback) { | 63 const OnGestureCompleteCallback& callback) { |
63 gestures_.push_back(std::move(gesture)); | 64 gestures_.push_back(std::move(gesture)); |
(...skipping 11 matching lines...) Expand all Loading... |
75 CHECK(gestures_.empty() == callbacks_.empty()); | 76 CHECK(gestures_.empty() == callbacks_.empty()); |
76 return gestures_.empty(); | 77 return gestures_.empty(); |
77 } | 78 } |
78 private: | 79 private: |
79 std::vector<std::unique_ptr<SyntheticGesture>> gestures_; | 80 std::vector<std::unique_ptr<SyntheticGesture>> gestures_; |
80 std::queue<OnGestureCompleteCallback> callbacks_; | 81 std::queue<OnGestureCompleteCallback> callbacks_; |
81 | 82 |
82 DISALLOW_COPY_AND_ASSIGN(GestureAndCallbackQueue); | 83 DISALLOW_COPY_AND_ASSIGN(GestureAndCallbackQueue); |
83 } pending_gesture_queue_; | 84 } pending_gesture_queue_; |
84 | 85 |
| 86 BeginFrameRequestCallback begin_frame_callback_; |
| 87 |
| 88 base::WeakPtrFactory<SyntheticGestureController> weak_ptr_factory_; |
| 89 |
85 DISALLOW_COPY_AND_ASSIGN(SyntheticGestureController); | 90 DISALLOW_COPY_AND_ASSIGN(SyntheticGestureController); |
86 }; | 91 }; |
87 | 92 |
88 } // namespace content | 93 } // namespace content |
89 | 94 |
90 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_GESTURE_CONTROLLER_H_ | 95 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_GESTURE_CONTROLLER_H_ |
OLD | NEW |