| Index: ui/base/x/device_data_manager.cc
|
| diff --git a/ui/base/x/device_data_manager.cc b/ui/base/x/device_data_manager.cc
|
| deleted file mode 100644
|
| index e5b6187c92eec5fdeeefda78e5ed263a0f209719..0000000000000000000000000000000000000000
|
| --- a/ui/base/x/device_data_manager.cc
|
| +++ /dev/null
|
| @@ -1,423 +0,0 @@
|
| -// Copyright 2013 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/base/x/device_data_manager.h"
|
| -
|
| -#include <X11/extensions/XInput.h>
|
| -#include <X11/extensions/XInput2.h>
|
| -#include <X11/Xlib.h>
|
| -
|
| -#include "base/logging.h"
|
| -#include "base/memory/singleton.h"
|
| -#include "base/message_pump_aurax11.h"
|
| -#include "ui/base/events/event_constants.h"
|
| -#include "ui/base/events/event_utils.h"
|
| -#include "ui/base/x/device_list_cache_x.h"
|
| -#include "ui/base/x/x11_util.h"
|
| -
|
| -// Copied from xserver-properties.h
|
| -#define AXIS_LABEL_PROP_REL_HWHEEL "Rel Horiz Wheel"
|
| -#define AXIS_LABEL_PROP_REL_WHEEL "Rel Vert Wheel"
|
| -
|
| -// CMT specific timings
|
| -#define AXIS_LABEL_PROP_ABS_DBL_START_TIME "Abs Dbl Start Timestamp"
|
| -#define AXIS_LABEL_PROP_ABS_DBL_END_TIME "Abs Dbl End Timestamp"
|
| -
|
| -// Ordinal values
|
| -#define AXIS_LABEL_PROP_ABS_DBL_ORDINAL_X "Abs Dbl Ordinal X"
|
| -#define AXIS_LABEL_PROP_ABS_DBL_ORDINAL_Y "Abs Dbl Ordinal Y"
|
| -
|
| -// Fling properties
|
| -#define AXIS_LABEL_PROP_ABS_DBL_FLING_VX "Abs Dbl Fling X Velocity"
|
| -#define AXIS_LABEL_PROP_ABS_DBL_FLING_VY "Abs Dbl Fling Y Velocity"
|
| -#define AXIS_LABEL_PROP_ABS_FLING_STATE "Abs Fling State"
|
| -
|
| -#define AXIS_LABEL_PROP_ABS_FINGER_COUNT "Abs Finger Count"
|
| -
|
| -// Touchscreen multi-touch
|
| -#define AXIS_LABEL_ABS_MT_TOUCH_MAJOR "Abs MT Touch Major"
|
| -#define AXIS_LABEL_ABS_MT_TOUCH_MINOR "Abs MT Touch Minor"
|
| -#define AXIS_LABEL_ABS_MT_ORIENTATION "Abs MT Orientation"
|
| -#define AXIS_LABEL_ABS_MT_PRESSURE "Abs MT Pressure"
|
| -#define AXIS_LABEL_ABS_MT_SLOT_ID "Abs MT Slot ID"
|
| -#define AXIS_LABEL_ABS_MT_TRACKING_ID "Abs MT Tracking ID"
|
| -#define AXIS_LABEL_TOUCH_TIMESTAMP "Touch Timestamp"
|
| -
|
| -// When you add new data types, please make sure the order here is aligned
|
| -// with the order in the DataType enum in the header file because we assume
|
| -// they are in sync when updating the device list (see UpdateDeviceList).
|
| -const char* kCachedAtoms[] = {
|
| - AXIS_LABEL_PROP_REL_HWHEEL,
|
| - AXIS_LABEL_PROP_REL_WHEEL,
|
| - AXIS_LABEL_PROP_ABS_DBL_ORDINAL_X,
|
| - AXIS_LABEL_PROP_ABS_DBL_ORDINAL_Y,
|
| - AXIS_LABEL_PROP_ABS_DBL_START_TIME,
|
| - AXIS_LABEL_PROP_ABS_DBL_END_TIME,
|
| - AXIS_LABEL_PROP_ABS_DBL_FLING_VX,
|
| - AXIS_LABEL_PROP_ABS_DBL_FLING_VY,
|
| - AXIS_LABEL_PROP_ABS_FLING_STATE,
|
| - AXIS_LABEL_PROP_ABS_FINGER_COUNT,
|
| - AXIS_LABEL_ABS_MT_TOUCH_MAJOR,
|
| - AXIS_LABEL_ABS_MT_TOUCH_MINOR,
|
| - AXIS_LABEL_ABS_MT_ORIENTATION,
|
| - AXIS_LABEL_ABS_MT_PRESSURE,
|
| -#if !defined(USE_XI2_MT)
|
| - AXIS_LABEL_ABS_MT_SLOT_ID,
|
| -#endif
|
| - AXIS_LABEL_ABS_MT_TRACKING_ID,
|
| - AXIS_LABEL_TOUCH_TIMESTAMP,
|
| -
|
| - NULL
|
| -};
|
| -
|
| -// Constants for checking if a data type lies in the range of CMT/Touch data
|
| -// types.
|
| -const int kCMTDataTypeStart = ui::DeviceDataManager::DT_CMT_SCROLL_X;
|
| -const int kCMTDataTypeEnd = ui::DeviceDataManager::DT_CMT_FINGER_COUNT;
|
| -const int kTouchDataTypeStart = ui::DeviceDataManager::DT_TOUCH_MAJOR;
|
| -const int kTouchDataTypeEnd = ui::DeviceDataManager::DT_TOUCH_RAW_TIMESTAMP;
|
| -
|
| -namespace ui {
|
| -
|
| -bool DeviceDataManager::IsCMTDataType(const int type) {
|
| - return (type >= kCMTDataTypeStart) && (type <= kCMTDataTypeEnd);
|
| -}
|
| -
|
| -bool DeviceDataManager::IsTouchDataType(const int type) {
|
| - return (type >= kTouchDataTypeStart) && (type <= kTouchDataTypeEnd);
|
| -}
|
| -
|
| -DeviceDataManager* DeviceDataManager::GetInstance() {
|
| - return Singleton<DeviceDataManager>::get();
|
| -}
|
| -
|
| -DeviceDataManager::DeviceDataManager()
|
| - : natural_scroll_enabled_(false),
|
| - atom_cache_(ui::GetXDisplay(), kCachedAtoms) {
|
| - // Make sure the sizes of enum and kCachedAtoms are aligned.
|
| - CHECK(arraysize(kCachedAtoms) == static_cast<size_t>(DT_LAST_ENTRY) + 1);
|
| - UpdateDeviceList(ui::GetXDisplay());
|
| -}
|
| -
|
| -DeviceDataManager::~DeviceDataManager() {
|
| -}
|
| -
|
| -float DeviceDataManager::GetNaturalScrollFactor(int sourceid) const {
|
| - // Natural scroll is touchpad-only.
|
| - if (sourceid >= kMaxDeviceNum || !touchpads_[sourceid])
|
| - return -1.0f;
|
| -
|
| - return natural_scroll_enabled_ ? 1.0f : -1.0f;
|
| -}
|
| -
|
| -void DeviceDataManager::UpdateDeviceList(Display* display) {
|
| - cmt_devices_.reset();
|
| - touchpads_.reset();
|
| - for (int i = 0; i < kMaxDeviceNum; ++i) {
|
| - valuator_count_[i] = 0;
|
| - valuator_lookup_[i].clear();
|
| - data_type_lookup_[i].clear();
|
| - valuator_min_[i].clear();
|
| - valuator_max_[i].clear();
|
| - last_seen_valuator_[i].clear();
|
| - }
|
| -
|
| - // Find all the touchpad devices.
|
| - XDeviceList dev_list =
|
| - ui::DeviceListCacheX::GetInstance()->GetXDeviceList(display);
|
| - Atom xi_touchpad = XInternAtom(display, XI_TOUCHPAD, false);
|
| - for (int i = 0; i < dev_list.count; ++i)
|
| - if (dev_list[i].type == xi_touchpad)
|
| - touchpads_[dev_list[i].id] = true;
|
| -
|
| - // Update the structs with new valuator information
|
| - XIDeviceList info_list =
|
| - ui::DeviceListCacheX::GetInstance()->GetXI2DeviceList(display);
|
| - Atom atoms[DT_LAST_ENTRY];
|
| - for (int data_type = 0; data_type < DT_LAST_ENTRY; ++data_type)
|
| - atoms[data_type] = atom_cache_.GetAtom(kCachedAtoms[data_type]);
|
| -
|
| - for (int i = 0; i < info_list.count; ++i) {
|
| - XIDeviceInfo* info = info_list.devices + i;
|
| -
|
| - // We currently handle only slave, non-keyboard devices
|
| - if (info->use != XISlavePointer && info->use != XIFloatingSlave)
|
| - continue;
|
| -
|
| - bool possible_cmt = false;
|
| - bool not_cmt = false;
|
| - const int deviceid = info->deviceid;
|
| -
|
| - for (int j = 0; j < info->num_classes; ++j) {
|
| - if (info->classes[j]->type == XIValuatorClass)
|
| - ++valuator_count_[deviceid];
|
| - else if (info->classes[j]->type == XIScrollClass)
|
| - not_cmt = true;
|
| - }
|
| -
|
| - // Skip devices that don't use any valuator
|
| - if (!valuator_count_[deviceid])
|
| - continue;
|
| -
|
| - valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1);
|
| - data_type_lookup_[deviceid].resize(
|
| - valuator_count_[deviceid], DT_LAST_ENTRY);
|
| - valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0);
|
| - valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0);
|
| - last_seen_valuator_[deviceid].resize(DT_LAST_ENTRY, 0);
|
| - for (int j = 0; j < info->num_classes; ++j) {
|
| - if (info->classes[j]->type != XIValuatorClass)
|
| - continue;
|
| -
|
| - XIValuatorClassInfo* v =
|
| - reinterpret_cast<XIValuatorClassInfo*>(info->classes[j]);
|
| - for (int data_type = 0; data_type < DT_LAST_ENTRY; ++data_type) {
|
| - if (v->label == atoms[data_type]) {
|
| - valuator_lookup_[deviceid][data_type] = v->number;
|
| - data_type_lookup_[deviceid][v->number] = data_type;
|
| - valuator_min_[deviceid][data_type] = v->min;
|
| - valuator_max_[deviceid][data_type] = v->max;
|
| - if (IsCMTDataType(data_type))
|
| - possible_cmt = true;
|
| - break;
|
| - }
|
| - }
|
| - }
|
| -
|
| - if (possible_cmt && !not_cmt)
|
| - cmt_devices_[deviceid] = true;
|
| - }
|
| -}
|
| -
|
| -void DeviceDataManager::GetEventRawData(const XEvent& xev, EventData* data) {
|
| - if (xev.type != GenericEvent)
|
| - return;
|
| -
|
| - XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data);
|
| - if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum)
|
| - return;
|
| - data->clear();
|
| - const int sourceid = xiev->sourceid;
|
| - double* valuators = xiev->valuators.values;
|
| - for (int i = 0; i <= valuator_count_[sourceid]; ++i) {
|
| - if (XIMaskIsSet(xiev->valuators.mask, i)) {
|
| - int type = data_type_lookup_[sourceid][i];
|
| - if (type != DT_LAST_ENTRY) {
|
| - (*data)[type] = *valuators;
|
| - if (IsTouchDataType(type))
|
| - last_seen_valuator_[sourceid][type] = *valuators;
|
| - }
|
| - valuators++;
|
| - }
|
| - }
|
| -}
|
| -
|
| -bool DeviceDataManager::GetEventData(const XEvent& xev,
|
| - const DataType type, double* value) {
|
| - if (xev.type != GenericEvent)
|
| - return false;
|
| -
|
| - XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data);
|
| - if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum)
|
| - return false;
|
| - const int sourceid = xiev->sourceid;
|
| - if (valuator_lookup_[sourceid].empty())
|
| - return false;
|
| -
|
| - int val_index = valuator_lookup_[sourceid][type];
|
| - if (val_index >= 0) {
|
| - if (XIMaskIsSet(xiev->valuators.mask, val_index)) {
|
| - double* valuators = xiev->valuators.values;
|
| - while (val_index--) {
|
| - if (XIMaskIsSet(xiev->valuators.mask, val_index))
|
| - ++valuators;
|
| - }
|
| - *value = *valuators;
|
| - last_seen_valuator_[sourceid][type] = *value;
|
| - return true;
|
| - } else if (IsTouchDataType(type)) {
|
| - *value = last_seen_valuator_[sourceid][type];
|
| - }
|
| - }
|
| -
|
| -#if defined(USE_XI2_MT)
|
| - // With XInput2 MT, Tracking ID is provided in the detail field.
|
| - if (type == DT_TOUCH_TRACKING_ID) {
|
| - *value = xiev->detail;
|
| - return true;
|
| - }
|
| -#endif
|
| -
|
| - return false;
|
| -}
|
| -
|
| -bool DeviceDataManager::IsTouchpadXInputEvent(
|
| - const base::NativeEvent& native_event) const {
|
| - if (native_event->type != GenericEvent)
|
| - return false;
|
| -
|
| - XIDeviceEvent* xievent =
|
| - static_cast<XIDeviceEvent*>(native_event->xcookie.data);
|
| - if (xievent->sourceid >= kMaxDeviceNum)
|
| - return false;
|
| - return touchpads_[xievent->sourceid];
|
| -}
|
| -
|
| -bool DeviceDataManager::IsCMTDeviceEvent(
|
| - const base::NativeEvent& native_event) const {
|
| - if (native_event->type != GenericEvent)
|
| - return false;
|
| -
|
| - XIDeviceEvent* xievent =
|
| - static_cast<XIDeviceEvent*>(native_event->xcookie.data);
|
| - if (xievent->sourceid >= kMaxDeviceNum)
|
| - return false;
|
| - return cmt_devices_[xievent->sourceid];
|
| -}
|
| -
|
| -bool DeviceDataManager::IsCMTGestureEvent(
|
| - const base::NativeEvent& native_event) const {
|
| - return (IsScrollEvent(native_event) ||
|
| - IsFlingEvent(native_event));
|
| -}
|
| -
|
| -bool DeviceDataManager::HasEventData(
|
| - const XIDeviceEvent* xiev, const DataType type) const {
|
| - const int idx = valuator_lookup_[xiev->sourceid][type];
|
| - return (idx >= 0) && XIMaskIsSet(xiev->valuators.mask, idx);
|
| -}
|
| -
|
| -bool DeviceDataManager::IsScrollEvent(
|
| - const base::NativeEvent& native_event) const {
|
| - if (!IsCMTDeviceEvent(native_event))
|
| - return false;
|
| -
|
| - XIDeviceEvent* xiev =
|
| - static_cast<XIDeviceEvent*>(native_event->xcookie.data);
|
| - return (HasEventData(xiev, DT_CMT_SCROLL_X) ||
|
| - HasEventData(xiev, DT_CMT_SCROLL_Y));
|
| -}
|
| -
|
| -bool DeviceDataManager::IsFlingEvent(
|
| - const base::NativeEvent& native_event) const {
|
| - if (!IsCMTDeviceEvent(native_event))
|
| - return false;
|
| -
|
| - XIDeviceEvent* xiev =
|
| - static_cast<XIDeviceEvent*>(native_event->xcookie.data);
|
| - return (HasEventData(xiev, DT_CMT_FLING_X) &&
|
| - HasEventData(xiev, DT_CMT_FLING_Y) &&
|
| - HasEventData(xiev, DT_CMT_FLING_STATE));
|
| -}
|
| -
|
| -bool DeviceDataManager::HasGestureTimes(
|
| - const base::NativeEvent& native_event) const {
|
| - if (!IsCMTDeviceEvent(native_event))
|
| - return false;
|
| -
|
| - XIDeviceEvent* xiev =
|
| - static_cast<XIDeviceEvent*>(native_event->xcookie.data);
|
| - return (HasEventData(xiev, DT_CMT_START_TIME) &&
|
| - HasEventData(xiev, DT_CMT_END_TIME));
|
| -}
|
| -
|
| -void DeviceDataManager::GetScrollOffsets(const base::NativeEvent& native_event,
|
| - float* x_offset, float* y_offset,
|
| - float* x_offset_ordinal,
|
| - float* y_offset_ordinal,
|
| - int* finger_count) {
|
| - *x_offset = 0;
|
| - *y_offset = 0;
|
| - *x_offset_ordinal = 0;
|
| - *y_offset_ordinal = 0;
|
| - *finger_count = 2;
|
| -
|
| - XIDeviceEvent* xiev =
|
| - static_cast<XIDeviceEvent*>(native_event->xcookie.data);
|
| - const float natural_scroll_factor = GetNaturalScrollFactor(xiev->sourceid);
|
| - EventData data;
|
| - GetEventRawData(*native_event, &data);
|
| -
|
| - if (data.find(DT_CMT_SCROLL_X) != data.end())
|
| - *x_offset = data[DT_CMT_SCROLL_X] * natural_scroll_factor;
|
| - if (data.find(DT_CMT_SCROLL_Y) != data.end())
|
| - *y_offset = data[DT_CMT_SCROLL_Y] * natural_scroll_factor;
|
| - if (data.find(DT_CMT_ORDINAL_X) != data.end())
|
| - *x_offset_ordinal = data[DT_CMT_ORDINAL_X] * natural_scroll_factor;
|
| - if (data.find(DT_CMT_ORDINAL_Y) != data.end())
|
| - *y_offset_ordinal = data[DT_CMT_ORDINAL_Y] * natural_scroll_factor;
|
| - if (data.find(DT_CMT_FINGER_COUNT) != data.end())
|
| - *finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]);
|
| -}
|
| -
|
| -void DeviceDataManager::GetFlingData(const base::NativeEvent& native_event,
|
| - float* vx, float* vy,
|
| - float* vx_ordinal, float* vy_ordinal,
|
| - bool* is_cancel) {
|
| - *vx = 0;
|
| - *vy = 0;
|
| - *vx_ordinal = 0;
|
| - *vy_ordinal = 0;
|
| - *is_cancel = false;
|
| -
|
| - XIDeviceEvent* xiev =
|
| - static_cast<XIDeviceEvent*>(native_event->xcookie.data);
|
| - const float natural_scroll_factor = GetNaturalScrollFactor(xiev->sourceid);
|
| - EventData data;
|
| - GetEventRawData(*native_event, &data);
|
| -
|
| - if (data.find(DT_CMT_FLING_X) != data.end())
|
| - *vx = data[DT_CMT_FLING_X] * natural_scroll_factor;
|
| - if (data.find(DT_CMT_FLING_Y) != data.end())
|
| - *vy = data[DT_CMT_FLING_Y] * natural_scroll_factor;
|
| - if (data.find(DT_CMT_FLING_STATE) != data.end())
|
| - *is_cancel = !!static_cast<unsigned int>(data[DT_CMT_FLING_STATE]);
|
| - if (data.find(DT_CMT_ORDINAL_X) != data.end())
|
| - *vx_ordinal = data[DT_CMT_ORDINAL_X] * natural_scroll_factor;
|
| - if (data.find(DT_CMT_ORDINAL_Y) != data.end())
|
| - *vy_ordinal = data[DT_CMT_ORDINAL_Y] * natural_scroll_factor;
|
| -}
|
| -
|
| -void DeviceDataManager::GetGestureTimes(const base::NativeEvent& native_event,
|
| - double* start_time,
|
| - double* end_time) {
|
| - *start_time = 0;
|
| - *end_time = 0;
|
| -
|
| - EventData data;
|
| - GetEventRawData(*native_event, &data);
|
| -
|
| - if (data.find(DT_CMT_START_TIME) != data.end())
|
| - *start_time = data[DT_CMT_START_TIME];
|
| - if (data.find(DT_CMT_END_TIME) != data.end())
|
| - *end_time = data[DT_CMT_END_TIME];
|
| -}
|
| -
|
| -bool DeviceDataManager::NormalizeData(unsigned int deviceid,
|
| - const DataType type,
|
| - double* value) {
|
| - double max_value;
|
| - double min_value;
|
| - if (GetDataRange(deviceid, type, &min_value, &max_value)) {
|
| - *value = (*value - min_value) / (max_value - min_value);
|
| - DCHECK(*value >= 0.0 && *value <= 1.0);
|
| - return true;
|
| - }
|
| - return false;
|
| -}
|
| -
|
| -bool DeviceDataManager::GetDataRange(unsigned int deviceid,
|
| - const DataType type,
|
| - double* min, double* max) {
|
| - if (deviceid >= static_cast<unsigned int>(kMaxDeviceNum))
|
| - return false;
|
| - if (valuator_lookup_[deviceid][type] >= 0) {
|
| - *min = valuator_min_[deviceid][type];
|
| - *max = valuator_max_[deviceid][type];
|
| - return true;
|
| - }
|
| - return false;
|
| -}
|
| -
|
| -} // namespace ui
|
|
|