Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / ui / events / devices / device_data_manager.h
blobf3782ebd02629af8341bc470a5341dc72ec5a5a6
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 namespace test {
24 class DeviceDataManagerTestAPI;
25 } // namespace test
27 class InputDeviceEventObserver;
29 // Keeps track of device mappings and event transformations.
30 class EVENTS_DEVICES_EXPORT DeviceDataManager
31 : public DeviceHotplugEventObserver {
32 public:
33 static const int kMaxDeviceNum = 128;
34 ~DeviceDataManager() override;
36 static void CreateInstance();
37 static void DeleteInstance();
38 static DeviceDataManager* GetInstance();
39 static bool HasInstance();
41 void ClearTouchDeviceAssociations();
42 void UpdateTouchInfoForDisplay(int64_t target_display_id,
43 int touch_device_id,
44 const gfx::Transform& touch_transformer);
45 void ApplyTouchTransformer(int touch_device_id, float* x, float* y);
47 // Gets the display that touches from |touch_device_id| should be sent to.
48 int64_t GetTargetDisplayForTouchDevice(int touch_device_id) const;
50 void UpdateTouchRadiusScale(int touch_device_id, double scale);
51 void ApplyTouchRadiusScale(int touch_device_id, double* radius);
53 const std::vector<TouchscreenDevice>& touchscreen_devices() const {
54 return touchscreen_devices_;
57 const std::vector<KeyboardDevice>& keyboard_devices() const {
58 return keyboard_devices_;
61 bool device_lists_complete() const { return device_lists_complete_; }
63 void AddObserver(InputDeviceEventObserver* observer);
64 void RemoveObserver(InputDeviceEventObserver* observer);
66 protected:
67 DeviceDataManager();
69 static DeviceDataManager* instance();
71 static void set_instance(DeviceDataManager* instance);
73 // DeviceHotplugEventObserver:
74 void OnTouchscreenDevicesUpdated(
75 const std::vector<TouchscreenDevice>& devices) override;
76 void OnKeyboardDevicesUpdated(
77 const std::vector<KeyboardDevice>& devices) override;
78 void OnMouseDevicesUpdated(
79 const std::vector<InputDevice>& devices) override;
80 void OnTouchpadDevicesUpdated(
81 const std::vector<InputDevice>& devices) override;
82 void OnDeviceListsComplete() override;
84 private:
85 friend class test::DeviceDataManagerTestAPI;
87 static DeviceDataManager* instance_;
89 bool IsTouchDeviceIdValid(int touch_device_id) const;
91 void NotifyObserversTouchscreenDeviceConfigurationChanged();
92 void NotifyObserversKeyboardDeviceConfigurationChanged();
93 void NotifyObserversMouseDeviceConfigurationChanged();
94 void NotifyObserversTouchpadDeviceConfigurationChanged();
95 void NotifyObserversDeviceListsComplete();
97 double touch_radius_scale_map_[kMaxDeviceNum];
99 // Index table to find the target display id for a touch device.
100 int64_t touch_device_to_target_display_map_[kMaxDeviceNum];
101 // Index table to find the TouchTransformer for a touch device.
102 gfx::Transform touch_device_transformer_map_[kMaxDeviceNum];
104 std::vector<TouchscreenDevice> touchscreen_devices_;
105 std::vector<KeyboardDevice> keyboard_devices_;
106 std::vector<InputDevice> mouse_devices_;
107 std::vector<InputDevice> touchpad_devices_;
108 bool device_lists_complete_ = false;
110 base::ObserverList<InputDeviceEventObserver> observers_;
112 DISALLOW_COPY_AND_ASSIGN(DeviceDataManager);
115 } // namespace ui
117 #endif // UI_EVENTS_DEVICES_DEVICE_DATA_MANAGER_H_