summaryrefslogtreecommitdiffstats
path: root/views/events
diff options
context:
space:
mode:
authormiletus@chromium.org <miletus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-18 17:42:52 +0000
committermiletus@chromium.org <miletus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-18 17:42:52 +0000
commitf9740e86231f2ed7eef6bb782e028b708833e243 (patch)
treefc50d4b56dfff78faaff92b11f823ae0f04baa21 /views/events
parentbf2ecb42b2821b9609ce5736d8218c730011d7db (diff)
downloadchromium_src-f9740e86231f2ed7eef6bb782e028b708833e243.zip
chromium_src-f9740e86231f2ed7eef6bb782e028b708833e243.tar.gz
chromium_src-f9740e86231f2ed7eef6bb782e028b708833e243.tar.bz2
Add extra touch information and related API to views::TouchEvent.
Some touch devices provide, other than (x,y) location, extra touch information. views::TouchEvent is changed to keep track of touch radius, touch angle and ratio between major and minor touch axis. To be able to query what extra touch data is supported by the device, bookkeeping of the device supported TouchParams is added to views::TouchFactory. Next step will be routing these touch information to WebKit. BUG= TEST= Review URL: http://codereview.chromium.org/6820004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81963 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/events')
-rw-r--r--views/events/event.cc41
-rw-r--r--views/events/event.h34
-rw-r--r--views/events/event_x.cc58
3 files changed, 104 insertions, 29 deletions
diff --git a/views/events/event.cc b/views/events/event.cc
index dfab221..ac3bd2a 100644
--- a/views/events/event.cc
+++ b/views/events/event.cc
@@ -189,27 +189,38 @@ MouseEvent::MouseEvent(const MouseEvent& model, View* source, View* target)
// TouchEvent, public:
#if defined(TOUCH_UI)
-TouchEvent::TouchEvent(ui::EventType type, int x, int y, int flags,
- int touch_id)
- : LocatedEvent(type, gfx::Point(x, y), flags),
- touch_id_(touch_id) {
-}
-
-
TouchEvent::TouchEvent(ui::EventType type,
- View* source,
- View* target,
- const gfx::Point& l,
+ int x,
+ int y,
int flags,
- int touch_id)
- : LocatedEvent(TouchEvent(type, l.x(), l.y(), flags, touch_id), source,
- target),
- touch_id_(touch_id) {
+ int touch_id,
+ float radius,
+ float angle,
+ float ratio)
+ : LocatedEvent(type, gfx::Point(x, y), flags),
+ touch_id_(touch_id),
+ radius_(radius),
+ angle_(angle),
+ ratio_(ratio) {
}
TouchEvent::TouchEvent(const TouchEvent& model, View* source, View* target)
: LocatedEvent(model, source, target),
- touch_id_(model.touch_id_) {
+ touch_id_(model.touch_id_),
+ radius_(model.radius_),
+ angle_(model.angle_),
+ ratio_(model.ratio_) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// TouchEvent, private:
+
+TouchEvent::TouchEvent(const TouchEvent& model, RootView* root)
+ : LocatedEvent(model, root),
+ touch_id_(model.touch_id_),
+ radius_(model.radius_),
+ angle_(model.angle_),
+ ratio_(model.ratio_) {
}
#endif
diff --git a/views/events/event.h b/views/events/event.h
index 2a11d37..12e2e2f 100644
--- a/views/events/event.h
+++ b/views/events/event.h
@@ -240,17 +240,14 @@ class TouchEvent : public LocatedEvent {
TouchEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native);
// Create a new touch event.
- TouchEvent(ui::EventType type, int x, int y, int flags, int touch_id);
-
- // Create a new touch event from a type and a point. If from / to views
- // are provided, the point will be converted from 'source' coordinate system
- // to 'target' coordinate system.
TouchEvent(ui::EventType type,
- View* source,
- View* target,
- const gfx::Point& l,
+ int x,
+ int y,
int flags,
- int touch_id);
+ int touch_id,
+ float radius,
+ float angle,
+ float ratio);
// Create a new TouchEvent which is identical to the provided model.
// If source / target views are provided, the model location will be converted
@@ -259,18 +256,29 @@ class TouchEvent : public LocatedEvent {
int identity() const { return touch_id_; }
+ float radius() const { return radius_; }
+ float angle() const { return angle_; }
+ float ratio() const { return ratio_; }
+
private:
friend class RootView;
- TouchEvent(const TouchEvent& model, RootView* root)
- : LocatedEvent(model, root),
- touch_id_(model.touch_id_) {
- }
+ TouchEvent(const TouchEvent& model, RootView* root);
// The identity (typically finger) of the touch starting at 0 and incrementing
// for each separable additional touch that the hardware can detect.
const int touch_id_;
+ // Half length of the major axis of the touch ellipse. Default 0.0.
+ const float radius_;
+
+ // Angle of the major axis away from the X axis. Default 0.0.
+ const float angle_;
+
+ // Length ratio between major axis and minor axis of the touch ellipse. 1.0
+ // if only the major axis is available, prentending the touch is a circle.
+ const float ratio_;
+
DISALLOW_COPY_AND_ASSIGN(TouchEvent);
};
#endif
diff --git a/views/events/event_x.cc b/views/events/event_x.cc
index ebbcfc1..65a1281 100644
--- a/views/events/event_x.cc
+++ b/views/events/event_x.cc
@@ -16,6 +16,10 @@
#include "views/widget/root_view.h"
#include "views/widget/widget_gtk.h"
+#if defined(HAVE_XINPUT2)
+#include "views/touchui/touch_factory.h"
+#endif
+
namespace views {
namespace {
@@ -226,6 +230,55 @@ uint16 GetCharacterFromXKeyEvent(XKeyEvent* key) {
result.length() == 1) ? result[0] : 0;
}
+float GetTouchRadiusFromXEvent(XEvent* xev) {
+ float diameter = 0.0;
+
+#if defined(HAVE_XINPUT2)
+ TouchFactory* touch_factory = TouchFactory::GetInstance();
+ touch_factory->ExtractTouchParam(*xev, TouchFactory::TP_TOUCH_MAJOR,
+ &diameter);
+#endif
+
+ return diameter / 2.0;
+}
+
+float GetTouchAngleFromXEvent(XEvent* xev) {
+ float angle = 0.0;
+
+#if defined(HAVE_XINPUT2)
+ TouchFactory* touch_factory = TouchFactory::GetInstance();
+ touch_factory->ExtractTouchParam(*xev, TouchFactory::TP_ORIENTATION,
+ &angle);
+#endif
+
+ return angle;
+}
+
+
+float GetTouchRatioFromXEvent(XEvent* xev) {
+ float ratio = 1.0;
+
+#if defined(HAVE_XINPUT2)
+ TouchFactory* touch_factory = TouchFactory::GetInstance();
+ float major_v = -1.0;
+ float minor_v = -1.0;
+
+ if (!touch_factory->ExtractTouchParam(*xev,
+ TouchFactory::TP_TOUCH_MAJOR,
+ &major_v) ||
+ !touch_factory->ExtractTouchParam(*xev,
+ TouchFactory::TP_TOUCH_MINOR,
+ &minor_v))
+ return ratio;
+
+ // In case minor axis exists but is zero.
+ if (minor_v > 0.0)
+ ratio = major_v / minor_v;
+#endif
+
+ return ratio;
+}
+
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -318,7 +371,10 @@ TouchEvent::TouchEvent(NativeEvent2 native_event_2,
: LocatedEvent(GetTouchEventType(native_event_2),
GetEventLocation(native_event_2),
GetLocatedEventFlags(native_event_2, true)),
- touch_id_(GetTouchIDFromXEvent(native_event_2)) {
+ touch_id_(GetTouchIDFromXEvent(native_event_2)),
+ radius_(GetTouchRadiusFromXEvent(native_event_2)),
+ angle_(GetTouchAngleFromXEvent(native_event_2)),
+ ratio_(GetTouchRatioFromXEvent(native_event_2)) {
}
#endif