| 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" | 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 { | 12 namespace { |
| 13 const float kTouchMajor = 10.f; | 13 const float kTouchMajor = 10.f; |
| 14 } // namespace | 14 } // namespace |
| 15 | 15 |
| 16 MockMotionEvent::MockMotionEvent() | 16 MockMotionEvent::MockMotionEvent() |
| 17 : action(ACTION_CANCEL), pointer_count(1) {} | 17 : action(ACTION_CANCEL), pointer_count(1), id(0) {} |
| 18 | 18 |
| 19 MockMotionEvent::MockMotionEvent(Action action) | 19 MockMotionEvent::MockMotionEvent(Action action) |
| 20 : action(action), pointer_count(1) {} | 20 : action(action), pointer_count(1), id(0) {} |
| 21 | 21 |
| 22 MockMotionEvent::MockMotionEvent(Action action, | 22 MockMotionEvent::MockMotionEvent(Action action, |
| 23 TimeTicks time, | 23 TimeTicks time, |
| 24 float x, | 24 float x, |
| 25 float y) | 25 float y) |
| 26 : action(action), pointer_count(1), time(time) { | 26 : action(action), pointer_count(1), time(time), id(0) { |
| 27 points[0].SetPoint(x, y); | 27 points[0].SetPoint(x, y); |
| 28 } | 28 } |
| 29 | 29 |
| 30 MockMotionEvent::MockMotionEvent(Action action, | 30 MockMotionEvent::MockMotionEvent(Action action, |
| 31 TimeTicks time, | 31 TimeTicks time, |
| 32 float x0, | 32 float x0, |
| 33 float y0, | 33 float y0, |
| 34 float x1, | 34 float x1, |
| 35 float y1) | 35 float y1) |
| 36 : action(action), pointer_count(2), time(time) { | 36 : action(action), pointer_count(2), time(time), id(0) { |
| 37 points[0].SetPoint(x0, y0); | 37 points[0].SetPoint(x0, y0); |
| 38 points[1].SetPoint(x1, y1); | 38 points[1].SetPoint(x1, y1); |
| 39 } | 39 } |
| 40 | 40 |
| 41 MockMotionEvent::MockMotionEvent(const MockMotionEvent& other) | 41 MockMotionEvent::MockMotionEvent(const MockMotionEvent& other) |
| 42 : action(other.action), | 42 : action(other.action), |
| 43 pointer_count(other.pointer_count), | 43 pointer_count(other.pointer_count), |
| 44 time(other.time) { | 44 time(other.time), |
| 45 id(other.GetId()) { |
| 45 points[0] = other.points[0]; | 46 points[0] = other.points[0]; |
| 46 points[1] = other.points[1]; | 47 points[1] = other.points[1]; |
| 47 } | 48 } |
| 48 | 49 |
| 49 MockMotionEvent::~MockMotionEvent() {} | 50 MockMotionEvent::~MockMotionEvent() {} |
| 50 | 51 |
| 51 MotionEvent::Action MockMotionEvent::GetAction() const { return action; } | 52 MotionEvent::Action MockMotionEvent::GetAction() const { return action; } |
| 52 | 53 |
| 53 int MockMotionEvent::GetActionIndex() const { | 54 int MockMotionEvent::GetActionIndex() const { |
| 54 return static_cast<int>(pointer_count) - 1; | 55 return static_cast<int>(pointer_count) - 1; |
| 55 } | 56 } |
| 56 | 57 |
| 57 size_t MockMotionEvent::GetPointerCount() const { return pointer_count; } | 58 size_t MockMotionEvent::GetPointerCount() const { return pointer_count; } |
| 58 | 59 |
| 60 int MockMotionEvent::GetId() const { |
| 61 return id; |
| 62 } |
| 63 |
| 64 void MockMotionEvent::SetId(int new_id) { |
| 65 id = new_id; |
| 66 } |
| 67 |
| 59 int MockMotionEvent::GetPointerId(size_t pointer_index) const { | 68 int MockMotionEvent::GetPointerId(size_t pointer_index) const { |
| 69 DCHECK(pointer_index < pointer_count); |
| 60 return static_cast<int>(pointer_index); | 70 return static_cast<int>(pointer_index); |
| 61 } | 71 } |
| 62 | 72 |
| 63 float MockMotionEvent::GetX(size_t pointer_index) const { | 73 float MockMotionEvent::GetX(size_t pointer_index) const { |
| 64 return points[pointer_index].x(); | 74 return points[pointer_index].x(); |
| 65 } | 75 } |
| 66 | 76 |
| 67 float MockMotionEvent::GetY(size_t pointer_index) const { | 77 float MockMotionEvent::GetY(size_t pointer_index) const { |
| 68 return points[pointer_index].y(); | 78 return points[pointer_index].y(); |
| 69 } | 79 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 } | 148 } |
| 139 | 149 |
| 140 void MockMotionEvent::CancelPoint() { | 150 void MockMotionEvent::CancelPoint() { |
| 141 DCHECK_GT(pointer_count, 0U); | 151 DCHECK_GT(pointer_count, 0U); |
| 142 if (pointer_count > 1) | 152 if (pointer_count > 1) |
| 143 --pointer_count; | 153 --pointer_count; |
| 144 action = ACTION_CANCEL; | 154 action = ACTION_CANCEL; |
| 145 } | 155 } |
| 146 | 156 |
| 147 } // namespace ui | 157 } // namespace ui |
| OLD | NEW |