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 <map> | |
10 #include <utility> | |
mfomitchev
2015/01/13 17:01:25
why are these new imports needed?
caelyn
2015/01/13 23:48:58
See reasoning from the .h file.
| |
11 | |
9 #include "base/event_types.h" | 12 #include "base/event_types.h" |
10 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
11 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/metrics/histogram_macros.h" | |
12 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
13 #include "ui/aura/client/capture_client.h" | 17 #include "ui/aura/client/capture_client.h" |
14 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
15 #include "ui/aura/window_tree_host.h" | 19 #include "ui/aura/window_tree_host.h" |
16 #include "ui/base/clipboard/clipboard.h" | 20 #include "ui/base/clipboard/clipboard.h" |
17 #include "ui/base/dragdrop/drop_target_event.h" | 21 #include "ui/base/dragdrop/drop_target_event.h" |
18 #include "ui/base/dragdrop/os_exchange_data.h" | 22 #include "ui/base/dragdrop/os_exchange_data.h" |
19 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" | 23 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" |
20 #include "ui/base/x/selection_utils.h" | 24 #include "ui/base/x/selection_utils.h" |
21 #include "ui/base/x/x11_foreign_window_manager.h" | 25 #include "ui/base/x/x11_foreign_window_manager.h" |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 xwindow_(xwindow), | 414 xwindow_(xwindow), |
411 atom_cache_(xdisplay_, kAtomsToCache), | 415 atom_cache_(xdisplay_, kAtomsToCache), |
412 current_modifier_state_(ui::EF_NONE), | 416 current_modifier_state_(ui::EF_NONE), |
413 target_window_(NULL), | 417 target_window_(NULL), |
414 waiting_on_status_(false), | 418 waiting_on_status_(false), |
415 status_received_since_enter_(false), | 419 status_received_since_enter_(false), |
416 source_provider_(NULL), | 420 source_provider_(NULL), |
417 source_current_window_(None), | 421 source_current_window_(None), |
418 source_state_(SOURCE_STATE_OTHER), | 422 source_state_(SOURCE_STATE_OTHER), |
419 drag_operation_(0), | 423 drag_operation_(0), |
424 current_drag_event_source_(ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE), | |
420 negotiated_operation_(ui::DragDropTypes::DRAG_NONE), | 425 negotiated_operation_(ui::DragDropTypes::DRAG_NONE), |
421 weak_ptr_factory_(this) { | 426 weak_ptr_factory_(this) { |
422 // Some tests change the DesktopDragDropClientAuraX11 associated with an | 427 // Some tests change the DesktopDragDropClientAuraX11 associated with an |
423 // |xwindow|. | 428 // |xwindow|. |
424 g_live_client_map.Get()[xwindow] = this; | 429 g_live_client_map.Get()[xwindow] = this; |
425 | 430 |
426 // Mark that we are aware of drag and drop concepts. | 431 // Mark that we are aware of drag and drop concepts. |
427 unsigned long xdnd_version = kMinXdndVersion; | 432 unsigned long xdnd_version = kMinXdndVersion; |
428 XChangeProperty(xdisplay_, xwindow_, atom_cache_.GetAtom("XdndAware"), | 433 XChangeProperty(xdisplay_, xwindow_, atom_cache_.GetAtom("XdndAware"), |
429 XA_ATOM, 32, PropModeReplace, | 434 XA_ATOM, 32, PropModeReplace, |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
639 XDeleteProperty(xdisplay_, xwindow_, xselection.property); | 644 XDeleteProperty(xdisplay_, xwindow_, xselection.property); |
640 } | 645 } |
641 | 646 |
642 int DesktopDragDropClientAuraX11::StartDragAndDrop( | 647 int DesktopDragDropClientAuraX11::StartDragAndDrop( |
643 const ui::OSExchangeData& data, | 648 const ui::OSExchangeData& data, |
644 aura::Window* root_window, | 649 aura::Window* root_window, |
645 aura::Window* source_window, | 650 aura::Window* source_window, |
646 const gfx::Point& root_location, | 651 const gfx::Point& root_location, |
647 int operation, | 652 int operation, |
648 ui::DragDropTypes::DragEventSource source) { | 653 ui::DragDropTypes::DragEventSource source) { |
654 UMA_HISTOGRAM_ENUMERATION("DragDrop.Start", source, | |
655 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT); | |
656 | |
649 source_current_window_ = None; | 657 source_current_window_ = None; |
650 DCHECK(!g_current_drag_drop_client); | 658 DCHECK(!g_current_drag_drop_client); |
651 g_current_drag_drop_client = this; | 659 g_current_drag_drop_client = this; |
652 waiting_on_status_ = false; | 660 waiting_on_status_ = false; |
653 next_position_message_.reset(); | 661 next_position_message_.reset(); |
654 status_received_since_enter_ = false; | 662 status_received_since_enter_ = false; |
655 source_state_ = SOURCE_STATE_OTHER; | 663 source_state_ = SOURCE_STATE_OTHER; |
656 drag_operation_ = operation; | 664 drag_operation_ = operation; |
657 negotiated_operation_ = ui::DragDropTypes::DRAG_NONE; | 665 negotiated_operation_ = ui::DragDropTypes::DRAG_NONE; |
666 current_drag_event_source_ = source; | |
658 | 667 |
659 const ui::OSExchangeData::Provider* provider = &data.provider(); | 668 const ui::OSExchangeData::Provider* provider = &data.provider(); |
660 source_provider_ = static_cast<const ui::OSExchangeDataProviderAuraX11*>( | 669 source_provider_ = static_cast<const ui::OSExchangeDataProviderAuraX11*>( |
661 provider); | 670 provider); |
662 | 671 |
663 source_provider_->TakeOwnershipOfSelection(); | 672 source_provider_->TakeOwnershipOfSelection(); |
664 | 673 |
665 std::vector< ::Atom> actions = GetOfferedDragOperations(); | 674 std::vector< ::Atom> actions = GetOfferedDragOperations(); |
666 if (!source_provider_->file_contents_name().empty()) { | 675 if (!source_provider_->file_contents_name().empty()) { |
667 actions.push_back(atom_cache_.GetAtom(kXdndActionDirectSave)); | 676 actions.push_back(atom_cache_.GetAtom(kXdndActionDirectSave)); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
716 const ui::LocatedEvent& event) { | 725 const ui::LocatedEvent& event) { |
717 NOTIMPLEMENTED(); | 726 NOTIMPLEMENTED(); |
718 } | 727 } |
719 | 728 |
720 void DesktopDragDropClientAuraX11::Drop(aura::Window* target, | 729 void DesktopDragDropClientAuraX11::Drop(aura::Window* target, |
721 const ui::LocatedEvent& event) { | 730 const ui::LocatedEvent& event) { |
722 NOTIMPLEMENTED(); | 731 NOTIMPLEMENTED(); |
723 } | 732 } |
724 | 733 |
725 void DesktopDragDropClientAuraX11::DragCancel() { | 734 void DesktopDragDropClientAuraX11::DragCancel() { |
735 UMA_HISTOGRAM_ENUMERATION("DragDrop.Cancel", current_drag_event_source_, | |
736 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT); | |
726 move_loop_->EndMoveLoop(); | 737 move_loop_->EndMoveLoop(); |
727 } | 738 } |
728 | 739 |
729 bool DesktopDragDropClientAuraX11::IsDragDropInProgress() { | 740 bool DesktopDragDropClientAuraX11::IsDragDropInProgress() { |
730 return !!g_current_drag_drop_client; | 741 return !!g_current_drag_drop_client; |
731 } | 742 } |
732 | 743 |
733 void DesktopDragDropClientAuraX11::OnWindowDestroyed(aura::Window* window) { | 744 void DesktopDragDropClientAuraX11::OnWindowDestroyed(aura::Window* window) { |
734 DCHECK_EQ(target_window_, window); | 745 DCHECK_EQ(target_window_, window); |
735 target_window_ = NULL; | 746 target_window_ = NULL; |
(...skipping 17 matching lines...) Expand all Loading... | |
753 repeat_mouse_move_timer_.Stop(); | 764 repeat_mouse_move_timer_.Stop(); |
754 ProcessMouseMove(screen_point, event_time.InMilliseconds()); | 765 ProcessMouseMove(screen_point, event_time.InMilliseconds()); |
755 } | 766 } |
756 | 767 |
757 void DesktopDragDropClientAuraX11::OnMouseReleased() { | 768 void DesktopDragDropClientAuraX11::OnMouseReleased() { |
758 repeat_mouse_move_timer_.Stop(); | 769 repeat_mouse_move_timer_.Stop(); |
759 | 770 |
760 if (source_state_ != SOURCE_STATE_OTHER) { | 771 if (source_state_ != SOURCE_STATE_OTHER) { |
761 // The user has previously released the mouse and is clicking in | 772 // The user has previously released the mouse and is clicking in |
762 // frustration. | 773 // frustration. |
763 move_loop_->EndMoveLoop(); | 774 DragCancel(); |
764 return; | 775 return; |
765 } | 776 } |
766 | 777 |
767 if (source_current_window_ != None) { | 778 if (source_current_window_ != None) { |
768 if (waiting_on_status_) { | 779 if (waiting_on_status_) { |
769 if (status_received_since_enter_) { | 780 if (status_received_since_enter_) { |
770 // If we are waiting for an XdndStatus message, we need to wait for it | 781 // If we are waiting for an XdndStatus message, we need to wait for it |
771 // to complete. | 782 // to complete. |
772 source_state_ = SOURCE_STATE_PENDING_DROP; | 783 source_state_ = SOURCE_STATE_PENDING_DROP; |
773 | 784 |
774 // Start timer to end the move loop if the target takes too long to send | 785 // Start timer to end the move loop if the target takes too long to send |
775 // the XdndStatus and XdndFinished messages. | 786 // the XdndStatus and XdndFinished messages. |
776 StartEndMoveLoopTimer(); | 787 StartEndMoveLoopTimer(); |
788 DragCancel(); | |
777 return; | 789 return; |
778 } | 790 } |
779 | 791 |
780 move_loop_->EndMoveLoop(); | 792 DragCancel(); |
781 return; | 793 return; |
782 } | 794 } |
783 | 795 |
784 if (negotiated_operation_ != ui::DragDropTypes::DRAG_NONE) { | 796 if (negotiated_operation_ != ui::DragDropTypes::DRAG_NONE) { |
785 // Start timer to end the move loop if the target takes too long to send | 797 // Start timer to end the move loop if the target takes too long to send |
786 // an XdndFinished message. It is important that StartEndMoveLoopTimer() | 798 // an XdndFinished message. It is important that StartEndMoveLoopTimer() |
787 // is called before SendXdndDrop() because SendXdndDrop() | 799 // is called before SendXdndDrop() because SendXdndDrop() |
788 // sends XdndFinished synchronously if the drop target is a Chrome | 800 // sends XdndFinished synchronously if the drop target is a Chrome |
789 // window. | 801 // window. |
790 StartEndMoveLoopTimer(); | 802 StartEndMoveLoopTimer(); |
791 | 803 |
792 // We have negotiated an action with the other end. | 804 // We have negotiated an action with the other end. |
793 source_state_ = SOURCE_STATE_DROPPED; | 805 source_state_ = SOURCE_STATE_DROPPED; |
806 UMA_HISTOGRAM_ENUMERATION("DragDrop.Drop", current_drag_event_source_, | |
807 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT); | |
794 SendXdndDrop(source_current_window_); | 808 SendXdndDrop(source_current_window_); |
795 return; | 809 return; |
810 } else { | |
811 DragCancel(); | |
mfomitchev
2015/01/13 17:01:25
Unless there is a good reason not to, just let it
caelyn
2015/01/13 23:48:58
Done.
| |
812 return; | |
796 } | 813 } |
797 } | 814 } |
798 | 815 |
799 move_loop_->EndMoveLoop(); | 816 move_loop_->EndMoveLoop(); |
mfomitchev
2015/01/13 17:01:25
DragCancel()?
caelyn
2015/01/13 23:48:58
Since OnMoveLoopEnded gets called from X11WholeScr
| |
800 } | 817 } |
801 | 818 |
802 void DesktopDragDropClientAuraX11::OnMoveLoopEnded() { | 819 void DesktopDragDropClientAuraX11::OnMoveLoopEnded() { |
803 if (source_current_window_ != None) { | 820 if (source_current_window_ != None) { |
804 SendXdndLeave(source_current_window_); | 821 SendXdndLeave(source_current_window_); |
805 source_current_window_ = None; | 822 source_current_window_ = None; |
806 } | 823 } |
807 target_current_context_.reset(); | 824 target_current_context_.reset(); |
808 repeat_mouse_move_timer_.Stop(); | 825 repeat_mouse_move_timer_.Stop(); |
809 end_move_loop_timer_.Stop(); | 826 end_move_loop_timer_.Stop(); |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1192 for (int x = 0; x < in_bitmap->width(); ++x) { | 1209 for (int x = 0; x < in_bitmap->width(); ++x) { |
1193 if (SkColorGetA(in_row[x]) > kMinAlpha) | 1210 if (SkColorGetA(in_row[x]) > kMinAlpha) |
1194 return true; | 1211 return true; |
1195 } | 1212 } |
1196 } | 1213 } |
1197 | 1214 |
1198 return false; | 1215 return false; |
1199 } | 1216 } |
1200 | 1217 |
1201 } // namespace views | 1218 } // namespace views |
OLD | NEW |