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

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

Powered by Google App Engine
This is Rietveld 408576698