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
3 // found in the LICENSE file.
5 #ifndef UI_BASE_X_SELECTION_REQUESTOR_H_
6 #define UI_BASE_X_SELECTION_REQUESTOR_H_
10 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class.
15 #include "base/basictypes.h"
16 #include "base/callback.h"
17 #include "base/memory/ref_counted_memory.h"
18 #include "ui/base/ui_export.h"
19 #include "ui/gfx/x/x11_atom_cache.h"
24 // Requests and later receives data from the X11 server through the selection
27 // X11 uses a system called "selections" to implement clipboards and drag and
28 // drop. This class interprets messages from the statefull selection request
29 // API. SelectionRequestor should only deal with the X11 details; it does not
30 // implement per-component fast-paths.
31 class UI_EXPORT SelectionRequestor {
33 SelectionRequestor(Display* xdisplay,
35 ::Atom selection_name);
36 ~SelectionRequestor();
38 // Does the work of requesting |target| from the selection we handle,
39 // spinning up the nested message loop, and reading the resulting data
40 // back. |out_data| is allocated with the X allocator and must be freed with
41 // XFree(). |out_data_bytes| is the length in machine chars, while
42 // |out_data_items| is the length in |out_type| items.
43 bool PerformBlockingConvertSelection(
45 scoped_refptr<base::RefCountedMemory>* out_data,
46 size_t* out_data_bytes,
47 size_t* out_data_items,
50 // Returns the first of |types| offered by the current selection holder, or
51 // returns NULL if none of those types are available.
52 SelectionData RequestAndWaitForTypes(const std::vector< ::Atom>& types);
54 // It is our owner's responsibility to plumb X11 SelectionNotify events on
56 void OnSelectionNotify(const XSelectionEvent& event);
63 // True if we're currently running a nested message loop, waiting for data to
64 // come back from the X server.
67 // The X11 selection that this instance communicates on.
68 ::Atom selection_name_;
70 // Data to the current XConvertSelection request. Used for error detection;
71 // we verify it on the return message.
72 ::Atom current_target_;
74 // The property in the returning SelectNotify message is used to signal
75 // success. If None, our request failed somehow. If equal to the property
76 // atom that we sent in the XConvertSelection call, we can read that property
77 // on |x_window_| for the requested data.
78 ::Atom returned_property_;
80 // Called to terminate the nested message loop.
81 base::Closure quit_closure_;
83 X11AtomCache atom_cache_;
85 DISALLOW_COPY_AND_ASSIGN(SelectionRequestor);
90 #endif // UI_BASE_X_SELECTION_REQUESTOR_H_