Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / events / ozone / evdev / event_device_info.h
blobc5a69c539fdbc2cb3611ccba12d5268f61cf0f6e
1 // Copyright 2013 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_EVENT_DEVICE_INFO_H_
6 #define UI_EVENTS_OZONE_EVDEV_EVENT_DEVICE_INFO_H_
8 #include <limits.h>
9 #include <linux/input.h>
11 #include <vector>
13 #include "base/basictypes.h"
14 #include "ui/events/ozone/evdev/event_device_util.h"
15 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
17 #if !defined(ABS_MT_TOOL_Y)
18 #define ABS_MT_TOOL_Y 0x3d
19 #endif
21 // ABS_MT_SLOT isn't valid options for EVIOCGMTSLOTS ioctl.
22 #define EVDEV_ABS_MT_FIRST ABS_MT_TOUCH_MAJOR
23 #define EVDEV_ABS_MT_LAST ABS_MT_TOOL_Y
24 #define EVDEV_ABS_MT_COUNT (EVDEV_ABS_MT_LAST - EVDEV_ABS_MT_FIRST + 1)
26 namespace ui {
28 // Input device types.
29 enum EVENTS_OZONE_EVDEV_EXPORT EventDeviceType {
30 DT_KEYBOARD,
31 DT_MOUSE,
32 DT_TOUCHPAD,
33 DT_TOUCHSCREEN,
34 DT_MULTITOUCH,
35 DT_MULTITOUCH_MOUSE,
36 DT_ALL,
39 // Device information for Linux input devices
41 // This stores and queries information about input devices; in
42 // particular it knows which events the device can generate.
43 class EVENTS_OZONE_EVDEV_EXPORT EventDeviceInfo {
44 public:
45 EventDeviceInfo();
46 ~EventDeviceInfo();
48 // Initialize device information from an open device.
49 bool Initialize(int fd);
51 // Manual initialization.
52 void SetEventTypes(const unsigned long* ev_bits, size_t len);
53 void SetKeyEvents(const unsigned long* key_bits, size_t len);
54 void SetRelEvents(const unsigned long* rel_bits, size_t len);
55 void SetAbsEvents(const unsigned long* abs_bits, size_t len);
56 void SetMscEvents(const unsigned long* msc_bits, size_t len);
57 void SetSwEvents(const unsigned long* sw_bits, size_t len);
58 void SetLedEvents(const unsigned long* led_bits, size_t len);
59 void SetProps(const unsigned long* prop_bits, size_t len);
60 void SetAbsInfo(unsigned int code, const input_absinfo& absinfo);
61 void SetAbsMtSlots(unsigned int code, const std::vector<int32_t>& values);
62 void SetAbsMtSlot(unsigned int code, unsigned int slot, uint32_t value);
64 // Check events this device can generate.
65 bool HasEventType(unsigned int type) const;
66 bool HasKeyEvent(unsigned int code) const;
67 bool HasRelEvent(unsigned int code) const;
68 bool HasAbsEvent(unsigned int code) const;
69 bool HasMscEvent(unsigned int code) const;
70 bool HasSwEvent(unsigned int code) const;
71 bool HasLedEvent(unsigned int code) const;
73 // Properties of absolute axes.
74 int32_t GetAbsMinimum(unsigned int code) const;
75 int32_t GetAbsMaximum(unsigned int code) const;
76 int32_t GetAbsValue(unsigned int code) const;
77 uint32_t GetAbsMtSlotCount() const;
78 int32_t GetAbsMtSlotValue(unsigned int code, unsigned int slot) const;
79 int32_t GetAbsMtSlotValueWithDefault(unsigned int code,
80 unsigned int slot,
81 int32_t default_value) const;
83 // Check input device properties.
84 bool HasProp(unsigned int code) const;
86 // Has absolute X & Y axes (excludes MT)
87 bool HasAbsXY() const;
89 // Has MT absolute X & Y events.
90 bool HasMTAbsXY() const;
92 // Has relative X & Y axes.
93 bool HasRelXY() const;
95 // Has multitouch protocol "B".
96 bool HasMultitouch() const;
98 // Determine whether this is a "Direct Touch" device e.g. touchscreen.
99 // Corresponds to INPUT_PROP_DIRECT but may be inferred.
100 // NB: The Linux documentation says tablets would be direct, but they are
101 // not (and drivers do not actually set INPUT_PROP_DIRECT for them).
102 bool HasDirect() const;
104 // Determine whether device moves the cursor. This is the case for touchpads
105 // and tablets but not touchscreens.
106 // Corresponds to INPUT_PROP_POINTER but may be inferred.
107 bool HasPointer() const;
109 // Has stylus EV_KEY events.
110 bool HasStylus() const;
112 // Determine whether there's a keyboard on this device.
113 bool HasKeyboard() const;
115 // Determine whether there's a mouse on this device.
116 bool HasMouse() const;
118 // Determine whether there's a touchpad on this device.
119 bool HasTouchpad() const;
121 // Determine whether there's a tablet on this device.
122 bool HasTablet() const;
124 // Determine whether there's a touchscreen on this device.
125 bool HasTouchscreen() const;
127 private:
128 enum class LegacyAbsoluteDeviceType {
129 LADT_TOUCHPAD,
130 LADT_TOUCHSCREEN,
131 LADT_TABLET,
132 LADT_NONE,
135 // Probe absolute X & Y axis behavior. This is for legacy drivers that
136 // do not tell us what the axes mean.
137 LegacyAbsoluteDeviceType ProbeLegacyAbsoluteDevice() const;
139 unsigned long ev_bits_[EVDEV_BITS_TO_LONGS(EV_CNT)];
140 unsigned long key_bits_[EVDEV_BITS_TO_LONGS(KEY_CNT)];
141 unsigned long rel_bits_[EVDEV_BITS_TO_LONGS(REL_CNT)];
142 unsigned long abs_bits_[EVDEV_BITS_TO_LONGS(ABS_CNT)];
143 unsigned long msc_bits_[EVDEV_BITS_TO_LONGS(MSC_CNT)];
144 unsigned long sw_bits_[EVDEV_BITS_TO_LONGS(SW_CNT)];
145 unsigned long led_bits_[EVDEV_BITS_TO_LONGS(LED_CNT)];
146 unsigned long prop_bits_[EVDEV_BITS_TO_LONGS(INPUT_PROP_CNT)];
148 struct input_absinfo abs_info_[ABS_CNT];
150 // Store the values for the multi-touch properties for each slot.
151 std::vector<int32_t> slot_values_[EVDEV_ABS_MT_COUNT];
153 DISALLOW_COPY_AND_ASSIGN(EventDeviceInfo);
156 } // namspace ui
158 #endif // UI_EVENTS_OZONE_EVDEV_EVENT_DEVICE_INFO_H_