1 // Copyright (c) 2012 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_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_AURAX11_H_
6 #define UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_AURAX11_H_
10 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class.
15 #include "base/files/file_path.h"
16 #include "base/message_loop/message_pump_dispatcher.h"
17 #include "base/pickle.h"
18 #include "ui/base/dragdrop/os_exchange_data.h"
19 #include "ui/base/x/selection_owner.h"
20 #include "ui/base/x/selection_requestor.h"
21 #include "ui/base/x/selection_utils.h"
22 #include "ui/gfx/image/image_skia.h"
23 #include "ui/gfx/vector2d.h"
24 #include "ui/gfx/x/x11_atom_cache.h"
30 class OSExchangeDataProviderAuraX11Test
;
32 // OSExchangeData::Provider implementation for aura on linux.
33 class UI_BASE_EXPORT OSExchangeDataProviderAuraX11
34 : public OSExchangeData::Provider
,
35 public base::MessagePumpDispatcher
{
37 // |x_window| is the window the cursor is over, and |selection| is the set of
38 // data being offered.
39 OSExchangeDataProviderAuraX11(::Window x_window
,
40 const SelectionFormatMap
& selection
);
42 // Creates a Provider for sending drag information. This creates its own,
43 // hidden X11 window to own send data.
44 OSExchangeDataProviderAuraX11();
46 virtual ~OSExchangeDataProviderAuraX11();
48 // After all the Set* methods have built up the data we're offering, call
49 // this to take ownership of the XdndSelection clipboard.
50 void TakeOwnershipOfSelection() const;
52 // Retrieves a list of types we're offering. Noop if we haven't taken the
54 void RetrieveTargets(std::vector
<Atom
>* targets
) const;
56 // Makes a copy of the format map currently being offered.
57 SelectionFormatMap
GetFormatMap() const;
59 // Overridden from OSExchangeData::Provider:
60 virtual Provider
* Clone() const OVERRIDE
;
61 virtual void SetString(const base::string16
& data
) OVERRIDE
;
62 virtual void SetURL(const GURL
& url
, const base::string16
& title
) OVERRIDE
;
63 virtual void SetFilename(const base::FilePath
& path
) OVERRIDE
;
64 virtual void SetFilenames(
65 const std::vector
<OSExchangeData::FileInfo
>& filenames
) OVERRIDE
;
66 virtual void SetPickledData(const OSExchangeData::CustomFormat
& format
,
67 const Pickle
& pickle
) OVERRIDE
;
68 virtual bool GetString(base::string16
* data
) const OVERRIDE
;
69 virtual bool GetURLAndTitle(GURL
* url
, base::string16
* title
) const OVERRIDE
;
70 virtual bool GetFilename(base::FilePath
* path
) const OVERRIDE
;
71 virtual bool GetFilenames(
72 std::vector
<OSExchangeData::FileInfo
>* filenames
) const OVERRIDE
;
73 virtual bool GetPickledData(const OSExchangeData::CustomFormat
& format
,
74 Pickle
* pickle
) const OVERRIDE
;
75 virtual bool HasString() const OVERRIDE
;
76 virtual bool HasURL() const OVERRIDE
;
77 virtual bool HasFile() const OVERRIDE
;
78 virtual bool HasCustomFormat(const OSExchangeData::CustomFormat
& format
) const
81 virtual void SetHtml(const base::string16
& html
,
82 const GURL
& base_url
) OVERRIDE
;
83 virtual bool GetHtml(base::string16
* html
, GURL
* base_url
) const OVERRIDE
;
84 virtual bool HasHtml() const OVERRIDE
;
85 virtual void SetDragImage(const gfx::ImageSkia
& image
,
86 const gfx::Vector2d
& cursor_offset
) OVERRIDE
;
87 virtual const gfx::ImageSkia
& GetDragImage() const OVERRIDE
;
88 virtual const gfx::Vector2d
& GetDragImageOffset() const OVERRIDE
;
90 // Overridden from base::MessagePumpDispatcher:
91 virtual bool Dispatch(const base::NativeEvent
& event
) OVERRIDE
;
94 friend class OSExchangeDataProviderAuraX11Test
;
95 typedef std::map
<OSExchangeData::CustomFormat
, Pickle
> PickleData
;
97 // Returns true if |formats_| contains a string format and the string can be
99 bool GetPlainTextURL(GURL
* url
) const;
101 // Returns the targets in |format_map_|.
102 std::vector
< ::Atom
> GetTargets() const;
104 // Drag image and offset data.
105 gfx::ImageSkia drag_image_
;
106 gfx::Vector2d drag_image_offset_
;
110 ::Window x_root_window_
;
112 // In X11, because the IPC parts of drag operations are implemented by
113 // XSelection, we require an x11 window to receive drag messages on. The
114 // OSExchangeDataProvider system is modeled on the Windows implementation,
115 // which does not require a window. We only sometimes have a valid window
116 // available (in the case of drag receiving). Other times, we need to create
117 // our own xwindow just to receive events on it.
118 const bool own_window_
;
122 X11AtomCache atom_cache_
;
124 // A representation of data. This is either passed to us from the other
125 // process, or built up through a sequence of Set*() calls. It can be passed
126 // to |selection_owner_| when we take the selection.
127 SelectionFormatMap format_map_
;
129 // Takes a snapshot of |format_map_| and offers it to other windows.
130 mutable SelectionOwner selection_owner_
;
132 DISALLOW_COPY_AND_ASSIGN(OSExchangeDataProviderAuraX11
);
137 #endif // UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_AURAX11_H_