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_EVENTS_OZONE_EVENT_FACTORY_OZONE_H_ 6 #define UI_EVENTS_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/events/events_export.h" 13 #include "ui/events/ozone/event_converter_ozone.h" 14 15 namespace ui { 16 17 // Creates and dispatches |ui.Event|'s. Ozone assumes that events arrive on file 18 // descriptors with one |EventConverterOzone| instance for each descriptor. 19 // Ozone presumes that the set of file desctiprtors can vary at runtime so this 20 // class supports dynamically adding and removing |EventConverterOzone| 21 // instances as necessary. 22 class EVENTS_EXPORT EventFactoryOzone { 23 public: 24 EventFactoryOzone(); 25 virtual ~EventFactoryOzone(); 26 27 // Called from RootWindowHostOzone to initialize and start processing events. 28 // This should create the initial set of converters, and potentially arrange 29 // for more converters to be created as new event sources become available. 30 // No events processing should happen until this is called. All processes have 31 // an EventFactoryOzone but not all of them should process events. In chrome, 32 // events are dispatched in the browser process on the UI thread. 33 virtual void StartProcessingEvents(); 34 35 // Returns the static instance last set using SetInstance(). 36 static EventFactoryOzone* GetInstance(); 37 38 // Sets the implementation delegate. Ownership is retained by the caller. 39 static void SetInstance(EventFactoryOzone*); 40 41 // Add an |EventConverterOzone| instances for the given file descriptor. 42 // Transfers ownership of the |EventConverterOzone| to this class. 43 void AddEventConverter(int fd, scoped_ptr<EventConverterOzone> converter); 44 45 // Remote the |EventConverterOzone| 46 void RemoveEventConverter(int fd); 47 48 private: 49 // |EventConverterOzone| for each file descriptor. 50 typedef EventConverterOzone* Converter; 51 typedef base::MessagePumpLibevent::FileDescriptorWatcher* FDWatcher; 52 std::map<int, Converter> converters_; 53 std::map<int, FDWatcher> watchers_; 54 55 static EventFactoryOzone* impl_; // not owned 56 57 DISALLOW_COPY_AND_ASSIGN(EventFactoryOzone); 58 }; 59 60 } // namespace ui 61 62 #endif // UI_EVENTS_OZONE_EVENT_FACTORY_OZONE_H_ 63