OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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. | |
4 | |
5 #include "components/mus/public/cpp/input_devices/input_device_client.h" | |
6 | |
7 #include "base/logging.h" | |
8 | |
9 namespace input_device { | |
10 | |
11 InputDeviceClient::InputDeviceClient() : binding_(this) { | |
12 InputDeviceManager::SetInstance(this); | |
13 } | |
14 | |
15 InputDeviceClient::~InputDeviceClient() { | |
16 InputDeviceManager::ClearInstance(); | |
17 } | |
18 | |
19 void InputDeviceClient::Connect(mojom::InputDeviceServerPtr server) { | |
20 DCHECK(server.is_bound()); | |
21 | |
22 // Add this class as an observer via Mojo IPC. | |
sadrul
2016/06/10 18:01:49
The comment isn't necessary
kylechar
2016/06/10 19:29:31
Done.
| |
23 server->AddObserver(binding_.CreateInterfacePtrAndBind()); | |
24 } | |
25 | |
26 void InputDeviceClient::OnKeyboardDeviceConfigurationChanged( | |
27 mojo::Array<ui::InputDevice> devices) { | |
28 keyboard_devices_ = devices.To<std::vector<ui::InputDevice>>(); | |
29 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, | |
30 OnKeyboardDeviceConfigurationChanged()); | |
31 } | |
32 | |
33 void InputDeviceClient::OnTouchscreenDeviceConfigurationChanged( | |
34 mojo::Array<ui::TouchscreenDevice> devices) { | |
35 touchscreen_devices_ = devices.To<std::vector<ui::TouchscreenDevice>>(); | |
36 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, | |
37 OnTouchscreenDeviceConfigurationChanged()); | |
38 } | |
39 | |
40 void InputDeviceClient::OnMouseDeviceConfigurationChanged( | |
41 mojo::Array<ui::InputDevice> devices) { | |
42 mouse_devices_ = devices.To<std::vector<ui::InputDevice>>(); | |
43 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, | |
44 OnMouseDeviceConfigurationChanged()); | |
45 } | |
46 | |
47 void InputDeviceClient::OnTouchpadDeviceConfigurationChanged( | |
48 mojo::Array<ui::InputDevice> devices) { | |
49 touchpad_devices_ = devices.To<std::vector<ui::InputDevice>>(); | |
50 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, | |
51 OnTouchpadDeviceConfigurationChanged()); | |
52 } | |
53 | |
54 void InputDeviceClient::OnDeviceListsComplete( | |
55 mojo::Array<ui::InputDevice> keyboard_devices, | |
sadrul
2016/06/10 18:01:49
It may be nice to have struct-traits take care of
kylechar
2016/06/10 19:29:31
That would be ideal but I don't think Mojo support
| |
56 mojo::Array<ui::TouchscreenDevice> touchscreen_devices, | |
57 mojo::Array<ui::InputDevice> mouse_devices, | |
58 mojo::Array<ui::InputDevice> touchpad_devices) { | |
59 // Update the cached device lists if the received list isn't empty. | |
60 if (!keyboard_devices.empty()) | |
61 OnKeyboardDeviceConfigurationChanged(std::move(keyboard_devices)); | |
62 if (!touchscreen_devices.empty()) | |
63 OnTouchscreenDeviceConfigurationChanged(std::move(touchscreen_devices)); | |
64 if (!mouse_devices.empty()) | |
65 OnMouseDeviceConfigurationChanged(std::move(mouse_devices)); | |
66 if (!touchpad_devices.empty()) | |
67 OnTouchpadDeviceConfigurationChanged(std::move(touchpad_devices)); | |
68 | |
69 if (!device_lists_complete_) { | |
70 device_lists_complete_ = true; | |
71 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, | |
72 OnDeviceListsComplete()); | |
73 } | |
74 } | |
75 | |
76 void InputDeviceClient::AddObserver(ui::InputDeviceEventObserver* observer) { | |
77 observers_.AddObserver(observer); | |
78 } | |
79 | |
80 void InputDeviceClient::RemoveObserver(ui::InputDeviceEventObserver* observer) { | |
81 observers_.RemoveObserver(observer); | |
82 } | |
83 | |
84 const std::vector<ui::InputDevice>& InputDeviceClient::GetKeyboardDevices() | |
85 const { | |
86 return keyboard_devices_; | |
87 } | |
88 | |
89 const std::vector<ui::TouchscreenDevice>& | |
90 InputDeviceClient::GetTouchscreenDevices() const { | |
91 return touchscreen_devices_; | |
92 } | |
93 | |
94 const std::vector<ui::InputDevice>& InputDeviceClient::GetMouseDevices() const { | |
95 return mouse_devices_; | |
96 } | |
97 | |
98 const std::vector<ui::InputDevice>& InputDeviceClient::GetTouchpadDevices() | |
99 const { | |
100 return touchpad_devices_; | |
101 } | |
102 | |
103 bool InputDeviceClient::AreDeviceListsComplete() const { | |
104 return device_lists_complete_; | |
105 } | |
106 | |
107 bool InputDeviceClient::AreTouchscreensEnabled() const { | |
108 // TODO(kylechar): This obviously isn't right. We either need to pass this | |
109 // state around or modify the interface. | |
110 return true; | |
111 } | |
112 | |
113 } // namespace input_device | |
OLD | NEW |