summaryrefslogtreecommitdiffstats
path: root/views/events
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/events
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/events')
-rw-r--r--views/events/event.cc12
-rw-r--r--views/events/event.h11
-rw-r--r--views/events/event_x.cc21
3 files changed, 34 insertions, 10 deletions
diff --git a/views/events/event.cc b/views/events/event.cc
index 8ec7ea8..93e5735 100644
--- a/views/events/event.cc
+++ b/views/events/event.cc
@@ -187,12 +187,14 @@ TouchEvent::TouchEvent(ui::EventType type,
int touch_id,
float radius_x,
float radius_y,
- float angle)
+ float angle,
+ float force)
: LocatedEvent(type, gfx::Point(x, y), flags),
touch_id_(touch_id),
radius_x_(radius_x),
radius_y_(radius_y),
- angle_(angle) {
+ rotation_angle_(angle),
+ force_(force) {
}
TouchEvent::TouchEvent(const TouchEvent& model, View* source, View* target)
@@ -200,7 +202,8 @@ TouchEvent::TouchEvent(const TouchEvent& model, View* source, View* target)
touch_id_(model.touch_id_),
radius_x_(model.radius_x_),
radius_y_(model.radius_y_),
- angle_(model.angle_) {
+ rotation_angle_(model.rotation_angle_),
+ force_(model.force_) {
}
////////////////////////////////////////////////////////////////////////////////
@@ -211,7 +214,8 @@ TouchEvent::TouchEvent(const TouchEvent& model, View* root)
touch_id_(model.touch_id_),
radius_x_(model.radius_x_),
radius_y_(model.radius_y_),
- angle_(model.angle_) {
+ rotation_angle_(model.rotation_angle_),
+ force_(model.force_) {
}
#endif
diff --git a/views/events/event.h b/views/events/event.h
index 9b1d33a..531b506 100644
--- a/views/events/event.h
+++ b/views/events/event.h
@@ -263,7 +263,8 @@ class TouchEvent : public LocatedEvent {
int touch_id,
float radius_x,
float radius_y,
- float angle);
+ float angle,
+ float force);
// Create a new TouchEvent which is identical to the provided model.
// If source / target views are provided, the model location will be converted
@@ -274,7 +275,8 @@ class TouchEvent : public LocatedEvent {
float radius_x() const { return radius_x_; }
float radius_y() const { return radius_y_; }
- float angle() const { return angle_; }
+ float rotation_angle() const { return rotation_angle_; }
+ float force() const { return force_; }
private:
friend class internal::RootView;
@@ -292,7 +294,10 @@ class TouchEvent : public LocatedEvent {
const float radius_y_;
// Angle of the major axis away from the X axis. Default 0.0.
- const float angle_;
+ const float rotation_angle_;
+
+ // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0.
+ const float force_;
DISALLOW_COPY_AND_ASSIGN(TouchEvent);
};
diff --git a/views/events/event_x.cc b/views/events/event_x.cc
index 0fa471e..ec1d722 100644
--- a/views/events/event_x.cc
+++ b/views/events/event_x.cc
@@ -254,6 +254,20 @@ float GetTouchParamFromXEvent(XEvent* xev,
return default_value;
}
+float GetTouchForceFromXEvent(XEvent* xev) {
+ float force = 0.0;
+#if defined(HAVE_XINPUT2)
+ force = GetTouchParamFromXEvent(xev, TouchFactory::TP_PRESSURE, 0.0);
+ unsigned int deviceid =
+ static_cast<XIDeviceEvent*>(xev->xcookie.data)->sourceid;
+ // Force is normalized to fall into [0, 1]
+ if (!TouchFactory::GetInstance()->NormalizeTouchParam(
+ deviceid, TouchFactory::TP_PRESSURE, &force))
+ force = 0.0;
+#endif
+ return force;
+}
+
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -387,9 +401,10 @@ TouchEvent::TouchEvent(NativeEvent2 native_event_2,
radius_y_(GetTouchParamFromXEvent(native_event_2,
TouchFactory::TP_TOUCH_MINOR,
2.0) / 2.0),
- angle_(GetTouchParamFromXEvent(native_event_2,
- TouchFactory::TP_ORIENTATION,
- 0.0)) {
+ rotation_angle_(GetTouchParamFromXEvent(native_event_2,
+ TouchFactory::TP_ORIENTATION,
+ 0.0)),
+ force_(GetTouchForceFromXEvent(native_event_2)) {
if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) {
TouchFactory* factory = TouchFactory::GetInstance();
float slot;