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

Side by Side Diff: ui/events/devices/x11/touch_factory_x11.cc

Issue 1071193002: Change device IDs from unsigned to signed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more test fixes Created 5 years, 8 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/devices/x11/touch_factory_x11.h ('k') | ui/events/test/events_test_utils_x11.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/devices/x11/touch_factory_x11.h" 5 #include "ui/events/devices/x11/touch_factory_x11.h"
6 6
7 #include <X11/Xatom.h> 7 #include <X11/Xatom.h>
8 #include <X11/cursorfont.h> 8 #include <X11/cursorfont.h>
9 #include <X11/extensions/XInput.h> 9 #include <X11/extensions/XInput.h>
10 #include <X11/extensions/XInput2.h> 10 #include <X11/extensions/XInput2.h>
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 void TouchFactory::SetTouchDeviceListFromCommandLine() { 56 void TouchFactory::SetTouchDeviceListFromCommandLine() {
57 // Get a list of pointer-devices that should be treated as touch-devices. 57 // Get a list of pointer-devices that should be treated as touch-devices.
58 // This is primarily used for testing/debugging touch-event processing when a 58 // This is primarily used for testing/debugging touch-event processing when a
59 // touch-device isn't available. 59 // touch-device isn't available.
60 std::string touch_devices = 60 std::string touch_devices =
61 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 61 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
62 switches::kTouchDevices); 62 switches::kTouchDevices);
63 63
64 if (!touch_devices.empty()) { 64 if (!touch_devices.empty()) {
65 std::vector<std::string> devs; 65 std::vector<std::string> devs;
66 std::vector<unsigned int> device_ids; 66 std::vector<int> device_ids;
67 unsigned int devid; 67 int devid;
68 base::SplitString(touch_devices, ',', &devs); 68 base::SplitString(touch_devices, ',', &devs);
69 for (std::vector<std::string>::iterator iter = devs.begin(); 69 for (std::vector<std::string>::iterator iter = devs.begin();
70 iter != devs.end(); ++iter) { 70 iter != devs.end(); ++iter) {
71 if (base::StringToInt(*iter, reinterpret_cast<int*>(&devid))) 71 if (base::StringToInt(*iter, reinterpret_cast<int*>(&devid)))
72 device_ids.push_back(devid); 72 device_ids.push_back(devid);
73 else 73 else
74 DLOG(WARNING) << "Invalid touch-device id: " << *iter; 74 DLOG(WARNING) << "Invalid touch-device id: " << *iter;
75 } 75 }
76 ui::TouchFactory::GetInstance()->SetTouchDeviceList(device_ids); 76 ui::TouchFactory::GetInstance()->SetTouchDeviceList(device_ids);
77 } 77 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 #endif 209 #endif
210 210
211 XIEventMask evmask; 211 XIEventMask evmask;
212 evmask.deviceid = XIAllDevices; 212 evmask.deviceid = XIAllDevices;
213 evmask.mask_len = sizeof(mask); 213 evmask.mask_len = sizeof(mask);
214 evmask.mask = mask; 214 evmask.mask = mask;
215 XISelectEvents(display, window, &evmask, 1); 215 XISelectEvents(display, window, &evmask, 1);
216 XFlush(display); 216 XFlush(display);
217 } 217 }
218 218
219 void TouchFactory::SetTouchDeviceList( 219 void TouchFactory::SetTouchDeviceList(const std::vector<int>& devices) {
220 const std::vector<unsigned int>& devices) {
221 touch_device_lookup_.reset(); 220 touch_device_lookup_.reset();
222 touch_device_list_.clear(); 221 touch_device_list_.clear();
223 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); 222 for (std::vector<int>::const_iterator iter = devices.begin();
224 iter != devices.end(); ++iter) { 223 iter != devices.end(); ++iter) {
225 DCHECK(*iter < touch_device_lookup_.size()); 224 DCHECK((*iter >= 0) &&
225 (static_cast<size_t>(*iter) < touch_device_lookup_.size()));
Daniel Erat 2015/04/09 19:55:27 one more comment: since this is duplicated a few t
kpschoedel 2015/04/09 20:12:32 Done.
226 touch_device_lookup_[*iter] = true; 226 touch_device_lookup_[*iter] = true;
227 touch_device_list_[*iter] = false; 227 touch_device_list_[*iter] = false;
228 } 228 }
229 } 229 }
230 230
231 bool TouchFactory::IsTouchDevice(unsigned deviceid) const { 231 bool TouchFactory::IsTouchDevice(int deviceid) const {
232 return deviceid < touch_device_lookup_.size() ? 232 return deviceid >= 0 &&
233 touch_device_lookup_[deviceid] : false; 233 static_cast<size_t>(deviceid) < touch_device_lookup_.size()
234 ? touch_device_lookup_[deviceid]
235 : false;
234 } 236 }
235 237
236 bool TouchFactory::IsMultiTouchDevice(unsigned int deviceid) const { 238 bool TouchFactory::IsMultiTouchDevice(int deviceid) const {
237 return (deviceid < touch_device_lookup_.size() && 239 return (deviceid >= 0 &&
238 touch_device_lookup_[deviceid]) ? 240 static_cast<size_t>(deviceid) < touch_device_lookup_.size() &&
239 touch_device_list_.find(deviceid)->second : 241 touch_device_lookup_[deviceid])
240 false; 242 ? touch_device_list_.find(deviceid)->second
243 : false;
241 } 244 }
242 245
243 bool TouchFactory::QuerySlotForTrackingID(uint32 tracking_id, int* slot) { 246 bool TouchFactory::QuerySlotForTrackingID(uint32 tracking_id, int* slot) {
244 if (!id_generator_.HasGeneratedIDFor(tracking_id)) 247 if (!id_generator_.HasGeneratedIDFor(tracking_id))
245 return false; 248 return false;
246 *slot = static_cast<int>(id_generator_.GetGeneratedID(tracking_id)); 249 *slot = static_cast<int>(id_generator_.GetGeneratedID(tracking_id));
247 return true; 250 return true;
248 } 251 }
249 252
250 int TouchFactory::GetSlotForTrackingID(uint32 tracking_id) { 253 int TouchFactory::GetSlotForTrackingID(uint32 tracking_id) {
(...skipping 11 matching lines...) Expand all
262 void TouchFactory::ResetForTest() { 265 void TouchFactory::ResetForTest() {
263 pointer_device_lookup_.reset(); 266 pointer_device_lookup_.reset();
264 touch_device_lookup_.reset(); 267 touch_device_lookup_.reset();
265 touch_events_disabled_ = false; 268 touch_events_disabled_ = false;
266 touch_device_list_.clear(); 269 touch_device_list_.clear();
267 touchscreen_ids_.clear(); 270 touchscreen_ids_.clear();
268 id_generator_.ResetForTest(); 271 id_generator_.ResetForTest();
269 } 272 }
270 273
271 void TouchFactory::SetTouchDeviceForTest( 274 void TouchFactory::SetTouchDeviceForTest(
272 const std::vector<unsigned int>& devices) { 275 const std::vector<int>& devices) {
273 touch_device_lookup_.reset(); 276 touch_device_lookup_.reset();
274 touch_device_list_.clear(); 277 touch_device_list_.clear();
275 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); 278 for (std::vector<int>::const_iterator iter = devices.begin();
276 iter != devices.end(); ++iter) { 279 iter != devices.end(); ++iter) {
277 DCHECK(*iter < touch_device_lookup_.size()); 280 DCHECK((*iter >= 0) &&
281 (static_cast<size_t>(*iter) < touch_device_lookup_.size()));
278 touch_device_lookup_[*iter] = true; 282 touch_device_lookup_[*iter] = true;
279 touch_device_list_[*iter] = true; 283 touch_device_list_[*iter] = true;
280 } 284 }
281 touch_events_disabled_ = false; 285 touch_events_disabled_ = false;
282 } 286 }
283 287
284 void TouchFactory::SetPointerDeviceForTest( 288 void TouchFactory::SetPointerDeviceForTest(
285 const std::vector<unsigned int>& devices) { 289 const std::vector<int>& devices) {
286 pointer_device_lookup_.reset(); 290 pointer_device_lookup_.reset();
287 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); 291 for (std::vector<int>::const_iterator iter = devices.begin();
288 iter != devices.end(); ++iter) { 292 iter != devices.end(); ++iter) {
289 pointer_device_lookup_[*iter] = true; 293 pointer_device_lookup_[*iter] = true;
290 } 294 }
291 } 295 }
292 296
293 void TouchFactory::CacheTouchscreenIds(Display* display, int device_id) { 297 void TouchFactory::CacheTouchscreenIds(Display* display, int device_id) {
294 XDevice* device = XOpenDevice(display, device_id); 298 XDevice* device = XOpenDevice(display, device_id);
295 if (!device) 299 if (!device)
296 return; 300 return;
297 301
(...skipping 25 matching lines...) Expand all
323 if (ptr[0] || ptr[1]) 327 if (ptr[0] || ptr[1])
324 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); 328 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1]));
325 } 329 }
326 XFree(prop_return); 330 XFree(prop_return);
327 } 331 }
328 332
329 XCloseDevice(display, device); 333 XCloseDevice(display, device);
330 } 334 }
331 335
332 } // namespace ui 336 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/devices/x11/touch_factory_x11.h ('k') | ui/events/test/events_test_utils_x11.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698