OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_BASE_X_X11_WINDOW_EVENT_MANAGER_H_ | 5 #ifndef UI_BASE_X_X11_SCOPED_EVENT_SELECTOR_H_ |
6 #define UI_BASE_X_X11_WINDOW_EVENT_MANAGER_H_ | 6 #define UI_BASE_X_X11_SCOPED_EVENT_SELECTOR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | |
10 | 9 |
11 #include "base/compiler_specific.h" | |
12 #include "base/macros.h" | 10 #include "base/macros.h" |
13 #include "ui/base/x/ui_base_x_export.h" | 11 #include "ui/base/x/ui_base_x_export.h" |
14 #include "ui/gfx/x/x11_types.h" | 12 #include "ui/gfx/x/x11_types.h" |
15 | 13 |
16 // A process wide singleton for selecting events on X windows which were not | |
17 // created by Chrome. | |
18 namespace base { | |
19 template <typename T> | |
20 struct DefaultSingletonTraits; | |
21 } | |
22 | |
23 namespace ui { | 14 namespace ui { |
24 | 15 |
25 // Ensures events in |event_mask| are selected on |xid| for the duration of this | 16 // Ensures events in |event_mask| are selected on |xid| for the duration of this |
26 // object's lifetime. | 17 // object's lifetime. This class allows multiple clients within Chrome to |
| 18 // select events on the same X window. |
27 class UI_BASE_X_EXPORT XScopedEventSelector { | 19 class UI_BASE_X_EXPORT XScopedEventSelector { |
28 public: | 20 public: |
29 XScopedEventSelector(XID xid, uint32_t event_mask); | 21 XScopedEventSelector(XID xid, uint32_t event_mask); |
30 ~XScopedEventSelector(); | 22 ~XScopedEventSelector(); |
31 | 23 |
32 private: | 24 private: |
33 XID xid_; | |
34 uint32_t event_mask_; | |
35 | |
36 DISALLOW_COPY_AND_ASSIGN(XScopedEventSelector); | |
37 }; | |
38 | |
39 // Manages the events that Chrome has selected on X windows which were not | |
40 // created by Chrome. This class allows multiple clients within Chrome to select | |
41 // events on the same X window. | |
42 class UI_BASE_X_EXPORT XWindowEventManager { | |
43 public: | |
44 static XWindowEventManager* GetInstance(); | |
45 | |
46 private: | |
47 friend struct base::DefaultSingletonTraits<XWindowEventManager>; | |
48 friend class XScopedEventSelector; | |
49 | |
50 class MultiMask; | |
51 | |
52 XWindowEventManager(); | |
53 ~XWindowEventManager(); | |
54 | |
55 // Guarantees that events in |event_mask| will be reported to Chrome. | 25 // Guarantees that events in |event_mask| will be reported to Chrome. |
56 void SelectEvents(XID xid, uint32_t event_mask); | 26 void SelectEvents(XID xid, uint32_t event_mask); |
57 | 27 |
58 // Deselects events on |event_mask|. Chrome will stop receiving events for | 28 // Deselects events on |event_mask|. Chrome will stop receiving events for |
59 // any set bit in |event_mask| only if no other client has selected that bit. | 29 // any set bit in |event_mask| only if no other client has selected that bit. |
60 void DeselectEvents(XID xid, uint32_t event_mask); | 30 void DeselectEvents(XID xid, uint32_t event_mask); |
61 | 31 |
62 // Called whenever the mask corresponding to window |xid| might have changed. | 32 // Called whenever the mask corresponding to window |xid| might have changed. |
63 // Updates the event mask with respect to the server, if necessary. | 33 // Updates the event mask with respect to the server, if necessary. |
64 void AfterMaskChanged(XID xid, uint32_t old_mask); | 34 void AfterMaskChanged(XID xid, uint32_t old_mask); |
65 | 35 |
66 std::map<XID, std::unique_ptr<MultiMask>> mask_map_; | 36 class MultiMask; |
67 | 37 |
68 DISALLOW_COPY_AND_ASSIGN(XWindowEventManager); | 38 XID xid_; |
| 39 uint32_t event_mask_; |
| 40 |
| 41 static std::map<XID, std::unique_ptr<MultiMask>> mask_map_; |
| 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(XScopedEventSelector); |
69 }; | 44 }; |
70 | 45 |
71 } // namespace ui | 46 } // namespace ui |
72 | 47 |
73 #endif // UI_BASE_X_X11_FOREIGN_WINDOW_MANAGER_H_ | 48 #endif // UI_BASE_X_X11_SCOPED_EVENT_SELECTOR_H_ |
OLD | NEW |