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