OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_SELECTION_REQUESTOR_H_ | 5 #ifndef UI_BASE_X_SELECTION_REQUESTOR_H_ |
6 #define UI_BASE_X_SELECTION_REQUESTOR_H_ | 6 #define UI_BASE_X_SELECTION_REQUESTOR_H_ |
7 | 7 |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 | 9 |
10 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. | 10 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. |
11 #undef RootWindow | 11 #undef RootWindow |
12 | 12 |
13 #include <list> | 13 #include <list> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
17 #include "base/callback.h" | 17 #include "base/callback.h" |
18 #include "base/event_types.h" | |
18 #include "base/memory/ref_counted_memory.h" | 19 #include "base/memory/ref_counted_memory.h" |
19 #include "ui/base/ui_base_export.h" | 20 #include "ui/base/ui_base_export.h" |
20 #include "ui/gfx/x/x11_atom_cache.h" | 21 #include "ui/gfx/x/x11_atom_cache.h" |
21 | 22 |
23 typedef unsigned long Atom; | |
24 typedef unsigned long XID; | |
25 typedef struct _XDisplay XDisplay; | |
Daniel Erat
2014/07/16 03:03:13
can you include ui/gfx/x/x11_types.h instead (and
| |
26 | |
22 namespace ui { | 27 namespace ui { |
23 class PlatformEventDispatcher; | 28 class PlatformEventDispatcher; |
24 class SelectionData; | 29 class SelectionData; |
25 | 30 |
26 // Requests and later receives data from the X11 server through the selection | 31 // Requests and later receives data from the X11 server through the selection |
27 // system. | 32 // system. |
28 // | 33 // |
29 // X11 uses a system called "selections" to implement clipboards and drag and | 34 // X11 uses a system called "selections" to implement clipboards and drag and |
30 // drop. This class interprets messages from the statefull selection request | 35 // drop. This class interprets messages from the statefull selection request |
31 // API. SelectionRequestor should only deal with the X11 details; it does not | 36 // API. SelectionRequestor should only deal with the X11 details; it does not |
32 // implement per-component fast-paths. | 37 // implement per-component fast-paths. |
33 class UI_BASE_EXPORT SelectionRequestor { | 38 class UI_BASE_EXPORT SelectionRequestor { |
34 public: | 39 public: |
35 SelectionRequestor(Display* xdisplay, | 40 SelectionRequestor(XDisplay* xdisplay, |
36 ::Window xwindow, | 41 XID xwindow, |
37 ::Atom selection_name, | 42 Atom selection_name, |
38 PlatformEventDispatcher* dispatcher); | 43 PlatformEventDispatcher* dispatcher); |
39 ~SelectionRequestor(); | 44 ~SelectionRequestor(); |
40 | 45 |
41 // Does the work of requesting |target| from the selection we handle, | 46 // Does the work of requesting |target| from the selection we handle, |
42 // spinning up the nested message loop, and reading the resulting data | 47 // spinning up the nested message loop, and reading the resulting data |
43 // back. The result is stored in |out_data|. | 48 // back. The result is stored in |out_data|. |
44 // |out_data_items| is the length of |out_data| in |out_type| items. | 49 // |out_data_items| is the length of |out_data| in |out_type| items. |
45 bool PerformBlockingConvertSelection( | 50 bool PerformBlockingConvertSelection( |
46 ::Atom target, | 51 Atom target, |
47 scoped_refptr<base::RefCountedMemory>* out_data, | 52 scoped_refptr<base::RefCountedMemory>* out_data, |
48 size_t* out_data_items, | 53 size_t* out_data_items, |
49 ::Atom* out_type); | 54 Atom* out_type); |
50 | 55 |
51 // Requests |target| from the selection that we handle, passing |parameter| | 56 // Requests |target| from the selection that we handle, passing |parameter| |
52 // as a parameter to XConvertSelection(). | 57 // as a parameter to XConvertSelection(). |
53 void PerformBlockingConvertSelectionWithParameter( | 58 void PerformBlockingConvertSelectionWithParameter( |
54 ::Atom target, | 59 Atom target, |
55 const std::vector< ::Atom>& parameter); | 60 const std::vector<Atom>& parameter); |
56 | 61 |
57 // Returns the first of |types| offered by the current selection holder, or | 62 // Returns the first of |types| offered by the current selection holder, or |
58 // returns NULL if none of those types are available. | 63 // returns NULL if none of those types are available. |
59 SelectionData RequestAndWaitForTypes(const std::vector< ::Atom>& types); | 64 SelectionData RequestAndWaitForTypes(const std::vector<Atom>& types); |
60 | 65 |
61 // It is our owner's responsibility to plumb X11 SelectionNotify events on | 66 // It is our owner's responsibility to plumb X11 SelectionNotify events on |
62 // |xwindow_| to us. | 67 // |xwindow_| to us. |
63 void OnSelectionNotify(const XSelectionEvent& event); | 68 void OnSelectionNotify(const XEvent& event); |
64 | 69 |
65 private: | 70 private: |
66 // A request that has been issued and we are waiting for a response to. | 71 // A request that has been issued and we are waiting for a response to. |
67 struct PendingRequest { | 72 struct PendingRequest { |
68 explicit PendingRequest(Atom target); | 73 explicit PendingRequest(Atom target); |
69 ~PendingRequest(); | 74 ~PendingRequest(); |
70 | 75 |
71 // Data to the current XConvertSelection request. Used for error detection; | 76 // Data to the current XConvertSelection request. Used for error detection; |
72 // we verify it on the return message. | 77 // we verify it on the return message. |
73 ::Atom target; | 78 Atom target; |
74 | 79 |
75 // Called to terminate the nested message loop. | 80 // Called to terminate the nested message loop. |
76 base::Closure quit_closure; | 81 base::Closure quit_closure; |
77 | 82 |
78 // The property in the returning SelectNotify message is used to signal | 83 // The property in the returning SelectNotify message is used to signal |
79 // success. If None, our request failed somehow. If equal to the property | 84 // success. If None, our request failed somehow. If equal to the property |
80 // atom that we sent in the XConvertSelection call, we can read that | 85 // atom that we sent in the XConvertSelection call, we can read that |
81 // property on |x_window_| for the requested data. | 86 // property on |x_window_| for the requested data. |
82 ::Atom returned_property; | 87 Atom returned_property; |
83 | 88 |
84 // Set to true when return_property is populated. | 89 // Set to true when return_property is populated. |
85 bool returned; | 90 bool returned; |
86 }; | 91 }; |
87 | 92 |
88 // Blocks till SelectionNotify is received for the target specified in | 93 // Blocks till SelectionNotify is received for the target specified in |
89 // |request|. | 94 // |request|. |
90 void BlockTillSelectionNotifyForRequest(PendingRequest* request); | 95 void BlockTillSelectionNotifyForRequest(PendingRequest* request); |
91 | 96 |
92 // Our X11 state. | 97 // Our X11 state. |
93 Display* x_display_; | 98 XDisplay* x_display_; |
94 ::Window x_window_; | 99 XID x_window_; |
95 | 100 |
96 // The X11 selection that this instance communicates on. | 101 // The X11 selection that this instance communicates on. |
97 ::Atom selection_name_; | 102 Atom selection_name_; |
98 | 103 |
99 // Dispatcher which handles SelectionNotify and SelectionRequest for | 104 // Dispatcher which handles SelectionNotify and SelectionRequest for |
100 // |selection_name_|. PerformBlockingConvertSelection() calls the | 105 // |selection_name_|. PerformBlockingConvertSelection() calls the |
101 // dispatcher directly if PerformBlockingConvertSelection() is called after | 106 // dispatcher directly if PerformBlockingConvertSelection() is called after |
102 // the PlatformEventSource is destroyed. | 107 // the PlatformEventSource is destroyed. |
103 // Not owned. | 108 // Not owned. |
104 PlatformEventDispatcher* dispatcher_; | 109 PlatformEventDispatcher* dispatcher_; |
105 | 110 |
106 // A list of requests for which we are waiting for responses. | 111 // A list of requests for which we are waiting for responses. |
107 std::list<PendingRequest*> pending_requests_; | 112 std::list<PendingRequest*> pending_requests_; |
108 | 113 |
109 X11AtomCache atom_cache_; | 114 X11AtomCache atom_cache_; |
110 | 115 |
111 DISALLOW_COPY_AND_ASSIGN(SelectionRequestor); | 116 DISALLOW_COPY_AND_ASSIGN(SelectionRequestor); |
112 }; | 117 }; |
113 | 118 |
114 } // namespace ui | 119 } // namespace ui |
115 | 120 |
116 #endif // UI_BASE_X_SELECTION_REQUESTOR_H_ | 121 #endif // UI_BASE_X_SELECTION_REQUESTOR_H_ |
OLD | NEW |