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/input_devices/public/cpp/input_device_client.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" |
| 9 #include "base/logging.h" |
| 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/stringprintf.h" |
| 12 |
| 13 namespace input_device { |
| 14 |
| 15 namespace { |
| 16 |
| 17 // TODO(kylechar): Debug, remove eventually. |
| 18 template <class DeviceType> |
| 19 void PrintDevices(std::string title, const DeviceType& devices) { |
| 20 std::vector<std::string> device_strings; |
| 21 device_strings.push_back(base::StringPrintf("%s devices.size()=%zu", |
| 22 title.c_str(), devices.size())); |
| 23 for (const auto& device : devices) { |
| 24 device_strings.push_back(device.ToString()); |
| 25 } |
| 26 LOG(ERROR) << base::JoinString(device_strings, ", "); |
| 27 } |
| 28 |
| 29 } // namespace |
| 30 |
| 31 InputDeviceClient::InputDeviceClient() : binding_(this) { |
| 32 InputDeviceManager::SetInstance(this); |
| 33 } |
| 34 |
| 35 InputDeviceClient::~InputDeviceClient() { |
| 36 InputDeviceManager::ClearInstance(); |
| 37 } |
| 38 |
| 39 void InputDeviceClient::Connect(shell::Connector* connector) { |
| 40 mojom::InputDeviceServerPtr service; |
| 41 connector->ConnectToInterface("mojo:mus", &service); |
| 42 |
| 43 // Add this class as an observer via Mojo IPC. |
| 44 service->AddObserver(binding_.CreateInterfacePtrAndBind()); |
| 45 } |
| 46 |
| 47 void InputDeviceClient::OnKeyboardDeviceConfigurationChanged( |
| 48 mojo::Array<ui::InputDevice> devices) { |
| 49 keyboard_devices_ = devices.To<std::vector<ui::InputDevice>>(); |
| 50 PrintDevices("UpdateKeyboardDevices", keyboard_devices_); |
| 51 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, |
| 52 OnKeyboardDeviceConfigurationChanged()); |
| 53 } |
| 54 |
| 55 void InputDeviceClient::OnTouchscreenDeviceConfigurationChanged( |
| 56 mojo::Array<ui::TouchscreenDevice> devices) { |
| 57 touchscreen_devices_ = devices.To<std::vector<ui::TouchscreenDevice>>(); |
| 58 PrintDevices("UpdateTouchscreenDevices", touchscreen_devices_); |
| 59 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, |
| 60 OnTouchscreenDeviceConfigurationChanged()); |
| 61 } |
| 62 |
| 63 void InputDeviceClient::OnMouseDeviceConfigurationChanged( |
| 64 mojo::Array<ui::InputDevice> devices) { |
| 65 mouse_devices_ = devices.To<std::vector<ui::InputDevice>>(); |
| 66 PrintDevices("UpdateMouseDevices", mouse_devices_); |
| 67 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, |
| 68 OnMouseDeviceConfigurationChanged()); |
| 69 } |
| 70 |
| 71 void InputDeviceClient::OnTouchpadDeviceConfigurationChanged( |
| 72 mojo::Array<ui::InputDevice> devices) { |
| 73 touchpad_devices_ = devices.To<std::vector<ui::InputDevice>>(); |
| 74 PrintDevices("UpdateTouchpadDevices", touchpad_devices_); |
| 75 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, |
| 76 OnTouchpadDeviceConfigurationChanged()); |
| 77 } |
| 78 |
| 79 void InputDeviceClient::OnDeviceListsComplete() { |
| 80 if (!device_lists_complete_) { |
| 81 LOG(ERROR) << "InputDeviceClient::OnDeviceListsComplete"; |
| 82 device_lists_complete_ = true; |
| 83 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, |
| 84 OnDeviceListsComplete()); |
| 85 } |
| 86 } |
| 87 |
| 88 void InputDeviceClient::AddObserver(ui::InputDeviceEventObserver* observer) { |
| 89 observers_.AddObserver(observer); |
| 90 } |
| 91 |
| 92 void InputDeviceClient::RemoveObserver(ui::InputDeviceEventObserver* observer) { |
| 93 observers_.RemoveObserver(observer); |
| 94 } |
| 95 |
| 96 const std::vector<ui::InputDevice>& InputDeviceClient::keyboard_devices() |
| 97 const { |
| 98 return keyboard_devices_; |
| 99 } |
| 100 |
| 101 const std::vector<ui::TouchscreenDevice>& |
| 102 InputDeviceClient::touchscreen_devices() const { |
| 103 return touchscreen_devices_; |
| 104 } |
| 105 |
| 106 const std::vector<ui::InputDevice>& InputDeviceClient::mouse_devices() const { |
| 107 return mouse_devices_; |
| 108 } |
| 109 |
| 110 const std::vector<ui::InputDevice>& InputDeviceClient::touchpad_devices() |
| 111 const { |
| 112 return touchpad_devices_; |
| 113 } |
| 114 |
| 115 bool InputDeviceClient::device_lists_complete() const { |
| 116 return device_lists_complete_; |
| 117 } |
| 118 |
| 119 bool InputDeviceClient::AreTouchscreensEnabled() const { |
| 120 // TODO(kylechar): This obviously isn't right. We either need to pass this |
| 121 // state around or modify the interface. |
| 122 return true; |
| 123 } |
| 124 |
| 125 } // namespace input_device |
OLD | NEW |