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

Unified 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: Addressed previous comments. Refactored the code per style guide. 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 side-by-side diff with in-line comments
Download patch
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..be5f3e983540bb8c57e8bc14bf59f6f21f8948fc
--- /dev/null
+++ b/ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h
@@ -0,0 +1,268 @@
+// 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);
+
+ // Get the GesturesProp object. Returns NULL if not found.
+ //
+ // The user may use the object returned to set/get the property value in the
+ // gesture library's memory. 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").
+ GesturesProp* GetProperty(const DeviceId device_id, const std::string& name);
+
+ private:
+ friend class GesturesPropFunctionsWrapper;
+
+ // Mapping table from a device 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 device 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(const DevicePtr device, const bool do_create);
+
+ // 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* property);
+ 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, const DevicePtr device);
+
+ // 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_;
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
+
+ // 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* device_data,
+ const char* name,
+ int* value,
+ size_t count,
+ const int* init);
+ static GesturesProp* CreateShort(void* device_data,
+ const char* name,
+ short* value,
+ size_t count,
+ const short* init);
+ static GesturesProp* CreateBool(void* device_data,
+ const char* name,
+ GesturesPropBool* value,
+ size_t count,
+ const GesturesPropBool* init);
+
+ // 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* device_data,
+ const char* name,
+ const char** value,
+ const char* init);
+
+ static GesturesProp* CreateReal(void* device_data,
+ const char* name,
+ double* value,
+ size_t count,
+ const double* init);
+
+ // Set the handlers to call when a property is accessed.
+ static void RegisterHandlers(void* device_data,
+ GesturesProp* property,
+ void* handler_data,
+ GesturesPropGetHandler get,
+ GesturesPropSetHandler set);
+
+ // Free a property.
+ static void Free(void* device_data, GesturesProp* property);
+
+ // Initialize hardware-related device properties which will be used in the
+ // gesture lib.
+ static bool InitializeDeviceProperties(void* device_data,
+ GestureDeviceProperties* properties);
+
+ private:
+ // Property helper functions.
+ // Core template function for creating GestureProps. Used by numerical types.
+ template <typename T, class PROPTYPE>
+ static GesturesProp* CreateProperty(void* device_data,
+ const char* name,
+ T* value,
+ size_t count,
+ const T* init);
+
+ // Do things that should happen BEFORE we create the property.
+ static GesturesProp* PreCreateProperty(void* device_data, const char* name);
+ // Do things that should happen AFTER we create the property.
+ static void PostCreateProperty(void* device_data,
+ const char* name,
+ GesturesProp* property);
+
+ // Some other utility functions used in InitializeDeviceProperties.
+ static GesturesProp* CreateIntSingle(void* device_data,
+ const char* name,
+ int* value,
+ int init);
+ static GesturesProp* CreateBoolSingle(void* device_data,
+ const char* name,
+ GesturesPropBool* value,
+ GesturesPropBool init);
+
+ // Routines to get the device pointer and the property provider from the
+ // GestureInterpreterLibevdevCros pointer.
+ static GesturePropertyProvider* GetPropertyProvider(void* device_data);
+ static GesturePropertyProvider::DevicePtr GetDevicePointer(void* device_data);
+};
+
+extern const GesturesPropProvider kGesturePropProvider;
+
+} // namspace ui
+
+#endif // UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_PROPERTY_PROVIDER_H_

Powered by Google App Engine
This is Rietveld 408576698