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
3 // found in the LICENSE file.
5 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h"
7 #include "base/metrics/histogram_macros.h"
8 #include "base/tracked_objects.h"
9 #include "ui/base/dragdrop/drag_drop_types.h"
10 #include "ui/base/dragdrop/drag_source_win.h"
11 #include "ui/base/dragdrop/drop_target_event.h"
12 #include "ui/base/dragdrop/os_exchange_data_provider_win.h"
13 #include "ui/views/widget/desktop_aura/desktop_drop_target_win.h"
14 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h"
18 DesktopDragDropClientWin::DesktopDragDropClientWin(
19 aura::Window
* root_window
,
21 : drag_drop_in_progress_(false),
24 drop_target_
= new DesktopDropTargetWin(root_window
, window
);
27 DesktopDragDropClientWin::~DesktopDragDropClientWin() {
28 if (drag_drop_in_progress_
)
32 int DesktopDragDropClientWin::StartDragAndDrop(
33 const ui::OSExchangeData
& data
,
34 aura::Window
* root_window
,
35 aura::Window
* source_window
,
36 const gfx::Point
& root_location
,
38 ui::DragDropTypes::DragEventSource source
) {
39 drag_drop_in_progress_
= true;
40 drag_operation_
= operation
;
42 base::WeakPtr
<DesktopDragDropClientWin
> alive(weak_factory_
.GetWeakPtr());
44 drag_source_
= new ui::DragSourceWin
;
45 scoped_refptr
<ui::DragSourceWin
> drag_source_copy
= drag_source_
;
49 UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Start", source
,
50 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT
);
52 // Use task stopwatch to exclude the drag-drop time current task, if any.
53 tracked_objects::TaskStopwatch stopwatch
;
55 HRESULT result
= DoDragDrop(
56 ui::OSExchangeDataProviderWin::GetIDataObject(data
), drag_source_
.get(),
57 ui::DragDropTypes::DragOperationToDropEffect(operation
), &effect
);
61 drag_drop_in_progress_
= false;
63 if (result
!= DRAGDROP_S_DROP
)
64 effect
= DROPEFFECT_NONE
;
66 int drag_operation
= ui::DragDropTypes::DropEffectToDragOperation(effect
);
68 if (drag_operation
== ui::DragDropTypes::DRAG_NONE
) {
69 UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Cancel", source
,
70 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT
);
72 UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Drop", source
,
73 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT
);
76 return drag_operation
;
79 void DesktopDragDropClientWin::DragUpdate(aura::Window
* target
,
80 const ui::LocatedEvent
& event
) {
83 void DesktopDragDropClientWin::Drop(aura::Window
* target
,
84 const ui::LocatedEvent
& event
) {
87 void DesktopDragDropClientWin::DragCancel() {
88 drag_source_
->CancelDrag();
92 bool DesktopDragDropClientWin::IsDragDropInProgress() {
93 return drag_drop_in_progress_
;
96 void DesktopDragDropClientWin::OnNativeWidgetDestroying(HWND window
) {
97 if (drop_target_
.get()) {
98 RevokeDragDrop(window
);