Index: components/mus/public/cpp/input_devices/input_device_client.cc |
diff --git a/components/mus/public/cpp/input_devices/input_device_client.cc b/components/mus/public/cpp/input_devices/input_device_client.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cf8c45e29c3a84b882883b0262372ab585ef899c |
--- /dev/null |
+++ b/components/mus/public/cpp/input_devices/input_device_client.cc |
@@ -0,0 +1,102 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/mus/public/cpp/input_devices/input_device_client.h" |
+ |
+#include "base/logging.h" |
+ |
+namespace input_device { |
+ |
+InputDeviceClient::InputDeviceClient() : binding_(this) { |
+ InputDeviceManager::SetInstance(this); |
+} |
+ |
+InputDeviceClient::~InputDeviceClient() { |
+ InputDeviceManager::ClearInstance(); |
+} |
+ |
+void InputDeviceClient::Connect(mojom::InputDeviceServerPtr server) { |
+ DCHECK(server.is_bound()); |
+ |
+ // Add this class as an observer via Mojo IPC. |
+ server->AddObserver(binding_.CreateInterfacePtrAndBind()); |
+ binding_.set_connection_error_handler([]() { |
+ DLOG(ERROR) << "InputDeviceClient failed to bind observer pipe."; |
sadrul
2016/06/08 16:31:09
Note: the failure can happen after bind succeeds.
kylechar
2016/06/08 18:13:16
What's the idiomatic way to log connection errors
|
+ }); |
+} |
+ |
+void InputDeviceClient::OnKeyboardDeviceConfigurationChanged( |
+ mojo::Array<ui::InputDevice> devices) { |
+ keyboard_devices_ = devices.To<std::vector<ui::InputDevice>>(); |
+ FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, |
+ OnKeyboardDeviceConfigurationChanged()); |
+} |
+ |
+void InputDeviceClient::OnTouchscreenDeviceConfigurationChanged( |
+ mojo::Array<ui::TouchscreenDevice> devices) { |
+ touchscreen_devices_ = devices.To<std::vector<ui::TouchscreenDevice>>(); |
+ FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, |
+ OnTouchscreenDeviceConfigurationChanged()); |
+} |
+ |
+void InputDeviceClient::OnMouseDeviceConfigurationChanged( |
+ mojo::Array<ui::InputDevice> devices) { |
+ mouse_devices_ = devices.To<std::vector<ui::InputDevice>>(); |
+ FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, |
+ OnMouseDeviceConfigurationChanged()); |
+} |
+ |
+void InputDeviceClient::OnTouchpadDeviceConfigurationChanged( |
+ mojo::Array<ui::InputDevice> devices) { |
+ touchpad_devices_ = devices.To<std::vector<ui::InputDevice>>(); |
+ FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, |
+ OnTouchpadDeviceConfigurationChanged()); |
+} |
+ |
+void InputDeviceClient::OnDeviceListsComplete() { |
+ if (!device_lists_complete_) { |
+ device_lists_complete_ = true; |
+ FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, |
+ OnDeviceListsComplete()); |
+ } |
+} |
+ |
+void InputDeviceClient::AddObserver(ui::InputDeviceEventObserver* observer) { |
+ observers_.AddObserver(observer); |
+} |
+ |
+void InputDeviceClient::RemoveObserver(ui::InputDeviceEventObserver* observer) { |
+ observers_.RemoveObserver(observer); |
+} |
+ |
+const std::vector<ui::InputDevice>& InputDeviceClient::GetKeyboardDevices() |
+ const { |
+ return keyboard_devices_; |
+} |
+ |
+const std::vector<ui::TouchscreenDevice>& |
+InputDeviceClient::GetTouchscreenDevices() const { |
+ return touchscreen_devices_; |
+} |
+ |
+const std::vector<ui::InputDevice>& InputDeviceClient::GetMouseDevices() const { |
+ return mouse_devices_; |
+} |
+ |
+const std::vector<ui::InputDevice>& InputDeviceClient::GetTouchpadDevices() |
+ const { |
+ return touchpad_devices_; |
+} |
+ |
+bool InputDeviceClient::AreDeviceListsComplete() const { |
+ return device_lists_complete_; |
+} |
+ |
+bool InputDeviceClient::AreTouchscreensEnabled() const { |
+ // TODO(kylechar): This obviously isn't right. We either need to pass this |
+ // state around or modify the interface. |
+ return true; |
+} |
+ |
+} // namespace input_device |