1116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Copyright 2014 The Chromium Authors. All rights reserved. 27d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 37d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// found in the LICENSE file. 47d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 5116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#ifndef UI_EVENTS_X_DEVICE_DATA_MANAGER_X11_H_ 6116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#define UI_EVENTS_X_DEVICE_DATA_MANAGER_X11_H_ 77d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 8f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Generically-named #defines from Xlib is conflicting with symbols in GTest. 9f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// So many tests .cc file #undef Bool before including device_data_manager.h, 10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// which makes Bool unrecognized in XInput2.h. 11f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#ifndef Bool 12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#define Bool int 13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif 14f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include <X11/extensions/XInput2.h> 167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include <bitset> 187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include <map> 19116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include <set> 207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include <vector> 217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/basictypes.h" 237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/event_types.h" 24cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 25116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "ui/events/device_data_manager.h" 26d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/event_constants.h" 27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ui/events/events_base_export.h" 281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ui/events/keycodes/keyboard_codes.h" 29cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ui/gfx/geometry/rect.h" 3068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ui/gfx/x/x11_atom_cache.h" 317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)typedef union _XEvent XEvent; 337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)namespace ui { 357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 36eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// CrOS touchpad metrics gesture types 37eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochenum GestureMetricsType { 38eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kGestureMetricsTypeNoisyGround = 0, 39eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kGestureMetricsTypeUnknown, 40eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}; 41eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// A class that extracts and tracks the input events data. It currently handles 437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// mouse, touchpad and touchscreen devices. 44116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass EVENTS_BASE_EXPORT DeviceDataManagerX11 : public DeviceDataManager { 457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) public: 467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Enumerate additional data that one might be interested on an input event, 477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // which are usually wrapped in X valuators. If you modify any of this, 487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // make sure to update the kCachedAtoms data structure in the source file 497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // and the k*Type[Start/End] constants used by IsCMTDataType and 507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // IsTouchDataType. 517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) enum DataType { 527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Define the valuators used the CrOS CMT driver. Used by mice and CrOS 537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // touchpads. 547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DT_CMT_SCROLL_X = 0, // Scroll amount on the X (horizontal) direction. 557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DT_CMT_SCROLL_Y, // Scroll amount on the Y (vertical) direction. 567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DT_CMT_ORDINAL_X, // Original (unaccelerated) value on the X direction. 577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Can be used both for scrolls and flings. 587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DT_CMT_ORDINAL_Y, // Original (unaccelerated) value on the Y direction. 597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Can be used both for scrolls and flings. 607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DT_CMT_START_TIME, // Gesture start time. 617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DT_CMT_END_TIME, // Gesture end time. 627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DT_CMT_FLING_X, // Fling amount on the X (horizontal) direction. 637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DT_CMT_FLING_Y, // Fling amount on the Y (vertical) direction. 647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DT_CMT_FLING_STATE, // The state of fling gesture (whether the user just 657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // start flinging or that he/she taps down). 66eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DT_CMT_METRICS_TYPE, // Metrics type of the metrics gesture, which are 67eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // used to wrap interesting patterns that we would 68eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // like to track via the UMA system. 69eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DT_CMT_METRICS_DATA1, // Complementary data 1 of the metrics gesture. 70eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DT_CMT_METRICS_DATA2, // Complementary data 2 of the metrics gesture. 717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DT_CMT_FINGER_COUNT, // Finger counts in the current gesture. A same type 727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // of gesture can have very different meanings based 737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // on that (e.g. 2f scroll v.s. 3f swipe). 747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // End of CMT data types. 767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Beginning of touch data types. 777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Define the valuators following the Multi-touch Protocol. Used by 797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // touchscreen devices. 807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DT_TOUCH_MAJOR, // Length of the touch area. 817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DT_TOUCH_MINOR, // Width of the touch area. 827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DT_TOUCH_ORIENTATION, // Angle between the X-axis and the major axis of the 837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // touch area. 847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DT_TOUCH_PRESSURE, // Pressure of the touch contact. 857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) DT_TOUCH_POSITION_X, // Touch X position. 875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) DT_TOUCH_POSITION_Y, // Touch Y position. 885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // NOTE for XInput MT: 'Tracking ID' is provided in every touch event to 907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // track individual touch. 'Tracking ID' is an unsigned 32-bit value and 917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // is increased for each new touch. It will wrap back to 0 when reaching 927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // the numerical limit. 937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DT_TOUCH_TRACKING_ID, // ID of the touch point. 947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 957d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Kernel timestamp from touch screen (if available). 967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DT_TOUCH_RAW_TIMESTAMP, 977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // End of touch data types. 997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1007d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DT_LAST_ENTRY // This must come last. 1017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) }; 1027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Data struct to store extracted data from an input event. 1047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) typedef std::map<int, double> EventData; 1057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 106116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch static void CreateInstance(); 107116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 1087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // We use int because enums can be casted to ints but not vice versa. 1097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) static bool IsCMTDataType(const int type); 1107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) static bool IsTouchDataType(const int type); 1117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 112116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Returns the DeviceDataManagerX11 singleton. 113116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch static DeviceDataManagerX11* GetInstance(); 1147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 115f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Returns if XInput2 is available on the system. 116f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bool IsXInput2Available() const; 117f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Updates the list of devices. 1197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void UpdateDeviceList(Display* display); 1207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 121a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // For multitouch events we use slot number to distinguish touches from 122a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // different fingers. This function returns true if the associated slot 123a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // for |xiev| can be found and it is saved in |slot|, returns false if 124a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // no slot can be found. 125a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) bool GetSlotNumber(const XIDeviceEvent* xiev, int* slot); 126a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 1277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Get all event data in one pass. We extract only data types that we know 1287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // about (defined in enum DataType). The data is not processed (e.g. not 1297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // filled in by cached values) as in GetEventData. 1307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void GetEventRawData(const XEvent& xev, EventData* data); 1317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Get a datum of the specified type. Return true and the value 1337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // is updated if the data is found, false and value unchanged if the data is 1347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // not found. In the case of MT-B/XI2.2, the value can come from a previously 1357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // cached one (see the comment above last_seen_valuator_). 1367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool GetEventData(const XEvent& xev, const DataType type, double* value); 1377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Check if the event is an XI input event in the strict sense 1397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // (i.e. XIDeviceEvent). This rules out things like hierarchy changes, 1407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch /// device changes, property changes and so on. 1417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch bool IsXIDeviceEvent(const base::NativeEvent& native_event) const; 1427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Check if the event comes from touchpad devices. 1447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool IsTouchpadXInputEvent(const base::NativeEvent& native_event) const; 1457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Check if the event comes from devices running CMT driver or using 1477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // CMT valuators (e.g. mouses). Note that doesn't necessarily mean the event 1487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // is a CMT event (e.g. it could be a mouse pointer move). 1497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool IsCMTDeviceEvent(const base::NativeEvent& native_event) const; 1507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Check if the event is one of the CMT gesture events (scroll, fling, 1527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // metrics etc.). 1537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool IsCMTGestureEvent(const base::NativeEvent& native_event) const; 1547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Returns true if the event is of the specific type, false if not. 1567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool IsScrollEvent(const base::NativeEvent& native_event) const; 1577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool IsFlingEvent(const base::NativeEvent& native_event) const; 158eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool IsCMTMetricsEvent(const base::NativeEvent& native_event) const; 1597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Returns true if the event has CMT start/end timestamps. 1617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool HasGestureTimes(const base::NativeEvent& native_event) const; 1627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Extract data from a scroll event (a motion event with the necessary 1647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // valuators). User must first verify the event type with IsScrollEvent. 1657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Pointers shouldn't be NULL. 1667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void GetScrollOffsets(const base::NativeEvent& native_event, 1677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) float* x_offset, 1687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) float* y_offset, 1697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) float* x_offset_ordinal, 1707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) float* y_offset_ordinal, 1717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) int* finger_count); 1727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Extract data from a fling event. User must first verify the event type 1747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // with IsFlingEvent. Pointers shouldn't be NULL. 1757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void GetFlingData(const base::NativeEvent& native_event, 1767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) float* vx, 1777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) float* vy, 1787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) float* vx_ordinal, 1797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) float* vy_ordinal, 1807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool* is_cancel); 1817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 182eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Extract data from a CrOS metrics gesture event. User must first verify 183eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // the event type with IsCMTMetricsEvent. Pointers shouldn't be NULL. 184eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void GetMetricsData(const base::NativeEvent& native_event, 185eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GestureMetricsType* type, 186eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch float* data1, 187eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch float* data2); 188eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 18968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Returns the mapped button. 19068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) int GetMappedButton(int button); 19168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 19268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Updates button mapping. This is usually called when a MappingNotify event 19368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // is received. 19468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) void UpdateButtonMap(); 19568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 1967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Extract the start/end timestamps from CMT events. User must first verify 1977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // the event with HasGestureTimes. Pointers shouldn't be NULL. 1987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void GetGestureTimes(const base::NativeEvent& native_event, 1997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) double* start_time, 2007d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) double* end_time); 2017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 2027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Normalize the data value on deviceid to fall into [0, 1]. 2037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // *value = (*value - min_value_of_tp) / (max_value_of_tp - min_value_of_tp) 2047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Returns true and sets the normalized value in|value| if normalization is 2057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // successful. Returns false and |value| is unchanged otherwise. 2067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool NormalizeData(unsigned int deviceid, 2077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const DataType type, 2087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) double* value); 2097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 2107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Extract the range of the data type. Return true if the range is available 2117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // and written into min & max, false if the range is not available. 2127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool GetDataRange(unsigned int deviceid, 2137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const DataType type, 2147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) double* min, 2157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) double* max); 2167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 217a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Sets up relevant valuator informations for device ids in the device lists. 218a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // This function is only for test purpose. It does not query the X server for 219a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // the actual device info, but rather inits the relevant valuator structures 220a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // to have safe default values for testing. 221a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void SetDeviceListForTest(const std::vector<unsigned int>& touchscreen, 222a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const std::vector<unsigned int>& cmt_devices); 223a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 224a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void SetValuatorDataForTest(XIDeviceEvent* xievent, 225a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) DataType type, 226a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) double value); 227a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 228cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) bool TouchEventNeedsCalibrate(int touch_device_id) const; 229cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 2306e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Sets the keys which are still allowed on a disabled keyboard device. 2316e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) void SetDisabledKeyboardAllowedKeys( 2326e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) scoped_ptr<std::set<KeyboardCode> > excepted_keys); 2337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 234116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Disables and enables events from devices by device id. 235116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch void DisableDevice(unsigned int deviceid); 236116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch void EnableDevice(unsigned int deviceid); 237116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 238116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Returns true if |native_event| should be blocked. 239116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool IsEventBlocked(const base::NativeEvent& native_event); 240116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 241116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch private: 242116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch DeviceDataManagerX11(); 243116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual ~DeviceDataManagerX11(); 2447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 2457dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Initialize the XInput related system information. 2467dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch bool InitializeXInputInternal(); 2477dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 2487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Check if an XI event contains data of the specified type. 2497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool HasEventData(const XIDeviceEvent* xiev, const DataType type) const; 2507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 251a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void InitializeValuatorsForTest(int deviceid, 252a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) int start_valuator, 253a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) int end_valuator, 254a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) double min_value, 255a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) double max_value); 256a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 2577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch static const int kMaxXIEventType = XI_LASTEVENT + 1; 258a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) static const int kMaxSlotNum = 10; 2597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 2607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Major opcode for the XInput extension. Used to identify XInput events. 2617dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch int xi_opcode_; 2627dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 2637dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // A quick lookup table for determining if the XI event is an XIDeviceEvent. 2647dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch std::bitset<kMaxXIEventType> xi_device_event_types_; 2657dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 2667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // A quick lookup table for determining if events from the pointer device 2677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // should be processed. 2687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::bitset<kMaxDeviceNum> cmt_devices_; 2697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::bitset<kMaxDeviceNum> touchpads_; 2707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 271116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // A quick lookup table for determining if events from the XI device 272116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // should be blocked. 273116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch std::bitset<kMaxDeviceNum> blocked_devices_; 274116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 275116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // The set of keys allowed while the keyboard is blocked. 276116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch scoped_ptr<std::set<KeyboardCode> > blocked_keyboard_allowed_keys_; 277116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 2787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Number of valuators on the specific device. 2797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) int valuator_count_[kMaxDeviceNum]; 2807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 2817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Index table to find the valuator for DataType on the specific device 2827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // by valuator_lookup_[device_id][data_type]. 2837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::vector<int> valuator_lookup_[kMaxDeviceNum]; 2847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 2857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Index table to find the DataType for valuator on the specific device 2867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // by data_type_lookup_[device_id][valuator]. 2877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::vector<int> data_type_lookup_[kMaxDeviceNum]; 2887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 2897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Index table to find the min & max value of the Valuator on a specific 2907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // device. 2917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::vector<double> valuator_min_[kMaxDeviceNum]; 2927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::vector<double> valuator_max_[kMaxDeviceNum]; 2937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 2947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Table to keep track of the last seen value for the specified valuator for 295a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // a specified slot of a device. Defaults to 0 if the valuator for that slot 296a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // was not specified in an earlier event. With MT-B/XI2.2, valuators in an 297a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // XEvent are not reported if the values haven't changed from the previous 298a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // event. So it is necessary to remember these valuators so that chrome 299a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // doesn't think X/device doesn't know about the valuators. We currently 300a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // use this only on touchscreen devices. 301a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) std::vector<double> last_seen_valuator_[kMaxDeviceNum][kMaxSlotNum]; 3027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 3037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // X11 atoms cache. 3047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) X11AtomCache atom_cache_; 3057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 30668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) unsigned char button_map_[256]; 30768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) int button_map_count_; 30868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 309116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch DISALLOW_COPY_AND_ASSIGN(DeviceDataManagerX11); 3107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}; 3117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 3127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} // namespace ui 3137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 314116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#endif // UI_EVENTS_X_DEVICE_DATA_MANAGER_X11_H_ 315