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 // Get the GesturesProp object. Returns NULL if not found. | |
| 92 // | |
| 93 // The user may use the object returned to set/get the property value in the | |
| 94 // gesture library's memory. Note that the values in preferences are not | |
| 95 // synced with the ones here in realtime - they are only applied from the | |
| 96 // preference side in a single way once appropriate (e.g., when the user | |
| 97 // clicked "OK"). | |
| 98 GesturesProp* GetProperty(const DeviceId device_id, const std::string& name); | |
| 99 | |
| 100 private: | |
| 101 friend class GesturesPropFunctionsWrapper; | |
| 102 | |
| 103 // Mapping table from a device pointer to its device id. | |
| 104 typedef std::map<DevicePtr, DeviceId> DeviceIdMap; | |
| 105 | |
| 106 // Mapping table from a property name to its corresponding GesturesProp | |
| 107 // object pointer. | |
| 108 typedef base::hash_map<std::string, GesturesProp*> PropertyMap; | |
| 109 typedef base::ScopedPtrHashMap<std::string, GesturesProp> ScopedPropertyMap; | |
| 110 | |
| 111 // Mapping table from a device id to its property map. | |
| 112 typedef base::ScopedPtrHashMap<DeviceId, PropertyMap> ScopedDevicePropertyMap; | |
| 113 typedef base::ScopedPtrHashMap<DeviceId, ScopedPropertyMap> | |
| 114 ScopedDeviceScopedPropertyMap; | |
| 115 | |
| 116 // Get the device id of a device pointer. May create a new one if not | |
| 117 // currently mapped. | |
| 118 DeviceId GetDeviceId(const DevicePtr device, const bool do_create); | |
| 119 | |
| 120 // Called by functions in GesturesPropFunctionsWrapper to manipulate | |
| 121 // properties. Note these functions do not new/delete the GesturesProp | |
| 122 // pointers. It is caller's responsibility to manage them. | |
| 123 void AddProperty(const DeviceId device_id, | |
| 124 const std::string& name, | |
| 125 GesturesProp* property); | |
| 126 void DeleteProperty(const DeviceId device_id, const std::string& name); | |
| 127 | |
| 128 // Check if a property exists for a device. Return if it is found. | |
| 129 GesturesProp* FindProperty(const DeviceId device_id, const std::string& name); | |
| 130 | |
| 131 // Get the default value of a property based on the configuration files. | |
| 132 GesturesProp* GetDefaultProperty(const DeviceId device_id, | |
| 133 const std::string& name); | |
| 134 | |
| 135 // The device configuration files are parsed and stored in the memory upon | |
| 136 // Chrome starts. The default property values are then applied to each device | |
| 137 // when it is attached/detected. | |
| 138 void LoadDeviceConfigurations(); | |
| 139 | |
| 140 // Parse a xorg-conf file. We ignore all sections other than InputClass. | |
| 141 // Check the xorg-conf spec for more infomation about its format. | |
| 142 void ParseXorgConfFile(const std::string& content); | |
| 143 | |
| 144 // Create a match criteria. | |
| 145 internal::MatchCriteria* CreateMatchCriteria(const std::string& match_type, | |
| 146 const std::string& arg); | |
| 147 | |
| 148 // Create a property that comes from the conf files. | |
| 149 GesturesProp* CreateDefaultProperty(const std::string& name, | |
| 150 const std::string& value); | |
| 151 | |
| 152 // Setup default property values for a newly found device. | |
| 153 void SetupDefaultProperties(const DeviceId device_id, const DevicePtr device); | |
| 154 | |
| 155 // An incremental counter of the next device id to be used for mapping. | |
| 156 DeviceId device_id_counter_; | |
| 157 | |
| 158 // Map of device ids. | |
| 159 DeviceIdMap device_ids_map_; | |
| 160 | |
| 161 // Array of property maps indexed by their respective device ids. Owns all the | |
| 162 // GesturesProp objects in it. | |
| 163 ScopedDeviceScopedPropertyMap properties_maps_; | |
| 164 | |
| 165 // Same as properties_maps_, but loaded with only values specified in the | |
| 166 // configuration files. Will be applied when a property of the same name is | |
| 167 // created. Note that it only references the properties in configurations_ and | |
| 168 // doesn't own any GesturesProp by itself. | |
| 169 ScopedDevicePropertyMap default_properties_maps_; | |
|
spang
2014/10/08 19:09:15
I think I managed to figure out what all the typed
Shecky Lin
2014/10/09 09:19:31
I have combined both maps to a struct per your sug
| |
| 170 | |
| 171 // A vector of parsed sections in configuration files. Owns MatchCriterias, | |
| 172 // GesturesProps and ConfigurationSections in it. | |
| 173 ScopedVector<internal::ConfigurationSection> configurations_; | |
| 174 | |
| 175 DISALLOW_COPY_AND_ASSIGN(GesturePropertyProvider); | |
| 176 }; | |
| 177 | |
| 178 // Wrapper of GesturesProp related functions. We group them together so that we | |
| 179 // can friend them all at once. | |
| 180 class GesturesPropFunctionsWrapper { | |
| 181 public: | |
| 182 // Property provider interface implementation. | |
| 183 // | |
| 184 // These functions will create a GesturesProp object that can link back to the | |
| 185 // memory that holds the real value, which is often declared in the gesture | |
| 186 // lib. | |
| 187 static GesturesProp* CreateInt(void* device_data, | |
| 188 const char* name, | |
| 189 int* value, | |
| 190 size_t count, | |
| 191 const int* init); | |
| 192 static GesturesProp* CreateShort(void* device_data, | |
| 193 const char* name, | |
| 194 short* value, | |
| 195 size_t count, | |
| 196 const short* init); | |
| 197 static GesturesProp* CreateBool(void* device_data, | |
| 198 const char* name, | |
| 199 GesturesPropBool* value, | |
| 200 size_t count, | |
| 201 const GesturesPropBool* init); | |
| 202 | |
| 203 // String GestureProps needs special care due to the use of const char* in the | |
| 204 // gesture lib. Its argument list is also different from numeric properties'. | |
| 205 static GesturesProp* CreateString(void* device_data, | |
| 206 const char* name, | |
| 207 const char** value, | |
| 208 const char* init); | |
| 209 | |
| 210 static GesturesProp* CreateReal(void* device_data, | |
| 211 const char* name, | |
| 212 double* value, | |
| 213 size_t count, | |
| 214 const double* init); | |
| 215 | |
| 216 // Set the handlers to call when a property is accessed. | |
| 217 static void RegisterHandlers(void* device_data, | |
| 218 GesturesProp* property, | |
| 219 void* handler_data, | |
| 220 GesturesPropGetHandler get, | |
| 221 GesturesPropSetHandler set); | |
| 222 | |
| 223 // Free a property. | |
| 224 static void Free(void* device_data, GesturesProp* property); | |
| 225 | |
| 226 // Initialize hardware-related device properties which will be used in the | |
| 227 // gesture lib. | |
| 228 static bool InitializeDeviceProperties(void* device_data, | |
| 229 GestureDeviceProperties* properties); | |
| 230 | |
| 231 private: | |
| 232 // Property helper functions. | |
| 233 // Core template function for creating GestureProps. Used by numerical types. | |
| 234 template <typename T, class PROPTYPE> | |
| 235 static GesturesProp* CreateProperty(void* device_data, | |
| 236 const char* name, | |
| 237 T* value, | |
| 238 size_t count, | |
| 239 const T* init); | |
| 240 | |
| 241 // Do things that should happen BEFORE we create the property. | |
| 242 static GesturesProp* PreCreateProperty(void* device_data, const char* name); | |
| 243 // Do things that should happen AFTER we create the property. | |
| 244 static void PostCreateProperty(void* device_data, | |
| 245 const char* name, | |
| 246 GesturesProp* property); | |
| 247 | |
| 248 // Some other utility functions used in InitializeDeviceProperties. | |
| 249 static GesturesProp* CreateIntSingle(void* device_data, | |
| 250 const char* name, | |
| 251 int* value, | |
| 252 int init); | |
| 253 static GesturesProp* CreateBoolSingle(void* device_data, | |
| 254 const char* name, | |
| 255 GesturesPropBool* value, | |
| 256 GesturesPropBool init); | |
| 257 | |
| 258 // Routines to get the device pointer and the property provider from the | |
| 259 // GestureInterpreterLibevdevCros pointer. | |
| 260 static GesturePropertyProvider* GetPropertyProvider(void* device_data); | |
| 261 static GesturePropertyProvider::DevicePtr GetDevicePointer(void* device_data); | |
| 262 }; | |
| 263 | |
| 264 extern const GesturesPropProvider kGesturePropProvider; | |
| 265 | |
| 266 } // namspace ui | |
| 267 | |
| 268 #endif // UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_PROPERTY_PROVIDER_H_ | |
| OLD | NEW |