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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 if (!id_generator_.HasGeneratedIDFor(tracking_id)) | 243 if (!id_generator_.HasGeneratedIDFor(tracking_id)) |
244 return false; | 244 return false; |
245 *slot = static_cast<int>(id_generator_.GetGeneratedID(tracking_id)); | 245 *slot = static_cast<int>(id_generator_.GetGeneratedID(tracking_id)); |
246 return true; | 246 return true; |
247 } | 247 } |
248 | 248 |
249 int TouchFactory::GetSlotForTrackingID(uint32 tracking_id) { | 249 int TouchFactory::GetSlotForTrackingID(uint32 tracking_id) { |
250 return id_generator_.GetGeneratedID(tracking_id); | 250 return id_generator_.GetGeneratedID(tracking_id); |
251 } | 251 } |
252 | 252 |
| 253 void TouchFactory::AcquireSlotForTrackingID(uint32 tracking_id) { |
| 254 tracking_id_refcounts_[tracking_id]++; |
| 255 } |
| 256 |
253 void TouchFactory::ReleaseSlotForTrackingID(uint32 tracking_id) { | 257 void TouchFactory::ReleaseSlotForTrackingID(uint32 tracking_id) { |
254 id_generator_.ReleaseNumber(tracking_id); | 258 tracking_id_refcounts_[tracking_id]--; |
| 259 if (tracking_id_refcounts_[tracking_id] == 0) |
| 260 id_generator_.ReleaseNumber(tracking_id); |
255 } | 261 } |
256 | 262 |
257 bool TouchFactory::IsTouchDevicePresent() { | 263 bool TouchFactory::IsTouchDevicePresent() { |
258 return !touch_events_disabled_ && touch_device_lookup_.any(); | 264 return !touch_events_disabled_ && touch_device_lookup_.any(); |
259 } | 265 } |
260 | 266 |
261 void TouchFactory::ResetForTest() { | 267 void TouchFactory::ResetForTest() { |
262 pointer_device_lookup_.reset(); | 268 pointer_device_lookup_.reset(); |
263 touch_device_lookup_.reset(); | 269 touch_device_lookup_.reset(); |
264 touch_events_disabled_ = false; | 270 touch_events_disabled_ = false; |
265 touch_device_list_.clear(); | 271 touch_device_list_.clear(); |
266 touchscreen_ids_.clear(); | 272 touchscreen_ids_.clear(); |
| 273 tracking_id_refcounts_.clear(); |
267 id_generator_.ResetForTest(); | 274 id_generator_.ResetForTest(); |
268 } | 275 } |
269 | 276 |
270 void TouchFactory::SetTouchDeviceForTest( | 277 void TouchFactory::SetTouchDeviceForTest( |
271 const std::vector<unsigned int>& devices) { | 278 const std::vector<unsigned int>& devices) { |
272 touch_device_lookup_.reset(); | 279 touch_device_lookup_.reset(); |
273 touch_device_list_.clear(); | 280 touch_device_list_.clear(); |
274 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); | 281 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); |
275 iter != devices.end(); ++iter) { | 282 iter != devices.end(); ++iter) { |
276 DCHECK(*iter < touch_device_lookup_.size()); | 283 DCHECK(*iter < touch_device_lookup_.size()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 if (ptr[0] || ptr[1]) | 329 if (ptr[0] || ptr[1]) |
323 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); | 330 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); |
324 } | 331 } |
325 XFree(prop_return); | 332 XFree(prop_return); |
326 } | 333 } |
327 | 334 |
328 XCloseDevice(display, device); | 335 XCloseDevice(display, device); |
329 } | 336 } |
330 | 337 |
331 } // namespace ui | 338 } // namespace ui |
OLD | NEW |