Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc

Issue 397223002: Enable copying long text to Chrome and pasting long text from Chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h" 5 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h"
6 6
7 #include <X11/Xatom.h> 7 #include <X11/Xatom.h>
8 8
9 #include "base/event_types.h" 9 #include "base/event_types.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "ui/aura/window.h" 12 #include "ui/aura/window.h"
13 #include "ui/aura/window_tree_host.h" 13 #include "ui/aura/window_tree_host.h"
14 #include "ui/base/clipboard/clipboard.h" 14 #include "ui/base/clipboard/clipboard.h"
15 #include "ui/base/dragdrop/drop_target_event.h" 15 #include "ui/base/dragdrop/drop_target_event.h"
16 #include "ui/base/dragdrop/os_exchange_data.h" 16 #include "ui/base/dragdrop/os_exchange_data.h"
17 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" 17 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h"
18 #include "ui/base/x/selection_utils.h" 18 #include "ui/base/x/selection_utils.h"
19 #include "ui/base/x/x11_foreign_window_manager.h"
19 #include "ui/base/x/x11_util.h" 20 #include "ui/base/x/x11_util.h"
20 #include "ui/events/event.h" 21 #include "ui/events/event.h"
21 #include "ui/events/platform/platform_event_source.h" 22 #include "ui/events/platform/platform_event_source.h"
22 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" 23 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h"
23 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h" 24 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h"
24 #include "ui/wm/public/drag_drop_client.h" 25 #include "ui/wm/public/drag_drop_client.h"
25 #include "ui/wm/public/drag_drop_delegate.h" 26 #include "ui/wm/public/drag_drop_delegate.h"
26 27
27 using aura::client::DragDropDelegate; 28 using aura::client::DragDropDelegate;
28 using ui::OSExchangeData; 29 using ui::OSExchangeData;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 135
135 // The atom cache owned by our parent. 136 // The atom cache owned by our parent.
136 ui::X11AtomCache* atom_cache_; 137 ui::X11AtomCache* atom_cache_;
137 138
138 // The XID of our chrome local aura window handling our events. 139 // The XID of our chrome local aura window handling our events.
139 ::Window local_window_; 140 ::Window local_window_;
140 141
141 // The XID of the window that's initiated the drag. 142 // The XID of the window that's initiated the drag.
142 unsigned long source_window_; 143 unsigned long source_window_;
143 144
145 // The DesktopDragDropClientAuraX11 for |source_window_| if |source_window_|
146 // belongs to a Chrome window.
147 DesktopDragDropClientAuraX11* source_client_;
148
149 // Used to unselect PropertyChangeMask on |source_window_| if |source_window_|
150 // does not belong to a Chrome window when X11DragContext is destroyed.
151 int foreign_window_manager_source_window_id_;
152
144 // The client we inform once we're done with requesting data. 153 // The client we inform once we're done with requesting data.
145 DesktopDragDropClientAuraX11* drag_drop_client_; 154 DesktopDragDropClientAuraX11* drag_drop_client_;
146 155
147 // Whether we're blocking the handling of an XdndPosition message by waiting 156 // Whether we're blocking the handling of an XdndPosition message by waiting
148 // for |unfetched_targets_| to be fetched. 157 // for |unfetched_targets_| to be fetched.
149 bool waiting_to_handle_position_; 158 bool waiting_to_handle_position_;
150 159
151 // Where the cursor is on screen. 160 // Where the cursor is on screen.
152 gfx::Point screen_point_; 161 gfx::Point screen_point_;
153 162
(...skipping 14 matching lines...) Expand all
168 DISALLOW_COPY_AND_ASSIGN(X11DragContext); 177 DISALLOW_COPY_AND_ASSIGN(X11DragContext);
169 }; 178 };
170 179
171 DesktopDragDropClientAuraX11::X11DragContext::X11DragContext( 180 DesktopDragDropClientAuraX11::X11DragContext::X11DragContext(
172 ui::X11AtomCache* atom_cache, 181 ui::X11AtomCache* atom_cache,
173 ::Window local_window, 182 ::Window local_window,
174 const XClientMessageEvent& event) 183 const XClientMessageEvent& event)
175 : atom_cache_(atom_cache), 184 : atom_cache_(atom_cache),
176 local_window_(local_window), 185 local_window_(local_window),
177 source_window_(event.data.l[0]), 186 source_window_(event.data.l[0]),
187 source_client_(
188 DesktopDragDropClientAuraX11::GetForWindow(source_window_)),
189 foreign_window_manager_source_window_id_(0),
178 drag_drop_client_(NULL), 190 drag_drop_client_(NULL),
179 waiting_to_handle_position_(false), 191 waiting_to_handle_position_(false),
180 suggested_action_(None) { 192 suggested_action_(None) {
181 bool get_types = ((event.data.l[1] & 1) != 0); 193 bool get_types = ((event.data.l[1] & 1) != 0);
182 194
183 if (get_types) { 195 if (get_types) {
184 if (!ui::GetAtomArrayProperty(source_window_, 196 if (!ui::GetAtomArrayProperty(source_window_,
185 "XdndTypeList", 197 "XdndTypeList",
186 &unfetched_targets_)) { 198 &unfetched_targets_)) {
187 return; 199 return;
188 } 200 }
189 } else { 201 } else {
190 // data.l[2,3,4] contain the first three types. Unused slots can be None. 202 // data.l[2,3,4] contain the first three types. Unused slots can be None.
191 for (int i = 0; i < 3; ++i) { 203 for (int i = 0; i < 3; ++i) {
192 if (event.data.l[2+i] != None) { 204 if (event.data.l[2+i] != None) {
193 unfetched_targets_.push_back(event.data.l[2+i]); 205 unfetched_targets_.push_back(event.data.l[2+i]);
194 } 206 }
195 } 207 }
196 } 208 }
197 209
198 DesktopDragDropClientAuraX11* client = 210 if (!source_client_) {
199 DesktopDragDropClientAuraX11::GetForWindow(source_window_);
200 if (!client) {
201 // The window doesn't have a DesktopDragDropClientAuraX11, that means it's 211 // The window doesn't have a DesktopDragDropClientAuraX11, that means it's
202 // created by some other process. Listen for messages on it. 212 // created by some other process. Listen for messages on it.
203 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); 213 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
204 XSelectInput(gfx::GetXDisplay(), source_window_, PropertyChangeMask); 214 foreign_window_manager_source_window_id_ =
215 ui::XForeignWindowManager::GetInstance()->RequestEvents(
216 source_window_, PropertyChangeMask);
205 217
206 // We must perform a full sync here because we could be racing 218 // We must perform a full sync here because we could be racing
207 // |source_window_|. 219 // |source_window_|.
208 XSync(gfx::GetXDisplay(), False); 220 XSync(gfx::GetXDisplay(), False);
209 } else { 221 } else {
210 // This drag originates from an aura window within our process. This means 222 // This drag originates from an aura window within our process. This means
211 // that we can shortcut the X11 server and ask the owning SelectionOwner 223 // that we can shortcut the X11 server and ask the owning SelectionOwner
212 // for the data it's offering. 224 // for the data it's offering.
213 fetched_targets_ = client->GetFormatMap(); 225 fetched_targets_ = source_client_->GetFormatMap();
214 unfetched_targets_.clear(); 226 unfetched_targets_.clear();
215 } 227 }
216 228
217 ReadActions(); 229 ReadActions();
218 } 230 }
219 231
220 DesktopDragDropClientAuraX11::X11DragContext::~X11DragContext() { 232 DesktopDragDropClientAuraX11::X11DragContext::~X11DragContext() {
221 // Unsubscribe from message events. 233 if (!source_client_) {
222 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); 234 // Unsubscribe from message events.
235 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
236 ui::XForeignWindowManager::GetInstance()->CancelRequest(
237 foreign_window_manager_source_window_id_);
238 }
223 } 239 }
224 240
225 void DesktopDragDropClientAuraX11::X11DragContext::OnStartXdndPositionMessage( 241 void DesktopDragDropClientAuraX11::X11DragContext::OnStartXdndPositionMessage(
226 DesktopDragDropClientAuraX11* client, 242 DesktopDragDropClientAuraX11* client,
227 ::Atom suggested_action, 243 ::Atom suggested_action,
228 ::Window source_window, 244 ::Window source_window,
229 const gfx::Point& screen_point) { 245 const gfx::Point& screen_point) {
230 DCHECK_EQ(source_window_, source_window); 246 DCHECK_EQ(source_window_, source_window);
231 suggested_action_ = suggested_action; 247 suggested_action_ = suggested_action;
232 248
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 if (!unfetched_targets_.empty()) { 292 if (!unfetched_targets_.empty()) {
277 RequestNextTarget(); 293 RequestNextTarget();
278 } else { 294 } else {
279 waiting_to_handle_position_ = false; 295 waiting_to_handle_position_ = false;
280 drag_drop_client_->CompleteXdndPosition(source_window_, screen_point_); 296 drag_drop_client_->CompleteXdndPosition(source_window_, screen_point_);
281 drag_drop_client_ = NULL; 297 drag_drop_client_ = NULL;
282 } 298 }
283 } 299 }
284 300
285 void DesktopDragDropClientAuraX11::X11DragContext::ReadActions() { 301 void DesktopDragDropClientAuraX11::X11DragContext::ReadActions() {
286 DesktopDragDropClientAuraX11* client = 302 if (!source_client_) {
287 DesktopDragDropClientAuraX11::GetForWindow(source_window_);
288 if (!client) {
289 std::vector<Atom> atom_array; 303 std::vector<Atom> atom_array;
290 if (!ui::GetAtomArrayProperty(source_window_, 304 if (!ui::GetAtomArrayProperty(source_window_,
291 "XdndActionList", 305 "XdndActionList",
292 &atom_array)) { 306 &atom_array)) {
293 actions_.clear(); 307 actions_.clear();
294 } else { 308 } else {
295 actions_.swap(atom_array); 309 actions_.swap(atom_array);
296 } 310 }
297 } else { 311 } else {
298 // We have a property notify set up for other windows in case they change 312 // We have a property notify set up for other windows in case they change
299 // their action list. Thankfully, the views interface is static and you 313 // their action list. Thankfully, the views interface is static and you
300 // can't change the action list after you enter StartDragAndDrop(). 314 // can't change the action list after you enter StartDragAndDrop().
301 actions_ = client->GetOfferedDragOperations(); 315 actions_ = source_client_->GetOfferedDragOperations();
302 } 316 }
303 } 317 }
304 318
305 int DesktopDragDropClientAuraX11::X11DragContext::GetDragOperation() const { 319 int DesktopDragDropClientAuraX11::X11DragContext::GetDragOperation() const {
306 int drag_operation = ui::DragDropTypes::DRAG_NONE; 320 int drag_operation = ui::DragDropTypes::DRAG_NONE;
307 for (std::vector<Atom>::const_iterator it = actions_.begin(); 321 for (std::vector<Atom>::const_iterator it = actions_.begin();
308 it != actions_.end(); ++it) { 322 it != actions_.end(); ++it) {
309 MaskOperation(*it, &drag_operation); 323 MaskOperation(*it, &drag_operation);
310 } 324 }
311 325
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 xev.xclient.window = dest_window; 1039 xev.xclient.window = dest_window;
1026 xev.xclient.data.l[0] = xwindow_; 1040 xev.xclient.data.l[0] = xwindow_;
1027 xev.xclient.data.l[1] = 0; 1041 xev.xclient.data.l[1] = 0;
1028 xev.xclient.data.l[2] = CurrentTime; 1042 xev.xclient.data.l[2] = CurrentTime;
1029 xev.xclient.data.l[3] = None; 1043 xev.xclient.data.l[3] = None;
1030 xev.xclient.data.l[4] = None; 1044 xev.xclient.data.l[4] = None;
1031 SendXClientEvent(dest_window, &xev); 1045 SendXClientEvent(dest_window, &xev);
1032 } 1046 }
1033 1047
1034 } // namespace views 1048 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698