Add ICU message format support
[chromium-blink-merge.git] / ui / events / devices / x11 / touch_factory_x11.h
blobc2e95802deea66f3cf39312efff3e0a744e3c3f8
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_EVENTS_DEVICES_X11_TOUCH_FACTORY_X11_H_
6 #define UI_EVENTS_DEVICES_X11_TOUCH_FACTORY_X11_H_
8 #include <bitset>
9 #include <map>
10 #include <set>
11 #include <utility>
12 #include <vector>
14 #include "ui/events/devices/events_devices_export.h"
15 #include "ui/gfx/sequential_id_generator.h"
17 template <typename T> struct DefaultSingletonTraits;
19 typedef unsigned long Cursor;
20 typedef unsigned long Window;
21 typedef struct _XDisplay Display;
22 typedef union _XEvent XEvent;
24 namespace ui {
26 // Functions related to determining touch devices.
27 class EVENTS_DEVICES_EXPORT TouchFactory {
28 private:
29 TouchFactory();
30 ~TouchFactory();
32 public:
33 // Returns the TouchFactory singleton.
34 static TouchFactory* GetInstance();
36 // Sets the touch devices from the command line.
37 static void SetTouchDeviceListFromCommandLine();
39 // Updates the list of devices.
40 void UpdateDeviceList(Display* display);
42 // Checks whether an XI2 event should be processed or not (i.e. if the event
43 // originated from a device we are interested in).
44 bool ShouldProcessXI2Event(XEvent* xevent);
46 // Setup an X Window for XInput2 events.
47 void SetupXI2ForXWindow(::Window xid);
49 // Keeps a list of touch devices so that it is possible to determine if a
50 // pointer event is a touch-event or a mouse-event. The list is reset each
51 // time this is called.
52 void SetTouchDeviceList(const std::vector<int>& devices);
54 // Is the device ID valid?
55 bool IsValidDevice(int deviceid) const;
57 // Is the device a touch-device?
58 bool IsTouchDevice(int deviceid) const;
60 // Is the device a real multi-touch-device? (see doc. for |touch_device_list_|
61 // below for more explanation.)
62 bool IsMultiTouchDevice(int deviceid) const;
64 // Tries to find an existing slot ID mapping to tracking ID. Returns true
65 // if the slot is found and it is saved in |slot|, false if no such slot
66 // can be found.
67 bool QuerySlotForTrackingID(uint32 tracking_id, int* slot);
69 // Tries to find an existing slot ID mapping to tracking ID. If there
70 // isn't one already, allocates a new slot ID and sets up the mapping.
71 int GetSlotForTrackingID(uint32 tracking_id);
73 // Releases the slot ID mapping to tracking ID.
74 void ReleaseSlotForTrackingID(uint32 tracking_id);
76 // Whether any touch device is currently present and enabled.
77 bool IsTouchDevicePresent();
79 // Pairs of <vendor id, product id> of external touch screens.
80 const std::set<std::pair<int, int> >& GetTouchscreenIds() const {
81 return touchscreen_ids_;
84 // Resets the TouchFactory singleton.
85 void ResetForTest();
87 // Sets up the device id in the list |devices| as multi-touch capable
88 // devices and enables touch events processing. This function is only
89 // for test purpose, and it does not query from X server.
90 void SetTouchDeviceForTest(const std::vector<int>& devices);
92 // Sets up the device id in the list |devices| as pointer devices.
93 // This function is only for test purpose, and it does not query from
94 // X server.
95 void SetPointerDeviceForTest(const std::vector<int>& devices);
97 private:
98 // Requirement for Singleton
99 friend struct DefaultSingletonTraits<TouchFactory>;
101 void CacheTouchscreenIds(int id);
103 // NOTE: To keep track of touch devices, we currently maintain a lookup table
104 // to quickly decide if a device is a touch device or not. We also maintain a
105 // list of the touch devices. Ideally, there will be only one touch device,
106 // and instead of having the lookup table and the list, there will be a single
107 // identifier for the touch device. This can be completed after enough testing
108 // on real touch devices.
110 static const int kMaxDeviceNum = 128;
112 // A quick lookup table for determining if events from the pointer device
113 // should be processed.
114 std::bitset<kMaxDeviceNum> pointer_device_lookup_;
116 // A quick lookup table for determining if a device is a touch device.
117 std::bitset<kMaxDeviceNum> touch_device_lookup_;
119 // Indicates whether touch events are explicitly disabled.
120 bool touch_events_disabled_;
122 // The list of touch devices. For testing/debugging purposes, a single-pointer
123 // device (mouse or touch screen without sufficient X/driver support for MT)
124 // can sometimes be treated as a touch device. The key in the map represents
125 // the device id, and the value represents if the device is multi-touch
126 // capable.
127 std::map<int, bool> touch_device_list_;
129 // Touch screen <vid, pid>s.
130 std::set<std::pair<int, int> > touchscreen_ids_;
132 // Device ID of the virtual core keyboard.
133 int virtual_core_keyboard_device_;
135 SequentialIDGenerator id_generator_;
137 // Associate each device ID with its master device ID.
138 std::map<int, int> device_master_id_list_;
140 DISALLOW_COPY_AND_ASSIGN(TouchFactory);
143 } // namespace ui
145 #endif // UI_EVENTS_DEVICES_X11_TOUCH_FACTORY_X11_H_