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 #ifndef COMPONENTS_MUS_PUBLIC_CPP_INPUT_DEVICES_INPUT_DEVICE_CLIENT_H_ |
| 6 #define COMPONENTS_MUS_PUBLIC_CPP_INPUT_DEVICES_INPUT_DEVICE_CLIENT_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/observer_list.h" |
| 12 #include "components/mus/public/interfaces/input_devices/input_devices.mojom.h" |
| 13 #include "mojo/public/cpp/bindings/array.h" |
| 14 #include "mojo/public/cpp/bindings/binding.h" |
| 15 #include "services/shell/public/cpp/connector.h" |
| 16 #include "ui/events/devices/input_device.h" |
| 17 #include "ui/events/devices/input_device_event_observer.h" |
| 18 #include "ui/events/devices/input_device_manager.h" |
| 19 #include "ui/events/devices/touchscreen_device.h" |
| 20 |
| 21 namespace input_device { |
| 22 |
| 23 // Allows in-process client code to register as a ui:::InputDeviceEventObserver |
| 24 // and get information about input-devices. InputDeviceClient itself acts as an |
| 25 // InputDeviceObserverMojo and registers to get updates from InputDeviceServer. |
| 26 // Essentially, InputDeviceClient forwards input-device events and caches |
| 27 // input-device state. |
| 28 // |
| 29 // One instance of InputDeviceClient should be instantiated in each process that |
| 30 // doesn't have a DeviceDataManager. The Mojo app should call Connect() with the |
| 31 // mojo shell connector to register as an observer with mus. Client code should |
| 32 // use InputDeviceManager and doesn't need to be aware it's not dealing with |
| 33 // DeviceDataManager directly. |
| 34 class InputDeviceClient : public mojom::InputDeviceObserverMojo, |
| 35 public ui::InputDeviceManager { |
| 36 public: |
| 37 InputDeviceClient(); |
| 38 ~InputDeviceClient() override; |
| 39 |
| 40 // Connects to mojo:mus as an observer on InputDeviceServer to receive input |
| 41 // device updates. |
| 42 void Connect(shell::Connector* connector); |
| 43 |
| 44 // mojom::InputDeviceObserverMojo: |
| 45 void OnKeyboardDeviceConfigurationChanged( |
| 46 mojo::Array<ui::InputDevice> devices) override; |
| 47 void OnTouchscreenDeviceConfigurationChanged( |
| 48 mojo::Array<ui::TouchscreenDevice> devices) override; |
| 49 void OnMouseDeviceConfigurationChanged( |
| 50 mojo::Array<ui::InputDevice> devices) override; |
| 51 void OnTouchpadDeviceConfigurationChanged( |
| 52 mojo::Array<ui::InputDevice> devices) override; |
| 53 void OnDeviceListsComplete() override; |
| 54 |
| 55 // ui::InputDeviceManager: |
| 56 void AddObserver(ui::InputDeviceEventObserver* observer) override; |
| 57 void RemoveObserver(ui::InputDeviceEventObserver* observer) override; |
| 58 const std::vector<ui::InputDevice>& GetKeyboardDevices() const override; |
| 59 const std::vector<ui::TouchscreenDevice>& GetTouchscreenDevices() |
| 60 const override; |
| 61 const std::vector<ui::InputDevice>& GetMouseDevices() const override; |
| 62 const std::vector<ui::InputDevice>& GetTouchpadDevices() const override; |
| 63 bool AreDeviceListsComplete() const override; |
| 64 bool AreTouchscreensEnabled() const override; |
| 65 |
| 66 private: |
| 67 mojo::Binding<mojom::InputDeviceObserverMojo> binding_; |
| 68 |
| 69 // Holds the list of input devices and signal that we have received the lists |
| 70 // after initialization. |
| 71 std::vector<ui::InputDevice> keyboard_devices_; |
| 72 std::vector<ui::TouchscreenDevice> touchscreen_devices_; |
| 73 std::vector<ui::InputDevice> mouse_devices_; |
| 74 std::vector<ui::InputDevice> touchpad_devices_; |
| 75 bool device_lists_complete_ = false; |
| 76 |
| 77 // List of observers in this process. |
| 78 base::ObserverList<ui::InputDeviceEventObserver> observers_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(InputDeviceClient); |
| 81 }; |
| 82 |
| 83 } // namespace input_device |
| 84 |
| 85 #endif // COMPONENTS_MUS_PUBLIC_CPP_INPUT_DEVICES_INPUT_DEVICE_CLIENT_H_ |
OLD | NEW |