Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / events / ozone / evdev / event_device_info.h
blob0979f9d7fe5fcd93da495cbaaca624d328f5bb67
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 <string>
12 #include <vector>
14 #include "base/basictypes.h"
15 #include "ui/events/devices/input_device.h"
16 #include "ui/events/ozone/evdev/event_device_util.h"
17 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
19 #if !defined(ABS_MT_TOOL_Y)
20 #define ABS_MT_TOOL_Y 0x3d
21 #endif
23 // ABS_MT_SLOT isn't valid options for EVIOCGMTSLOTS ioctl.
24 #define EVDEV_ABS_MT_FIRST ABS_MT_TOUCH_MAJOR
25 #define EVDEV_ABS_MT_LAST ABS_MT_TOOL_Y
26 #define EVDEV_ABS_MT_COUNT (EVDEV_ABS_MT_LAST - EVDEV_ABS_MT_FIRST + 1)
28 namespace base {
29 class FilePath;
32 namespace ui {
34 // Input device types.
35 enum EVENTS_OZONE_EVDEV_EXPORT EventDeviceType {
36 DT_KEYBOARD,
37 DT_MOUSE,
38 DT_TOUCHPAD,
39 DT_TOUCHSCREEN,
40 DT_MULTITOUCH,
41 DT_MULTITOUCH_MOUSE,
42 DT_ALL,
45 // Device information for Linux input devices
47 // This stores and queries information about input devices; in
48 // particular it knows which events the device can generate.
49 class EVENTS_OZONE_EVDEV_EXPORT EventDeviceInfo {
50 public:
51 EventDeviceInfo();
52 ~EventDeviceInfo();
54 // Initialize device information from an open device.
55 bool Initialize(int fd, const base::FilePath& path);
57 // Manual initialization.
58 void SetEventTypes(const unsigned long* ev_bits, size_t len);
59 void SetKeyEvents(const unsigned long* key_bits, size_t len);
60 void SetRelEvents(const unsigned long* rel_bits, size_t len);
61 void SetAbsEvents(const unsigned long* abs_bits, size_t len);
62 void SetMscEvents(const unsigned long* msc_bits, size_t len);
63 void SetSwEvents(const unsigned long* sw_bits, size_t len);
64 void SetLedEvents(const unsigned long* led_bits, size_t len);
65 void SetProps(const unsigned long* prop_bits, size_t len);
66 void SetAbsInfo(unsigned int code, const input_absinfo& absinfo);
67 void SetAbsMtSlots(unsigned int code, const std::vector<int32_t>& values);
68 void SetAbsMtSlot(unsigned int code, unsigned int slot, uint32_t value);
69 void SetDeviceType(InputDeviceType type);
71 // Check events this device can generate.
72 bool HasEventType(unsigned int type) const;
73 bool HasKeyEvent(unsigned int code) const;
74 bool HasRelEvent(unsigned int code) const;
75 bool HasAbsEvent(unsigned int code) const;
76 bool HasMscEvent(unsigned int code) const;
77 bool HasSwEvent(unsigned int code) const;
78 bool HasLedEvent(unsigned int code) const;
80 // Properties of absolute axes.
81 int32_t GetAbsMinimum(unsigned int code) const;
82 int32_t GetAbsMaximum(unsigned int code) const;
83 int32_t GetAbsValue(unsigned int code) const;
84 input_absinfo GetAbsInfoByCode(unsigned int code) const;
85 uint32_t GetAbsMtSlotCount() const;
86 int32_t GetAbsMtSlotValue(unsigned int code, unsigned int slot) const;
87 int32_t GetAbsMtSlotValueWithDefault(unsigned int code,
88 unsigned int slot,
89 int32_t default_value) const;
91 // Device identification.
92 const std::string& name() const { return name_; }
93 uint16_t vendor_id() const { return vendor_id_; }
94 uint16_t product_id() const { return product_id_; }
96 // Check input device properties.
97 bool HasProp(unsigned int code) const;
99 // Has absolute X & Y axes (excludes MT)
100 bool HasAbsXY() const;
102 // Has MT absolute X & Y events.
103 bool HasMTAbsXY() const;
105 // Has relative X & Y axes.
106 bool HasRelXY() const;
108 // Has multitouch protocol "B".
109 bool HasMultitouch() const;
111 // Determine whether this is a "Direct Touch" device e.g. touchscreen.
112 // Corresponds to INPUT_PROP_DIRECT but may be inferred.
113 // NB: The Linux documentation says tablets would be direct, but they are
114 // not (and drivers do not actually set INPUT_PROP_DIRECT for them).
115 bool HasDirect() const;
117 // Determine whether device moves the cursor. This is the case for touchpads
118 // and tablets but not touchscreens.
119 // Corresponds to INPUT_PROP_POINTER but may be inferred.
120 bool HasPointer() const;
122 // Has stylus EV_KEY events.
123 bool HasStylus() const;
125 // Determine whether there's a keyboard on this device.
126 bool HasKeyboard() const;
128 // Determine whether there's a mouse on this device.
129 bool HasMouse() const;
131 // Determine whether there's a touchpad on this device.
132 bool HasTouchpad() const;
134 // Determine whether there's a tablet on this device.
135 bool HasTablet() const;
137 // Determine whether there's a touchscreen on this device.
138 bool HasTouchscreen() const;
140 // The device type (internal or external.)
141 InputDeviceType device_type() const { return device_type_; }
143 private:
144 enum class LegacyAbsoluteDeviceType {
145 LADT_TOUCHPAD,
146 LADT_TOUCHSCREEN,
147 LADT_TABLET,
148 LADT_NONE,
151 // Probe absolute X & Y axis behavior. This is for legacy drivers that
152 // do not tell us what the axes mean.
153 LegacyAbsoluteDeviceType ProbeLegacyAbsoluteDevice() const;
155 unsigned long ev_bits_[EVDEV_BITS_TO_LONGS(EV_CNT)];
156 unsigned long key_bits_[EVDEV_BITS_TO_LONGS(KEY_CNT)];
157 unsigned long rel_bits_[EVDEV_BITS_TO_LONGS(REL_CNT)];
158 unsigned long abs_bits_[EVDEV_BITS_TO_LONGS(ABS_CNT)];
159 unsigned long msc_bits_[EVDEV_BITS_TO_LONGS(MSC_CNT)];
160 unsigned long sw_bits_[EVDEV_BITS_TO_LONGS(SW_CNT)];
161 unsigned long led_bits_[EVDEV_BITS_TO_LONGS(LED_CNT)];
162 unsigned long prop_bits_[EVDEV_BITS_TO_LONGS(INPUT_PROP_CNT)];
164 struct input_absinfo abs_info_[ABS_CNT];
166 // Store the values for the multi-touch properties for each slot.
167 std::vector<int32_t> slot_values_[EVDEV_ABS_MT_COUNT];
169 // Device identification.
170 std::string name_;
171 uint16_t vendor_id_;
172 uint16_t product_id_;
174 // Whether this is an internal or external device.
175 InputDeviceType device_type_ = InputDeviceType::INPUT_DEVICE_UNKNOWN;
177 DISALLOW_COPY_AND_ASSIGN(EventDeviceInfo);
180 } // namspace ui
182 #endif // UI_EVENTS_OZONE_EVDEV_EVENT_DEVICE_INFO_H_