OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #ifndef UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_AURAX11_H_ | |
6 #define UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_AURAX11_H_ | |
7 | |
8 #include <X11/Xlib.h> | |
9 | |
10 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. | |
11 #undef RootWindow | |
12 | |
13 #include <map> | |
14 | |
15 #include "base/files/file_path.h" | |
16 #include "base/message_pump_dispatcher.h" | |
17 #include "base/pickle.h" | |
18 #include "googleurl/src/gurl.h" | |
19 #include "ui/base/dragdrop/os_exchange_data.h" | |
20 #include "ui/base/x/selection_owner.h" | |
21 #include "ui/base/x/selection_requestor.h" | |
22 #include "ui/base/x/x11_atom_cache.h" | |
23 #include "ui/gfx/image/image_skia.h" | |
24 #include "ui/gfx/vector2d.h" | |
25 | |
26 namespace ui { | |
27 | |
28 class Clipboard; | |
29 class DesktopSelectionProviderAuraX11; | |
30 | |
31 // OSExchangeData::Provider implementation for aura on linux. | |
32 class UI_EXPORT OSExchangeDataProviderAuraX11 | |
33 : public OSExchangeData::Provider, | |
34 public base::MessagePumpDispatcher { | |
35 public: | |
36 // Creates a Provider for drag receiving. |x_window| is the window the cursor | |
37 // is over, and |targets| are the MIME types being offered by the other | |
38 // process. | |
39 OSExchangeDataProviderAuraX11(ui::DesktopSelectionProviderAuraX11* provider, | |
40 ::Window x_window, | |
41 const std::vector< ::Atom> targets); | |
42 | |
43 // Creates a Provider for sending drag information. This creates its own, | |
44 // hidden X11 window to own send data. | |
45 OSExchangeDataProviderAuraX11(); | |
46 | |
47 virtual ~OSExchangeDataProviderAuraX11(); | |
48 | |
49 // If we are receiving, we receive messages from a DesktopRootWindowHost | |
50 // through this interface. | |
51 void OnSelectionNotify(const XSelectionEvent& event); | |
52 | |
53 // Overridden from OSExchangeData::Provider: | |
54 virtual void SetString(const string16& data) OVERRIDE; | |
55 virtual void SetURL(const GURL& url, const string16& title) OVERRIDE; | |
56 virtual void SetFilename(const base::FilePath& path) OVERRIDE; | |
57 virtual void SetFilenames( | |
58 const std::vector<OSExchangeData::FileInfo>& filenames) OVERRIDE; | |
59 virtual void SetPickledData(OSExchangeData::CustomFormat format, | |
60 const Pickle& data) OVERRIDE; | |
61 virtual bool GetString(string16* data) const OVERRIDE; | |
62 virtual bool GetURLAndTitle(GURL* url, string16* title) const OVERRIDE; | |
63 virtual bool GetFilename(base::FilePath* path) const OVERRIDE; | |
64 virtual bool GetFilenames( | |
65 std::vector<OSExchangeData::FileInfo>* filenames) const OVERRIDE; | |
66 virtual bool GetPickledData(OSExchangeData::CustomFormat format, | |
67 Pickle* data) const OVERRIDE; | |
68 virtual bool HasString() const OVERRIDE; | |
69 virtual bool HasURL() const OVERRIDE; | |
70 virtual bool HasFile() const OVERRIDE; | |
71 virtual bool HasCustomFormat( | |
72 OSExchangeData::CustomFormat format) const OVERRIDE; | |
73 | |
74 virtual void SetHtml(const string16& html, const GURL& base_url) OVERRIDE; | |
75 virtual bool GetHtml(string16* html, GURL* base_url) const OVERRIDE; | |
76 virtual bool HasHtml() const OVERRIDE; | |
77 virtual void SetDragImage(const gfx::ImageSkia& image, | |
78 const gfx::Vector2d& cursor_offset) OVERRIDE; | |
79 virtual const gfx::ImageSkia& GetDragImage() const OVERRIDE; | |
80 virtual const gfx::Vector2d& GetDragImageOffset() const OVERRIDE; | |
81 | |
82 // Overridden from base::MessagePumpDispatcher: | |
83 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE; | |
84 | |
85 private: | |
86 typedef std::map<OSExchangeData::CustomFormat, Pickle> PickleData; | |
87 | |
88 // Returns true if |formats_| contains a string format and the string can be | |
89 // parsed as a URL. | |
90 bool GetPlainTextURL(GURL* url) const;; | |
sky
2013/04/12 20:12:11
;; -> ;
| |
91 | |
92 // Drag image and offset data. | |
93 gfx::ImageSkia drag_image_; | |
94 gfx::Vector2d drag_image_offset_; | |
95 | |
96 // Our X11 state. | |
97 Display* x_display_; | |
98 ::Window x_root_window_; | |
99 | |
100 // In X11, because the IPC parts of drag operations are implemented by | |
101 // XSelection, we require an x11 window to receive drag messages on. The | |
102 // OSExchangeDataProvider system is modeled on the Windows implementation, | |
103 // which does not require a window. We only sometimes have a valid window | |
104 // available (in the case of drag receiving). Othertimes, we need to create | |
105 // our own xwindow just to receive events on it. | |
106 bool own_window_; | |
sky
2013/04/12 20:12:11
const
| |
107 | |
108 // When we don't own the window, we keep track of the object that does so we | |
109 // can receive messages from it. | |
110 ui::DesktopSelectionProviderAuraX11* selection_event_provider_; | |
111 | |
112 ::Window x_window_; | |
113 | |
114 X11AtomCache atom_cache_; | |
115 | |
116 mutable SelectionRequestor selection_requestor_; | |
117 mutable SelectionOwner selection_owner_; | |
118 | |
119 // The mime types we have been offered by the source window. | |
120 std::vector< ::Atom> targets_; | |
121 | |
122 DISALLOW_COPY_AND_ASSIGN(OSExchangeDataProviderAuraX11); | |
123 }; | |
124 | |
125 } // namespace ui | |
126 | |
127 #endif // UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_AURAX11_H_ | |
OLD | NEW |