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_INPUT_DEVICE_FACTORY_EVDEV_H_
6 #define UI_EVENTS_OZONE_EVDEV_INPUT_DEVICE_FACTORY_EVDEV_H_
12 #include "base/callback.h"
13 #include "base/compiler_specific.h"
14 #include "base/files/file_path.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/task_runner.h"
17 #include "ui/events/ozone/evdev/event_converter_evdev.h"
18 #include "ui/events/ozone/evdev/event_device_info.h"
19 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
20 #include "ui/events/ozone/evdev/input_device_settings_evdev.h"
24 class CursorDelegateEvdev
;
25 class DeviceEventDispatcherEvdev
;
26 class InputDeviceFactoryEvdevProxy
;
28 #if !defined(USE_EVDEV)
29 #error Missing dependency on ui/events/ozone:events_ozone_evdev
32 #if defined(USE_EVDEV_GESTURES)
33 class GesturePropertyProvider
;
36 typedef base::Callback
<void(scoped_ptr
<std::string
>)> GetTouchDeviceStatusReply
;
37 typedef base::Callback
<void(scoped_ptr
<std::vector
<base::FilePath
>>)>
38 GetTouchEventLogReply
;
40 // Manager for event device objects. All device I/O starts here.
41 class EVENTS_OZONE_EVDEV_EXPORT InputDeviceFactoryEvdev
{
43 InputDeviceFactoryEvdev(scoped_ptr
<DeviceEventDispatcherEvdev
> dispatcher
,
44 CursorDelegateEvdev
* cursor
);
45 ~InputDeviceFactoryEvdev();
47 // Open & start reading a newly plugged-in input device.
48 void AddInputDevice(int id
, const base::FilePath
& path
);
50 // Stop reading & close an unplugged input device.
51 void RemoveInputDevice(const base::FilePath
& path
);
53 // Device thread handler for initial scan completion.
54 void OnStartupScanComplete();
57 void SetCapsLockLed(bool enabled
);
59 // Bits from InputController that have to be answered on IO.
60 void UpdateInputDeviceSettings(const InputDeviceSettingsEvdev
& settings
);
61 void GetTouchDeviceStatus(const GetTouchDeviceStatusReply
& reply
);
62 void GetTouchEventLog(const base::FilePath
& out_dir
,
63 const GetTouchEventLogReply
& reply
);
65 base::WeakPtr
<InputDeviceFactoryEvdev
> GetWeakPtr();
68 // Open device at path & starting processing events (on UI thread).
69 void AttachInputDevice(scoped_ptr
<EventConverterEvdev
> converter
);
71 // Close device at path (on UI thread).
72 void DetachInputDevice(const base::FilePath
& file_path
);
74 // Sync input_device_settings_ to attached devices.
75 void ApplyInputDeviceSettings();
76 void ApplyCapsLockLed();
78 // Policy for device enablement.
79 bool IsDeviceEnabled(const EventConverterEvdev
* converter
);
81 // Update observers on device changes.
82 void UpdateDirtyFlags(const EventConverterEvdev
* converter
);
83 void NotifyDevicesUpdated();
84 void NotifyKeyboardsUpdated();
85 void NotifyTouchscreensUpdated();
86 void NotifyMouseDevicesUpdated();
87 void NotifyTouchpadDevicesUpdated();
89 void SetIntPropertyForOneType(const EventDeviceType type
,
90 const std::string
& name
,
92 void SetBoolPropertyForOneType(const EventDeviceType type
,
93 const std::string
& name
,
96 // Owned per-device event converters (by path).
97 std::map
<base::FilePath
, EventConverterEvdev
*> converters_
;
99 // Task runner for our thread.
100 scoped_refptr
<base::TaskRunner
> task_runner_
;
103 CursorDelegateEvdev
* cursor_
;
105 #if defined(USE_EVDEV_GESTURES)
106 // Gesture library property provider (used by touchpads/mice).
107 scoped_ptr
<GesturePropertyProvider
> gesture_property_provider_
;
110 // Dispatcher for events.
111 scoped_ptr
<DeviceEventDispatcherEvdev
> dispatcher_
;
113 // Number of pending device additions & device classes.
114 int pending_device_changes_
= 0;
115 bool touchscreen_list_dirty_
= true;
116 bool keyboard_list_dirty_
= true;
117 bool mouse_list_dirty_
= true;
118 bool touchpad_list_dirty_
= true;
120 // Whether we have a list of devices that were present at startup.
121 bool startup_devices_enumerated_
= false;
123 // Whether devices that were present at startup are open.
124 bool startup_devices_opened_
= false;
127 bool caps_lock_led_enabled_
= false;
129 // Device settings. These primarily affect libgestures behavior.
130 InputDeviceSettingsEvdev input_device_settings_
;
132 // Support weak pointers for attach & detach callbacks.
133 base::WeakPtrFactory
<InputDeviceFactoryEvdev
> weak_ptr_factory_
;
135 DISALLOW_COPY_AND_ASSIGN(InputDeviceFactoryEvdev
);
140 #endif // UI_EVENTS_OZONE_EVDEV_INPUT_DEVICE_FACTORY_EVDEV_H_