Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / ui / events / devices / device_data_manager.h
blob7d7a00941d8a64bf12bca49562691d909ddf8a62
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_
8 #include <stdint.h>
10 #include <vector>
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"
21 namespace ui {
23 class InputDeviceEventObserver;
25 // Keeps track of device mappings and event transformations.
26 class EVENTS_DEVICES_EXPORT DeviceDataManager
27 : public DeviceHotplugEventObserver {
28 public:
29 static const int kMaxDeviceNum = 128;
30 ~DeviceDataManager() override;
32 static void CreateInstance();
33 static DeviceDataManager* GetInstance();
34 static bool HasInstance();
36 void ClearTouchTransformerRecord();
37 void UpdateTouchInfoForDisplay(int64_t 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);
41 int64_t GetDisplayForTouchDevice(unsigned int touch_device_id) const;
43 void UpdateTouchRadiusScale(unsigned int touch_device_id, double scale);
44 void ApplyTouchRadiusScale(unsigned int touch_device_id, double* radius);
46 const std::vector<TouchscreenDevice>& touchscreen_devices() const {
47 return touchscreen_devices_;
50 const std::vector<KeyboardDevice>& keyboard_devices() const {
51 return keyboard_devices_;
54 void AddObserver(InputDeviceEventObserver* observer);
55 void RemoveObserver(InputDeviceEventObserver* observer);
57 protected:
58 DeviceDataManager();
60 static DeviceDataManager* instance();
62 // DeviceHotplugEventObserver:
63 void OnTouchscreenDevicesUpdated(
64 const std::vector<TouchscreenDevice>& devices) override;
65 void OnKeyboardDevicesUpdated(
66 const std::vector<KeyboardDevice>& devices) override;
68 private:
69 static DeviceDataManager* instance_;
71 bool IsTouchDeviceIdValid(unsigned int touch_device_id) const;
73 double touch_radius_scale_map_[kMaxDeviceNum];
75 // Table to keep track of which display id is mapped to which touch device.
76 int64_t touch_device_to_display_map_[kMaxDeviceNum];
77 // Index table to find the TouchTransformer for a touch device.
78 gfx::Transform touch_device_transformer_map_[kMaxDeviceNum];
80 std::vector<TouchscreenDevice> touchscreen_devices_;
81 std::vector<KeyboardDevice> keyboard_devices_;
83 ObserverList<InputDeviceEventObserver> observers_;
85 DISALLOW_COPY_AND_ASSIGN(DeviceDataManager);
88 } // namespace ui
90 #endif // UI_EVENTS_DEVICES_DEVICE_DATA_MANAGER_H_