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 const SyntheticPointerActionParams& params, | 18 std::unique_ptr<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_(std::move(param_list)), | |
| 22 synthetic_pointer_(synthetic_pointer), | |
| 23 index_map_(index_map) {} | |
|
samuong
2016/07/08 18:38:34
In a previous discussion, we decided that the Synt
lanwei
2016/07/12 19:54:55
Yes, it is commented in its head file.
| |
| 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); |
|
samuong
2016/07/08 18:38:35
Does this still need to be a separate function, or
lanwei
2016/07/12 19:54:55
This will be changed in the next patch, so I think
| |
| 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 int point_index; |
| 41 case SyntheticPointerActionParams::PointerActionType::PRESS: | 38 for (const SyntheticPointerActionParams& params : *param_list_) { |
| 42 synthetic_pointer_->Press(params_.position().x(), params_.position().y(), | 39 if (!UserInputCheck(params)) |
| 43 target, timestamp); | 40 return POINTER_ACTION_INPUT_INVALID; |
| 44 break; | 41 |
| 45 case SyntheticPointerActionParams::PointerActionType::MOVE: | 42 switch (params.pointer_action_type()) { |
| 46 synthetic_pointer_->Move(params_.index(), params_.position().x(), | 43 case SyntheticPointerActionParams::PointerActionType::PRESS: |
| 47 params_.position().y(), target, timestamp); | 44 point_index = synthetic_pointer_->Press( |
| 48 break; | 45 params.position().x(), params.position().y(), target, timestamp); |
| 49 case SyntheticPointerActionParams::PointerActionType::RELEASE: | 46 SetPointIndex(params.index(), point_index); |
| 50 synthetic_pointer_->Release(params_.index(), target, timestamp); | 47 break; |
| 51 break; | 48 case SyntheticPointerActionParams::PointerActionType::MOVE: |
| 52 default: | 49 point_index = GetPointIndex(params.index()); |
| 53 NOTREACHED(); | 50 synthetic_pointer_->Move(point_index, params.position().x(), |
| 54 break; | 51 params.position().y(), target, timestamp); |
| 52 break; | |
| 53 case SyntheticPointerActionParams::PointerActionType::RELEASE: | |
| 54 point_index = GetPointIndex(params.index()); | |
| 55 synthetic_pointer_->Release(point_index, target, timestamp); | |
| 56 SetPointIndex(params.index(), -1); | |
| 57 break; | |
| 58 default: | |
| 59 return POINTER_ACTION_INPUT_INVALID; | |
| 60 } | |
| 55 } | 61 } |
| 56 synthetic_pointer_->DispatchEvent(target, timestamp); | 62 synthetic_pointer_->DispatchEvent(target, timestamp); |
| 63 return GESTURE_FINISHED; | |
| 64 } | |
| 65 | |
| 66 bool SyntheticPointerAction::UserInputCheck( | |
| 67 const SyntheticPointerActionParams& params) { | |
| 68 if (params.index() < 0 || params.index() >= WebTouchEvent::touchesLengthCap) | |
| 69 return false; | |
| 70 | |
| 71 if (synthetic_pointer_->PointerSourceType() != 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 ((params.pointer_action_type() == | |
| 81 SyntheticPointerActionParams::PointerActionType::MOVE || | |
| 82 params.pointer_action_type() == | |
| 83 SyntheticPointerActionParams::PointerActionType::RELEASE) && | |
| 84 GetPointIndex(params.index()) < 0) { | |
| 85 return false; | |
| 86 } | |
| 87 return true; | |
| 57 } | 88 } |
| 58 | 89 |
| 59 } // namespace content | 90 } // namespace content |
| OLD | NEW |