OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/events/gesture_detection/mock_motion_event.h" | 5 #include "ui/events/gesture_detection/mock_motion_event.h" |
6 | 6 |
| 7 #include "base/logging.h" |
| 8 |
7 using base::TimeTicks; | 9 using base::TimeTicks; |
8 | 10 |
9 namespace ui { | 11 namespace ui { |
10 namespace { | 12 namespace { |
11 const float kTouchMajor = 10.f; | 13 const float kTouchMajor = 10.f; |
12 } // namespace | 14 } // namespace |
13 | 15 |
| 16 MockMotionEvent::MockMotionEvent() |
| 17 : action(ACTION_CANCEL), pointer_count(1) {} |
| 18 |
| 19 MockMotionEvent::MockMotionEvent(Action action) |
| 20 : action(action), pointer_count(1) {} |
| 21 |
14 MockMotionEvent::MockMotionEvent(Action action, | 22 MockMotionEvent::MockMotionEvent(Action action, |
15 TimeTicks time, | 23 TimeTicks time, |
16 float x, | 24 float x, |
17 float y) | 25 float y) |
18 : action(action), pointer_count(1), time(time) { | 26 : action(action), pointer_count(1), time(time) { |
19 points[0].SetPoint(x, y); | 27 points[0].SetPoint(x, y); |
20 } | 28 } |
21 | 29 |
22 MockMotionEvent::MockMotionEvent(Action action, | 30 MockMotionEvent::MockMotionEvent(Action action, |
23 TimeTicks time, | 31 TimeTicks time, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 scoped_ptr<MotionEvent> MockMotionEvent::Clone() const { | 99 scoped_ptr<MotionEvent> MockMotionEvent::Clone() const { |
92 return scoped_ptr<MotionEvent>(new MockMotionEvent(*this)); | 100 return scoped_ptr<MotionEvent>(new MockMotionEvent(*this)); |
93 } | 101 } |
94 | 102 |
95 scoped_ptr<MotionEvent> MockMotionEvent::Cancel() const { | 103 scoped_ptr<MotionEvent> MockMotionEvent::Cancel() const { |
96 scoped_ptr<MockMotionEvent> cancel_event(new MockMotionEvent(*this)); | 104 scoped_ptr<MockMotionEvent> cancel_event(new MockMotionEvent(*this)); |
97 cancel_event->action = MotionEvent::ACTION_CANCEL; | 105 cancel_event->action = MotionEvent::ACTION_CANCEL; |
98 return cancel_event.PassAs<MotionEvent>(); | 106 return cancel_event.PassAs<MotionEvent>(); |
99 } | 107 } |
100 | 108 |
| 109 void MockMotionEvent::PressPoint(float x, float y) { |
| 110 // Reset the pointer count if the previously released and/or cancelled pointer |
| 111 // was the last pointer in the event. |
| 112 if (pointer_count == 1 && (action == ACTION_UP || action == ACTION_CANCEL)) |
| 113 pointer_count = 0; |
| 114 |
| 115 DCHECK_LT(pointer_count + 1, static_cast<size_t>(MAX_POINTERS)); |
| 116 points[pointer_count++] = gfx::PointF(x, y); |
| 117 action = pointer_count > 1 ? ACTION_POINTER_DOWN : ACTION_DOWN; |
| 118 } |
| 119 |
| 120 void MockMotionEvent::MovePoint(size_t index, float x, float y) { |
| 121 DCHECK_LT(index, pointer_count); |
| 122 points[index] = gfx::PointF(x, y); |
| 123 action = ACTION_MOVE; |
| 124 } |
| 125 |
| 126 void MockMotionEvent::ReleasePoint() { |
| 127 DCHECK_GT(pointer_count, 0U); |
| 128 if (pointer_count > 1) { |
| 129 --pointer_count; |
| 130 action = ACTION_POINTER_UP; |
| 131 } else { |
| 132 action = ACTION_UP; |
| 133 } |
| 134 } |
| 135 |
| 136 void MockMotionEvent::CancelPoint() { |
| 137 DCHECK_GT(pointer_count, 0U); |
| 138 if (pointer_count > 1) |
| 139 --pointer_count; |
| 140 action = ACTION_CANCEL; |
| 141 } |
| 142 |
101 } // namespace ui | 143 } // namespace ui |
OLD | NEW |