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

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: do not select text when two buttons are pressed 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
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 12
13 MockMotionEvent::MockMotionEvent() 13 MockMotionEvent::MockMotionEvent()
14 : action(ACTION_CANCEL), pointer_count(1), touch_major(TOUCH_MAJOR), id(0) { 14 : action(ACTION_CANCEL), pointer_count(1), touch_major(TOUCH_MAJOR), id(0),
15 button_state(0) {
15 } 16 }
16 17
17 MockMotionEvent::MockMotionEvent(Action action) 18 MockMotionEvent::MockMotionEvent(Action action)
18 : action(action), pointer_count(1), touch_major(TOUCH_MAJOR), id(0) { 19 : action(action), pointer_count(1), touch_major(TOUCH_MAJOR), id(0),
20 button_state(0) {
19 } 21 }
20 22
21 MockMotionEvent::MockMotionEvent(Action action, 23 MockMotionEvent::MockMotionEvent(Action action,
22 TimeTicks time, 24 TimeTicks time,
23 float x, 25 float x,
24 float y) 26 float y)
25 : action(action), 27 : action(action),
26 pointer_count(1), 28 pointer_count(1),
27 time(time), 29 time(time),
28 touch_major(TOUCH_MAJOR), 30 touch_major(TOUCH_MAJOR),
29 id(0) { 31 id(0),
32 button_state(0) {
30 points[0].SetPoint(x, y); 33 points[0].SetPoint(x, y);
34 tool_types[0] = TOOL_TYPE_UNKNOWN;
31 } 35 }
32 36
33 MockMotionEvent::MockMotionEvent(Action action, 37 MockMotionEvent::MockMotionEvent(Action action,
34 TimeTicks time, 38 TimeTicks time,
35 float x0, 39 float x0,
36 float y0, 40 float y0,
37 float x1, 41 float x1,
38 float y1) 42 float y1)
39 : action(action), 43 : action(action),
40 pointer_count(2), 44 pointer_count(2),
41 time(time), 45 time(time),
42 touch_major(TOUCH_MAJOR), 46 touch_major(TOUCH_MAJOR),
43 id(0) { 47 id(0),
48 button_state(0) {
44 points[0].SetPoint(x0, y0); 49 points[0].SetPoint(x0, y0);
50 tool_types[0] = TOOL_TYPE_UNKNOWN;
45 points[1].SetPoint(x1, y1); 51 points[1].SetPoint(x1, y1);
52 tool_types[1] = TOOL_TYPE_UNKNOWN;
46 } 53 }
47 54
48 MockMotionEvent::MockMotionEvent(Action action, 55 MockMotionEvent::MockMotionEvent(Action action,
49 TimeTicks time, 56 TimeTicks time,
50 float x0, 57 float x0,
51 float y0, 58 float y0,
52 float x1, 59 float x1,
53 float y1, 60 float y1,
54 float x2, 61 float x2,
55 float y2) 62 float y2)
56 : action(action), 63 : action(action),
57 pointer_count(3), 64 pointer_count(3),
58 time(time), 65 time(time),
59 touch_major(TOUCH_MAJOR), 66 touch_major(TOUCH_MAJOR),
60 id(0) { 67 id(0),
68 button_state(0) {
61 points[0].SetPoint(x0, y0); 69 points[0].SetPoint(x0, y0);
70 tool_types[0] = TOOL_TYPE_UNKNOWN;
62 points[1].SetPoint(x1, y1); 71 points[1].SetPoint(x1, y1);
72 tool_types[1] = TOOL_TYPE_UNKNOWN;
63 points[2].SetPoint(x2, y2); 73 points[2].SetPoint(x2, y2);
74 tool_types[2] = TOOL_TYPE_UNKNOWN;
64 } 75 }
65 76
66 MockMotionEvent::MockMotionEvent(const MockMotionEvent& other) 77 MockMotionEvent::MockMotionEvent(const MockMotionEvent& other)
67 : action(other.action), 78 : action(other.action),
68 pointer_count(other.pointer_count), 79 pointer_count(other.pointer_count),
69 time(other.time), 80 time(other.time),
70 touch_major(other.touch_major), 81 touch_major(other.touch_major),
71 id(other.GetId()) { 82 id(other.GetId()),
72 for (size_t i = 0; i < pointer_count; ++i) 83 button_state(other.GetButtonState()) {
84 for (size_t i = 0; i < pointer_count; ++i) {
73 points[i] = other.points[i]; 85 points[i] = other.points[i];
86 tool_types[i] = other.tool_types[i];
87 }
74 } 88 }
75 89
76 MockMotionEvent::~MockMotionEvent() {} 90 MockMotionEvent::~MockMotionEvent() {}
77 91
78 MotionEvent::Action MockMotionEvent::GetAction() const { return action; } 92 MotionEvent::Action MockMotionEvent::GetAction() const { return action; }
79 93
80 int MockMotionEvent::GetActionIndex() const { 94 int MockMotionEvent::GetActionIndex() const {
81 return static_cast<int>(pointer_count) - 1; 95 return static_cast<int>(pointer_count) - 1;
82 } 96 }
83 97
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 size_t historical_index) const { 148 size_t historical_index) const {
135 return 0; 149 return 0;
136 } 150 }
137 151
138 float MockMotionEvent::GetHistoricalY(size_t pointer_index, 152 float MockMotionEvent::GetHistoricalY(size_t pointer_index,
139 size_t historical_index) const { 153 size_t historical_index) const {
140 return 0; 154 return 0;
141 } 155 }
142 156
143 MotionEvent::ToolType MockMotionEvent::GetToolType(size_t pointer_index) const { 157 MotionEvent::ToolType MockMotionEvent::GetToolType(size_t pointer_index) const {
144 return MotionEvent::TOOL_TYPE_UNKNOWN; 158 DCHECK_GT(pointer_count, pointer_index);
jdduke (slow) 2014/06/24 15:38:37 Nit: For consistency make this "DCHECK_LT(pointer_
Changwan Ryu 2014/06/25 07:26:21 Done.
159 return tool_types[pointer_index];
145 } 160 }
146 161
147 int MockMotionEvent::GetButtonState() const { 162 int MockMotionEvent::GetButtonState() const {
148 return 0; 163 return button_state;
149 } 164 }
150 165
151 scoped_ptr<MotionEvent> MockMotionEvent::Clone() const { 166 scoped_ptr<MotionEvent> MockMotionEvent::Clone() const {
152 return scoped_ptr<MotionEvent>(new MockMotionEvent(*this)); 167 return scoped_ptr<MotionEvent>(new MockMotionEvent(*this));
153 } 168 }
154 169
155 scoped_ptr<MotionEvent> MockMotionEvent::Cancel() const { 170 scoped_ptr<MotionEvent> MockMotionEvent::Cancel() const {
156 scoped_ptr<MockMotionEvent> cancel_event(new MockMotionEvent(*this)); 171 scoped_ptr<MockMotionEvent> cancel_event(new MockMotionEvent(*this));
157 cancel_event->action = MotionEvent::ACTION_CANCEL; 172 cancel_event->action = MotionEvent::ACTION_CANCEL;
158 return cancel_event.PassAs<MotionEvent>(); 173 return cancel_event.PassAs<MotionEvent>();
159 } 174 }
160 175
161 void MockMotionEvent::SetId(int new_id) { 176 void MockMotionEvent::SetId(int new_id) {
162 id = new_id; 177 id = new_id;
163 } 178 }
164 179
165 void MockMotionEvent::SetTime(base::TimeTicks new_time) { 180 void MockMotionEvent::SetTime(base::TimeTicks new_time) {
166 time = new_time; 181 time = new_time;
167 } 182 }
168 183
169 void MockMotionEvent::PressPoint(float x, float y) { 184 void MockMotionEvent::PressPoint(float x, float y) {
170 // Reset the pointer count if the previously released and/or cancelled pointer 185 // Reset the pointer count if the previously released and/or cancelled pointer
171 // was the last pointer in the event. 186 // was the last pointer in the event.
172 if (pointer_count == 1 && (action == ACTION_UP || action == ACTION_CANCEL)) 187 if (pointer_count == 1 && (action == ACTION_UP || action == ACTION_CANCEL))
173 pointer_count = 0; 188 pointer_count = 0;
174 189
175 DCHECK_LT(pointer_count, static_cast<size_t>(MAX_POINTERS)); 190 DCHECK_LT(pointer_count, static_cast<size_t>(MAX_POINTERS));
176 points[pointer_count++] = gfx::PointF(x, y); 191 points[pointer_count++] = gfx::PointF(x, y);
192 tool_types[pointer_count] = TOOL_TYPE_UNKNOWN;
177 action = pointer_count > 1 ? ACTION_POINTER_DOWN : ACTION_DOWN; 193 action = pointer_count > 1 ? ACTION_POINTER_DOWN : ACTION_DOWN;
178 } 194 }
179 195
180 void MockMotionEvent::MovePoint(size_t index, float x, float y) { 196 void MockMotionEvent::MovePoint(size_t index, float x, float y) {
181 DCHECK_LT(index, pointer_count); 197 DCHECK_LT(index, pointer_count);
182 points[index] = gfx::PointF(x, y); 198 points[index] = gfx::PointF(x, y);
199 tool_types[index] = TOOL_TYPE_UNKNOWN;
183 action = ACTION_MOVE; 200 action = ACTION_MOVE;
184 } 201 }
185 202
186 void MockMotionEvent::ReleasePoint() { 203 void MockMotionEvent::ReleasePoint() {
187 DCHECK_GT(pointer_count, 0U); 204 DCHECK_GT(pointer_count, 0U);
188 if (pointer_count > 1) { 205 if (pointer_count > 1) {
189 --pointer_count; 206 --pointer_count;
190 action = ACTION_POINTER_UP; 207 action = ACTION_POINTER_UP;
191 } else { 208 } else {
192 action = ACTION_UP; 209 action = ACTION_UP;
193 } 210 }
194 } 211 }
195 212
196 void MockMotionEvent::CancelPoint() { 213 void MockMotionEvent::CancelPoint() {
197 DCHECK_GT(pointer_count, 0U); 214 DCHECK_GT(pointer_count, 0U);
198 if (pointer_count > 1) 215 if (pointer_count > 1)
199 --pointer_count; 216 --pointer_count;
200 action = ACTION_CANCEL; 217 action = ACTION_CANCEL;
201 } 218 }
202 219
203 void MockMotionEvent::SetTouchMajor(float new_touch_major) { 220 void MockMotionEvent::SetTouchMajor(float new_touch_major) {
204 touch_major = new_touch_major; 221 touch_major = new_touch_major;
205 } 222 }
206 223
207 void MockMotionEvent::SetRawOffset(float raw_offset_x, float raw_offset_y) { 224 void MockMotionEvent::SetRawOffset(float raw_offset_x, float raw_offset_y) {
208 raw_offset.set_x(raw_offset_x); 225 raw_offset.set_x(raw_offset_x);
209 raw_offset.set_y(raw_offset_y); 226 raw_offset.set_y(raw_offset_y);
210 } 227 }
211 228
229 void MockMotionEvent::SetToolType(size_t index, ToolType tool_type) {
230 DCHECK_GT(pointer_count, index);
231 tool_types[index] = tool_type;
232 }
233
234 void MockMotionEvent::SetButtonState(int new_button_state) {
235 button_state = new_button_state;
236 }
237
212 } // namespace ui 238 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698