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 #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/client/capture_client.h" | |
12 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
13 #include "ui/aura/window_tree_host.h" | 14 #include "ui/aura/window_tree_host.h" |
14 #include "ui/base/clipboard/clipboard.h" | 15 #include "ui/base/clipboard/clipboard.h" |
15 #include "ui/base/dragdrop/drop_target_event.h" | 16 #include "ui/base/dragdrop/drop_target_event.h" |
16 #include "ui/base/dragdrop/os_exchange_data.h" | 17 #include "ui/base/dragdrop/os_exchange_data.h" |
17 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" | 18 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" |
18 #include "ui/base/x/selection_utils.h" | 19 #include "ui/base/x/selection_utils.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" |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
539 // We were waiting on the status message so we could send the XdndDrop. | 540 // We were waiting on the status message so we could send the XdndDrop. |
540 if (negotiated_operation_ == ui::DragDropTypes::DRAG_NONE) { | 541 if (negotiated_operation_ == ui::DragDropTypes::DRAG_NONE) { |
541 move_loop_.EndMoveLoop(); | 542 move_loop_.EndMoveLoop(); |
542 return; | 543 return; |
543 } | 544 } |
544 source_state_ = SOURCE_STATE_DROPPED; | 545 source_state_ = SOURCE_STATE_DROPPED; |
545 SendXdndDrop(source_window); | 546 SendXdndDrop(source_window); |
546 return; | 547 return; |
547 } | 548 } |
548 | 549 |
549 switch (negotiated_operation_) { | 550 UpdateCursor(); |
550 case ui::DragDropTypes::DRAG_COPY: | |
551 move_loop_.UpdateCursor(copy_grab_cursor_); | |
552 break; | |
553 case ui::DragDropTypes::DRAG_MOVE: | |
554 move_loop_.UpdateCursor(move_grab_cursor_); | |
555 break; | |
556 default: | |
557 move_loop_.UpdateCursor(grab_cursor_); | |
558 break; | |
559 } | |
560 | 551 |
561 // Note: event.data.[2,3] specify a rectangle. It is a request by the other | 552 // Note: event.data.[2,3] specify a rectangle. It is a request by the other |
562 // window to not send further XdndPosition messages while the cursor is | 553 // window to not send further XdndPosition messages while the cursor is |
563 // within it. However, it is considered advisory and (at least according to | 554 // within it. However, it is considered advisory and (at least according to |
564 // the spec) the other side must handle further position messages within | 555 // the spec) the other side must handle further position messages within |
565 // it. GTK+ doesn't bother with this, so neither should we. | 556 // it. GTK+ doesn't bother with this, so neither should we. |
566 | 557 |
567 if (next_position_message_.get()) { | 558 if (next_position_message_.get()) { |
568 // We were waiting on the status message so we could send off the next | 559 // We were waiting on the status message so we could send off the next |
569 // position message we queued up. | 560 // position message we queued up. |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
892 if (drag_operation_ & ui::DragDropTypes::DRAG_LINK) | 883 if (drag_operation_ & ui::DragDropTypes::DRAG_LINK) |
893 operations.push_back(atom_cache_.GetAtom(kXdndActionLink)); | 884 operations.push_back(atom_cache_.GetAtom(kXdndActionLink)); |
894 return operations; | 885 return operations; |
895 } | 886 } |
896 | 887 |
897 ui::SelectionFormatMap DesktopDragDropClientAuraX11::GetFormatMap() const { | 888 ui::SelectionFormatMap DesktopDragDropClientAuraX11::GetFormatMap() const { |
898 return source_provider_ ? source_provider_->GetFormatMap() : | 889 return source_provider_ ? source_provider_->GetFormatMap() : |
899 ui::SelectionFormatMap(); | 890 ui::SelectionFormatMap(); |
900 } | 891 } |
901 | 892 |
893 void DesktopDragDropClientAuraX11::UpdateCursor() { | |
894 if (!move_loop_.in_move_loop()) | |
895 return; | |
896 | |
897 // If we're still in the move loop, re-grab the pointer with the updated | |
898 // cursor. Note: we can be called from handling an XdndStatus message after | |
899 // EndMoveLoop() was called, but before we return from the nested RunLoop. | |
pkotwicz
2014/05/05 18:14:37
I do not completely understand this comment.
move_
varkha
2014/05/05 19:06:04
Yes, with the source_current_window_ set to None i
| |
900 aura::client::CaptureClient* capture_client = | |
901 aura::client::GetCaptureClient(root_window_); | |
902 if (!capture_client) | |
903 return; | |
904 aura::Window* capture_window = capture_client->GetGlobalCaptureWindow(); | |
905 if (!capture_window) | |
906 return; | |
907 | |
908 gfx::NativeCursor cursor = grab_cursor_; | |
909 switch (negotiated_operation_) { | |
910 case ui::DragDropTypes::DRAG_COPY: | |
911 cursor = copy_grab_cursor_; | |
912 break; | |
913 case ui::DragDropTypes::DRAG_MOVE: | |
914 cursor = move_grab_cursor_; | |
915 break; | |
916 default: | |
917 break; | |
918 } | |
919 | |
pkotwicz
2014/05/05 18:14:37
Would XChangeActivePointerGrab() be more appropria
varkha
2014/05/05 19:06:04
Done. This also eliminates the need to get the cur
| |
920 XUngrabPointer(xdisplay_, CurrentTime); | |
921 int ret = XGrabPointer( | |
922 xdisplay_, | |
923 capture_window->GetHost()->GetAcceleratedWidget(), | |
924 False, | |
925 ButtonPressMask | ButtonReleaseMask | PointerMotionMask, | |
926 GrabModeAsync, | |
927 GrabModeAsync, | |
928 None, | |
929 cursor.platform(), | |
930 CurrentTime); | |
931 if (ret != GrabSuccess) { | |
932 DLOG(ERROR) << "Grabbing pointer for dragging failed: " | |
933 << ui::GetX11ErrorString(xdisplay_, ret); | |
934 } | |
935 } | |
936 | |
902 void DesktopDragDropClientAuraX11::CompleteXdndPosition( | 937 void DesktopDragDropClientAuraX11::CompleteXdndPosition( |
903 ::Window source_window, | 938 ::Window source_window, |
904 const gfx::Point& screen_point) { | 939 const gfx::Point& screen_point) { |
905 int drag_operation = ui::DragDropTypes::DRAG_NONE; | 940 int drag_operation = ui::DragDropTypes::DRAG_NONE; |
906 scoped_ptr<ui::OSExchangeData> data; | 941 scoped_ptr<ui::OSExchangeData> data; |
907 scoped_ptr<ui::DropTargetEvent> drop_target_event; | 942 scoped_ptr<ui::DropTargetEvent> drop_target_event; |
908 DragDropDelegate* delegate = NULL; | 943 DragDropDelegate* delegate = NULL; |
909 DragTranslate(screen_point, &data, &drop_target_event, &delegate); | 944 DragTranslate(screen_point, &data, &drop_target_event, &delegate); |
910 if (delegate) | 945 if (delegate) |
911 drag_operation = delegate->OnDragUpdated(*drop_target_event); | 946 drag_operation = delegate->OnDragUpdated(*drop_target_event); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1040 // GdkEvent about the failed drag. (And sending this message doesn't appear | 1075 // GdkEvent about the failed drag. (And sending this message doesn't appear |
1041 // to go through normal xlib machinery, but instead passes through the low | 1076 // to go through normal xlib machinery, but instead passes through the low |
1042 // level xProto (the x11 wire format) that I don't understand. | 1077 // level xProto (the x11 wire format) that I don't understand. |
1043 // | 1078 // |
1044 // I'm unsure if I have to jump through those hoops, or if XSendEvent is | 1079 // I'm unsure if I have to jump through those hoops, or if XSendEvent is |
1045 // sufficient. | 1080 // sufficient. |
1046 XSendEvent(xdisplay_, xid, False, 0, xev); | 1081 XSendEvent(xdisplay_, xid, False, 0, xev); |
1047 } | 1082 } |
1048 | 1083 |
1049 } // namespace views | 1084 } // namespace views |
OLD | NEW |