| 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 mus { | |
| 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 server->AddObserver(binding_.CreateInterfacePtrAndBind()); | |
| 23 } | |
| 24 | |
| 25 void InputDeviceClient::OnKeyboardDeviceConfigurationChanged( | |
| 26 mojo::Array<ui::InputDevice> devices) { | |
| 27 keyboard_devices_ = devices.To<std::vector<ui::InputDevice>>(); | |
| 28 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, | |
| 29 OnKeyboardDeviceConfigurationChanged()); | |
| 30 } | |
| 31 | |
| 32 void InputDeviceClient::OnTouchscreenDeviceConfigurationChanged( | |
| 33 mojo::Array<ui::TouchscreenDevice> devices) { | |
| 34 touchscreen_devices_ = devices.To<std::vector<ui::TouchscreenDevice>>(); | |
| 35 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, | |
| 36 OnTouchscreenDeviceConfigurationChanged()); | |
| 37 } | |
| 38 | |
| 39 void InputDeviceClient::OnMouseDeviceConfigurationChanged( | |
| 40 mojo::Array<ui::InputDevice> devices) { | |
| 41 mouse_devices_ = devices.To<std::vector<ui::InputDevice>>(); | |
| 42 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, | |
| 43 OnMouseDeviceConfigurationChanged()); | |
| 44 } | |
| 45 | |
| 46 void InputDeviceClient::OnTouchpadDeviceConfigurationChanged( | |
| 47 mojo::Array<ui::InputDevice> devices) { | |
| 48 touchpad_devices_ = devices.To<std::vector<ui::InputDevice>>(); | |
| 49 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, | |
| 50 OnTouchpadDeviceConfigurationChanged()); | |
| 51 } | |
| 52 | |
| 53 void InputDeviceClient::OnDeviceListsComplete( | |
| 54 mojo::Array<ui::InputDevice> keyboard_devices, | |
| 55 mojo::Array<ui::TouchscreenDevice> touchscreen_devices, | |
| 56 mojo::Array<ui::InputDevice> mouse_devices, | |
| 57 mojo::Array<ui::InputDevice> touchpad_devices) { | |
| 58 // Update the cached device lists if the received list isn't empty. | |
| 59 if (!keyboard_devices.empty()) | |
| 60 OnKeyboardDeviceConfigurationChanged(std::move(keyboard_devices)); | |
| 61 if (!touchscreen_devices.empty()) | |
| 62 OnTouchscreenDeviceConfigurationChanged(std::move(touchscreen_devices)); | |
| 63 if (!mouse_devices.empty()) | |
| 64 OnMouseDeviceConfigurationChanged(std::move(mouse_devices)); | |
| 65 if (!touchpad_devices.empty()) | |
| 66 OnTouchpadDeviceConfigurationChanged(std::move(touchpad_devices)); | |
| 67 | |
| 68 if (!device_lists_complete_) { | |
| 69 device_lists_complete_ = true; | |
| 70 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, | |
| 71 OnDeviceListsComplete()); | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 void InputDeviceClient::AddObserver(ui::InputDeviceEventObserver* observer) { | |
| 76 observers_.AddObserver(observer); | |
| 77 } | |
| 78 | |
| 79 void InputDeviceClient::RemoveObserver(ui::InputDeviceEventObserver* observer) { | |
| 80 observers_.RemoveObserver(observer); | |
| 81 } | |
| 82 | |
| 83 const std::vector<ui::InputDevice>& InputDeviceClient::GetKeyboardDevices() | |
| 84 const { | |
| 85 return keyboard_devices_; | |
| 86 } | |
| 87 | |
| 88 const std::vector<ui::TouchscreenDevice>& | |
| 89 InputDeviceClient::GetTouchscreenDevices() const { | |
| 90 return touchscreen_devices_; | |
| 91 } | |
| 92 | |
| 93 const std::vector<ui::InputDevice>& InputDeviceClient::GetMouseDevices() const { | |
| 94 return mouse_devices_; | |
| 95 } | |
| 96 | |
| 97 const std::vector<ui::InputDevice>& InputDeviceClient::GetTouchpadDevices() | |
| 98 const { | |
| 99 return touchpad_devices_; | |
| 100 } | |
| 101 | |
| 102 bool InputDeviceClient::AreDeviceListsComplete() const { | |
| 103 return device_lists_complete_; | |
| 104 } | |
| 105 | |
| 106 bool InputDeviceClient::AreTouchscreensEnabled() const { | |
| 107 // TODO(kylechar): This obviously isn't right. We either need to pass this | |
| 108 // state around or modify the interface. | |
| 109 return true; | |
| 110 } | |
| 111 | |
| 112 } // namespace mus | |
| OLD | NEW |