| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_PROPERTY_PROVIDER_H_ | 5 #ifndef UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_PROPERTY_PROVIDER_H_ |
| 6 #define UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_PROPERTY_PROVIDER_H_ | 6 #define UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_PROPERTY_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <gestures/gestures.h> | 8 #include <gestures/gestures.h> |
| 9 #include <libevdev/libevdev.h> | 9 #include <libevdev/libevdev.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| 11 #include <stdint.h> | 11 #include <stdint.h> |
| 12 | 12 |
| 13 #include <map> | 13 #include <map> |
| 14 #include <memory> |
| 14 #include <ostream> | 15 #include <ostream> |
| 15 #include <string> | 16 #include <string> |
| 16 #include <vector> | 17 #include <vector> |
| 17 | 18 |
| 18 #include "base/containers/scoped_ptr_hash_map.h" | 19 #include "base/containers/scoped_ptr_hash_map.h" |
| 19 #include "base/macros.h" | 20 #include "base/macros.h" |
| 20 #include "base/memory/scoped_ptr.h" | |
| 21 #include "base/memory/scoped_vector.h" | 21 #include "base/memory/scoped_vector.h" |
| 22 #include "ui/events/ozone/evdev/event_device_info.h" | 22 #include "ui/events/ozone/evdev/event_device_info.h" |
| 23 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h" | 23 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h" |
| 24 | 24 |
| 25 namespace ui { | 25 namespace ui { |
| 26 | 26 |
| 27 class GesturesPropFunctionsWrapper; | 27 class GesturesPropFunctionsWrapper; |
| 28 class GestureInterpreterLibevdevCros; | 28 class GestureInterpreterLibevdevCros; |
| 29 | 29 |
| 30 // Not for public consumption, so we wrap it in namespace internal. | 30 // Not for public consumption, so we wrap it in namespace internal. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 friend class GesturesPropFunctionsWrapper; | 110 friend class GesturesPropFunctionsWrapper; |
| 111 | 111 |
| 112 // Mapping table from a device id to its device pointer. | 112 // Mapping table from a device id to its device pointer. |
| 113 typedef std::map<DeviceId, DevicePtr> DeviceMap; | 113 typedef std::map<DeviceId, DevicePtr> DeviceMap; |
| 114 | 114 |
| 115 // Mapping table from a device id to its property data. | 115 // Mapping table from a device id to its property data. |
| 116 // GestureDevicePropertyData contains both properties in use and default | 116 // GestureDevicePropertyData contains both properties in use and default |
| 117 // properties whose values will be applied upon the device attachment. | 117 // properties whose values will be applied upon the device attachment. |
| 118 typedef base::ScopedPtrHashMap< | 118 typedef base::ScopedPtrHashMap< |
| 119 DeviceId, | 119 DeviceId, |
| 120 scoped_ptr<internal::GestureDevicePropertyData>> ScopedDeviceDataMap; | 120 std::unique_ptr<internal::GestureDevicePropertyData>> |
| 121 ScopedDeviceDataMap; |
| 121 | 122 |
| 122 // Register a device. Setup data-structures and the device's default | 123 // Register a device. Setup data-structures and the device's default |
| 123 // properties. | 124 // properties. |
| 124 void RegisterDevice(const DeviceId id, const DevicePtr device); | 125 void RegisterDevice(const DeviceId id, const DevicePtr device); |
| 125 | 126 |
| 126 // Unregister a device. Remove all of its properties being tracked. | 127 // Unregister a device. Remove all of its properties being tracked. |
| 127 void UnregisterDevice(const DeviceId id); | 128 void UnregisterDevice(const DeviceId id); |
| 128 | 129 |
| 129 // Called by functions in GesturesPropFunctionsWrapper to manipulate | 130 // Called by functions in GesturesPropFunctionsWrapper to manipulate |
| 130 // properties. Note these functions do not new/delete the GesturesProp | 131 // properties. Note these functions do not new/delete the GesturesProp |
| 131 // pointers. It is caller's responsibility to manage them. | 132 // pointers. It is caller's responsibility to manage them. |
| 132 void AddProperty(const DeviceId device_id, | 133 void AddProperty(const DeviceId device_id, |
| 133 const std::string& name, | 134 const std::string& name, |
| 134 scoped_ptr<GesturesProp> property); | 135 std::unique_ptr<GesturesProp> property); |
| 135 void DeleteProperty(const DeviceId device_id, const std::string& name); | 136 void DeleteProperty(const DeviceId device_id, const std::string& name); |
| 136 | 137 |
| 137 // Check if a property exists for a device. Return if it is found. | 138 // Check if a property exists for a device. Return if it is found. |
| 138 GesturesProp* FindProperty(const DeviceId device_id, const std::string& name); | 139 GesturesProp* FindProperty(const DeviceId device_id, const std::string& name); |
| 139 | 140 |
| 140 // Get the default value of a property based on the configuration files. | 141 // Get the default value of a property based on the configuration files. |
| 141 GesturesProp* GetDefaultProperty(const DeviceId device_id, | 142 GesturesProp* GetDefaultProperty(const DeviceId device_id, |
| 142 const std::string& name); | 143 const std::string& name); |
| 143 | 144 |
| 144 // The device configuration files are parsed and stored in the memory upon | 145 // The device configuration files are parsed and stored in the memory upon |
| 145 // Chrome starts. The default property values are then applied to each device | 146 // Chrome starts. The default property values are then applied to each device |
| 146 // when it is attached/detected. | 147 // when it is attached/detected. |
| 147 void LoadDeviceConfigurations(); | 148 void LoadDeviceConfigurations(); |
| 148 | 149 |
| 149 // Parse a xorg-conf file. We ignore all sections other than InputClass. | 150 // Parse a xorg-conf file. We ignore all sections other than InputClass. |
| 150 // Check the xorg-conf spec for more infomation about its format. | 151 // Check the xorg-conf spec for more infomation about its format. |
| 151 void ParseXorgConfFile(const std::string& content); | 152 void ParseXorgConfFile(const std::string& content); |
| 152 | 153 |
| 153 // Create a match criteria. | 154 // Create a match criteria. |
| 154 scoped_ptr<internal::MatchCriteria> CreateMatchCriteria( | 155 std::unique_ptr<internal::MatchCriteria> CreateMatchCriteria( |
| 155 const std::string& match_type, | 156 const std::string& match_type, |
| 156 const std::string& arg); | 157 const std::string& arg); |
| 157 | 158 |
| 158 // Create a property that comes from the conf files. | 159 // Create a property that comes from the conf files. |
| 159 scoped_ptr<GesturesProp> CreateDefaultProperty(const std::string& name, | 160 std::unique_ptr<GesturesProp> CreateDefaultProperty(const std::string& name, |
| 160 const std::string& value); | 161 const std::string& value); |
| 161 | 162 |
| 162 // Setup default property values for a newly found device. | 163 // Setup default property values for a newly found device. |
| 163 void SetupDefaultProperties(const DeviceId device_id, const DevicePtr device); | 164 void SetupDefaultProperties(const DeviceId device_id, const DevicePtr device); |
| 164 | 165 |
| 165 // Map from device ids to device pointers. | 166 // Map from device ids to device pointers. |
| 166 DeviceMap device_map_; | 167 DeviceMap device_map_; |
| 167 | 168 |
| 168 // GestureDevicePropertyData indexed by their respective device ids. Owns the | 169 // GestureDevicePropertyData indexed by their respective device ids. Owns the |
| 169 // objects. | 170 // objects. |
| 170 ScopedDeviceDataMap device_data_map_; | 171 ScopedDeviceDataMap device_data_map_; |
| 171 | 172 |
| 172 // A vector of parsed sections in configuration files. Owns MatchCriterias, | 173 // A vector of parsed sections in configuration files. Owns MatchCriterias, |
| 173 // GesturesProps and ConfigurationSections in it. | 174 // GesturesProps and ConfigurationSections in it. |
| 174 std::vector<scoped_ptr<internal::ConfigurationSection>> configurations_; | 175 std::vector<std::unique_ptr<internal::ConfigurationSection>> configurations_; |
| 175 | 176 |
| 176 DISALLOW_COPY_AND_ASSIGN(GesturePropertyProvider); | 177 DISALLOW_COPY_AND_ASSIGN(GesturePropertyProvider); |
| 177 }; | 178 }; |
| 178 | 179 |
| 179 // Wrapper of GesturesProp related functions. We group them together so that we | 180 // Wrapper of GesturesProp related functions. We group them together so that we |
| 180 // can friend them all at once. | 181 // can friend them all at once. |
| 181 class GesturesPropFunctionsWrapper { | 182 class GesturesPropFunctionsWrapper { |
| 182 public: | 183 public: |
| 183 // Property provider interface implementation. | 184 // Property provider interface implementation. |
| 184 // | 185 // |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 const T* init); | 244 const T* init); |
| 244 | 245 |
| 245 // Do things that should happen BEFORE we create the property. | 246 // Do things that should happen BEFORE we create the property. |
| 246 static bool PreCreateProperty(void* device_data, | 247 static bool PreCreateProperty(void* device_data, |
| 247 const char* name, | 248 const char* name, |
| 248 GesturesProp** default_property); | 249 GesturesProp** default_property); |
| 249 | 250 |
| 250 // Do things that should happen AFTER we create the property. | 251 // Do things that should happen AFTER we create the property. |
| 251 static void PostCreateProperty(void* device_data, | 252 static void PostCreateProperty(void* device_data, |
| 252 const char* name, | 253 const char* name, |
| 253 scoped_ptr<GesturesProp> property); | 254 std::unique_ptr<GesturesProp> property); |
| 254 | 255 |
| 255 // Some other utility functions used in InitializeDeviceProperties. | 256 // Some other utility functions used in InitializeDeviceProperties. |
| 256 static GesturesProp* CreateIntSingle(void* device_data, | 257 static GesturesProp* CreateIntSingle(void* device_data, |
| 257 const char* name, | 258 const char* name, |
| 258 int* value, | 259 int* value, |
| 259 int init); | 260 int init); |
| 260 static GesturesProp* CreateBoolSingle(void* device_data, | 261 static GesturesProp* CreateBoolSingle(void* device_data, |
| 261 const char* name, | 262 const char* name, |
| 262 GesturesPropBool* value, | 263 GesturesPropBool* value, |
| 263 GesturesPropBool init); | 264 GesturesPropBool init); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 // Handler function pointers and the data to be passed to them when the | 337 // Handler function pointers and the data to be passed to them when the |
| 337 // property is accessed. | 338 // property is accessed. |
| 338 GesturesPropGetHandler get_; | 339 GesturesPropGetHandler get_; |
| 339 GesturesPropSetHandler set_; | 340 GesturesPropSetHandler set_; |
| 340 void* handler_data_; | 341 void* handler_data_; |
| 341 | 342 |
| 342 DISALLOW_COPY_AND_ASSIGN(GesturesProp); | 343 DISALLOW_COPY_AND_ASSIGN(GesturesProp); |
| 343 }; | 344 }; |
| 344 | 345 |
| 345 #endif // UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_PROPERTY_PROVIDER_H_ | 346 #endif // UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_PROPERTY_PROVIDER_H_ |
| OLD | NEW |