Improve YouCompleteMe handling of Blink header without source files.
[chromium-blink-merge.git] / ui / events / test / mock_motion_event.cc
blob98fceae1a8ed9d27e92c6ba6dd5c179074413ddb
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/test/mock_motion_event.h"
7 #include "base/logging.h"
9 using base::TimeTicks;
11 namespace ui {
12 namespace test {
14 MockMotionEvent::MockMotionEvent()
15 : action(ACTION_CANCEL), pointer_count(1), touch_major(TOUCH_MAJOR), id(0),
16 button_state(0) {
19 MockMotionEvent::MockMotionEvent(Action action)
20 : action(action), pointer_count(1), touch_major(TOUCH_MAJOR), id(0),
21 button_state(0) {
24 MockMotionEvent::MockMotionEvent(Action action,
25 TimeTicks time,
26 float x,
27 float y)
28 : action(action),
29 pointer_count(1),
30 time(time),
31 touch_major(TOUCH_MAJOR),
32 id(0),
33 button_state(0) {
34 points[0].SetPoint(x, y);
35 tool_types[0] = TOOL_TYPE_UNKNOWN;
38 MockMotionEvent::MockMotionEvent(Action action,
39 TimeTicks time,
40 float x0,
41 float y0,
42 float x1,
43 float y1)
44 : action(action),
45 pointer_count(2),
46 time(time),
47 touch_major(TOUCH_MAJOR),
48 id(0),
49 button_state(0) {
50 points[0].SetPoint(x0, y0);
51 tool_types[0] = TOOL_TYPE_UNKNOWN;
52 points[1].SetPoint(x1, y1);
53 tool_types[1] = TOOL_TYPE_UNKNOWN;
56 MockMotionEvent::MockMotionEvent(Action action,
57 TimeTicks time,
58 float x0,
59 float y0,
60 float x1,
61 float y1,
62 float x2,
63 float y2)
64 : action(action),
65 pointer_count(3),
66 time(time),
67 touch_major(TOUCH_MAJOR),
68 id(0),
69 button_state(0) {
70 points[0].SetPoint(x0, y0);
71 tool_types[0] = TOOL_TYPE_UNKNOWN;
72 points[1].SetPoint(x1, y1);
73 tool_types[1] = TOOL_TYPE_UNKNOWN;
74 points[2].SetPoint(x2, y2);
75 tool_types[2] = TOOL_TYPE_UNKNOWN;
78 MockMotionEvent::MockMotionEvent(const MockMotionEvent& other)
79 : action(other.action),
80 pointer_count(other.pointer_count),
81 time(other.time),
82 touch_major(other.touch_major),
83 id(other.GetId()),
84 button_state(other.GetButtonState()) {
85 for (size_t i = 0; i < pointer_count; ++i) {
86 points[i] = other.points[i];
87 tool_types[i] = other.tool_types[i];
91 MockMotionEvent::~MockMotionEvent() {}
93 MotionEvent::Action MockMotionEvent::GetAction() const { return action; }
95 int MockMotionEvent::GetActionIndex() const {
96 return static_cast<int>(pointer_count) - 1;
99 size_t MockMotionEvent::GetPointerCount() const { return pointer_count; }
101 int MockMotionEvent::GetId() const {
102 return id;
105 int MockMotionEvent::GetPointerId(size_t pointer_index) const {
106 DCHECK(pointer_index < pointer_count);
107 return static_cast<int>(pointer_index);
110 float MockMotionEvent::GetX(size_t pointer_index) const {
111 return points[pointer_index].x();
114 float MockMotionEvent::GetY(size_t pointer_index) const {
115 return points[pointer_index].y();
118 float MockMotionEvent::GetRawX(size_t pointer_index) const {
119 return GetX(pointer_index) + raw_offset.x();
122 float MockMotionEvent::GetRawY(size_t pointer_index) const {
123 return GetY(pointer_index) + raw_offset.y();
126 float MockMotionEvent::GetTouchMajor(size_t pointer_index) const {
127 return touch_major;
130 float MockMotionEvent::GetPressure(size_t pointer_index) const {
131 return 0;
134 TimeTicks MockMotionEvent::GetEventTime() const { return time; }
136 size_t MockMotionEvent::GetHistorySize() const { return 0; }
138 TimeTicks MockMotionEvent::GetHistoricalEventTime(
139 size_t historical_index) const {
140 return TimeTicks();
143 float MockMotionEvent::GetHistoricalTouchMajor(size_t pointer_index,
144 size_t historical_index) const {
145 return 0;
148 float MockMotionEvent::GetHistoricalX(size_t pointer_index,
149 size_t historical_index) const {
150 return 0;
153 float MockMotionEvent::GetHistoricalY(size_t pointer_index,
154 size_t historical_index) const {
155 return 0;
158 MotionEvent::ToolType MockMotionEvent::GetToolType(size_t pointer_index) const {
159 DCHECK_LT(pointer_index, pointer_count);
160 return tool_types[pointer_index];
163 int MockMotionEvent::GetButtonState() const {
164 return button_state;
167 scoped_ptr<MotionEvent> MockMotionEvent::Clone() const {
168 return scoped_ptr<MotionEvent>(new MockMotionEvent(*this));
171 scoped_ptr<MotionEvent> MockMotionEvent::Cancel() const {
172 scoped_ptr<MockMotionEvent> cancel_event(new MockMotionEvent(*this));
173 cancel_event->action = MotionEvent::ACTION_CANCEL;
174 return cancel_event.PassAs<MotionEvent>();
177 void MockMotionEvent::SetId(int new_id) {
178 id = new_id;
181 void MockMotionEvent::SetTime(base::TimeTicks new_time) {
182 time = new_time;
185 void MockMotionEvent::PressPoint(float x, float y) {
186 // Reset the pointer count if the previously released and/or cancelled pointer
187 // was the last pointer in the event.
188 if (pointer_count == 1 && (action == ACTION_UP || action == ACTION_CANCEL))
189 pointer_count = 0;
191 DCHECK_LT(pointer_count, static_cast<size_t>(MAX_POINTERS));
192 points[pointer_count++] = gfx::PointF(x, y);
193 tool_types[pointer_count] = TOOL_TYPE_UNKNOWN;
194 action = pointer_count > 1 ? ACTION_POINTER_DOWN : ACTION_DOWN;
197 void MockMotionEvent::MovePoint(size_t index, float x, float y) {
198 DCHECK_LT(index, pointer_count);
199 points[index] = gfx::PointF(x, y);
200 tool_types[index] = TOOL_TYPE_UNKNOWN;
201 action = ACTION_MOVE;
204 void MockMotionEvent::ReleasePoint() {
205 DCHECK_GT(pointer_count, 0U);
206 if (pointer_count > 1) {
207 --pointer_count;
208 action = ACTION_POINTER_UP;
209 } else {
210 action = ACTION_UP;
214 void MockMotionEvent::CancelPoint() {
215 DCHECK_GT(pointer_count, 0U);
216 if (pointer_count > 1)
217 --pointer_count;
218 action = ACTION_CANCEL;
221 void MockMotionEvent::SetTouchMajor(float new_touch_major) {
222 touch_major = new_touch_major;
225 void MockMotionEvent::SetRawOffset(float raw_offset_x, float raw_offset_y) {
226 raw_offset.set_x(raw_offset_x);
227 raw_offset.set_y(raw_offset_y);
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;
235 void MockMotionEvent::SetButtonState(int new_button_state) {
236 button_state = new_button_state;
239 } // namespace test
240 } // namespace ui