Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: ui/events/platform/x11/x11_event_source.h

Issue 1602173005: Add PlatformWindow/Event related code for Ozone X11. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: XEventDispatcher added. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ 5 #ifndef UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_
6 #define UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ 6 #define UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/observer_list.h"
12 #include "ui/events/events_export.h" 13 #include "ui/events/events_export.h"
13 #include "ui/events/platform/platform_event_source.h" 14 #include "ui/events/platform/platform_event_source.h"
14 #include "ui/gfx/x/x11_types.h" 15 #include "ui/gfx/x/x11_types.h"
15 16
16 typedef struct _GPollFD GPollFD; 17 typedef struct _GPollFD GPollFD;
17 typedef struct _GSource GSource; 18 typedef struct _GSource GSource;
18 typedef union _XEvent XEvent; 19 typedef union _XEvent XEvent;
19 typedef unsigned long XID; 20 typedef unsigned long XID;
20 21
21 namespace ui { 22 namespace ui {
22 23
24 // Interface for classes that want to receive XEvent directly. Only used with
25 // ozone_platform_x11 and only events that can't be translated into ui::Events
26 // are sent via this path.
27 class EVENTS_EXPORT XEventDispatcher {
28 public:
29 // Sends XEvent to XEventDispatcher for handling. Returns true if the XEvent
30 // was dispatched, otherwise false. After the first XEventDispatcher returns
31 // true XEvent dispatching stops.
32 virtual bool DispatchXEvent(const XEvent& event) = 0;
33
34 protected:
35 virtual ~XEventDispatcher() {}
36 };
37
23 class X11HotplugEventHandler; 38 class X11HotplugEventHandler;
24 39
25 // A PlatformEventSource implementation for reading events from X11 server and 40 // A PlatformEventSource implementation for reading events from X11 server and
26 // dispatching the events to the appropriate dispatcher. 41 // dispatching the events to the appropriate dispatcher.
27 class EVENTS_EXPORT X11EventSource : public PlatformEventSource { 42 class EVENTS_EXPORT X11EventSource : public PlatformEventSource {
28 public: 43 public:
29 explicit X11EventSource(XDisplay* display); 44 explicit X11EventSource(XDisplay* display);
30 ~X11EventSource() override; 45 ~X11EventSource() override;
31 46
32 static X11EventSource* GetInstance(); 47 static X11EventSource* GetInstance();
33 48
49 // Adds a XEvent dispatcher to the dispatcher list.
50 void AddXEventDispatcher(XEventDispatcher* dispatcher);
51
52 // Removes a XEvent dispatcher from the dispatcher list.
53 void RemoveXEventDispatcher(XEventDispatcher* dispatcher);
54
34 // Called by the glib source dispatch function. Processes all (if any) 55 // Called by the glib source dispatch function. Processes all (if any)
35 // available X events. 56 // available X events.
36 void DispatchXEvents(); 57 void DispatchXEvents();
37 58
38 // Blocks on the X11 event queue until we receive notification from the 59 // Blocks on the X11 event queue until we receive notification from the
39 // xserver that |w| has been mapped; StructureNotifyMask events on |w| are 60 // xserver that |w| has been mapped; StructureNotifyMask events on |w| are
40 // pulled out from the queue and dispatched out of order. 61 // pulled out from the queue and dispatched out of order.
41 // 62 //
42 // For those that know X11, this is really a wrapper around XWindowEvent 63 // For those that know X11, this is really a wrapper around XWindowEvent
43 // which still makes sure the preempted event is dispatched instead of 64 // which still makes sure the preempted event is dispatched instead of
44 // dropped on the floor. This method exists because mapping a window is 65 // dropped on the floor. This method exists because mapping a window is
45 // asynchronous (and we receive an XEvent when mapped), while there are also 66 // asynchronous (and we receive an XEvent when mapped), while there are also
46 // functions which require a mapped window. 67 // functions which require a mapped window.
47 void BlockUntilWindowMapped(XID window); 68 void BlockUntilWindowMapped(XID window);
48 69
49 protected: 70 protected:
50 XDisplay* display() { return display_; } 71 XDisplay* display() { return display_; }
51 72
52 private: 73 private:
53 // Extracts cookie data from |xevent| if it's of GenericType, and dispatches 74 // Extracts cookie data from |xevent| if it's of GenericType, and dispatches
54 // the event. This function also frees up the cookie data after dispatch is 75 // the event. This function also frees up the cookie data after dispatch is
55 // complete. 76 // complete.
56 uint32_t ExtractCookieDataDispatchEvent(XEvent* xevent); 77 uint32_t ExtractCookieDataDispatchEvent(XEvent* xevent);
57 78
58 // PlatformEventSource: 79 // PlatformEventSource:
59 uint32_t DispatchEvent(XEvent* xevent) override; 80 uint32_t DispatchEvent(base::NativeEvent native_event) override;
60 void StopCurrentEventStream() override; 81 void StopCurrentEventStream() override;
61 void OnDispatcherListChanged() override; 82 void OnDispatcherListChanged() override;
62 83
84 // Sends XEvent to registered XEventDispatchers.
85 void DispatchXEventToXEventDispatchers(XEvent* xevent);
86
87 // Handles updates after event has been dispatched.
88 void PostDispatchEvent(XEvent* xevent);
89
63 // The connection to the X11 server used to receive the events. 90 // The connection to the X11 server used to receive the events.
64 XDisplay* display_; 91 XDisplay* display_;
65 92
66 // Keeps track of whether this source should continue to dispatch all the 93 // Keeps track of whether this source should continue to dispatch all the
67 // available events. 94 // available events.
68 bool continue_stream_; 95 bool continue_stream_;
69 96
70 scoped_ptr<X11HotplugEventHandler> hotplug_event_handler_; 97 scoped_ptr<X11HotplugEventHandler> hotplug_event_handler_;
71 98
99 // Keep track of all XEventDispatcher to send XEvents directly to, only used
100 // with ozone.
spang 2016/01/26 21:37:40 Why "only used with ozone" ? I think anything tha
kylechar 2016/01/27 15:39:26 As long as there are no PlatformEventObservers in
kylechar 2016/02/01 16:44:27 After talking with Sadrul we decided that only X11
101 base::ObserverList<XEventDispatcher> x_dispatchers_;
102
72 DISALLOW_COPY_AND_ASSIGN(X11EventSource); 103 DISALLOW_COPY_AND_ASSIGN(X11EventSource);
73 }; 104 };
74 105
75 } // namespace ui 106 } // namespace ui
76 107
77 #endif // UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ 108 #endif // UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698