| 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/test/mock_motion_event.h" | 5 #include "ui/events/test/motion_event_test_utils.h" |
| 6 |
| 7 #include <sstream> |
| 6 | 8 |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ui/events/gesture_detection/bitset_32.h" |
| 11 #include "ui/events/gesture_detection/motion_event.h" |
| 8 | 12 |
| 9 using base::TimeTicks; | 13 using base::TimeTicks; |
| 10 | 14 |
| 11 namespace ui { | 15 namespace ui { |
| 12 namespace test { | 16 namespace test { |
| 13 namespace { | 17 namespace { |
| 14 | 18 |
| 15 PointerProperties CreatePointer() { | 19 PointerProperties CreatePointer() { |
| 16 PointerProperties pointer; | 20 PointerProperties pointer; |
| 17 pointer.touch_major = MockMotionEvent::TOUCH_MAJOR; | 21 pointer.touch_major = MockMotionEvent::TOUCH_MAJOR; |
| 18 return pointer; | 22 return pointer; |
| 19 } | 23 } |
| 20 | 24 |
| 21 PointerProperties CreatePointer(float x, float y, int id) { | 25 PointerProperties CreatePointer(float x, float y, int id) { |
| 22 PointerProperties pointer(x, y); | 26 PointerProperties pointer(x, y, MockMotionEvent::TOUCH_MAJOR); |
| 23 pointer.touch_major = MockMotionEvent::TOUCH_MAJOR; | |
| 24 pointer.id = id; | 27 pointer.id = id; |
| 25 return pointer; | 28 return pointer; |
| 26 } | 29 } |
| 27 | 30 |
| 28 | |
| 29 } // namespace | 31 } // namespace |
| 30 | 32 |
| 31 MockMotionEvent::MockMotionEvent() | 33 MockMotionEvent::MockMotionEvent() |
| 32 : MotionEventGeneric(ACTION_CANCEL, base::TimeTicks(), CreatePointer()) { | 34 : MotionEventGeneric(ACTION_CANCEL, base::TimeTicks(), CreatePointer()) { |
| 33 } | 35 } |
| 34 | 36 |
| 35 MockMotionEvent::MockMotionEvent(Action action) | 37 MockMotionEvent::MockMotionEvent(Action action) |
| 36 : MotionEventGeneric(action, base::TimeTicks(), CreatePointer()) { | 38 : MotionEventGeneric(action, base::TimeTicks(), CreatePointer()) { |
| 37 } | 39 } |
| 38 | 40 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 if (action == ACTION_POINTER_UP || action == ACTION_POINTER_DOWN) | 80 if (action == ACTION_POINTER_UP || action == ACTION_POINTER_DOWN) |
| 79 set_action_index(static_cast<int>(positions.size()) - 1); | 81 set_action_index(static_cast<int>(positions.size()) - 1); |
| 80 for (size_t i = 0; i < positions.size(); ++i) | 82 for (size_t i = 0; i < positions.size(); ++i) |
| 81 PushPointer(positions[i].x(), positions[i].y()); | 83 PushPointer(positions[i].x(), positions[i].y()); |
| 82 } | 84 } |
| 83 | 85 |
| 84 MockMotionEvent::MockMotionEvent(const MockMotionEvent& other) | 86 MockMotionEvent::MockMotionEvent(const MockMotionEvent& other) |
| 85 : MotionEventGeneric(other) { | 87 : MotionEventGeneric(other) { |
| 86 } | 88 } |
| 87 | 89 |
| 88 MockMotionEvent::~MockMotionEvent() {} | 90 MockMotionEvent::~MockMotionEvent() { |
| 89 | |
| 90 scoped_ptr<MotionEvent> MockMotionEvent::Clone() const { | |
| 91 return scoped_ptr<MotionEvent>(new MockMotionEvent(*this)); | |
| 92 } | |
| 93 | |
| 94 scoped_ptr<MotionEvent> MockMotionEvent::Cancel() const { | |
| 95 scoped_ptr<MockMotionEvent> event(new MockMotionEvent(*this)); | |
| 96 event->set_action(MotionEvent::ACTION_CANCEL); | |
| 97 return event.Pass(); | |
| 98 } | 91 } |
| 99 | 92 |
| 100 void MockMotionEvent::PressPoint(float x, float y) { | 93 void MockMotionEvent::PressPoint(float x, float y) { |
| 101 ResolvePointers(); | 94 ResolvePointers(); |
| 102 PushPointer(x, y); | 95 PushPointer(x, y); |
| 103 if (GetPointerCount() > 1) { | 96 if (GetPointerCount() > 1) { |
| 104 set_action_index(static_cast<int>(GetPointerCount()) - 1); | 97 set_action_index(static_cast<int>(GetPointerCount()) - 1); |
| 105 set_action(ACTION_POINTER_DOWN); | 98 set_action(ACTION_POINTER_DOWN); |
| 106 } else { | 99 } else { |
| 107 set_action(ACTION_DOWN); | 100 set_action(ACTION_DOWN); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 case ACTION_UP: | 159 case ACTION_UP: |
| 167 case ACTION_POINTER_UP: | 160 case ACTION_POINTER_UP: |
| 168 case ACTION_CANCEL: | 161 case ACTION_CANCEL: |
| 169 PopPointer(); | 162 PopPointer(); |
| 170 return; | 163 return; |
| 171 default: | 164 default: |
| 172 break; | 165 break; |
| 173 } | 166 } |
| 174 } | 167 } |
| 175 | 168 |
| 169 std::string ToString(const MotionEvent& event) { |
| 170 std::stringstream ss; |
| 171 ss << "MotionEvent {" |
| 172 << "\n ID: " << event.GetId() << "\n Action: " << event.GetAction() |
| 173 << "\n ActionIndex: " << event.GetActionIndex() |
| 174 << "\n Flags: " << event.GetFlags() |
| 175 << "\n ButtonState: " << event.GetButtonState() << "\n Pointers: ["; |
| 176 const size_t pointer_count = event.GetPointerCount(); |
| 177 const size_t history_size = event.GetHistorySize(); |
| 178 |
| 179 BitSet32 pointer_ids; |
| 180 for (size_t i = 0; i < pointer_count; ++i) { |
| 181 pointer_ids.mark_bit(event.GetPointerId(i)); |
| 182 |
| 183 // Print the pointers sorted by id. |
| 184 while (!pointer_ids.is_empty()) { |
| 185 int pi = event.FindPointerIndexOfId(pointer_ids.first_marked_bit()); |
| 186 DCHECK_GE(pi, 0); |
| 187 pointer_ids.clear_first_marked_bit(); |
| 188 ss << "{" |
| 189 << "\n Pos: (" << event.GetX(pi) << ", " << event.GetY(pi) << ")" |
| 190 << "\n RawPos: (" << event.GetX(pi) << ", " << event.GetY(pi) << ")" |
| 191 << "\n Size: (" << event.GetTouchMajor(pi) << ", " |
| 192 << event.GetTouchMinor(pi) << ")" |
| 193 << "\n Orientation: " << event.GetOrientation(pi) |
| 194 << "\n Pressure: " << event.GetOrientation(pi) |
| 195 << "\n Tool: " << event.GetToolType(pi); |
| 196 if (history_size) { |
| 197 ss << "\n History: ["; |
| 198 for (size_t h = 0; h < history_size; ++h) { |
| 199 ss << "\n { " << event.GetHistoricalX(pi, h) << ", " |
| 200 << event.GetHistoricalY(pi, h) << ", " |
| 201 << event.GetHistoricalTouchMajor(pi, h) << ", " |
| 202 << event.GetHistoricalEventTime(pi).ToInternalValue() << " }"; |
| 203 if (h + 1 < history_size) |
| 204 ss << ","; |
| 205 } |
| 206 ss << "\n ]"; |
| 207 } |
| 208 ss << "\n }"; |
| 209 if (i + 1 < pointer_count) |
| 210 ss << ", "; |
| 211 } |
| 212 ss << "]\n}"; |
| 213 } |
| 214 |
| 215 return ss.str(); |
| 216 } |
| 217 |
| 176 } // namespace test | 218 } // namespace test |
| 177 } // namespace ui | 219 } // namespace ui |
| OLD | NEW |