Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "services/ui/public/cpp/input_devices/input_device_client.h" | 5 #include "services/ui/public/cpp/input_devices/input_device_client.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 namespace ui { | 9 namespace ui { |
| 10 | 10 |
| 11 InputDeviceClient::InputDeviceClient() : binding_(this) { | 11 InputDeviceClient::InputDeviceClient() : InputDeviceClient(true) {} |
| 12 InputDeviceManager::SetInstance(this); | |
| 13 } | |
| 14 | 12 |
| 15 InputDeviceClient::~InputDeviceClient() { | 13 InputDeviceClient::~InputDeviceClient() { |
| 16 InputDeviceManager::ClearInstance(); | 14 if (is_input_device_manager_) |
| 15 InputDeviceManager::ClearInstance(); | |
| 17 } | 16 } |
| 18 | 17 |
| 19 void InputDeviceClient::Connect(mojom::InputDeviceServerPtr server) { | 18 void InputDeviceClient::Connect(mojom::InputDeviceServerPtr server) { |
| 20 DCHECK(server.is_bound()); | 19 DCHECK(server.is_bound()); |
| 20 server->AddObserver(GetIntefacePtr()); | |
| 21 } | |
| 21 | 22 |
| 22 server->AddObserver(binding_.CreateInterfacePtrAndBind()); | 23 const std::vector<ui::InputDevice>& InputDeviceClient::GetKeyboardDevices() |
| 24 const { | |
| 25 return keyboard_devices_; | |
| 26 } | |
| 27 | |
| 28 const std::vector<ui::TouchscreenDevice>& | |
| 29 InputDeviceClient::GetTouchscreenDevices() const { | |
| 30 return touchscreen_devices_; | |
| 31 } | |
| 32 | |
| 33 const std::vector<ui::InputDevice>& InputDeviceClient::GetMouseDevices() const { | |
| 34 return mouse_devices_; | |
| 35 } | |
| 36 | |
| 37 const std::vector<ui::InputDevice>& InputDeviceClient::GetTouchpadDevices() | |
| 38 const { | |
| 39 return touchpad_devices_; | |
| 40 } | |
| 41 | |
| 42 bool InputDeviceClient::AreDeviceListsComplete() const { | |
| 43 return device_lists_complete_; | |
| 44 } | |
| 45 | |
| 46 bool InputDeviceClient::AreTouchscreensEnabled() const { | |
| 47 // TODO(kylechar): This obviously isn't right. We either need to pass this | |
| 48 // state around or modify the interface. | |
| 49 return true; | |
| 50 } | |
| 51 | |
| 52 void InputDeviceClient::AddObserver(ui::InputDeviceEventObserver* observer) { | |
| 53 observers_.AddObserver(observer); | |
| 54 } | |
| 55 | |
| 56 void InputDeviceClient::RemoveObserver(ui::InputDeviceEventObserver* observer) { | |
| 57 observers_.RemoveObserver(observer); | |
| 58 } | |
| 59 | |
| 60 InputDeviceClient::InputDeviceClient(bool is_input_device_manager) | |
| 61 : binding_(this) { | |
|
sadrul
2016/08/02 15:16:14
Initialize |is_input_device_manager_| here
kylechar
2016/08/02 17:46:57
Done.
| |
| 62 if (is_input_device_manager) { | |
| 63 InputDeviceManager::SetInstance(this); | |
| 64 is_input_device_manager_ = true; | |
| 65 } | |
| 66 } | |
| 67 | |
| 68 mojom::InputDeviceObserverMojoPtr InputDeviceClient::GetIntefacePtr() { | |
| 69 return binding_.CreateInterfacePtrAndBind(); | |
| 23 } | 70 } |
| 24 | 71 |
| 25 void InputDeviceClient::OnKeyboardDeviceConfigurationChanged( | 72 void InputDeviceClient::OnKeyboardDeviceConfigurationChanged( |
| 26 const std::vector<ui::InputDevice>& devices) { | 73 const std::vector<ui::InputDevice>& devices) { |
| 27 keyboard_devices_ = devices; | 74 keyboard_devices_ = devices; |
| 28 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, | 75 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, |
| 29 OnKeyboardDeviceConfigurationChanged()); | 76 OnKeyboardDeviceConfigurationChanged()); |
| 30 } | 77 } |
| 31 | 78 |
| 32 void InputDeviceClient::OnTouchscreenDeviceConfigurationChanged( | 79 void InputDeviceClient::OnTouchscreenDeviceConfigurationChanged( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 if (!touchpad_devices.empty()) | 112 if (!touchpad_devices.empty()) |
| 66 OnTouchpadDeviceConfigurationChanged(touchpad_devices); | 113 OnTouchpadDeviceConfigurationChanged(touchpad_devices); |
| 67 | 114 |
| 68 if (!device_lists_complete_) { | 115 if (!device_lists_complete_) { |
| 69 device_lists_complete_ = true; | 116 device_lists_complete_ = true; |
| 70 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, | 117 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, |
| 71 OnDeviceListsComplete()); | 118 OnDeviceListsComplete()); |
| 72 } | 119 } |
| 73 } | 120 } |
| 74 | 121 |
| 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 ui | 122 } // namespace ui |
| OLD | NEW |