| 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/x/touch_factory_x11.h" | 5 #include "ui/events/x/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 10 matching lines...) Expand all Loading... |
| 21 #include "base/sys_info.h" | 21 #include "base/sys_info.h" |
| 22 #include "ui/events/event_switches.h" | 22 #include "ui/events/event_switches.h" |
| 23 #include "ui/events/x/device_data_manager_x11.h" | 23 #include "ui/events/x/device_data_manager_x11.h" |
| 24 #include "ui/events/x/device_list_cache_x.h" | 24 #include "ui/events/x/device_list_cache_x.h" |
| 25 #include "ui/gfx/x/x11_types.h" | 25 #include "ui/gfx/x/x11_types.h" |
| 26 | 26 |
| 27 namespace ui { | 27 namespace ui { |
| 28 | 28 |
| 29 TouchFactory::TouchFactory() | 29 TouchFactory::TouchFactory() |
| 30 : pointer_device_lookup_(), | 30 : pointer_device_lookup_(), |
| 31 touch_device_available_(false), | |
| 32 touch_events_disabled_(false), | 31 touch_events_disabled_(false), |
| 33 touch_device_list_(), | 32 touch_device_list_(), |
| 34 max_touch_points_(-1), | 33 max_touch_points_(-1), |
| 35 virtual_core_keyboard_device_(-1), | 34 virtual_core_keyboard_device_(-1), |
| 36 id_generator_(0) { | 35 id_generator_(0) { |
| 37 if (!DeviceDataManagerX11::GetInstance()->IsXInput2Available()) | 36 if (!DeviceDataManagerX11::GetInstance()->IsXInput2Available()) |
| 38 return; | 37 return; |
| 39 | 38 |
| 40 XDisplay* display = gfx::GetXDisplay(); | 39 XDisplay* display = gfx::GetXDisplay(); |
| 41 UpdateDeviceList(display); | 40 UpdateDeviceList(display); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 device_ids.push_back(devid); | 73 device_ids.push_back(devid); |
| 75 else | 74 else |
| 76 DLOG(WARNING) << "Invalid touch-device id: " << *iter; | 75 DLOG(WARNING) << "Invalid touch-device id: " << *iter; |
| 77 } | 76 } |
| 78 ui::TouchFactory::GetInstance()->SetTouchDeviceList(device_ids); | 77 ui::TouchFactory::GetInstance()->SetTouchDeviceList(device_ids); |
| 79 } | 78 } |
| 80 } | 79 } |
| 81 | 80 |
| 82 void TouchFactory::UpdateDeviceList(Display* display) { | 81 void TouchFactory::UpdateDeviceList(Display* display) { |
| 83 // Detect touch devices. | 82 // Detect touch devices. |
| 84 touch_device_available_ = false; | |
| 85 touch_device_lookup_.reset(); | 83 touch_device_lookup_.reset(); |
| 86 touch_device_list_.clear(); | 84 touch_device_list_.clear(); |
| 87 touchscreen_ids_.clear(); | 85 touchscreen_ids_.clear(); |
| 88 max_touch_points_ = -1; | 86 max_touch_points_ = -1; |
| 89 | 87 |
| 90 #if !defined(USE_XI2_MT) | 88 #if !defined(USE_XI2_MT) |
| 91 // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does | 89 // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does |
| 92 // not provide enough information to detect a touch device. As a result, the | 90 // not provide enough information to detect a touch device. As a result, the |
| 93 // old version of query function (XListInputDevices) is used instead. | 91 // old version of query function (XListInputDevices) is used instead. |
| 94 // If XInput2 is not supported, this will return null (with count of -1) so | 92 // If XInput2 is not supported, this will return null (with count of -1) so |
| 95 // we assume there cannot be any touch devices. | 93 // we assume there cannot be any touch devices. |
| 96 // With XI2.1 or older, we allow only single touch devices. | 94 // With XI2.1 or older, we allow only single touch devices. |
| 97 XDeviceList dev_list = | 95 XDeviceList dev_list = |
| 98 DeviceListCacheX::GetInstance()->GetXDeviceList(display); | 96 DeviceListCacheX::GetInstance()->GetXDeviceList(display); |
| 99 Atom xi_touchscreen = XInternAtom(display, XI_TOUCHSCREEN, false); | 97 Atom xi_touchscreen = XInternAtom(display, XI_TOUCHSCREEN, false); |
| 100 for (int i = 0; i < dev_list.count; i++) { | 98 for (int i = 0; i < dev_list.count; i++) { |
| 101 if (dev_list[i].type == xi_touchscreen) { | 99 if (dev_list[i].type == xi_touchscreen) { |
| 102 touch_device_lookup_[dev_list[i].id] = true; | 100 touch_device_lookup_[dev_list[i].id] = true; |
| 103 touch_device_list_[dev_list[i].id] = false; | 101 touch_device_list_[dev_list[i].id] = false; |
| 104 touch_device_available_ = true; | |
| 105 } | 102 } |
| 106 } | 103 } |
| 107 #endif | 104 #endif |
| 108 | 105 |
| 109 if (!DeviceDataManagerX11::GetInstance()->IsXInput2Available()) | 106 if (!DeviceDataManagerX11::GetInstance()->IsXInput2Available()) |
| 110 return; | 107 return; |
| 111 | 108 |
| 112 // Instead of asking X for the list of devices all the time, let's maintain a | 109 // Instead of asking X for the list of devices all the time, let's maintain a |
| 113 // list of pointer devices we care about. | 110 // list of pointer devices we care about. |
| 114 // It should not be necessary to select for slave devices. XInput2 provides | 111 // It should not be necessary to select for slave devices. XInput2 provides |
| (...skipping 15 matching lines...) Expand all Loading... |
| 130 #if defined(USE_XI2_MT) | 127 #if defined(USE_XI2_MT) |
| 131 for (int k = 0; k < devinfo->num_classes; ++k) { | 128 for (int k = 0; k < devinfo->num_classes; ++k) { |
| 132 XIAnyClassInfo* xiclassinfo = devinfo->classes[k]; | 129 XIAnyClassInfo* xiclassinfo = devinfo->classes[k]; |
| 133 if (xiclassinfo->type == XITouchClass) { | 130 if (xiclassinfo->type == XITouchClass) { |
| 134 XITouchClassInfo* tci = | 131 XITouchClassInfo* tci = |
| 135 reinterpret_cast<XITouchClassInfo*>(xiclassinfo); | 132 reinterpret_cast<XITouchClassInfo*>(xiclassinfo); |
| 136 // Only care direct touch device (such as touch screen) right now | 133 // Only care direct touch device (such as touch screen) right now |
| 137 if (tci->mode == XIDirectTouch) { | 134 if (tci->mode == XIDirectTouch) { |
| 138 touch_device_lookup_[devinfo->deviceid] = true; | 135 touch_device_lookup_[devinfo->deviceid] = true; |
| 139 touch_device_list_[devinfo->deviceid] = true; | 136 touch_device_list_[devinfo->deviceid] = true; |
| 140 touch_device_available_ = true; | |
| 141 if (tci->num_touches > 0 && tci->num_touches > max_touch_points_) | 137 if (tci->num_touches > 0 && tci->num_touches > max_touch_points_) |
| 142 max_touch_points_ = tci->num_touches; | 138 max_touch_points_ = tci->num_touches; |
| 143 } | 139 } |
| 144 } | 140 } |
| 145 } | 141 } |
| 146 #endif | 142 #endif |
| 147 pointer_device_lookup_[devinfo->deviceid] = true; | 143 pointer_device_lookup_[devinfo->deviceid] = true; |
| 148 } else if (devinfo->use == XIMasterKeyboard) { | 144 } else if (devinfo->use == XIMasterKeyboard) { |
| 149 virtual_core_keyboard_device_ = devinfo->deviceid; | 145 virtual_core_keyboard_device_ = devinfo->deviceid; |
| 150 } | 146 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 tracking_id_refcounts_[tracking_id]++; | 266 tracking_id_refcounts_[tracking_id]++; |
| 271 } | 267 } |
| 272 | 268 |
| 273 void TouchFactory::ReleaseSlotForTrackingID(uint32 tracking_id) { | 269 void TouchFactory::ReleaseSlotForTrackingID(uint32 tracking_id) { |
| 274 tracking_id_refcounts_[tracking_id]--; | 270 tracking_id_refcounts_[tracking_id]--; |
| 275 if (tracking_id_refcounts_[tracking_id] == 0) | 271 if (tracking_id_refcounts_[tracking_id] == 0) |
| 276 id_generator_.ReleaseNumber(tracking_id); | 272 id_generator_.ReleaseNumber(tracking_id); |
| 277 } | 273 } |
| 278 | 274 |
| 279 bool TouchFactory::IsTouchDevicePresent() { | 275 bool TouchFactory::IsTouchDevicePresent() { |
| 280 return !touch_events_disabled_ && touch_device_available_; | 276 return !touch_events_disabled_ && touch_device_lookup_.any(); |
| 281 } | 277 } |
| 282 | 278 |
| 283 int TouchFactory::GetMaxTouchPoints() const { | 279 int TouchFactory::GetMaxTouchPoints() const { |
| 284 return max_touch_points_; | 280 return max_touch_points_; |
| 285 } | 281 } |
| 286 | 282 |
| 287 void TouchFactory::ResetForTest() { | 283 void TouchFactory::ResetForTest() { |
| 288 pointer_device_lookup_.reset(); | 284 pointer_device_lookup_.reset(); |
| 289 touch_device_lookup_.reset(); | 285 touch_device_lookup_.reset(); |
| 290 touch_device_available_ = false; | |
| 291 touch_events_disabled_ = false; | 286 touch_events_disabled_ = false; |
| 292 touch_device_list_.clear(); | 287 touch_device_list_.clear(); |
| 293 touchscreen_ids_.clear(); | 288 touchscreen_ids_.clear(); |
| 294 tracking_id_refcounts_.clear(); | 289 tracking_id_refcounts_.clear(); |
| 295 max_touch_points_ = -1; | 290 max_touch_points_ = -1; |
| 296 id_generator_.ResetForTest(); | 291 id_generator_.ResetForTest(); |
| 297 } | 292 } |
| 298 | 293 |
| 299 void TouchFactory::SetTouchDeviceForTest( | 294 void TouchFactory::SetTouchDeviceForTest( |
| 300 const std::vector<unsigned int>& devices) { | 295 const std::vector<unsigned int>& devices) { |
| 301 touch_device_lookup_.reset(); | 296 touch_device_lookup_.reset(); |
| 302 touch_device_list_.clear(); | 297 touch_device_list_.clear(); |
| 303 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); | 298 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); |
| 304 iter != devices.end(); ++iter) { | 299 iter != devices.end(); ++iter) { |
| 305 DCHECK(*iter < touch_device_lookup_.size()); | 300 DCHECK(*iter < touch_device_lookup_.size()); |
| 306 touch_device_lookup_[*iter] = true; | 301 touch_device_lookup_[*iter] = true; |
| 307 touch_device_list_[*iter] = true; | 302 touch_device_list_[*iter] = true; |
| 308 } | 303 } |
| 309 touch_device_available_ = true; | |
| 310 touch_events_disabled_ = false; | 304 touch_events_disabled_ = false; |
| 311 } | 305 } |
| 312 | 306 |
| 313 void TouchFactory::SetPointerDeviceForTest( | 307 void TouchFactory::SetPointerDeviceForTest( |
| 314 const std::vector<unsigned int>& devices) { | 308 const std::vector<unsigned int>& devices) { |
| 315 pointer_device_lookup_.reset(); | 309 pointer_device_lookup_.reset(); |
| 316 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); | 310 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); |
| 317 iter != devices.end(); ++iter) { | 311 iter != devices.end(); ++iter) { |
| 318 pointer_device_lookup_[*iter] = true; | 312 pointer_device_lookup_[*iter] = true; |
| 319 } | 313 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 if (ptr[0] || ptr[1]) | 346 if (ptr[0] || ptr[1]) |
| 353 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); | 347 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); |
| 354 } | 348 } |
| 355 XFree(prop_return); | 349 XFree(prop_return); |
| 356 } | 350 } |
| 357 | 351 |
| 358 XCloseDevice(display, device); | 352 XCloseDevice(display, device); |
| 359 } | 353 } |
| 360 | 354 |
| 361 } // namespace ui | 355 } // namespace ui |
| OLD | NEW |