Chromium Code Reviews| Index: ui/events/ozone/evdev/tablet_event_converter_evdev.cc |
| diff --git a/ui/events/ozone/evdev/tablet_event_converter_evdev.cc b/ui/events/ozone/evdev/tablet_event_converter_evdev.cc |
| index 58dafb931298dbd787936cd77f758dde4b0badb6..a738dbbf90592c253d4f477f03ed726fc027c775 100644 |
| --- a/ui/events/ozone/evdev/tablet_event_converter_evdev.cc |
| +++ b/ui/events/ozone/evdev/tablet_event_converter_evdev.cc |
| @@ -8,6 +8,7 @@ |
| #include <linux/input.h> |
| #include "base/message_loop/message_loop.h" |
| +#include "base/time/time.h" |
| #include "ui/events/event.h" |
| namespace ui { |
| @@ -26,11 +27,15 @@ TabletEventConverterEvdev::TabletEventConverterEvdev( |
| modifiers_(modifiers), |
| callback_(callback), |
| stylus_(0), |
| - abs_value_dirty_(false) { |
| + abs_value_dirty_(false), |
| + on_screen_stylus_(false) { |
| x_abs_min_ = info.GetAbsMinimum(ABS_X); |
| x_abs_range_ = info.GetAbsMaximum(ABS_X) - x_abs_min_ + 1; |
| y_abs_min_ = info.GetAbsMinimum(ABS_Y); |
| y_abs_range_ = info.GetAbsMaximum(ABS_Y) - y_abs_min_ + 1; |
| + pressure_min_ = info.GetAbsMinimum(ABS_PRESSURE); |
| + pressure_range_ = info.GetAbsMaximum(ABS_PRESSURE) - pressure_min_ + 1; |
| + on_screen_stylus_ = !info.HasProp(INPUT_PROP_POINTER); |
| } |
| TabletEventConverterEvdev::~TabletEventConverterEvdev() { |
| @@ -69,7 +74,7 @@ void TabletEventConverterEvdev::ProcessEvents(const input_event* inputs, |
| ConvertAbsEvent(input); |
| break; |
| case EV_SYN: |
| - FlushEvents(); |
| + FlushEvents(input); |
| break; |
| } |
| } |
| @@ -88,8 +93,11 @@ void TabletEventConverterEvdev::ConvertKeyEvent(const input_event& input) { |
| } |
| if (input.code >= BTN_TOUCH && input.code <= BTN_STYLUS2) { |
| - DispatchMouseButton(input); |
| - return; |
| + if (input.code == BTN_TOUCH && on_screen_stylus_) { |
| + DispatchTouch(input); |
| + } else { |
| + DispatchMouseButton(input); |
| + } |
| } |
| } |
| @@ -106,6 +114,9 @@ void TabletEventConverterEvdev::ConvertAbsEvent(const input_event& input) { |
| y_abs_location_ = input.value; |
| abs_value_dirty_ = true; |
| break; |
| + case ABS_PRESSURE: |
| + pressure_ = input.value; |
| + break; |
| } |
| } |
| @@ -123,6 +134,31 @@ void TabletEventConverterEvdev::UpdateCursor() { |
| cursor_->MoveCursorTo(gfx::PointF(x, y)); |
| } |
| +void TabletEventConverterEvdev::DispatchTouch(const input_event& input) { |
| + if (abs_value_dirty_) { |
| + UpdateCursor(); |
| + abs_value_dirty_ = false; |
| + } |
| + |
| + // Start making motion events touch motion rather than mouse |
| + emit_touch_ = input.value; |
| + |
| + base::TimeDelta delta = base::TimeDelta::FromMicroseconds( |
| + input.time.tv_sec * 1000000 + input.time.tv_usec); |
| + scoped_ptr<TouchEvent> touch_event(new TouchEvent( |
| + input.value ? ET_TOUCH_PRESSED : ET_TOUCH_RELEASED, |
| + cursor_->GetLocation(), |
| + /* flags */ 0, |
| + /* touch_id */ 1, |
| + /* delta */ delta, |
| + /* radius_x */ 1.0, |
| + /* radius_y */ 1.0, |
| + /* angle */ 0., |
| + /* force */ (float)(pressure_ - pressure_min_) / pressure_range_)); |
| + touch_event->set_source_device_id(id_); |
| + callback_.Run(touch_event.Pass()); |
| +} |
| + |
| void TabletEventConverterEvdev::DispatchMouseButton(const input_event& input) { |
| if (!cursor_) |
| return; |
| @@ -151,7 +187,7 @@ void TabletEventConverterEvdev::DispatchMouseButton(const input_event& input) { |
| modifiers_->GetModifierFlags() | flag, flag))); |
| } |
| -void TabletEventConverterEvdev::FlushEvents() { |
| +void TabletEventConverterEvdev::FlushEvents(const input_event& input) { |
| if (!cursor_) |
| return; |
| @@ -166,11 +202,27 @@ void TabletEventConverterEvdev::FlushEvents() { |
| UpdateCursor(); |
| + if (emit_touch_) { |
| + base::TimeDelta delta = base::TimeDelta::FromMicroseconds( |
| + input.time.tv_sec * 1000000 + input.time.tv_usec); |
| + scoped_ptr<TouchEvent> touch_event(new TouchEvent( |
| + ET_TOUCH_MOVED, |
| + cursor_->GetLocation(), |
| + /* flags */ 0, |
| + /* touch_id */ 1, |
|
Rick Byers
2015/01/19 20:44:20
What if there is both real touchscreen and stylus
|
| + /* delta */ delta, |
| + /* radius_x */ 1.0, |
| + /* radius_y */ 1.0, |
| + /* angle */ 0., |
| + /* force */ (float)(pressure_ - pressure_min_) / pressure_range_)); |
| + touch_event->set_source_device_id(id_); |
| + callback_.Run(touch_event.Pass()); |
| + } else { |
| callback_.Run(make_scoped_ptr( |
| new MouseEvent(ui::ET_MOUSE_MOVED, cursor_->GetLocation(), |
| cursor_->GetLocation(), modifiers_->GetModifierFlags(), |
| /* changed_button_flags */ 0))); |
| - |
| + } |
| abs_value_dirty_ = false; |
| } |