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_BASE_X_X11_WINDOW_EVENT_MANAGER_H_ |
| 6 #define UI_BASE_X_X11_WINDOW_EVENT_MANAGER_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/compiler_specific.h" |
| 12 #include "base/macros.h" |
| 13 #include "ui/base/x/ui_base_x_export.h" |
| 14 #include "ui/gfx/x/x11_types.h" |
| 15 |
| 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 { |
| 24 |
| 25 // Ensures events in |event_mask| are selected on |xid| for the duration of this |
| 26 // object's lifetime. |
| 27 class UI_BASE_X_EXPORT XScopedEventSelector { |
| 28 public: |
| 29 XScopedEventSelector(XID xid, uint32_t event_mask); |
| 30 ~XScopedEventSelector(); |
| 31 |
| 32 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. |
| 56 void SelectEvents(XID xid, uint32_t event_mask); |
| 57 |
| 58 // 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. |
| 60 void DeselectEvents(XID xid, uint32_t event_mask); |
| 61 |
| 62 // Called whenever the mask corresponding to window |xid| might have changed. |
| 63 // Updates the event mask with respect to the server, if necessary. |
| 64 void AfterMaskChanged(XID xid, uint32_t old_mask); |
| 65 |
| 66 std::map<XID, std::unique_ptr<MultiMask>> mask_map_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(XWindowEventManager); |
| 69 }; |
| 70 |
| 71 } // namespace ui |
| 72 |
| 73 #endif // UI_BASE_X_X11_FOREIGN_WINDOW_MANAGER_H_ |
OLD | NEW |