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
,
38 unsigned int touch_device_id
,
39 const gfx::Transform
& touch_transformer
);
40 void ApplyTouchTransformer(unsigned 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(unsigned int touch_device_id
) const;
45 void UpdateTouchRadiusScale(unsigned int touch_device_id
, double scale
);
46 void ApplyTouchRadiusScale(unsigned 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 void AddObserver(InputDeviceEventObserver
* observer
);
57 void RemoveObserver(InputDeviceEventObserver
* observer
);
62 static DeviceDataManager
* instance();
64 // DeviceHotplugEventObserver:
65 void OnTouchscreenDevicesUpdated(
66 const std::vector
<TouchscreenDevice
>& devices
) override
;
67 void OnKeyboardDevicesUpdated(
68 const std::vector
<KeyboardDevice
>& devices
) override
;
69 void OnMouseDevicesUpdated(
70 const std::vector
<InputDevice
>& devices
) override
;
71 void OnTouchpadDevicesUpdated(
72 const std::vector
<InputDevice
>& devices
) override
;
75 static DeviceDataManager
* instance_
;
77 bool IsTouchDeviceIdValid(unsigned int touch_device_id
) const;
79 double touch_radius_scale_map_
[kMaxDeviceNum
];
81 // Index table to find the target display id for a touch device.
82 int64_t touch_device_to_target_display_map_
[kMaxDeviceNum
];
83 // Index table to find the TouchTransformer for a touch device.
84 gfx::Transform touch_device_transformer_map_
[kMaxDeviceNum
];
86 std::vector
<TouchscreenDevice
> touchscreen_devices_
;
87 std::vector
<KeyboardDevice
> keyboard_devices_
;
88 std::vector
<InputDevice
> mouse_devices_
;
89 std::vector
<InputDevice
> touchpad_devices_
;
91 ObserverList
<InputDeviceEventObserver
> observers_
;
93 DISALLOW_COPY_AND_ASSIGN(DeviceDataManager
);
98 #endif // UI_EVENTS_DEVICES_DEVICE_DATA_MANAGER_H_