Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <X11/Xatom.h> | 8 #include <X11/Xatom.h> |
| 9 #include <X11/cursorfont.h> | 9 #include <X11/cursorfont.h> |
| 10 #include <X11/extensions/XInput.h> | 10 #include <X11/extensions/XInput.h> |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 device_ids.push_back(devid); | 67 device_ids.push_back(devid); |
| 68 else | 68 else |
| 69 DLOG(WARNING) << "Invalid touch-device id: " << dev.as_string(); | 69 DLOG(WARNING) << "Invalid touch-device id: " << dev.as_string(); |
| 70 } | 70 } |
| 71 ui::TouchFactory::GetInstance()->SetTouchDeviceList(device_ids); | 71 ui::TouchFactory::GetInstance()->SetTouchDeviceList(device_ids); |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 void TouchFactory::UpdateDeviceList(XDisplay* display) { | 75 void TouchFactory::UpdateDeviceList(XDisplay* display) { |
| 76 // Detect touch devices. | 76 // Detect touch devices. |
| 77 touch_device_lookup_.reset(); | |
| 78 touch_device_list_.clear(); | 77 touch_device_list_.clear(); |
| 79 touchscreen_ids_.clear(); | 78 touchscreen_ids_.clear(); |
| 80 | 79 |
| 81 if (!DeviceDataManagerX11::GetInstance()->IsXInput2Available()) | 80 if (!DeviceDataManagerX11::GetInstance()->IsXInput2Available()) |
| 82 return; | 81 return; |
| 83 | 82 |
| 84 // Instead of asking X for the list of devices all the time, let's maintain a | 83 // Instead of asking X for the list of devices all the time, let's maintain a |
| 85 // list of pointer devices we care about. | 84 // list of pointer devices we care about. |
| 86 // It should not be necessary to select for slave devices. XInput2 provides | 85 // It should not be necessary to select for slave devices. XInput2 provides |
| 87 // enough information to the event callback to decide which slave device | 86 // enough information to the event callback to decide which slave device |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 98 DeviceListCacheX11::GetInstance()->GetXI2DeviceList(display); | 97 DeviceListCacheX11::GetInstance()->GetXI2DeviceList(display); |
| 99 for (int i = 0; i < xi_dev_list.count; i++) { | 98 for (int i = 0; i < xi_dev_list.count; i++) { |
| 100 const XIDeviceInfo& devinfo = xi_dev_list[i]; | 99 const XIDeviceInfo& devinfo = xi_dev_list[i]; |
| 101 if (devinfo.use == XIFloatingSlave || devinfo.use == XIMasterPointer) { | 100 if (devinfo.use == XIFloatingSlave || devinfo.use == XIMasterPointer) { |
| 102 for (int k = 0; k < devinfo.num_classes; ++k) { | 101 for (int k = 0; k < devinfo.num_classes; ++k) { |
| 103 XIAnyClassInfo* xiclassinfo = devinfo.classes[k]; | 102 XIAnyClassInfo* xiclassinfo = devinfo.classes[k]; |
| 104 if (xiclassinfo->type == XITouchClass) { | 103 if (xiclassinfo->type == XITouchClass) { |
| 105 XITouchClassInfo* tci = | 104 XITouchClassInfo* tci = |
| 106 reinterpret_cast<XITouchClassInfo*>(xiclassinfo); | 105 reinterpret_cast<XITouchClassInfo*>(xiclassinfo); |
| 107 // Only care direct touch device (such as touch screen) right now | 106 // Only care direct touch device (such as touch screen) right now |
| 108 if (tci->mode == XIDirectTouch) { | 107 if (tci->mode == XIDirectTouch) |
| 109 touch_device_lookup_[devinfo.deviceid] = true; | |
| 110 touch_device_list_[devinfo.deviceid] = true; | 108 touch_device_list_[devinfo.deviceid] = true; |
| 111 } | |
| 112 } | 109 } |
| 113 } | 110 } |
| 114 pointer_device_lookup_[devinfo.deviceid] = true; | 111 pointer_device_lookup_[devinfo.deviceid] = true; |
| 115 } else if (devinfo.use == XIMasterKeyboard) { | 112 } else if (devinfo.use == XIMasterKeyboard) { |
| 116 virtual_core_keyboard_device_ = devinfo.deviceid; | 113 virtual_core_keyboard_device_ = devinfo.deviceid; |
| 117 } | 114 } |
| 118 | 115 |
| 119 if (devinfo.use == XIFloatingSlave || devinfo.use == XISlavePointer) { | 116 if (devinfo.use == XIFloatingSlave || devinfo.use == XISlavePointer) { |
| 120 for (int k = 0; k < devinfo.num_classes; ++k) { | 117 for (int k = 0; k < devinfo.num_classes; ++k) { |
| 121 XIAnyClassInfo* xiclassinfo = devinfo.classes[k]; | 118 XIAnyClassInfo* xiclassinfo = devinfo.classes[k]; |
| 122 if (xiclassinfo->type == XITouchClass) { | 119 if (xiclassinfo->type == XITouchClass) { |
| 123 XITouchClassInfo* tci = | 120 XITouchClassInfo* tci = |
| 124 reinterpret_cast<XITouchClassInfo*>(xiclassinfo); | 121 reinterpret_cast<XITouchClassInfo*>(xiclassinfo); |
| 125 // Only care direct touch device (such as touch screen) right now | 122 // Only care direct touch device (such as touch screen) right now |
| 126 if (tci->mode == XIDirectTouch) { | 123 if (tci->mode == XIDirectTouch) { |
| 127 CacheTouchscreenIds(devinfo.deviceid); | 124 CacheTouchscreenIds(devinfo.deviceid); |
| 128 if (devinfo.use == XISlavePointer) { | 125 if (devinfo.use == XISlavePointer) { |
| 129 device_master_id_list_[devinfo.deviceid] = devinfo.attachment; | 126 device_master_id_list_[devinfo.deviceid] = devinfo.attachment; |
| 130 // If the slave device is direct touch device, we also set its | 127 // If the slave device is direct touch device, we also set its |
| 131 // master device to be touch device. | 128 // master device to be touch device. |
| 132 touch_device_lookup_[devinfo.attachment] = true; | |
| 133 touch_device_list_[devinfo.attachment] = true; | 129 touch_device_list_[devinfo.attachment] = true; |
| 134 } | 130 } |
| 135 } | 131 } |
| 136 } | 132 } |
| 137 } | 133 } |
| 138 } | 134 } |
| 139 } | 135 } |
| 140 } | 136 } |
| 141 | 137 |
| 142 bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) { | 138 bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 | 221 |
| 226 XIEventMask evmask; | 222 XIEventMask evmask; |
| 227 evmask.deviceid = XIAllDevices; | 223 evmask.deviceid = XIAllDevices; |
| 228 evmask.mask_len = sizeof(mask); | 224 evmask.mask_len = sizeof(mask); |
| 229 evmask.mask = mask; | 225 evmask.mask = mask; |
| 230 XISelectEvents(display, window, &evmask, 1); | 226 XISelectEvents(display, window, &evmask, 1); |
| 231 XFlush(display); | 227 XFlush(display); |
| 232 } | 228 } |
| 233 | 229 |
| 234 void TouchFactory::SetTouchDeviceList(const std::vector<int>& devices) { | 230 void TouchFactory::SetTouchDeviceList(const std::vector<int>& devices) { |
| 235 touch_device_lookup_.reset(); | |
| 236 touch_device_list_.clear(); | 231 touch_device_list_.clear(); |
| 237 for (int deviceid : devices) { | 232 for (int deviceid : devices) { |
| 238 DCHECK(IsValidDevice(deviceid)); | 233 DCHECK(IsValidDevice(deviceid)); |
| 239 touch_device_lookup_[deviceid] = true; | |
| 240 touch_device_list_[deviceid] = false; | 234 touch_device_list_[deviceid] = false; |
| 241 if (device_master_id_list_.find(deviceid) != device_master_id_list_.end()) { | 235 if (device_master_id_list_.find(deviceid) != device_master_id_list_.end()) { |
| 242 // When we set the device through the "--touch-devices" flag to slave | 236 // When we set the device through the "--touch-devices" flag to slave |
| 243 // touch device, we also set its master device to be touch device. | 237 // touch device, we also set its master device to be touch device. |
| 244 touch_device_lookup_[device_master_id_list_[deviceid]] = true; | |
| 245 touch_device_list_[device_master_id_list_[deviceid]] = false; | 238 touch_device_list_[device_master_id_list_[deviceid]] = false; |
| 246 } | 239 } |
| 247 } | 240 } |
| 248 } | 241 } |
| 249 | 242 |
| 250 bool TouchFactory::IsValidDevice(int deviceid) const { | 243 bool TouchFactory::IsValidDevice(int deviceid) const { |
| 251 return (deviceid >= 0) && | 244 return deviceid >= 0; |
|
sadrul
2016/12/08 17:53:16
Should we check size of |touch_device_list_| inste
| |
| 252 (static_cast<size_t>(deviceid) < touch_device_lookup_.size()); | |
| 253 } | 245 } |
| 254 | 246 |
| 255 bool TouchFactory::IsTouchDevice(int deviceid) const { | 247 bool TouchFactory::IsTouchDevice(int deviceid) const { |
| 256 return IsValidDevice(deviceid) ? touch_device_lookup_[deviceid] : false; | 248 return IsValidDevice(deviceid) && (touch_device_list_.count(deviceid) > 0); |
| 257 } | 249 } |
| 258 | 250 |
| 259 bool TouchFactory::IsMultiTouchDevice(int deviceid) const { | 251 bool TouchFactory::IsMultiTouchDevice(int deviceid) const { |
| 260 return (IsValidDevice(deviceid) && touch_device_lookup_[deviceid]) | 252 return IsTouchDevice(deviceid) |
| 261 ? touch_device_list_.find(deviceid)->second | 253 ? touch_device_list_.find(deviceid)->second |
| 262 : false; | 254 : false; |
| 263 } | 255 } |
| 264 | 256 |
| 265 bool TouchFactory::QuerySlotForTrackingID(uint32_t tracking_id, int* slot) { | 257 bool TouchFactory::QuerySlotForTrackingID(uint32_t tracking_id, int* slot) { |
| 266 if (!id_generator_.HasGeneratedIDFor(tracking_id)) | 258 if (!id_generator_.HasGeneratedIDFor(tracking_id)) |
| 267 return false; | 259 return false; |
| 268 *slot = static_cast<int>(id_generator_.GetGeneratedID(tracking_id)); | 260 *slot = static_cast<int>(id_generator_.GetGeneratedID(tracking_id)); |
| 269 return true; | 261 return true; |
| 270 } | 262 } |
| 271 | 263 |
| 272 int TouchFactory::GetSlotForTrackingID(uint32_t tracking_id) { | 264 int TouchFactory::GetSlotForTrackingID(uint32_t tracking_id) { |
| 273 return id_generator_.GetGeneratedID(tracking_id); | 265 return id_generator_.GetGeneratedID(tracking_id); |
| 274 } | 266 } |
| 275 | 267 |
| 276 void TouchFactory::ReleaseSlotForTrackingID(uint32_t tracking_id) { | 268 void TouchFactory::ReleaseSlotForTrackingID(uint32_t tracking_id) { |
| 277 id_generator_.ReleaseNumber(tracking_id); | 269 id_generator_.ReleaseNumber(tracking_id); |
| 278 } | 270 } |
| 279 | 271 |
| 280 bool TouchFactory::IsTouchDevicePresent() { | 272 bool TouchFactory::IsTouchDevicePresent() { |
| 281 return touch_screens_enabled_ && | 273 return touch_screens_enabled_ && !touch_device_list_.empty(); |
| 282 touch_device_lookup_.any(); | |
| 283 } | 274 } |
| 284 | 275 |
| 285 void TouchFactory::ResetForTest() { | 276 void TouchFactory::ResetForTest() { |
| 286 pointer_device_lookup_.reset(); | 277 pointer_device_lookup_.reset(); |
| 287 touch_device_lookup_.reset(); | |
| 288 touch_device_list_.clear(); | 278 touch_device_list_.clear(); |
| 289 touchscreen_ids_.clear(); | 279 touchscreen_ids_.clear(); |
| 290 id_generator_.ResetForTest(); | 280 id_generator_.ResetForTest(); |
| 291 SetTouchscreensEnabled(true); | 281 SetTouchscreensEnabled(true); |
| 292 } | 282 } |
| 293 | 283 |
| 294 void TouchFactory::SetTouchDeviceForTest( | 284 void TouchFactory::SetTouchDeviceForTest( |
| 295 const std::vector<int>& devices) { | 285 const std::vector<int>& devices) { |
| 296 touch_device_lookup_.reset(); | |
| 297 touch_device_list_.clear(); | 286 touch_device_list_.clear(); |
| 298 for (std::vector<int>::const_iterator iter = devices.begin(); | 287 for (std::vector<int>::const_iterator iter = devices.begin(); |
| 299 iter != devices.end(); ++iter) { | 288 iter != devices.end(); ++iter) { |
| 300 DCHECK(IsValidDevice(*iter)); | 289 DCHECK(IsValidDevice(*iter)); |
| 301 touch_device_lookup_[*iter] = true; | |
| 302 touch_device_list_[*iter] = true; | 290 touch_device_list_[*iter] = true; |
| 303 } | 291 } |
| 304 SetTouchscreensEnabled(true); | 292 SetTouchscreensEnabled(true); |
| 305 } | 293 } |
| 306 | 294 |
| 307 void TouchFactory::SetPointerDeviceForTest( | 295 void TouchFactory::SetPointerDeviceForTest( |
| 308 const std::vector<int>& devices) { | 296 const std::vector<int>& devices) { |
| 309 pointer_device_lookup_.reset(); | 297 pointer_device_lookup_.reset(); |
| 310 for (std::vector<int>::const_iterator iter = devices.begin(); | 298 for (std::vector<int>::const_iterator iter = devices.begin(); |
| 311 iter != devices.end(); ++iter) { | 299 iter != devices.end(); ++iter) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 327 std::find_if(touchscreens.begin(), touchscreens.end(), | 315 std::find_if(touchscreens.begin(), touchscreens.end(), |
| 328 [device_id](const TouchscreenDevice& touchscreen) { | 316 [device_id](const TouchscreenDevice& touchscreen) { |
| 329 return touchscreen.id == device_id; | 317 return touchscreen.id == device_id; |
| 330 }); | 318 }); |
| 331 // Internal displays will have a vid and pid of 0. Ignore them. | 319 // Internal displays will have a vid and pid of 0. Ignore them. |
| 332 if (it != touchscreens.end() && it->vendor_id && it->product_id) | 320 if (it != touchscreens.end() && it->vendor_id && it->product_id) |
| 333 touchscreen_ids_.insert(std::make_pair(it->vendor_id, it->product_id)); | 321 touchscreen_ids_.insert(std::make_pair(it->vendor_id, it->product_id)); |
| 334 } | 322 } |
| 335 | 323 |
| 336 } // namespace ui | 324 } // namespace ui |
| OLD | NEW |