touch_event_converter_evdev.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef UI_EVENTS_OZONE_EVDEV_TOUCH_EVENT_CONVERTER_EVDEV_H_
6#define UI_EVENTS_OZONE_EVDEV_TOUCH_EVENT_CONVERTER_EVDEV_H_
7
8#include <bitset>
9
10#include "base/compiler_specific.h"
11#include "base/files/file_path.h"
12#include "base/message_loop/message_pump_libevent.h"
13#include "ui/events/event_constants.h"
14#include "ui/events/events_export.h"
15#include "ui/events/ozone/evdev/event_converter_evdev.h"
16#include "ui/events/ozone/evdev/event_device_info.h"
17
18namespace ui {
19
20class TouchEvent;
21
22class EVENTS_EXPORT TouchEventConverterEvdev
23    : public EventConverterEvdev,
24      base::MessagePumpLibevent::Watcher {
25 public:
26  enum {
27    MAX_FINGERS = 11
28  };
29  TouchEventConverterEvdev(int fd,
30                           base::FilePath path,
31                           const EventDeviceInfo& info);
32  virtual ~TouchEventConverterEvdev();
33
34  // Start & stop watching for events.
35  virtual void Start() OVERRIDE;
36  virtual void Stop() OVERRIDE;
37
38 private:
39  friend class MockTouchEventConverterEvdev;
40
41  // Unsafe part of initialization.
42  void Init();
43
44  // Overidden from base::MessagePumpLibevent::Watcher.
45  virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
46  virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
47
48  // Pressure values.
49  int pressure_min_;
50  int pressure_max_;  // Used to normalize pressure values.
51
52  // Touch scaling.
53  float x_scale_;
54  float y_scale_;
55
56  // Range for x-axis.
57  int x_min_;
58  int x_max_;
59
60  // Range for y-axis.
61  int y_min_;
62  int y_max_;
63
64  // Touch point currently being updated from the /dev/input/event* stream.
65  int current_slot_;
66
67  // File descriptor for the /dev/input/event* instance.
68  int fd_;
69
70  // Path to input device.
71  base::FilePath path_;
72
73  // Bit field tracking which in-progress touch points have been modified
74  // without a syn event.
75  std::bitset<MAX_FINGERS> altered_slots_;
76
77  struct InProgressEvents {
78    int x_;
79    int y_;
80    int id_;  // Device reported "unique" touch point id; -1 means not active
81    int finger_;  // "Finger" id starting from 0; -1 means not active
82
83    EventType type_;
84    int major_;
85    float pressure_;
86  };
87
88  // In-progress touch points.
89  InProgressEvents events_[MAX_FINGERS];
90
91  // Controller for watching the input fd.
92  base::MessagePumpLibevent::FileDescriptorWatcher controller_;
93
94  DISALLOW_COPY_AND_ASSIGN(TouchEventConverterEvdev);
95};
96
97}  // namespace ui
98
99#endif  // UI_EVENTS_OZONE_EVDEV_TOUCH_EVENT_CONVERTER_EVDEV_H_
100
101