| 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_touch_driver.h" | 5 #include "content/browser/renderer_host/input/synthetic_touch_driver.h" |
| 6 | 6 |
| 7 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" | 7 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" |
| 8 | 8 |
| 9 using blink::WebTouchEvent; | 9 using blink::WebTouchEvent; |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 | 12 |
| 13 SyntheticTouchDriver::SyntheticTouchDriver() {} | 13 SyntheticTouchDriver::SyntheticTouchDriver() { |
| 14 std::fill(index_map_.begin(), index_map_.end(), -1); |
| 15 } |
| 14 | 16 |
| 15 SyntheticTouchDriver::SyntheticTouchDriver(SyntheticWebTouchEvent touch_event) | 17 SyntheticTouchDriver::SyntheticTouchDriver(SyntheticWebTouchEvent touch_event) |
| 16 : touch_event_(touch_event) {} | 18 : touch_event_(touch_event) { |
| 19 std::fill(index_map_.begin(), index_map_.end(), -1); |
| 20 } |
| 17 | 21 |
| 18 SyntheticTouchDriver::~SyntheticTouchDriver() {} | 22 SyntheticTouchDriver::~SyntheticTouchDriver() {} |
| 19 | 23 |
| 20 void SyntheticTouchDriver::DispatchEvent(SyntheticGestureTarget* target, | 24 void SyntheticTouchDriver::DispatchEvent(SyntheticGestureTarget* target, |
| 21 const base::TimeTicks& timestamp) { | 25 const base::TimeTicks& timestamp) { |
| 22 touch_event_.timeStampSeconds = ConvertTimestampToSeconds(timestamp); | 26 touch_event_.timeStampSeconds = ConvertTimestampToSeconds(timestamp); |
| 23 target->DispatchInputEventToPlatform(touch_event_); | 27 target->DispatchInputEventToPlatform(touch_event_); |
| 24 touch_event_.ResetPoints(); | 28 touch_event_.ResetPoints(); |
| 25 } | 29 } |
| 26 | 30 |
| 27 int SyntheticTouchDriver::Press(float x, float y) { | 31 void SyntheticTouchDriver::Press(float x, float y, int index) { |
| 28 int index = touch_event_.PressPoint(x, y); | 32 DCHECK_GE(index, 0); |
| 29 return index; | 33 DCHECK_LT(index, blink::WebTouchEvent::kTouchesLengthCap); |
| 34 int touch_index = touch_event_.PressPoint(x, y); |
| 35 index_map_[index] = touch_index; |
| 30 } | 36 } |
| 31 | 37 |
| 32 void SyntheticTouchDriver::Move(float x, float y, int index) { | 38 void SyntheticTouchDriver::Move(float x, float y, int index) { |
| 33 touch_event_.MovePoint(index, x, y); | 39 DCHECK_GE(index, 0); |
| 40 DCHECK_LT(index, blink::WebTouchEvent::kTouchesLengthCap); |
| 41 touch_event_.MovePoint(index_map_[index], x, y); |
| 34 } | 42 } |
| 35 | 43 |
| 36 void SyntheticTouchDriver::Release(int index) { | 44 void SyntheticTouchDriver::Release(int index) { |
| 37 touch_event_.ReleasePoint(index); | 45 DCHECK_GE(index, 0); |
| 46 DCHECK_LT(index, blink::WebTouchEvent::kTouchesLengthCap); |
| 47 touch_event_.ReleasePoint(index_map_[index]); |
| 48 index_map_[index] = -1; |
| 38 } | 49 } |
| 39 | 50 |
| 40 bool SyntheticTouchDriver::UserInputCheck( | 51 bool SyntheticTouchDriver::UserInputCheck( |
| 41 const SyntheticPointerActionParams& params) const { | 52 const SyntheticPointerActionParams& params) const { |
| 42 DCHECK_GE(params.index(), -1); | 53 if (params.index() < 0 || params.index() >= WebTouchEvent::kTouchesLengthCap) |
| 43 DCHECK_LT(params.index(), WebTouchEvent::kTouchesLengthCap); | |
| 44 if (params.gesture_source_type != SyntheticGestureParams::TOUCH_INPUT) | |
| 45 return false; | 54 return false; |
| 46 | 55 |
| 47 if (params.pointer_action_type() == | 56 if (params.pointer_action_type() == |
| 48 SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED) { | 57 SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED) { |
| 49 return false; | 58 return false; |
| 50 } | 59 } |
| 51 | 60 |
| 52 if (params.pointer_action_type() == | 61 if (params.pointer_action_type() == |
| 53 SyntheticPointerActionParams::PointerActionType::PRESS && | 62 SyntheticPointerActionParams::PointerActionType::PRESS && |
| 54 params.index() >= 0) { | 63 index_map_[params.index()] >= 0) { |
| 55 return false; | 64 return false; |
| 56 } | 65 } |
| 57 | 66 |
| 58 if (params.pointer_action_type() == | 67 if (params.pointer_action_type() == |
| 59 SyntheticPointerActionParams::PointerActionType::MOVE && | 68 SyntheticPointerActionParams::PointerActionType::MOVE && |
| 60 params.index() == -1) { | 69 index_map_[params.index()] == -1) { |
| 61 return false; | 70 return false; |
| 62 } | 71 } |
| 63 | 72 |
| 64 if (params.pointer_action_type() == | 73 if (params.pointer_action_type() == |
| 65 SyntheticPointerActionParams::PointerActionType::RELEASE && | 74 SyntheticPointerActionParams::PointerActionType::RELEASE && |
| 66 params.index() == -1) { | 75 index_map_[params.index()] == -1) { |
| 67 return false; | 76 return false; |
| 68 } | 77 } |
| 69 | 78 |
| 70 return true; | 79 return true; |
| 71 } | 80 } |
| 72 | 81 |
| 73 } // namespace content | 82 } // namespace content |
| OLD | NEW |