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

Side by Side Diff: ui/base/x/x11_window_event_manager.h

Issue 2319933002: X11: Remove calls to XSelectInput (Closed)
Patch Set: Comments Created 4 years, 3 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
« no previous file with comments | « ui/base/clipboard/clipboard_aurax11.cc ('k') | ui/base/x/x11_window_event_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_WINDOW_EVENT_MANAGER_H_
6 #define UI_BASE_X_X11_WINDOW_EVENT_MANAGER_H_ 6 #define UI_BASE_X_X11_WINDOW_EVENT_MANAGER_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"
11 #include "base/memory/weak_ptr.h"
13 #include "ui/base/x/ui_base_x_export.h" 12 #include "ui/base/x/ui_base_x_export.h"
14 #include "ui/gfx/x/x11_types.h" 13 #include "ui/gfx/x/x11_types.h"
15 14
16 // A process wide singleton for selecting events on X windows which were not
17 // created by Chrome.
18 namespace base { 15 namespace base {
19 template <typename T> 16 template <typename T>
20 struct DefaultSingletonTraits; 17 struct DefaultSingletonTraits;
21 } 18 }
22 19
23 namespace ui { 20 namespace ui {
24 21
22 class XWindowEventManager;
23
25 // Ensures events in |event_mask| are selected on |xid| for the duration of this 24 // Ensures events in |event_mask| are selected on |xid| for the duration of this
26 // object's lifetime. 25 // object's lifetime.
27 class UI_BASE_X_EXPORT XScopedEventSelector { 26 class UI_BASE_X_EXPORT XScopedEventSelector {
28 public: 27 public:
29 XScopedEventSelector(XID xid, uint32_t event_mask); 28 XScopedEventSelector(XID xid, uint32_t event_mask);
30 ~XScopedEventSelector(); 29 ~XScopedEventSelector();
31 30
32 private: 31 private:
33 XID xid_; 32 XID xid_;
34 uint32_t event_mask_; 33 uint32_t event_mask_;
34 base::WeakPtr<XWindowEventManager> event_manager_;
35 35
36 DISALLOW_COPY_AND_ASSIGN(XScopedEventSelector); 36 DISALLOW_COPY_AND_ASSIGN(XScopedEventSelector);
37 }; 37 };
38 38
39 // Manages the events that Chrome has selected on X windows which were not 39 // Allows multiple clients within Chrome to select events on the same X window.
40 // created by Chrome. This class allows multiple clients within Chrome to select 40 class XWindowEventManager {
41 // events on the same X window.
42 class UI_BASE_X_EXPORT XWindowEventManager {
43 public: 41 public:
44 static XWindowEventManager* GetInstance(); 42 static XWindowEventManager* GetInstance();
45 43
46 private: 44 private:
47 friend struct base::DefaultSingletonTraits<XWindowEventManager>; 45 friend struct base::DefaultSingletonTraits<XWindowEventManager>;
48 friend class XScopedEventSelector; 46 friend class XScopedEventSelector;
49 47
50 class MultiMask; 48 class MultiMask;
51 49
52 XWindowEventManager(); 50 XWindowEventManager();
53 ~XWindowEventManager(); 51 ~XWindowEventManager();
54 52
55 // Guarantees that events in |event_mask| will be reported to Chrome. 53 // Guarantees that events in |event_mask| will be reported to Chrome.
56 void SelectEvents(XID xid, uint32_t event_mask); 54 void SelectEvents(XID xid, uint32_t event_mask);
57 55
58 // Deselects events on |event_mask|. Chrome will stop receiving events for 56 // 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. 57 // any set bit in |event_mask| only if no other client has selected that bit.
60 void DeselectEvents(XID xid, uint32_t event_mask); 58 void DeselectEvents(XID xid, uint32_t event_mask);
61 59
62 // Called whenever the mask corresponding to window |xid| might have changed. 60 // Helper method called by SelectEvents and DeselectEvents whenever the mask
63 // Updates the event mask with respect to the server, if necessary. 61 // corresponding to window |xid| might have changed. Calls SetEventMask if
62 // necessary.
64 void AfterMaskChanged(XID xid, uint32_t old_mask); 63 void AfterMaskChanged(XID xid, uint32_t old_mask);
65 64
66 std::map<XID, std::unique_ptr<MultiMask>> mask_map_; 65 std::map<XID, std::unique_ptr<MultiMask>> mask_map_;
67 66
67 // This is used to set XScopedEventSelector::event_manager_. If |this| is
68 // destroyed before any XScopedEventSelector, the |event_manager_| will become
69 // invalidated.
70 base::WeakPtrFactory<XWindowEventManager> weak_ptr_factory_;
71
68 DISALLOW_COPY_AND_ASSIGN(XWindowEventManager); 72 DISALLOW_COPY_AND_ASSIGN(XWindowEventManager);
69 }; 73 };
70 74
71 } // namespace ui 75 } // namespace ui
72 76
73 #endif // UI_BASE_X_X11_FOREIGN_WINDOW_MANAGER_H_ 77 #endif // UI_BASE_X_X11_WINDOW_EVENT_MANAGER_H_
OLDNEW
« no previous file with comments | « ui/base/clipboard/clipboard_aurax11.cc ('k') | ui/base/x/x11_window_event_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698