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 } | 28 } |
25 | 29 |
26 int SyntheticTouchDriver::Press(float x, float y) { | 30 void SyntheticTouchDriver::Press(float x, float y, int index) { |
27 int index = touch_event_.PressPoint(x, y); | 31 DCHECK_GE(index, 0); |
28 return index; | 32 DCHECK_LT(index, WebTouchEvent::kTouchesLengthCap); |
33 int touch_index = touch_event_.PressPoint(x, y); | |
34 index_map_[index] = touch_index; | |
Navid Zolghadr
2016/12/09 16:04:47
I wonder if the debug check is enough. When users
| |
29 } | 35 } |
30 | 36 |
31 void SyntheticTouchDriver::Move(float x, float y, int index) { | 37 void SyntheticTouchDriver::Move(float x, float y, int index) { |
32 touch_event_.MovePoint(index, x, y); | 38 DCHECK_GE(index, 0); |
39 DCHECK_LT(index, WebTouchEvent::kTouchesLengthCap); | |
40 touch_event_.MovePoint(index_map_[index], x, y); | |
33 } | 41 } |
34 | 42 |
35 void SyntheticTouchDriver::Release(int index) { | 43 void SyntheticTouchDriver::Release(int index) { |
36 touch_event_.ReleasePoint(index); | 44 DCHECK_GE(index, 0); |
45 DCHECK_LT(index, WebTouchEvent::kTouchesLengthCap); | |
46 touch_event_.ReleasePoint(index_map_[index]); | |
47 index_map_[index] = -1; | |
37 } | 48 } |
38 | 49 |
39 bool SyntheticTouchDriver::UserInputCheck( | 50 bool SyntheticTouchDriver::UserInputCheck( |
40 const SyntheticPointerActionParams& params) const { | 51 const SyntheticPointerActionParams& params) const { |
41 DCHECK_GE(params.index(), -1); | 52 DCHECK_GE(params.index(), 0); |
42 DCHECK_LT(params.index(), WebTouchEvent::kTouchesLengthCap); | 53 DCHECK_LT(params.index(), WebTouchEvent::kTouchesLengthCap); |
43 if (params.gesture_source_type != SyntheticGestureParams::TOUCH_INPUT) | 54 |
55 if (params.gesture_source_type() != SyntheticGestureParams::TOUCH_INPUT) | |
44 return false; | 56 return false; |
45 | 57 |
46 if (params.pointer_action_type() == | 58 if (params.pointer_action_type() == |
47 SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED) { | 59 SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED) { |
48 return false; | 60 return false; |
49 } | 61 } |
50 | 62 |
51 if (params.pointer_action_type() == | 63 if (params.pointer_action_type() == |
52 SyntheticPointerActionParams::PointerActionType::PRESS && | 64 SyntheticPointerActionParams::PointerActionType::PRESS && |
53 params.index() >= 0) { | 65 index_map_[params.index()] >= 0) { |
54 return false; | 66 return false; |
55 } | 67 } |
56 | 68 |
57 if (params.pointer_action_type() == | 69 if (params.pointer_action_type() == |
58 SyntheticPointerActionParams::PointerActionType::MOVE && | 70 SyntheticPointerActionParams::PointerActionType::MOVE && |
59 params.index() == -1) { | 71 index_map_[params.index()] == -1) { |
60 return false; | 72 return false; |
61 } | 73 } |
62 | 74 |
63 if (params.pointer_action_type() == | 75 if (params.pointer_action_type() == |
64 SyntheticPointerActionParams::PointerActionType::RELEASE && | 76 SyntheticPointerActionParams::PointerActionType::RELEASE && |
65 params.index() == -1) { | 77 index_map_[params.index()] == -1) { |
66 return false; | 78 return false; |
67 } | 79 } |
68 | 80 |
69 return true; | 81 return true; |
70 } | 82 } |
71 | 83 |
72 } // namespace content | 84 } // namespace content |
OLD | NEW |