| Index: components/mus/input_devices/input_device_server.cc
|
| diff --git a/components/mus/input_devices/input_device_server.cc b/components/mus/input_devices/input_device_server.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f028a40d27b4c713aae7306e153b832fb33a0733
|
| --- /dev/null
|
| +++ b/components/mus/input_devices/input_device_server.cc
|
| @@ -0,0 +1,119 @@
|
| +// 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/input_devices/input_device_server.h"
|
| +
|
| +#include <utility>
|
| +#include <vector>
|
| +
|
| +#include "mojo/public/cpp/bindings/array.h"
|
| +#include "ui/events/devices/input_device.h"
|
| +#include "ui/events/devices/touchscreen_device.h"
|
| +
|
| +namespace input_device {
|
| +
|
| +InputDeviceServer::InputDeviceServer() {}
|
| +
|
| +InputDeviceServer::~InputDeviceServer() {
|
| + if (manager_ && ui::DeviceDataManager::HasInstance()) {
|
| + manager_->RemoveObserver(this);
|
| + manager_ = nullptr;
|
| + }
|
| +}
|
| +
|
| +void InputDeviceServer::RegisterAsObserver() {
|
| + if (!manager_) {
|
| + manager_ = ui::DeviceDataManager::GetInstance();
|
| + manager_->AddObserver(this);
|
| + }
|
| +}
|
| +
|
| +void InputDeviceServer::RegisterInterface(shell::Connection* connection) {
|
| + DCHECK(manager_);
|
| + connection->AddInterface<mojom::InputDeviceServer>(this);
|
| +}
|
| +
|
| +void InputDeviceServer::Create(shell::Connection* connection,
|
| + mojom::InputDeviceServerRequest request) {
|
| + bindings_.AddBinding(this, std::move(request));
|
| +}
|
| +
|
| +void InputDeviceServer::AddObserver(
|
| + mojom::InputDeviceObserverMojoPtr observer) {
|
| + SendInputDeviceState(observer.get());
|
| + observers_.AddPtr(std::move(observer));
|
| +}
|
| +
|
| +void InputDeviceServer::OnKeyboardDeviceConfigurationChanged() {
|
| + auto& devices = manager_->GetKeyboardDevices();
|
| + observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
|
| + observer->OnKeyboardDeviceConfigurationChanged(
|
| + mojo::Array<ui::InputDevice>::From(devices));
|
| + });
|
| +}
|
| +
|
| +void InputDeviceServer::OnTouchscreenDeviceConfigurationChanged() {
|
| + auto& devices = manager_->GetTouchscreenDevices();
|
| + observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
|
| + observer->OnTouchscreenDeviceConfigurationChanged(
|
| + mojo::Array<ui::TouchscreenDevice>::From(devices));
|
| + });
|
| +}
|
| +
|
| +void InputDeviceServer::OnMouseDeviceConfigurationChanged() {
|
| + auto& devices = manager_->GetMouseDevices();
|
| + observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
|
| + observer->OnMouseDeviceConfigurationChanged(
|
| + mojo::Array<ui::InputDevice>::From(devices));
|
| + });
|
| +}
|
| +
|
| +void InputDeviceServer::OnTouchpadDeviceConfigurationChanged() {
|
| + auto& devices = manager_->GetTouchpadDevices();
|
| + observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
|
| + observer->OnTouchpadDeviceConfigurationChanged(
|
| + mojo::Array<ui::InputDevice>::From(devices));
|
| + });
|
| +}
|
| +
|
| +void InputDeviceServer::OnDeviceListsComplete() {
|
| + observers_.ForAllPtrs([](mojom::InputDeviceObserverMojo* observer) {
|
| + observer->OnDeviceListsComplete();
|
| + });
|
| +}
|
| +
|
| +void InputDeviceServer::SendInputDeviceState(
|
| + mojom::InputDeviceObserverMojo* observer) {
|
| + auto& keyboard_devices = manager_->GetKeyboardDevices();
|
| + if (!keyboard_devices.empty()) {
|
| + observer->OnKeyboardDeviceConfigurationChanged(
|
| + mojo::Array<ui::InputDevice>::From(keyboard_devices));
|
| + }
|
| +
|
| + auto& touchscreen_devices = manager_->GetTouchscreenDevices();
|
| + if (!touchscreen_devices.empty()) {
|
| + observer->OnTouchscreenDeviceConfigurationChanged(
|
| + mojo::Array<ui::TouchscreenDevice>::From(touchscreen_devices));
|
| + }
|
| +
|
| + auto& mouse_devices = manager_->GetMouseDevices();
|
| + if (!mouse_devices.empty()) {
|
| + observer->OnMouseDeviceConfigurationChanged(
|
| + mojo::Array<ui::InputDevice>::From(mouse_devices));
|
| + }
|
| +
|
| + auto& touchpad_devices = manager_->GetTouchpadDevices();
|
| + if (!touchpad_devices.empty()) {
|
| + observer->OnTouchpadDeviceConfigurationChanged(
|
| + mojo::Array<ui::InputDevice>::From(touchpad_devices));
|
| + }
|
| +
|
| + // We only want to send this message once, so we need to check to make sure
|
| + // device lists are actually complete before sending it to a new observer.
|
| + if (manager_->AreDeviceListsComplete()) {
|
| + observer->OnDeviceListsComplete();
|
| + }
|
| +}
|
| +
|
| +} // namespace input_device
|
|
|