Landing Recent QUIC Changes.
[chromium-blink-merge.git] / ui / events / ozone / evdev / event_factory_evdev.h
blobd5079b38142a943ae992cea4ed6ba927c933e5aa
1 // Copyright 2014 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.
5 #ifndef UI_EVENTS_OZONE_EVDEV_EVENT_FACTORY_EVDEV_H_
6 #define UI_EVENTS_OZONE_EVDEV_EVENT_FACTORY_EVDEV_H_
8 #include "base/callback.h"
9 #include "base/compiler_specific.h"
10 #include "base/files/file_path.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/task_runner.h"
13 #include "ui/events/ozone/device/device_event_observer.h"
14 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h"
15 #include "ui/events/ozone/evdev/event_modifiers_evdev.h"
16 #include "ui/events/ozone/evdev/event_thread_evdev.h"
17 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
18 #include "ui/events/ozone/evdev/input_controller_evdev.h"
19 #include "ui/events/ozone/evdev/keyboard_evdev.h"
20 #include "ui/events/ozone/evdev/mouse_button_map_evdev.h"
21 #include "ui/events/platform/platform_event_source.h"
22 #include "ui/gfx/native_widget_types.h"
23 #include "ui/ozone/public/system_input_injector.h"
25 namespace gfx {
26 class PointF;
27 } // namespace gfx
29 namespace ui {
31 class CursorDelegateEvdev;
32 class DeviceManager;
33 class InputDeviceFactoryEvdev;
34 class InputDeviceFactoryEvdevProxy;
35 class SystemInputInjector;
36 enum class DomCode;
38 #if !defined(USE_EVDEV)
39 #error Missing dependency on ui/events/ozone:events_ozone_evdev
40 #endif
42 // Ozone events implementation for the Linux input subsystem ("evdev").
44 // This is a UI thread object, but creates its own thread for I/O. See
45 // InputDeviceFactoryEvdev for the I/O thread part.
46 class EVENTS_OZONE_EVDEV_EXPORT EventFactoryEvdev : public DeviceEventObserver,
47 public PlatformEventSource {
48 public:
49 EventFactoryEvdev(CursorDelegateEvdev* cursor,
50 DeviceManager* device_manager,
51 KeyboardLayoutEngine* keyboard_layout_engine);
52 ~EventFactoryEvdev() override;
54 // Initialize. Must be called with a valid message loop.
55 void Init();
57 void WarpCursorTo(gfx::AcceleratedWidget widget,
58 const gfx::PointF& location);
60 scoped_ptr<SystemInputInjector> CreateSystemInputInjector();
62 InputController* input_controller() { return &input_controller_; }
64 // User input events.
65 void DispatchKeyEvent(const KeyEventParams& params);
66 void DispatchMouseMoveEvent(const MouseMoveEventParams& params);
67 void DispatchMouseButtonEvent(const MouseButtonEventParams& params);
68 void DispatchMouseWheelEvent(const MouseWheelEventParams& params);
69 void DispatchScrollEvent(const ScrollEventParams& params);
70 void DispatchTouchEvent(const TouchEventParams& params);
72 // Device lifecycle events.
73 void DispatchKeyboardDevicesUpdated(
74 const std::vector<KeyboardDevice>& devices);
75 void DispatchTouchscreenDevicesUpdated(
76 const std::vector<TouchscreenDevice>& devices);
77 void DispatchMouseDevicesUpdated(const std::vector<InputDevice>& devices);
78 void DispatchTouchpadDevicesUpdated(const std::vector<InputDevice>& devices);
80 protected:
81 // DeviceEventObserver overrides:
83 // Callback for device add (on UI thread).
84 void OnDeviceEvent(const DeviceEvent& event) override;
86 // PlatformEventSource:
87 void OnDispatcherListChanged() override;
89 private:
90 // Dispatch event via PlatformEventSource.
91 void DispatchUiEvent(ui::Event* event);
93 int NextDeviceId();
95 // Device thread initialization.
96 void StartThread();
97 void OnThreadStarted(
98 scoped_ptr<InputDeviceFactoryEvdevProxy> input_device_factory);
100 // Used to uniquely identify input devices.
101 int last_device_id_;
103 // Interface for scanning & monitoring input devices.
104 DeviceManager* device_manager_; // Not owned.
106 // Proxy for input device factory (manages device I/O objects).
107 // The real object lives on a different thread.
108 scoped_ptr<InputDeviceFactoryEvdevProxy> input_device_factory_proxy_;
110 // Modifier key state (shift, ctrl, etc).
111 EventModifiersEvdev modifiers_;
113 // Mouse button map.
114 MouseButtonMapEvdev button_map_;
116 // Keyboard state.
117 KeyboardEvdev keyboard_;
119 // Cursor movement.
120 CursorDelegateEvdev* cursor_;
122 // Object for controlling input devices.
123 InputControllerEvdev input_controller_;
125 // Whether we've set up the device factory.
126 bool initialized_;
128 // Thread for device I/O.
129 EventThreadEvdev thread_;
131 // Support weak pointers for attach & detach callbacks.
132 base::WeakPtrFactory<EventFactoryEvdev> weak_ptr_factory_;
134 DISALLOW_COPY_AND_ASSIGN(EventFactoryEvdev);
137 } // namespace ui
139 #endif // UI_EVENTS_OZONE_EVDEV_EVENT_FACTORY_EVDEV_H_