Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ui / events / ozone / evdev / event_factory_evdev.h
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.
4
5 #ifndef UI_EVENTS_OZONE_EVDEV_EVENT_FACTORY_EVDEV_H_
6 #define UI_EVENTS_OZONE_EVDEV_EVENT_FACTORY_EVDEV_H_
7
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/events_export.h"
14 #include "ui/events/ozone/evdev/event_converter_evdev.h"
15 #include "ui/events/ozone/evdev/event_modifiers_evdev.h"
16 #include "ui/events/ozone/event_factory_ozone.h"
17
18 namespace ui {
19
20 class DeviceManagerEvdev;
21
22 // Ozone events implementation for the Linux input subsystem ("evdev").
23 class EVENTS_EXPORT EventFactoryEvdev : public EventFactoryOzone {
24  public:
25   EventFactoryEvdev();
26   virtual ~EventFactoryEvdev();
27
28   virtual void StartProcessingEvents() OVERRIDE;
29
30   // Set task runner to use for device polling & initialization.
31   virtual void SetFileTaskRunner(scoped_refptr<base::TaskRunner> task_runner)
32       OVERRIDE;
33
34  private:
35   // Open device at path & starting processing events (on UI thread).
36   void AttachInputDevice(const base::FilePath& file_path,
37                          scoped_ptr<EventConverterEvdev> converter);
38
39   // Close device at path (on UI thread).
40   void DetachInputDevice(const base::FilePath& file_path);
41
42   // Callback for device add (on UI thread).
43   void OnDeviceAdded(const base::FilePath& path);
44
45   // Callback for device remove (on UI thread).
46   void OnDeviceRemoved(const base::FilePath& path);
47
48   // Owned per-device event converters (by path).
49   std::map<base::FilePath, EventConverterEvdev*> converters_;
50
51   // Interface for scanning & monitoring input devices.
52   scoped_ptr<DeviceManagerEvdev> device_manager_;
53
54   // Task runner for event dispatch.
55   scoped_refptr<base::TaskRunner> ui_task_runner_;
56
57   // Task runner for file I/O.
58   scoped_refptr<base::TaskRunner> file_task_runner_;
59
60   // Modifier key state (shift, ctrl, etc).
61   EventModifiersEvdev modifiers_;
62
63   // Support weak pointers for attach & detach callbacks.
64   base::WeakPtrFactory<EventFactoryEvdev> weak_ptr_factory_;
65
66   DISALLOW_COPY_AND_ASSIGN(EventFactoryEvdev);
67 };
68
69 }  // namespace ui
70
71 #endif  // UI_EVENTS_OZONE_EVDEV_EVENT_FACTORY_EVDEV_H_