Chromium Code Reviews| Index: ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h |
| diff --git a/ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h b/ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3e45e5424383536c6912a47f305ac96a69b6e524 |
| --- /dev/null |
| +++ b/ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h |
| @@ -0,0 +1,311 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_PROPERTY_PROVIDER_H_ |
| +#define UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_PROPERTY_PROVIDER_H_ |
| + |
| +#include <gestures/gestures.h> |
| +#include <libevdev/libevdev.h> |
| + |
| +#include <map> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/containers/hash_tables.h" |
| +#include "base/containers/scoped_ptr_hash_map.h" |
| +#include "base/memory/scoped_vector.h" |
| +#include "ui/events/ozone/evdev/events_ozone_evdev_export.h" |
| + |
| +namespace ui { |
| + |
| +class GesturesPropFunctionsWrapper; |
| +class GestureInterpreterLibevdevCros; |
| + |
| +// Not for public consumption, so we wrap it in namespace internal. |
| +namespace internal { |
| +class MatchCriteria; |
| +struct ConfigurationSection; |
| +} |
| + |
| +// A struct holding device properties that are useful when interacting with |
| +// the gestures lib. |
| +struct GestureDeviceProperties { |
| + int area_left; |
| + int area_right; |
| + int area_top; |
| + int area_bottom; |
| + int res_y; |
| + int res_x; |
| + int orientation_minimum; |
| + int orientation_maximum; |
| + GesturesPropBool raw_passthrough; |
| + GesturesPropBool dump_debug_log; |
| +}; |
| + |
| +// Provide the interface to access the CrOS gesture library properties. |
| +// It maintains the property data for all input devices that runs with |
| +// the gesture library. |
| +// |
| +// The class also parses the configuration files on the system to |
| +// initialize the specified property values. The configuration files are |
| +// currently in the xorg-conf format so that they can be shared with non-Ozone |
| +// builds. |
| +class EVENTS_OZONE_EVDEV_EXPORT GesturePropertyProvider { |
| + public: |
| + // Device types. |
| + enum DeviceType { |
| + DT_MOUSE, |
| + DT_TOUCHPAD, |
| + DT_TOUCHSCREEN, |
| + DT_MULTITOUCH, |
| + DT_MULTITOUCH_MOUSE, |
| + DT_ALL, |
| + }; |
| + |
| + // Property types. |
| + enum PropertyType { |
| + PT_INT, |
| + PT_SHORT, |
| + PT_BOOL, |
| + PT_STRING, |
| + PT_REAL, |
| + }; |
| + |
| + // Pointer that leads to the device info. |
| + typedef Evdev* DevicePtr; |
| + |
| + // The device ids are only maintained by GesturePropertyProvider to identify |
| + // the input devices that uses the gesture lib and are not to be confused with |
| + // the Evdev input node id, for example. |
| + typedef int DeviceId; |
| + |
| + GesturePropertyProvider(); |
| + ~GesturePropertyProvider(); |
| + |
| + // Get a list of device ids that matches a device type. |
| + void GetDeviceIdsByType(const DeviceType type, |
| + std::vector<DeviceId>* device_ids); |
| + |
| + // Property access functions for other classes in Chrome, e.g., the |
| + // preferences page. Note that the values in preferences are not synced with |
| + // the ones here in realtime - they are only applied from the preference |
| + // side in a single way once appropriate (e.g., when the user clicked "OK"). |
| + |
| + // Get the property type. |
| + 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.
|
| + const std::string& name, |
| + PropertyType* type); |
| + |
| + // Get the property value. |
| + bool GetIntProperty(const DeviceId device_id, |
| + const std::string& name, |
| + int* val, |
| + size_t* count); |
| + bool GetShortProperty(const DeviceId device_id, |
| + const std::string& name, |
| + short* val, |
| + size_t* count); |
| + bool GetBoolProperty(const DeviceId device_id, |
| + const std::string& name, |
| + bool* val, |
| + size_t* count); |
| + bool GetStringProperty(const DeviceId device_id, |
| + const std::string& name, |
| + std::string* val, |
| + size_t* count); |
| + bool GetDoubleProperty(const DeviceId device_id, |
| + const std::string& name, |
| + double* val, |
| + size_t* count); |
| + |
| + // Set the property value. Note that one can't change the property type/count |
| + // which are both fixed since the property was created. Also, one can't create |
| + // new properties with the function. A property can only be created with |
| + // creators in GesturesPropFunctionsWrapper. |
| + bool SetIntProperty(const DeviceId device_id, |
| + const std::string& name, |
| + const int* val); |
| + bool SetShortProperty(const DeviceId device_id, |
| + const std::string& name, |
| + const short* val); |
| + bool SetBoolProperty(const DeviceId device_id, |
| + const std::string& name, |
| + const bool* val); |
| + bool SetStringProperty(const DeviceId device_id, |
| + const std::string& name, |
| + const char* val); |
| + bool SetStringProperty(const DeviceId device_id, |
| + const std::string& name, |
| + const std::string* val); |
| + bool SetDoubleProperty(const DeviceId device_id, |
| + const std::string& name, |
| + const double* val); |
| + |
| + private: |
| + friend class GesturesPropFunctionsWrapper; |
| + |
| + // Mapping table from a dev pointer to its device id. |
| + typedef std::map<DevicePtr, DeviceId> DeviceIdMap; |
| + |
| + // Mapping table from a property name to its corresponding GesturesProp |
| + // object pointer. |
| + typedef base::hash_map<std::string, GesturesProp*> PropertyMap; |
| + typedef base::ScopedPtrHashMap<std::string, GesturesProp> ScopedPropertyMap; |
| + |
| + // Mapping table from a dev id to its property map. |
| + typedef base::ScopedPtrHashMap<DeviceId, PropertyMap> ScopedDevicePropertyMap; |
| + typedef base::ScopedPtrHashMap<DeviceId, ScopedPropertyMap> |
| + ScopedDeviceScopedPropertyMap; |
| + |
| + // Get the device id of a device pointer. May create a new one if not |
| + // currently mapped. |
| + DeviceId GetDeviceId(DevicePtr dev, const bool do_create); |
| + |
| + // Core function of setting/getting property values. Do all things other than |
| + // setting/getting the property value to avoid code redundancy. |
| + template <typename T> |
| + GesturesProp* PreSetProperty(const DeviceId device_id, |
| + const std::string& name, |
| + const T* val); |
| + GesturesProp* PreGetProperty(const DeviceId device_id, |
| + const std::string& name, |
| + PropertyType* type, |
| + size_t* count); |
| + |
| + // Called by functions in GesturesPropFunctionsWrapper to manipulate |
| + // properties. Note these functions do not new/delete the GesturesProp |
| + // pointers. It is caller's responsibility to manage them. |
| + void AddProperty(const DeviceId device_id, |
| + const std::string& name, |
| + GesturesProp* prop); |
| + void DeleteProperty(const DeviceId device_id, const std::string& name); |
| + |
| + // Check if a property exists for a device. Return if it is found. |
| + GesturesProp* FindProperty(const DeviceId device_id, const std::string& name); |
| + |
| + // Get the default value of a property based on the configuration files. |
| + GesturesProp* GetDefaultProperty(const DeviceId device_id, |
| + const std::string& name); |
| + |
| + // The device configuration files are parsed and stored in the memory upon |
| + // Chrome starts. The default property values are then applied to each device |
| + // when it is attached/detected. |
| + void LoadDeviceConfigurations(); |
| + |
| + // Parse a xorg-conf file. We ignore all sections other than InputClass. |
| + // Check the xorg-conf spec for more infomation about its format. |
| + void ParseXorgConfFile(const std::string& content); |
| + |
| + // Create a match criteria. |
| + internal::MatchCriteria* CreateMatchCriteria(const std::string& match_type, |
| + const std::string& arg); |
| + |
| + // Create a property that comes from the conf files. |
| + GesturesProp* CreateDefaultProperty(const std::string& name, |
| + const std::string& value); |
| + |
| + // Setup default property values for a newly found device. |
| + void SetupDefaultProperties(const DeviceId device_id, DevicePtr dev); |
| + |
| + // An incremental counter of the next device id to be used for mapping. |
| + DeviceId device_id_counter_; |
| + |
| + // Map of device ids. |
| + DeviceIdMap device_ids_map_; |
| + |
| + // Array of property maps indexed by their respective device ids. Owns all the |
| + // GesturesProp objects in it. |
| + ScopedDeviceScopedPropertyMap properties_maps_; |
| + |
| + // Same as properties_maps_, but loaded with only values specified in the |
| + // configuration files. Will be applied when a property of the same name is |
| + // created. Note that it only references the properties in configurations_ and |
| + // doesn't own any GesturesProp by itself. |
| + ScopedDevicePropertyMap default_properties_maps_; |
| + |
| + // A vector of parsed sections in configuration files. Owns MatchCriterias, |
| + // GesturesProps and ConfigurationSections in it. |
| + ScopedVector<internal::ConfigurationSection> configurations_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(GesturePropertyProvider); |
| +}; |
| + |
| +// Wrapper of GesturesProp related functions. We group them together so that we |
| +// can friend them all at once. |
| +class GesturesPropFunctionsWrapper { |
| + public: |
| + // Property provider interface implementation. |
| + // |
| + // These functions will create a GesturesProp object that can link back to the |
| + // memory that holds the real value, which is often declared in the gesture |
| + // lib. |
| + static GesturesProp* CreateInt(void*, const char*, int*, size_t, const int*); |
| + static GesturesProp* CreateShort(void*, |
| + const char*, |
| + short*, |
| + size_t, |
| + const short*); |
| + static GesturesProp* CreateBool(void*, |
| + const char*, |
| + GesturesPropBool*, |
| + size_t, |
| + const GesturesPropBool*); |
| + |
| + // String GestureProps needs special care due to the use of const char* in the |
| + // gesture lib. Its argument list is also different from numeric properties. |
| + static GesturesProp* CreateString(void*, |
| + const char*, |
| + const char**, |
| + const char*); |
| + |
| + 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.
|
| + const char*, |
| + double*, |
| + size_t, |
| + const double*); |
| + |
| + // Set the handlers to call when a property is accessed. |
| + static void RegisterHandlers(void*, |
| + GesturesProp*, |
| + void*, |
| + GesturesPropGetHandler, |
| + GesturesPropSetHandler); |
| + |
| + // Free a property. |
| + static void Free(void*, GesturesProp*); |
| + |
| + // Initialize hardware-related device properties which will be used in the |
| + // gesture lib. |
| + static bool InitializeDeviceProperties(void*, GestureDeviceProperties* props); |
| + |
| + private: |
| + // Property helper functions. |
| + // Core template function for creating GestureProps. Used by numerical types. |
| + template <typename T, class PROPTYPE> |
| + static GesturesProp* CreateProperty(void*, const char*, T*, size_t, const T*); |
| + |
| + // Do things that should happen BEFORE we create the property. |
| + static GesturesProp* PreCreateProperty(void*, const char*); |
| + // Do things that should happen AFTER we create the property. |
| + static void PostCreateProperty(void*, const char*, GesturesProp*); |
| + |
| + // Some other utility functions used in InitializeDeviceProperties. |
| + static GesturesProp* CreateIntSingle(void*, const char*, int*, int); |
| + static GesturesProp* CreateBoolSingle(void*, |
| + const char*, |
| + GesturesPropBool*, |
| + GesturesPropBool); |
| + |
| + // Routines to get the device pointer and the property provider from the |
| + // GestureInterpreterLibevdevCros pointer. |
| + static GesturePropertyProvider* GetPropertyProvider(void*); |
| + static GesturePropertyProvider::DevicePtr GetDevicePointer(void*); |
| +}; |
| + |
| +extern const GesturesPropProvider kGesturePropProvider; |
| + |
| +} // namspace ui |
| + |
| +#endif // UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_PROPERTY_PROVIDER_H_ |