Chromium Code Reviews| 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 "base/metrics/histogram_macros.h" | |
| 12 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 13 #include "ui/aura/client/capture_client.h" | 14 #include "ui/aura/client/capture_client.h" |
| 14 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 15 #include "ui/aura/window_tree_host.h" | 16 #include "ui/aura/window_tree_host.h" |
| 16 #include "ui/base/clipboard/clipboard.h" | 17 #include "ui/base/clipboard/clipboard.h" |
| 17 #include "ui/base/dragdrop/drop_target_event.h" | 18 #include "ui/base/dragdrop/drop_target_event.h" |
| 18 #include "ui/base/dragdrop/os_exchange_data.h" | 19 #include "ui/base/dragdrop/os_exchange_data.h" |
| 19 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" | 20 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" |
| 20 #include "ui/base/x/selection_utils.h" | 21 #include "ui/base/x/selection_utils.h" |
| 21 #include "ui/base/x/x11_foreign_window_manager.h" | 22 #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), | 411 xwindow_(xwindow), |
| 411 atom_cache_(xdisplay_, kAtomsToCache), | 412 atom_cache_(xdisplay_, kAtomsToCache), |
| 412 current_modifier_state_(ui::EF_NONE), | 413 current_modifier_state_(ui::EF_NONE), |
| 413 target_window_(NULL), | 414 target_window_(NULL), |
| 414 waiting_on_status_(false), | 415 waiting_on_status_(false), |
| 415 status_received_since_enter_(false), | 416 status_received_since_enter_(false), |
| 416 source_provider_(NULL), | 417 source_provider_(NULL), |
| 417 source_current_window_(None), | 418 source_current_window_(None), |
| 418 source_state_(SOURCE_STATE_OTHER), | 419 source_state_(SOURCE_STATE_OTHER), |
| 419 drag_operation_(0), | 420 drag_operation_(0), |
| 421 current_drag_event_source_(ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE), | |
| 420 negotiated_operation_(ui::DragDropTypes::DRAG_NONE), | 422 negotiated_operation_(ui::DragDropTypes::DRAG_NONE), |
| 421 weak_ptr_factory_(this) { | 423 weak_ptr_factory_(this) { |
| 422 // Some tests change the DesktopDragDropClientAuraX11 associated with an | 424 // Some tests change the DesktopDragDropClientAuraX11 associated with an |
| 423 // |xwindow|. | 425 // |xwindow|. |
| 424 g_live_client_map.Get()[xwindow] = this; | 426 g_live_client_map.Get()[xwindow] = this; |
| 425 | 427 |
| 426 // Mark that we are aware of drag and drop concepts. | 428 // Mark that we are aware of drag and drop concepts. |
| 427 unsigned long xdnd_version = kMinXdndVersion; | 429 unsigned long xdnd_version = kMinXdndVersion; |
| 428 XChangeProperty(xdisplay_, xwindow_, atom_cache_.GetAtom("XdndAware"), | 430 XChangeProperty(xdisplay_, xwindow_, atom_cache_.GetAtom("XdndAware"), |
| 429 XA_ATOM, 32, PropModeReplace, | 431 XA_ATOM, 32, PropModeReplace, |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 603 target_window_location_, | 605 target_window_location_, |
| 604 target_window_root_location_, | 606 target_window_root_location_, |
| 605 target_current_context_->GetDragOperation()); | 607 target_current_context_->GetDragOperation()); |
| 606 if (target_current_context_->source_client()) { | 608 if (target_current_context_->source_client()) { |
| 607 event.set_flags(target_current_context_->source_client() | 609 event.set_flags(target_current_context_->source_client() |
| 608 ->current_modifier_state()); | 610 ->current_modifier_state()); |
| 609 } else { | 611 } else { |
| 610 event.set_flags(XGetModifiers()); | 612 event.set_flags(XGetModifiers()); |
| 611 } | 613 } |
| 612 | 614 |
| 613 drag_operation = delegate->OnPerformDrop(event); | 615 drag_operation = delegate->OnPerformDrop(event); |
|
pkotwicz
2015/01/14 18:31:30
If you put a histogram here, you would be able to
caelyn
2015/01/14 20:00:26
The real question is whether we can do the same th
pkotwicz
2015/01/14 20:39:55
I think that DesktopDropTargetWin::OnDrop() gets c
| |
| 614 } | 616 } |
| 615 | 617 |
| 616 target_window_->RemoveObserver(this); | 618 target_window_->RemoveObserver(this); |
| 617 target_window_ = NULL; | 619 target_window_ = NULL; |
| 618 } | 620 } |
| 619 | 621 |
| 620 XEvent xev; | 622 XEvent xev; |
| 621 xev.xclient.type = ClientMessage; | 623 xev.xclient.type = ClientMessage; |
| 622 xev.xclient.message_type = atom_cache_.GetAtom("XdndFinished"); | 624 xev.xclient.message_type = atom_cache_.GetAtom("XdndFinished"); |
| 623 xev.xclient.format = 32; | 625 xev.xclient.format = 32; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 639 XDeleteProperty(xdisplay_, xwindow_, xselection.property); | 641 XDeleteProperty(xdisplay_, xwindow_, xselection.property); |
| 640 } | 642 } |
| 641 | 643 |
| 642 int DesktopDragDropClientAuraX11::StartDragAndDrop( | 644 int DesktopDragDropClientAuraX11::StartDragAndDrop( |
| 643 const ui::OSExchangeData& data, | 645 const ui::OSExchangeData& data, |
| 644 aura::Window* root_window, | 646 aura::Window* root_window, |
| 645 aura::Window* source_window, | 647 aura::Window* source_window, |
| 646 const gfx::Point& root_location, | 648 const gfx::Point& root_location, |
| 647 int operation, | 649 int operation, |
| 648 ui::DragDropTypes::DragEventSource source) { | 650 ui::DragDropTypes::DragEventSource source) { |
| 651 UMA_HISTOGRAM_ENUMERATION("DragDrop.Start", source, | |
| 652 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT); | |
| 653 | |
| 649 source_current_window_ = None; | 654 source_current_window_ = None; |
| 650 DCHECK(!g_current_drag_drop_client); | 655 DCHECK(!g_current_drag_drop_client); |
| 651 g_current_drag_drop_client = this; | 656 g_current_drag_drop_client = this; |
| 652 waiting_on_status_ = false; | 657 waiting_on_status_ = false; |
| 653 next_position_message_.reset(); | 658 next_position_message_.reset(); |
| 654 status_received_since_enter_ = false; | 659 status_received_since_enter_ = false; |
| 655 source_state_ = SOURCE_STATE_OTHER; | 660 source_state_ = SOURCE_STATE_OTHER; |
| 656 drag_operation_ = operation; | 661 drag_operation_ = operation; |
| 657 negotiated_operation_ = ui::DragDropTypes::DRAG_NONE; | 662 negotiated_operation_ = ui::DragDropTypes::DRAG_NONE; |
| 663 current_drag_event_source_ = source; | |
|
pkotwicz
2015/01/14 18:31:30
Chrome for Desktop Linux does not support initiati
caelyn
2015/01/14 20:00:26
I know that chrome on linux does not support touch
pkotwicz
2015/01/14 20:39:55
Once you move all of the histograms to this method
caelyn
2015/01/21 16:29:53
Done.
| |
| 658 | 664 |
| 659 const ui::OSExchangeData::Provider* provider = &data.provider(); | 665 const ui::OSExchangeData::Provider* provider = &data.provider(); |
| 660 source_provider_ = static_cast<const ui::OSExchangeDataProviderAuraX11*>( | 666 source_provider_ = static_cast<const ui::OSExchangeDataProviderAuraX11*>( |
| 661 provider); | 667 provider); |
| 662 | 668 |
| 663 source_provider_->TakeOwnershipOfSelection(); | 669 source_provider_->TakeOwnershipOfSelection(); |
| 664 | 670 |
| 665 std::vector< ::Atom> actions = GetOfferedDragOperations(); | 671 std::vector< ::Atom> actions = GetOfferedDragOperations(); |
| 666 if (!source_provider_->file_contents_name().empty()) { | 672 if (!source_provider_->file_contents_name().empty()) { |
| 667 actions.push_back(atom_cache_.GetAtom(kXdndActionDirectSave)); | 673 actions.push_back(atom_cache_.GetAtom(kXdndActionDirectSave)); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 690 // whether it is alive after the drag ends. | 696 // whether it is alive after the drag ends. |
| 691 base::WeakPtr<DesktopDragDropClientAuraX11> alive( | 697 base::WeakPtr<DesktopDragDropClientAuraX11> alive( |
| 692 weak_ptr_factory_.GetWeakPtr()); | 698 weak_ptr_factory_.GetWeakPtr()); |
| 693 | 699 |
| 694 // Windows has a specific method, DoDragDrop(), which performs the entire | 700 // Windows has a specific method, DoDragDrop(), which performs the entire |
| 695 // drag. We have to emulate this, so we spin off a nested runloop which will | 701 // drag. We have to emulate this, so we spin off a nested runloop which will |
| 696 // track all cursor movement and reroute events to a specific handler. | 702 // track all cursor movement and reroute events to a specific handler. |
| 697 move_loop_->RunMoveLoop( | 703 move_loop_->RunMoveLoop( |
| 698 source_window, | 704 source_window, |
| 699 cursor_manager_->GetInitializedCursor(ui::kCursorGrabbing)); | 705 cursor_manager_->GetInitializedCursor(ui::kCursorGrabbing)); |
| 700 | 706 |
|
pkotwicz
2015/01/14 18:31:30
Can you move the histogram code for whether a drag
caelyn
2015/01/14 20:00:26
Acknowledged. - My tests show moving it here has t
| |
| 701 if (alive) { | 707 if (alive) { |
| 702 drag_widget_.reset(); | 708 drag_widget_.reset(); |
| 703 | 709 |
| 704 source_provider_ = NULL; | 710 source_provider_ = NULL; |
| 705 g_current_drag_drop_client = NULL; | 711 g_current_drag_drop_client = NULL; |
| 706 drag_operation_ = 0; | 712 drag_operation_ = 0; |
| 707 XDeleteProperty(xdisplay_, xwindow_, atom_cache_.GetAtom("XdndActionList")); | 713 XDeleteProperty(xdisplay_, xwindow_, atom_cache_.GetAtom("XdndActionList")); |
| 708 XDeleteProperty(xdisplay_, xwindow_, atom_cache_.GetAtom(kXdndDirectSave0)); | 714 XDeleteProperty(xdisplay_, xwindow_, atom_cache_.GetAtom(kXdndDirectSave0)); |
| 709 | 715 |
| 710 return negotiated_operation_; | 716 return negotiated_operation_; |
| 711 } | 717 } |
| 712 return ui::DragDropTypes::DRAG_NONE; | 718 return ui::DragDropTypes::DRAG_NONE; |
| 713 } | 719 } |
| 714 | 720 |
| 715 void DesktopDragDropClientAuraX11::DragUpdate(aura::Window* target, | 721 void DesktopDragDropClientAuraX11::DragUpdate(aura::Window* target, |
| 716 const ui::LocatedEvent& event) { | 722 const ui::LocatedEvent& event) { |
| 717 NOTIMPLEMENTED(); | 723 NOTIMPLEMENTED(); |
| 718 } | 724 } |
| 719 | 725 |
| 720 void DesktopDragDropClientAuraX11::Drop(aura::Window* target, | 726 void DesktopDragDropClientAuraX11::Drop(aura::Window* target, |
| 721 const ui::LocatedEvent& event) { | 727 const ui::LocatedEvent& event) { |
| 722 NOTIMPLEMENTED(); | 728 NOTIMPLEMENTED(); |
| 723 } | 729 } |
| 724 | 730 |
| 725 void DesktopDragDropClientAuraX11::DragCancel() { | 731 void DesktopDragDropClientAuraX11::DragCancel() { |
| 732 // EndMoveLoop will call DesktopDragDropClientAuraX11::OnMoveLoopEnded and | |
|
mfomitchev
2015/01/14 17:03:41
IMHO this is not really worth explaining in a comm
caelyn
2015/01/21 16:29:53
Done.
| |
| 733 // record a DragDrop.Cancel event in UMA | |
| 726 move_loop_->EndMoveLoop(); | 734 move_loop_->EndMoveLoop(); |
| 727 } | 735 } |
| 728 | 736 |
| 729 bool DesktopDragDropClientAuraX11::IsDragDropInProgress() { | 737 bool DesktopDragDropClientAuraX11::IsDragDropInProgress() { |
| 730 return !!g_current_drag_drop_client; | 738 return !!g_current_drag_drop_client; |
| 731 } | 739 } |
| 732 | 740 |
| 733 void DesktopDragDropClientAuraX11::OnWindowDestroyed(aura::Window* window) { | 741 void DesktopDragDropClientAuraX11::OnWindowDestroyed(aura::Window* window) { |
| 734 DCHECK_EQ(target_window_, window); | 742 DCHECK_EQ(target_window_, window); |
| 735 target_window_ = NULL; | 743 target_window_ = NULL; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 793 source_state_ = SOURCE_STATE_DROPPED; | 801 source_state_ = SOURCE_STATE_DROPPED; |
| 794 SendXdndDrop(source_current_window_); | 802 SendXdndDrop(source_current_window_); |
| 795 return; | 803 return; |
| 796 } | 804 } |
| 797 } | 805 } |
| 798 | 806 |
| 799 move_loop_->EndMoveLoop(); | 807 move_loop_->EndMoveLoop(); |
| 800 } | 808 } |
| 801 | 809 |
| 802 void DesktopDragDropClientAuraX11::OnMoveLoopEnded() { | 810 void DesktopDragDropClientAuraX11::OnMoveLoopEnded() { |
| 811 if (negotiated_operation_ == ui::DragDropTypes::DRAG_NONE) { | |
| 812 UMA_HISTOGRAM_ENUMERATION("DragDrop.Cancel", current_drag_event_source_, | |
| 813 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT); | |
| 814 } else { | |
| 815 UMA_HISTOGRAM_ENUMERATION("DragDrop.Drop", current_drag_event_source_, | |
| 816 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT); | |
| 817 } | |
| 803 if (source_current_window_ != None) { | 818 if (source_current_window_ != None) { |
| 804 SendXdndLeave(source_current_window_); | 819 SendXdndLeave(source_current_window_); |
| 805 source_current_window_ = None; | 820 source_current_window_ = None; |
| 806 } | 821 } |
| 807 target_current_context_.reset(); | 822 target_current_context_.reset(); |
| 808 repeat_mouse_move_timer_.Stop(); | 823 repeat_mouse_move_timer_.Stop(); |
| 809 end_move_loop_timer_.Stop(); | 824 end_move_loop_timer_.Stop(); |
| 810 } | 825 } |
| 811 | 826 |
| 812 scoped_ptr<X11MoveLoop> DesktopDragDropClientAuraX11::CreateMoveLoop( | 827 scoped_ptr<X11MoveLoop> DesktopDragDropClientAuraX11::CreateMoveLoop( |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1192 for (int x = 0; x < in_bitmap->width(); ++x) { | 1207 for (int x = 0; x < in_bitmap->width(); ++x) { |
| 1193 if (SkColorGetA(in_row[x]) > kMinAlpha) | 1208 if (SkColorGetA(in_row[x]) > kMinAlpha) |
| 1194 return true; | 1209 return true; |
| 1195 } | 1210 } |
| 1196 } | 1211 } |
| 1197 | 1212 |
| 1198 return false; | 1213 return false; |
| 1199 } | 1214 } |
| 1200 | 1215 |
| 1201 } // namespace views | 1216 } // namespace views |
| OLD | NEW |