OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/events/device_data_manager.h" | 5 #include "ui/events/device_data_manager.h" |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ui/events/input_device_event_observer.h" | 10 #include "ui/events/input_device_event_observer.h" |
11 #include "ui/gfx/display.h" | 11 #include "ui/gfx/display.h" |
12 #include "ui/gfx/geometry/point3_f.h" | 12 #include "ui/gfx/geometry/point3_f.h" |
13 | 13 |
14 namespace ui { | 14 namespace ui { |
15 | 15 |
| 16 namespace { |
| 17 |
| 18 bool InputDeviceEquals(const ui::InputDevice& a, const ui::InputDevice& b) { |
| 19 return a.id == b.id; |
| 20 } |
| 21 |
| 22 } // namespace |
| 23 |
16 // static | 24 // static |
17 DeviceDataManager* DeviceDataManager::instance_ = NULL; | 25 DeviceDataManager* DeviceDataManager::instance_ = NULL; |
18 | 26 |
19 DeviceDataManager::DeviceDataManager() { | 27 DeviceDataManager::DeviceDataManager() { |
20 CHECK(!instance_) << "Can not create multiple instances of DeviceDataManager"; | 28 CHECK(!instance_) << "Can not create multiple instances of DeviceDataManager"; |
21 instance_ = this; | 29 instance_ = this; |
22 | 30 |
23 base::AtExitManager::RegisterTask( | 31 base::AtExitManager::RegisterTask( |
24 base::Bind(&base::DeletePointer<DeviceDataManager>, this)); | 32 base::Bind(&base::DeletePointer<DeviceDataManager>, this)); |
25 | 33 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 } | 65 } |
58 | 66 |
59 void DeviceDataManager::ClearTouchTransformerRecord() { | 67 void DeviceDataManager::ClearTouchTransformerRecord() { |
60 for (int i = 0; i < kMaxDeviceNum; i++) { | 68 for (int i = 0; i < kMaxDeviceNum; i++) { |
61 touch_device_transformer_map_[i] = gfx::Transform(); | 69 touch_device_transformer_map_[i] = gfx::Transform(); |
62 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; | 70 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; |
63 touch_radius_scale_map_[i] = 1.0; | 71 touch_radius_scale_map_[i] = 1.0; |
64 } | 72 } |
65 } | 73 } |
66 | 74 |
67 bool DeviceDataManager::IsTouchDeviceIdValid(int touch_device_id) const { | 75 bool DeviceDataManager::IsTouchDeviceIdValid( |
| 76 unsigned int touch_device_id) const { |
68 return (touch_device_id > 0 && touch_device_id < kMaxDeviceNum); | 77 return (touch_device_id > 0 && touch_device_id < kMaxDeviceNum); |
69 } | 78 } |
70 | 79 |
71 void DeviceDataManager::UpdateTouchInfoForDisplay( | 80 void DeviceDataManager::UpdateTouchInfoForDisplay( |
72 int64_t display_id, | 81 int64_t display_id, |
73 int touch_device_id, | 82 unsigned int touch_device_id, |
74 const gfx::Transform& touch_transformer) { | 83 const gfx::Transform& touch_transformer) { |
75 if (IsTouchDeviceIdValid(touch_device_id)) { | 84 if (IsTouchDeviceIdValid(touch_device_id)) { |
76 touch_device_to_display_map_[touch_device_id] = display_id; | 85 touch_device_to_display_map_[touch_device_id] = display_id; |
77 touch_device_transformer_map_[touch_device_id] = touch_transformer; | 86 touch_device_transformer_map_[touch_device_id] = touch_transformer; |
78 } | 87 } |
79 } | 88 } |
80 | 89 |
81 void DeviceDataManager::UpdateTouchRadiusScale(int touch_device_id, | 90 void DeviceDataManager::UpdateTouchRadiusScale(unsigned int touch_device_id, |
82 double scale) { | 91 double scale) { |
83 if (IsTouchDeviceIdValid(touch_device_id)) | 92 if (IsTouchDeviceIdValid(touch_device_id)) |
84 touch_radius_scale_map_[touch_device_id] = scale; | 93 touch_radius_scale_map_[touch_device_id] = scale; |
85 } | 94 } |
86 | 95 |
87 void DeviceDataManager::ApplyTouchRadiusScale(int touch_device_id, | 96 void DeviceDataManager::ApplyTouchRadiusScale(unsigned int touch_device_id, |
88 double* radius) { | 97 double* radius) { |
89 if (IsTouchDeviceIdValid(touch_device_id)) | 98 if (IsTouchDeviceIdValid(touch_device_id)) |
90 *radius = (*radius) * touch_radius_scale_map_[touch_device_id]; | 99 *radius = (*radius) * touch_radius_scale_map_[touch_device_id]; |
91 } | 100 } |
92 | 101 |
93 void DeviceDataManager::ApplyTouchTransformer(int touch_device_id, | 102 void DeviceDataManager::ApplyTouchTransformer(unsigned int touch_device_id, |
94 float* x, | 103 float* x, |
95 float* y) { | 104 float* y) { |
96 if (IsTouchDeviceIdValid(touch_device_id)) { | 105 if (IsTouchDeviceIdValid(touch_device_id)) { |
97 gfx::Point3F point(*x, *y, 0.0); | 106 gfx::Point3F point(*x, *y, 0.0); |
98 const gfx::Transform& trans = | 107 const gfx::Transform& trans = |
99 touch_device_transformer_map_[touch_device_id]; | 108 touch_device_transformer_map_[touch_device_id]; |
100 trans.TransformPoint(&point); | 109 trans.TransformPoint(&point); |
101 *x = point.x(); | 110 *x = point.x(); |
102 *y = point.y(); | 111 *y = point.y(); |
103 } | 112 } |
104 } | 113 } |
105 | 114 |
106 int64_t DeviceDataManager::GetDisplayForTouchDevice(int touch_device_id) const { | 115 int64_t DeviceDataManager::GetDisplayForTouchDevice( |
| 116 unsigned int touch_device_id) const { |
107 if (IsTouchDeviceIdValid(touch_device_id)) | 117 if (IsTouchDeviceIdValid(touch_device_id)) |
108 return touch_device_to_display_map_[touch_device_id]; | 118 return touch_device_to_display_map_[touch_device_id]; |
109 return gfx::Display::kInvalidDisplayID; | 119 return gfx::Display::kInvalidDisplayID; |
110 } | 120 } |
111 | 121 |
112 void DeviceDataManager::OnTouchscreenDevicesUpdated( | 122 void DeviceDataManager::OnTouchscreenDevicesUpdated( |
113 const std::vector<TouchscreenDevice>& devices) { | 123 const std::vector<TouchscreenDevice>& devices) { |
| 124 if (devices.size() == touchscreen_devices_.size() && |
| 125 std::equal(devices.begin(), |
| 126 devices.end(), |
| 127 touchscreen_devices_.begin(), |
| 128 InputDeviceEquals)) { |
| 129 return; |
| 130 } |
114 touchscreen_devices_ = devices; | 131 touchscreen_devices_ = devices; |
115 | |
116 FOR_EACH_OBSERVER(InputDeviceEventObserver, | 132 FOR_EACH_OBSERVER(InputDeviceEventObserver, |
117 observers_, | 133 observers_, |
118 OnInputDeviceConfigurationChanged()); | 134 OnTouchscreenDeviceConfigurationChanged()); |
| 135 } |
| 136 |
| 137 void DeviceDataManager::OnKeyboardDevicesUpdated( |
| 138 const std::vector<KeyboardDevice>& devices) { |
| 139 if (devices.size() == keyboard_devices_.size() && |
| 140 std::equal(devices.begin(), |
| 141 devices.end(), |
| 142 keyboard_devices_.begin(), |
| 143 InputDeviceEquals)) { |
| 144 return; |
| 145 } |
| 146 keyboard_devices_ = devices; |
| 147 FOR_EACH_OBSERVER(InputDeviceEventObserver, |
| 148 observers_, |
| 149 OnKeyboardDeviceConfigurationChanged()); |
119 } | 150 } |
120 | 151 |
121 void DeviceDataManager::AddObserver(InputDeviceEventObserver* observer) { | 152 void DeviceDataManager::AddObserver(InputDeviceEventObserver* observer) { |
122 observers_.AddObserver(observer); | 153 observers_.AddObserver(observer); |
123 } | 154 } |
124 | 155 |
125 void DeviceDataManager::RemoveObserver(InputDeviceEventObserver* observer) { | 156 void DeviceDataManager::RemoveObserver(InputDeviceEventObserver* observer) { |
126 observers_.RemoveObserver(observer); | 157 observers_.RemoveObserver(observer); |
127 } | 158 } |
128 | 159 |
129 } // namespace ui | 160 } // namespace ui |
OLD | NEW |