1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h"
#include <memory>
#include "base/metrics/histogram_macros.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/drag_source_win.h"
#include "ui/base/dragdrop/drop_target_event.h"
#include "ui/base/dragdrop/os_exchange_data_provider_win.h"
#include "ui/views/widget/desktop_aura/desktop_drop_target_win.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h"
namespace views {
DesktopDragDropClientWin::DesktopDragDropClientWin(aura::Window* root_window,
HWND window)
: drag_drop_in_progress_(false), drag_operation_(0) {
drop_target_ = new DesktopDropTargetWin(root_window);
drop_target_->Init(window);
}
DesktopDragDropClientWin::~DesktopDragDropClientWin() {
if (drag_drop_in_progress_)
DragCancel();
}
int DesktopDragDropClientWin::StartDragAndDrop(
std::unique_ptr<ui::OSExchangeData> data,
aura::Window* root_window,
aura::Window* source_window,
const gfx::Point& screen_location,
int operation,
ui::DragDropTypes::DragEventSource source) {
drag_drop_in_progress_ = true;
drag_operation_ = operation;
base::WeakPtr<DesktopDragDropClientWin> alive(weak_factory_.GetWeakPtr());
drag_source_ = ui::DragSourceWin::Create();
Microsoft::WRL::ComPtr<ui::DragSourceWin> drag_source_copy = drag_source_;
drag_source_copy->set_data(data.get());
ui::OSExchangeDataProviderWin::GetDataObjectImpl(*data.get())
->set_in_drag_loop(true);
DWORD effect;
UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Start", source,
ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT);
HRESULT result = DoDragDrop(
ui::OSExchangeDataProviderWin::GetIDataObject(*data.get()),
drag_source_.Get(),
ui::DragDropTypes::DragOperationToDropEffect(operation), &effect);
drag_source_copy->set_data(nullptr);
if (alive)
drag_drop_in_progress_ = false;
if (result != DRAGDROP_S_DROP)
effect = DROPEFFECT_NONE;
int drag_operation = ui::DragDropTypes::DropEffectToDragOperation(effect);
if (drag_operation == ui::DragDropTypes::DRAG_NONE) {
UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Cancel", source,
ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT);
} else {
UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Drop", source,
ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT);
}
return drag_operation;
}
void DesktopDragDropClientWin::DragCancel() {
drag_source_->CancelDrag();
drag_operation_ = 0;
}
bool DesktopDragDropClientWin::IsDragDropInProgress() {
return drag_drop_in_progress_;
}
void DesktopDragDropClientWin::AddObserver(
aura::client::DragDropClientObserver* observer) {
NOTIMPLEMENTED();
}
void DesktopDragDropClientWin::RemoveObserver(
aura::client::DragDropClientObserver* observer) {
NOTIMPLEMENTED();
}
void DesktopDragDropClientWin::OnNativeWidgetDestroying(HWND window) {
if (drop_target_.get()) {
RevokeDragDrop(window);
drop_target_ = nullptr;
}
}
} // namespace views
|