summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-17 16:06:35 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-17 16:06:35 +0000
commit5951806fdc9a6d3063014b0479307dba66767f97 (patch)
tree1b52d819db6119600bcaeab8f51ccc3a3d48c925 /views
parentb5ad6bd0e8eda70dc4f3b1dbd6229f9d82cdb17b (diff)
downloadchromium_src-5951806fdc9a6d3063014b0479307dba66767f97.zip
chromium_src-5951806fdc9a6d3063014b0479307dba66767f97.tar.gz
chromium_src-5951806fdc9a6d3063014b0479307dba66767f97.tar.bz2
aura: Add support for touch events.
Among the changes: . Add touch event handling in EventFilter. Be default, activates a window on TOUCH_START (like for MOUSE_PRESSED). . Move TouchEvent details functions into ui/. Moved the X11 implementations from views/ to ui/. NOTIMPLEMENTED on windows. . Disable RWHVAura et. al. for touchui for now (they are still compiled in, but not used). BUG=100269 TEST=none Review URL: http://codereview.chromium.org/8274025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105816 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/aura_desktop/aura_desktop_main.cc5
-rw-r--r--views/events/event.h2
-rw-r--r--views/events/event_aura.cc12
-rw-r--r--views/events/event_x.cc61
-rw-r--r--views/touchui/gesture_manager.cc2
-rw-r--r--views/widget/native_widget_aura.cc8
-rw-r--r--views/widget/native_widget_aura.h4
7 files changed, 34 insertions, 60 deletions
diff --git a/views/aura_desktop/aura_desktop_main.cc b/views/aura_desktop/aura_desktop_main.cc
index aca5b14..033c21a 100644
--- a/views/aura_desktop/aura_desktop_main.cc
+++ b/views/aura_desktop/aura_desktop_main.cc
@@ -49,7 +49,10 @@ class DemoWindowDelegate : public aura::WindowDelegate {
virtual bool OnMouseEvent(aura::MouseEvent* event) OVERRIDE {
return true;
}
- virtual bool ShouldActivate(aura::MouseEvent* event) OVERRIDE {
+ virtual ui::TouchStatus OnTouchEvent(aura::TouchEvent* event) OVERRIDE {
+ return ui::TOUCH_STATUS_END;
+ }
+ virtual bool ShouldActivate(aura::Event* event) OVERRIDE {
return true;
}
virtual void OnActivated() OVERRIDE {}
diff --git a/views/events/event.h b/views/events/event.h
index 5312ecd..a7b3620 100644
--- a/views/events/event.h
+++ b/views/events/event.h
@@ -243,7 +243,7 @@ class VIEWS_EXPORT MouseEvent : public LocatedEvent {
////////////////////////////////////////////////////////////////////////////////
class VIEWS_EXPORT TouchEvent : public LocatedEvent {
public:
- explicit TouchEvent(const base::NativeEvent& native_event);
+ explicit TouchEvent(const NativeEvent& native_event);
// Create a new touch event.
TouchEvent(ui::EventType type,
diff --git a/views/events/event_aura.cc b/views/events/event_aura.cc
index dca43fd..bf6a1c5 100644
--- a/views/events/event_aura.cc
+++ b/views/events/event_aura.cc
@@ -18,6 +18,18 @@ LocatedEvent::LocatedEvent(const NativeEvent& native_event)
}
////////////////////////////////////////////////////////////////////////////////
+// TouchEvent, public:
+
+TouchEvent::TouchEvent(const NativeEvent& event)
+ : LocatedEvent(event),
+ touch_id_(static_cast<aura::TouchEvent*>(event)->touch_id()),
+ radius_x_(static_cast<aura::TouchEvent*>(event)->radius_x()),
+ radius_y_(static_cast<aura::TouchEvent*>(event)->radius_y()),
+ rotation_angle_(static_cast<aura::TouchEvent*>(event)->rotation_angle()),
+ force_(static_cast<aura::TouchEvent*>(event)->force()) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
// KeyEvent, public:
KeyEvent::KeyEvent(const NativeEvent& native_event)
diff --git a/views/events/event_x.cc b/views/events/event_x.cc
index 7dbaedb..1c1c51d 100644
--- a/views/events/event_x.cc
+++ b/views/events/event_x.cc
@@ -11,6 +11,7 @@
#include "base/logging.h"
#include "base/utf_string_conversions.h"
+#include "ui/base/events.h"
#include "ui/base/keycodes/keyboard_code_conversion_x.h"
#include "ui/base/touch/touch_factory.h"
#include "views/widget/root_view.h"
@@ -19,31 +20,6 @@ namespace views {
namespace {
-int GetTouchIDFromXEvent(XEvent* xev) {
- float slot = 0;
- ui::TouchFactory* factory = ui::TouchFactory::GetInstance();
- XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data);
- if (!factory->IsRealTouchDevice(xievent->sourceid)) {
- // TODO(sad): Come up with a way to generate touch-ids for multi-touch
- // events when touch-events are generated from a mouse.
- return slot;
- }
-
-#if defined(USE_XI2_MT)
- float tracking_id;
- if (!factory->ExtractTouchParam(
- *xev, ui::TouchFactory::TP_TRACKING_ID, &tracking_id))
- LOG(ERROR) << "Could not get the slot ID for the event. Using 0.";
- else
- slot = factory->GetSlotForTrackingID(tracking_id);
-#else
- if (!factory->ExtractTouchParam(
- *xev, ui::TouchFactory::TP_SLOT_ID, &slot))
- LOG(ERROR) << "Could not get the slot ID for the event. Using 0.";
-#endif
- return slot;
-}
-
uint16 GetCharacterFromXKeyEvent(XKeyEvent* key) {
char buf[6];
int bytes_written = XLookupString(key, buf, 6, NULL, NULL);
@@ -54,25 +30,6 @@ uint16 GetCharacterFromXKeyEvent(XKeyEvent* key) {
result.length() == 1) ? result[0] : 0;
}
-float GetTouchParamFromXEvent(XEvent* xev,
- ui::TouchFactory::TouchParam tp,
- float default_value) {
- ui::TouchFactory::GetInstance()->ExtractTouchParam(*xev, tp, &default_value);
- return default_value;
-}
-
-float GetTouchForceFromXEvent(XEvent* xev) {
- float force = 0.0;
- force = GetTouchParamFromXEvent(xev, ui::TouchFactory::TP_PRESSURE, 0.0);
- unsigned int deviceid =
- static_cast<XIDeviceEvent*>(xev->xcookie.data)->sourceid;
- // Force is normalized to fall into [0, 1]
- if (!ui::TouchFactory::GetInstance()->NormalizeTouchParam(
- deviceid, ui::TouchFactory::TP_PRESSURE, &force))
- force = 0.0;
- return force;
-}
-
// The following two functions are copied from event_gtk.cc. These will be
// removed when GTK dependency is removed.
#if defined(TOOLKIT_USES_GTK)
@@ -171,17 +128,11 @@ uint16 KeyEvent::GetUnmodifiedCharacter() const {
TouchEvent::TouchEvent(const base::NativeEvent& native_event)
: LocatedEvent(native_event),
- touch_id_(GetTouchIDFromXEvent(native_event)),
- radius_x_(GetTouchParamFromXEvent(native_event,
- ui::TouchFactory::TP_TOUCH_MAJOR,
- 2.0) / 2.0),
- radius_y_(GetTouchParamFromXEvent(native_event,
- ui::TouchFactory::TP_TOUCH_MINOR,
- 2.0) / 2.0),
- rotation_angle_(GetTouchParamFromXEvent(native_event,
- ui::TouchFactory::TP_ORIENTATION,
- 0.0)),
- force_(GetTouchForceFromXEvent(native_event)) {
+ touch_id_(ui::GetTouchId(native_event)),
+ radius_x_(ui::GetTouchRadiusX(native_event)),
+ radius_y_(ui::GetTouchRadiusY(native_event)),
+ rotation_angle_(ui::GetTouchAngle(native_event)),
+ force_(ui::GetTouchForce(native_event)) {
#if defined(USE_XI2_MT)
if (type() == ui::ET_TOUCH_RELEASED) {
// NOTE: The slot is allocated by TouchFactory for each XI_TouchBegin
diff --git a/views/touchui/gesture_manager.cc b/views/touchui/gesture_manager.cc
index 723db77..0ffc1e5 100644
--- a/views/touchui/gesture_manager.cc
+++ b/views/touchui/gesture_manager.cc
@@ -49,7 +49,7 @@ bool GestureManager::ProcessTouchEventForGesture(const TouchEvent& event,
} else {
Widget* source_widget = source->GetWidget();
Widget* top_widget = source_widget->GetTopLevelWidget();
- if (source_widget != top_widget) {
+ if (source_widget != top_widget && top_widget) {
// This is necessary as TYPE_CHILD widget is still NativeWidgetGtk.
// Fix this once TYPE_CHILD is switched to NativeWidgetViews.
MouseEvent converted(mouseev,
diff --git a/views/widget/native_widget_aura.cc b/views/widget/native_widget_aura.cc
index 1158e7b..18c82cd 100644
--- a/views/widget/native_widget_aura.cc
+++ b/views/widget/native_widget_aura.cc
@@ -521,7 +521,13 @@ bool NativeWidgetAura::OnMouseEvent(aura::MouseEvent* event) {
return delegate_->OnMouseEvent(mouse_event);
}
-bool NativeWidgetAura::ShouldActivate(aura::MouseEvent* event) {
+ui::TouchStatus NativeWidgetAura::OnTouchEvent(aura::TouchEvent* event) {
+ DCHECK(window_->IsVisible());
+ TouchEvent touch_event(event);
+ return delegate_->OnTouchEvent(touch_event);
+}
+
+bool NativeWidgetAura::ShouldActivate(aura::Event* event) {
return can_activate_;
}
diff --git a/views/widget/native_widget_aura.h b/views/widget/native_widget_aura.h
index a21637b..9ba5f86 100644
--- a/views/widget/native_widget_aura.h
+++ b/views/widget/native_widget_aura.h
@@ -9,6 +9,7 @@
#include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h"
#include "ui/aura/window_delegate.h"
+#include "ui/base/events.h"
#include "views/views_export.h"
#include "views/widget/native_widget_private.h"
@@ -131,7 +132,8 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE;
virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE;
virtual bool OnMouseEvent(aura::MouseEvent* event) OVERRIDE;
- virtual bool ShouldActivate(aura::MouseEvent* event) OVERRIDE;
+ virtual ui::TouchStatus OnTouchEvent(aura::TouchEvent* event) OVERRIDE;
+ virtual bool ShouldActivate(aura::Event* event) OVERRIDE;
virtual void OnActivated() OVERRIDE;
virtual void OnLostActive() OVERRIDE;
virtual void OnCaptureLost() OVERRIDE;