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