| 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/test/mock_motion_event.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 using base::TimeTicks; | 9 using base::TimeTicks; |
| 10 | 10 |
| 11 namespace ui { | 11 namespace ui { |
| 12 namespace test { |
| 12 | 13 |
| 13 MockMotionEvent::MockMotionEvent() | 14 MockMotionEvent::MockMotionEvent() |
| 14 : action(ACTION_CANCEL), pointer_count(1), touch_major(TOUCH_MAJOR), id(0) { | 15 : action(ACTION_CANCEL), pointer_count(1), touch_major(TOUCH_MAJOR), id(0), |
| 16 button_state(0) { |
| 15 } | 17 } |
| 16 | 18 |
| 17 MockMotionEvent::MockMotionEvent(Action action) | 19 MockMotionEvent::MockMotionEvent(Action action) |
| 18 : action(action), pointer_count(1), touch_major(TOUCH_MAJOR), id(0) { | 20 : action(action), pointer_count(1), touch_major(TOUCH_MAJOR), id(0), |
| 21 button_state(0) { |
| 19 } | 22 } |
| 20 | 23 |
| 21 MockMotionEvent::MockMotionEvent(Action action, | 24 MockMotionEvent::MockMotionEvent(Action action, |
| 22 TimeTicks time, | 25 TimeTicks time, |
| 23 float x, | 26 float x, |
| 24 float y) | 27 float y) |
| 25 : action(action), | 28 : action(action), |
| 26 pointer_count(1), | 29 pointer_count(1), |
| 27 time(time), | 30 time(time), |
| 28 touch_major(TOUCH_MAJOR), | 31 touch_major(TOUCH_MAJOR), |
| 29 id(0) { | 32 id(0), |
| 33 button_state(0) { |
| 30 points[0].SetPoint(x, y); | 34 points[0].SetPoint(x, y); |
| 35 tool_types[0] = TOOL_TYPE_UNKNOWN; |
| 31 } | 36 } |
| 32 | 37 |
| 33 MockMotionEvent::MockMotionEvent(Action action, | 38 MockMotionEvent::MockMotionEvent(Action action, |
| 34 TimeTicks time, | 39 TimeTicks time, |
| 35 float x0, | 40 float x0, |
| 36 float y0, | 41 float y0, |
| 37 float x1, | 42 float x1, |
| 38 float y1) | 43 float y1) |
| 39 : action(action), | 44 : action(action), |
| 40 pointer_count(2), | 45 pointer_count(2), |
| 41 time(time), | 46 time(time), |
| 42 touch_major(TOUCH_MAJOR), | 47 touch_major(TOUCH_MAJOR), |
| 43 id(0) { | 48 id(0), |
| 49 button_state(0) { |
| 44 points[0].SetPoint(x0, y0); | 50 points[0].SetPoint(x0, y0); |
| 51 tool_types[0] = TOOL_TYPE_UNKNOWN; |
| 45 points[1].SetPoint(x1, y1); | 52 points[1].SetPoint(x1, y1); |
| 53 tool_types[1] = TOOL_TYPE_UNKNOWN; |
| 46 } | 54 } |
| 47 | 55 |
| 48 MockMotionEvent::MockMotionEvent(Action action, | 56 MockMotionEvent::MockMotionEvent(Action action, |
| 49 TimeTicks time, | 57 TimeTicks time, |
| 50 float x0, | 58 float x0, |
| 51 float y0, | 59 float y0, |
| 52 float x1, | 60 float x1, |
| 53 float y1, | 61 float y1, |
| 54 float x2, | 62 float x2, |
| 55 float y2) | 63 float y2) |
| 56 : action(action), | 64 : action(action), |
| 57 pointer_count(3), | 65 pointer_count(3), |
| 58 time(time), | 66 time(time), |
| 59 touch_major(TOUCH_MAJOR), | 67 touch_major(TOUCH_MAJOR), |
| 60 id(0) { | 68 id(0), |
| 69 button_state(0) { |
| 61 points[0].SetPoint(x0, y0); | 70 points[0].SetPoint(x0, y0); |
| 71 tool_types[0] = TOOL_TYPE_UNKNOWN; |
| 62 points[1].SetPoint(x1, y1); | 72 points[1].SetPoint(x1, y1); |
| 73 tool_types[1] = TOOL_TYPE_UNKNOWN; |
| 63 points[2].SetPoint(x2, y2); | 74 points[2].SetPoint(x2, y2); |
| 75 tool_types[2] = TOOL_TYPE_UNKNOWN; |
| 64 } | 76 } |
| 65 | 77 |
| 66 MockMotionEvent::MockMotionEvent(const MockMotionEvent& other) | 78 MockMotionEvent::MockMotionEvent(const MockMotionEvent& other) |
| 67 : action(other.action), | 79 : action(other.action), |
| 68 pointer_count(other.pointer_count), | 80 pointer_count(other.pointer_count), |
| 69 time(other.time), | 81 time(other.time), |
| 70 touch_major(other.touch_major), | 82 touch_major(other.touch_major), |
| 71 id(other.GetId()) { | 83 id(other.GetId()), |
| 72 for (size_t i = 0; i < pointer_count; ++i) | 84 button_state(other.GetButtonState()) { |
| 85 for (size_t i = 0; i < pointer_count; ++i) { |
| 73 points[i] = other.points[i]; | 86 points[i] = other.points[i]; |
| 87 tool_types[i] = other.tool_types[i]; |
| 88 } |
| 74 } | 89 } |
| 75 | 90 |
| 76 MockMotionEvent::~MockMotionEvent() {} | 91 MockMotionEvent::~MockMotionEvent() {} |
| 77 | 92 |
| 78 MotionEvent::Action MockMotionEvent::GetAction() const { return action; } | 93 MotionEvent::Action MockMotionEvent::GetAction() const { return action; } |
| 79 | 94 |
| 80 int MockMotionEvent::GetActionIndex() const { | 95 int MockMotionEvent::GetActionIndex() const { |
| 81 return static_cast<int>(pointer_count) - 1; | 96 return static_cast<int>(pointer_count) - 1; |
| 82 } | 97 } |
| 83 | 98 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 size_t historical_index) const { | 149 size_t historical_index) const { |
| 135 return 0; | 150 return 0; |
| 136 } | 151 } |
| 137 | 152 |
| 138 float MockMotionEvent::GetHistoricalY(size_t pointer_index, | 153 float MockMotionEvent::GetHistoricalY(size_t pointer_index, |
| 139 size_t historical_index) const { | 154 size_t historical_index) const { |
| 140 return 0; | 155 return 0; |
| 141 } | 156 } |
| 142 | 157 |
| 143 MotionEvent::ToolType MockMotionEvent::GetToolType(size_t pointer_index) const { | 158 MotionEvent::ToolType MockMotionEvent::GetToolType(size_t pointer_index) const { |
| 144 return MotionEvent::TOOL_TYPE_UNKNOWN; | 159 DCHECK_LT(pointer_index, pointer_count); |
| 160 return tool_types[pointer_index]; |
| 145 } | 161 } |
| 146 | 162 |
| 147 int MockMotionEvent::GetButtonState() const { | 163 int MockMotionEvent::GetButtonState() const { |
| 148 return 0; | 164 return button_state; |
| 149 } | 165 } |
| 150 | 166 |
| 151 scoped_ptr<MotionEvent> MockMotionEvent::Clone() const { | 167 scoped_ptr<MotionEvent> MockMotionEvent::Clone() const { |
| 152 return scoped_ptr<MotionEvent>(new MockMotionEvent(*this)); | 168 return scoped_ptr<MotionEvent>(new MockMotionEvent(*this)); |
| 153 } | 169 } |
| 154 | 170 |
| 155 scoped_ptr<MotionEvent> MockMotionEvent::Cancel() const { | 171 scoped_ptr<MotionEvent> MockMotionEvent::Cancel() const { |
| 156 scoped_ptr<MockMotionEvent> cancel_event(new MockMotionEvent(*this)); | 172 scoped_ptr<MockMotionEvent> cancel_event(new MockMotionEvent(*this)); |
| 157 cancel_event->action = MotionEvent::ACTION_CANCEL; | 173 cancel_event->action = MotionEvent::ACTION_CANCEL; |
| 158 return cancel_event.PassAs<MotionEvent>(); | 174 return cancel_event.PassAs<MotionEvent>(); |
| 159 } | 175 } |
| 160 | 176 |
| 161 void MockMotionEvent::SetId(int new_id) { | 177 void MockMotionEvent::SetId(int new_id) { |
| 162 id = new_id; | 178 id = new_id; |
| 163 } | 179 } |
| 164 | 180 |
| 165 void MockMotionEvent::SetTime(base::TimeTicks new_time) { | 181 void MockMotionEvent::SetTime(base::TimeTicks new_time) { |
| 166 time = new_time; | 182 time = new_time; |
| 167 } | 183 } |
| 168 | 184 |
| 169 void MockMotionEvent::PressPoint(float x, float y) { | 185 void MockMotionEvent::PressPoint(float x, float y) { |
| 170 // Reset the pointer count if the previously released and/or cancelled pointer | 186 // Reset the pointer count if the previously released and/or cancelled pointer |
| 171 // was the last pointer in the event. | 187 // was the last pointer in the event. |
| 172 if (pointer_count == 1 && (action == ACTION_UP || action == ACTION_CANCEL)) | 188 if (pointer_count == 1 && (action == ACTION_UP || action == ACTION_CANCEL)) |
| 173 pointer_count = 0; | 189 pointer_count = 0; |
| 174 | 190 |
| 175 DCHECK_LT(pointer_count, static_cast<size_t>(MAX_POINTERS)); | 191 DCHECK_LT(pointer_count, static_cast<size_t>(MAX_POINTERS)); |
| 176 points[pointer_count++] = gfx::PointF(x, y); | 192 points[pointer_count++] = gfx::PointF(x, y); |
| 193 tool_types[pointer_count] = TOOL_TYPE_UNKNOWN; |
| 177 action = pointer_count > 1 ? ACTION_POINTER_DOWN : ACTION_DOWN; | 194 action = pointer_count > 1 ? ACTION_POINTER_DOWN : ACTION_DOWN; |
| 178 } | 195 } |
| 179 | 196 |
| 180 void MockMotionEvent::MovePoint(size_t index, float x, float y) { | 197 void MockMotionEvent::MovePoint(size_t index, float x, float y) { |
| 181 DCHECK_LT(index, pointer_count); | 198 DCHECK_LT(index, pointer_count); |
| 182 points[index] = gfx::PointF(x, y); | 199 points[index] = gfx::PointF(x, y); |
| 200 tool_types[index] = TOOL_TYPE_UNKNOWN; |
| 183 action = ACTION_MOVE; | 201 action = ACTION_MOVE; |
| 184 } | 202 } |
| 185 | 203 |
| 186 void MockMotionEvent::ReleasePoint() { | 204 void MockMotionEvent::ReleasePoint() { |
| 187 DCHECK_GT(pointer_count, 0U); | 205 DCHECK_GT(pointer_count, 0U); |
| 188 if (pointer_count > 1) { | 206 if (pointer_count > 1) { |
| 189 --pointer_count; | 207 --pointer_count; |
| 190 action = ACTION_POINTER_UP; | 208 action = ACTION_POINTER_UP; |
| 191 } else { | 209 } else { |
| 192 action = ACTION_UP; | 210 action = ACTION_UP; |
| 193 } | 211 } |
| 194 } | 212 } |
| 195 | 213 |
| 196 void MockMotionEvent::CancelPoint() { | 214 void MockMotionEvent::CancelPoint() { |
| 197 DCHECK_GT(pointer_count, 0U); | 215 DCHECK_GT(pointer_count, 0U); |
| 198 if (pointer_count > 1) | 216 if (pointer_count > 1) |
| 199 --pointer_count; | 217 --pointer_count; |
| 200 action = ACTION_CANCEL; | 218 action = ACTION_CANCEL; |
| 201 } | 219 } |
| 202 | 220 |
| 203 void MockMotionEvent::SetTouchMajor(float new_touch_major) { | 221 void MockMotionEvent::SetTouchMajor(float new_touch_major) { |
| 204 touch_major = new_touch_major; | 222 touch_major = new_touch_major; |
| 205 } | 223 } |
| 206 | 224 |
| 207 void MockMotionEvent::SetRawOffset(float raw_offset_x, float raw_offset_y) { | 225 void MockMotionEvent::SetRawOffset(float raw_offset_x, float raw_offset_y) { |
| 208 raw_offset.set_x(raw_offset_x); | 226 raw_offset.set_x(raw_offset_x); |
| 209 raw_offset.set_y(raw_offset_y); | 227 raw_offset.set_y(raw_offset_y); |
| 210 } | 228 } |
| 211 | 229 |
| 230 void MockMotionEvent::SetToolType(size_t pointer_index, ToolType tool_type) { |
| 231 DCHECK_LT(pointer_index, pointer_count); |
| 232 tool_types[pointer_index] = tool_type; |
| 233 } |
| 234 |
| 235 void MockMotionEvent::SetButtonState(int new_button_state) { |
| 236 button_state = new_button_state; |
| 237 } |
| 238 |
| 239 } // namespace test |
| 212 } // namespace ui | 240 } // namespace ui |
| OLD | NEW |