Chromium Code Reviews| Index: ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.cc |
| diff --git a/ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.cc b/ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..23d17fe9c88d06c5c8be879260e97ad45807b5cd |
| --- /dev/null |
| +++ b/ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.cc |
| @@ -0,0 +1,1247 @@ |
| +// 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. |
| + |
| +#include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" |
| + |
| +#include <gestures/gestures.h> |
| +#include <libevdev/libevdev.h> |
| + |
| +#include <fnmatch.h> |
| +#include <string.h> |
| + |
| +#include <algorithm> |
| +#include <iostream> |
| +#include <set> |
| + |
| +#include "base/files/file_enumerator.h" |
| +#include "base/files/file_util.h" |
| +#include "base/logging.h" |
| +#include "base/strings/string_number_conversions.h" |
| +#include "base/strings/string_split.h" |
| +#include "base/strings/string_tokenizer.h" |
| +#include "base/strings/string_util.h" |
| +#include "base/strings/stringize_macros.h" |
| +#include "base/strings/stringprintf.h" |
| +#include "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cros.h" |
| + |
| +// Severity level for general info logging purpose. |
| +#define GPROP_LOG DVLOG |
| +#define INFO_SEVERITY 1 |
| + |
| +/* Implementation of GesturesProp declared in gestures.h |
| + * |
| + * libgestures requires that this be in the top level namespace. |
| + * */ |
| +struct GesturesProp { |
|
spang
2014/09/26 15:15:32
This interface needs work to avoid lots of the cas
Shecky Lin
2014/10/03 03:58:55
I've tried to comply with this as much as possible
|
| + GesturesProp() |
| + : type(ui::GesturePropertyProvider::PT_INT), |
| + count(1), |
| + is_allocated(false), |
| + is_read_only(false), |
| + write_back(NULL), |
| + handler_data(NULL), |
| + get(NULL), |
| + set(NULL) { |
| + val = NULL; |
| + } |
| + virtual ~GesturesProp() {} |
| + |
| + // Get the memory size of one element of the property data type. |
| + virtual size_t GetElementSize() const = 0; |
| + |
| + // Get the data pointer as a specific type. |
| + template<typename T> |
| + T* GetValueAsType() const { |
| + return reinterpret_cast<T*>(val); |
|
spang
2014/09/26 15:15:32
This allows arbitrary unsafe casts of the pointer.
Shecky Lin
2014/10/03 03:58:55
Removed.
|
| + } |
| + |
| + // Name-typed version for easier access. Note that we always return pointers |
| + // as the underlying data can be an array. |
| + int* GetIntValue() const { return GetValueAsType<int>(); } |
| + short* GetShortValue() const { return GetValueAsType<short>(); } |
| + GesturesPropBool* GetBoolValue() const { |
| + return GetValueAsType<GesturesPropBool>(); |
| + } |
| + std::string* GetStringValue() const { return GetValueAsType<std::string>(); } |
| + double* GetDoubleValue() const { return GetValueAsType<double>(); } |
| + |
| + // Property name, type and number of elements. |
| + std::string name; |
| + ui::GesturePropertyProvider::PropertyType type; |
| + size_t count; |
| + |
| + // Data pointer. |
| + void* val; |
| + |
| + // If the flag is on, it means the memory that the data pointer points to is |
| + // allocated here. We will need to free the memory by ourselves when the |
| + // GesturesProp is destroyed. |
| + bool is_allocated; |
| + |
| + // If the flag is on, it means the GesturesProp is created by passing a NULL |
| + // data pointer to the creator functions. We define the property as a |
| + // read-only one and that no value change will be allowed for it. Note that |
| + // the flag is different from is_allocated in that StringProperty will always |
| + // allocate no matter it is created with NULL or not. |
| + bool is_read_only; |
| + |
| + // In some cases, we don't directly use the data pointer provided by the |
| + // creators due to its limitation and instead use our own types (e.g., in |
| + // the case of string). We thus need to store the write back pointer so that |
| + // we can update the value in the gesture lib if the property value gets |
| + // changed. |
| + void* write_back; |
| + |
| + // Handler function pointers and the data to be passed to them when the |
| + // property is accessed. |
| + void* handler_data; |
| + GesturesPropGetHandler get; |
| + GesturesPropSetHandler set; |
| + private: |
| + // For logging purpose. |
| + friend std::ostream& operator<<(std::ostream& os, const GesturesProp& prop); |
| +}; |
| + |
| +enum GesturesPropLengthType { |
| + GesturesPropSingle, |
| + GesturesPropArray, |
| +}; |
| + |
| +// Type-templated GesturesProp. |
| +template <typename T, GesturesPropLengthType C> |
| +struct TypedGesturesProp : public GesturesProp { |
| + virtual ~TypedGesturesProp() { |
| + if (is_allocated) { |
| + if (C == GesturesPropArray) |
| + delete[] GesturesProp::GetValueAsType<T>(); |
| + else |
| + delete GesturesProp::GetValueAsType<T>(); |
| + } |
| + } |
| + virtual size_t GetElementSize() const { return sizeof(T); } |
| +}; |
| + |
| +// Type-templated GesturesProp creation functions. |
| +template <typename T> |
| +GesturesProp* CreateFixedTypedGesturesProp(const size_t count) { |
| + if (count > 1) |
| + return new TypedGesturesProp<T, GesturesPropArray>; |
| + return new TypedGesturesProp<T, GesturesPropSingle>; |
| +} |
| + |
| +GesturesProp* CreateTypedGesturesProp( |
| + const ui::GesturePropertyProvider::PropertyType& type, |
| + const size_t count) { |
| + GesturesProp* result = NULL; |
| + switch (type) { |
| + case (ui::GesturePropertyProvider::PT_INT): |
| + result = CreateFixedTypedGesturesProp<int>(count); |
| + break; |
| + case (ui::GesturePropertyProvider::PT_SHORT): |
| + result = CreateFixedTypedGesturesProp<short>(count); |
| + break; |
| + case (ui::GesturePropertyProvider::PT_BOOL): |
| + result = CreateFixedTypedGesturesProp<GesturesPropBool>(count); |
| + break; |
| + case (ui::GesturePropertyProvider::PT_STRING): |
| + result = CreateFixedTypedGesturesProp<std::string>(count); |
| + break; |
| + case (ui::GesturePropertyProvider::PT_REAL): |
| + result = CreateFixedTypedGesturesProp<double>(count); |
| + break; |
| + default: |
| + NOTREACHED(); |
| + break; |
| + } |
| + if (result) { |
| + result->type = type; |
| + result->count = count; |
| + } |
| + return result; |
| +} |
| + |
| +// Property type logging function. |
| +std::ostream& operator<<(std::ostream& out, |
| + const ui::GesturePropertyProvider::PropertyType type) { |
| + std::string s; |
| +#define TYPE_CASE(TYPE) \ |
| + case (ui::GesturePropertyProvider::TYPE): \ |
| + s = #TYPE; \ |
| + break; |
| + switch (type) { |
| + TYPE_CASE(PT_INT); |
| + TYPE_CASE(PT_SHORT); |
| + TYPE_CASE(PT_BOOL); |
| + TYPE_CASE(PT_STRING); |
| + TYPE_CASE(PT_REAL); |
| + default: |
| + NOTREACHED(); |
| + break; |
| + } |
| +#undef TYPE_CASE |
| + return out << s; |
| +} |
| + |
| +// GesturesProp logging function. |
| +std::ostream& operator<<(std::ostream& os, const GesturesProp& prop) { |
| + os << "\"" << prop.name << "\", " << prop.type << ", " << prop.count << ", (" |
| + << prop.is_allocated << ", " << prop.is_read_only << "), " |
| + << prop.write_back << ", ("; |
| + for (size_t i = 0; i < prop.count; i++) { |
| + switch (prop.type) { |
| + case ui::GesturePropertyProvider::PT_INT: |
| + os << prop.GetIntValue()[i]; |
| + break; |
| + case ui::GesturePropertyProvider::PT_SHORT: |
| + os << prop.GetShortValue()[i]; |
| + break; |
| + case ui::GesturePropertyProvider::PT_BOOL: |
| + // Prevent the value being printed as characters. |
| + os << static_cast<bool>(prop.GetBoolValue()[i]); |
| + break; |
| + case ui::GesturePropertyProvider::PT_STRING: |
| + os << prop.GetStringValue()[i]; |
| + break; |
| + case ui::GesturePropertyProvider::PT_REAL: |
| + os << prop.GetDoubleValue()[i]; |
| + break; |
| + default: |
| + LOG(ERROR) << "Unknown gesture property type: " << prop.type; |
| + NOTREACHED(); |
| + break; |
| + } |
| + os << ", "; |
| + } |
| + os << ")"; |
| + return os; |
| +} |
| + |
| +namespace ui { |
| + |
| +// The path that we will look for conf files. |
| +const char kConfigurationFilePath[] = "/etc/gesture"; |
| + |
| +// We support only match types that have already been used. One should change |
| +// this if we start using new types in the future. Note that most unsupported |
| +// match types are either useless in CrOS or inapplicable to the non-X |
| +// environment. |
| +const char* kSupportedMatchTypes[] = {"MatchProduct", |
| + "MatchDevicePath", |
| + "MatchUSBID", |
| + "MatchIsPointer", |
| + "MatchIsTouchpad", |
| + "MatchIsTouchscreen"}; |
| +const char* kUnsupportedMatchTypes[] = {"MatchVendor", |
| + "MatchOS", |
| + "MatchPnPID", |
| + "MatchDriver", |
| + "MatchTag", |
| + "MatchLayout", |
| + "MatchIsKeyboard", |
| + "MatchIsJoystick", |
| + "MatchIsTablet"}; |
| + |
| +// Special keywords for boolean values. |
| +const char* kTrue[] = {"on", "true", "yes"}; |
| +const char* kFalse[] = {"off", "false", "no"}; |
| + |
| +// Trick to get the device path from a file descriptor. |
| +std::string GetDeviceNodePath(void* dev) { |
| + std::string proc_symlink = |
| + "/proc/self/fd/" + base::IntToString(static_cast<Evdev*>(dev)->fd); |
| + base::FilePath path; |
| + if (!base::ReadSymbolicLink(base::FilePath(proc_symlink), &path)) |
| + return std::string(); |
| + return path.value(); |
| +} |
| + |
| +GesturePropertyProvider::GesturePropertyProvider() : device_id_counter_(0) { |
| + RegisterMatchCriterias(); |
| + LoadDeviceConfigurations(); |
| +} |
| + |
| +GesturePropertyProvider::~GesturePropertyProvider() { |
| +} |
| + |
| +void GesturePropertyProvider::RegisterMatchCriterias() { |
| + // Macro for registering match criteria derived classes. |
| +#define REGISTER_MATCH_CRITERIA(NAME) \ |
| + match_criteria_map_[#NAME] = \ |
| + &ui::GesturePropertyProvider::AllocateMatchCriteria<NAME> |
| + REGISTER_MATCH_CRITERIA(MatchProduct); |
| + REGISTER_MATCH_CRITERIA(MatchDevicePath); |
| + REGISTER_MATCH_CRITERIA(MatchUSBID); |
| + REGISTER_MATCH_CRITERIA(MatchIsPointer); |
| + REGISTER_MATCH_CRITERIA(MatchIsTouchpad); |
| + REGISTER_MATCH_CRITERIA(MatchIsTouchscreen); |
| +#undef REGISTER_MATCH_CRITERIA |
| + CHECK(arraysize(kSupportedMatchTypes) == match_criteria_map_.size()); |
| +} |
| + |
| +void GesturePropertyProvider::GetDeviceIdsByType( |
| + const DeviceType type, |
| + std::vector<DeviceId>* device_ids) { |
| + device_ids->clear(); |
| + DeviceIdMap::iterator it = device_ids_map_.begin(); |
| + for (; it != device_ids_map_.end(); ++it) |
| + if (IsDeviceOfType(it->first, type)) |
| + device_ids->push_back(it->second); |
| +} |
| + |
| +bool GesturePropertyProvider::IsDeviceOfType(DevicePtr device, |
| + const DeviceType type) { |
| + EvdevClass evdev_class = device->info.evdev_class; |
| + switch (type) { |
| + case DT_MOUSE: |
| + return (evdev_class == EvdevClassMouse || |
| + evdev_class == EvdevClassMultitouchMouse); |
| + break; |
| + case DT_TOUCHPAD: |
| + // Note that the behavior here is different from the inputcontrol script |
| + // which actually returns touchscreen devices as well. |
| + return (evdev_class == EvdevClassTouchpad); |
| + break; |
| + case DT_TOUCHSCREEN: |
| + return (evdev_class == EvdevClassTouchscreen); |
| + break; |
| + case DT_MULTITOUCH: |
| + return (evdev_class == EvdevClassTouchpad || |
| + evdev_class == EvdevClassTouchscreen || |
| + evdev_class == EvdevClassMultitouchMouse); |
| + break; |
| + case DT_MULTITOUCH_MOUSE: |
| + return (evdev_class == EvdevClassMultitouchMouse); |
| + break; |
| + case DT_ALL: |
| + return true; |
| + break; |
| + default: |
| + NOTREACHED(); |
| + break; |
| + } |
| + return false; |
| +} |
| + |
| +GesturePropertyProvider::DeviceId GesturePropertyProvider::GetDeviceId( |
| + DevicePtr dev, |
| + const bool do_create) { |
| + DeviceIdMap::iterator it = device_ids_map_.find(dev); |
| + if (it != device_ids_map_.end()) |
| + return it->second; |
| + if (!do_create) |
| + return -1; |
| + |
| + // Insert a new one if not exists. |
| + // TODO(sheckylin): Replace this id generation scheme with a better one. |
| + // The current way may result in memory leaks. |
| + DeviceId id = device_id_counter_; |
| + device_ids_map_[dev] = id; |
| + properties_maps_.set(id, |
| + scoped_ptr<ScopedPropertyMap>(new ScopedPropertyMap)); |
| + device_id_counter_ = (device_id_counter_ + 1) % kMaxDeviceNum; |
| + |
| + // Apply default prop values for the device. |
| + SetupDefaultProperties(id, dev); |
| + return id; |
| +} |
| + |
| +GesturePropertyProvider::MatchCriteria::MatchCriteria(const std::string& arg) { |
| + // TODO(sheckylin): Should we trim all tokens here? |
| + Tokenize(arg, "|", &args_); |
| +} |
| + |
| +GesturePropertyProvider::MatchProduct::MatchProduct(const std::string& arg) |
| + : MatchCriteria(arg) { |
| +} |
| + |
| +bool GesturePropertyProvider::MatchProduct::Match(DevicePtr device) { |
| + if (args_.empty()) |
| + return true; |
| + std::string name(device->info.name); |
| + for (size_t i = 0; i < args_.size(); i++) |
| + if (name.find(args_[i]) != std::string::npos) |
| + return true; |
| + return false; |
| +} |
| + |
| +GesturePropertyProvider::MatchDevicePath::MatchDevicePath( |
| + const std::string& arg) |
| + : MatchCriteria(arg) { |
| +} |
| + |
| +bool GesturePropertyProvider::MatchDevicePath::Match(DevicePtr device) { |
| + if (args_.empty()) |
| + return true; |
| + |
| + // Check if the device path matches any pattern. |
| + std::string path = GetDeviceNodePath(device); |
| + if (path.empty()) |
| + return false; |
| + for (size_t i = 0; i < args_.size(); i++) |
| + if (fnmatch(args_[i].c_str(), path.c_str(), FNM_NOESCAPE) == 0) |
| + return true; |
| + return false; |
| +} |
| + |
| +GesturePropertyProvider::MatchUSBID::MatchUSBID(const std::string& arg) |
| + : MatchCriteria(arg) { |
| + // Check each pattern and split valid ones into vids and pids. |
| + for (size_t i = 0; i < args_.size(); i++) { |
| + if (!IsValidPattern(args_[i])) |
| + continue; |
| + std::vector<std::string> tokens; |
| + base::SplitString(args_[i], ':', &tokens); |
| + vid_patterns_.push_back(base::StringToLowerASCII(tokens[0])); |
| + pid_patterns_.push_back(base::StringToLowerASCII(tokens[1])); |
| + } |
| +} |
| + |
| +bool GesturePropertyProvider::MatchUSBID::Match(DevicePtr device) { |
| + if (vid_patterns_.empty()) |
| + return true; |
|
spang
2014/09/26 15:15:32
Doesn't this mean if all of the patterns are inval
Shecky Lin
2014/10/03 03:58:55
Done.
|
| + std::string vid = base::StringPrintf("%04x", device->info.id.vendor); |
| + std::string pid = base::StringPrintf("%04x", device->info.id.product); |
| + for (size_t i = 0; i < vid_patterns_.size(); i++) { |
| + if (fnmatch(vid_patterns_[i].c_str(), vid.c_str(), FNM_NOESCAPE) == 0 && |
| + fnmatch(pid_patterns_[i].c_str(), pid.c_str(), FNM_NOESCAPE) == 0) { |
| + return true; |
| + } |
| + } |
| + return false; |
| +} |
| + |
| +bool GesturePropertyProvider::MatchUSBID::IsValidPattern( |
| + const std::string& pattern) { |
| + // Each USB id should be in the lsusb format, i.e., xxxx:xxxx. We choose to do |
| + // a lazy check here: if the pattern contains wrong characters not in the hex |
| + // number range, it won't be matched anyway. |
| + int number_of_colons = 0; |
| + size_t pos_of_colon = 0; |
| + for (size_t i = 0; i < pattern.size(); i++) |
| + if (pattern[i] == ':') |
| + ++number_of_colons, pos_of_colon = i; |
| + return (number_of_colons == 1) && (pos_of_colon != 0) && |
| + (pos_of_colon != pattern.size() - 1); |
| +} |
| + |
| +GesturePropertyProvider::MatchDeviceType::MatchDeviceType( |
| + const std::string& arg) |
| + : MatchCriteria(arg), value_(true), is_valid_(false) { |
| + // Default value of a match criteria is true. |
| + if (args_.empty()) |
| + args_.push_back("on"); |
| + |
| + // We care only about the first argument. |
| + int value = ParseBooleanKeyword(args_[0]); |
| + if (value) { |
| + is_valid_ = true; |
| + value_ = value > 0; |
| + } |
| +} |
| + |
| +GesturePropertyProvider::MatchIsPointer::MatchIsPointer(const std::string& arg) |
| + : MatchDeviceType(arg) { |
| +} |
| + |
| +bool GesturePropertyProvider::MatchIsPointer::Match(DevicePtr device) { |
| + if (!is_valid_) |
| + return true; |
| + return (value_ == (device->info.evdev_class == EvdevClassMouse || |
| + device->info.evdev_class == EvdevClassMultitouchMouse)); |
| +} |
| + |
| +GesturePropertyProvider::MatchIsTouchpad::MatchIsTouchpad( |
| + const std::string& arg) |
| + : MatchDeviceType(arg) { |
| +} |
| + |
| +bool GesturePropertyProvider::MatchIsTouchpad::Match(DevicePtr device) { |
| + if (!is_valid_) |
| + return true; |
| + return (value_ == (device->info.evdev_class == EvdevClassTouchpad)); |
| +} |
| + |
| +GesturePropertyProvider::MatchIsTouchscreen::MatchIsTouchscreen( |
| + const std::string& arg) |
| + : MatchDeviceType(arg) { |
| +} |
| + |
| +bool GesturePropertyProvider::MatchIsTouchscreen::Match(DevicePtr device) { |
| + if (!is_valid_) |
| + return true; |
| + return (value_ == (device->info.evdev_class == EvdevClassTouchscreen)); |
| +} |
| + |
| +bool GesturePropertyProvider::ConfigurationSection::Match(DevicePtr device) { |
| + for (size_t i = 0; i < criterias.size(); ++i) |
| + if (!criterias[i]->Match(device)) |
| + return false; |
| + return true; |
| +} |
| + |
| +bool GesturePropertyProvider::GetProperty(const DeviceId device_id, |
| + const std::string& name, |
| + PropertyType* type, |
| + void* val, |
| + size_t* count) { |
| + // Return if no property of the name is found. |
| + GesturesProp* prop = FindProperty(device_id, name); |
| + if (!prop) |
| + return false; |
| + |
| + // Get the property values. |
| + if (type) |
| + *type = prop->type; |
| + if (count) |
| + *count = prop->count; |
| + if (val) { |
| + if (prop->type == PT_STRING) { |
| + // String properties have constructors so they can't be simply copied. |
| + *(static_cast<std::string*>(val)) = *(prop->GetStringValue()); |
| + } else if (prop->type == PT_BOOL) { |
| + // The internal representation of bool values may contain values outside |
| + // of the bool range so we need to clamp them. |
| + bool* des = static_cast<bool*>(val); |
| + GesturesPropBool* src = prop->GetBoolValue(); |
| + for (size_t i = 0; i < prop->count; ++i) |
| + des[i] = static_cast<bool>(src[i]); |
| + } else { |
| + memmove(val, prop->val, prop->count * prop->GetElementSize()); |
| + } |
| + } |
| + |
| + // We don't have the X server now so there is currently nothing to do when |
| + // the get handler returns true. |
| + // TODO(sheckylin): Re-visit this if we use handlers that modifies the |
| + // property. |
| + if (prop->get) |
| + prop->get(prop->handler_data); |
| + return true; |
| +} |
| + |
| +bool GesturePropertyProvider::SetProperty(const DeviceId device_id, |
| + const std::string& name, |
| + const void* val) { |
| + if (!val) |
| + return false; |
| + |
| + // Return if no property of the name is found. |
| + GesturesProp* prop = FindProperty(device_id, name); |
| + if (!prop) |
| + return false; |
| + |
| + // As per the legacy guideline, all read-only properties (created with NULL) |
| + // can't be modified. If we want to change this in the future, re-think about |
| + // the different cases here. |
| + if (prop->is_read_only) |
| + return false; |
| + |
| + // Set the property value. |
| + if (prop->type == PT_STRING) { |
| + *(prop->GetStringValue()) = *(static_cast<const std::string*>(val)); |
| + } else if (prop->type == PT_BOOL) { |
| + // The internal representation of bool values is not actually bool. |
| + const bool* src = static_cast<const bool*>(val); |
| + GesturesPropBool* des = prop->GetBoolValue(); |
| + for (size_t i = 0; i < prop->count; ++i) |
| + des[i] = static_cast<GesturesPropBool>(src[i]); |
| + } else { |
| + // For the other numerical types, we can just copy the memory. |
| + memmove(prop->val, val, prop->count * prop->GetElementSize()); |
| + } |
| + |
| + // Write back the pointer if necessary (e.g., string re-allocation). |
| + if (prop->write_back) { |
| + if (prop->type == PT_STRING) { |
| + *(static_cast<const char**>(prop->write_back)) = |
| + prop->GetStringValue()->c_str(); |
| + } else { |
| + NOTREACHED(); |
| + } |
| + } |
| + |
| + // Call the property set handler if available. |
| + if (prop->set) |
| + prop->set(prop->handler_data); |
| + return true; |
| +} |
| + |
| +bool GesturePropertyProvider::SetStringProperty(const DeviceId device_id, |
| + const std::string& name, |
| + const char* val) { |
| + if (!val) |
| + return false; |
| + std::string s = val; |
| + return SetProperty(device_id, name, &s); |
| +} |
| + |
| +void GesturePropertyProvider::AddProperty(const DeviceId device_id, |
| + const std::string& name, |
| + GesturesProp* prop) { |
| + // The look-up should never fail because ideally a property can only be |
| + // created with GesturesPropCreate* functions from the gesture lib side. |
| + // Therefore, we simply return on failure. |
| + ScopedDeviceScopedPropertyMap::iterator it = properties_maps_.find(device_id); |
| + if (it != properties_maps_.end()) |
| + it->second->set(name, scoped_ptr<GesturesProp>(prop)); |
| +} |
| + |
| +void GesturePropertyProvider::DeleteProperty(const DeviceId device_id, |
| + const std::string& name) { |
| + ScopedDeviceScopedPropertyMap::iterator it = properties_maps_.find(device_id); |
| + if (it != properties_maps_.end()) |
| + it->second->erase(name); |
| +} |
| + |
| +GesturesProp* GesturePropertyProvider::FindProperty(const DeviceId device_id, |
| + const std::string& name) { |
| + ScopedDeviceScopedPropertyMap::const_iterator ia = |
| + properties_maps_.find(device_id); |
| + if (ia == properties_maps_.end()) |
| + return NULL; |
| + ScopedPropertyMap::const_iterator ib = ia->second->find(name); |
| + if (ib == ia->second->end()) |
| + return NULL; |
| + return ib->second; |
| +} |
| + |
| +GesturesProp* GesturePropertyProvider::GetDefaultProperty( |
| + const DeviceId device_id, |
| + const std::string& name) { |
| + ScopedDevicePropertyMap::const_iterator ia = |
| + default_properties_maps_.find(device_id); |
| + if (ia == default_properties_maps_.end()) |
| + return NULL; |
| + PropertyMap::const_iterator ib = ia->second->find(name); |
| + if (ib == ia->second->end()) |
| + return NULL; |
| + return ib->second; |
| +} |
| + |
| +void GesturePropertyProvider::LoadDeviceConfigurations() { |
| + // Enumerate conf files and sort them lexicographically. |
| + std::set<base::FilePath> files; |
| + base::FileEnumerator file_enum(base::FilePath(kConfigurationFilePath), |
| + false, |
| + base::FileEnumerator::FILES, |
| + "*.conf"); |
| + for (base::FilePath path = file_enum.Next(); !path.empty(); |
| + path = file_enum.Next()) { |
| + files.insert(path); |
| + } |
| + GPROP_LOG(INFO_SEVERITY) << files.size() << " conf files were found"; |
| + |
| + // Parse conf files one-by-one. |
| + for (std::set<base::FilePath>::iterator file_iter = files.begin(); |
| + file_iter != files.end(); |
| + ++file_iter) { |
| + GPROP_LOG(INFO_SEVERITY) << "Parsing conf file: " << (*file_iter).value(); |
| + std::string content; |
| + if (!base::ReadFileToString(*file_iter, &content)) { |
| + LOG(ERROR) << "Can't loading gestures conf file: " |
| + << (*file_iter).value(); |
| + continue; |
| + } |
| + ParseXorgConfFile(content); |
| + } |
| +} |
| + |
| +void GesturePropertyProvider::ParseXorgConfFile(const std::string& content) { |
| + // To simplify the parsing work, we made some assumption about the conf file |
| + // format which doesn't exist in the original xorg-conf spec. Most important |
| + // ones are: |
| + // 1. All keywords and names are now case-sensitive. Also, underscores are not |
| + // ignored. |
| + // 2. Each entry takes up one and exactly one line in the file. |
| + // 3. No negation of the option value even if the option name is prefixed with |
| + // "No" as it may cause problems for option names that does start with "No" |
| + // (e.g., "Non-linearity"). |
| + |
| + // Break the content into sections, lines and then pieces. |
| + // Sections are delimited by the "EndSection" keyword. |
| + // Lines are delimited by "\n". |
| + // Pieces are delimited by all white-spaces. |
| + std::vector<std::string> sections; |
| + base::SplitStringUsingSubstr(content, "EndSection", §ions); |
| + for (size_t i = 0; i < sections.size(); ++i) { |
| + // Create a new configuration section. |
| + configurations_.push_back(new ConfigurationSection()); |
| + ConfigurationSection* config = configurations_.back(); |
| + |
| + // Break the section into lines. |
| + base::StringTokenizer lines(sections[i], "\n"); |
| + bool is_input_class_section = true; |
| + bool has_checked_section_type = false; |
| + while (is_input_class_section && lines.GetNext()) { |
| + // Parse the line w.r.t. the xorg-conf format. |
| + std::string line(lines.token()); |
| + |
| + // Skip empty lines. |
| + if (line.empty()) |
| + continue; |
| + |
| + // Treat all whitespaces as delimiters. |
| + base::StringTokenizer pieces(line, base::kWhitespaceASCII); |
| + pieces.set_quote_chars("\""); |
| + bool is_parsing = false; |
| + bool has_error = false; |
| + bool next_is_section_type = false; |
| + bool next_is_option_name = false; |
| + bool next_is_option_value = false; |
| + bool next_is_match_criteria = false; |
| + bool next_is_identifier = false; |
| + std::string match_type, option_name; |
| + while (pieces.GetNext()) { |
| + std::string piece(pieces.token()); |
| + |
| + // Skip empty pieces. |
| + if (piece.empty()) |
| + continue; |
| + |
| + // See if we are currently parsing an entry or are still looking for |
| + // one. |
| + if (is_parsing) { |
| + // Stop parsing the current line if the format is wrong. |
| + if (piece.size() <= 2 || piece[0] != '\"' || |
| + piece[piece.size() - 1] != '\"') { |
| + LOG(ERROR) << "Error parsing line: " << lines.token(); |
| + has_error = true; |
| + if (next_is_section_type) |
| + is_input_class_section = false; |
| + break; |
| + } |
| + |
| + // Parse the arguments. Note that we don't break even if a whitespace |
| + // string is passed. It will just be handled in various ways based on |
| + // the entry type. |
| + std::string arg; |
| + base::TrimWhitespaceASCII( |
| + piece.substr(1, piece.size() - 2), base::TRIM_ALL, &arg); |
| + if (next_is_section_type) { |
| + // We only care about InputClass sections. |
| + if (arg != "InputClass") { |
| + has_error = true; |
| + is_input_class_section = false; |
| + } else { |
| + GPROP_LOG(INFO_SEVERITY) << "New InputClass section found"; |
| + has_checked_section_type = true; |
| + } |
| + break; |
| + } else if (next_is_identifier) { |
| + GPROP_LOG(INFO_SEVERITY) << "Identifier: " << arg; |
| + config->identifier = arg; |
| + next_is_identifier = false; |
| + break; |
| + } else if (next_is_option_name) { |
| + // TODO(sheckylin): Support option "Ignore". |
| + option_name = arg; |
| + next_is_option_value = true; |
| + next_is_option_name = false; |
| + } else if (next_is_option_value) { |
| + GesturesProp* prop = CreateDefaultProperty(option_name, arg); |
| + if(prop) |
| + config->properties.push_back(prop); |
| + next_is_option_value = false; |
| + break; |
| + } else if (next_is_match_criteria) { |
| + // Skip all match types that are not supported. |
| + if (IsMatchTypeSupported(match_type)) { |
| + MatchCriteria* criteria = CreateMatchCriteria(match_type, arg); |
| + if (criteria) |
| + config->criterias.push_back(criteria); |
| + } |
| + next_is_match_criteria = false; |
| + break; |
| + } |
| + } else { |
| + // If the section type hasn't been decided yet, look for it. |
| + // Otherwise, look for valid entries according to the spec. |
| + if (has_checked_section_type) { |
| + if (piece == "Driver") { |
| + // TODO(sheckylin): Support "Driver" so that we can force a device |
| + // not to use the gesture lib. |
| + NOTIMPLEMENTED(); |
| + break; |
| + } else if (piece == "Identifier") { |
| + is_parsing = true; |
| + next_is_identifier = true; |
| + continue; |
| + } else if (piece == "Option") { |
| + is_parsing = true; |
| + next_is_option_name = true; |
| + continue; |
| + } else if (piece.size() > 5 && piece.compare(0, 5, "Match") == 0) { |
| + match_type = piece; |
| + is_parsing = true; |
| + next_is_match_criteria = true; |
| + continue; |
| + } |
| + } else if (piece == "Section") { |
| + is_parsing = true; |
| + next_is_section_type = true; |
| + continue; |
| + } |
| + |
| + // If none of the above is found, check if the current piece starts a |
| + // comment. |
| + if (piece.empty() || piece[0] != '#') { |
| + LOG(ERROR) << "Error parsing line: " << lines.token(); |
| + has_error = true; |
| + } |
| + break; |
| + } |
| + } |
| + |
| + // The value of a boolean option is skipped (default is true). |
| + if (!has_error && (next_is_option_value || next_is_match_criteria)) { |
| + if (next_is_option_value) { |
| + GesturesProp* prop = CreateDefaultProperty(option_name, "on"); |
| + if (prop) |
| + config->properties.push_back(prop); |
| + } else if (IsMatchTypeSupported(match_type) && |
| + IsMatchDeviceType(match_type)) { |
| + MatchCriteria* criteria = CreateMatchCriteria(match_type, "on"); |
| + if (criteria) |
| + config->criterias.push_back(criteria); |
| + } |
| + } |
| + } |
| + |
| + // Remove useless config sections. |
| + if (!is_input_class_section || |
| + (config->criterias.empty() && config->properties.empty())) { |
| + configurations_.pop_back(); |
| + } |
| + } |
| +} |
| + |
| +bool GesturePropertyProvider::IsMatchTypeSupported( |
| + const std::string& match_type) { |
| + for (size_t i = 0; i < arraysize(kSupportedMatchTypes); i++) |
| + if (match_type == kSupportedMatchTypes[i]) |
| + return true; |
| + for (size_t i = 0; i < arraysize(kUnsupportedMatchTypes); i++) { |
| + if (match_type == kUnsupportedMatchTypes[i]) { |
| + LOG(ERROR) << "Unsupported gestures input class match type: " |
| + << match_type; |
| + return false; |
| + } |
| + } |
| + return false; |
| +} |
| + |
| +bool GesturePropertyProvider::IsMatchDeviceType( |
| + const std::string& match_type) { |
| + return StartsWithASCII(match_type, "MatchIs", true); |
| +} |
| + |
| +GesturePropertyProvider::MatchCriteria* |
| +GesturePropertyProvider::CreateMatchCriteria(const std::string& match_type, |
| + const std::string& arg) { |
| + GPROP_LOG(INFO_SEVERITY) << "Creating match criteria: (" << match_type << ", " |
| + << arg << ")"; |
| + return (this->*match_criteria_map_[match_type])(arg); |
| +} |
| + |
| +GesturesProp* GesturePropertyProvider::CreateDefaultProperty( |
| + const std::string& name, |
| + const std::string& value) { |
| + // Our parsing rule: |
| + // 1. No hex or oct number is accepted. |
| + // 2. All numbers will be stored as double. |
| + // 3. Array elements can be separated by both white-spaces or commas. |
| + // 4. A token is treated as numeric either if it is one of the special |
| + // keywords for boolean values (on, true, yes, off, false, no) or if |
| + // base::StringToDouble succeeds. |
| + // 5. The property is treated as numeric if and only if all of its elements |
| + // (if any) are numerics. Otherwise, it will be treated as a string. |
| + // 6. A string property will be trimmed before storing its value. |
| + GPROP_LOG(INFO_SEVERITY) << "Creating default property: (" << name << ", " |
| + << value << ")"; |
| + |
| + // Parse elements one-by-one. |
| + std::string delimiters(base::kWhitespaceASCII); |
| + delimiters.append(","); |
| + base::StringTokenizer tokens(value, delimiters); |
| + bool is_all_numeric = true; |
| + std::vector<double> numbers; |
| + while (tokens.GetNext()) { |
| + // Skip empty tokens. |
| + std::string token(tokens.token()); |
| + if (token.empty()) |
| + continue; |
| + |
| + // Check if it is a boolean keyword. |
| + int bool_result = ParseBooleanKeyword(token); |
| + if (bool_result) { |
| + numbers.push_back(bool_result > 0); |
| + continue; |
| + } |
| + |
| + // Check if it is a number. |
| + double real_result; |
| + bool success = base::StringToDouble(token, &real_result); |
| + if (!success) { |
| + is_all_numeric = false; |
| + break; |
| + } |
| + numbers.push_back(real_result); |
| + } |
| + |
| + // Setup GesturesProp data. |
| + GesturesProp* prop = NULL; |
| + // Arrays need to contain at least one number and may contain numbers only. |
| + if (is_all_numeric && numbers.size()) { |
| + prop = CreateTypedGesturesProp(PT_REAL, numbers.size()); |
| + prop->val = new double[numbers.size()]; |
| + std::copy(numbers.begin(), numbers.end(), prop->GetDoubleValue()); |
| + } else { |
| + prop = CreateTypedGesturesProp(PT_STRING, 1); |
| + std::string trimmed; |
| + base::TrimWhitespaceASCII(value, base::TRIM_ALL, &trimmed); |
| + prop->val = new std::string(trimmed); |
| + } |
| + prop->name = name; |
| + |
| + GPROP_LOG(INFO_SEVERITY) << "Prop: " << *prop; |
| + // The function will always succeed for now but it may change later if we |
| + // specify some name or args as invalid. |
| + return prop; |
| +} |
| + |
| +int GesturePropertyProvider::ParseBooleanKeyword(const std::string& value) { |
| + for (size_t i = 0; i < arraysize(kTrue); i++) |
| + if (LowerCaseEqualsASCII(value, kTrue[i])) |
| + return 1; |
| + for (size_t i = 0; i < arraysize(kFalse); i++) |
| + if (LowerCaseEqualsASCII(value, kFalse[i])) |
| + return -1; |
| + return 0; |
| +} |
| + |
| +void GesturePropertyProvider::SetupDefaultProperties( |
| + const DeviceId device_id, |
| + DevicePtr dev) { |
| + GPROP_LOG(INFO_SEVERITY) << "Setting up default properties for (" << dev |
| + << ", " << device_id << ", " << dev->info.name |
| + << ")"; |
| + |
| + // Go through all parsed sections. |
| + scoped_ptr<PropertyMap> prop_map(new PropertyMap); |
| + for (size_t i = 0; i < configurations_.size(); i++) { |
| + if (configurations_[i]->Match(dev)) { |
| + GPROP_LOG(INFO_SEVERITY) << "Conf section \"" |
| + << configurations_[i]->identifier |
| + << "\" is matched"; |
| + for (size_t j = 0; j < configurations_[i]->properties.size(); j++) { |
| + GesturesProp* prop = configurations_[i]->properties[j]; |
| + // We can't use insert here because a property may be set for several |
| + // times along the way. |
| + (*prop_map)[prop->name] = prop; |
| + } |
| + } |
| + } |
| + default_properties_maps_.set(device_id, prop_map.Pass()); |
| +} |
| + |
| +template <typename T> |
| +GesturesProp* GesturesPropFunctionsWrapper::Create( |
| + void* priv, |
| + const char* name, |
| + GesturePropertyProvider::PropertyType type, |
| + T* val, |
| + size_t count) { |
| + GesturePropertyProvider* provider = GetPropertyProvider(priv); |
| + GesturePropertyProvider::DevicePtr dev = GetDevicePointer(priv); |
| + |
| + // Create a new PropertyMap for the device if not exists already. |
| + GesturePropertyProvider::DeviceId device_id = |
| + provider->GetDeviceId(dev, true); |
| + |
| + /* Insert property and setup property values */ |
| + |
| + // First, see if the GesturesProp already exists. |
| + GPROP_LOG(3) << "Creating Property: \"" << name << "\""; |
| + GesturesProp* prop = provider->FindProperty(device_id, name); |
| + |
| + // If so, delete it as we can't reuse the data structure (newly-created |
| + // property may have different data type and count, which are fixed upon |
| + // creation via the template mechanism). |
| + if (prop) { |
| + GPROP_LOG(3) << "Found old property, deleting it ..."; |
|
spang
2014/09/26 15:15:32
Does the lib ever create differently types propert
Shecky Lin
2014/10/03 03:58:55
In general, it shouldn't, but in case it happens I
|
| + Free(dev, prop); |
| + } |
| + prop = CreateTypedGesturesProp(type, count); |
| + provider->AddProperty(device_id, name, prop); |
| + prop->name = name; |
| + |
| + // Allocate memory for the data if a NULL pointer is provided. |
| + if (!val) { |
| + if (count > 1) |
| + prop->val = new T[count]; |
| + else |
| + prop->val = new T; |
| + prop->is_allocated = true; |
| + } else { |
| + prop->val = val; |
| + } |
| + return prop; |
| +} |
| + |
| +template <typename T, GesturePropertyProvider::PropertyType type> |
| +GesturesProp* GesturesPropFunctionsWrapper::CreateProperty(void* priv, |
| + const char* name, |
| + T* val, |
| + size_t count, |
| + const T* init) { |
| + GesturePropertyProvider* provider = GetPropertyProvider(priv); |
| + GesturePropertyProvider::DevicePtr dev = GetDevicePointer(priv); |
| + |
| + // Create the object first. |
| + GesturesProp* result = Create(priv, name, type, val, count); |
| + if (!val) |
| + result->is_read_only = true; |
| + |
| + // We currently assumed that we won't specify any array property in the |
| + // configuration files. The code needs to be updated if the assumption becomes |
| + // invalid in the future. |
| + if (count == 1) { |
| + GesturesProp* default_prop = |
| + provider->GetDefaultProperty(provider->GetDeviceId(dev), name); |
| + if (!default_prop || |
| + default_prop->type == GesturePropertyProvider::PT_STRING) { |
| + *(result->GetValueAsType<T>()) = *init; |
| + } else { |
| + GPROP_LOG(INFO_SEVERITY) << "Default property found. Using its value ..."; |
| + // TODO(sheckylin): Handle value out-of-range (e.g., double to int). |
| + *(result->GetValueAsType<T>()) = |
| + static_cast<T>(*(default_prop->GetDoubleValue())); |
| + } |
| + } else { |
| + memmove(result->val, init, count * sizeof(T)); |
| + } |
| + |
| + GPROP_LOG(INFO_SEVERITY) << "Created active prop: " << *result; |
| + return result; |
| +} |
| + |
| +GesturesProp* GesturesPropFunctionsWrapper::CreateInt(void* priv, |
| + const char* name, |
| + int* val, |
| + size_t count, |
| + const int* init) { |
| + return CreateProperty<int, GesturePropertyProvider::PT_INT>( |
| + priv, name, val, count, init); |
| +} |
| + |
| +GesturesProp* GesturesPropFunctionsWrapper::CreateShort(void* priv, |
| + const char* name, |
| + short* val, |
| + size_t count, |
| + const short* init) { |
| + return CreateProperty<short, GesturePropertyProvider::PT_SHORT>( |
| + priv, name, val, count, init); |
| +} |
| + |
| +GesturesProp* GesturesPropFunctionsWrapper::CreateBool( |
| + void* priv, |
| + const char* name, |
| + GesturesPropBool* val, |
| + size_t count, |
| + const GesturesPropBool* init) { |
| + return CreateProperty<GesturesPropBool, GesturePropertyProvider::PT_BOOL>( |
| + priv, name, val, count, init); |
| +} |
| + |
| +GesturesProp* GesturesPropFunctionsWrapper::CreateReal(void* priv, |
| + const char* name, |
| + double* val, |
| + size_t count, |
| + const double* init) { |
| + return CreateProperty<double, GesturePropertyProvider::PT_REAL>( |
| + priv, name, val, count, init); |
| +} |
| + |
| +GesturesProp* GesturesPropFunctionsWrapper::CreateString(void* priv, |
| + const char* name, |
| + const char** val, |
| + const char* init) { |
| + GesturePropertyProvider* provider = GetPropertyProvider(priv); |
| + GesturePropertyProvider::DevicePtr dev = GetDevicePointer(priv); |
| + |
| + // StringProperty's memory is always allocated on this side instead of |
| + // externally in the gesture lib as the original one will be destroyed right |
| + // after the constructor call (check the design of StringProperty). To do |
| + // this, we call the Create function with NULL pointer so that it always |
| + // allocates. |
| + GesturesProp* result = Create(priv, |
| + name, |
| + GesturePropertyProvider::PT_STRING, |
| + static_cast<std::string*>(NULL), |
| + 1); |
| + if (!val) |
| + result->is_read_only = true; |
| + |
| + // Setup its value just like the other data types. |
| + GesturesProp* default_prop = |
| + provider->GetDefaultProperty(provider->GetDeviceId(dev), name); |
| + if (!default_prop || |
| + default_prop->type != GesturePropertyProvider::PT_STRING) { |
| + *(result->GetStringValue()) = init; |
| + } else { |
| + GPROP_LOG(INFO_SEVERITY) << "Default property found. Using its value ..."; |
| + *(result->GetStringValue()) = *(default_prop->GetStringValue()); |
| + } |
| + |
| + // If the provided pointer is not NULL, replace its content |
| + // (val_ of StringProperty) with the address of our allocated string. |
| + // Note that we don't have to do this for the other data types as they will |
| + // use the original data pointer if possible and it is unnecessary to do so |
| + // if the pointer is NULL. |
| + if (val) { |
| + *(val) = result->GetStringValue()->c_str(); |
| + result->write_back = val; |
| + } |
| + |
| + GPROP_LOG(INFO_SEVERITY) << "Created active prop: " << *result; |
| + return result; |
| +} |
| + |
| +void GesturesPropFunctionsWrapper::RegisterHandlers( |
| + void* priv, |
| + GesturesProp* prop, |
| + void* handler_data, |
| + GesturesPropGetHandler get, |
| + GesturesPropSetHandler set) { |
| + // Sanity checks |
| + if (!priv || !prop) |
| + return; |
| + |
| + prop->handler_data = handler_data; |
| + prop->get = get; |
| + prop->set = set; |
| +} |
| + |
| +void GesturesPropFunctionsWrapper::Free(void* priv, GesturesProp* prop) { |
| + if (!prop) |
| + return; |
| + |
| + GesturePropertyProvider* provider = GetPropertyProvider(priv); |
| + GesturePropertyProvider::DevicePtr dev = GetDevicePointer(priv); |
| + GesturePropertyProvider::DeviceId device_id = provider->GetDeviceId(dev); |
| + if (device_id < 0) |
| + return; |
| + |
| + // No need to manually delete the prop pointer as it is implicitly handled |
| + // with scoped ptr. |
| + GPROP_LOG(3) << "Freeing Property: \"" << prop->name << "\""; |
| + provider->DeleteProperty(device_id, prop->name); |
| +} |
| + |
| +GesturesProp* GesturesPropFunctionsWrapper::CreateIntSingle( |
| + void* priv, |
| + const char* name, |
| + int* val, |
| + int init) { |
| + return CreateInt(priv, name, val, 1, &init); |
| +} |
| + |
| +GesturesProp* GesturesPropFunctionsWrapper::CreateBoolSingle( |
| + void* priv, |
| + const char* name, |
| + GesturesPropBool* val, |
| + GesturesPropBool init) { |
| + return CreateBool(priv, name, val, 1, &init); |
| +} |
| + |
| +GesturePropertyProvider* GesturesPropFunctionsWrapper::GetPropertyProvider( |
| + void* priv) { |
| + return static_cast<GestureInterpreterLibevdevCros*>(priv) |
| + ->GetPropertyProvider(); |
| +} |
| + |
| +GesturePropertyProvider::DevicePtr |
| +GesturesPropFunctionsWrapper::GetDevicePointer(void* priv) { |
| + return static_cast<GestureInterpreterLibevdevCros*>(priv)->GetDevicePointer(); |
| +} |
| + |
| +bool GesturesPropFunctionsWrapper::InitializeDeviceProperties( |
| + void* priv, |
| + GestureDeviceProperties* props) { |
| + if (!priv) |
| + return false; |
| + GesturePropertyProvider::DevicePtr dev = GetDevicePointer(priv); |
| + |
| + /* Create Device Properties */ |
| + |
| + // Read Only properties. |
| + CreateString(priv, "Device Node", NULL, GetDeviceNodePath(dev).c_str()); |
| + CreateShort(priv, |
| + "Device Vendor ID", |
| + NULL, |
| + 1, |
| + reinterpret_cast<short*>(&(dev->info.id.vendor))); |
|
spang
2014/09/26 15:15:32
This isn't allowed with strict aliasing, please do
Shecky Lin
2014/10/03 03:58:55
Done.
|
| + CreateShort(priv, |
| + "Device Product ID", |
| + NULL, |
| + 1, |
| + reinterpret_cast<short*>(&(dev->info.id.product))); |
| + |
| + // Useable trackpad area. If not configured in .conf file, |
| + // use x/y valuator min/max as reported by kernel driver. |
| + CreateIntSingle( |
| + priv, "Active Area Left", &props->area_left, Event_Get_Left(dev)); |
| + CreateIntSingle( |
| + priv, "Active Area Right", &props->area_right, Event_Get_Right(dev)); |
| + CreateIntSingle( |
| + priv, "Active Area Top", &props->area_top, Event_Get_Top(dev)); |
| + CreateIntSingle( |
| + priv, "Active Area Bottom", &props->area_bottom, Event_Get_Bottom(dev)); |
| + |
| + // Trackpad resolution (pixels/mm). If not configured in .conf file, |
| + // use x/y resolution as reported by kernel driver. |
| + CreateIntSingle( |
| + priv, "Vertical Resolution", &props->res_y, Event_Get_Res_Y(dev)); |
| + CreateIntSingle( |
| + priv, "Horizontal Resolution", &props->res_x, Event_Get_Res_X(dev)); |
| + |
| + // Trackpad orientation minimum/maximum. If not configured in .conf file, |
| + // use min/max as reported by kernel driver. |
| + CreateIntSingle(priv, |
| + "Orientation Minimum", |
| + &props->orientation_minimum, |
| + Event_Get_Orientation_Minimum(dev)); |
| + CreateIntSingle(priv, |
| + "Orientation Maximum", |
| + &props->orientation_maximum, |
| + Event_Get_Orientation_Maximum(dev)); |
| + |
| + // Log dump property. Will call Event_Dump_Debug_Log when its value is being |
| + // set. |
| + GesturesProp* dump_debug_log_prop = |
| + CreateBoolSingle(priv, "Dump Debug Log", &props->dump_debug_log, false); |
| + RegisterHandlers(priv, dump_debug_log_prop, dev, NULL, Event_Dump_Debug_Log); |
| + |
| + // Whether to do the gesture recognition or just passing the multi-touch data |
| + // to upper layers. |
| + CreateBoolSingle( |
| + priv, "Raw Touch Passthrough", &props->raw_passthrough, false); |
| + return true; |
| +} |
| + |
| +/* Global GesturesPropProvider |
| + * |
| + * Used by PropRegistry in GestureInterpreter to forward property value |
| + * creations from there. |
| + * */ |
| +const GesturesPropProvider kGesturePropProvider = { |
| + GesturesPropFunctionsWrapper::CreateInt, |
| + GesturesPropFunctionsWrapper::CreateShort, |
| + GesturesPropFunctionsWrapper::CreateBool, |
| + GesturesPropFunctionsWrapper::CreateString, |
| + GesturesPropFunctionsWrapper::CreateReal, |
| + GesturesPropFunctionsWrapper::RegisterHandlers, |
| + GesturesPropFunctionsWrapper::Free}; |
| + |
| +} // namespace ui |