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 TouchscreenEquals(const ui::TouchscreenDevice& a, | |
19 const ui::TouchscreenDevice& b) { | |
20 return a.id == b.id; | |
21 } | |
22 | |
23 bool KeyboardEquals(const ui::KeyboardDevice& a, | |
24 const ui::KeyboardDevice& b) { | |
25 return a.id == b.id; | |
26 } | |
27 | |
28 } // namespace | |
29 | |
16 // static | 30 // static |
17 DeviceDataManager* DeviceDataManager::instance_ = NULL; | 31 DeviceDataManager* DeviceDataManager::instance_ = NULL; |
18 | 32 |
19 DeviceDataManager::DeviceDataManager() { | 33 DeviceDataManager::DeviceDataManager() { |
20 CHECK(!instance_) << "Can not create multiple instances of DeviceDataManager"; | 34 CHECK(!instance_) << "Can not create multiple instances of DeviceDataManager"; |
21 instance_ = this; | 35 instance_ = this; |
22 | 36 |
23 base::AtExitManager::RegisterTask( | 37 base::AtExitManager::RegisterTask( |
24 base::Bind(&base::DeletePointer<DeviceDataManager>, this)); | 38 base::Bind(&base::DeletePointer<DeviceDataManager>, this)); |
25 | 39 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 } | 118 } |
105 | 119 |
106 int64_t DeviceDataManager::GetDisplayForTouchDevice(int touch_device_id) const { | 120 int64_t DeviceDataManager::GetDisplayForTouchDevice(int touch_device_id) const { |
107 if (IsTouchDeviceIdValid(touch_device_id)) | 121 if (IsTouchDeviceIdValid(touch_device_id)) |
108 return touch_device_to_display_map_[touch_device_id]; | 122 return touch_device_to_display_map_[touch_device_id]; |
109 return gfx::Display::kInvalidDisplayID; | 123 return gfx::Display::kInvalidDisplayID; |
110 } | 124 } |
111 | 125 |
112 void DeviceDataManager::OnTouchscreenDevicesUpdated( | 126 void DeviceDataManager::OnTouchscreenDevicesUpdated( |
113 const std::vector<TouchscreenDevice>& devices) { | 127 const std::vector<TouchscreenDevice>& devices) { |
114 touchscreen_devices_ = devices; | 128 if (devices.size() != touchscreen_devices_.size() || |
129 std::equal(devices.begin(), devices.end(), | |
flackr
2014/10/04 00:35:12
Did you mean !std::equal(...?
rsadam
2014/10/04 18:46:27
Done.
| |
130 touchscreen_devices_.begin(), TouchscreenEquals)) { | |
flackr
2014/10/04 00:35:12
nit: indent 4 more (to show it's wrapped from std:
rsadam
2014/10/04 18:46:27
Done.
| |
131 touchscreen_devices_ = devices; | |
flackr
2014/10/04 00:35:12
Better yet, early return if the device list looks
rsadam
2014/10/04 18:46:27
Done.
| |
132 FOR_EACH_OBSERVER(InputDeviceEventObserver, | |
133 observers_, | |
134 OnTouchscreenDeviceConfigurationChanged()); | |
135 } | |
136 } | |
115 | 137 |
116 FOR_EACH_OBSERVER(InputDeviceEventObserver, | 138 void DeviceDataManager::OnKeyboardDevicesUpdated( |
139 const std::vector<KeyboardDevice>& devices) { | |
140 if (devices.size() != keyboard_devices_.size() || | |
141 std::equal(devices.begin(), devices.end(), | |
flackr
2014/10/04 00:35:12
ditto, !std::equal?
rsadam
2014/10/04 18:46:27
Done.
| |
142 keyboard_devices_.begin(), KeyboardEquals)) { | |
flackr
2014/10/04 00:35:12
ditto, indent 4 more or to just past '(' above.
rsadam
2014/10/04 18:46:27
Done.
| |
143 keyboard_devices_ = devices; | |
144 FOR_EACH_OBSERVER(InputDeviceEventObserver, | |
117 observers_, | 145 observers_, |
118 OnInputDeviceConfigurationChanged()); | 146 OnKeyboardDeviceConfigurationChanged()); |
147 } | |
119 } | 148 } |
120 | 149 |
121 void DeviceDataManager::AddObserver(InputDeviceEventObserver* observer) { | 150 void DeviceDataManager::AddObserver(InputDeviceEventObserver* observer) { |
122 observers_.AddObserver(observer); | 151 observers_.AddObserver(observer); |
123 } | 152 } |
124 | 153 |
125 void DeviceDataManager::RemoveObserver(InputDeviceEventObserver* observer) { | 154 void DeviceDataManager::RemoveObserver(InputDeviceEventObserver* observer) { |
126 observers_.RemoveObserver(observer); | 155 observers_.RemoveObserver(observer); |
127 } | 156 } |
128 | 157 |
129 } // namespace ui | 158 } // namespace ui |
OLD | NEW |