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 // Disables the internal touchpad.
54 void DisableInternalTouchpad();
56 // Enables the internal touchpad.
57 void EnableInternalTouchpad();
59 // Disables all keys on the internal keyboard except |excepted_keys|.
60 void DisableInternalKeyboardExceptKeys(
61 scoped_ptr
<std::set
<DomCode
>> excepted_keys
);
63 // Enables all keys on the internal keyboard.
64 void EnableInternalKeyboard();
67 void SetCapsLockLed(bool enabled
);
69 // Bits from InputController that have to be answered on IO.
70 void UpdateInputDeviceSettings(const InputDeviceSettingsEvdev
& settings
);
71 void GetTouchDeviceStatus(const GetTouchDeviceStatusReply
& reply
);
72 void GetTouchEventLog(const base::FilePath
& out_dir
,
73 const GetTouchEventLogReply
& reply
);
75 base::WeakPtr
<InputDeviceFactoryEvdev
> GetWeakPtr();
78 // Open device at path & starting processing events (on UI thread).
79 void AttachInputDevice(scoped_ptr
<EventConverterEvdev
> converter
);
81 // Close device at path (on UI thread).
82 void DetachInputDevice(const base::FilePath
& file_path
);
84 // Sync input_device_settings_ to attached devices.
85 void ApplyInputDeviceSettings();
86 void ApplyCapsLockLed();
88 // Update observers on device changes.
89 void UpdateDirtyFlags(const EventConverterEvdev
* converter
);
90 void NotifyDevicesUpdated();
91 void NotifyKeyboardsUpdated();
92 void NotifyTouchscreensUpdated();
93 void NotifyMouseDevicesUpdated();
94 void NotifyTouchpadDevicesUpdated();
96 void SetIntPropertyForOneType(const EventDeviceType type
,
97 const std::string
& name
,
99 void SetBoolPropertyForOneType(const EventDeviceType type
,
100 const std::string
& name
,
103 // Owned per-device event converters (by path).
104 std::map
<base::FilePath
, EventConverterEvdev
*> converters_
;
106 // Task runner for our thread.
107 scoped_refptr
<base::TaskRunner
> task_runner_
;
110 CursorDelegateEvdev
* cursor_
;
112 #if defined(USE_EVDEV_GESTURES)
113 // Gesture library property provider (used by touchpads/mice).
114 scoped_ptr
<GesturePropertyProvider
> gesture_property_provider_
;
117 // Dispatcher for events.
118 scoped_ptr
<DeviceEventDispatcherEvdev
> dispatcher_
;
120 // Number of pending device additions & device classes.
121 int pending_device_changes_
;
122 bool touchscreen_list_dirty_
;
123 bool keyboard_list_dirty_
;
124 bool mouse_list_dirty_
;
125 bool touchpad_list_dirty_
;
128 bool caps_lock_led_enabled_
;
130 // Device settings. These primarily affect libgestures behavior.
131 InputDeviceSettingsEvdev input_device_settings_
;
133 // Support weak pointers for attach & detach callbacks.
134 base::WeakPtrFactory
<InputDeviceFactoryEvdev
> weak_ptr_factory_
;
136 DISALLOW_COPY_AND_ASSIGN(InputDeviceFactoryEvdev
);
141 #endif // UI_EVENTS_OZONE_EVDEV_INPUT_DEVICE_FACTORY_EVDEV_H_