1 // Copyright (c) 2011 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/base/dragdrop/drop_target_win.h"
9 #include "base/logging.h"
13 IDropTargetHelper
* DropTargetWin::cached_drop_target_helper_
= NULL
;
15 DropTargetWin::DropTargetWin(HWND hwnd
)
19 HRESULT result
= RegisterDragDrop(hwnd
, this);
20 DCHECK(SUCCEEDED(result
));
23 DropTargetWin::~DropTargetWin() {
27 IDropTargetHelper
* DropTargetWin::DropHelper() {
28 if (!cached_drop_target_helper_
) {
29 CoCreateInstance(CLSID_DragDropHelper
, 0, CLSCTX_INPROC_SERVER
,
30 IID_IDropTargetHelper
,
31 reinterpret_cast<void**>(&cached_drop_target_helper_
));
33 return cached_drop_target_helper_
;
36 ///////////////////////////////////////////////////////////////////////////////
37 // DropTargetWin, IDropTarget implementation:
39 HRESULT
DropTargetWin::DragEnter(IDataObject
* data_object
,
41 POINTL cursor_position
,
43 // Tell the helper that we entered so it can update the drag image.
44 IDropTargetHelper
* drop_helper
= DropHelper();
46 drop_helper
->DragEnter(GetHWND(), data_object
,
47 reinterpret_cast<POINT
*>(&cursor_position
), *effect
);
50 current_data_object_
= data_object
;
51 POINT screen_pt
= { cursor_position
.x
, cursor_position
.y
};
53 OnDragEnter(current_data_object_
.get(), key_state
, screen_pt
, *effect
);
57 HRESULT
DropTargetWin::DragOver(DWORD key_state
,
58 POINTL cursor_position
,
60 // Tell the helper that we moved over it so it can update the drag image.
61 IDropTargetHelper
* drop_helper
= DropHelper();
63 drop_helper
->DragOver(reinterpret_cast<POINT
*>(&cursor_position
), *effect
);
65 POINT screen_pt
= { cursor_position
.x
, cursor_position
.y
};
67 OnDragOver(current_data_object_
.get(), key_state
, screen_pt
, *effect
);
71 HRESULT
DropTargetWin::DragLeave() {
72 // Tell the helper that we moved out of it so it can update the drag image.
73 IDropTargetHelper
* drop_helper
= DropHelper();
75 drop_helper
->DragLeave();
77 OnDragLeave(current_data_object_
.get());
79 current_data_object_
= NULL
;
83 HRESULT
DropTargetWin::Drop(IDataObject
* data_object
,
85 POINTL cursor_position
,
87 // Tell the helper that we dropped onto it so it can update the drag image.
88 IDropTargetHelper
* drop_helper
= DropHelper();
90 drop_helper
->Drop(current_data_object_
.get(),
91 reinterpret_cast<POINT
*>(&cursor_position
), *effect
);
94 POINT screen_pt
= { cursor_position
.x
, cursor_position
.y
};
95 *effect
= OnDrop(current_data_object_
.get(), key_state
, screen_pt
, *effect
);
99 ///////////////////////////////////////////////////////////////////////////////
100 // DropTargetWin, IUnknown implementation:
102 HRESULT
DropTargetWin::QueryInterface(const IID
& iid
, void** object
) {
104 if (IsEqualIID(iid
, IID_IUnknown
) || IsEqualIID(iid
, IID_IDropTarget
)) {
107 return E_NOINTERFACE
;
113 ULONG
DropTargetWin::AddRef() {
117 ULONG
DropTargetWin::Release() {
118 if (--ref_count_
== 0) {
125 DWORD
DropTargetWin::OnDragEnter(IDataObject
* data_object
,
127 POINT cursor_position
,
129 return DROPEFFECT_NONE
;
132 DWORD
DropTargetWin::OnDragOver(IDataObject
* data_object
,
134 POINT cursor_position
,
136 return DROPEFFECT_NONE
;
139 void DropTargetWin::OnDragLeave(IDataObject
* data_object
) {
142 DWORD
DropTargetWin::OnDrop(IDataObject
* data_object
,
144 POINT cursor_position
,
146 return DROPEFFECT_NONE
;