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
3 // found in the LICENSE file.
5 #include "ui/events/gesture_detection/mock_motion_event.h"
7 #include "base/logging.h"
13 MockMotionEvent::MockMotionEvent()
14 : action(ACTION_CANCEL), pointer_count(1), touch_major(TOUCH_MAJOR), id(0) {
17 MockMotionEvent::MockMotionEvent(Action action)
18 : action(action), pointer_count(1), touch_major(TOUCH_MAJOR), id(0) {
21 MockMotionEvent::MockMotionEvent(Action action,
28 touch_major(TOUCH_MAJOR),
30 points[0].SetPoint(x, y);
33 MockMotionEvent::MockMotionEvent(Action action,
42 touch_major(TOUCH_MAJOR),
44 points[0].SetPoint(x0, y0);
45 points[1].SetPoint(x1, y1);
48 MockMotionEvent::MockMotionEvent(Action action,
59 touch_major(TOUCH_MAJOR),
61 points[0].SetPoint(x0, y0);
62 points[1].SetPoint(x1, y1);
63 points[2].SetPoint(x2, y2);
66 MockMotionEvent::MockMotionEvent(const MockMotionEvent& other)
67 : action(other.action),
68 pointer_count(other.pointer_count),
70 touch_major(other.touch_major),
72 for (size_t i = 0; i < pointer_count; ++i)
73 points[i] = other.points[i];
76 MockMotionEvent::~MockMotionEvent() {}
78 MotionEvent::Action MockMotionEvent::GetAction() const { return action; }
80 int MockMotionEvent::GetActionIndex() const {
81 return static_cast<int>(pointer_count) - 1;
84 size_t MockMotionEvent::GetPointerCount() const { return pointer_count; }
86 int MockMotionEvent::GetId() const {
90 int MockMotionEvent::GetPointerId(size_t pointer_index) const {
91 DCHECK(pointer_index < pointer_count);
92 return static_cast<int>(pointer_index);
95 float MockMotionEvent::GetX(size_t pointer_index) const {
96 return points[pointer_index].x();
99 float MockMotionEvent::GetY(size_t pointer_index) const {
100 return points[pointer_index].y();
103 float MockMotionEvent::GetRawX(size_t pointer_index) const {
104 return GetX(pointer_index) + raw_offset.x();
107 float MockMotionEvent::GetRawY(size_t pointer_index) const {
108 return GetY(pointer_index) + raw_offset.y();
111 float MockMotionEvent::GetTouchMajor(size_t pointer_index) const {
115 float MockMotionEvent::GetPressure(size_t pointer_index) const {
119 TimeTicks MockMotionEvent::GetEventTime() const { return time; }
121 size_t MockMotionEvent::GetHistorySize() const { return 0; }
123 TimeTicks MockMotionEvent::GetHistoricalEventTime(
124 size_t historical_index) const {
128 float MockMotionEvent::GetHistoricalTouchMajor(size_t pointer_index,
129 size_t historical_index) const {
133 float MockMotionEvent::GetHistoricalX(size_t pointer_index,
134 size_t historical_index) const {
138 float MockMotionEvent::GetHistoricalY(size_t pointer_index,
139 size_t historical_index) const {
143 scoped_ptr<MotionEvent> MockMotionEvent::Clone() const {
144 return scoped_ptr<MotionEvent>(new MockMotionEvent(*this));
147 scoped_ptr<MotionEvent> MockMotionEvent::Cancel() const {
148 scoped_ptr<MockMotionEvent> cancel_event(new MockMotionEvent(*this));
149 cancel_event->action = MotionEvent::ACTION_CANCEL;
150 return cancel_event.PassAs<MotionEvent>();
153 void MockMotionEvent::SetId(int new_id) {
157 void MockMotionEvent::SetTime(base::TimeTicks new_time) {
161 void MockMotionEvent::PressPoint(float x, float y) {
162 // Reset the pointer count if the previously released and/or cancelled pointer
163 // was the last pointer in the event.
164 if (pointer_count == 1 && (action == ACTION_UP || action == ACTION_CANCEL))
167 DCHECK_LT(pointer_count, static_cast<size_t>(MAX_POINTERS));
168 points[pointer_count++] = gfx::PointF(x, y);
169 action = pointer_count > 1 ? ACTION_POINTER_DOWN : ACTION_DOWN;
172 void MockMotionEvent::MovePoint(size_t index, float x, float y) {
173 DCHECK_LT(index, pointer_count);
174 points[index] = gfx::PointF(x, y);
175 action = ACTION_MOVE;
178 void MockMotionEvent::ReleasePoint() {
179 DCHECK_GT(pointer_count, 0U);
180 if (pointer_count > 1) {
182 action = ACTION_POINTER_UP;
188 void MockMotionEvent::CancelPoint() {
189 DCHECK_GT(pointer_count, 0U);
190 if (pointer_count > 1)
192 action = ACTION_CANCEL;
195 void MockMotionEvent::SetTouchMajor(float new_touch_major) {
196 touch_major = new_touch_major;
199 void MockMotionEvent::SetRawOffset(float raw_offset_x, float raw_offset_y) {
200 raw_offset.set_x(raw_offset_x);
201 raw_offset.set_y(raw_offset_y);