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"
21 class DeviceEventDispatcherEvdev
;
23 class TouchNoiseFinder
;
24 struct InProgressTouchEvdev
;
26 class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev
27 : public EventConverterEvdev
{
29 TouchEventConverterEvdev(int fd
,
33 DeviceEventDispatcherEvdev
* dispatcher
);
34 ~TouchEventConverterEvdev() override
;
36 // EventConverterEvdev:
37 bool HasTouchscreen() const override
;
38 gfx::Size
GetTouchscreenSize() const override
;
39 int GetTouchPoints() const override
;
41 // Unsafe part of initialization.
42 virtual void Initialize(const EventDeviceInfo
& info
);
45 friend class MockTouchEventConverterEvdev
;
47 // Overidden from base::MessagePumpLibevent::Watcher.
48 void OnFileCanReadWithoutBlocking(int fd
) override
;
50 virtual bool Reinitialize();
52 void ProcessMultitouchEvent(const input_event
& input
);
53 void EmulateMultitouchEvent(const input_event
& input
);
54 void ProcessKey(const input_event
& input
);
55 void ProcessAbs(const input_event
& input
);
56 void ProcessSyn(const input_event
& input
);
58 // Returns an EventType to dispatch for |touch|. Returns ET_UNKNOWN if an
59 // event should not be dispatched.
60 EventType
GetEventTypeForTouch(const InProgressTouchEvdev
& touch
);
62 void ReportEvent(const InProgressTouchEvdev
& event
,
64 const base::TimeDelta
& delta
);
65 void ReportEvents(base::TimeDelta delta
);
67 // Normalize pressure value to [0, 1].
68 float ScalePressure(int32_t value
);
72 // Dispatcher for events.
73 DeviceEventDispatcherEvdev
* dispatcher_
;
75 // Set if we have seen a SYN_DROPPED and not yet re-synced with the device.
78 // Device has multitouch capability.
83 int pressure_max_
; // Used to normalize pressure values.
85 // Input range for x-axis.
89 // Input range for y-axis.
93 // Number of touch points reported by driver
96 // Tracking id counter.
97 int next_tracking_id_
;
99 // Touch point currently being updated from the /dev/input/event* stream.
100 size_t current_slot_
;
102 // In-progress touch points.
103 std::vector
<InProgressTouchEvdev
> events_
;
105 // Finds touch noise.
106 scoped_ptr
<TouchNoiseFinder
> touch_noise_finder_
;
108 DISALLOW_COPY_AND_ASSIGN(TouchEventConverterEvdev
);
113 #endif // UI_EVENTS_OZONE_EVDEV_TOUCH_EVENT_CONVERTER_EVDEV_H_