Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / ui / events / ozone / evdev / touch_event_converter_evdev.h
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/ozone/evdev/event_converter_evdev.h"
15 #include "ui/events/ozone/evdev/event_device_info.h"
16 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
17
18 namespace ui {
19
20 class TouchEvent;
21
22 class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev
23     : public EventConverterEvdev {
24  public:
25   enum {
26     MAX_FINGERS = 11
27   };
28   TouchEventConverterEvdev(int fd,
29                            base::FilePath path,
30                            const EventDeviceInfo& info,
31                            const EventDispatchCallback& dispatch);
32   virtual ~TouchEventConverterEvdev();
33
34  private:
35   friend class MockTouchEventConverterEvdev;
36
37   // Unsafe part of initialization.
38   void Init(const EventDeviceInfo& info);
39
40   // Overidden from base::MessagePumpLibevent::Watcher.
41   virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
42
43   virtual bool Reinitialize();
44
45   void ProcessInputEvent(const input_event& input);
46   void ProcessAbs(const input_event& input);
47   void ProcessSyn(const input_event& input);
48
49   void ReportEvents(base::TimeDelta delta);
50
51   // Callback for dispatching events.
52   EventDispatchCallback callback_;
53
54   // Set if we have seen a SYN_DROPPED and not yet re-synced with the device.
55   bool syn_dropped_;
56
57   // Set if this is a type A device (uses SYN_MT_REPORT).
58   bool is_type_a_;
59
60   // Pressure values.
61   int pressure_min_;
62   int pressure_max_;  // Used to normalize pressure values.
63
64   // Input range for x-axis.
65   float x_min_tuxels_;
66   float x_num_tuxels_;
67
68   // Input range for y-axis.
69   float y_min_tuxels_;
70   float y_num_tuxels_;
71
72   // Output range for x-axis.
73   float x_min_pixels_;
74   float x_num_pixels_;
75
76   // Output range for y-axis.
77   float y_min_pixels_;
78   float y_num_pixels_;
79
80   // Touch point currently being updated from the /dev/input/event* stream.
81   int current_slot_;
82
83   // Bit field tracking which in-progress touch points have been modified
84   // without a syn event.
85   std::bitset<MAX_FINGERS> altered_slots_;
86
87   struct InProgressEvents {
88     float x_;
89     float y_;
90     int id_;  // Device reported "unique" touch point id; -1 means not active
91     int finger_;  // "Finger" id starting from 0; -1 means not active
92
93     EventType type_;
94     float radius_x_;
95     float radius_y_;
96     float pressure_;
97   };
98
99   // In-progress touch points.
100   InProgressEvents events_[MAX_FINGERS];
101
102   DISALLOW_COPY_AND_ASSIGN(TouchEventConverterEvdev);
103 };
104
105 }  // namespace ui
106
107 #endif  // UI_EVENTS_OZONE_EVDEV_TOUCH_EVENT_CONVERTER_EVDEV_H_