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::unique_ptr<std::vector<SyntheticPointerActionParams>> param_list, |
| 19 SyntheticPointer* synthetic_pointer, | 19 SyntheticPointerDriver* synthetic_pointer_driver) |
| 20 IndexMap* index_map) | |
| 21 : param_list_(std::move(param_list)), | 20 : param_list_(std::move(param_list)), |
| 22 synthetic_pointer_(synthetic_pointer), | 21 synthetic_pointer_driver_(synthetic_pointer_driver) {} |
| 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; | |
| 38 for (const SyntheticPointerActionParams& params : *param_list_) { | 35 for (const SyntheticPointerActionParams& params : *param_list_) { |
| 39 if (!UserInputCheck(params)) | 36 if (!UserInputCheck(params)) |
| 40 return POINTER_ACTION_INPUT_INVALID; | 37 return POINTER_ACTION_INPUT_INVALID; |
| 41 | 38 |
| 42 switch (params.pointer_action_type()) { | 39 switch (params.pointer_action_type()) { |
| 43 case SyntheticPointerActionParams::PointerActionType::PRESS: | 40 case SyntheticPointerActionParams::PointerActionType::PRESS: |
| 44 point_index = synthetic_pointer_->Press( | 41 synthetic_pointer_driver_->Press(params.index(), params.position().x(), |
| 45 params.position().x(), params.position().y(), target, timestamp); | 42 params.position().y(), target, |
| 46 SetPointIndex(params.index(), point_index); | 43 timestamp); |
| 47 break; | 44 break; |
| 48 case SyntheticPointerActionParams::PointerActionType::MOVE: | 45 case SyntheticPointerActionParams::PointerActionType::MOVE: |
| 49 point_index = GetPointIndex(params.index()); | 46 synthetic_pointer_driver_->Move(params.index(), params.position().x(), |
| 50 synthetic_pointer_->Move(point_index, params.position().x(), | 47 params.position().y(), target, |
| 51 params.position().y(), target, timestamp); | 48 timestamp); |
| 52 break; | 49 break; |
| 53 case SyntheticPointerActionParams::PointerActionType::RELEASE: | 50 case SyntheticPointerActionParams::PointerActionType::RELEASE: |
| 54 point_index = GetPointIndex(params.index()); | 51 synthetic_pointer_driver_->Release(params.index(), target, timestamp); |
| 55 synthetic_pointer_->Release(point_index, target, timestamp); | |
| 56 SetPointIndex(params.index(), -1); | |
| 57 break; | 52 break; |
| 58 default: | 53 default: |
| 59 return POINTER_ACTION_INPUT_INVALID; | 54 return POINTER_ACTION_INPUT_INVALID; |
| 60 } | 55 } |
| 61 } | 56 } |
| 62 synthetic_pointer_->DispatchEvent(target, timestamp); | 57 synthetic_pointer_driver_->DispatchEvent(target, timestamp); |
| 63 return GESTURE_FINISHED; | 58 return GESTURE_FINISHED; |
| 64 } | 59 } |
| 65 | 60 |
| 66 bool SyntheticPointerAction::UserInputCheck( | 61 bool SyntheticPointerAction::UserInputCheck( |
| 67 const SyntheticPointerActionParams& params) { | 62 const SyntheticPointerActionParams& params) { |
| 68 if (params.index() < 0 || params.index() >= WebTouchEvent::kTouchesLengthCap) | 63 if (params.index() < 0 || |
| 64 (synthetic_pointer_driver_->SourceType() == | |
| 65 SyntheticGestureParams::TOUCH_INPUT && | |
| 66 params.index() >= WebTouchEvent::kTouchesLengthCap)) { | |
|
tdresser
2016/11/07 17:44:11
I'd split this up to make it a bit more legible.
lanwei
2016/11/07 23:28:48
Done.
| |
| 69 return false; | 67 return false; |
| 68 } | |
| 70 | 69 |
| 71 if (synthetic_pointer_->SourceType() != params.gesture_source_type) | 70 if (synthetic_pointer_driver_->SourceType() != params.gesture_source_type) |
| 72 return false; | 71 return false; |
| 73 | 72 |
| 74 if (params.pointer_action_type() == | 73 if (params.pointer_action_type() == |
| 75 SyntheticPointerActionParams::PointerActionType::PRESS && | 74 SyntheticPointerActionParams::PointerActionType::PRESS && |
| 76 GetPointIndex(params.index()) >= 0) { | 75 synthetic_pointer_driver_->GetPointIndex(params.index()) >= 0) { |
| 77 return false; | 76 return false; |
| 78 } | 77 } |
| 79 | 78 |
| 80 if (synthetic_pointer_->SourceType() == SyntheticGestureParams::TOUCH_INPUT && | 79 if (synthetic_pointer_driver_->SourceType() == |
| 80 SyntheticGestureParams::TOUCH_INPUT && | |
| 81 params.pointer_action_type() == | 81 params.pointer_action_type() == |
| 82 SyntheticPointerActionParams::PointerActionType::MOVE && | 82 SyntheticPointerActionParams::PointerActionType::MOVE && |
| 83 GetPointIndex(params.index()) < 0) { | 83 synthetic_pointer_driver_->GetPointIndex(params.index()) < 0) { |
| 84 return false; | 84 return false; |
| 85 } | 85 } |
| 86 | 86 |
| 87 if (params.pointer_action_type() == | 87 if (params.pointer_action_type() == |
| 88 SyntheticPointerActionParams::PointerActionType::RELEASE && | 88 SyntheticPointerActionParams::PointerActionType::RELEASE && |
| 89 GetPointIndex(params.index()) < 0) { | 89 synthetic_pointer_driver_->GetPointIndex(params.index()) < 0) { |
| 90 return false; | 90 return false; |
| 91 } | 91 } |
| 92 return true; | 92 return true; |
| 93 } | 93 } |
| 94 | 94 |
| 95 } // namespace content | 95 } // namespace content |
| OLD | NEW |