1 // Copyright 2014 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_DEVICE_DATA_MANAGER_H_
6 #define UI_EVENTS_DEVICES_DEVICE_DATA_MANAGER_H_
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list.h"
15 #include "ui/events/devices/device_hotplug_event_observer.h"
16 #include "ui/events/devices/events_devices_export.h"
17 #include "ui/events/devices/keyboard_device.h"
18 #include "ui/events/devices/touchscreen_device.h"
19 #include "ui/gfx/transform.h"
23 class InputDeviceEventObserver
;
25 // Keeps track of device mappings and event transformations.
26 class EVENTS_DEVICES_EXPORT DeviceDataManager
27 : public DeviceHotplugEventObserver
{
29 static const int kMaxDeviceNum
= 128;
30 ~DeviceDataManager() override
;
32 static void CreateInstance();
33 static DeviceDataManager
* GetInstance();
34 static bool HasInstance();
36 void ClearTouchDeviceAssociations();
37 void UpdateTouchInfoForDisplay(int64_t target_display_id
,
39 const gfx::Transform
& touch_transformer
);
40 void ApplyTouchTransformer(int touch_device_id
, float* x
, float* y
);
42 // Gets the display that touches from |touch_device_id| should be sent to.
43 int64_t GetTargetDisplayForTouchDevice(int touch_device_id
) const;
45 void UpdateTouchRadiusScale(int touch_device_id
, double scale
);
46 void ApplyTouchRadiusScale(int touch_device_id
, double* radius
);
48 const std::vector
<TouchscreenDevice
>& touchscreen_devices() const {
49 return touchscreen_devices_
;
52 const std::vector
<KeyboardDevice
>& keyboard_devices() const {
53 return keyboard_devices_
;
56 bool device_lists_complete() const { return device_lists_complete_
; }
58 void AddObserver(InputDeviceEventObserver
* observer
);
59 void RemoveObserver(InputDeviceEventObserver
* observer
);
64 static DeviceDataManager
* instance();
66 // DeviceHotplugEventObserver:
67 void OnTouchscreenDevicesUpdated(
68 const std::vector
<TouchscreenDevice
>& devices
) override
;
69 void OnKeyboardDevicesUpdated(
70 const std::vector
<KeyboardDevice
>& devices
) override
;
71 void OnMouseDevicesUpdated(
72 const std::vector
<InputDevice
>& devices
) override
;
73 void OnTouchpadDevicesUpdated(
74 const std::vector
<InputDevice
>& devices
) override
;
75 void OnDeviceListsComplete() override
;
78 static DeviceDataManager
* instance_
;
80 bool IsTouchDeviceIdValid(int touch_device_id
) const;
82 double touch_radius_scale_map_
[kMaxDeviceNum
];
84 // Index table to find the target display id for a touch device.
85 int64_t touch_device_to_target_display_map_
[kMaxDeviceNum
];
86 // Index table to find the TouchTransformer for a touch device.
87 gfx::Transform touch_device_transformer_map_
[kMaxDeviceNum
];
89 std::vector
<TouchscreenDevice
> touchscreen_devices_
;
90 std::vector
<KeyboardDevice
> keyboard_devices_
;
91 std::vector
<InputDevice
> mouse_devices_
;
92 std::vector
<InputDevice
> touchpad_devices_
;
93 bool device_lists_complete_
= false;
95 base::ObserverList
<InputDeviceEventObserver
> observers_
;
97 DISALLOW_COPY_AND_ASSIGN(DeviceDataManager
);
102 #endif // UI_EVENTS_DEVICES_DEVICE_DATA_MANAGER_H_