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_OWNER_H_
6 #define UI_BASE_X_SELECTION_OWNER_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 "ui/base/ui_export.h"
18 #include "ui/base/x/selection_utils.h"
19 #include "ui/gfx/x/x11_atom_cache.h"
23 // Owns a specific X11 selection on an X window.
25 // The selection owner object keeps track of which xwindow is the current
26 // owner, and when its |xwindow_|, offers different data types to other
28 class UI_EXPORT SelectionOwner {
30 SelectionOwner(Display* xdisplay,
32 ::Atom selection_name);
35 // Returns the current selection data. Useful for fast paths.
36 const SelectionFormatMap& selection_format_map() { return format_map_; }
38 // Retrieves a list of types we're offering.
39 void RetrieveTargets(std::vector<Atom>* targets);
41 // Attempts to take ownership of the selection. If we're successful, present
42 // |data| to other windows.
43 void TakeOwnershipOfSelection(const SelectionFormatMap& data);
45 // Releases the selection (if we own it) and clears any data we own.
48 // It is our owner's responsibility to plumb X11 events on |xwindow_| to us.
49 void OnSelectionRequest(const XSelectionRequestEvent& event);
50 void OnSelectionClear(const XSelectionClearEvent& event);
51 // TODO(erg): Do we also need to follow PropertyNotify events? We currently
52 // don't, but there were open todos in the previous implementation.
59 // The X11 selection that this instance communicates on.
60 ::Atom selection_name_;
62 // The data we are currently serving.
63 SelectionFormatMap format_map_;
65 X11AtomCache atom_cache_;
67 DISALLOW_COPY_AND_ASSIGN(SelectionOwner);
72 #endif // UI_BASE_X_SELECTION_OWNER_H_