Chromium Code Reviews| 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 std::unique_ptr<std::vector<SyntheticPointerActionParams>> param_list, | 18 std::vector<SyntheticPointerActionParams>* param_list, |
| 19 SyntheticPointer* synthetic_pointer, | 19 SyntheticPointerDriver* synthetic_pointer_driver) |
| 20 IndexMap* index_map) | 20 : param_list_(param_list), |
| 21 : param_list_(std::move(param_list)), | 21 synthetic_pointer_driver_(synthetic_pointer_driver) {} |
| 22 synthetic_pointer_(synthetic_pointer), | |
| 23 index_map_(index_map) {} | |
| 24 | 22 |
| 25 SyntheticPointerAction::~SyntheticPointerAction() {} | 23 SyntheticPointerAction::~SyntheticPointerAction() {} |
| 26 | 24 |
| 27 SyntheticGesture::Result SyntheticPointerAction::ForwardInputEvents( | 25 SyntheticGesture::Result SyntheticPointerAction::ForwardInputEvents( |
| 28 const base::TimeTicks& timestamp, | 26 const base::TimeTicks& timestamp, |
| 29 SyntheticGestureTarget* target) { | 27 SyntheticGestureTarget* target) { |
| 30 DCHECK(synthetic_pointer_); | 28 DCHECK(synthetic_pointer_driver_); |
| 31 return ForwardTouchOrMouseInputEvents(timestamp, target); | 29 return ForwardTouchOrMouseInputEvents(timestamp, target); |
| 32 } | 30 } |
| 33 | 31 |
| 34 SyntheticGesture::Result SyntheticPointerAction::ForwardTouchOrMouseInputEvents( | 32 SyntheticGesture::Result SyntheticPointerAction::ForwardTouchOrMouseInputEvents( |
| 35 const base::TimeTicks& timestamp, | 33 const base::TimeTicks& timestamp, |
| 36 SyntheticGestureTarget* target) { | 34 SyntheticGestureTarget* target) { |
| 37 int point_index; | 35 for (size_t i = 0; i < param_list_->size(); ++i) { |
|
tdresser
2016/11/10 14:58:32
Why did we switch away from a range based for loop
lanwei
2016/11/10 19:45:22
I thought I could not change params's index in its
| |
| 38 for (const SyntheticPointerActionParams& params : *param_list_) { | 36 SyntheticPointerActionParams& params = (*param_list_)[i]; |
| 39 if (!UserInputCheck(params)) | 37 if (!synthetic_pointer_driver_->UserInputCheck(params)) |
| 40 return POINTER_ACTION_INPUT_INVALID; | 38 return POINTER_ACTION_INPUT_INVALID; |
| 41 | 39 |
| 42 switch (params.pointer_action_type()) { | 40 switch (params.pointer_action_type()) { |
| 43 case SyntheticPointerActionParams::PointerActionType::PRESS: | 41 case SyntheticPointerActionParams::PointerActionType::PRESS: { |
| 44 point_index = synthetic_pointer_->Press( | 42 int index = synthetic_pointer_driver_->Press(params.position().x(), |
| 45 params.position().x(), params.position().y(), target, timestamp); | 43 params.position().y()); |
| 46 SetPointIndex(params.index(), point_index); | 44 params.set_index(index); |
| 47 break; | 45 break; |
| 46 } | |
| 48 case SyntheticPointerActionParams::PointerActionType::MOVE: | 47 case SyntheticPointerActionParams::PointerActionType::MOVE: |
| 49 point_index = GetPointIndex(params.index()); | 48 synthetic_pointer_driver_->Move(params.position().x(), |
| 50 synthetic_pointer_->Move(point_index, params.position().x(), | 49 params.position().y(), params.index()); |
| 51 params.position().y(), target, timestamp); | |
| 52 break; | 50 break; |
| 53 case SyntheticPointerActionParams::PointerActionType::RELEASE: | 51 case SyntheticPointerActionParams::PointerActionType::RELEASE: |
| 54 point_index = GetPointIndex(params.index()); | 52 synthetic_pointer_driver_->Release(params.index()); |
| 55 synthetic_pointer_->Release(point_index, target, timestamp); | 53 params.set_index(-1); |
| 56 SetPointIndex(params.index(), -1); | |
| 57 break; | 54 break; |
| 58 default: | 55 default: |
|
tdresser
2016/11/10 14:58:32
Should we explicitly handle the other cases here?
lanwei
2016/11/10 19:45:22
The case for finish may change later, but 'return
| |
| 59 return POINTER_ACTION_INPUT_INVALID; | 56 break; |
| 60 } | 57 } |
| 61 } | 58 } |
| 62 synthetic_pointer_->DispatchEvent(target, timestamp); | 59 synthetic_pointer_driver_->DispatchEvent(target, timestamp); |
| 63 return GESTURE_FINISHED; | 60 return GESTURE_FINISHED; |
| 64 } | 61 } |
| 65 | 62 |
| 66 bool SyntheticPointerAction::UserInputCheck( | |
| 67 const SyntheticPointerActionParams& params) { | |
| 68 if (params.index() < 0 || params.index() >= WebTouchEvent::kTouchesLengthCap) | |
| 69 return false; | |
| 70 | |
| 71 if (synthetic_pointer_->SourceType() != params.gesture_source_type) | |
| 72 return false; | |
| 73 | |
| 74 if (params.pointer_action_type() == | |
| 75 SyntheticPointerActionParams::PointerActionType::PRESS && | |
| 76 GetPointIndex(params.index()) >= 0) { | |
| 77 return false; | |
| 78 } | |
| 79 | |
| 80 if (synthetic_pointer_->SourceType() == SyntheticGestureParams::TOUCH_INPUT && | |
| 81 params.pointer_action_type() == | |
| 82 SyntheticPointerActionParams::PointerActionType::MOVE && | |
| 83 GetPointIndex(params.index()) < 0) { | |
| 84 return false; | |
| 85 } | |
| 86 | |
| 87 if (params.pointer_action_type() == | |
| 88 SyntheticPointerActionParams::PointerActionType::RELEASE && | |
| 89 GetPointIndex(params.index()) < 0) { | |
| 90 return false; | |
| 91 } | |
| 92 return true; | |
| 93 } | |
| 94 | |
| 95 } // namespace content | 63 } // namespace content |
| OLD | NEW |