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.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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 XDeleteProperty(xdisplay_, xwindow_, xselection.property); | 640 XDeleteProperty(xdisplay_, xwindow_, xselection.property); |
| 639 } | 641 } |
| 640 | 642 |
| 641 int DesktopDragDropClientAuraX11::StartDragAndDrop( | 643 int DesktopDragDropClientAuraX11::StartDragAndDrop( |
| 642 const ui::OSExchangeData& data, | 644 const ui::OSExchangeData& data, |
| 643 aura::Window* root_window, | 645 aura::Window* root_window, |
| 644 aura::Window* source_window, | 646 aura::Window* source_window, |
| 645 const gfx::Point& root_location, | 647 const gfx::Point& root_location, |
| 646 int operation, | 648 int operation, |
| 647 ui::DragDropTypes::DragEventSource source) { | 649 ui::DragDropTypes::DragEventSource source) { |
| 650 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) { | |
| 651 UMA_HISTOGRAM_COUNTS("DragDrop.Touch.Start", 1); | |
| 652 } else if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE) { | |
| 653 UMA_HISTOGRAM_COUNTS("DragDrop.Mouse.Start", 1); | |
| 654 } | |
| 655 | |
| 648 source_current_window_ = None; | 656 source_current_window_ = None; |
| 649 DCHECK(!g_current_drag_drop_client); | 657 DCHECK(!g_current_drag_drop_client); |
| 650 g_current_drag_drop_client = this; | 658 g_current_drag_drop_client = this; |
| 651 waiting_on_status_ = false; | 659 waiting_on_status_ = false; |
| 652 next_position_message_.reset(); | 660 next_position_message_.reset(); |
| 653 status_received_since_enter_ = false; | 661 status_received_since_enter_ = false; |
| 654 source_state_ = SOURCE_STATE_OTHER; | 662 source_state_ = SOURCE_STATE_OTHER; |
| 655 drag_operation_ = operation; | 663 drag_operation_ = operation; |
| 656 negotiated_operation_ = ui::DragDropTypes::DRAG_NONE; | 664 negotiated_operation_ = ui::DragDropTypes::DRAG_NONE; |
| 665 current_drag_event_source_ = source; | |
| 657 | 666 |
| 658 const ui::OSExchangeData::Provider* provider = &data.provider(); | 667 const ui::OSExchangeData::Provider* provider = &data.provider(); |
| 659 source_provider_ = static_cast<const ui::OSExchangeDataProviderAuraX11*>( | 668 source_provider_ = static_cast<const ui::OSExchangeDataProviderAuraX11*>( |
| 660 provider); | 669 provider); |
| 661 | 670 |
| 662 source_provider_->TakeOwnershipOfSelection(); | 671 source_provider_->TakeOwnershipOfSelection(); |
| 663 | 672 |
| 664 std::vector< ::Atom> actions = GetOfferedDragOperations(); | 673 std::vector< ::Atom> actions = GetOfferedDragOperations(); |
| 665 if (!source_provider_->file_contents_name().empty()) { | 674 if (!source_provider_->file_contents_name().empty()) { |
| 666 actions.push_back(atom_cache_.GetAtom(kXdndActionDirectSave)); | 675 actions.push_back(atom_cache_.GetAtom(kXdndActionDirectSave)); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 765 | 774 |
| 766 if (source_current_window_ != None) { | 775 if (source_current_window_ != None) { |
| 767 if (waiting_on_status_) { | 776 if (waiting_on_status_) { |
| 768 if (status_received_since_enter_) { | 777 if (status_received_since_enter_) { |
| 769 // If we are waiting for an XdndStatus message, we need to wait for it | 778 // If we are waiting for an XdndStatus message, we need to wait for it |
| 770 // to complete. | 779 // to complete. |
| 771 source_state_ = SOURCE_STATE_PENDING_DROP; | 780 source_state_ = SOURCE_STATE_PENDING_DROP; |
| 772 | 781 |
| 773 // Start timer to end the move loop if the target takes too long to send | 782 // Start timer to end the move loop if the target takes too long to send |
| 774 // the XdndStatus and XdndFinished messages. | 783 // the XdndStatus and XdndFinished messages. |
| 775 StartEndMoveLoopTimer(); | 784 StartEndMoveLoopTimer(); |
|
mfomitchev
2015/01/08 23:30:59
Wouldn't this lead to cancelling the DnD? (meaning
caelyn
2015/01/12 22:43:10
See comment below.
| |
| 776 return; | 785 return; |
| 777 } | 786 } |
| 778 | 787 |
| 779 move_loop_->EndMoveLoop(); | 788 move_loop_->EndMoveLoop(); |
|
mfomitchev
2015/01/08 23:30:59
And this?
caelyn
2015/01/12 22:43:10
See comment below.
| |
| 780 return; | 789 return; |
| 781 } | 790 } |
| 782 | 791 |
| 783 if (negotiated_operation_ != ui::DragDropTypes::DRAG_NONE) { | 792 if (negotiated_operation_ != ui::DragDropTypes::DRAG_NONE) { |
|
mfomitchev
2015/01/08 23:30:59
What if the negotiated operation is NONE? Don't we
caelyn
2015/01/12 22:43:10
EndMoveLoop is not always called in circumstances
mfomitchev
2015/01/13 17:01:25
DragCancel() is at least called from web_contents_
caelyn
2015/01/13 23:48:58
Oops. Should have checked from the virtual method,
| |
| 784 // Start timer to end the move loop if the target takes too long to send | 793 // Start timer to end the move loop if the target takes too long to send |
| 785 // an XdndFinished message. It is important that StartEndMoveLoopTimer() | 794 // an XdndFinished message. It is important that StartEndMoveLoopTimer() |
| 786 // is called before SendXdndDrop() because SendXdndDrop() | 795 // is called before SendXdndDrop() because SendXdndDrop() |
| 787 // sends XdndFinished synchronously if the drop target is a Chrome | 796 // sends XdndFinished synchronously if the drop target is a Chrome |
| 788 // window. | 797 // window. |
| 789 StartEndMoveLoopTimer(); | 798 StartEndMoveLoopTimer(); |
| 790 | 799 |
| 791 // We have negotiated an action with the other end. | 800 // We have negotiated an action with the other end. |
| 792 source_state_ = SOURCE_STATE_DROPPED; | 801 source_state_ = SOURCE_STATE_DROPPED; |
| 802 if (current_drag_event_source_ == | |
| 803 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) { | |
| 804 UMA_HISTOGRAM_COUNTS("DragDrop.Touch.Drop", 1); | |
| 805 } else if (current_drag_event_source_ == | |
| 806 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE) { | |
| 807 UMA_HISTOGRAM_COUNTS("DragDrop.Mouse.Drop", 1); | |
| 808 } | |
| 793 SendXdndDrop(source_current_window_); | 809 SendXdndDrop(source_current_window_); |
| 794 return; | 810 return; |
| 795 } | 811 } |
| 796 } | 812 } |
| 797 | 813 |
| 798 move_loop_->EndMoveLoop(); | 814 move_loop_->EndMoveLoop(); |
| 799 } | 815 } |
| 800 | 816 |
| 801 void DesktopDragDropClientAuraX11::OnMoveLoopEnded() { | 817 void DesktopDragDropClientAuraX11::OnMoveLoopEnded() { |
| 802 if (source_current_window_ != None) { | 818 if (source_current_window_ != None) { |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1191 for (int x = 0; x < in_bitmap->width(); ++x) { | 1207 for (int x = 0; x < in_bitmap->width(); ++x) { |
| 1192 if (SkColorGetA(in_row[x]) > kMinAlpha) | 1208 if (SkColorGetA(in_row[x]) > kMinAlpha) |
| 1193 return true; | 1209 return true; |
| 1194 } | 1210 } |
| 1195 } | 1211 } |
| 1196 | 1212 |
| 1197 return false; | 1213 return false; |
| 1198 } | 1214 } |
| 1199 | 1215 |
| 1200 } // namespace views | 1216 } // namespace views |
| OLD | NEW |