OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_AURAX11_H_ | 5 #ifndef UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_AURAX11_H_ |
6 #define UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_AURAX11_H_ | 6 #define UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_AURAX11_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 <map> | 13 #include <map> |
14 | 14 |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/message_pump_dispatcher.h" | 16 #include "base/message_pump_dispatcher.h" |
17 #include "base/pickle.h" | 17 #include "base/pickle.h" |
18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
19 #include "ui/base/dragdrop/os_exchange_data.h" | 19 #include "ui/base/dragdrop/os_exchange_data.h" |
20 #include "ui/base/x/selection_owner.h" | 20 #include "ui/base/x/selection_owner.h" |
21 #include "ui/base/x/selection_requestor.h" | 21 #include "ui/base/x/selection_requestor.h" |
22 #include "ui/base/x/x11_atom_cache.h" | 22 #include "ui/base/x/x11_atom_cache.h" |
23 #include "ui/gfx/image/image_skia.h" | 23 #include "ui/gfx/image/image_skia.h" |
24 #include "ui/gfx/vector2d.h" | 24 #include "ui/gfx/vector2d.h" |
25 | 25 |
26 namespace ui { | 26 namespace ui { |
27 | 27 |
28 class Clipboard; | 28 class Clipboard; |
29 class DesktopSelectionProviderAuraX11; | |
30 | 29 |
31 // OSExchangeData::Provider implementation for aura on linux. | 30 // OSExchangeData::Provider implementation for aura on linux. |
32 class UI_EXPORT OSExchangeDataProviderAuraX11 | 31 class UI_EXPORT OSExchangeDataProviderAuraX11 |
33 : public OSExchangeData::Provider, | 32 : public OSExchangeData::Provider, |
34 public base::MessagePumpDispatcher { | 33 public base::MessagePumpDispatcher { |
35 public: | 34 public: |
36 // Creates a Provider for drag receiving. |x_window| is the window the cursor | 35 // |x_window| is the window the cursor is over, and |targets| are the MIME |
Daniel Erat
2013/06/17 22:09:57
nit: update this comment to remove stale mention o
| |
37 // is over, and |targets| are the MIME types being offered by the other | 36 // types being offered by the other process. |
38 // process. | 37 OSExchangeDataProviderAuraX11(::Window x_window, |
39 OSExchangeDataProviderAuraX11(ui::DesktopSelectionProviderAuraX11* provider, | 38 SelectionFormatMap* selection); |
40 ::Window x_window, | |
41 const std::vector< ::Atom> targets); | |
42 | 39 |
43 // Creates a Provider for sending drag information. This creates its own, | 40 // Creates a Provider for sending drag information. This creates its own, |
44 // hidden X11 window to own send data. | 41 // hidden X11 window to own send data. |
45 OSExchangeDataProviderAuraX11(); | 42 OSExchangeDataProviderAuraX11(); |
46 | 43 |
47 virtual ~OSExchangeDataProviderAuraX11(); | 44 virtual ~OSExchangeDataProviderAuraX11(); |
48 | 45 |
49 // If we are receiving, we receive messages from a DesktopRootWindowHost | 46 // After all the Set* methods have built up the data we're offering, call |
50 // through this interface. | 47 // this to |
Daniel Erat
2013/06/17 22:09:57
nit: fix this comment
| |
51 void OnSelectionNotify(const XSelectionEvent& event); | 48 void TakeOwnershipOfSelection() const; |
49 | |
50 // Retrieves a list of types we're offering. Noop if we haven't taken the | |
51 // selection. | |
52 void RetrieveTargets(std::vector<Atom>* targets) const; | |
53 | |
54 // Makes a copy of the format map currently being offered. | |
55 SelectionFormatMap* CloneFormatMap() const; | |
52 | 56 |
53 // Overridden from OSExchangeData::Provider: | 57 // Overridden from OSExchangeData::Provider: |
54 virtual void SetString(const string16& data) OVERRIDE; | 58 virtual void SetString(const string16& data) OVERRIDE; |
55 virtual void SetURL(const GURL& url, const string16& title) OVERRIDE; | 59 virtual void SetURL(const GURL& url, const string16& title) OVERRIDE; |
56 virtual void SetFilename(const base::FilePath& path) OVERRIDE; | 60 virtual void SetFilename(const base::FilePath& path) OVERRIDE; |
57 virtual void SetFilenames( | 61 virtual void SetFilenames( |
58 const std::vector<OSExchangeData::FileInfo>& filenames) OVERRIDE; | 62 const std::vector<OSExchangeData::FileInfo>& filenames) OVERRIDE; |
59 virtual void SetPickledData(const OSExchangeData::CustomFormat& format, | 63 virtual void SetPickledData(const OSExchangeData::CustomFormat& format, |
60 const Pickle& data) OVERRIDE; | 64 const Pickle& data) OVERRIDE; |
61 virtual bool GetString(string16* data) const OVERRIDE; | 65 virtual bool GetString(string16* data) const OVERRIDE; |
(...skipping 20 matching lines...) Expand all Loading... | |
82 // Overridden from base::MessagePumpDispatcher: | 86 // Overridden from base::MessagePumpDispatcher: |
83 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE; | 87 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE; |
84 | 88 |
85 private: | 89 private: |
86 typedef std::map<OSExchangeData::CustomFormat, Pickle> PickleData; | 90 typedef std::map<OSExchangeData::CustomFormat, Pickle> PickleData; |
87 | 91 |
88 // Returns true if |formats_| contains a string format and the string can be | 92 // Returns true if |formats_| contains a string format and the string can be |
89 // parsed as a URL. | 93 // parsed as a URL. |
90 bool GetPlainTextURL(GURL* url) const; | 94 bool GetPlainTextURL(GURL* url) const; |
91 | 95 |
96 // Returns the targets in |format_map_|. | |
97 std::vector< ::Atom> GetTargets() const; | |
98 | |
92 // Drag image and offset data. | 99 // Drag image and offset data. |
93 gfx::ImageSkia drag_image_; | 100 gfx::ImageSkia drag_image_; |
94 gfx::Vector2d drag_image_offset_; | 101 gfx::Vector2d drag_image_offset_; |
95 | 102 |
96 // Our X11 state. | 103 // Our X11 state. |
97 Display* x_display_; | 104 Display* x_display_; |
98 ::Window x_root_window_; | 105 ::Window x_root_window_; |
99 | 106 |
100 // In X11, because the IPC parts of drag operations are implemented by | 107 // 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 | 108 // XSelection, we require an x11 window to receive drag messages on. The |
102 // OSExchangeDataProvider system is modeled on the Windows implementation, | 109 // OSExchangeDataProvider system is modeled on the Windows implementation, |
103 // which does not require a window. We only sometimes have a valid window | 110 // which does not require a window. We only sometimes have a valid window |
104 // available (in the case of drag receiving). Other times, we need to create | 111 // available (in the case of drag receiving). Other times, we need to create |
105 // our own xwindow just to receive events on it. | 112 // our own xwindow just to receive events on it. |
106 const bool own_window_; | 113 const bool own_window_; |
107 | 114 |
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_; | 115 ::Window x_window_; |
113 | 116 |
114 X11AtomCache atom_cache_; | 117 X11AtomCache atom_cache_; |
115 | 118 |
116 mutable SelectionRequestor selection_requestor_; | 119 // A representation of data. This is either passed to us from the other |
120 // process, or build up through a sequence of Set*() calls. It can be passed | |
Daniel Erat
2013/06/17 22:09:57
nit: s/build/built/
| |
121 // to |selection_owner_| when we take the selection. | |
122 scoped_ptr<SelectionFormatMap> format_map_; | |
123 | |
124 // Takes a snapshot of |format_map_| and offers it to other windows. | |
117 mutable SelectionOwner selection_owner_; | 125 mutable SelectionOwner selection_owner_; |
118 | 126 |
119 // The mime types we have been offered by the source window. | |
120 std::vector< ::Atom> targets_; | |
121 | |
122 DISALLOW_COPY_AND_ASSIGN(OSExchangeDataProviderAuraX11); | 127 DISALLOW_COPY_AND_ASSIGN(OSExchangeDataProviderAuraX11); |
123 }; | 128 }; |
124 | 129 |
125 } // namespace ui | 130 } // namespace ui |
126 | 131 |
127 #endif // UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_AURAX11_H_ | 132 #endif // UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_AURAX11_H_ |
OLD | NEW |