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
;
40 void OnStopped() override
;
42 // Unsafe part of initialization.
43 virtual void Initialize(const EventDeviceInfo
& info
);
46 friend class MockTouchEventConverterEvdev
;
48 // Overidden from base::MessagePumpLibevent::Watcher.
49 void OnFileCanReadWithoutBlocking(int fd
) override
;
51 virtual bool Reinitialize();
53 void ProcessMultitouchEvent(const input_event
& input
);
54 void EmulateMultitouchEvent(const input_event
& input
);
55 void ProcessKey(const input_event
& input
);
56 void ProcessAbs(const input_event
& input
);
57 void ProcessSyn(const input_event
& input
);
59 // Returns an EventType to dispatch for |touch|. Returns ET_UNKNOWN if an
60 // event should not be dispatched.
61 EventType
GetEventTypeForTouch(const InProgressTouchEvdev
& touch
);
63 void ReportEvent(const InProgressTouchEvdev
& event
,
65 const base::TimeDelta
& delta
);
66 void ReportEvents(base::TimeDelta delta
);
68 void UpdateTrackingId(int slot
, int tracking_id
);
69 void ReleaseTouches();
71 // Normalize pressure value to [0, 1].
72 float ScalePressure(int32_t value
);
76 // Dispatcher for events.
77 DeviceEventDispatcherEvdev
* dispatcher_
;
79 // Set if we have seen a SYN_DROPPED and not yet re-synced with the device.
82 // Device has multitouch capability.
87 int pressure_max_
; // Used to normalize pressure values.
89 // Input range for x-axis.
93 // Input range for y-axis.
97 // Number of touch points reported by driver
100 // Tracking id counter.
101 int next_tracking_id_
;
103 // Touch point currently being updated from the /dev/input/event* stream.
104 size_t current_slot_
;
106 // In-progress touch points.
107 std::vector
<InProgressTouchEvdev
> events_
;
109 // Finds touch noise.
110 scoped_ptr
<TouchNoiseFinder
> touch_noise_finder_
;
112 DISALLOW_COPY_AND_ASSIGN(TouchEventConverterEvdev
);
117 #endif // UI_EVENTS_OZONE_EVDEV_TOUCH_EVENT_CONVERTER_EVDEV_H_