Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #include <vector> | |
| 14 | |
| 15 #include "base/basictypes.h" | |
| 16 #include "base/containers/hash_tables.h" | |
| 17 #include "base/containers/scoped_ptr_hash_map.h" | |
| 18 #include "base/memory/scoped_vector.h" | |
| 19 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h" | |
| 20 | |
| 21 namespace ui { | |
| 22 | |
| 23 class GesturesPropFunctionsWrapper; | |
| 24 class GestureInterpreterLibevdevCros; | |
| 25 | |
| 26 // Not for public consumption, so we wrap it in namespace internal. | |
| 27 namespace internal { | |
| 28 class MatchCriteria; | |
| 29 struct ConfigurationSection; | |
| 30 } | |
| 31 | |
| 32 // A struct holding device properties that are useful when interacting with | |
| 33 // the gestures lib. | |
| 34 struct GestureDeviceProperties { | |
| 35 int area_left; | |
| 36 int area_right; | |
| 37 int area_top; | |
| 38 int area_bottom; | |
| 39 int res_y; | |
| 40 int res_x; | |
| 41 int orientation_minimum; | |
| 42 int orientation_maximum; | |
| 43 GesturesPropBool raw_passthrough; | |
| 44 GesturesPropBool dump_debug_log; | |
| 45 }; | |
| 46 | |
| 47 // Provide the interface to access the CrOS gesture library properties. | |
| 48 // It maintains the property data for all input devices that runs with | |
| 49 // the gesture library. | |
| 50 // | |
| 51 // The class also parses the configuration files on the system to | |
| 52 // initialize the specified property values. The configuration files are | |
| 53 // currently in the xorg-conf format so that they can be shared with non-Ozone | |
| 54 // builds. | |
| 55 class EVENTS_OZONE_EVDEV_EXPORT GesturePropertyProvider { | |
| 56 public: | |
| 57 // Device types. | |
| 58 enum DeviceType { | |
| 59 DT_MOUSE, | |
| 60 DT_TOUCHPAD, | |
| 61 DT_TOUCHSCREEN, | |
| 62 DT_MULTITOUCH, | |
| 63 DT_MULTITOUCH_MOUSE, | |
| 64 DT_ALL, | |
| 65 }; | |
| 66 | |
| 67 // Property types. | |
| 68 enum PropertyType { | |
| 69 PT_INT, | |
| 70 PT_SHORT, | |
| 71 PT_BOOL, | |
| 72 PT_STRING, | |
| 73 PT_REAL, | |
| 74 }; | |
| 75 | |
| 76 // Pointer that leads to the device info. | |
| 77 typedef Evdev* DevicePtr; | |
| 78 | |
| 79 // The device ids are only maintained by GesturePropertyProvider to identify | |
| 80 // the input devices that uses the gesture lib and are not to be confused with | |
| 81 // the Evdev input node id, for example. | |
| 82 typedef int DeviceId; | |
| 83 | |
| 84 GesturePropertyProvider(); | |
| 85 ~GesturePropertyProvider(); | |
| 86 | |
| 87 // Get a list of device ids that matches a device type. | |
| 88 void GetDeviceIdsByType(const DeviceType type, | |
| 89 std::vector<DeviceId>* device_ids); | |
| 90 | |
| 91 // Property access functions for other classes in Chrome, e.g., the | |
| 92 // preferences page. Note that the values in preferences are not synced with | |
| 93 // the ones here in realtime - they are only applied from the preference | |
| 94 // side in a single way once appropriate (e.g., when the user clicked "OK"). | |
| 95 | |
| 96 // Get the property type. | |
| 97 bool GetPropertyType(const DeviceId device_id, | |
|
spang
2014/10/03 21:40:11
I think you can replace these with just one functi
Shecky Lin
2014/10/08 10:51:00
Done.
| |
| 98 const std::string& name, | |
| 99 PropertyType* type); | |
| 100 | |
| 101 // Get the property value. | |
| 102 bool GetIntProperty(const DeviceId device_id, | |
| 103 const std::string& name, | |
| 104 int* val, | |
| 105 size_t* count); | |
| 106 bool GetShortProperty(const DeviceId device_id, | |
| 107 const std::string& name, | |
| 108 short* val, | |
| 109 size_t* count); | |
| 110 bool GetBoolProperty(const DeviceId device_id, | |
| 111 const std::string& name, | |
| 112 bool* val, | |
| 113 size_t* count); | |
| 114 bool GetStringProperty(const DeviceId device_id, | |
| 115 const std::string& name, | |
| 116 std::string* val, | |
| 117 size_t* count); | |
| 118 bool GetDoubleProperty(const DeviceId device_id, | |
| 119 const std::string& name, | |
| 120 double* val, | |
| 121 size_t* count); | |
| 122 | |
| 123 // Set the property value. Note that one can't change the property type/count | |
| 124 // which are both fixed since the property was created. Also, one can't create | |
| 125 // new properties with the function. A property can only be created with | |
| 126 // creators in GesturesPropFunctionsWrapper. | |
| 127 bool SetIntProperty(const DeviceId device_id, | |
| 128 const std::string& name, | |
| 129 const int* val); | |
| 130 bool SetShortProperty(const DeviceId device_id, | |
| 131 const std::string& name, | |
| 132 const short* val); | |
| 133 bool SetBoolProperty(const DeviceId device_id, | |
| 134 const std::string& name, | |
| 135 const bool* val); | |
| 136 bool SetStringProperty(const DeviceId device_id, | |
| 137 const std::string& name, | |
| 138 const char* val); | |
| 139 bool SetStringProperty(const DeviceId device_id, | |
| 140 const std::string& name, | |
| 141 const std::string* val); | |
| 142 bool SetDoubleProperty(const DeviceId device_id, | |
| 143 const std::string& name, | |
| 144 const double* val); | |
| 145 | |
| 146 private: | |
| 147 friend class GesturesPropFunctionsWrapper; | |
| 148 | |
| 149 // Mapping table from a dev pointer to its device id. | |
| 150 typedef std::map<DevicePtr, DeviceId> DeviceIdMap; | |
| 151 | |
| 152 // Mapping table from a property name to its corresponding GesturesProp | |
| 153 // object pointer. | |
| 154 typedef base::hash_map<std::string, GesturesProp*> PropertyMap; | |
| 155 typedef base::ScopedPtrHashMap<std::string, GesturesProp> ScopedPropertyMap; | |
| 156 | |
| 157 // Mapping table from a dev id to its property map. | |
| 158 typedef base::ScopedPtrHashMap<DeviceId, PropertyMap> ScopedDevicePropertyMap; | |
| 159 typedef base::ScopedPtrHashMap<DeviceId, ScopedPropertyMap> | |
| 160 ScopedDeviceScopedPropertyMap; | |
| 161 | |
| 162 // Get the device id of a device pointer. May create a new one if not | |
| 163 // currently mapped. | |
| 164 DeviceId GetDeviceId(DevicePtr dev, const bool do_create); | |
| 165 | |
| 166 // Core function of setting/getting property values. Do all things other than | |
| 167 // setting/getting the property value to avoid code redundancy. | |
| 168 template <typename T> | |
| 169 GesturesProp* PreSetProperty(const DeviceId device_id, | |
| 170 const std::string& name, | |
| 171 const T* val); | |
| 172 GesturesProp* PreGetProperty(const DeviceId device_id, | |
| 173 const std::string& name, | |
| 174 PropertyType* type, | |
| 175 size_t* count); | |
| 176 | |
| 177 // Called by functions in GesturesPropFunctionsWrapper to manipulate | |
| 178 // properties. Note these functions do not new/delete the GesturesProp | |
| 179 // pointers. It is caller's responsibility to manage them. | |
| 180 void AddProperty(const DeviceId device_id, | |
| 181 const std::string& name, | |
| 182 GesturesProp* prop); | |
| 183 void DeleteProperty(const DeviceId device_id, const std::string& name); | |
| 184 | |
| 185 // Check if a property exists for a device. Return if it is found. | |
| 186 GesturesProp* FindProperty(const DeviceId device_id, const std::string& name); | |
| 187 | |
| 188 // Get the default value of a property based on the configuration files. | |
| 189 GesturesProp* GetDefaultProperty(const DeviceId device_id, | |
| 190 const std::string& name); | |
| 191 | |
| 192 // The device configuration files are parsed and stored in the memory upon | |
| 193 // Chrome starts. The default property values are then applied to each device | |
| 194 // when it is attached/detected. | |
| 195 void LoadDeviceConfigurations(); | |
| 196 | |
| 197 // Parse a xorg-conf file. We ignore all sections other than InputClass. | |
| 198 // Check the xorg-conf spec for more infomation about its format. | |
| 199 void ParseXorgConfFile(const std::string& content); | |
| 200 | |
| 201 // Create a match criteria. | |
| 202 internal::MatchCriteria* CreateMatchCriteria(const std::string& match_type, | |
| 203 const std::string& arg); | |
| 204 | |
| 205 // Create a property that comes from the conf files. | |
| 206 GesturesProp* CreateDefaultProperty(const std::string& name, | |
| 207 const std::string& value); | |
| 208 | |
| 209 // Setup default property values for a newly found device. | |
| 210 void SetupDefaultProperties(const DeviceId device_id, DevicePtr dev); | |
| 211 | |
| 212 // An incremental counter of the next device id to be used for mapping. | |
| 213 DeviceId device_id_counter_; | |
| 214 | |
| 215 // Map of device ids. | |
| 216 DeviceIdMap device_ids_map_; | |
| 217 | |
| 218 // Array of property maps indexed by their respective device ids. Owns all the | |
| 219 // GesturesProp objects in it. | |
| 220 ScopedDeviceScopedPropertyMap properties_maps_; | |
| 221 | |
| 222 // Same as properties_maps_, but loaded with only values specified in the | |
| 223 // configuration files. Will be applied when a property of the same name is | |
| 224 // created. Note that it only references the properties in configurations_ and | |
| 225 // doesn't own any GesturesProp by itself. | |
| 226 ScopedDevicePropertyMap default_properties_maps_; | |
| 227 | |
| 228 // A vector of parsed sections in configuration files. Owns MatchCriterias, | |
| 229 // GesturesProps and ConfigurationSections in it. | |
| 230 ScopedVector<internal::ConfigurationSection> configurations_; | |
| 231 | |
| 232 DISALLOW_COPY_AND_ASSIGN(GesturePropertyProvider); | |
| 233 }; | |
| 234 | |
| 235 // Wrapper of GesturesProp related functions. We group them together so that we | |
| 236 // can friend them all at once. | |
| 237 class GesturesPropFunctionsWrapper { | |
| 238 public: | |
| 239 // Property provider interface implementation. | |
| 240 // | |
| 241 // These functions will create a GesturesProp object that can link back to the | |
| 242 // memory that holds the real value, which is often declared in the gesture | |
| 243 // lib. | |
| 244 static GesturesProp* CreateInt(void*, const char*, int*, size_t, const int*); | |
| 245 static GesturesProp* CreateShort(void*, | |
| 246 const char*, | |
| 247 short*, | |
| 248 size_t, | |
| 249 const short*); | |
| 250 static GesturesProp* CreateBool(void*, | |
| 251 const char*, | |
| 252 GesturesPropBool*, | |
| 253 size_t, | |
| 254 const GesturesPropBool*); | |
| 255 | |
| 256 // String GestureProps needs special care due to the use of const char* in the | |
| 257 // gesture lib. Its argument list is also different from numeric properties. | |
| 258 static GesturesProp* CreateString(void*, | |
| 259 const char*, | |
| 260 const char**, | |
| 261 const char*); | |
| 262 | |
| 263 static GesturesProp* CreateReal(void*, | |
|
alexst (slow to review)
2014/10/03 22:32:02
Please add names to all the parameters
Shecky Lin
2014/10/08 10:51:00
Done.
| |
| 264 const char*, | |
| 265 double*, | |
| 266 size_t, | |
| 267 const double*); | |
| 268 | |
| 269 // Set the handlers to call when a property is accessed. | |
| 270 static void RegisterHandlers(void*, | |
| 271 GesturesProp*, | |
| 272 void*, | |
| 273 GesturesPropGetHandler, | |
| 274 GesturesPropSetHandler); | |
| 275 | |
| 276 // Free a property. | |
| 277 static void Free(void*, GesturesProp*); | |
| 278 | |
| 279 // Initialize hardware-related device properties which will be used in the | |
| 280 // gesture lib. | |
| 281 static bool InitializeDeviceProperties(void*, GestureDeviceProperties* props); | |
| 282 | |
| 283 private: | |
| 284 // Property helper functions. | |
| 285 // Core template function for creating GestureProps. Used by numerical types. | |
| 286 template <typename T, class PROPTYPE> | |
| 287 static GesturesProp* CreateProperty(void*, const char*, T*, size_t, const T*); | |
| 288 | |
| 289 // Do things that should happen BEFORE we create the property. | |
| 290 static GesturesProp* PreCreateProperty(void*, const char*); | |
| 291 // Do things that should happen AFTER we create the property. | |
| 292 static void PostCreateProperty(void*, const char*, GesturesProp*); | |
| 293 | |
| 294 // Some other utility functions used in InitializeDeviceProperties. | |
| 295 static GesturesProp* CreateIntSingle(void*, const char*, int*, int); | |
| 296 static GesturesProp* CreateBoolSingle(void*, | |
| 297 const char*, | |
| 298 GesturesPropBool*, | |
| 299 GesturesPropBool); | |
| 300 | |
| 301 // Routines to get the device pointer and the property provider from the | |
| 302 // GestureInterpreterLibevdevCros pointer. | |
| 303 static GesturePropertyProvider* GetPropertyProvider(void*); | |
| 304 static GesturePropertyProvider::DevicePtr GetDevicePointer(void*); | |
| 305 }; | |
| 306 | |
| 307 extern const GesturesPropProvider kGesturePropProvider; | |
| 308 | |
| 309 } // namspace ui | |
| 310 | |
| 311 #endif // UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_PROPERTY_PROVIDER_H_ | |
| OLD | NEW |