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.
5 #ifndef UI_EVENTS_OZONE_EVDEV_TOUCH_EVENT_CONVERTER_EVDEV_H_
6 #define UI_EVENTS_OZONE_EVDEV_TOUCH_EVENT_CONVERTER_EVDEV_H_
10 #include "base/compiler_specific.h"
11 #include "base/files/file_path.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_pump_libevent.h"
14 #include "ui/events/event_constants.h"
15 #include "ui/events/ozone/evdev/event_converter_evdev.h"
16 #include "ui/events/ozone/evdev/event_device_info.h"
17 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
18 #include "ui/events/ozone/evdev/touch_evdev_debug_buffer.h"
22 class DeviceEventDispatcherEvdev
;
24 class TouchNoiseFinder
;
25 struct InProgressTouchEvdev
;
27 class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev
28 : public EventConverterEvdev
{
30 TouchEventConverterEvdev(int fd
,
33 const EventDeviceInfo
& devinfo
,
34 DeviceEventDispatcherEvdev
* dispatcher
);
35 ~TouchEventConverterEvdev() override
;
37 // EventConverterEvdev:
38 bool HasTouchscreen() const override
;
39 gfx::Size
GetTouchscreenSize() const override
;
40 int GetTouchPoints() const override
;
41 void OnEnabled() override
;
42 void OnDisabled() override
;
44 void DumpTouchEventLog(const char* filename
) override
;
46 // Update touch event logging state
47 void SetTouchEventLoggingEnabled(bool enabled
) override
;
49 // Unsafe part of initialization.
50 virtual void Initialize(const EventDeviceInfo
& info
);
53 friend class MockTouchEventConverterEvdev
;
55 // Overidden from base::MessagePumpLibevent::Watcher.
56 void OnFileCanReadWithoutBlocking(int fd
) override
;
58 virtual void Reinitialize();
60 void ProcessMultitouchEvent(const input_event
& input
);
61 void EmulateMultitouchEvent(const input_event
& input
);
62 void ProcessKey(const input_event
& input
);
63 void ProcessAbs(const input_event
& input
);
64 void ProcessSyn(const input_event
& input
);
66 // Returns an EventType to dispatch for |touch|. Returns ET_UNKNOWN if an
67 // event should not be dispatched.
68 EventType
GetEventTypeForTouch(const InProgressTouchEvdev
& touch
);
70 void ReportEvent(const InProgressTouchEvdev
& event
,
72 const base::TimeDelta
& delta
);
73 void ReportEvents(base::TimeDelta delta
);
75 void UpdateTrackingId(int slot
, int tracking_id
);
76 void ReleaseTouches();
78 // Normalize pressure value to [0, 1].
79 float ScalePressure(int32_t value
);
83 // Dispatcher for events.
84 DeviceEventDispatcherEvdev
* dispatcher_
;
86 // Set if we drop events in kernel (SYN_DROPPED) or in process.
87 bool dropped_events_
= false;
89 // Device has multitouch capability.
92 // Use BTN_LEFT instead of BT_TOUCH.
93 bool quirk_left_mouse_button_
= false;
97 int pressure_max_
; // Used to normalize pressure values.
99 // Input range for x-axis.
103 // Input range for y-axis.
107 // Number of touch points reported by driver
108 int touch_points_
= 0;
110 // Tracking id counter.
111 int next_tracking_id_
= 0;
113 // Touch point currently being updated from the /dev/input/event* stream.
114 size_t current_slot_
= 0;
116 // Flag that indicates if the touch logging enabled or not.
117 bool touch_logging_enabled_
= true;
119 // In-progress touch points.
120 std::vector
<InProgressTouchEvdev
> events_
;
122 // Finds touch noise.
123 scoped_ptr
<TouchNoiseFinder
> touch_noise_finder_
;
125 // Records the recent touch events. It is used to fill the feedback reports
126 TouchEventLogEvdev touch_evdev_debug_buffer_
;
128 DISALLOW_COPY_AND_ASSIGN(TouchEventConverterEvdev
);
133 #endif // UI_EVENTS_OZONE_EVDEV_TOUCH_EVENT_CONVERTER_EVDEV_H_