| 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 #if defined(TOOLKIT_USES_GTK) | 7 #if defined(TOOLKIT_USES_GTK) |
| 8 // TODO(sad) Remove all TOOLKIT_USES_GTK uses once we move to aura only. | 8 // TODO(sad) Remove all TOOLKIT_USES_GTK uses once we move to aura only. |
| 9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
| 10 #include <gdk/gdkx.h> | 10 #include <gdk/gdkx.h> |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 // static | 127 // static |
| 128 TouchFactory* TouchFactory::GetInstance() { | 128 TouchFactory* TouchFactory::GetInstance() { |
| 129 return Singleton<TouchFactory>::get(); | 129 return Singleton<TouchFactory>::get(); |
| 130 } | 130 } |
| 131 | 131 |
| 132 TouchFactory::TouchFactory() | 132 TouchFactory::TouchFactory() |
| 133 : is_cursor_visible_(true), | 133 : is_cursor_visible_(true), |
| 134 keep_mouse_cursor_(false), | 134 keep_mouse_cursor_(false), |
| 135 cursor_timer_(), | 135 cursor_timer_(), |
| 136 pointer_device_lookup_(), | 136 pointer_device_lookup_(), |
| 137 touch_device_list_(), |
| 137 #if defined(USE_XI2_MT) | 138 #if defined(USE_XI2_MT) |
| 138 touch_device_list_() { | 139 min_available_slot_(0), |
| 140 slots_used_(), |
| 141 tracking_id_map_() { |
| 139 #else | 142 #else |
| 140 touch_device_list_(), | |
| 141 slots_used_() { | 143 slots_used_() { |
| 142 #endif | 144 #endif |
| 143 #if defined(TOUCH_UI) | 145 #if defined(TOUCH_UI) |
| 144 if (!base::MessagePumpForUI::HasXInput2()) | 146 if (!base::MessagePumpForUI::HasXInput2()) |
| 145 return; | 147 return; |
| 146 #endif | 148 #endif |
| 147 | 149 |
| 148 char nodata[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; | 150 char nodata[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 149 XColor black; | 151 XColor black; |
| 150 black.red = black.green = black.blue = 0; | 152 black.red = black.green = black.blue = 0; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 } | 322 } |
| 321 | 323 |
| 322 SetupValuator(); | 324 SetupValuator(); |
| 323 } | 325 } |
| 324 | 326 |
| 325 bool TouchFactory::IsTouchDevice(unsigned deviceid) const { | 327 bool TouchFactory::IsTouchDevice(unsigned deviceid) const { |
| 326 return deviceid < touch_device_lookup_.size() ? | 328 return deviceid < touch_device_lookup_.size() ? |
| 327 touch_device_lookup_[deviceid] : false; | 329 touch_device_lookup_[deviceid] : false; |
| 328 } | 330 } |
| 329 | 331 |
| 330 #if !defined(USE_XI2_MT) | 332 #if defined(USE_XI2_MT) |
| 333 int TouchFactory::GetSlotForTrackingID(uint32 tracking_id) { |
| 334 TrackingIdMap::iterator itr = tracking_id_map_.find(tracking_id); |
| 335 if (itr != tracking_id_map_.end()) |
| 336 return itr->second; |
| 337 |
| 338 int slot = min_available_slot_; |
| 339 if (slot == kMaxTouchPoints) { |
| 340 LOG(ERROR) << "Could not find available slot for touch point"; |
| 341 return 0; |
| 342 } |
| 343 SetSlotUsed(slot, true); |
| 344 tracking_id_map_.insert(std::make_pair(tracking_id, slot)); |
| 345 |
| 346 // Updates the minium available slot ID |
| 347 while (++min_available_slot_ < kMaxTouchPoints && |
| 348 IsSlotUsed(min_available_slot_)) |
| 349 continue; |
| 350 |
| 351 return slot; |
| 352 } |
| 353 |
| 354 void TouchFactory::ReleaseSlotForTrackingID(uint32 tracking_id) { |
| 355 TrackingIdMap::iterator itr = tracking_id_map_.find(tracking_id); |
| 356 if (itr != tracking_id_map_.end()) { |
| 357 int slot = itr->second; |
| 358 SetSlotUsed(slot, false); |
| 359 tracking_id_map_.erase(itr); |
| 360 if (slot < min_available_slot_) |
| 361 min_available_slot_ = slot; |
| 362 } else { |
| 363 NOTREACHED() << "Cannot find slot mapping to tracking ID " << tracking_id; |
| 364 } |
| 365 } |
| 366 #endif |
| 367 |
| 331 bool TouchFactory::IsSlotUsed(int slot) const { | 368 bool TouchFactory::IsSlotUsed(int slot) const { |
| 332 CHECK_LT(slot, kMaxTouchPoints); | 369 CHECK_LT(slot, kMaxTouchPoints); |
| 333 return slots_used_[slot]; | 370 return slots_used_[slot]; |
| 334 } | 371 } |
| 335 | 372 |
| 336 void TouchFactory::SetSlotUsed(int slot, bool used) { | 373 void TouchFactory::SetSlotUsed(int slot, bool used) { |
| 337 CHECK_LT(slot, kMaxTouchPoints); | 374 CHECK_LT(slot, kMaxTouchPoints); |
| 338 slots_used_[slot] = used; | 375 slots_used_[slot] = used; |
| 339 } | 376 } |
| 340 #endif | |
| 341 | 377 |
| 342 bool TouchFactory::GrabTouchDevices(Display* display, ::Window window) { | 378 bool TouchFactory::GrabTouchDevices(Display* display, ::Window window) { |
| 343 #if defined(TOUCH_UI) | 379 #if defined(TOUCH_UI) |
| 344 if (!base::MessagePumpForUI::HasXInput2() || | 380 if (!base::MessagePumpForUI::HasXInput2() || |
| 345 touch_device_list_.empty()) | 381 touch_device_list_.empty()) |
| 346 return true; | 382 return true; |
| 347 #endif | 383 #endif |
| 348 | 384 |
| 349 unsigned char mask[XIMaskLen(XI_LASTEVENT)]; | 385 unsigned char mask[XIMaskLen(XI_LASTEVENT)]; |
| 350 bool success = true; | 386 bool success = true; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 float* max) { | 529 float* max) { |
| 494 if (valuator_lookup_[deviceid][tp] >= 0) { | 530 if (valuator_lookup_[deviceid][tp] >= 0) { |
| 495 *min = touch_param_min_[deviceid][tp]; | 531 *min = touch_param_min_[deviceid][tp]; |
| 496 *max = touch_param_max_[deviceid][tp]; | 532 *max = touch_param_max_[deviceid][tp]; |
| 497 return true; | 533 return true; |
| 498 } | 534 } |
| 499 return false; | 535 return false; |
| 500 } | 536 } |
| 501 | 537 |
| 502 } // namespace ui | 538 } // namespace ui |
| OLD | NEW |