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