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

Side by Side Diff: ui/events/test/motion_event_test_utils.cc

Issue 2175803002: The helper functions for slop region check and subtraction are modified. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « ui/events/test/motion_event_test_utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/test/motion_event_test_utils.h" 5 #include "ui/events/test/motion_event_test_utils.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "ui/events/base_event_utils.h" 10 #include "ui/events/base_event_utils.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 float dy = x - p.y; 112 float dy = x - p.y;
113 p.x = x; 113 p.x = x;
114 p.y = y; 114 p.y = y;
115 p.raw_x += dx; 115 p.raw_x += dx;
116 p.raw_y += dy; 116 p.raw_y += dy;
117 set_action(ACTION_MOVE); 117 set_action(ACTION_MOVE);
118 return *this; 118 return *this;
119 } 119 }
120 120
121 MockMotionEvent& MockMotionEvent::ReleasePoint() { 121 MockMotionEvent& MockMotionEvent::ReleasePoint() {
122 DCHECK_GT(GetPointerCount(), 0U);
123 switch (GetAction()) {
124 // If the previous action is one of those who need removing a pointer in
125 // UpdatePointersAndID, then the last index will be GetPointerCount() - 2.
126 case ACTION_POINTER_UP:
127 case ACTION_UP:
128 case ACTION_CANCEL:
129 return ReleasePointAtIndex(GetPointerCount() - 2);
130 break;
131 default:
132 break;
133 }
134 return ReleasePointAtIndex(GetPointerCount() - 1);
135 }
136
137 MockMotionEvent& MockMotionEvent::ReleasePointAtIndex(size_t index) {
122 UpdatePointersAndID(); 138 UpdatePointersAndID();
123 DCHECK_GT(GetPointerCount(), 0U); 139 DCHECK_LT(index, GetPointerCount());
124 if (GetPointerCount() > 1) { 140 if (GetPointerCount() > 1) {
125 set_action_index(static_cast<int>(GetPointerCount()) - 1); 141 set_action_index(static_cast<int>(index));
126 set_action(ACTION_POINTER_UP); 142 set_action(ACTION_POINTER_UP);
127 } else { 143 } else {
128 set_action(ACTION_UP); 144 set_action(ACTION_UP);
129 } 145 }
130 return *this; 146 return *this;
131 } 147 }
132 148
133 MockMotionEvent& MockMotionEvent::CancelPoint() { 149 MockMotionEvent& MockMotionEvent::CancelPoint() {
134 UpdatePointersAndID(); 150 UpdatePointersAndID();
135 DCHECK_GT(GetPointerCount(), 0U); 151 DCHECK_GT(GetPointerCount(), 0U);
(...skipping 22 matching lines...) Expand all
158 pointer(pointer_index).tool_type = tool_type; 174 pointer(pointer_index).tool_type = tool_type;
159 return *this; 175 return *this;
160 } 176 }
161 177
162 void MockMotionEvent::PushPointer(float x, float y) { 178 void MockMotionEvent::PushPointer(float x, float y) {
163 MotionEventGeneric::PushPointer( 179 MotionEventGeneric::PushPointer(
164 CreatePointer(x, y, static_cast<int>(GetPointerCount()))); 180 CreatePointer(x, y, static_cast<int>(GetPointerCount())));
165 } 181 }
166 182
167 void MockMotionEvent::UpdatePointersAndID() { 183 void MockMotionEvent::UpdatePointersAndID() {
168 set_action_index(-1);
169 set_unique_event_id(ui::GetNextTouchEventId()); 184 set_unique_event_id(ui::GetNextTouchEventId());
170 switch (GetAction()) { 185 switch (GetAction()) {
186 case ACTION_POINTER_UP: {
187 int index = GetActionIndex();
188 DCHECK_LT(index, static_cast<int>(GetPointerCount()));
189 RemovePointerAt(index);
190 break;
191 }
171 case ACTION_UP: 192 case ACTION_UP:
172 case ACTION_POINTER_UP:
173 case ACTION_CANCEL: 193 case ACTION_CANCEL:
174 PopPointer(); 194 PopPointer();
175 return; 195 break;
176 default: 196 default:
177 break; 197 break;
178 } 198 }
199 set_action_index(-1);
179 } 200 }
180 201
181 MockMotionEvent& MockMotionEvent::SetPrimaryPointerId(int id) { 202 MockMotionEvent& MockMotionEvent::SetPrimaryPointerId(int id) {
182 DCHECK_GT(GetPointerCount(), 0U); 203 DCHECK_GT(GetPointerCount(), 0U);
183 pointer(0).id = id; 204 pointer(0).id = id;
184 return *this; 205 return *this;
185 } 206 }
186 207
187 std::string ToString(const MotionEvent& event) { 208 std::string ToString(const MotionEvent& event) {
188 std::stringstream ss; 209 std::stringstream ss;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 ss << ", "; 253 ss << ", ";
233 } 254 }
234 ss << "]\n}"; 255 ss << "]\n}";
235 } 256 }
236 257
237 return ss.str(); 258 return ss.str();
238 } 259 }
239 260
240 } // namespace test 261 } // namespace test
241 } // namespace ui 262 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/test/motion_event_test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698