Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Side by Side Diff: ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h

Issue 545063006: ozone: evdev: Add gesture property provider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase code again. Fix #ifdef. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #ifndef UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_PROPERTY_PROVIDER_H_
6 #define UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_PROPERTY_PROVIDER_H_
7
8 #include <gestures/gestures.h>
9 #include <libevdev/libevdev.h>
10
11 #include <map>
12 #include <string>
13
14 #include "base/containers/scoped_ptr_hash_map.h"
15 #include "base/memory/scoped_vector.h"
16 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
17
18 namespace ui {
19
20 class GesturesPropFunctionsWrapper;
21 class GestureInterpreterLibevdevCros;
22
23 // Not for public consumption, so we wrap it in namespace internal.
24 namespace internal {
25 struct GestureDevicePropertyData;
26 class MatchCriteria;
27 struct ConfigurationSection;
28 }
29
30 // A struct holding device properties that are useful when interacting with
31 // the gestures lib.
32 struct GestureDeviceProperties {
33 int area_left;
34 int area_right;
35 int area_top;
36 int area_bottom;
37 int res_y;
38 int res_x;
39 int orientation_minimum;
40 int orientation_maximum;
41 GesturesPropBool raw_passthrough;
42 GesturesPropBool dump_debug_log;
43 };
44
45 // Provide the interface to access the CrOS gesture library properties.
46 // It maintains the property data for all input devices that runs with
47 // the gesture library.
48 //
49 // The class also parses the configuration files on the system to
50 // initialize the specified property values. The configuration files are
51 // currently in the xorg-conf format so that they can be shared with non-Ozone
52 // builds.
53 class EVENTS_OZONE_EVDEV_EXPORT GesturePropertyProvider {
54 public:
55 // Device types.
56 enum DeviceType {
57 DT_MOUSE,
58 DT_TOUCHPAD,
59 DT_TOUCHSCREEN,
60 DT_MULTITOUCH,
61 DT_MULTITOUCH_MOUSE,
62 DT_ALL,
63 };
64
65 // Property types.
66 enum PropertyType {
67 PT_INT,
68 PT_SHORT,
69 PT_BOOL,
70 PT_STRING,
71 PT_REAL,
72 };
73
74 // Pointer that leads to the device info.
75 typedef Evdev* DevicePtr;
76
77 // The device ids are only maintained by EventFactoryEvdev to identify the
78 // input devices and are not to be confused with the Evdev input node id, for
79 // example.
80 typedef int DeviceId;
81
82 GesturePropertyProvider();
83 ~GesturePropertyProvider();
84
85 // Get a list of device ids that matches a device type.
86 void GetDeviceIdsByType(const DeviceType type,
87 std::vector<DeviceId>* device_ids);
88
89 // Get the GesturesProp object. Returns NULL if not found.
90 //
91 // The user may use the object returned to set/get the property value in the
92 // gesture library's memory. Note that the values in preferences are not
93 // synced with the ones here in realtime - they are only applied from the
94 // preference side in a single way once appropriate (e.g., when the user
95 // clicked "OK").
96 GesturesProp* GetProperty(const DeviceId device_id, const std::string& name);
97
98 private:
99 friend class GesturesPropFunctionsWrapper;
100
101 // Mapping table from a device id to its device pointer.
102 typedef std::map<DeviceId, DevicePtr> DeviceMap;
103
104 // Mapping table from a device id to its property data.
105 // GestureDevicePropertyData contains both properties in use and default
106 // properties whose values will be applied upon the device attachment.
107 typedef base::ScopedPtrHashMap<DeviceId, internal::GestureDevicePropertyData>
108 ScopedDeviceDataMap;
109
110 // Register a device. Setup data-structures and the device's default
111 // properties.
112 void RegisterDevice(const DeviceId id, const DevicePtr device);
113
114 // Unregister a device. Remove all of its properties being tracked.
115 void UnregisterDevice(const DeviceId id);
116
117 // Called by functions in GesturesPropFunctionsWrapper to manipulate
118 // properties. Note these functions do not new/delete the GesturesProp
119 // pointers. It is caller's responsibility to manage them.
120 void AddProperty(const DeviceId device_id,
121 const std::string& name,
122 GesturesProp* property);
123 void DeleteProperty(const DeviceId device_id, const std::string& name);
124
125 // Check if a property exists for a device. Return if it is found.
126 GesturesProp* FindProperty(const DeviceId device_id, const std::string& name);
127
128 // Get the default value of a property based on the configuration files.
129 GesturesProp* GetDefaultProperty(const DeviceId device_id,
130 const std::string& name);
131
132 // The device configuration files are parsed and stored in the memory upon
133 // Chrome starts. The default property values are then applied to each device
134 // when it is attached/detected.
135 void LoadDeviceConfigurations();
136
137 // Parse a xorg-conf file. We ignore all sections other than InputClass.
138 // Check the xorg-conf spec for more infomation about its format.
139 void ParseXorgConfFile(const std::string& content);
140
141 // Create a match criteria.
142 internal::MatchCriteria* CreateMatchCriteria(const std::string& match_type,
143 const std::string& arg);
144
145 // Create a property that comes from the conf files.
146 GesturesProp* CreateDefaultProperty(const std::string& name,
147 const std::string& value);
148
149 // Setup default property values for a newly found device.
150 void SetupDefaultProperties(const DeviceId device_id, const DevicePtr device);
151
152 // Map from device ids to device pointers.
153 DeviceMap device_map_;
154
155 // GestureDevicePropertyData indexed by their respective device ids. Owns the
156 // objects.
157 ScopedDeviceDataMap device_data_map_;
158
159 // A vector of parsed sections in configuration files. Owns MatchCriterias,
160 // GesturesProps and ConfigurationSections in it.
161 ScopedVector<internal::ConfigurationSection> configurations_;
162
163 DISALLOW_COPY_AND_ASSIGN(GesturePropertyProvider);
164 };
165
166 // Wrapper of GesturesProp related functions. We group them together so that we
167 // can friend them all at once.
168 class GesturesPropFunctionsWrapper {
169 public:
170 // Property provider interface implementation.
171 //
172 // These functions will create a GesturesProp object that can link back to the
173 // memory that holds the real value, which is often declared in the gesture
174 // lib.
175 static GesturesProp* CreateInt(void* device_data,
176 const char* name,
177 int* value,
178 size_t count,
179 const int* init);
180 static GesturesProp* CreateShort(void* device_data,
181 const char* name,
182 short* value,
183 size_t count,
184 const short* init);
185 static GesturesProp* CreateBool(void* device_data,
186 const char* name,
187 GesturesPropBool* value,
188 size_t count,
189 const GesturesPropBool* init);
190
191 // String GestureProps needs special care due to the use of const char* in the
192 // gesture lib. Its argument list is also different from numeric properties'.
193 static GesturesProp* CreateString(void* device_data,
194 const char* name,
195 const char** value,
196 const char* init);
197
198 static GesturesProp* CreateReal(void* device_data,
199 const char* name,
200 double* value,
201 size_t count,
202 const double* init);
203
204 // Set the handlers to call when a property is accessed.
205 static void RegisterHandlers(void* device_data,
206 GesturesProp* property,
207 void* handler_data,
208 GesturesPropGetHandler get,
209 GesturesPropSetHandler set);
210
211 // Free a property.
212 static void Free(void* device_data, GesturesProp* property);
213
214 // Initialize hardware-related device properties which will be used in the
215 // gesture lib.
216 static bool InitializeDeviceProperties(void* device_data,
217 GestureDeviceProperties* properties);
218
219 // Unregister device from the gesture property provider.
220 static void UnregisterDevice(void* device_data);
221
222 private:
223 // Property helper functions.
224 // Core template function for creating GestureProps. Used by numerical types.
225 template <typename T, class PROPTYPE>
226 static GesturesProp* CreateProperty(void* device_data,
227 const char* name,
228 T* value,
229 size_t count,
230 const T* init);
231
232 // Do things that should happen BEFORE we create the property.
233 static bool PreCreateProperty(void* device_data,
234 const char* name,
235 GesturesProp** default_property);
236
237 // Do things that should happen AFTER we create the property.
238 static void PostCreateProperty(void* device_data,
239 const char* name,
240 GesturesProp* property);
241
242 // Some other utility functions used in InitializeDeviceProperties.
243 static GesturesProp* CreateIntSingle(void* device_data,
244 const char* name,
245 int* value,
246 int init);
247 static GesturesProp* CreateBoolSingle(void* device_data,
248 const char* name,
249 GesturesPropBool* value,
250 GesturesPropBool init);
251
252 // Routines to extract information from the GestureInterpreterLibevdevCros
253 // pointer.
254 static GesturePropertyProvider* GetPropertyProvider(void* device_data);
255 static GesturePropertyProvider::DevicePtr GetDevicePointer(void* device_data);
256 static GesturePropertyProvider::DeviceId GetDeviceId(void* device_data);
257 };
258
259 extern const GesturesPropProvider kGesturePropProvider;
260
261 } // namspace ui
262
263 #endif // UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_PROPERTY_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698