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, |
| 19 const ui::InputDevice& b) { |
| 20 return a.id == b.id; |
| 21 } |
| 22 |
| 23 } // namespace |
| 24 |
16 // static | 25 // static |
17 DeviceDataManager* DeviceDataManager::instance_ = NULL; | 26 DeviceDataManager* DeviceDataManager::instance_ = NULL; |
18 | 27 |
19 DeviceDataManager::DeviceDataManager() { | 28 DeviceDataManager::DeviceDataManager() { |
20 CHECK(!instance_) << "Can not create multiple instances of DeviceDataManager"; | 29 CHECK(!instance_) << "Can not create multiple instances of DeviceDataManager"; |
21 instance_ = this; | 30 instance_ = this; |
22 | 31 |
23 base::AtExitManager::RegisterTask( | 32 base::AtExitManager::RegisterTask( |
24 base::Bind(&base::DeletePointer<DeviceDataManager>, this)); | 33 base::Bind(&base::DeletePointer<DeviceDataManager>, this)); |
25 | 34 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 } | 113 } |
105 | 114 |
106 int64_t DeviceDataManager::GetDisplayForTouchDevice(int touch_device_id) const { | 115 int64_t DeviceDataManager::GetDisplayForTouchDevice(int touch_device_id) const { |
107 if (IsTouchDeviceIdValid(touch_device_id)) | 116 if (IsTouchDeviceIdValid(touch_device_id)) |
108 return touch_device_to_display_map_[touch_device_id]; | 117 return touch_device_to_display_map_[touch_device_id]; |
109 return gfx::Display::kInvalidDisplayID; | 118 return gfx::Display::kInvalidDisplayID; |
110 } | 119 } |
111 | 120 |
112 void DeviceDataManager::OnTouchscreenDevicesUpdated( | 121 void DeviceDataManager::OnTouchscreenDevicesUpdated( |
113 const std::vector<TouchscreenDevice>& devices) { | 122 const std::vector<TouchscreenDevice>& devices) { |
| 123 if (devices.size() == touchscreen_devices_.size() && |
| 124 std::equal(devices.begin(), devices.end(), |
| 125 touchscreen_devices_.begin(), InputDeviceEquals)) { |
| 126 return; |
| 127 } |
114 touchscreen_devices_ = devices; | 128 touchscreen_devices_ = devices; |
| 129 FOR_EACH_OBSERVER(InputDeviceEventObserver, |
| 130 observers_, |
| 131 OnTouchscreenDeviceConfigurationChanged()); |
| 132 } |
115 | 133 |
| 134 void DeviceDataManager::OnKeyboardDevicesUpdated( |
| 135 const std::vector<KeyboardDevice>& devices) { |
| 136 if (devices.size() == keyboard_devices_.size() && |
| 137 std::equal(devices.begin(), devices.end(), |
| 138 keyboard_devices_.begin(), InputDeviceEquals)) { |
| 139 return; |
| 140 } |
| 141 keyboard_devices_ = devices; |
116 FOR_EACH_OBSERVER(InputDeviceEventObserver, | 142 FOR_EACH_OBSERVER(InputDeviceEventObserver, |
117 observers_, | 143 observers_, |
118 OnInputDeviceConfigurationChanged()); | 144 OnKeyboardDeviceConfigurationChanged()); |
119 } | 145 } |
120 | 146 |
121 void DeviceDataManager::AddObserver(InputDeviceEventObserver* observer) { | 147 void DeviceDataManager::AddObserver(InputDeviceEventObserver* observer) { |
122 observers_.AddObserver(observer); | 148 observers_.AddObserver(observer); |
123 } | 149 } |
124 | 150 |
125 void DeviceDataManager::RemoveObserver(InputDeviceEventObserver* observer) { | 151 void DeviceDataManager::RemoveObserver(InputDeviceEventObserver* observer) { |
126 observers_.RemoveObserver(observer); | 152 observers_.RemoveObserver(observer); |
127 } | 153 } |
128 | 154 |
129 } // namespace ui | 155 } // namespace ui |
OLD | NEW |