1 // Copyright (c) 2013 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_BASE_OZONE_EVENT_FACTORY_OZONE_H_ 6 #define UI_BASE_OZONE_EVENT_FACTORY_OZONE_H_ 7 8 #include <map> 9 10 #include "base/memory/scoped_ptr.h" 11 #include "base/message_loop/message_pump_libevent.h" 12 #include "ui/base/ozone/event_converter_ozone.h" 13 #include "ui/base/ui_export.h" 14 15 namespace ui { 16 17 class EventFactoryDelegateOzone; 18 19 // Creates and dispatches |ui.Event|'s. Ozone assumes that events arrive on file 20 // descriptors with one |EventConverterOzone| instance for each descriptor. 21 // Ozone presumes that the set of file desctiprtors can vary at runtime so this 22 // class supports dynamically adding and removing |EventConverterOzone| 23 // instances as necessary. 24 class UI_EXPORT EventFactoryOzone { 25 public: 26 EventFactoryOzone(); 27 ~EventFactoryOzone(); 28 29 // Sets an optional delegate responsible for creating the starting set of 30 // EventConvertOzones under management. This permits embedders to override the 31 // Linux /dev/input/*-based default as desired. The caller must manage the 32 // scope of this object. 33 static void SetEventFactoryDelegateOzone(EventFactoryDelegateOzone* delegate); 34 35 // Called from RootWindowHostOzone to create the starting set of event 36 // converters. 37 void CreateStartupEventConverters(); 38 39 // Add an |EventConverterOzone| instances for the given file descriptor. 40 // Transfers ownership of the |EventConverterOzone| to this class. 41 void AddEventConverter(int fd, scoped_ptr<EventConverterOzone> converter); 42 43 // Remote the |EventConverterOzone| 44 void RemoveEventConverter(int fd); 45 46 private: 47 // |EventConverterOzone| for each file descriptor. 48 typedef EventConverterOzone* Converter; 49 typedef base::MessagePumpLibevent::FileDescriptorWatcher* FDWatcher; 50 std::map<int, Converter> converters_; 51 std::map<int, FDWatcher> watchers_; 52 53 static EventFactoryDelegateOzone* delegate_; 54 55 DISALLOW_COPY_AND_ASSIGN(EventFactoryOzone); 56 }; 57 58 } // namespace ui 59 60 #endif // UI_BASE_OZONE_EVENT_FACTORY_OZONE_H_ 61