summaryrefslogtreecommitdiffstats
path: root/ui/base/touch
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-25 16:09:26 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-25 16:09:26 +0000
commit4ba96d0e34ef8c2836045161b342516e88bcb891 (patch)
tree6495bb9c466250e927489b62ef41551c89539228 /ui/base/touch
parenta9e2990775165b2780a187a5a42917a967dcb69c (diff)
downloadchromium_src-4ba96d0e34ef8c2836045161b342516e88bcb891.zip
chromium_src-4ba96d0e34ef8c2836045161b342516e88bcb891.tar.gz
chromium_src-4ba96d0e34ef8c2836045161b342516e88bcb891.tar.bz2
XI2.2: Make sure valuators values are reported correctly.
With MT-B/XI2.2, valuators in an XEvent are not reported if the values haven't changed from the previous event. So it is necessary to remember these valuators so that chrome doesn't think X/device doesn't know about the valuators. BUG=129395 TEST=manually Review URL: https://chromiumcodereview.appspot.com/10412060 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139051 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base/touch')
-rw-r--r--ui/base/touch/touch_factory.cc149
-rw-r--r--ui/base/touch/touch_factory.h67
2 files changed, 0 insertions, 216 deletions
diff --git a/ui/base/touch/touch_factory.cc b/ui/base/touch/touch_factory.cc
index b3c254c..4eeba93 100644
--- a/ui/base/touch/touch_factory.cc
+++ b/ui/base/touch/touch_factory.cc
@@ -22,59 +22,6 @@ namespace {
// The X cursor is hidden if it is idle for kCursorIdleSeconds seconds.
int kCursorIdleSeconds = 5;
-// Given the TouchParam, return the correspoding XIValuatorClassInfo using
-// the X device information through Atom name matching.
-XIValuatorClassInfo* FindTPValuator(Display* display,
- XIDeviceInfo* info,
- ui::TouchFactory::TouchParam tp) {
- // Lookup table for mapping TouchParam to Atom string used in X.
- // A full set of Atom strings can be found at xserver-properties.h.
- static struct {
- ui::TouchFactory::TouchParam tp;
- const char* atom;
- } kTouchParamAtom[] = {
- { ui::TouchFactory::TP_TOUCH_MAJOR, "Abs MT Touch Major" },
- { ui::TouchFactory::TP_TOUCH_MINOR, "Abs MT Touch Minor" },
- { ui::TouchFactory::TP_ORIENTATION, "Abs MT Orientation" },
- { ui::TouchFactory::TP_PRESSURE, "Abs MT Pressure" },
-#if !defined(USE_XI2_MT)
- // For Slot ID, See this chromeos revision: http://git.chromium.org/gitweb/?
- // p=chromiumos/overlays/chromiumos-overlay.git;
- // a=commit;h=9164d0a75e48c4867e4ef4ab51f743ae231c059a
- { ui::TouchFactory::TP_SLOT_ID, "Abs MT Slot ID" },
-#endif
- { ui::TouchFactory::TP_TRACKING_ID, "Abs MT Tracking ID" },
- { ui::TouchFactory::TP_LAST_ENTRY, NULL },
- };
-
- const char* atom_tp = NULL;
-
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTouchParamAtom); i++) {
- if (tp == kTouchParamAtom[i].tp) {
- atom_tp = kTouchParamAtom[i].atom;
- break;
- }
- }
-
- if (!atom_tp)
- return NULL;
-
- for (int i = 0; i < info->num_classes; i++) {
- if (info->classes[i]->type != XIValuatorClass)
- continue;
- XIValuatorClassInfo* v =
- reinterpret_cast<XIValuatorClassInfo*>(info->classes[i]);
-
- if (v->label) {
- ui::XScopedString atom(XGetAtomName(display, v->label));
- if (atom.string() && strcmp(atom.string(), atom_tp) == 0)
- return v;
- }
- }
-
- return NULL;
-}
-
} // namespace
namespace ui {
@@ -211,8 +158,6 @@ void TouchFactory::UpdateDeviceList(Display* display) {
}
if (devices)
XIFreeDeviceInfo(devices);
-
- SetupValuator();
}
bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) {
@@ -278,8 +223,6 @@ void TouchFactory::SetTouchDeviceList(
touch_device_lookup_[*iter] = true;
touch_device_list_[*iter] = false;
}
-
- SetupValuator();
}
bool TouchFactory::IsTouchDevice(unsigned deviceid) const {
@@ -427,100 +370,8 @@ void TouchFactory::SetCursorVisible(bool show, bool start_timer) {
XDefineCursor(display, window, invisible_cursor_);
}
-bool TouchFactory::ExtractTouchParam(const XEvent& xev,
- TouchParam tp,
- float* value) {
- XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data);
- if (xiev->sourceid >= kMaxDeviceNum)
- return false;
- int v = valuator_lookup_[xiev->sourceid][tp];
- if (v >= 0 && XIMaskIsSet(xiev->valuators.mask, v)) {
- *value = xiev->valuators.values[v];
- return true;
- }
-
-#if defined(USE_XI2_MT)
- // With XInput2 MT, Tracking ID is provided in the detail field.
- if (tp == TP_TRACKING_ID) {
- *value = xiev->detail;
- return true;
- }
-#endif
-
- return false;
-}
-
-bool TouchFactory::NormalizeTouchParam(unsigned int deviceid,
- TouchParam tp,
- float* value) {
- float max_value;
- float min_value;
- if (GetTouchParamRange(deviceid, tp, &min_value, &max_value)) {
- *value = (*value - min_value) / (max_value - min_value);
- DCHECK(*value >= 0.0 && *value <= 1.0);
- return true;
- }
- return false;
-}
-
-bool TouchFactory::GetTouchParamRange(unsigned int deviceid,
- TouchParam tp,
- float* min,
- float* max) {
- if (valuator_lookup_[deviceid][tp] >= 0) {
- *min = touch_param_min_[deviceid][tp];
- *max = touch_param_max_[deviceid][tp];
- return true;
- }
- return false;
-}
-
bool TouchFactory::IsTouchDevicePresent() {
return (touch_device_available_ && touch_events_allowed_);
}
-void TouchFactory::SetupValuator() {
- memset(valuator_lookup_, -1, sizeof(valuator_lookup_));
- memset(touch_param_min_, 0, sizeof(touch_param_min_));
- memset(touch_param_max_, 0, sizeof(touch_param_max_));
-
- Display* display = ui::GetXDisplay();
- int ndevice;
- XIDeviceInfo* info_list = XIQueryDevice(display, XIAllDevices, &ndevice);
-
- for (int i = 0; i < ndevice; i++) {
- XIDeviceInfo* info = info_list + i;
-
- if (!IsTouchDevice(info->deviceid))
- continue;
-
- for (int j = 0; j < TP_LAST_ENTRY; j++) {
- TouchParam tp = static_cast<TouchParam>(j);
- XIValuatorClassInfo* valuator = FindTPValuator(display, info, tp);
- if (valuator) {
- valuator_lookup_[info->deviceid][j] = valuator->number;
- touch_param_min_[info->deviceid][j] = valuator->min;
- touch_param_max_[info->deviceid][j] = valuator->max;
- }
- }
-
-#if !defined(USE_XI2_MT)
- // In order to support multi-touch with XI2.0, we need both a slot_id and
- // tracking_id valuator. Without these we'll treat the device as a
- // single-touch device (like a mouse).
- // TODO(rbyers): Multi-touch is disabled: http://crbug.com/112329
- //if (valuator_lookup_[info->deviceid][TP_SLOT_ID] == -1 ||
- // valuator_lookup_[info->deviceid][TP_TRACKING_ID] == -1) {
- DVLOG(1) << "Touch device " << info->deviceid <<
- " does not provide enough information for multi-touch, treating as "
- "a single-touch device.";
- touch_device_list_[info->deviceid] = false;
- //}
-#endif
- }
-
- if (info_list)
- XIFreeDeviceInfo(info_list);
-}
-
} // namespace ui
diff --git a/ui/base/touch/touch_factory.h b/ui/base/touch/touch_factory.h
index 407cca3..feef80a 100644
--- a/ui/base/touch/touch_factory.h
+++ b/ui/base/touch/touch_factory.h
@@ -29,39 +29,6 @@ class UI_EXPORT TouchFactory {
~TouchFactory();
public:
- // Define the touch params following the Multi-touch Protocol.
- enum TouchParam {
- TP_TOUCH_MAJOR = 0, // Length of the touch area.
- TP_TOUCH_MINOR, // Width of the touch area.
- TP_ORIENTATION, // Angle between the X-axis and the major axis of the
- // touch area.
- TP_PRESSURE, // Pressure of the touch contact.
-
- // NOTE: A touch event can have multiple touch points. So when we receive a
- // touch event, we need to determine which point triggered the event.
- // A touch point can have both a 'Slot ID' and a 'Tracking ID', and they can
- // be (in fact, usually are) different. The 'Slot ID' ranges between 0 and
- // (X - 1), where X is the maximum touch points supported by the device. The
- // 'Tracking ID' can be any 16-bit value. With XInput 2.0, an XI_Motion
- // event that comes from a currently-unused 'Slot ID' indicates the creation
- // of a new touch point, and any event that comes with a 0 value for
- // 'Tracking ID' marks the removal of a touch point. During the lifetime of
- // a touchpoint, we use the 'Slot ID' as its identifier. The XI_ButtonPress
- // and XI_ButtonRelease events are ignored.
-#if !defined(USE_XI2_MT)
- TP_SLOT_ID, // ID of the finger that triggered a touch event
- // (useful when tracking multiple simultaneous
- // touches)
-#endif
- // NOTE for XInput MT: 'Tracking ID' is provided in every touch event to
- // track individual touch. 'Tracking ID' is an unsigned 32-bit value and
- // is increased for each new touch. It will wrap back to 0 when reaching
- // the numerical limit.
- TP_TRACKING_ID, // ID of the touch point.
-
- TP_LAST_ENTRY
- };
-
// Returns the TouchFactory singleton.
static TouchFactory* GetInstance();
@@ -120,24 +87,6 @@ class UI_EXPORT TouchFactory {
return is_cursor_visible_;
}
- // Extract the TouchParam from the XEvent. Return true and the value is set
- // if the TouchParam is found, false and value unchanged if the TouchParam
- // is not found.
- bool ExtractTouchParam(const XEvent& xev, TouchParam tp, float* value);
-
- // Normalize the TouchParam with value on deviceid to fall into [0, 1].
- // *value = (*value - min_value_of_tp) / (max_value_of_tp - min_value_of_tp)
- // Returns true and sets the normalized value in|value| if normalization is
- // successful. Returns false and |value| is unchanged otherwise.
- bool NormalizeTouchParam(unsigned int deviceid, TouchParam tp, float* value);
-
- // Extract the range of the TouchParam. Return true if the range is available
- // and written into min & max, false if the range is not available.
- bool GetTouchParamRange(unsigned int deviceid,
- TouchParam tp,
- float* min,
- float* max);
-
// Whether any touch device is currently present and enabled.
bool IsTouchDevicePresent();
@@ -146,10 +95,6 @@ class UI_EXPORT TouchFactory {
SetCursorVisible(false, false);
}
- // Setup the internal bookkeeping of the touch params valuator information for
- // touch devices
- void SetupValuator();
-
// Requirement for Signleton
friend struct DefaultSingletonTraits<TouchFactory>;
@@ -198,18 +143,6 @@ class UI_EXPORT TouchFactory {
// capable.
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
- // index at the expense of space. If the kMaxDeviceNum grows larger that the
- // space waste becomes a concern, the 2D lookup table can be replaced by a
- // hash map.
- signed char valuator_lookup_[kMaxDeviceNum][TP_LAST_ENTRY];
-
- // Index table to find the min & max value of the TouchParam on a specific
- // device.
- int touch_param_min_[kMaxDeviceNum][TP_LAST_ENTRY];
- int touch_param_max_[kMaxDeviceNum][TP_LAST_ENTRY];
-
// Maximum simultaneous touch points.
static const int kMaxTouchPoints = 32;