diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-27 15:43:35 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-27 15:43:35 +0000 |
commit | 9b03c4363bb1ccd28336aba7c7efa6206ca01a9c (patch) | |
tree | 92f6c0eefb9b5ab75d39731d1a90e3762ea2f89c /ui/base/touch | |
parent | 9bbbd960f5aa7cd1399f52ab316a954a9313bd92 (diff) | |
download | chromium_src-9b03c4363bb1ccd28336aba7c7efa6206ca01a9c.zip chromium_src-9b03c4363bb1ccd28336aba7c7efa6206ca01a9c.tar.gz chromium_src-9b03c4363bb1ccd28336aba7c7efa6206ca01a9c.tar.bz2 |
touchui: Fix --touch-devices flag.
This fixes the --touch-devices command-line flag, which can be used to create
touch-events from a normal mouse device.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/8048015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102936 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base/touch')
-rw-r--r-- | ui/base/touch/touch_factory.cc | 36 | ||||
-rw-r--r-- | ui/base/touch/touch_factory.h | 12 |
2 files changed, 32 insertions, 16 deletions
diff --git a/ui/base/touch/touch_factory.cc b/ui/base/touch/touch_factory.cc index c4f72b1..e528523 100644 --- a/ui/base/touch/touch_factory.cc +++ b/ui/base/touch/touch_factory.cc @@ -4,11 +4,6 @@ #include "ui/base/touch/touch_factory.h" -#if defined(TOOLKIT_USES_GTK) -// TODO(sad) Remove all TOOLKIT_USES_GTK uses once we move to aura only. -#include <gtk/gtk.h> -#include <gdk/gdkx.h> -#endif #include <X11/cursorfont.h> #include <X11/extensions/XInput.h> #include <X11/extensions/XInput2.h> @@ -20,6 +15,12 @@ #include "base/message_loop.h" #include "ui/base/x/x11_util.h" +#if defined(TOOLKIT_USES_GTK) +// TODO(sad) Remove all TOOLKIT_USES_GTK uses once we move to aura only. +#include <gtk/gtk.h> +#include <gdk/gdkx.h> +#endif + namespace { // The X cursor is hidden if it is idle for kCursorIdleSeconds seconds. @@ -211,7 +212,7 @@ void TouchFactory::UpdateDeviceList(Display* display) { const char* devtype = XGetAtomName(display, devlist[i].type); if (devtype && !strcmp(devtype, XI_TOUCHSCREEN)) { touch_device_lookup_[devlist[i].id] = true; - touch_device_list_.push_back(devlist[i].id); + touch_device_list_[devlist[i].id] = true; } } } @@ -244,7 +245,7 @@ void TouchFactory::UpdateDeviceList(Display* display) { // Only care direct touch device (such as touch screen) right now if (tci->mode == XIDirectTouch) { touch_device_lookup_[devinfo->deviceid] = true; - touch_device_list_.push_back(devinfo->deviceid); + touch_device_list_[devinfo->deviceid] = true; } } } @@ -316,7 +317,7 @@ void TouchFactory::SetTouchDeviceList( iter != devices.end(); ++iter) { DCHECK(*iter < touch_device_lookup_.size()); touch_device_lookup_[*iter] = true; - touch_device_list_.push_back(*iter); + touch_device_list_[*iter] = false; } SetupValuator(); @@ -327,6 +328,13 @@ bool TouchFactory::IsTouchDevice(unsigned deviceid) const { touch_device_lookup_[deviceid] : false; } +bool TouchFactory::IsRealTouchDevice(unsigned int deviceid) const { + return (deviceid < touch_device_lookup_.size() && + touch_device_lookup_[deviceid]) ? + touch_device_list_.find(deviceid)->second : + false; +} + #if !defined(USE_XI2_MT) bool TouchFactory::IsSlotUsed(int slot) const { CHECK_LT(slot, kMaxTouchPoints); @@ -362,12 +370,12 @@ bool TouchFactory::GrabTouchDevices(Display* display, ::Window window) { XIEventMask evmask; evmask.mask_len = sizeof(mask); evmask.mask = mask; - for (std::vector<int>::const_iterator iter = + for (std::map<int, bool>::const_iterator iter = touch_device_list_.begin(); iter != touch_device_list_.end(); ++iter) { - evmask.deviceid = *iter; - Status status = XIGrabDevice(display, *iter, window, CurrentTime, None, - GrabModeAsync, GrabModeAsync, False, &evmask); + evmask.deviceid = iter->first; + Status status = XIGrabDevice(display, iter->first, window, CurrentTime, + None, GrabModeAsync, GrabModeAsync, False, &evmask); success = success && status == GrabSuccess; } @@ -381,10 +389,10 @@ bool TouchFactory::UngrabTouchDevices(Display* display) { #endif bool success = true; - for (std::vector<int>::const_iterator iter = + for (std::map<int, bool>::const_iterator iter = touch_device_list_.begin(); iter != touch_device_list_.end(); ++iter) { - Status status = XIUngrabDevice(display, *iter, CurrentTime); + Status status = XIUngrabDevice(display, iter->first, CurrentTime); success = success && status == GrabSuccess; } return success; diff --git a/ui/base/touch/touch_factory.h b/ui/base/touch/touch_factory.h index a461738..9b16113 100644 --- a/ui/base/touch/touch_factory.h +++ b/ui/base/touch/touch_factory.h @@ -7,6 +7,7 @@ #pragma once #include <bitset> +#include <map> #include <vector> #include "base/memory/singleton.h" @@ -77,6 +78,10 @@ class UI_EXPORT TouchFactory { // Is the device a touch-device? bool IsTouchDevice(unsigned int deviceid) const; + // Is the device a real touch-device? (see doc. for |touch_device_list_| below + // for more explanation.) + bool IsRealTouchDevice(unsigned int deviceid) const; + #if !defined(USE_XI2_MT) // Is the slot ID currently used? bool IsSlotUsed(int slot) const; @@ -175,8 +180,11 @@ class UI_EXPORT TouchFactory { // A quick lookup table for determining if a device is a touch device. std::bitset<kMaxDeviceNum> touch_device_lookup_; - // The list of touch devices. - std::vector<int> touch_device_list_; + // The list of touch devices. For testing/debugging purposes, a mouse-device + // can sometimes be treated as a touch device. The key in the map represents + // the device id, and the value represents if the device is a real touch + // device (when true) or if the device is really a mouse device. + std::map<int, bool> touch_device_list_; // Index table to find the valuator for the TouchParam on the specific device // by valuator_lookup_[device_id][touch_params]. Use 2-D array to get fast |