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

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

Issue 289283015: Extract touchscreen device management into a generic manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 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 | Annotate | Revision Log
« no previous file with comments | « ui/events/test/events_test_utils_x11.h ('k') | ui/events/x/device_data_manager.h » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/events_test_utils_x11.h" 5 #include "ui/events/test/events_test_utils_x11.h"
6 6
7 #include <X11/extensions/XI2.h> 7 #include <X11/extensions/XI2.h>
8 #include <X11/keysym.h> 8 #include <X11/keysym.h>
9 #include <X11/X.h> 9 #include <X11/X.h>
10 #include <X11/Xlib.h> 10 #include <X11/Xlib.h>
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 return Button1; 83 return Button1;
84 if (flags & ui::EF_MIDDLE_MOUSE_BUTTON) 84 if (flags & ui::EF_MIDDLE_MOUSE_BUTTON)
85 return Button2; 85 return Button2;
86 if (flags & ui::EF_RIGHT_MOUSE_BUTTON) 86 if (flags & ui::EF_RIGHT_MOUSE_BUTTON)
87 return Button3; 87 return Button3;
88 88
89 return 0; 89 return 0;
90 } 90 }
91 91
92 void InitValuatorsForXIDeviceEvent(XIDeviceEvent* xiev) { 92 void InitValuatorsForXIDeviceEvent(XIDeviceEvent* xiev) {
93 int valuator_count = ui::DeviceDataManager::DT_LAST_ENTRY; 93 int valuator_count = ui::DeviceDataManagerX11::DT_LAST_ENTRY;
94 xiev->valuators.mask_len = (valuator_count / 8) + 1; 94 xiev->valuators.mask_len = (valuator_count / 8) + 1;
95 xiev->valuators.mask = new unsigned char[xiev->valuators.mask_len]; 95 xiev->valuators.mask = new unsigned char[xiev->valuators.mask_len];
96 memset(xiev->valuators.mask, 0, xiev->valuators.mask_len); 96 memset(xiev->valuators.mask, 0, xiev->valuators.mask_len);
97 xiev->valuators.values = new double[valuator_count]; 97 xiev->valuators.values = new double[valuator_count];
98 } 98 }
99 99
100 XEvent* CreateXInput2Event(int deviceid, 100 XEvent* CreateXInput2Event(int deviceid,
101 int evtype, 101 int evtype,
102 int tracking_id, 102 int tracking_id,
103 const gfx::Point& location) { 103 const gfx::Point& location) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 196
197 void ScopedXI2Event::InitScrollEvent(int deviceid, 197 void ScopedXI2Event::InitScrollEvent(int deviceid,
198 int x_offset, 198 int x_offset,
199 int y_offset, 199 int y_offset,
200 int x_offset_ordinal, 200 int x_offset_ordinal,
201 int y_offset_ordinal, 201 int y_offset_ordinal,
202 int finger_count) { 202 int finger_count) {
203 event_.reset(CreateXInput2Event(deviceid, XI_Motion, 0, gfx::Point())); 203 event_.reset(CreateXInput2Event(deviceid, XI_Motion, 0, gfx::Point()));
204 204
205 Valuator valuators[] = { 205 Valuator valuators[] = {
206 Valuator(DeviceDataManager::DT_CMT_SCROLL_X, x_offset), 206 Valuator(DeviceDataManagerX11::DT_CMT_SCROLL_X, x_offset),
207 Valuator(DeviceDataManager::DT_CMT_SCROLL_Y, y_offset), 207 Valuator(DeviceDataManagerX11::DT_CMT_SCROLL_Y, y_offset),
208 Valuator(DeviceDataManager::DT_CMT_ORDINAL_X, x_offset_ordinal), 208 Valuator(DeviceDataManagerX11::DT_CMT_ORDINAL_X, x_offset_ordinal),
209 Valuator(DeviceDataManager::DT_CMT_ORDINAL_Y, y_offset_ordinal), 209 Valuator(DeviceDataManagerX11::DT_CMT_ORDINAL_Y, y_offset_ordinal),
210 Valuator(DeviceDataManager::DT_CMT_FINGER_COUNT, finger_count) 210 Valuator(DeviceDataManagerX11::DT_CMT_FINGER_COUNT, finger_count)
211 }; 211 };
212 SetUpValuators( 212 SetUpValuators(
213 std::vector<Valuator>(valuators, valuators + arraysize(valuators))); 213 std::vector<Valuator>(valuators, valuators + arraysize(valuators)));
214 } 214 }
215 215
216 void ScopedXI2Event::InitFlingScrollEvent(int deviceid, 216 void ScopedXI2Event::InitFlingScrollEvent(int deviceid,
217 int x_velocity, 217 int x_velocity,
218 int y_velocity, 218 int y_velocity,
219 int x_velocity_ordinal, 219 int x_velocity_ordinal,
220 int y_velocity_ordinal, 220 int y_velocity_ordinal,
221 bool is_cancel) { 221 bool is_cancel) {
222 event_.reset(CreateXInput2Event(deviceid, XI_Motion, deviceid, gfx::Point())); 222 event_.reset(CreateXInput2Event(deviceid, XI_Motion, deviceid, gfx::Point()));
223 223
224 Valuator valuators[] = { 224 Valuator valuators[] = {
225 Valuator(DeviceDataManager::DT_CMT_FLING_STATE, is_cancel ? 1 : 0), 225 Valuator(DeviceDataManagerX11::DT_CMT_FLING_STATE, is_cancel ? 1 : 0),
226 Valuator(DeviceDataManager::DT_CMT_FLING_Y, y_velocity), 226 Valuator(DeviceDataManagerX11::DT_CMT_FLING_Y, y_velocity),
227 Valuator(DeviceDataManager::DT_CMT_ORDINAL_Y, y_velocity_ordinal), 227 Valuator(DeviceDataManagerX11::DT_CMT_ORDINAL_Y, y_velocity_ordinal),
228 Valuator(DeviceDataManager::DT_CMT_FLING_X, x_velocity), 228 Valuator(DeviceDataManagerX11::DT_CMT_FLING_X, x_velocity),
229 Valuator(DeviceDataManager::DT_CMT_ORDINAL_X, x_velocity_ordinal) 229 Valuator(DeviceDataManagerX11::DT_CMT_ORDINAL_X, x_velocity_ordinal)
230 }; 230 };
231 231
232 SetUpValuators( 232 SetUpValuators(
233 std::vector<Valuator>(valuators, valuators + arraysize(valuators))); 233 std::vector<Valuator>(valuators, valuators + arraysize(valuators)));
234 } 234 }
235 235
236 void ScopedXI2Event::InitTouchEvent(int deviceid, 236 void ScopedXI2Event::InitTouchEvent(int deviceid,
237 int evtype, 237 int evtype,
238 int tracking_id, 238 int tracking_id,
239 const gfx::Point& location, 239 const gfx::Point& location,
240 const std::vector<Valuator>& valuators) { 240 const std::vector<Valuator>& valuators) {
241 event_.reset(CreateXInput2Event(deviceid, evtype, tracking_id, location)); 241 event_.reset(CreateXInput2Event(deviceid, evtype, tracking_id, location));
242 242
243 // If a timestamp was specified, setup the event. 243 // If a timestamp was specified, setup the event.
244 for (size_t i = 0; i < valuators.size(); ++i) { 244 for (size_t i = 0; i < valuators.size(); ++i) {
245 if (valuators[i].data_type == DeviceDataManager::DT_TOUCH_RAW_TIMESTAMP) { 245 if (valuators[i].data_type ==
246 DeviceDataManagerX11::DT_TOUCH_RAW_TIMESTAMP) {
246 SetUpValuators(valuators); 247 SetUpValuators(valuators);
247 return; 248 return;
248 } 249 }
249 } 250 }
250 251
251 // No timestamp was specified. Use |ui::EventTimeForNow()|. 252 // No timestamp was specified. Use |ui::EventTimeForNow()|.
252 std::vector<Valuator> valuators_with_time = valuators; 253 std::vector<Valuator> valuators_with_time = valuators;
253 valuators_with_time.push_back( 254 valuators_with_time.push_back(
254 Valuator(DeviceDataManager::DT_TOUCH_RAW_TIMESTAMP, 255 Valuator(DeviceDataManagerX11::DT_TOUCH_RAW_TIMESTAMP,
255 (ui::EventTimeForNow()).InMicroseconds())); 256 (ui::EventTimeForNow()).InMicroseconds()));
256 SetUpValuators(valuators_with_time); 257 SetUpValuators(valuators_with_time);
257 } 258 }
258 259
259 void ScopedXI2Event::SetUpValuators(const std::vector<Valuator>& valuators) { 260 void ScopedXI2Event::SetUpValuators(const std::vector<Valuator>& valuators) {
260 CHECK(event_.get()); 261 CHECK(event_.get());
261 CHECK_EQ(GenericEvent, event_->type); 262 CHECK_EQ(GenericEvent, event_->type);
262 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(event_->xcookie.data); 263 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(event_->xcookie.data);
263 InitValuatorsForXIDeviceEvent(xiev); 264 InitValuatorsForXIDeviceEvent(xiev);
264 ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance(); 265 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance();
265 for (size_t i = 0; i < valuators.size(); ++i) { 266 for (size_t i = 0; i < valuators.size(); ++i) {
266 manager->SetValuatorDataForTest(xiev, valuators[i].data_type, 267 manager->SetValuatorDataForTest(xiev, valuators[i].data_type,
267 valuators[i].value); 268 valuators[i].value);
268 } 269 }
269 } 270 }
270 271
271 void SetUpTouchPadForTest(unsigned int deviceid) { 272 void SetUpTouchPadForTest(unsigned int deviceid) {
272 std::vector<unsigned int> device_list; 273 std::vector<unsigned int> device_list;
273 device_list.push_back(deviceid); 274 device_list.push_back(deviceid);
274 275
275 TouchFactory::GetInstance()->SetPointerDeviceForTest(device_list); 276 TouchFactory::GetInstance()->SetPointerDeviceForTest(device_list);
276 ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance(); 277 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance();
277 manager->SetDeviceListForTest(std::vector<unsigned int>(), device_list); 278 manager->SetDeviceListForTest(std::vector<unsigned int>(), device_list);
278 } 279 }
279 280
280 void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices) { 281 void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices) {
281 TouchFactory::GetInstance()->SetTouchDeviceForTest(devices); 282 TouchFactory::GetInstance()->SetTouchDeviceForTest(devices);
282 ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance(); 283 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance();
283 manager->SetDeviceListForTest(devices, std::vector<unsigned int>()); 284 manager->SetDeviceListForTest(devices, std::vector<unsigned int>());
284 } 285 }
285 286
286 } // namespace ui 287 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/test/events_test_utils_x11.h ('k') | ui/events/x/device_data_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698