15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file.
4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
58bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#ifndef UI_EVENTS_OZONE_EVDEV_TOUCH_EVENT_CONVERTER_EVDEV_H_
68bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#define UI_EVENTS_OZONE_EVDEV_TOUCH_EVENT_CONVERTER_EVDEV_H_
7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <bitset>
9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/compiler_specific.h"
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/files/file_path.h"
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/message_loop/message_pump_libevent.h"
13d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/event_constants.h"
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/events/ozone/evdev/event_converter_evdev.h"
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/events/ozone/evdev/event_device_info.h"
16cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace ui {
19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class TouchEvent;
21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
22cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev
231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    : public EventConverterEvdev {
24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  enum {
26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    MAX_FINGERS = 11
27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  };
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  TouchEventConverterEvdev(int fd,
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                           base::FilePath path,
300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                           const EventDeviceInfo& info,
310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                           const EventDispatchCallback& dispatch);
328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual ~TouchEventConverterEvdev();
33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private:
358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  friend class MockTouchEventConverterEvdev;
36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Unsafe part of initialization.
380de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)  void Init(const EventDeviceInfo& info);
39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Overidden from base::MessagePumpLibevent::Watcher.
41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
430de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)  virtual bool Reinitialize();
440de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)
45cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  void ProcessInputEvent(const input_event& input);
46cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  void ProcessAbs(const input_event& input);
47cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  void ProcessSyn(const input_event& input);
48cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
49cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  void ReportEvents(base::TimeDelta delta);
50cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Callback for dispatching events.
521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EventDispatchCallback callback_;
531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
540de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)  // Set if we have seen a SYN_DROPPED and not yet re-synced with the device.
550de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)  bool syn_dropped_;
560de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)
570de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)  // Set if this is a type A device (uses SYN_MT_REPORT).
580de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)  bool is_type_a_;
590de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)
60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Pressure values.
61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int pressure_min_;
62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int pressure_max_;  // Used to normalize pressure values.
63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
640529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // Input range for x-axis.
650529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  float x_min_tuxels_;
660529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  float x_num_tuxels_;
67868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
680529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // Input range for y-axis.
690529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  float y_min_tuxels_;
700529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  float y_num_tuxels_;
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
720529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // Output range for x-axis.
730529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  float x_min_pixels_;
740529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  float x_num_pixels_;
750529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
760529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // Output range for y-axis.
770529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  float y_min_pixels_;
780529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  float y_num_pixels_;
793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
80868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Touch point currently being updated from the /dev/input/event* stream.
81868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int current_slot_;
82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
83868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Bit field tracking which in-progress touch points have been modified
84868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // without a syn event.
85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  std::bitset<MAX_FINGERS> altered_slots_;
86868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  struct InProgressEvents {
880529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    float x_;
890529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    float y_;
90868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    int id_;  // Device reported "unique" touch point id; -1 means not active
91868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    int finger_;  // "Finger" id starting from 0; -1 means not active
92868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
93868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EventType type_;
941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    float radius_x_;
951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    float radius_y_;
96868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    float pressure_;
97868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  };
98868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
99868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // In-progress touch points.
100868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  InProgressEvents events_[MAX_FINGERS];
101868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TouchEventConverterEvdev);
103868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
104868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
105868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}  // namespace ui
106868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#endif  // UI_EVENTS_OZONE_EVDEV_TOUCH_EVENT_CONVERTER_EVDEV_H_
108