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/ozone/device/device_event_observer.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/evdev/events_ozone_evdev_export.h"
17#include "ui/events/platform/platform_event_source.h"
18#include "ui/gfx/native_widget_types.h"
19
20namespace gfx {
21class PointF;
22}  // namespace gfx
23
24namespace ui {
25
26class CursorDelegateEvdev;
27class DeviceManager;
28
29// Ozone events implementation for the Linux input subsystem ("evdev").
30class EVENTS_OZONE_EVDEV_EXPORT EventFactoryEvdev : public DeviceEventObserver,
31                                                    public PlatformEventSource {
32 public:
33  EventFactoryEvdev(CursorDelegateEvdev* cursor,
34                    DeviceManager* device_manager);
35  virtual ~EventFactoryEvdev();
36
37  void DispatchUiEvent(Event* event);
38
39  void WarpCursorTo(gfx::AcceleratedWidget widget,
40                    const gfx::PointF& location);
41
42 private:
43  // Open device at path & starting processing events (on UI thread).
44  void AttachInputDevice(const base::FilePath& file_path,
45                         scoped_ptr<EventConverterEvdev> converter);
46
47  // Close device at path (on UI thread).
48  void DetachInputDevice(const base::FilePath& file_path);
49
50  // DeviceEventObserver overrides:
51  //
52  // Callback for device add (on UI thread).
53  virtual void OnDeviceEvent(const DeviceEvent& event) OVERRIDE;
54
55  // PlatformEventSource:
56  virtual void OnDispatcherListChanged() OVERRIDE;
57
58  // Owned per-device event converters (by path).
59  std::map<base::FilePath, EventConverterEvdev*> converters_;
60
61  // Interface for scanning & monitoring input devices.
62  DeviceManager* device_manager_;  // Not owned.
63
64  // Task runner for event dispatch.
65  scoped_refptr<base::TaskRunner> ui_task_runner_;
66
67  // Modifier key state (shift, ctrl, etc).
68  EventModifiersEvdev modifiers_;
69
70  // Cursor movement.
71  CursorDelegateEvdev* cursor_;
72
73  // Dispatch callback for events.
74  EventDispatchCallback dispatch_callback_;
75
76  // Support weak pointers for attach & detach callbacks.
77  base::WeakPtrFactory<EventFactoryEvdev> weak_ptr_factory_;
78
79  DISALLOW_COPY_AND_ASSIGN(EventFactoryEvdev);
80};
81
82}  // namespace ui
83
84#endif  // UI_EVENTS_OZONE_EVDEV_EVENT_FACTORY_EVDEV_H_
85