Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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_PLATFORM_X11_X11_EVENT_SOURCE_OZONE_H_ | |
| 6 #define UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_OZONE_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/message_loop/message_pump_libevent.h" | |
| 10 #include "ui/events/events_export.h" | |
| 11 #include "ui/events/platform/x11/x11_event_source.h" | |
| 12 | |
| 13 namespace ui { | |
| 14 | |
| 15 // Interface for classes that want to receive XEvent directly. Only used with | |
| 16 // ozone_platform_x11 and only events that can't be translated into ui::Events | |
| 17 // are sent via this path. | |
| 18 class EVENTS_EXPORT XEventDispatcher { | |
| 19 public: | |
| 20 // Sends XEvent to XEventDispatcher for handling. Returns true if the XEvent | |
| 21 // was dispatched, otherwise false. After the first XEventDispatcher returns | |
| 22 // true XEvent dispatching stops. | |
| 23 virtual bool DispatchXEvent(XEvent* xev) = 0; | |
| 24 | |
| 25 protected: | |
| 26 virtual ~XEventDispatcher() {} | |
| 27 }; | |
| 28 | |
| 29 // A PlatformEventSource implementation for Ozone X11. Converts XEvents to | |
| 30 // ui::Events before dispatching. For X11 specific events a separate list of | |
| 31 // XEventDispatchers is maintained. Uses Libevent to be notified for incoming | |
| 32 // XEvents. | |
| 33 class EVENTS_EXPORT X11EventSourceOzone | |
|
sadrul
2016/02/04 22:29:32
Actually, can you continue to call this X11EventSo
kylechar
2016/02/05 18:21:46
Done.
| |
| 34 : public X11EventSource, | |
| 35 public base::MessagePumpLibevent::Watcher { | |
| 36 public: | |
| 37 explicit X11EventSourceOzone(XDisplay* display); | |
| 38 ~X11EventSourceOzone() override; | |
| 39 | |
| 40 static X11EventSourceOzone* GetInstance(); | |
| 41 | |
| 42 // Adds a XEvent dispatcher to the XEvent dispatcher list. | |
| 43 void AddXEventDispatcher(XEventDispatcher* dispatcher); | |
| 44 | |
| 45 // Removes a XEvent dispatcher from the XEvent dispatcher list. | |
| 46 void RemoveXEventDispatcher(XEventDispatcher* dispatcher); | |
| 47 | |
| 48 private: | |
| 49 // PlatformEventSource: | |
| 50 uint32_t DispatchEvent(base::NativeEvent native_event) override; | |
| 51 void OnDispatcherListChanged() override; | |
| 52 | |
| 53 // Registers event watcher with Libevent. | |
| 54 void AddEventWatcher(); | |
| 55 | |
| 56 // Sends XEvent to registered XEventDispatchers. | |
| 57 void DispatchXEventToXEventDispatchers(XEvent* xevent); | |
| 58 | |
| 59 // base::MessagePumpLibevent::Watcher: | |
| 60 void OnFileCanReadWithoutBlocking(int fd) override; | |
| 61 void OnFileCanWriteWithoutBlocking(int fd) override; | |
| 62 | |
| 63 // Keep track of all XEventDispatcher to send XEvents directly to. | |
| 64 base::ObserverList<XEventDispatcher> dispatchers_xevent_; | |
| 65 | |
| 66 base::MessagePumpLibevent::FileDescriptorWatcher watcher_controller_; | |
| 67 bool initialized_; | |
| 68 | |
| 69 DISALLOW_COPY_AND_ASSIGN(X11EventSourceOzone); | |
| 70 }; | |
| 71 | |
| 72 } // namespace ui | |
| 73 | |
| 74 #endif // UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_OZONE_H_ | |
| OLD | NEW |