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

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

Issue 1087893003: Support longpress drag selection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review Created 5 years, 7 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/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/gesture_detection/bitset_32.h" 10 #include "ui/events/gesture_detection/bitset_32.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 PushPointer(positions[i].x(), positions[i].y()); 83 PushPointer(positions[i].x(), positions[i].y());
84 } 84 }
85 85
86 MockMotionEvent::MockMotionEvent(const MockMotionEvent& other) 86 MockMotionEvent::MockMotionEvent(const MockMotionEvent& other)
87 : MotionEventGeneric(other) { 87 : MotionEventGeneric(other) {
88 } 88 }
89 89
90 MockMotionEvent::~MockMotionEvent() { 90 MockMotionEvent::~MockMotionEvent() {
91 } 91 }
92 92
93 void MockMotionEvent::PressPoint(float x, float y) { 93 MockMotionEvent& MockMotionEvent::PressPoint(float x, float y) {
94 ResolvePointers(); 94 ResolvePointers();
95 PushPointer(x, y); 95 PushPointer(x, y);
96 if (GetPointerCount() > 1) { 96 if (GetPointerCount() > 1) {
97 set_action_index(static_cast<int>(GetPointerCount()) - 1); 97 set_action_index(static_cast<int>(GetPointerCount()) - 1);
98 set_action(ACTION_POINTER_DOWN); 98 set_action(ACTION_POINTER_DOWN);
99 } else { 99 } else {
100 set_action(ACTION_DOWN); 100 set_action(ACTION_DOWN);
101 } 101 }
102 return *this;
102 } 103 }
103 104
104 void MockMotionEvent::MovePoint(size_t index, float x, float y) { 105 MockMotionEvent& MockMotionEvent::MovePoint(size_t index, float x, float y) {
105 ResolvePointers(); 106 ResolvePointers();
106 DCHECK_LT(index, GetPointerCount()); 107 DCHECK_LT(index, GetPointerCount());
107 PointerProperties& p = pointer(index); 108 PointerProperties& p = pointer(index);
108 float dx = x - p.x; 109 float dx = x - p.x;
109 float dy = x - p.y; 110 float dy = x - p.y;
110 p.x = x; 111 p.x = x;
111 p.y = y; 112 p.y = y;
112 p.raw_x += dx; 113 p.raw_x += dx;
113 p.raw_y += dy; 114 p.raw_y += dy;
114 set_action(ACTION_MOVE); 115 set_action(ACTION_MOVE);
116 return *this;
115 } 117 }
116 118
117 void MockMotionEvent::ReleasePoint() { 119 MockMotionEvent& MockMotionEvent::ReleasePoint() {
118 ResolvePointers(); 120 ResolvePointers();
119 DCHECK_GT(GetPointerCount(), 0U); 121 DCHECK_GT(GetPointerCount(), 0U);
120 if (GetPointerCount() > 1) { 122 if (GetPointerCount() > 1) {
121 set_action_index(static_cast<int>(GetPointerCount()) - 1); 123 set_action_index(static_cast<int>(GetPointerCount()) - 1);
122 set_action(ACTION_POINTER_UP); 124 set_action(ACTION_POINTER_UP);
123 } else { 125 } else {
124 set_action(ACTION_UP); 126 set_action(ACTION_UP);
125 } 127 }
128 return *this;
126 } 129 }
127 130
128 void MockMotionEvent::CancelPoint() { 131 MockMotionEvent& MockMotionEvent::CancelPoint() {
129 ResolvePointers(); 132 ResolvePointers();
130 DCHECK_GT(GetPointerCount(), 0U); 133 DCHECK_GT(GetPointerCount(), 0U);
131 set_action(ACTION_CANCEL); 134 set_action(ACTION_CANCEL);
135 return *this;
132 } 136 }
133 137
134 void MockMotionEvent::SetTouchMajor(float new_touch_major) { 138 MockMotionEvent& MockMotionEvent::SetTouchMajor(float new_touch_major) {
135 for (size_t i = 0; i < GetPointerCount(); ++i) 139 for (size_t i = 0; i < GetPointerCount(); ++i)
136 pointer(i).touch_major = new_touch_major; 140 pointer(i).touch_major = new_touch_major;
141 return *this;
137 } 142 }
138 143
139 void MockMotionEvent::SetRawOffset(float raw_offset_x, float raw_offset_y) { 144 MockMotionEvent& MockMotionEvent::SetRawOffset(float raw_offset_x,
145 float raw_offset_y) {
140 for (size_t i = 0; i < GetPointerCount(); ++i) { 146 for (size_t i = 0; i < GetPointerCount(); ++i) {
141 pointer(i).raw_x = pointer(i).x + raw_offset_x; 147 pointer(i).raw_x = pointer(i).x + raw_offset_x;
142 pointer(i).raw_y = pointer(i).y + raw_offset_y; 148 pointer(i).raw_y = pointer(i).y + raw_offset_y;
143 } 149 }
150 return *this;
144 } 151 }
145 152
146 void MockMotionEvent::SetToolType(size_t pointer_index, ToolType tool_type) { 153 MockMotionEvent& MockMotionEvent::SetToolType(size_t pointer_index,
154 ToolType tool_type) {
147 DCHECK_LT(pointer_index, GetPointerCount()); 155 DCHECK_LT(pointer_index, GetPointerCount());
148 pointer(pointer_index).tool_type = tool_type; 156 pointer(pointer_index).tool_type = tool_type;
157 return *this;
149 } 158 }
150 159
151 void MockMotionEvent::PushPointer(float x, float y) { 160 void MockMotionEvent::PushPointer(float x, float y) {
152 MotionEventGeneric::PushPointer( 161 MotionEventGeneric::PushPointer(
153 CreatePointer(x, y, static_cast<int>(GetPointerCount()))); 162 CreatePointer(x, y, static_cast<int>(GetPointerCount())));
154 } 163 }
155 164
156 void MockMotionEvent::ResolvePointers() { 165 void MockMotionEvent::ResolvePointers() {
157 set_action_index(-1); 166 set_action_index(-1);
158 switch (GetAction()) { 167 switch (GetAction()) {
159 case ACTION_UP: 168 case ACTION_UP:
160 case ACTION_POINTER_UP: 169 case ACTION_POINTER_UP:
161 case ACTION_CANCEL: 170 case ACTION_CANCEL:
162 PopPointer(); 171 PopPointer();
163 return; 172 return;
164 default: 173 default:
165 break; 174 break;
166 } 175 }
167 } 176 }
168 177
169 void MockMotionEvent::SetPrimaryPointerId(int id) { 178 MockMotionEvent& MockMotionEvent::SetPrimaryPointerId(int id) {
170 DCHECK_GT(GetPointerCount(), 0U); 179 DCHECK_GT(GetPointerCount(), 0U);
171 pointer(0).id = id; 180 pointer(0).id = id;
181 return *this;
172 } 182 }
173 183
174 std::string ToString(const MotionEvent& event) { 184 std::string ToString(const MotionEvent& event) {
175 std::stringstream ss; 185 std::stringstream ss;
176 ss << "MotionEvent {" 186 ss << "MotionEvent {"
177 << "\n Action: " << event.GetAction(); 187 << "\n Action: " << event.GetAction();
178 if (event.GetAction() == MotionEvent::ACTION_POINTER_DOWN || 188 if (event.GetAction() == MotionEvent::ACTION_POINTER_DOWN ||
179 event.GetAction() == MotionEvent::ACTION_POINTER_UP) 189 event.GetAction() == MotionEvent::ACTION_POINTER_UP)
180 ss << "\n ActionIndex: " << event.GetActionIndex(); 190 ss << "\n ActionIndex: " << event.GetActionIndex();
181 ss << "\n Flags: " << event.GetFlags() 191 ss << "\n Flags: " << event.GetFlags()
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 ss << ", "; 228 ss << ", ";
219 } 229 }
220 ss << "]\n}"; 230 ss << "]\n}";
221 } 231 }
222 232
223 return ss.str(); 233 return ss.str();
224 } 234 }
225 235
226 } // namespace test 236 } // namespace test
227 } // namespace ui 237 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698