Commit 43b7e059 authored by sadrul@chromium.org's avatar sadrul@chromium.org

x11: Listen for and process XInput2 events.

Use XInput2 events for mouse, keyboard, and touch events in X11Window. This allows
interacting with mojo_shell with touch.

BUG=361137
R=sky@chromium.org

Review URL: https://codereview.chromium.org/399743003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283996 0039d316-1c4b-4281-b951-d872f2087c98
parent 5d7b717c
...@@ -98,6 +98,20 @@ TypeConverter<EventPtr, scoped_ptr<ui::Event> >::ConvertTo( ...@@ -98,6 +98,20 @@ TypeConverter<EventPtr, scoped_ptr<ui::Event> >::ConvertTo(
input->flags)); input->flags));
break; break;
} }
case ui::ET_TOUCH_MOVED:
case ui::ET_TOUCH_PRESSED:
case ui::ET_TOUCH_CANCELLED:
case ui::ET_TOUCH_RELEASED: {
gfx::Point location(input->location->x, input->location->y);
ui_event.reset(new ui::TouchEvent(
static_cast<ui::EventType>(input->action),
location,
input->flags,
input->touch_data->pointer_id,
base::TimeDelta::FromInternalValue(input->time_stamp),
0.f, 0.f, 0.f, 0.f));
break;
}
default: default:
// TODO: support other types. // TODO: support other types.
// NOTIMPLEMENTED(); // NOTIMPLEMENTED();
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "mojo/services/view_manager/window_tree_host_impl.h" #include "mojo/services/view_manager/window_tree_host_impl.h"
#include "mojo/public/c/gles2/gles2.h" #include "mojo/public/c/gles2/gles2.h"
#include "mojo/services/public/cpp/geometry/geometry_type_converters.h" #include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
#include "mojo/services/public/cpp/input_events/input_events_type_converters.h"
#include "mojo/services/view_manager/context_factory_impl.h" #include "mojo/services/view_manager/context_factory_impl.h"
#include "ui/aura/env.h" #include "ui/aura/env.h"
#include "ui/aura/layout_manager.h" #include "ui/aura/layout_manager.h"
...@@ -185,38 +186,10 @@ void WindowTreeHostImpl::OnDestroyed(const mojo::Callback<void()>& callback) { ...@@ -185,38 +186,10 @@ void WindowTreeHostImpl::OnDestroyed(const mojo::Callback<void()>& callback) {
void WindowTreeHostImpl::OnEvent(EventPtr event, void WindowTreeHostImpl::OnEvent(EventPtr event,
const mojo::Callback<void()>& callback) { const mojo::Callback<void()>& callback) {
switch (event->action) { scoped_ptr<ui::Event> ui_event =
case ui::ET_MOUSE_PRESSED: TypeConverter<EventPtr, scoped_ptr<ui::Event> >::ConvertTo(event);
case ui::ET_MOUSE_DRAGGED: if (ui_event)
case ui::ET_MOUSE_RELEASED: SendEventToProcessor(ui_event.get());
case ui::ET_MOUSE_MOVED:
case ui::ET_MOUSE_ENTERED:
case ui::ET_MOUSE_EXITED: {
gfx::Point location(event->location->x, event->location->y);
ui::MouseEvent ev(static_cast<ui::EventType>(event->action), location,
location, event->flags, 0);
SendEventToProcessor(&ev);
break;
}
case ui::ET_MOUSEWHEEL: {
gfx::Vector2d offset(event->wheel_data->x_offset,
event->wheel_data->y_offset);
gfx::Point location(event->location->x, event->location->y);
ui::MouseWheelEvent ev(offset, location, location, event->flags, 0);
SendEventToProcessor(&ev);
break;
}
case ui::ET_KEY_PRESSED:
case ui::ET_KEY_RELEASED: {
ui::KeyEvent ev(
static_cast<ui::EventType>(event->action),
static_cast<ui::KeyboardCode>(event->key_data->key_code),
event->flags, event->key_data->is_char);
SendEventToProcessor(&ev);
break;
}
// TODO(beng): touch, etc.
}
callback.Run(); callback.Run();
}; };
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "ui/events/platform/platform_event_dispatcher.h" #include "ui/events/platform/platform_event_dispatcher.h"
#include "ui/events/platform/platform_event_source.h" #include "ui/events/platform/platform_event_source.h"
#include "ui/events/platform/x11/x11_event_source.h" #include "ui/events/platform/x11/x11_event_source.h"
#include "ui/events/x/touch_factory_x11.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/x/x11_atom_cache.h" #include "ui/gfx/x/x11_atom_cache.h"
#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/x11_types.h"
...@@ -47,6 +48,7 @@ X11Window::X11Window(PlatformWindowDelegate* delegate) ...@@ -47,6 +48,7 @@ X11Window::X11Window(PlatformWindowDelegate* delegate)
atom_cache_(xdisplay_, kAtomsToCache), atom_cache_(xdisplay_, kAtomsToCache),
window_mapped_(false) { window_mapped_(false) {
CHECK(delegate_); CHECK(delegate_);
TouchFactory::SetTouchDeviceListFromCommandLine();
} }
X11Window::~X11Window() { X11Window::~X11Window() {
...@@ -63,6 +65,50 @@ void X11Window::Destroy() { ...@@ -63,6 +65,50 @@ void X11Window::Destroy() {
xwindow_ = None; xwindow_ = None;
} }
void X11Window::ProcessXInput2Event(XEvent* xev) {
if (!TouchFactory::GetInstance()->ShouldProcessXI2Event(xev))
return;
EventType event_type = EventTypeFromNative(xev);
switch (event_type) {
case ET_KEY_PRESSED:
case ET_KEY_RELEASED: {
KeyEvent key_event(xev, false);
delegate_->DispatchEvent(&key_event);
break;
}
case ET_MOUSE_PRESSED:
case ET_MOUSE_MOVED:
case ET_MOUSE_DRAGGED:
case ET_MOUSE_RELEASED: {
MouseEvent mouse_event(xev);
delegate_->DispatchEvent(&mouse_event);
break;
}
case ET_MOUSEWHEEL: {
MouseWheelEvent wheel_event(xev);
delegate_->DispatchEvent(&wheel_event);
break;
}
case ET_SCROLL_FLING_START:
case ET_SCROLL_FLING_CANCEL:
case ET_SCROLL: {
ScrollEvent scroll_event(xev);
delegate_->DispatchEvent(&scroll_event);
break;
}
case ET_TOUCH_MOVED:
case ET_TOUCH_PRESSED:
case ET_TOUCH_CANCELLED:
case ET_TOUCH_RELEASED: {
TouchEvent touch_event(xev);
delegate_->DispatchEvent(&touch_event);
break;
}
default:
break;
}
}
void X11Window::Show() { void X11Window::Show() {
if (window_mapped_) if (window_mapped_)
return; return;
...@@ -100,6 +146,11 @@ void X11Window::Show() { ...@@ -100,6 +146,11 @@ void X11Window::Show() {
XISetMask(mask, XI_TouchBegin); XISetMask(mask, XI_TouchBegin);
XISetMask(mask, XI_TouchUpdate); XISetMask(mask, XI_TouchUpdate);
XISetMask(mask, XI_TouchEnd); XISetMask(mask, XI_TouchEnd);
XISetMask(mask, XI_ButtonPress);
XISetMask(mask, XI_ButtonRelease);
XISetMask(mask, XI_Motion);
XISetMask(mask, XI_KeyPress);
XISetMask(mask, XI_KeyRelease);
XIEventMask evmask; XIEventMask evmask;
evmask.deviceid = XIAllDevices; evmask.deviceid = XIAllDevices;
...@@ -292,6 +343,11 @@ uint32_t X11Window::DispatchEvent(const PlatformEvent& event) { ...@@ -292,6 +343,11 @@ uint32_t X11Window::DispatchEvent(const PlatformEvent& event) {
} }
break; break;
} }
case GenericEvent: {
ProcessXInput2Event(xev);
break;
}
} }
return POST_DISPATCH_STOP_PROPAGATION; return POST_DISPATCH_STOP_PROPAGATION;
} }
......
...@@ -26,6 +26,8 @@ class X11_WINDOW_EXPORT X11Window : public PlatformWindow, ...@@ -26,6 +26,8 @@ class X11_WINDOW_EXPORT X11Window : public PlatformWindow,
private: private:
void Destroy(); void Destroy();
void ProcessXInput2Event(XEvent* xevent);
// PlatformWindow: // PlatformWindow:
virtual void Show() OVERRIDE; virtual void Show() OVERRIDE;
virtual void Hide() OVERRIDE; virtual void Hide() OVERRIDE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment