| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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(IsValidDevice(*iter)); |
| 226 touch_device_lookup_[*iter] = true; | 225 touch_device_lookup_[*iter] = true; |
| 227 touch_device_list_[*iter] = false; | 226 touch_device_list_[*iter] = false; |
| 228 } | 227 } |
| 229 } | 228 } |
| 230 | 229 |
| 231 bool TouchFactory::IsTouchDevice(unsigned deviceid) const { | 230 bool TouchFactory::IsValidDevice(int deviceid) const { |
| 232 return deviceid < touch_device_lookup_.size() ? | 231 return (deviceid >= 0) && |
| 233 touch_device_lookup_[deviceid] : false; | 232 (static_cast<size_t>(deviceid) < touch_device_lookup_.size()); |
| 234 } | 233 } |
| 235 | 234 |
| 236 bool TouchFactory::IsMultiTouchDevice(unsigned int deviceid) const { | 235 bool TouchFactory::IsTouchDevice(int deviceid) const { |
| 237 return (deviceid < touch_device_lookup_.size() && | 236 return IsValidDevice(deviceid) ? touch_device_lookup_[deviceid] : false; |
| 238 touch_device_lookup_[deviceid]) ? | 237 } |
| 239 touch_device_list_.find(deviceid)->second : | 238 |
| 240 false; | 239 bool TouchFactory::IsMultiTouchDevice(int deviceid) const { |
| 240 return (IsValidDevice(deviceid) && touch_device_lookup_[deviceid]) |
| 241 ? touch_device_list_.find(deviceid)->second |
| 242 : false; |
| 241 } | 243 } |
| 242 | 244 |
| 243 bool TouchFactory::QuerySlotForTrackingID(uint32 tracking_id, int* slot) { | 245 bool TouchFactory::QuerySlotForTrackingID(uint32 tracking_id, int* slot) { |
| 244 if (!id_generator_.HasGeneratedIDFor(tracking_id)) | 246 if (!id_generator_.HasGeneratedIDFor(tracking_id)) |
| 245 return false; | 247 return false; |
| 246 *slot = static_cast<int>(id_generator_.GetGeneratedID(tracking_id)); | 248 *slot = static_cast<int>(id_generator_.GetGeneratedID(tracking_id)); |
| 247 return true; | 249 return true; |
| 248 } | 250 } |
| 249 | 251 |
| 250 int TouchFactory::GetSlotForTrackingID(uint32 tracking_id) { | 252 int TouchFactory::GetSlotForTrackingID(uint32 tracking_id) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 262 void TouchFactory::ResetForTest() { | 264 void TouchFactory::ResetForTest() { |
| 263 pointer_device_lookup_.reset(); | 265 pointer_device_lookup_.reset(); |
| 264 touch_device_lookup_.reset(); | 266 touch_device_lookup_.reset(); |
| 265 touch_events_disabled_ = false; | 267 touch_events_disabled_ = false; |
| 266 touch_device_list_.clear(); | 268 touch_device_list_.clear(); |
| 267 touchscreen_ids_.clear(); | 269 touchscreen_ids_.clear(); |
| 268 id_generator_.ResetForTest(); | 270 id_generator_.ResetForTest(); |
| 269 } | 271 } |
| 270 | 272 |
| 271 void TouchFactory::SetTouchDeviceForTest( | 273 void TouchFactory::SetTouchDeviceForTest( |
| 272 const std::vector<unsigned int>& devices) { | 274 const std::vector<int>& devices) { |
| 273 touch_device_lookup_.reset(); | 275 touch_device_lookup_.reset(); |
| 274 touch_device_list_.clear(); | 276 touch_device_list_.clear(); |
| 275 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); | 277 for (std::vector<int>::const_iterator iter = devices.begin(); |
| 276 iter != devices.end(); ++iter) { | 278 iter != devices.end(); ++iter) { |
| 277 DCHECK(*iter < touch_device_lookup_.size()); | 279 DCHECK(IsValidDevice(*iter)); |
| 278 touch_device_lookup_[*iter] = true; | 280 touch_device_lookup_[*iter] = true; |
| 279 touch_device_list_[*iter] = true; | 281 touch_device_list_[*iter] = true; |
| 280 } | 282 } |
| 281 touch_events_disabled_ = false; | 283 touch_events_disabled_ = false; |
| 282 } | 284 } |
| 283 | 285 |
| 284 void TouchFactory::SetPointerDeviceForTest( | 286 void TouchFactory::SetPointerDeviceForTest( |
| 285 const std::vector<unsigned int>& devices) { | 287 const std::vector<int>& devices) { |
| 286 pointer_device_lookup_.reset(); | 288 pointer_device_lookup_.reset(); |
| 287 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); | 289 for (std::vector<int>::const_iterator iter = devices.begin(); |
| 288 iter != devices.end(); ++iter) { | 290 iter != devices.end(); ++iter) { |
| 289 pointer_device_lookup_[*iter] = true; | 291 pointer_device_lookup_[*iter] = true; |
| 290 } | 292 } |
| 291 } | 293 } |
| 292 | 294 |
| 293 void TouchFactory::CacheTouchscreenIds(Display* display, int device_id) { | 295 void TouchFactory::CacheTouchscreenIds(Display* display, int device_id) { |
| 294 XDevice* device = XOpenDevice(display, device_id); | 296 XDevice* device = XOpenDevice(display, device_id); |
| 295 if (!device) | 297 if (!device) |
| 296 return; | 298 return; |
| 297 | 299 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 323 if (ptr[0] || ptr[1]) | 325 if (ptr[0] || ptr[1]) |
| 324 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); | 326 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); |
| 325 } | 327 } |
| 326 XFree(prop_return); | 328 XFree(prop_return); |
| 327 } | 329 } |
| 328 | 330 |
| 329 XCloseDevice(display, device); | 331 XCloseDevice(display, device); |
| 330 } | 332 } |
| 331 | 333 |
| 332 } // namespace ui | 334 } // namespace ui |
| OLD | NEW |