Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: ui/events/gesture_detection/mock_motion_event.cc

Issue 342633003: [Android] Select text when stylus first button is pressed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed signed unsigned comparison error Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "ui/events/gesture_detection/mock_motion_event.h"
6
7 #include "base/logging.h"
8
9 using base::TimeTicks;
10
11 namespace ui {
12
13 MockMotionEvent::MockMotionEvent()
14 : action(ACTION_CANCEL), pointer_count(1), touch_major(TOUCH_MAJOR), id(0) {
15 }
16
17 MockMotionEvent::MockMotionEvent(Action action)
18 : action(action), pointer_count(1), touch_major(TOUCH_MAJOR), id(0) {
19 }
20
21 MockMotionEvent::MockMotionEvent(Action action,
22 TimeTicks time,
23 float x,
24 float y)
25 : action(action),
26 pointer_count(1),
27 time(time),
28 touch_major(TOUCH_MAJOR),
29 id(0) {
30 points[0].SetPoint(x, y);
31 }
32
33 MockMotionEvent::MockMotionEvent(Action action,
34 TimeTicks time,
35 float x0,
36 float y0,
37 float x1,
38 float y1)
39 : action(action),
40 pointer_count(2),
41 time(time),
42 touch_major(TOUCH_MAJOR),
43 id(0) {
44 points[0].SetPoint(x0, y0);
45 points[1].SetPoint(x1, y1);
46 }
47
48 MockMotionEvent::MockMotionEvent(Action action,
49 TimeTicks time,
50 float x0,
51 float y0,
52 float x1,
53 float y1,
54 float x2,
55 float y2)
56 : action(action),
57 pointer_count(3),
58 time(time),
59 touch_major(TOUCH_MAJOR),
60 id(0) {
61 points[0].SetPoint(x0, y0);
62 points[1].SetPoint(x1, y1);
63 points[2].SetPoint(x2, y2);
64 }
65
66 MockMotionEvent::MockMotionEvent(const MockMotionEvent& other)
67 : action(other.action),
68 pointer_count(other.pointer_count),
69 time(other.time),
70 touch_major(other.touch_major),
71 id(other.GetId()) {
72 for (size_t i = 0; i < pointer_count; ++i)
73 points[i] = other.points[i];
74 }
75
76 MockMotionEvent::~MockMotionEvent() {}
77
78 MotionEvent::Action MockMotionEvent::GetAction() const { return action; }
79
80 int MockMotionEvent::GetActionIndex() const {
81 return static_cast<int>(pointer_count) - 1;
82 }
83
84 size_t MockMotionEvent::GetPointerCount() const { return pointer_count; }
85
86 int MockMotionEvent::GetId() const {
87 return id;
88 }
89
90 int MockMotionEvent::GetPointerId(size_t pointer_index) const {
91 DCHECK(pointer_index < pointer_count);
92 return static_cast<int>(pointer_index);
93 }
94
95 float MockMotionEvent::GetX(size_t pointer_index) const {
96 return points[pointer_index].x();
97 }
98
99 float MockMotionEvent::GetY(size_t pointer_index) const {
100 return points[pointer_index].y();
101 }
102
103 float MockMotionEvent::GetRawX(size_t pointer_index) const {
104 return GetX(pointer_index) + raw_offset.x();
105 }
106
107 float MockMotionEvent::GetRawY(size_t pointer_index) const {
108 return GetY(pointer_index) + raw_offset.y();
109 }
110
111 float MockMotionEvent::GetTouchMajor(size_t pointer_index) const {
112 return touch_major;
113 }
114
115 float MockMotionEvent::GetPressure(size_t pointer_index) const {
116 return 0;
117 }
118
119 TimeTicks MockMotionEvent::GetEventTime() const { return time; }
120
121 size_t MockMotionEvent::GetHistorySize() const { return 0; }
122
123 TimeTicks MockMotionEvent::GetHistoricalEventTime(
124 size_t historical_index) const {
125 return TimeTicks();
126 }
127
128 float MockMotionEvent::GetHistoricalTouchMajor(size_t pointer_index,
129 size_t historical_index) const {
130 return 0;
131 }
132
133 float MockMotionEvent::GetHistoricalX(size_t pointer_index,
134 size_t historical_index) const {
135 return 0;
136 }
137
138 float MockMotionEvent::GetHistoricalY(size_t pointer_index,
139 size_t historical_index) const {
140 return 0;
141 }
142
143 MotionEvent::ToolType MockMotionEvent::GetToolType(size_t pointer_index) const {
144 return MotionEvent::TOOL_TYPE_UNKNOWN;
145 }
146
147 int MockMotionEvent::GetButtonState() const {
148 return 0;
149 }
150
151 scoped_ptr<MotionEvent> MockMotionEvent::Clone() const {
152 return scoped_ptr<MotionEvent>(new MockMotionEvent(*this));
153 }
154
155 scoped_ptr<MotionEvent> MockMotionEvent::Cancel() const {
156 scoped_ptr<MockMotionEvent> cancel_event(new MockMotionEvent(*this));
157 cancel_event->action = MotionEvent::ACTION_CANCEL;
158 return cancel_event.PassAs<MotionEvent>();
159 }
160
161 void MockMotionEvent::SetId(int new_id) {
162 id = new_id;
163 }
164
165 void MockMotionEvent::SetTime(base::TimeTicks new_time) {
166 time = new_time;
167 }
168
169 void MockMotionEvent::PressPoint(float x, float y) {
170 // Reset the pointer count if the previously released and/or cancelled pointer
171 // was the last pointer in the event.
172 if (pointer_count == 1 && (action == ACTION_UP || action == ACTION_CANCEL))
173 pointer_count = 0;
174
175 DCHECK_LT(pointer_count, static_cast<size_t>(MAX_POINTERS));
176 points[pointer_count++] = gfx::PointF(x, y);
177 action = pointer_count > 1 ? ACTION_POINTER_DOWN : ACTION_DOWN;
178 }
179
180 void MockMotionEvent::MovePoint(size_t index, float x, float y) {
181 DCHECK_LT(index, pointer_count);
182 points[index] = gfx::PointF(x, y);
183 action = ACTION_MOVE;
184 }
185
186 void MockMotionEvent::ReleasePoint() {
187 DCHECK_GT(pointer_count, 0U);
188 if (pointer_count > 1) {
189 --pointer_count;
190 action = ACTION_POINTER_UP;
191 } else {
192 action = ACTION_UP;
193 }
194 }
195
196 void MockMotionEvent::CancelPoint() {
197 DCHECK_GT(pointer_count, 0U);
198 if (pointer_count > 1)
199 --pointer_count;
200 action = ACTION_CANCEL;
201 }
202
203 void MockMotionEvent::SetTouchMajor(float new_touch_major) {
204 touch_major = new_touch_major;
205 }
206
207 void MockMotionEvent::SetRawOffset(float raw_offset_x, float raw_offset_y) {
208 raw_offset.set_x(raw_offset_x);
209 raw_offset.set_y(raw_offset_y);
210 }
211
212 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698