Index: ui/events/devices/x11/device_data_manager_x11.cc |
diff --git a/ui/events/platform/x11/device_data_manager_x11.cc b/ui/events/devices/x11/device_data_manager_x11.cc |
similarity index 69% |
rename from ui/events/platform/x11/device_data_manager_x11.cc |
rename to ui/events/devices/x11/device_data_manager_x11.cc |
index 90c88310826cb6269ec9faf06e1fc3fca2e860f3..230b7fa5328cbecf9e0ee76c31428712ea5489a2 100644 |
--- a/ui/events/platform/x11/device_data_manager_x11.cc |
+++ b/ui/events/devices/x11/device_data_manager_x11.cc |
@@ -2,22 +2,25 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "ui/events/platform/x11/device_data_manager_x11.h" |
+#include "ui/events/devices/x11/device_data_manager_x11.h" |
#include <X11/extensions/XInput.h> |
#include <X11/extensions/XInput2.h> |
#include <X11/Xlib.h> |
+#include <utility> |
+ |
#include "base/logging.h" |
#include "base/memory/singleton.h" |
#include "base/sys_info.h" |
+#include "ui/events/devices/keyboard_device.h" |
+#include "ui/events/devices/x11/device_list_cache_x11.h" |
+#include "ui/events/devices/x11/touch_factory_x11.h" |
#include "ui/events/event_constants.h" |
#include "ui/events/event_switches.h" |
-#include "ui/events/platform/x11/device_list_cache_x.h" |
-#include "ui/events/platform/x11/keyboard_code_conversion_x11.h" |
-#include "ui/events/platform/x11/touch_factory_x11.h" |
+#include "ui/events/keycodes/keyboard_code_conversion_x.h" |
#include "ui/gfx/display.h" |
-#include "ui/gfx/point3_f.h" |
+#include "ui/gfx/geometry/point3_f.h" |
#include "ui/gfx/x/x11_types.h" |
// XIScrollClass was introduced in XI 2.1 so we need to define it here |
@@ -29,9 +32,9 @@ |
// Multi-touch support was introduced in XI 2.2. Add XI event types here |
// for backward-compatibility with older versions of XInput. |
#if !defined(XI_TouchBegin) |
-#define XI_TouchBegin 18 |
+#define XI_TouchBegin 18 |
#define XI_TouchUpdate 19 |
-#define XI_TouchEnd 20 |
+#define XI_TouchEnd 20 |
#endif |
// Copied from xserver-properties.h |
@@ -40,21 +43,21 @@ |
// 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" |
+#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" |
+#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_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" |
+#define AXIS_LABEL_PROP_ABS_FINGER_COUNT "Abs Finger Count" |
// Cros metrics gesture from touchpad |
-#define AXIS_LABEL_PROP_ABS_METRICS_TYPE "Abs Metrics Type" |
+#define AXIS_LABEL_PROP_ABS_METRICS_TYPE "Abs Metrics Type" |
#define AXIS_LABEL_PROP_ABS_DBL_METRICS_DATA1 "Abs Dbl Metrics Data 1" |
#define AXIS_LABEL_PROP_ABS_DBL_METRICS_DATA2 "Abs Dbl Metrics Data 2" |
@@ -62,38 +65,40 @@ |
#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_POSITION_X "Abs MT Position X" |
-#define AXIS_LABEL_ABS_MT_POSITION_Y "Abs MT Position Y" |
+#define AXIS_LABEL_ABS_MT_PRESSURE "Abs MT Pressure" |
+#define AXIS_LABEL_ABS_MT_POSITION_X "Abs MT Position X" |
+#define AXIS_LABEL_ABS_MT_POSITION_Y "Abs MT Position Y" |
#define AXIS_LABEL_ABS_MT_TRACKING_ID "Abs MT Tracking ID" |
-#define AXIS_LABEL_TOUCH_TIMESTAMP "Touch Timestamp" |
+#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_METRICS_TYPE, |
- AXIS_LABEL_PROP_ABS_DBL_METRICS_DATA1, |
- AXIS_LABEL_PROP_ABS_DBL_METRICS_DATA2, |
- 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, |
- AXIS_LABEL_ABS_MT_POSITION_X, |
- AXIS_LABEL_ABS_MT_POSITION_Y, |
- AXIS_LABEL_ABS_MT_TRACKING_ID, |
- AXIS_LABEL_TOUCH_TIMESTAMP, |
- |
- NULL}; |
+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_METRICS_TYPE, |
+ AXIS_LABEL_PROP_ABS_DBL_METRICS_DATA1, |
+ AXIS_LABEL_PROP_ABS_DBL_METRICS_DATA2, |
+ 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, |
+ AXIS_LABEL_ABS_MT_POSITION_X, |
+ AXIS_LABEL_ABS_MT_POSITION_Y, |
+ 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. |
@@ -104,6 +109,14 @@ const int kTouchDataTypeEnd = ui::DeviceDataManagerX11::DT_TOUCH_RAW_TIMESTAMP; |
namespace ui { |
+namespace { |
+ |
+bool DeviceHasId(const ui::InputDevice input_device, int id) { |
+ return input_device.id == id; |
+} |
+ |
+} // namespace |
+ |
bool DeviceDataManagerX11::IsCMTDataType(const int type) { |
return (type >= kCMTDataTypeStart) && (type <= kCMTDataTypeEnd); |
} |
@@ -145,29 +158,23 @@ bool DeviceDataManagerX11::InitializeXInputInternal() { |
// Check if XInput is available on the system. |
xi_opcode_ = -1; |
int opcode, event, error; |
- if (!XQueryExtension(gfx::GetXDisplay(), "XInputExtension", &opcode, &event, |
- &error)) { |
+ if (!XQueryExtension( |
+ gfx::GetXDisplay(), "XInputExtension", &opcode, &event, &error)) { |
VLOG(1) << "X Input extension not available: error=" << error; |
return false; |
} |
-// Check the XInput version. |
-#if defined(USE_XI2_MT) |
- int major = 2, minor = USE_XI2_MT; |
-#else |
- int major = 2, minor = 0; |
-#endif |
+ // Check the XInput version. |
+ int major = 2, minor = 2; |
if (XIQueryVersion(gfx::GetXDisplay(), &major, &minor) == BadRequest) { |
VLOG(1) << "XInput2 not supported in the server."; |
return false; |
} |
-#if defined(USE_XI2_MT) |
- if (major < 2 || (major == 2 && minor < USE_XI2_MT)) { |
+ if (major < 2 || (major == 2 && minor < 2)) { |
DVLOG(1) << "XI version on server is " << major << "." << minor << ". " |
- << "But 2." << USE_XI2_MT << " is required."; |
+ << "But 2.2 is required."; |
return false; |
} |
-#endif |
xi_opcode_ = opcode; |
CHECK_NE(-1, xi_opcode_); |
@@ -195,6 +202,7 @@ bool DeviceDataManagerX11::IsXInput2Available() const { |
void DeviceDataManagerX11::UpdateDeviceList(Display* display) { |
cmt_devices_.reset(); |
touchpads_.reset(); |
+ master_pointers_.clear(); |
for (int i = 0; i < kMaxDeviceNum; ++i) { |
valuator_count_[i] = 0; |
valuator_lookup_[i].clear(); |
@@ -206,8 +214,8 @@ void DeviceDataManagerX11::UpdateDeviceList(Display* display) { |
} |
// Find all the touchpad devices. |
- XDeviceList dev_list = |
- ui::DeviceListCacheX::GetInstance()->GetXDeviceList(display); |
+ const XDeviceList& dev_list = |
+ ui::DeviceListCacheX11::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) |
@@ -217,27 +225,30 @@ void DeviceDataManagerX11::UpdateDeviceList(Display* display) { |
return; |
// Update the structs with new valuator information |
- XIDeviceList info_list = |
- ui::DeviceListCacheX::GetInstance()->GetXI2DeviceList(display); |
+ const XIDeviceList& info_list = |
+ ui::DeviceListCacheX11::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; |
+ const XIDeviceInfo& info = info_list[i]; |
+ |
+ if (info.use == XIMasterPointer) |
+ master_pointers_.push_back(info.deviceid); |
// We currently handle only slave, non-keyboard devices |
- if (info->use != XISlavePointer && info->use != XIFloatingSlave) |
+ if (info.use != XISlavePointer && info.use != XIFloatingSlave) |
continue; |
bool possible_cmt = false; |
bool not_cmt = false; |
- const int deviceid = info->deviceid; |
+ const int deviceid = info.deviceid; |
- for (int j = 0; j < info->num_classes; ++j) { |
- if (info->classes[j]->type == XIValuatorClass) |
+ 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) |
+ else if (info.classes[j]->type == XIScrollClass) |
not_cmt = true; |
} |
@@ -246,18 +257,18 @@ void DeviceDataManagerX11::UpdateDeviceList(Display* display) { |
continue; |
valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1); |
- data_type_lookup_[deviceid].resize(valuator_count_[deviceid], |
- DT_LAST_ENTRY); |
+ 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); |
for (int j = 0; j < kMaxSlotNum; j++) |
last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); |
- for (int j = 0; j < info->num_classes; ++j) { |
- if (info->classes[j]->type != XIValuatorClass) |
+ for (int j = 0; j < info.num_classes; ++j) { |
+ if (info.classes[j]->type != XIValuatorClass) |
continue; |
XIValuatorClassInfo* v = |
- reinterpret_cast<XIValuatorClassInfo*>(info->classes[j]); |
+ 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; |
@@ -277,17 +288,12 @@ void DeviceDataManagerX11::UpdateDeviceList(Display* display) { |
} |
bool DeviceDataManagerX11::GetSlotNumber(const XIDeviceEvent* xiev, int* slot) { |
-#if defined(USE_XI2_MT) |
ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
if (!factory->IsMultiTouchDevice(xiev->sourceid)) { |
*slot = 0; |
return true; |
} |
return factory->QuerySlotForTrackingID(xiev->detail, slot); |
-#else |
- *slot = 0; |
- return true; |
-#endif |
} |
void DeviceDataManagerX11::GetEventRawData(const XEvent& xev, EventData* data) { |
@@ -295,6 +301,8 @@ void DeviceDataManagerX11::GetEventRawData(const XEvent& xev, EventData* data) { |
return; |
XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); |
+ CHECK(xiev->sourceid >= 0); |
+ CHECK(xiev->deviceid >= 0); |
if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum) |
return; |
data->clear(); |
@@ -317,12 +325,13 @@ void DeviceDataManagerX11::GetEventRawData(const XEvent& xev, EventData* data) { |
} |
bool DeviceDataManagerX11::GetEventData(const XEvent& xev, |
- const DataType type, |
- double* value) { |
+ const DataType type, double* value) { |
if (xev.type != GenericEvent) |
return false; |
XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); |
+ CHECK(xiev->sourceid >= 0); |
+ CHECK(xiev->deviceid >= 0); |
if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum) |
return false; |
const int sourceid = xiev->sourceid; |
@@ -332,7 +341,8 @@ bool DeviceDataManagerX11::GetEventData(const XEvent& xev, |
if (type == DT_TOUCH_TRACKING_ID) { |
// With XInput2 MT, Tracking ID is provided in the detail field for touch |
// events. |
- if (xiev->evtype == XI_TouchBegin || xiev->evtype == XI_TouchEnd || |
+ if (xiev->evtype == XI_TouchBegin || |
+ xiev->evtype == XI_TouchEnd || |
xiev->evtype == XI_TouchUpdate) { |
*value = xiev->detail; |
} else { |
@@ -380,6 +390,7 @@ bool DeviceDataManagerX11::IsTouchpadXInputEvent( |
XIDeviceEvent* xievent = |
static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
+ CHECK(xievent->sourceid >= 0); |
if (xievent->sourceid >= kMaxDeviceNum) |
return false; |
return touchpads_[xievent->sourceid]; |
@@ -392,6 +403,7 @@ bool DeviceDataManagerX11::IsCMTDeviceEvent( |
XIDeviceEvent* xievent = |
static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
+ CHECK(xievent->sourceid >= 0); |
if (xievent->sourceid >= kMaxDeviceNum) |
return false; |
return cmt_devices_[xievent->sourceid]; |
@@ -399,12 +411,18 @@ bool DeviceDataManagerX11::IsCMTDeviceEvent( |
bool DeviceDataManagerX11::IsCMTGestureEvent( |
const base::NativeEvent& native_event) const { |
- return (IsScrollEvent(native_event) || IsFlingEvent(native_event) || |
+ return (IsScrollEvent(native_event) || |
+ IsFlingEvent(native_event) || |
IsCMTMetricsEvent(native_event)); |
} |
-bool DeviceDataManagerX11::HasEventData(const XIDeviceEvent* xiev, |
- const DataType type) const { |
+bool DeviceDataManagerX11::HasEventData( |
+ const XIDeviceEvent* xiev, const DataType type) const { |
+ CHECK(xiev->sourceid >= 0); |
+ if (xiev->sourceid >= kMaxDeviceNum) |
+ return false; |
+ if (type >= valuator_lookup_[xiev->sourceid].size()) |
+ return false; |
const int idx = valuator_lookup_[xiev->sourceid][type]; |
return (idx >= 0) && XIMaskIsSet(xiev->valuators.mask, idx); |
} |
@@ -414,7 +432,8 @@ bool DeviceDataManagerX11::IsScrollEvent( |
if (!IsCMTDeviceEvent(native_event)) |
return false; |
- XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
+ XIDeviceEvent* xiev = |
+ static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
return (HasEventData(xiev, DT_CMT_SCROLL_X) || |
HasEventData(xiev, DT_CMT_SCROLL_Y)); |
} |
@@ -424,7 +443,8 @@ bool DeviceDataManagerX11::IsFlingEvent( |
if (!IsCMTDeviceEvent(native_event)) |
return false; |
- XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
+ 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)); |
@@ -435,7 +455,8 @@ bool DeviceDataManagerX11::IsCMTMetricsEvent( |
if (!IsCMTDeviceEvent(native_event)) |
return false; |
- XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
+ XIDeviceEvent* xiev = |
+ static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
return (HasEventData(xiev, DT_CMT_METRICS_TYPE) && |
HasEventData(xiev, DT_CMT_METRICS_DATA1) && |
HasEventData(xiev, DT_CMT_METRICS_DATA2)); |
@@ -446,7 +467,8 @@ bool DeviceDataManagerX11::HasGestureTimes( |
if (!IsCMTDeviceEvent(native_event)) |
return false; |
- XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
+ XIDeviceEvent* xiev = |
+ static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
return (HasEventData(xiev, DT_CMT_START_TIME) && |
HasEventData(xiev, DT_CMT_END_TIME)); |
} |
@@ -479,12 +501,13 @@ void DeviceDataManagerX11::GetScrollOffsets( |
*finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]); |
} |
-void DeviceDataManagerX11::GetFlingData(const base::NativeEvent& native_event, |
- float* vx, |
- float* vy, |
- float* vx_ordinal, |
- float* vy_ordinal, |
- bool* is_cancel) { |
+void DeviceDataManagerX11::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; |
@@ -506,10 +529,11 @@ void DeviceDataManagerX11::GetFlingData(const base::NativeEvent& native_event, |
*vy_ordinal = data[DT_CMT_ORDINAL_Y]; |
} |
-void DeviceDataManagerX11::GetMetricsData(const base::NativeEvent& native_event, |
- GestureMetricsType* type, |
- float* data1, |
- float* data2) { |
+void DeviceDataManagerX11::GetMetricsData( |
+ const base::NativeEvent& native_event, |
+ GestureMetricsType* type, |
+ float* data1, |
+ float* data2) { |
*type = kGestureMetricsTypeUnknown; |
*data1 = 0; |
*data2 = 0; |
@@ -531,12 +555,13 @@ void DeviceDataManagerX11::GetMetricsData(const base::NativeEvent& native_event, |
} |
int DeviceDataManagerX11::GetMappedButton(int button) { |
- return button > 0 && button <= button_map_count_ ? button_map_[button - 1] |
- : button; |
+ return button > 0 && button <= button_map_count_ ? button_map_[button - 1] : |
+ button; |
} |
void DeviceDataManagerX11::UpdateButtonMap() { |
- button_map_count_ = XGetPointerMapping(gfx::GetXDisplay(), button_map_, |
+ button_map_count_ = XGetPointerMapping(gfx::GetXDisplay(), |
+ button_map_, |
arraysize(button_map_)); |
} |
@@ -556,7 +581,7 @@ void DeviceDataManagerX11::GetGestureTimes( |
*end_time = data[DT_CMT_END_TIME]; |
} |
-bool DeviceDataManagerX11::NormalizeData(unsigned int deviceid, |
+bool DeviceDataManagerX11::NormalizeData(int deviceid, |
const DataType type, |
double* value) { |
double max_value; |
@@ -569,11 +594,12 @@ bool DeviceDataManagerX11::NormalizeData(unsigned int deviceid, |
return false; |
} |
-bool DeviceDataManagerX11::GetDataRange(unsigned int deviceid, |
+bool DeviceDataManagerX11::GetDataRange(int deviceid, |
const DataType type, |
double* min, |
double* max) { |
- if (deviceid >= static_cast<unsigned int>(kMaxDeviceNum)) |
+ CHECK(deviceid >= 0); |
+ if (deviceid >= kMaxDeviceNum) |
return false; |
if (valuator_lookup_[deviceid][type] >= 0) { |
*min = valuator_min_[deviceid][type]; |
@@ -584,8 +610,9 @@ bool DeviceDataManagerX11::GetDataRange(unsigned int deviceid, |
} |
void DeviceDataManagerX11::SetDeviceListForTest( |
- const std::vector<unsigned int>& touchscreen, |
- const std::vector<unsigned int>& cmt_devices) { |
+ const std::vector<int>& touchscreen, |
+ const std::vector<int>& cmt_devices, |
+ const std::vector<int>& other_devices) { |
for (int i = 0; i < kMaxDeviceNum; ++i) { |
valuator_count_[i] = 0; |
valuator_lookup_[i].clear(); |
@@ -596,20 +623,23 @@ void DeviceDataManagerX11::SetDeviceListForTest( |
last_seen_valuator_[i][j].clear(); |
} |
- for (size_t i = 0; i < touchscreen.size(); i++) { |
- unsigned int deviceid = touchscreen[i]; |
+ for (int deviceid : touchscreen) { |
InitializeValuatorsForTest(deviceid, kTouchDataTypeStart, kTouchDataTypeEnd, |
0, 1000); |
} |
cmt_devices_.reset(); |
- for (size_t i = 0; i < cmt_devices.size(); ++i) { |
- unsigned int deviceid = cmt_devices[i]; |
+ for (int deviceid : cmt_devices) { |
cmt_devices_[deviceid] = true; |
touchpads_[deviceid] = true; |
InitializeValuatorsForTest(deviceid, kCMTDataTypeStart, kCMTDataTypeEnd, |
-1000, 1000); |
} |
+ |
+ for (int deviceid : other_devices) { |
+ InitializeValuatorsForTest(deviceid, kCMTDataTypeStart, kCMTDataTypeEnd, |
+ -1000, 1000); |
+ } |
} |
void DeviceDataManagerX11::SetValuatorDataForTest(XIDeviceEvent* xievent, |
@@ -652,28 +682,54 @@ void DeviceDataManagerX11::InitializeValuatorsForTest(int deviceid, |
} |
bool DeviceDataManagerX11::TouchEventNeedsCalibrate(int touch_device_id) const { |
-#if defined(OS_CHROMEOS) && defined(USE_XI2_MT) |
- int64 touch_display_id = GetDisplayForTouchDevice(touch_device_id); |
- if (base::SysInfo::IsRunningOnChromeOS() && |
- touch_display_id == gfx::Display::InternalDisplayId()) { |
- return true; |
- } |
-#endif // defined(OS_CHROMEOS) && defined(USE_XI2_MT) |
+#if defined(OS_CHROMEOS) |
+ if (!base::SysInfo::IsRunningOnChromeOS()) |
+ return false; |
+ |
+ const std::vector<TouchscreenDevice>& touch_devices = |
+ ui::DeviceDataManager::GetInstance()->touchscreen_devices(); |
+ std::vector<TouchscreenDevice>::const_iterator it = |
+ std::find_if(touch_devices.begin(), touch_devices.end(), |
+ std::bind2nd(std::ptr_fun(&DeviceHasId), touch_device_id)); |
+ return it != touch_devices.end() && it->type == INPUT_DEVICE_INTERNAL; |
+#endif // defined(OS_CHROMEOS) |
return false; |
} |
void DeviceDataManagerX11::SetDisabledKeyboardAllowedKeys( |
- scoped_ptr<std::set<KeyboardCode>> excepted_keys) { |
- DCHECK(!excepted_keys.get() || !blocked_keyboard_allowed_keys_.get()); |
+ scoped_ptr<std::set<KeyboardCode> > excepted_keys) { |
+ DCHECK(!excepted_keys.get() || |
+ !blocked_keyboard_allowed_keys_.get()); |
blocked_keyboard_allowed_keys_ = excepted_keys.Pass(); |
} |
-void DeviceDataManagerX11::DisableDevice(unsigned int deviceid) { |
+void DeviceDataManagerX11::DisableDevice(int deviceid) { |
blocked_devices_.set(deviceid, true); |
+ // TODO(rsadam@): Support blocking touchscreen devices. |
+ std::vector<KeyboardDevice> keyboards = keyboard_devices(); |
+ std::vector<KeyboardDevice>::iterator it = |
+ std::find_if(keyboards.begin(), |
+ keyboards.end(), |
+ std::bind2nd(std::ptr_fun(&DeviceHasId), deviceid)); |
+ if (it != std::end(keyboards)) { |
+ blocked_keyboards_.insert( |
+ std::pair<int, KeyboardDevice>(deviceid, *it)); |
+ keyboards.erase(it); |
+ DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
+ } |
} |
-void DeviceDataManagerX11::EnableDevice(unsigned int deviceid) { |
+void DeviceDataManagerX11::EnableDevice(int deviceid) { |
blocked_devices_.set(deviceid, false); |
+ std::map<int, KeyboardDevice>::iterator it = |
+ blocked_keyboards_.find(deviceid); |
+ if (it != blocked_keyboards_.end()) { |
+ std::vector<KeyboardDevice> devices = keyboard_devices(); |
+ // Add device to current list of active devices. |
+ devices.push_back((*it).second); |
+ blocked_keyboards_.erase(it); |
+ DeviceDataManager::OnKeyboardDevicesUpdated(devices); |
+ } |
} |
bool DeviceDataManagerX11::IsEventBlocked( |
@@ -687,12 +743,37 @@ bool DeviceDataManagerX11::IsEventBlocked( |
// Allow any key events from blocked_keyboard_allowed_keys_. |
if (blocked_keyboard_allowed_keys_ && |
(xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) && |
- blocked_keyboard_allowed_keys_->find(KeyboardCodeFromXKeyEvent( |
- native_event)) != blocked_keyboard_allowed_keys_->end()) { |
+ blocked_keyboard_allowed_keys_->find( |
+ KeyboardCodeFromXKeyEvent(native_event)) != |
+ blocked_keyboard_allowed_keys_->end()) { |
return false; |
} |
return blocked_devices_.test(xievent->sourceid); |
} |
+void DeviceDataManagerX11::OnKeyboardDevicesUpdated( |
+ const std::vector<KeyboardDevice>& devices) { |
+ std::vector<KeyboardDevice> keyboards(devices); |
+ for (std::map<int, KeyboardDevice>::iterator blocked_iter = |
+ blocked_keyboards_.begin(); |
+ blocked_iter != blocked_keyboards_.end();) { |
+ // Check if the blocked device still exists in list of devices. |
+ std::vector<KeyboardDevice>::iterator it = std::find_if( |
+ keyboards.begin(), keyboards.end(), |
+ std::bind2nd(std::ptr_fun(&DeviceHasId), (*blocked_iter).first)); |
+ // If the device no longer exists, unblock it, else filter it out from our |
+ // active list. |
+ if (it == keyboards.end()) { |
+ blocked_devices_.set((*blocked_iter).first, false); |
+ blocked_keyboards_.erase(blocked_iter++); |
+ } else { |
+ keyboards.erase(it); |
+ ++blocked_iter; |
+ } |
+ } |
+ // Notify base class of updated list. |
+ DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
+} |
+ |
} // namespace ui |