OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_pointer_action.h" | 5 #include "content/browser/renderer_host/input/synthetic_pointer_action.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "third_party/WebKit/public/web/WebInputEvent.h" | 8 #include "third_party/WebKit/public/web/WebInputEvent.h" |
9 #include "ui/events/latency_info.h" | 9 #include "ui/events/latency_info.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 | 12 |
| 13 using blink::WebTouchEvent; |
| 14 |
13 SyntheticPointerAction::SyntheticPointerAction( | 15 SyntheticPointerAction::SyntheticPointerAction( |
14 const SyntheticPointerActionParams& params) | 16 const SyntheticPointerActionParams& params) |
15 : params_(params) {} | 17 : params_(params) {} |
16 | 18 |
17 SyntheticPointerAction::SyntheticPointerAction( | 19 SyntheticPointerAction::SyntheticPointerAction( |
18 const SyntheticPointerActionParams& params, | 20 const std::vector<SyntheticPointerActionParams>& param_list, |
19 SyntheticPointer* synthetic_pointer) | 21 SyntheticPointer* synthetic_pointer, |
20 : params_(params), synthetic_pointer_(synthetic_pointer) {} | 22 std::vector<int>* index_map) |
| 23 : param_list_(param_list), |
| 24 synthetic_pointer_(synthetic_pointer), |
| 25 index_map_(index_map) {} |
21 | 26 |
22 SyntheticPointerAction::~SyntheticPointerAction() {} | 27 SyntheticPointerAction::~SyntheticPointerAction() {} |
23 | 28 |
24 SyntheticGesture::Result SyntheticPointerAction::ForwardInputEvents( | 29 SyntheticGesture::Result SyntheticPointerAction::ForwardInputEvents( |
25 const base::TimeTicks& timestamp, | 30 const base::TimeTicks& timestamp, |
26 SyntheticGestureTarget* target) { | 31 SyntheticGestureTarget* target) { |
27 if (params_.gesture_source_type == SyntheticGestureParams::DEFAULT_INPUT) | 32 DCHECK(synthetic_pointer_); |
28 params_.gesture_source_type = | 33 return ForwardTouchOrMouseInputEvents(timestamp, target); |
29 target->GetDefaultSyntheticGestureSourceType(); | |
30 | |
31 DCHECK_NE(params_.gesture_source_type, SyntheticGestureParams::DEFAULT_INPUT); | |
32 | |
33 ForwardTouchOrMouseInputEvents(timestamp, target); | |
34 return SyntheticGesture::GESTURE_FINISHED; | |
35 } | 34 } |
36 | 35 |
37 void SyntheticPointerAction::ForwardTouchOrMouseInputEvents( | 36 SyntheticGesture::Result SyntheticPointerAction::ForwardTouchOrMouseInputEvents( |
38 const base::TimeTicks& timestamp, | 37 const base::TimeTicks& timestamp, |
39 SyntheticGestureTarget* target) { | 38 SyntheticGestureTarget* target) { |
40 switch (params_.pointer_action_type()) { | 39 for (auto iter = param_list_.begin(); iter != param_list_.end(); ++iter) { |
41 case SyntheticPointerActionParams::PointerActionType::PRESS: | 40 SyntheticPointerActionParams params = *iter; |
42 synthetic_pointer_->Press(params_.position().x(), params_.position().y(), | 41 if (params.pointer_action_type() == |
43 target, timestamp); | 42 SyntheticPointerActionParams::PointerActionType::FINISH) |
44 break; | 43 return SyntheticGesture::POINTER_ACTION_FINISHED; |
45 case SyntheticPointerActionParams::PointerActionType::MOVE: | 44 CHECK_GE(params.index(), 0); |
46 synthetic_pointer_->Move(params_.index(), params_.position().x(), | 45 CHECK_LT(params.index(), WebTouchEvent::touchesLengthCap); |
47 params_.position().y(), target, timestamp); | 46 switch (params.pointer_action_type()) { |
48 break; | 47 case SyntheticPointerActionParams::PointerActionType::PRESS: { |
49 case SyntheticPointerActionParams::PointerActionType::RELEASE: | 48 int index = synthetic_pointer_->Press( |
50 synthetic_pointer_->Release(params_.index(), target, timestamp); | 49 params.position().x(), params.position().y(), target, timestamp); |
51 break; | 50 (*index_map_)[params.index()] = index; |
52 default: | 51 break; |
53 NOTREACHED(); | 52 } |
54 break; | 53 case SyntheticPointerActionParams::PointerActionType::MOVE: |
| 54 CHECK_GE((*index_map_)[params.index()], 0); |
| 55 CHECK_LT((*index_map_)[params.index()], |
| 56 WebTouchEvent::touchesLengthCap); |
| 57 synthetic_pointer_->Move((*index_map_)[params.index()], |
| 58 params.position().x(), params.position().y(), |
| 59 target, timestamp); |
| 60 break; |
| 61 case SyntheticPointerActionParams::PointerActionType::RELEASE: |
| 62 CHECK_GE((*index_map_)[params.index()], 0); |
| 63 CHECK_LT((*index_map_)[params.index()], |
| 64 WebTouchEvent::touchesLengthCap); |
| 65 synthetic_pointer_->Release((*index_map_)[params.index()], target, |
| 66 timestamp); |
| 67 break; |
| 68 default: |
| 69 NOTREACHED(); |
| 70 break; |
| 71 } |
55 } | 72 } |
56 synthetic_pointer_->DispatchEvent(target, timestamp); | 73 synthetic_pointer_->DispatchEvent(target, timestamp); |
| 74 return SyntheticGesture::POINTER_ACTION_PROCESSED; |
57 } | 75 } |
58 | 76 |
59 } // namespace content | 77 } // namespace content |
OLD | NEW |