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

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

Issue 2914103002: Remove usages of XInternAtom (Closed)
Patch Set: Address sadrul and sergeyu comments Created 3 years, 6 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
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <X11/Xatom.h> 9 #include <X11/Xatom.h>
10 10
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 constexpr int kMaxXdndVersion = 5; 68 constexpr int kMaxXdndVersion = 5;
69 69
70 constexpr int kWillAcceptDrop = 1; 70 constexpr int kWillAcceptDrop = 1;
71 constexpr int kWantFurtherPosEvents = 2; 71 constexpr int kWantFurtherPosEvents = 2;
72 72
73 // These actions have the same meaning as in the W3C Drag and Drop spec. 73 // These actions have the same meaning as in the W3C Drag and Drop spec.
74 const char kXdndActionCopy[] = "XdndActionCopy"; 74 const char kXdndActionCopy[] = "XdndActionCopy";
75 const char kXdndActionMove[] = "XdndActionMove"; 75 const char kXdndActionMove[] = "XdndActionMove";
76 const char kXdndActionLink[] = "XdndActionLink"; 76 const char kXdndActionLink[] = "XdndActionLink";
77 77
78 // "The target will do something that the source would not understand." The
79 // source only needs to provide a copy of the dragged data.
80 const char kXdndActionPrivate[] = "XdndActionPrivate";
81
82 // The target should ask the user what action it wants to perform. Intended to
83 // match Windows' right-click drag and drop, which shows a dropdown.
84 const char kXdndActionAsk[] = "XdndActionAsk";
85
86 // Triggers the XDS protocol. 78 // Triggers the XDS protocol.
87 const char kXdndActionDirectSave[] = "XdndActionDirectSave"; 79 const char kXdndActionDirectSave[] = "XdndActionDirectSave";
88 80
89 // Window property that will receive the drag and drop selection data. 81 // Window property that will receive the drag and drop selection data.
90 const char kChromiumDragReciever[] = "_CHROMIUM_DRAG_RECEIVER"; 82 const char kChromiumDragReciever[] = "_CHROMIUM_DRAG_RECEIVER";
91 83
92 // Window property that contains the possible actions that will be presented to 84 // Window property that contains the possible actions that will be presented to
93 // the user when the drag and drop action is kXdndActionAsk. 85 // the user when the drag and drop action is kXdndActionAsk.
94 const char kXdndActionList[] = "XdndActionList"; 86 const char kXdndActionList[] = "XdndActionList";
95 87
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // information. 140 // information.
149 // After the target optionally acquires selection information, it must tell the 141 // After the target optionally acquires selection information, it must tell the
150 // source if it can accept the drop via an XdndStatus message. 142 // source if it can accept the drop via an XdndStatus message.
151 const char kXdndPosition[] = "XdndPosition"; 143 const char kXdndPosition[] = "XdndPosition";
152 144
153 // Message sent by the XDND target in response to an XdndPosition message. 145 // Message sent by the XDND target in response to an XdndPosition message.
154 // The message informs the source if the target will accept the drop, and what 146 // The message informs the source if the target will accept the drop, and what
155 // action will be taken if the drop is accepted. 147 // action will be taken if the drop is accepted.
156 const char kXdndStatus[] = "XdndStatus"; 148 const char kXdndStatus[] = "XdndStatus";
157 149
158 const char* kAtomsToCache[] = {
159 kChromiumDragReciever,
160 kXdndActionAsk,
161 kXdndActionCopy,
162 kXdndActionDirectSave,
163 kXdndActionLink,
164 kXdndActionList,
165 kXdndActionMove,
166 kXdndActionPrivate,
167 kXdndAware,
168 kXdndDirectSave0,
169 kXdndDrop,
170 kXdndEnter,
171 kXdndFinished,
172 kXdndLeave,
173 kXdndPosition,
174 kXdndProxy,
175 kXdndSelection,
176 kXdndStatus,
177 kXdndTypeList,
178 ui::Clipboard::kMimeTypeText,
179 NULL
180 };
181
182 int XGetModifiers() { 150 int XGetModifiers() {
183 XDisplay* display = gfx::GetXDisplay(); 151 XDisplay* display = gfx::GetXDisplay();
184 152
185 XID root, child; 153 XID root, child;
186 int root_x, root_y, win_x, win_y; 154 int root_x, root_y, win_x, win_y;
187 unsigned int mask; 155 unsigned int mask;
188 XQueryPointer(display, 156 XQueryPointer(display,
189 DefaultRootWindow(display), 157 DefaultRootWindow(display),
190 &root, 158 &root,
191 &child, 159 &child,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } // namespace 203 } // namespace
236 204
237 namespace views { 205 namespace views {
238 206
239 DesktopDragDropClientAuraX11* 207 DesktopDragDropClientAuraX11*
240 DesktopDragDropClientAuraX11::g_current_drag_drop_client = NULL; 208 DesktopDragDropClientAuraX11::g_current_drag_drop_client = NULL;
241 209
242 class DesktopDragDropClientAuraX11::X11DragContext 210 class DesktopDragDropClientAuraX11::X11DragContext
243 : public ui::PlatformEventDispatcher { 211 : public ui::PlatformEventDispatcher {
244 public: 212 public:
245 X11DragContext(ui::X11AtomCache* atom_cache, 213 X11DragContext(::Window local_window, const XClientMessageEvent& event);
246 ::Window local_window,
247 const XClientMessageEvent& event);
248 ~X11DragContext() override; 214 ~X11DragContext() override;
249 215
250 // When we receive an XdndPosition message, we need to have all the data 216 // When we receive an XdndPosition message, we need to have all the data
251 // copied from the other window before we process the XdndPosition 217 // copied from the other window before we process the XdndPosition
252 // message. If we have that data already, dispatch immediately. Otherwise, 218 // message. If we have that data already, dispatch immediately. Otherwise,
253 // delay dispatching until we do. 219 // delay dispatching until we do.
254 void OnXdndPositionMessage(DesktopDragDropClientAuraX11* client, 220 void OnXdndPositionMessage(DesktopDragDropClientAuraX11* client,
255 ::Atom suggested_action, 221 ::Atom suggested_action,
256 ::Window source_window, 222 ::Window source_window,
257 ::Time time_stamp, 223 ::Time time_stamp,
(...skipping 22 matching lines...) Expand all
280 void RequestNextTarget(); 246 void RequestNextTarget();
281 247
282 // Masks the X11 atom |xdnd_operation|'s views representation onto 248 // Masks the X11 atom |xdnd_operation|'s views representation onto
283 // |drag_operation|. 249 // |drag_operation|.
284 void MaskOperation(::Atom xdnd_operation, int* drag_operation) const; 250 void MaskOperation(::Atom xdnd_operation, int* drag_operation) const;
285 251
286 // ui::PlatformEventDispatcher: 252 // ui::PlatformEventDispatcher:
287 bool CanDispatchEvent(const ui::PlatformEvent& event) override; 253 bool CanDispatchEvent(const ui::PlatformEvent& event) override;
288 uint32_t DispatchEvent(const ui::PlatformEvent& event) override; 254 uint32_t DispatchEvent(const ui::PlatformEvent& event) override;
289 255
290 // The atom cache owned by our parent.
291 ui::X11AtomCache* atom_cache_;
292
293 // The XID of our chrome local aura window handling our events. 256 // The XID of our chrome local aura window handling our events.
294 ::Window local_window_; 257 ::Window local_window_;
295 258
296 // The XID of the window that's initiated the drag. 259 // The XID of the window that's initiated the drag.
297 unsigned long source_window_; 260 unsigned long source_window_;
298 261
299 // Events that we have selected on |source_window_|. 262 // Events that we have selected on |source_window_|.
300 std::unique_ptr<ui::XScopedEventSelector> source_window_events_; 263 std::unique_ptr<ui::XScopedEventSelector> source_window_events_;
301 264
302 // The DesktopDragDropClientAuraX11 for |source_window_| if |source_window_| 265 // The DesktopDragDropClientAuraX11 for |source_window_| if |source_window_|
(...skipping 26 matching lines...) Expand all
329 // use this, instead of the XdndActionList which is backed by |actions_|. 292 // use this, instead of the XdndActionList which is backed by |actions_|.
330 ::Atom suggested_action_; 293 ::Atom suggested_action_;
331 294
332 // Possible actions. 295 // Possible actions.
333 std::vector<::Atom> actions_; 296 std::vector<::Atom> actions_;
334 297
335 DISALLOW_COPY_AND_ASSIGN(X11DragContext); 298 DISALLOW_COPY_AND_ASSIGN(X11DragContext);
336 }; 299 };
337 300
338 DesktopDragDropClientAuraX11::X11DragContext::X11DragContext( 301 DesktopDragDropClientAuraX11::X11DragContext::X11DragContext(
339 ui::X11AtomCache* atom_cache,
340 ::Window local_window, 302 ::Window local_window,
341 const XClientMessageEvent& event) 303 const XClientMessageEvent& event)
342 : atom_cache_(atom_cache), 304 : local_window_(local_window),
343 local_window_(local_window),
344 source_window_(event.data.l[0]), 305 source_window_(event.data.l[0]),
345 source_client_( 306 source_client_(
346 DesktopDragDropClientAuraX11::GetForWindow(source_window_)), 307 DesktopDragDropClientAuraX11::GetForWindow(source_window_)),
347 drag_drop_client_(NULL), 308 drag_drop_client_(NULL),
348 waiting_to_handle_position_(false), 309 waiting_to_handle_position_(false),
349 suggested_action_(None) { 310 suggested_action_(None) {
350 if (!source_client_) { 311 if (!source_client_) {
351 bool get_types_from_property = ((event.data.l[1] & 1) != 0); 312 bool get_types_from_property = ((event.data.l[1] & 1) != 0);
352 313
353 if (get_types_from_property) { 314 if (get_types_from_property) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 } 384 }
424 385
425 void DesktopDragDropClientAuraX11::X11DragContext::RequestNextTarget() { 386 void DesktopDragDropClientAuraX11::X11DragContext::RequestNextTarget() {
426 DCHECK(!unfetched_targets_.empty()); 387 DCHECK(!unfetched_targets_.empty());
427 DCHECK(drag_drop_client_); 388 DCHECK(drag_drop_client_);
428 DCHECK(waiting_to_handle_position_); 389 DCHECK(waiting_to_handle_position_);
429 390
430 ::Atom target = unfetched_targets_.back(); 391 ::Atom target = unfetched_targets_.back();
431 unfetched_targets_.pop_back(); 392 unfetched_targets_.pop_back();
432 393
433 XConvertSelection(gfx::GetXDisplay(), 394 XConvertSelection(gfx::GetXDisplay(), ui::GetAtom(kXdndSelection), target,
434 atom_cache_->GetAtom(kXdndSelection), 395 ui::GetAtom(kChromiumDragReciever), local_window_,
435 target,
436 atom_cache_->GetAtom(kChromiumDragReciever),
437 local_window_,
438 position_time_stamp_); 396 position_time_stamp_);
439 } 397 }
440 398
441 void DesktopDragDropClientAuraX11::X11DragContext::OnSelectionNotify( 399 void DesktopDragDropClientAuraX11::X11DragContext::OnSelectionNotify(
442 const XSelectionEvent& event) { 400 const XSelectionEvent& event) {
443 if (!waiting_to_handle_position_) { 401 if (!waiting_to_handle_position_) {
444 // A misbehaved window may send SelectionNotify without us requesting data 402 // A misbehaved window may send SelectionNotify without us requesting data
445 // via XConvertSelection(). 403 // via XConvertSelection().
446 return; 404 return;
447 } 405 }
448 DCHECK(drag_drop_client_); 406 DCHECK(drag_drop_client_);
449 407
450 DVLOG(1) << "SelectionNotify, format " << event.target; 408 DVLOG(1) << "SelectionNotify, format " << event.target;
451 409
452 if (event.property != None) { 410 if (event.property != None) {
453 DCHECK_EQ(event.property, atom_cache_->GetAtom(kChromiumDragReciever)); 411 DCHECK_EQ(event.property, ui::GetAtom(kChromiumDragReciever));
454 412
455 scoped_refptr<base::RefCountedMemory> data; 413 scoped_refptr<base::RefCountedMemory> data;
456 ::Atom type = None; 414 ::Atom type = None;
457 if (ui::GetRawBytesOfProperty(local_window_, event.property, 415 if (ui::GetRawBytesOfProperty(local_window_, event.property,
458 &data, NULL, &type)) { 416 &data, NULL, &type)) {
459 fetched_targets_.Insert(event.target, data); 417 fetched_targets_.Insert(event.target, data);
460 } 418 }
461 } else { 419 } else {
462 // The source failed to convert the drop data to the format (target in X11 420 // The source failed to convert the drop data to the format (target in X11
463 // parlance) that we asked for. This happens, even though we only ask for 421 // parlance) that we asked for. This happens, even though we only ask for
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 } 459 }
502 460
503 MaskOperation(suggested_action_, &drag_operation); 461 MaskOperation(suggested_action_, &drag_operation);
504 462
505 return drag_operation; 463 return drag_operation;
506 } 464 }
507 465
508 void DesktopDragDropClientAuraX11::X11DragContext::MaskOperation( 466 void DesktopDragDropClientAuraX11::X11DragContext::MaskOperation(
509 ::Atom xdnd_operation, 467 ::Atom xdnd_operation,
510 int* drag_operation) const { 468 int* drag_operation) const {
511 if (xdnd_operation == atom_cache_->GetAtom(kXdndActionCopy)) 469 if (xdnd_operation == ui::GetAtom(kXdndActionCopy))
512 *drag_operation |= ui::DragDropTypes::DRAG_COPY; 470 *drag_operation |= ui::DragDropTypes::DRAG_COPY;
513 else if (xdnd_operation == atom_cache_->GetAtom(kXdndActionMove)) 471 else if (xdnd_operation == ui::GetAtom(kXdndActionMove))
514 *drag_operation |= ui::DragDropTypes::DRAG_MOVE; 472 *drag_operation |= ui::DragDropTypes::DRAG_MOVE;
515 else if (xdnd_operation == atom_cache_->GetAtom(kXdndActionLink)) 473 else if (xdnd_operation == ui::GetAtom(kXdndActionLink))
516 *drag_operation |= ui::DragDropTypes::DRAG_LINK; 474 *drag_operation |= ui::DragDropTypes::DRAG_LINK;
517 } 475 }
518 476
519 bool DesktopDragDropClientAuraX11::X11DragContext::CanDispatchEvent( 477 bool DesktopDragDropClientAuraX11::X11DragContext::CanDispatchEvent(
520 const ui::PlatformEvent& event) { 478 const ui::PlatformEvent& event) {
521 return event->xany.window == source_window_; 479 return event->xany.window == source_window_;
522 } 480 }
523 481
524 uint32_t DesktopDragDropClientAuraX11::X11DragContext::DispatchEvent( 482 uint32_t DesktopDragDropClientAuraX11::X11DragContext::DispatchEvent(
525 const ui::PlatformEvent& event) { 483 const ui::PlatformEvent& event) {
526 if (event->type == PropertyNotify && 484 if (event->type == PropertyNotify &&
527 event->xproperty.atom == atom_cache_->GetAtom(kXdndActionList)) { 485 event->xproperty.atom == ui::GetAtom(kXdndActionList)) {
528 ReadActions(); 486 ReadActions();
529 return ui::POST_DISPATCH_STOP_PROPAGATION; 487 return ui::POST_DISPATCH_STOP_PROPAGATION;
530 } 488 }
531 return ui::POST_DISPATCH_NONE; 489 return ui::POST_DISPATCH_NONE;
532 } 490 }
533 491
534 /////////////////////////////////////////////////////////////////////////////// 492 ///////////////////////////////////////////////////////////////////////////////
535 493
536 DesktopDragDropClientAuraX11::DesktopDragDropClientAuraX11( 494 DesktopDragDropClientAuraX11::DesktopDragDropClientAuraX11(
537 aura::Window* root_window, 495 aura::Window* root_window,
538 views::DesktopNativeCursorManager* cursor_manager, 496 views::DesktopNativeCursorManager* cursor_manager,
539 Display* xdisplay, 497 Display* xdisplay,
540 ::Window xwindow) 498 ::Window xwindow)
541 : root_window_(root_window), 499 : root_window_(root_window),
542 cursor_manager_(cursor_manager), 500 cursor_manager_(cursor_manager),
543 xdisplay_(xdisplay), 501 xdisplay_(xdisplay),
544 xwindow_(xwindow), 502 xwindow_(xwindow),
545 atom_cache_(xdisplay_, kAtomsToCache),
546 current_modifier_state_(ui::EF_NONE), 503 current_modifier_state_(ui::EF_NONE),
547 target_window_(NULL), 504 target_window_(NULL),
548 waiting_on_status_(false), 505 waiting_on_status_(false),
549 status_received_since_enter_(false), 506 status_received_since_enter_(false),
550 source_provider_(NULL), 507 source_provider_(NULL),
551 source_current_window_(None), 508 source_current_window_(None),
552 source_state_(SOURCE_STATE_OTHER), 509 source_state_(SOURCE_STATE_OTHER),
553 drag_operation_(0), 510 drag_operation_(0),
554 negotiated_operation_(ui::DragDropTypes::DRAG_NONE), 511 negotiated_operation_(ui::DragDropTypes::DRAG_NONE),
555 weak_ptr_factory_(this) { 512 weak_ptr_factory_(this) {
556 // Some tests change the DesktopDragDropClientAuraX11 associated with an 513 // Some tests change the DesktopDragDropClientAuraX11 associated with an
557 // |xwindow|. 514 // |xwindow|.
558 g_live_client_map.Get()[xwindow] = this; 515 g_live_client_map.Get()[xwindow] = this;
559 516
560 // Mark that we are aware of drag and drop concepts. 517 // Mark that we are aware of drag and drop concepts.
561 unsigned long xdnd_version = kMaxXdndVersion; 518 unsigned long xdnd_version = kMaxXdndVersion;
562 XChangeProperty(xdisplay_, xwindow_, atom_cache_.GetAtom(kXdndAware), 519 XChangeProperty(xdisplay_, xwindow_, ui::GetAtom(kXdndAware), XA_ATOM, 32,
563 XA_ATOM, 32, PropModeReplace, 520 PropModeReplace,
564 reinterpret_cast<unsigned char*>(&xdnd_version), 1); 521 reinterpret_cast<unsigned char*>(&xdnd_version), 1);
565 } 522 }
566 523
567 DesktopDragDropClientAuraX11::~DesktopDragDropClientAuraX11() { 524 DesktopDragDropClientAuraX11::~DesktopDragDropClientAuraX11() {
568 // This is necessary when the parent native widget gets destroyed while a drag 525 // This is necessary when the parent native widget gets destroyed while a drag
569 // operation is in progress. 526 // operation is in progress.
570 move_loop_->EndMoveLoop(); 527 move_loop_->EndMoveLoop();
571 NotifyDragLeave(); 528 NotifyDragLeave();
572 529
573 g_live_client_map.Get().erase(xwindow_); 530 g_live_client_map.Get().erase(xwindow_);
(...skipping 28 matching lines...) Expand all
602 if (version > kMaxXdndVersion) { 559 if (version > kMaxXdndVersion) {
603 // The XDND version used should be the minimum between the versions 560 // The XDND version used should be the minimum between the versions
604 // advertised by the source and the target. We advertise kMaxXdndVersion, so 561 // advertised by the source and the target. We advertise kMaxXdndVersion, so
605 // this should never happen when talking to an XDND-compliant application. 562 // this should never happen when talking to an XDND-compliant application.
606 LOG(ERROR) << "XdndEnter message discarded because its version is too new."; 563 LOG(ERROR) << "XdndEnter message discarded because its version is too new.";
607 return; 564 return;
608 } 565 }
609 566
610 // Make sure that we've run ~X11DragContext() before creating another one. 567 // Make sure that we've run ~X11DragContext() before creating another one.
611 target_current_context_.reset(); 568 target_current_context_.reset();
612 target_current_context_.reset( 569 target_current_context_.reset(new X11DragContext(xwindow_, event));
613 new X11DragContext(&atom_cache_, xwindow_, event));
614 570
615 // In the Windows implementation, we immediately call DesktopDropTargetWin:: 571 // In the Windows implementation, we immediately call DesktopDropTargetWin::
616 // Translate(). The XDND specification demands that we wait until we receive 572 // Translate(). The XDND specification demands that we wait until we receive
617 // an XdndPosition message before we use XConvertSelection or send an 573 // an XdndPosition message before we use XConvertSelection or send an
618 // XdndStatus message. 574 // XdndStatus message.
619 } 575 }
620 576
621 void DesktopDragDropClientAuraX11::OnXdndLeave( 577 void DesktopDragDropClientAuraX11::OnXdndLeave(
622 const XClientMessageEvent& event) { 578 const XClientMessageEvent& event) {
623 DVLOG(1) << "OnXdndLeave"; 579 DVLOG(1) << "OnXdndLeave";
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 719
764 drag_operation = delegate->OnPerformDrop(event); 720 drag_operation = delegate->OnPerformDrop(event);
765 } 721 }
766 722
767 target_window_->RemoveObserver(this); 723 target_window_->RemoveObserver(this);
768 target_window_ = NULL; 724 target_window_ = NULL;
769 } 725 }
770 726
771 XEvent xev; 727 XEvent xev;
772 xev.xclient.type = ClientMessage; 728 xev.xclient.type = ClientMessage;
773 xev.xclient.message_type = atom_cache_.GetAtom(kXdndFinished); 729 xev.xclient.message_type = ui::GetAtom(kXdndFinished);
774 xev.xclient.format = 32; 730 xev.xclient.format = 32;
775 xev.xclient.window = source_window; 731 xev.xclient.window = source_window;
776 xev.xclient.data.l[0] = xwindow_; 732 xev.xclient.data.l[0] = xwindow_;
777 xev.xclient.data.l[1] = (drag_operation != 0) ? 1 : 0; 733 xev.xclient.data.l[1] = (drag_operation != 0) ? 1 : 0;
778 xev.xclient.data.l[2] = DragOperationToAtom(drag_operation); 734 xev.xclient.data.l[2] = DragOperationToAtom(drag_operation);
779 735
780 SendXClientEvent(source_window, &xev); 736 SendXClientEvent(source_window, &xev);
781 } 737 }
782 738
783 void DesktopDragDropClientAuraX11::OnSelectionNotify( 739 void DesktopDragDropClientAuraX11::OnSelectionNotify(
(...skipping 28 matching lines...) Expand all
812 negotiated_operation_ = ui::DragDropTypes::DRAG_NONE; 768 negotiated_operation_ = ui::DragDropTypes::DRAG_NONE;
813 769
814 const ui::OSExchangeData::Provider* provider = &data.provider(); 770 const ui::OSExchangeData::Provider* provider = &data.provider();
815 source_provider_ = static_cast<const ui::OSExchangeDataProviderAuraX11*>( 771 source_provider_ = static_cast<const ui::OSExchangeDataProviderAuraX11*>(
816 provider); 772 provider);
817 773
818 source_provider_->TakeOwnershipOfSelection(); 774 source_provider_->TakeOwnershipOfSelection();
819 775
820 std::vector<::Atom> actions = GetOfferedDragOperations(); 776 std::vector<::Atom> actions = GetOfferedDragOperations();
821 if (!source_provider_->file_contents_name().empty()) { 777 if (!source_provider_->file_contents_name().empty()) {
822 actions.push_back(atom_cache_.GetAtom(kXdndActionDirectSave)); 778 actions.push_back(ui::GetAtom(kXdndActionDirectSave));
823 ui::SetStringProperty( 779 ui::SetStringProperty(
824 xwindow_, 780 xwindow_, ui::GetAtom(kXdndDirectSave0),
825 atom_cache_.GetAtom(kXdndDirectSave0), 781 ui::GetAtom(ui::Clipboard::kMimeTypeText),
826 atom_cache_.GetAtom(ui::Clipboard::kMimeTypeText),
827 source_provider_->file_contents_name().AsUTF8Unsafe()); 782 source_provider_->file_contents_name().AsUTF8Unsafe());
828 } 783 }
829 ui::SetAtomArrayProperty(xwindow_, kXdndActionList, "ATOM", actions); 784 ui::SetAtomArrayProperty(xwindow_, kXdndActionList, "ATOM", actions);
830 785
831 gfx::ImageSkia drag_image = source_provider_->GetDragImage(); 786 gfx::ImageSkia drag_image = source_provider_->GetDragImage();
832 if (IsValidDragImage(drag_image)) { 787 if (IsValidDragImage(drag_image)) {
833 CreateDragWidget(drag_image); 788 CreateDragWidget(drag_image);
834 drag_widget_offset_ = source_provider_->GetDragImageOffset(); 789 drag_widget_offset_ = source_provider_->GetDragImageOffset();
835 } 790 }
836 791
(...skipping 21 matching lines...) Expand all
858 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT); 813 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT);
859 } else { 814 } else {
860 UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Drop", source, 815 UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Drop", source,
861 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT); 816 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT);
862 } 817 }
863 drag_widget_.reset(); 818 drag_widget_.reset();
864 819
865 source_provider_ = NULL; 820 source_provider_ = NULL;
866 g_current_drag_drop_client = NULL; 821 g_current_drag_drop_client = NULL;
867 drag_operation_ = 0; 822 drag_operation_ = 0;
868 XDeleteProperty(xdisplay_, xwindow_, atom_cache_.GetAtom(kXdndActionList)); 823 XDeleteProperty(xdisplay_, xwindow_, ui::GetAtom(kXdndActionList));
869 XDeleteProperty(xdisplay_, xwindow_, atom_cache_.GetAtom(kXdndDirectSave0)); 824 XDeleteProperty(xdisplay_, xwindow_, ui::GetAtom(kXdndDirectSave0));
870 825
871 return negotiated_operation_; 826 return negotiated_operation_;
872 } 827 }
873 UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Cancel", source, 828 UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Cancel", source,
874 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT); 829 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT);
875 return ui::DragDropTypes::DRAG_NONE; 830 return ui::DragDropTypes::DRAG_NONE;
876 } 831 }
877 832
878 void DesktopDragDropClientAuraX11::DragCancel() { 833 void DesktopDragDropClientAuraX11::DragCancel() {
879 move_loop_->EndMoveLoop(); 834 move_loop_->EndMoveLoop();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 } 955 }
1001 956
1002 void DesktopDragDropClientAuraX11::SendXClientEvent(::Window xid, 957 void DesktopDragDropClientAuraX11::SendXClientEvent(::Window xid,
1003 XEvent* xev) { 958 XEvent* xev) {
1004 DCHECK_EQ(ClientMessage, xev->type); 959 DCHECK_EQ(ClientMessage, xev->type);
1005 960
1006 // Don't send messages to the X11 message queue if we can help it. 961 // Don't send messages to the X11 message queue if we can help it.
1007 DesktopDragDropClientAuraX11* short_circuit = GetForWindow(xid); 962 DesktopDragDropClientAuraX11* short_circuit = GetForWindow(xid);
1008 if (short_circuit) { 963 if (short_circuit) {
1009 Atom message_type = xev->xclient.message_type; 964 Atom message_type = xev->xclient.message_type;
1010 if (message_type == atom_cache_.GetAtom(kXdndEnter)) { 965 if (message_type == ui::GetAtom(kXdndEnter)) {
1011 short_circuit->OnXdndEnter(xev->xclient); 966 short_circuit->OnXdndEnter(xev->xclient);
1012 return; 967 return;
1013 } else if (message_type == atom_cache_.GetAtom(kXdndLeave)) { 968 } else if (message_type == ui::GetAtom(kXdndLeave)) {
1014 short_circuit->OnXdndLeave(xev->xclient); 969 short_circuit->OnXdndLeave(xev->xclient);
1015 return; 970 return;
1016 } else if (message_type == atom_cache_.GetAtom(kXdndPosition)) { 971 } else if (message_type == ui::GetAtom(kXdndPosition)) {
1017 short_circuit->OnXdndPosition(xev->xclient); 972 short_circuit->OnXdndPosition(xev->xclient);
1018 return; 973 return;
1019 } else if (message_type == atom_cache_.GetAtom(kXdndStatus)) { 974 } else if (message_type == ui::GetAtom(kXdndStatus)) {
1020 short_circuit->OnXdndStatus(xev->xclient); 975 short_circuit->OnXdndStatus(xev->xclient);
1021 return; 976 return;
1022 } else if (message_type == atom_cache_.GetAtom(kXdndFinished)) { 977 } else if (message_type == ui::GetAtom(kXdndFinished)) {
1023 short_circuit->OnXdndFinished(xev->xclient); 978 short_circuit->OnXdndFinished(xev->xclient);
1024 return; 979 return;
1025 } else if (message_type == atom_cache_.GetAtom(kXdndDrop)) { 980 } else if (message_type == ui::GetAtom(kXdndDrop)) {
1026 short_circuit->OnXdndDrop(xev->xclient); 981 short_circuit->OnXdndDrop(xev->xclient);
1027 return; 982 return;
1028 } 983 }
1029 } 984 }
1030 985
1031 // I don't understand why the GTK+ code is doing what it's doing here. It 986 // I don't understand why the GTK+ code is doing what it's doing here. It
1032 // goes out of its way to send the XEvent so that it receives a callback on 987 // goes out of its way to send the XEvent so that it receives a callback on
1033 // success or failure, and when it fails, it then sends an internal 988 // success or failure, and when it fails, it then sends an internal
1034 // GdkEvent about the failed drag. (And sending this message doesn't appear 989 // GdkEvent about the failed drag. (And sending this message doesn't appear
1035 // to go through normal xlib machinery, but instead passes through the low 990 // to go through normal xlib machinery, but instead passes through the low
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 aura::client::GetDragDropDelegate(target_window_); 1108 aura::client::GetDragDropDelegate(target_window_);
1154 if (delegate) 1109 if (delegate)
1155 delegate->OnDragExited(); 1110 delegate->OnDragExited();
1156 target_window_->RemoveObserver(this); 1111 target_window_->RemoveObserver(this);
1157 target_window_ = NULL; 1112 target_window_ = NULL;
1158 } 1113 }
1159 1114
1160 ::Atom DesktopDragDropClientAuraX11::DragOperationToAtom( 1115 ::Atom DesktopDragDropClientAuraX11::DragOperationToAtom(
1161 int drag_operation) { 1116 int drag_operation) {
1162 if (drag_operation & ui::DragDropTypes::DRAG_COPY) 1117 if (drag_operation & ui::DragDropTypes::DRAG_COPY)
1163 return atom_cache_.GetAtom(kXdndActionCopy); 1118 return ui::GetAtom(kXdndActionCopy);
1164 if (drag_operation & ui::DragDropTypes::DRAG_MOVE) 1119 if (drag_operation & ui::DragDropTypes::DRAG_MOVE)
1165 return atom_cache_.GetAtom(kXdndActionMove); 1120 return ui::GetAtom(kXdndActionMove);
1166 if (drag_operation & ui::DragDropTypes::DRAG_LINK) 1121 if (drag_operation & ui::DragDropTypes::DRAG_LINK)
1167 return atom_cache_.GetAtom(kXdndActionLink); 1122 return ui::GetAtom(kXdndActionLink);
1168 1123
1169 return None; 1124 return None;
1170 } 1125 }
1171 1126
1172 ui::DragDropTypes::DragOperation 1127 ui::DragDropTypes::DragOperation
1173 DesktopDragDropClientAuraX11::AtomToDragOperation(::Atom atom) { 1128 DesktopDragDropClientAuraX11::AtomToDragOperation(::Atom atom) {
1174 if (atom == atom_cache_.GetAtom(kXdndActionCopy)) 1129 if (atom == ui::GetAtom(kXdndActionCopy))
1175 return ui::DragDropTypes::DRAG_COPY; 1130 return ui::DragDropTypes::DRAG_COPY;
1176 if (atom == atom_cache_.GetAtom(kXdndActionMove)) 1131 if (atom == ui::GetAtom(kXdndActionMove))
1177 return ui::DragDropTypes::DRAG_MOVE; 1132 return ui::DragDropTypes::DRAG_MOVE;
1178 if (atom == atom_cache_.GetAtom(kXdndActionLink)) 1133 if (atom == ui::GetAtom(kXdndActionLink))
1179 return ui::DragDropTypes::DRAG_LINK; 1134 return ui::DragDropTypes::DRAG_LINK;
1180 1135
1181 return ui::DragDropTypes::DRAG_NONE; 1136 return ui::DragDropTypes::DRAG_NONE;
1182 } 1137 }
1183 1138
1184 std::vector<::Atom> DesktopDragDropClientAuraX11::GetOfferedDragOperations() { 1139 std::vector<::Atom> DesktopDragDropClientAuraX11::GetOfferedDragOperations() {
1185 std::vector<::Atom> operations; 1140 std::vector<::Atom> operations;
1186 if (drag_operation_ & ui::DragDropTypes::DRAG_COPY) 1141 if (drag_operation_ & ui::DragDropTypes::DRAG_COPY)
1187 operations.push_back(atom_cache_.GetAtom(kXdndActionCopy)); 1142 operations.push_back(ui::GetAtom(kXdndActionCopy));
1188 if (drag_operation_ & ui::DragDropTypes::DRAG_MOVE) 1143 if (drag_operation_ & ui::DragDropTypes::DRAG_MOVE)
1189 operations.push_back(atom_cache_.GetAtom(kXdndActionMove)); 1144 operations.push_back(ui::GetAtom(kXdndActionMove));
1190 if (drag_operation_ & ui::DragDropTypes::DRAG_LINK) 1145 if (drag_operation_ & ui::DragDropTypes::DRAG_LINK)
1191 operations.push_back(atom_cache_.GetAtom(kXdndActionLink)); 1146 operations.push_back(ui::GetAtom(kXdndActionLink));
1192 return operations; 1147 return operations;
1193 } 1148 }
1194 1149
1195 ui::SelectionFormatMap DesktopDragDropClientAuraX11::GetFormatMap() const { 1150 ui::SelectionFormatMap DesktopDragDropClientAuraX11::GetFormatMap() const {
1196 return source_provider_ ? source_provider_->GetFormatMap() : 1151 return source_provider_ ? source_provider_->GetFormatMap() :
1197 ui::SelectionFormatMap(); 1152 ui::SelectionFormatMap();
1198 } 1153 }
1199 1154
1200 void DesktopDragDropClientAuraX11::CompleteXdndPosition( 1155 void DesktopDragDropClientAuraX11::CompleteXdndPosition(
1201 ::Window source_window, 1156 ::Window source_window,
1202 const gfx::Point& screen_point) { 1157 const gfx::Point& screen_point) {
1203 int drag_operation = ui::DragDropTypes::DRAG_NONE; 1158 int drag_operation = ui::DragDropTypes::DRAG_NONE;
1204 std::unique_ptr<ui::OSExchangeData> data; 1159 std::unique_ptr<ui::OSExchangeData> data;
1205 std::unique_ptr<ui::DropTargetEvent> drop_target_event; 1160 std::unique_ptr<ui::DropTargetEvent> drop_target_event;
1206 DragDropDelegate* delegate = NULL; 1161 DragDropDelegate* delegate = NULL;
1207 DragTranslate(screen_point, &data, &drop_target_event, &delegate); 1162 DragTranslate(screen_point, &data, &drop_target_event, &delegate);
1208 if (delegate) 1163 if (delegate)
1209 drag_operation = delegate->OnDragUpdated(*drop_target_event); 1164 drag_operation = delegate->OnDragUpdated(*drop_target_event);
1210 1165
1211 // Sends an XdndStatus message back to the source_window. l[2,3] 1166 // Sends an XdndStatus message back to the source_window. l[2,3]
1212 // theoretically represent an area in the window where the current action is 1167 // theoretically represent an area in the window where the current action is
1213 // the same as what we're returning, but I can't find any implementation that 1168 // the same as what we're returning, but I can't find any implementation that
1214 // actually making use of this. A client can return (0, 0) and/or set the 1169 // actually making use of this. A client can return (0, 0) and/or set the
1215 // first bit of l[1] to disable the feature, and it appears that gtk neither 1170 // first bit of l[1] to disable the feature, and it appears that gtk neither
1216 // sets this nor respects it if set. 1171 // sets this nor respects it if set.
1217 XEvent xev; 1172 XEvent xev;
1218 xev.xclient.type = ClientMessage; 1173 xev.xclient.type = ClientMessage;
1219 xev.xclient.message_type = atom_cache_.GetAtom(kXdndStatus); 1174 xev.xclient.message_type = ui::GetAtom(kXdndStatus);
1220 xev.xclient.format = 32; 1175 xev.xclient.format = 32;
1221 xev.xclient.window = source_window; 1176 xev.xclient.window = source_window;
1222 xev.xclient.data.l[0] = xwindow_; 1177 xev.xclient.data.l[0] = xwindow_;
1223 xev.xclient.data.l[1] = (drag_operation != 0) ? 1178 xev.xclient.data.l[1] = (drag_operation != 0) ?
1224 (kWantFurtherPosEvents | kWillAcceptDrop) : 0; 1179 (kWantFurtherPosEvents | kWillAcceptDrop) : 0;
1225 xev.xclient.data.l[2] = 0; 1180 xev.xclient.data.l[2] = 0;
1226 xev.xclient.data.l[3] = 0; 1181 xev.xclient.data.l[3] = 0;
1227 xev.xclient.data.l[4] = DragOperationToAtom(drag_operation); 1182 xev.xclient.data.l[4] = DragOperationToAtom(drag_operation);
1228 1183
1229 SendXClientEvent(source_window, &xev); 1184 SendXClientEvent(source_window, &xev);
1230 } 1185 }
1231 1186
1232 void DesktopDragDropClientAuraX11::SendXdndEnter(::Window dest_window) { 1187 void DesktopDragDropClientAuraX11::SendXdndEnter(::Window dest_window) {
1233 XEvent xev; 1188 XEvent xev;
1234 xev.xclient.type = ClientMessage; 1189 xev.xclient.type = ClientMessage;
1235 xev.xclient.message_type = atom_cache_.GetAtom(kXdndEnter); 1190 xev.xclient.message_type = ui::GetAtom(kXdndEnter);
1236 xev.xclient.format = 32; 1191 xev.xclient.format = 32;
1237 xev.xclient.window = dest_window; 1192 xev.xclient.window = dest_window;
1238 xev.xclient.data.l[0] = xwindow_; 1193 xev.xclient.data.l[0] = xwindow_;
1239 xev.xclient.data.l[1] = (kMaxXdndVersion << 24); // The version number. 1194 xev.xclient.data.l[1] = (kMaxXdndVersion << 24); // The version number.
1240 xev.xclient.data.l[2] = 0; 1195 xev.xclient.data.l[2] = 0;
1241 xev.xclient.data.l[3] = 0; 1196 xev.xclient.data.l[3] = 0;
1242 xev.xclient.data.l[4] = 0; 1197 xev.xclient.data.l[4] = 0;
1243 1198
1244 std::vector<Atom> targets; 1199 std::vector<Atom> targets;
1245 source_provider_->RetrieveTargets(&targets); 1200 source_provider_->RetrieveTargets(&targets);
1246 1201
1247 if (targets.size() > 3) { 1202 if (targets.size() > 3) {
1248 xev.xclient.data.l[1] |= 1; 1203 xev.xclient.data.l[1] |= 1;
1249 ui::SetAtomArrayProperty(xwindow_, kXdndTypeList, "ATOM", targets); 1204 ui::SetAtomArrayProperty(xwindow_, kXdndTypeList, "ATOM", targets);
1250 } else { 1205 } else {
1251 // Pack the targets into the enter message. 1206 // Pack the targets into the enter message.
1252 for (size_t i = 0; i < targets.size(); ++i) 1207 for (size_t i = 0; i < targets.size(); ++i)
1253 xev.xclient.data.l[2 + i] = targets[i]; 1208 xev.xclient.data.l[2 + i] = targets[i];
1254 } 1209 }
1255 1210
1256 SendXClientEvent(dest_window, &xev); 1211 SendXClientEvent(dest_window, &xev);
1257 } 1212 }
1258 1213
1259 void DesktopDragDropClientAuraX11::SendXdndLeave(::Window dest_window) { 1214 void DesktopDragDropClientAuraX11::SendXdndLeave(::Window dest_window) {
1260 XEvent xev; 1215 XEvent xev;
1261 xev.xclient.type = ClientMessage; 1216 xev.xclient.type = ClientMessage;
1262 xev.xclient.message_type = atom_cache_.GetAtom(kXdndLeave); 1217 xev.xclient.message_type = ui::GetAtom(kXdndLeave);
1263 xev.xclient.format = 32; 1218 xev.xclient.format = 32;
1264 xev.xclient.window = dest_window; 1219 xev.xclient.window = dest_window;
1265 xev.xclient.data.l[0] = xwindow_; 1220 xev.xclient.data.l[0] = xwindow_;
1266 xev.xclient.data.l[1] = 0; 1221 xev.xclient.data.l[1] = 0;
1267 xev.xclient.data.l[2] = 0; 1222 xev.xclient.data.l[2] = 0;
1268 xev.xclient.data.l[3] = 0; 1223 xev.xclient.data.l[3] = 0;
1269 xev.xclient.data.l[4] = 0; 1224 xev.xclient.data.l[4] = 0;
1270 SendXClientEvent(dest_window, &xev); 1225 SendXClientEvent(dest_window, &xev);
1271 } 1226 }
1272 1227
1273 void DesktopDragDropClientAuraX11::SendXdndPosition( 1228 void DesktopDragDropClientAuraX11::SendXdndPosition(
1274 ::Window dest_window, 1229 ::Window dest_window,
1275 const gfx::Point& screen_point, 1230 const gfx::Point& screen_point,
1276 unsigned long event_time) { 1231 unsigned long event_time) {
1277 waiting_on_status_ = true; 1232 waiting_on_status_ = true;
1278 1233
1279 XEvent xev; 1234 XEvent xev;
1280 xev.xclient.type = ClientMessage; 1235 xev.xclient.type = ClientMessage;
1281 xev.xclient.message_type = atom_cache_.GetAtom(kXdndPosition); 1236 xev.xclient.message_type = ui::GetAtom(kXdndPosition);
1282 xev.xclient.format = 32; 1237 xev.xclient.format = 32;
1283 xev.xclient.window = dest_window; 1238 xev.xclient.window = dest_window;
1284 xev.xclient.data.l[0] = xwindow_; 1239 xev.xclient.data.l[0] = xwindow_;
1285 xev.xclient.data.l[1] = 0; 1240 xev.xclient.data.l[1] = 0;
1286 xev.xclient.data.l[2] = (screen_point.x() << 16) | screen_point.y(); 1241 xev.xclient.data.l[2] = (screen_point.x() << 16) | screen_point.y();
1287 xev.xclient.data.l[3] = event_time; 1242 xev.xclient.data.l[3] = event_time;
1288 xev.xclient.data.l[4] = DragOperationToAtom(drag_operation_); 1243 xev.xclient.data.l[4] = DragOperationToAtom(drag_operation_);
1289 SendXClientEvent(dest_window, &xev); 1244 SendXClientEvent(dest_window, &xev);
1290 1245
1291 // http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html and 1246 // http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html and
1292 // the Xdnd protocol both recommend that drag events should be sent 1247 // the Xdnd protocol both recommend that drag events should be sent
1293 // periodically. 1248 // periodically.
1294 repeat_mouse_move_timer_.Start( 1249 repeat_mouse_move_timer_.Start(
1295 FROM_HERE, 1250 FROM_HERE,
1296 base::TimeDelta::FromMilliseconds(kRepeatMouseMoveTimeoutMs), 1251 base::TimeDelta::FromMilliseconds(kRepeatMouseMoveTimeoutMs),
1297 base::Bind(&DesktopDragDropClientAuraX11::ProcessMouseMove, 1252 base::Bind(&DesktopDragDropClientAuraX11::ProcessMouseMove,
1298 base::Unretained(this), 1253 base::Unretained(this),
1299 screen_point, 1254 screen_point,
1300 event_time)); 1255 event_time));
1301 } 1256 }
1302 1257
1303 void DesktopDragDropClientAuraX11::SendXdndDrop(::Window dest_window) { 1258 void DesktopDragDropClientAuraX11::SendXdndDrop(::Window dest_window) {
1304 XEvent xev; 1259 XEvent xev;
1305 xev.xclient.type = ClientMessage; 1260 xev.xclient.type = ClientMessage;
1306 xev.xclient.message_type = atom_cache_.GetAtom(kXdndDrop); 1261 xev.xclient.message_type = ui::GetAtom(kXdndDrop);
1307 xev.xclient.format = 32; 1262 xev.xclient.format = 32;
1308 xev.xclient.window = dest_window; 1263 xev.xclient.window = dest_window;
1309 xev.xclient.data.l[0] = xwindow_; 1264 xev.xclient.data.l[0] = xwindow_;
1310 xev.xclient.data.l[1] = 0; 1265 xev.xclient.data.l[1] = 0;
1311 xev.xclient.data.l[2] = CurrentTime; 1266 xev.xclient.data.l[2] = CurrentTime;
1312 xev.xclient.data.l[3] = None; 1267 xev.xclient.data.l[3] = None;
1313 xev.xclient.data.l[4] = None; 1268 xev.xclient.data.l[4] = None;
1314 SendXClientEvent(dest_window, &xev); 1269 SendXClientEvent(dest_window, &xev);
1315 } 1270 }
1316 1271
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 for (int x = 0; x < in_bitmap->width(); ++x) { 1316 for (int x = 0; x < in_bitmap->width(); ++x) {
1362 if (SkColorGetA(in_row[x]) > kMinAlpha) 1317 if (SkColorGetA(in_row[x]) > kMinAlpha)
1363 return true; 1318 return true;
1364 } 1319 }
1365 } 1320 }
1366 1321
1367 return false; 1322 return false;
1368 } 1323 }
1369 1324
1370 } // namespace views 1325 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698