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 SyntheticPointerAction::SyntheticPointerAction( | 13 SyntheticPointerAction::SyntheticPointerAction( |
14 const SyntheticPointerActionParams& params) | 14 const SyntheticPointerActionParams& params) |
15 : params_(params) {} | 15 : params_(params) {} |
16 | 16 |
17 SyntheticPointerAction::SyntheticPointerAction( | 17 SyntheticPointerAction::SyntheticPointerAction( |
18 const SyntheticPointerActionParams& params, | 18 const std::vector<SyntheticPointerActionParams>& param_list, |
19 SyntheticPointer* synthetic_pointer) | 19 SyntheticPointer* synthetic_pointer, |
20 : params_(params), synthetic_pointer_(synthetic_pointer) {} | 20 IndexMap* index_map) |
| 21 : param_list_(param_list), |
| 22 synthetic_pointer_(synthetic_pointer), |
| 23 index_map_(index_map) {} |
21 | 24 |
22 SyntheticPointerAction::~SyntheticPointerAction() {} | 25 SyntheticPointerAction::~SyntheticPointerAction() {} |
23 | 26 |
24 SyntheticGesture::Result SyntheticPointerAction::ForwardInputEvents( | 27 SyntheticGesture::Result SyntheticPointerAction::ForwardInputEvents( |
25 const base::TimeTicks& timestamp, | 28 const base::TimeTicks& timestamp, |
26 SyntheticGestureTarget* target) { | 29 SyntheticGestureTarget* target) { |
27 if (params_.gesture_source_type == SyntheticGestureParams::DEFAULT_INPUT) | 30 DCHECK(synthetic_pointer_); |
28 params_.gesture_source_type = | 31 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 } | 32 } |
36 | 33 |
37 void SyntheticPointerAction::ForwardTouchOrMouseInputEvents( | 34 SyntheticGesture::Result SyntheticPointerAction::ForwardTouchOrMouseInputEvents( |
38 const base::TimeTicks& timestamp, | 35 const base::TimeTicks& timestamp, |
39 SyntheticGestureTarget* target) { | 36 SyntheticGestureTarget* target) { |
40 switch (params_.pointer_action_type()) { | 37 for (auto iter = param_list_.begin(); iter != param_list_.end(); ++iter) { |
41 case SyntheticPointerActionParams::PointerActionType::PRESS: | 38 SyntheticPointerActionParams params = *iter; |
42 synthetic_pointer_->Press(params_.position().x(), params_.position().y(), | 39 if (params.pointer_action_type() == |
43 target, timestamp); | 40 SyntheticPointerActionParams::PointerActionType::FINISH) |
44 break; | 41 return SyntheticGesture::POINTER_ACTION_FINISHED; |
45 case SyntheticPointerActionParams::PointerActionType::MOVE: | 42 CHECK_GE(params.index(), 0); |
46 synthetic_pointer_->Move(params_.index(), params_.position().x(), | 43 CHECK_LT(params.index(), WebTouchEvent::touchesLengthCap); |
47 params_.position().y(), target, timestamp); | 44 switch (params.pointer_action_type()) { |
48 break; | 45 case SyntheticPointerActionParams::PointerActionType::PRESS: { |
49 case SyntheticPointerActionParams::PointerActionType::RELEASE: | 46 int index = synthetic_pointer_->Press( |
50 synthetic_pointer_->Release(params_.index(), target, timestamp); | 47 params.position().x(), params.position().y(), target, timestamp); |
51 break; | 48 (*index_map_)[params.index()] = index; |
52 default: | 49 break; |
53 NOTREACHED(); | 50 } |
54 break; | 51 case SyntheticPointerActionParams::PointerActionType::MOVE: |
| 52 CHECK_GE((*index_map_)[params.index()], 0); |
| 53 CHECK_LT((*index_map_)[params.index()], |
| 54 WebTouchEvent::touchesLengthCap); |
| 55 synthetic_pointer_->Move((*index_map_)[params.index()], |
| 56 params.position().x(), params.position().y(), |
| 57 target, timestamp); |
| 58 break; |
| 59 case SyntheticPointerActionParams::PointerActionType::RELEASE: |
| 60 CHECK_GE((*index_map_)[params.index()], 0); |
| 61 CHECK_LT((*index_map_)[params.index()], |
| 62 WebTouchEvent::touchesLengthCap); |
| 63 synthetic_pointer_->Release((*index_map_)[params.index()], target, |
| 64 timestamp); |
| 65 break; |
| 66 default: |
| 67 NOTREACHED(); |
| 68 break; |
| 69 } |
55 } | 70 } |
56 synthetic_pointer_->DispatchEvent(target, timestamp); | 71 synthetic_pointer_->DispatchEvent(target, timestamp); |
| 72 return SyntheticGesture::POINTER_ACTION_PROCESSED; |
57 } | 73 } |
58 | 74 |
59 } // namespace content | 75 } // namespace content |
OLD | NEW |