Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / events / ozone / evdev / event_factory_evdev.h
blob18a1f90c5b66be348eda1d0b551981607e050df1
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/gfx/sequential_id_generator.h"
24 #include "ui/ozone/public/system_input_injector.h"
26 namespace gfx {
27 class PointF;
28 } // namespace gfx
30 namespace ui {
32 class CursorDelegateEvdev;
33 class DeviceManager;
34 class InputDeviceFactoryEvdev;
35 class InputDeviceFactoryEvdevProxy;
36 class SystemInputInjector;
37 enum class DomCode;
39 #if !defined(USE_EVDEV)
40 #error Missing dependency on ui/events/ozone:events_ozone_evdev
41 #endif
43 // Ozone events implementation for the Linux input subsystem ("evdev").
45 // This is a UI thread object, but creates its own thread for I/O. See
46 // InputDeviceFactoryEvdev for the I/O thread part.
47 class EVENTS_OZONE_EVDEV_EXPORT EventFactoryEvdev : public DeviceEventObserver,
48 public PlatformEventSource {
49 public:
50 EventFactoryEvdev(CursorDelegateEvdev* cursor,
51 DeviceManager* device_manager,
52 KeyboardLayoutEngine* keyboard_layout_engine);
53 ~EventFactoryEvdev() override;
55 // Initialize. Must be called with a valid message loop.
56 void Init();
58 void WarpCursorTo(gfx::AcceleratedWidget widget,
59 const gfx::PointF& location);
61 scoped_ptr<SystemInputInjector> CreateSystemInputInjector();
63 InputControllerEvdev* input_controller() { return &input_controller_; }
65 // User input events.
66 void DispatchKeyEvent(const KeyEventParams& params);
67 void DispatchMouseMoveEvent(const MouseMoveEventParams& params);
68 void DispatchMouseButtonEvent(const MouseButtonEventParams& params);
69 void DispatchMouseWheelEvent(const MouseWheelEventParams& params);
70 void DispatchScrollEvent(const ScrollEventParams& params);
71 void DispatchTouchEvent(const TouchEventParams& params);
73 // Device lifecycle events.
74 void DispatchKeyboardDevicesUpdated(
75 const std::vector<KeyboardDevice>& devices);
76 void DispatchTouchscreenDevicesUpdated(
77 const std::vector<TouchscreenDevice>& devices);
78 void DispatchMouseDevicesUpdated(const std::vector<InputDevice>& devices);
79 void DispatchTouchpadDevicesUpdated(const std::vector<InputDevice>& devices);
80 void DispatchDeviceListsComplete();
82 protected:
83 // DeviceEventObserver overrides:
85 // Callback for device add (on UI thread).
86 void OnDeviceEvent(const DeviceEvent& event) override;
88 // PlatformEventSource:
89 void OnDispatcherListChanged() override;
91 private:
92 // Dispatch event via PlatformEventSource.
93 void DispatchUiEvent(ui::Event* event);
95 int NextDeviceId();
97 // Device thread initialization.
98 void StartThread();
99 void OnThreadStarted(
100 scoped_ptr<InputDeviceFactoryEvdevProxy> input_device_factory);
102 // Used to uniquely identify input devices.
103 int last_device_id_ = 0;
105 // Interface for scanning & monitoring input devices.
106 DeviceManager* device_manager_; // Not owned.
108 // Proxy for input device factory (manages device I/O objects).
109 // The real object lives on a different thread.
110 scoped_ptr<InputDeviceFactoryEvdevProxy> input_device_factory_proxy_;
112 // Modifier key state (shift, ctrl, etc).
113 EventModifiersEvdev modifiers_;
115 // Mouse button map.
116 MouseButtonMapEvdev button_map_;
118 // Keyboard state.
119 KeyboardEvdev keyboard_;
121 // Cursor movement.
122 CursorDelegateEvdev* cursor_;
124 // Object for controlling input devices.
125 InputControllerEvdev input_controller_;
127 // Whether we've set up the device factory.
128 bool initialized_ = false;
130 // Thread for device I/O.
131 EventThreadEvdev thread_;
133 // Touch event id generator.
134 SequentialIDGenerator touch_id_generator_;
136 // Support weak pointers for attach & detach callbacks.
137 base::WeakPtrFactory<EventFactoryEvdev> weak_ptr_factory_;
139 DISALLOW_COPY_AND_ASSIGN(EventFactoryEvdev);
142 } // namespace ui
144 #endif // UI_EVENTS_OZONE_EVDEV_EVENT_FACTORY_EVDEV_H_