Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: components/mus/input_devices/input_device_server.cc

Issue 2119963002: Move mus to //services/ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/mus/input_devices/input_device_server.h ('k') | components/mus/main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/input_device_server.h"
6
7 #include <utility>
8 #include <vector>
9
10 #include "mojo/public/cpp/bindings/array.h"
11 #include "ui/events/devices/input_device.h"
12 #include "ui/events/devices/touchscreen_device.h"
13
14 namespace mus {
15
16 InputDeviceServer::InputDeviceServer() {}
17
18 InputDeviceServer::~InputDeviceServer() {
19 if (manager_ && ui::DeviceDataManager::HasInstance()) {
20 manager_->RemoveObserver(this);
21 manager_ = nullptr;
22 }
23 }
24
25 void InputDeviceServer::RegisterAsObserver() {
26 if (!manager_ && ui::DeviceDataManager::HasInstance()) {
27 manager_ = ui::DeviceDataManager::GetInstance();
28 manager_->AddObserver(this);
29 }
30 }
31
32 bool InputDeviceServer::IsRegisteredAsObserver() const {
33 return manager_ != nullptr;
34 }
35
36 void InputDeviceServer::AddInterface(shell::Connection* connection) {
37 DCHECK(manager_);
38 connection->AddInterface<mojom::InputDeviceServer>(this);
39 }
40
41 void InputDeviceServer::AddObserver(
42 mojom::InputDeviceObserverMojoPtr observer) {
43 // We only want to send this message once, so we need to check to make sure
44 // device lists are actually complete before sending it to a new observer.
45 if (manager_->AreDeviceListsComplete())
46 SendDeviceListsComplete(observer.get());
47 observers_.AddPtr(std::move(observer));
48 }
49
50 void InputDeviceServer::OnKeyboardDeviceConfigurationChanged() {
51 if (!manager_->AreDeviceListsComplete())
52 return;
53
54 auto& devices = manager_->GetKeyboardDevices();
55 observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
56 observer->OnKeyboardDeviceConfigurationChanged(devices);
57 });
58 }
59
60 void InputDeviceServer::OnTouchscreenDeviceConfigurationChanged() {
61 if (!manager_->AreDeviceListsComplete())
62 return;
63
64 auto& devices = manager_->GetTouchscreenDevices();
65 observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
66 observer->OnTouchscreenDeviceConfigurationChanged(devices);
67 });
68 }
69
70 void InputDeviceServer::OnMouseDeviceConfigurationChanged() {
71 if (!manager_->AreDeviceListsComplete())
72 return;
73
74 auto& devices = manager_->GetMouseDevices();
75 observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
76 observer->OnMouseDeviceConfigurationChanged(devices);
77 });
78 }
79
80 void InputDeviceServer::OnTouchpadDeviceConfigurationChanged() {
81 if (!manager_->AreDeviceListsComplete())
82 return;
83
84 auto& devices = manager_->GetTouchpadDevices();
85 observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
86 observer->OnTouchpadDeviceConfigurationChanged(devices);
87 });
88 }
89
90 void InputDeviceServer::OnDeviceListsComplete() {
91 observers_.ForAllPtrs([this](mojom::InputDeviceObserverMojo* observer) {
92 SendDeviceListsComplete(observer);
93 });
94 }
95
96 void InputDeviceServer::SendDeviceListsComplete(
97 mojom::InputDeviceObserverMojo* observer) {
98 DCHECK(manager_->AreDeviceListsComplete());
99
100 observer->OnDeviceListsComplete(
101 manager_->GetKeyboardDevices(), manager_->GetTouchscreenDevices(),
102 manager_->GetMouseDevices(), manager_->GetTouchpadDevices());
103 }
104
105 void InputDeviceServer::Create(shell::Connection* connection,
106 mojom::InputDeviceServerRequest request) {
107 bindings_.AddBinding(this, std::move(request));
108 }
109
110 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/input_devices/input_device_server.h ('k') | components/mus/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698