summaryrefslogtreecommitdiffstats
path: root/views/touchui
diff options
context:
space:
mode:
authormiletus@chromium.org <miletus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-16 22:04:54 +0000
committermiletus@chromium.org <miletus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-16 22:04:54 +0000
commitbc9b2f4215e0ee88e0faaa42a1f116231ce2a311 (patch)
tree96ee0fbd3bb9743cb4628ac4635db2eb5c7a799e /views/touchui
parentd6329956970efea131fa4c8423cfc0eb0be597ec (diff)
downloadchromium_src-bc9b2f4215e0ee88e0faaa42a1f116231ce2a311.zip
chromium_src-bc9b2f4215e0ee88e0faaa42a1f116231ce2a311.tar.gz
chromium_src-bc9b2f4215e0ee88e0faaa42a1f116231ce2a311.tar.bz2
Add pressure information to touch event.
1. Add touch pressure information to the views::TouchEvent. The pressure is normalized to be in [0, 1] to conform with W3C Touch Event standard (draft)'s definition on pressure. 2. Augment TouchFactory with the ability to save/query the range of TouchParam. In this patch, the max value of pressure is used to normalize the absolute pressure value extracted from the touch device. BUG=None TEST=None Review URL: http://codereview.chromium.org/7149002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89408 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/touchui')
-rw-r--r--views/touchui/touch_factory.cc55
-rw-r--r--views/touchui/touch_factory.h19
2 files changed, 63 insertions, 11 deletions
diff --git a/views/touchui/touch_factory.cc b/views/touchui/touch_factory.cc
index 17542ad..772e47e 100644
--- a/views/touchui/touch_factory.cc
+++ b/views/touchui/touch_factory.cc
@@ -21,11 +21,11 @@ namespace {
// The X cursor is hidden if it is idle for kCursorIdleSeconds seconds.
int kCursorIdleSeconds = 5;
-// Given the TouchParam, return the correspoding valuator index using
+// Given the TouchParam, return the correspoding XIValuatorClassInfo using
// the X device information through Atom name matching.
-char FindTPValuator(Display* display,
- XIDeviceInfo* info,
- views::TouchFactory::TouchParam touch_param) {
+XIValuatorClassInfo* FindTPValuator(Display* display,
+ XIDeviceInfo* info,
+ views::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.
// For Slot ID, See this chromeos revision: http://git.chromium.org/gitweb/?
@@ -38,6 +38,7 @@ char FindTPValuator(Display* display,
{ views::TouchFactory::TP_TOUCH_MAJOR, "Abs MT Touch Major" },
{ views::TouchFactory::TP_TOUCH_MINOR, "Abs MT Touch Minor" },
{ views::TouchFactory::TP_ORIENTATION, "Abs MT Orientation" },
+ { views::TouchFactory::TP_PRESSURE, "Abs MT Pressure" },
{ views::TouchFactory::TP_SLOT_ID, "Abs MT Slot ID" },
{ views::TouchFactory::TP_TRACKING_ID, "Abs MT Tracking ID" },
{ views::TouchFactory::TP_LAST_ENTRY, NULL },
@@ -46,14 +47,14 @@ char FindTPValuator(Display* display,
const char* atom_tp = NULL;
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTouchParamAtom); i++) {
- if (touch_param == kTouchParamAtom[i].tp) {
+ if (tp == kTouchParamAtom[i].tp) {
atom_tp = kTouchParamAtom[i].atom;
break;
}
}
if (!atom_tp)
- return -1;
+ return NULL;
for (int i = 0; i < info->num_classes; i++) {
if (info->classes[i]->type != XIValuatorClass)
@@ -63,10 +64,10 @@ char FindTPValuator(Display* display,
const char* atom = XGetAtomName(display, v->label);
if (atom && strcmp(atom, atom_tp) == 0)
- return v->number;
+ return v;
}
- return -1;
+ return NULL;
}
// Setup XInput2 select for the GtkWidget.
@@ -349,6 +350,8 @@ void TouchFactory::SetCursorVisible(bool show, bool start_timer) {
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;
@@ -360,9 +363,14 @@ void TouchFactory::SetupValuator() {
if (!IsTouchDevice(info->deviceid))
continue;
- for (int i = 0; i < TP_LAST_ENTRY; i++) {
- TouchParam tp = static_cast<TouchParam>(i);
- valuator_lookup_[info->deviceid][i] = FindTPValuator(display, info, tp);
+ 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;
+ }
}
}
@@ -385,4 +393,29 @@ bool TouchFactory::ExtractTouchParam(const XEvent& xev,
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;
+}
+
} // namespace views
diff --git a/views/touchui/touch_factory.h b/views/touchui/touch_factory.h
index 9929483..201f5bd 100644
--- a/views/touchui/touch_factory.h
+++ b/views/touchui/touch_factory.h
@@ -28,6 +28,7 @@ class TouchFactory {
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.
@@ -98,6 +99,19 @@ class TouchFactory {
// 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);
+
void set_keep_mouse_cursor(bool keep) { keep_mouse_cursor_ = keep; }
bool keep_mouse_cursor() const { return keep_mouse_cursor_; }
@@ -162,6 +176,11 @@ class TouchFactory {
// hash map.
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;