Chromium Code Reviews| Index: components/mus/public/cpp/input_devices/lib/input_device_client.cc |
| diff --git a/components/mus/public/cpp/input_devices/lib/input_device_client.cc b/components/mus/public/cpp/input_devices/lib/input_device_client.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..48a1f52cf97709b901c4f206ec3aacc7cff8ccd9 |
| --- /dev/null |
| +++ b/components/mus/public/cpp/input_devices/lib/input_device_client.cc |
| @@ -0,0 +1,128 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
|
Ben Goodger (Google)
2016/06/02 19:35:18
we're going to get rid of lib subdirs... so just p
kylechar
2016/06/03 14:35:57
Done. Will upload a new patch after rebasing later
|
| +// 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/bind.h" |
| +#include "base/files/file_path.h" |
| +#include "base/logging.h" |
| +#include "base/strings/string_util.h" |
| +#include "base/strings/stringprintf.h" |
| + |
| +namespace input_device { |
| + |
| +namespace { |
| + |
| +// TODO(kylechar): Debug, remove eventually. |
| +template <class DeviceType> |
| +void PrintDevices(std::string title, const DeviceType& devices) { |
| + std::vector<std::string> device_strings; |
| + device_strings.push_back(base::StringPrintf("%s devices.size()=%zu", |
| + title.c_str(), devices.size())); |
| + for (const auto& device : devices) { |
| + device_strings.push_back(device.ToString()); |
| + } |
| + LOG(ERROR) << base::JoinString(device_strings, ", "); |
| +} |
| + |
| +} // namespace |
| + |
| +InputDeviceClient::InputDeviceClient() : binding_(this) { |
| + InputDeviceManager::SetInstance(this); |
| +} |
| + |
| +InputDeviceClient::~InputDeviceClient() { |
| + InputDeviceManager::ClearInstance(); |
| +} |
| + |
| +void InputDeviceClient::Connect(shell::Connector* connector) { |
|
Ben Goodger (Google)
2016/06/02 19:35:18
rather than passing in a connector, can you requir
kylechar
2016/06/03 14:35:57
Yeah, that's absolutely possible. I'm just getting
|
| + mojom::InputDeviceServerPtr service; |
| + connector->ConnectToInterface("mojo:mus", &service); |
| + |
| + // Add this class as an observer via Mojo IPC. |
| + service->AddObserver(binding_.CreateInterfacePtrAndBind()); |
| + binding_.set_connection_error_handler([]() { |
| + LOG(ERROR) << "InputDeviceClient failed to bind observer pipe."; |
| + }); |
| +} |
| + |
| +void InputDeviceClient::OnKeyboardDeviceConfigurationChanged( |
| + mojo::Array<ui::InputDevice> devices) { |
| + keyboard_devices_ = devices.To<std::vector<ui::InputDevice>>(); |
| + PrintDevices("UpdateKeyboardDevices", keyboard_devices_); |
| + FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, |
| + OnKeyboardDeviceConfigurationChanged()); |
| +} |
| + |
| +void InputDeviceClient::OnTouchscreenDeviceConfigurationChanged( |
| + mojo::Array<ui::TouchscreenDevice> devices) { |
| + touchscreen_devices_ = devices.To<std::vector<ui::TouchscreenDevice>>(); |
| + PrintDevices("UpdateTouchscreenDevices", touchscreen_devices_); |
| + FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, |
| + OnTouchscreenDeviceConfigurationChanged()); |
| +} |
| + |
| +void InputDeviceClient::OnMouseDeviceConfigurationChanged( |
| + mojo::Array<ui::InputDevice> devices) { |
| + mouse_devices_ = devices.To<std::vector<ui::InputDevice>>(); |
| + PrintDevices("UpdateMouseDevices", mouse_devices_); |
| + FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, |
| + OnMouseDeviceConfigurationChanged()); |
| +} |
| + |
| +void InputDeviceClient::OnTouchpadDeviceConfigurationChanged( |
| + mojo::Array<ui::InputDevice> devices) { |
| + touchpad_devices_ = devices.To<std::vector<ui::InputDevice>>(); |
| + PrintDevices("UpdateTouchpadDevices", touchpad_devices_); |
| + FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, |
| + OnTouchpadDeviceConfigurationChanged()); |
| +} |
| + |
| +void InputDeviceClient::OnDeviceListsComplete() { |
| + if (!device_lists_complete_) { |
| + LOG(ERROR) << "InputDeviceClient::OnDeviceListsComplete"; |
| + 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 |