OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base/touch/touch_factory.h" | 5 #include "ui/base/touch/touch_factory.h" |
6 | 6 |
7 #include <X11/cursorfont.h> | 7 #include <X11/cursorfont.h> |
8 #include <X11/extensions/XInput.h> | 8 #include <X11/extensions/XInput.h> |
9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
10 #include <X11/extensions/XIproto.h> | 10 #include <X11/extensions/XIproto.h> |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 // static | 128 // static |
129 TouchFactory* TouchFactory::GetInstance() { | 129 TouchFactory* TouchFactory::GetInstance() { |
130 return Singleton<TouchFactory>::get(); | 130 return Singleton<TouchFactory>::get(); |
131 } | 131 } |
132 | 132 |
133 TouchFactory::TouchFactory() | 133 TouchFactory::TouchFactory() |
134 : is_cursor_visible_(true), | 134 : is_cursor_visible_(true), |
135 keep_mouse_cursor_(false), | 135 keep_mouse_cursor_(false), |
136 cursor_timer_(), | 136 cursor_timer_(), |
137 pointer_device_lookup_(), | 137 pointer_device_lookup_(), |
138 touch_device_list_(), | |
138 #if defined(USE_XI2_MT) | 139 #if defined(USE_XI2_MT) |
139 touch_device_list_() { | 140 min_available_slot_(0), |
140 #else | 141 tracking_id_map_(), |
sky
2011/09/28 16:09:48
nit: remove this from initializer list.
sadrul
2011/09/28 16:16:55
Done.
| |
141 touch_device_list_(), | 142 #endif |
142 slots_used_() { | 143 slots_used_() { |
143 #endif | |
144 #if defined(TOUCH_UI) | 144 #if defined(TOUCH_UI) |
145 if (!base::MessagePumpForUI::HasXInput2()) | 145 if (!base::MessagePumpForUI::HasXInput2()) |
146 return; | 146 return; |
147 #endif | 147 #endif |
148 | 148 |
149 char nodata[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; | 149 char nodata[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
150 XColor black; | 150 XColor black; |
151 black.red = black.green = black.blue = 0; | 151 black.red = black.green = black.blue = 0; |
152 Display* display = ui::GetXDisplay(); | 152 Display* display = ui::GetXDisplay(); |
153 Pixmap blank = XCreateBitmapFromData(display, ui::GetX11RootWindow(), | 153 Pixmap blank = XCreateBitmapFromData(display, ui::GetX11RootWindow(), |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 touch_device_lookup_[deviceid] : false; | 328 touch_device_lookup_[deviceid] : false; |
329 } | 329 } |
330 | 330 |
331 bool TouchFactory::IsRealTouchDevice(unsigned int deviceid) const { | 331 bool TouchFactory::IsRealTouchDevice(unsigned int deviceid) const { |
332 return (deviceid < touch_device_lookup_.size() && | 332 return (deviceid < touch_device_lookup_.size() && |
333 touch_device_lookup_[deviceid]) ? | 333 touch_device_lookup_[deviceid]) ? |
334 touch_device_list_.find(deviceid)->second : | 334 touch_device_list_.find(deviceid)->second : |
335 false; | 335 false; |
336 } | 336 } |
337 | 337 |
338 #if !defined(USE_XI2_MT) | 338 #if defined(USE_XI2_MT) |
339 int TouchFactory::GetSlotForTrackingID(uint32 tracking_id) { | |
340 TrackingIdMap::iterator itr = tracking_id_map_.find(tracking_id); | |
341 if (itr != tracking_id_map_.end()) | |
342 return itr->second; | |
343 | |
344 int slot = min_available_slot_; | |
345 if (slot == kMaxTouchPoints) { | |
346 LOG(ERROR) << "Could not find available slot for touch point"; | |
347 return 0; | |
348 } | |
349 SetSlotUsed(slot, true); | |
350 tracking_id_map_.insert(std::make_pair(tracking_id, slot)); | |
351 | |
352 // Updates the minium available slot ID | |
353 while (++min_available_slot_ < kMaxTouchPoints && | |
354 IsSlotUsed(min_available_slot_)) | |
355 continue; | |
356 | |
357 return slot; | |
358 } | |
359 | |
360 void TouchFactory::ReleaseSlotForTrackingID(uint32 tracking_id) { | |
361 TrackingIdMap::iterator itr = tracking_id_map_.find(tracking_id); | |
362 if (itr != tracking_id_map_.end()) { | |
363 int slot = itr->second; | |
364 SetSlotUsed(slot, false); | |
365 tracking_id_map_.erase(itr); | |
366 if (slot < min_available_slot_) | |
367 min_available_slot_ = slot; | |
368 } else { | |
369 NOTREACHED() << "Cannot find slot mapping to tracking ID " << tracking_id; | |
370 } | |
371 } | |
372 #endif | |
373 | |
339 bool TouchFactory::IsSlotUsed(int slot) const { | 374 bool TouchFactory::IsSlotUsed(int slot) const { |
340 CHECK_LT(slot, kMaxTouchPoints); | 375 CHECK_LT(slot, kMaxTouchPoints); |
341 return slots_used_[slot]; | 376 return slots_used_[slot]; |
342 } | 377 } |
343 | 378 |
344 void TouchFactory::SetSlotUsed(int slot, bool used) { | 379 void TouchFactory::SetSlotUsed(int slot, bool used) { |
345 CHECK_LT(slot, kMaxTouchPoints); | 380 CHECK_LT(slot, kMaxTouchPoints); |
346 slots_used_[slot] = used; | 381 slots_used_[slot] = used; |
347 } | 382 } |
348 #endif | |
349 | 383 |
350 bool TouchFactory::GrabTouchDevices(Display* display, ::Window window) { | 384 bool TouchFactory::GrabTouchDevices(Display* display, ::Window window) { |
351 #if defined(TOUCH_UI) | 385 #if defined(TOUCH_UI) |
352 if (!base::MessagePumpForUI::HasXInput2() || | 386 if (!base::MessagePumpForUI::HasXInput2() || |
353 touch_device_list_.empty()) | 387 touch_device_list_.empty()) |
354 return true; | 388 return true; |
355 #endif | 389 #endif |
356 | 390 |
357 unsigned char mask[XIMaskLen(XI_LASTEVENT)]; | 391 unsigned char mask[XIMaskLen(XI_LASTEVENT)]; |
358 bool success = true; | 392 bool success = true; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
501 float* max) { | 535 float* max) { |
502 if (valuator_lookup_[deviceid][tp] >= 0) { | 536 if (valuator_lookup_[deviceid][tp] >= 0) { |
503 *min = touch_param_min_[deviceid][tp]; | 537 *min = touch_param_min_[deviceid][tp]; |
504 *max = touch_param_max_[deviceid][tp]; | 538 *max = touch_param_max_[deviceid][tp]; |
505 return true; | 539 return true; |
506 } | 540 } |
507 return false; | 541 return false; |
508 } | 542 } |
509 | 543 |
510 } // namespace ui | 544 } // namespace ui |
OLD | NEW |