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 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" | 5 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" | 10 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" |
11 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" | 11 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" |
12 #include "content/common/input_messages.h" | 12 #include "content/common/input_messages.h" |
13 #include "content/public/browser/render_widget_host.h" | 13 #include "content/public/browser/render_widget_host.h" |
14 | 14 |
| 15 using blink::WebTouchEvent; |
| 16 |
15 namespace content { | 17 namespace content { |
16 | 18 |
17 SyntheticGestureController::SyntheticGestureController( | 19 SyntheticGestureController::SyntheticGestureController( |
18 std::unique_ptr<SyntheticGestureTarget> gesture_target) | 20 std::unique_ptr<SyntheticGestureTarget> gesture_target) |
19 : gesture_target_(std::move(gesture_target)) {} | 21 : gesture_target_(std::move(gesture_target)) { |
| 22 index_map_ = std::vector<int>(WebTouchEvent::touchesLengthCap, -1); |
| 23 } |
20 | 24 |
21 SyntheticGestureController::~SyntheticGestureController() {} | 25 SyntheticGestureController::~SyntheticGestureController() {} |
22 | 26 |
23 void SyntheticGestureController::QueueSyntheticGesture( | 27 void SyntheticGestureController::QueueSyntheticGesture( |
24 std::unique_ptr<SyntheticGesture> synthetic_gesture, | 28 std::unique_ptr<SyntheticGesture> synthetic_gesture, |
25 const OnGestureCompleteCallback& completion_callback) { | 29 const OnGestureCompleteCallback& completion_callback) { |
26 DCHECK(synthetic_gesture); | 30 DCHECK(synthetic_gesture); |
27 | 31 |
28 bool was_empty = pending_gesture_queue_.IsEmpty(); | 32 bool was_empty = pending_gesture_queue_.IsEmpty(); |
29 | 33 |
30 pending_gesture_queue_.Push(std::move(synthetic_gesture), | 34 pending_gesture_queue_.Push(std::move(synthetic_gesture), |
31 completion_callback); | 35 completion_callback); |
32 | 36 |
33 if (was_empty) | 37 if (was_empty) |
34 StartGesture(*pending_gesture_queue_.FrontGesture()); | 38 StartGesture(*pending_gesture_queue_.FrontGesture()); |
35 } | 39 } |
36 | 40 |
| 41 void SyntheticGestureController::QueueSyntheticPointerAction( |
| 42 const SyntheticPointerActionParams& gesture_params, |
| 43 const OnGestureCompleteCallback& completion_callback) { |
| 44 DCHECK(gesture_params.pointer_action_type() != |
| 45 SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED); |
| 46 |
| 47 if (gesture_params.pointer_action_type() == |
| 48 SyntheticPointerActionParams::PointerActionType::PROCESS || |
| 49 gesture_params.pointer_action_type() == |
| 50 SyntheticPointerActionParams::PointerActionType::FINISH) { |
| 51 if (gesture_params.pointer_action_type() == |
| 52 SyntheticPointerActionParams::PointerActionType::FINISH) { |
| 53 action_param_list_.push_back(gesture_params); |
| 54 } |
| 55 |
| 56 // TODO(lanwei): Will support multiple pointer types in the same stream |
| 57 // later. |
| 58 if (!action_param_list_.empty()) { |
| 59 if (!synthetic_pointer_) |
| 60 SetSyntheticPointer(gesture_params); |
| 61 |
| 62 std::unique_ptr<SyntheticGesture> synthetic_gesture = |
| 63 std::unique_ptr<SyntheticGesture>(new SyntheticPointerAction( |
| 64 action_param_list_, synthetic_pointer_.get(), &index_map_)); |
| 65 QueueSyntheticGesture(std::move(synthetic_gesture), completion_callback); |
| 66 action_param_list_.clear(); |
| 67 } |
| 68 } else |
| 69 action_param_list_.push_back(gesture_params); |
| 70 } |
| 71 |
| 72 void SyntheticGestureController::SetSyntheticPointer( |
| 73 const SyntheticPointerActionParams& gesture_params) { |
| 74 SyntheticGestureParams::GestureSourceType gesture_source_type = |
| 75 gesture_params.gesture_source_type; |
| 76 if (gesture_source_type == SyntheticGestureParams::DEFAULT_INPUT) |
| 77 gesture_source_type = |
| 78 gesture_target_->GetDefaultSyntheticGestureSourceType(); |
| 79 DCHECK_NE(gesture_source_type, SyntheticGestureParams::DEFAULT_INPUT); |
| 80 synthetic_pointer_ = SyntheticPointer::Create(gesture_source_type); |
| 81 } |
| 82 |
| 83 void SyntheticGestureController::ResetSyntheticPointer() { |
| 84 synthetic_pointer_.reset(); |
| 85 } |
| 86 |
37 void SyntheticGestureController::Flush(base::TimeTicks timestamp) { | 87 void SyntheticGestureController::Flush(base::TimeTicks timestamp) { |
38 TRACE_EVENT0("input", "SyntheticGestureController::Flush"); | 88 TRACE_EVENT0("input", "SyntheticGestureController::Flush"); |
39 if (pending_gesture_queue_.IsEmpty()) | 89 if (pending_gesture_queue_.IsEmpty()) |
40 return; | 90 return; |
41 | 91 |
42 if (pending_gesture_result_) | 92 if (pending_gesture_result_) |
43 return; | 93 return; |
44 | 94 |
45 SyntheticGesture* gesture = pending_gesture_queue_.FrontGesture(); | 95 SyntheticGesture* gesture = pending_gesture_queue_.FrontGesture(); |
46 SyntheticGesture::Result result = | 96 SyntheticGesture::Result result = |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 const OnGestureCompleteCallback& completion_callback, | 136 const OnGestureCompleteCallback& completion_callback, |
87 SyntheticGesture::Result result) { | 137 SyntheticGesture::Result result) { |
88 DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING); | 138 DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING); |
89 TRACE_EVENT_ASYNC_END0("input,benchmark", | 139 TRACE_EVENT_ASYNC_END0("input,benchmark", |
90 "SyntheticGestureController::running", | 140 "SyntheticGestureController::running", |
91 &gesture); | 141 &gesture); |
92 | 142 |
93 completion_callback.Run(result); | 143 completion_callback.Run(result); |
94 } | 144 } |
95 | 145 |
| 146 int SyntheticGestureController::PointerIndex(int index) const { |
| 147 CHECK_GE(index, 0); |
| 148 CHECK_LT(index, WebTouchEvent::touchesLengthCap); |
| 149 return index_map_[index]; |
| 150 } |
| 151 |
96 SyntheticGestureController::GestureAndCallbackQueue::GestureAndCallbackQueue() { | 152 SyntheticGestureController::GestureAndCallbackQueue::GestureAndCallbackQueue() { |
97 } | 153 } |
98 | 154 |
99 SyntheticGestureController::GestureAndCallbackQueue:: | 155 SyntheticGestureController::GestureAndCallbackQueue:: |
100 ~GestureAndCallbackQueue() { | 156 ~GestureAndCallbackQueue() { |
101 } | 157 } |
102 | 158 |
103 } // namespace content | 159 } // namespace content |
OLD | NEW |