| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "ui/base/dragdrop/drop_target_win.h" | |
| 6 | |
| 7 #include <shlobj.h> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 | |
| 11 namespace ui { | |
| 12 | |
| 13 IDropTargetHelper* DropTargetWin::cached_drop_target_helper_ = NULL; | |
| 14 | |
| 15 DropTargetWin::DropTargetWin(HWND hwnd) | |
| 16 : hwnd_(hwnd), | |
| 17 ref_count_(0) { | |
| 18 DCHECK(hwnd); | |
| 19 HRESULT result = RegisterDragDrop(hwnd, this); | |
| 20 DCHECK(SUCCEEDED(result)); | |
| 21 } | |
| 22 | |
| 23 DropTargetWin::~DropTargetWin() { | |
| 24 } | |
| 25 | |
| 26 // static | |
| 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_)); | |
| 32 } | |
| 33 return cached_drop_target_helper_; | |
| 34 } | |
| 35 | |
| 36 /////////////////////////////////////////////////////////////////////////////// | |
| 37 // DropTargetWin, IDropTarget implementation: | |
| 38 | |
| 39 HRESULT DropTargetWin::DragEnter(IDataObject* data_object, | |
| 40 DWORD key_state, | |
| 41 POINTL cursor_position, | |
| 42 DWORD* effect) { | |
| 43 // Tell the helper that we entered so it can update the drag image. | |
| 44 IDropTargetHelper* drop_helper = DropHelper(); | |
| 45 if (drop_helper) { | |
| 46 drop_helper->DragEnter(GetHWND(), data_object, | |
| 47 reinterpret_cast<POINT*>(&cursor_position), *effect); | |
| 48 } | |
| 49 | |
| 50 current_data_object_ = data_object; | |
| 51 POINT screen_pt = { cursor_position.x, cursor_position.y }; | |
| 52 *effect = OnDragEnter(current_data_object_.get(), key_state, screen_pt, | |
| 53 *effect); | |
| 54 return S_OK; | |
| 55 } | |
| 56 | |
| 57 HRESULT DropTargetWin::DragOver(DWORD key_state, | |
| 58 POINTL cursor_position, | |
| 59 DWORD* effect) { | |
| 60 // Tell the helper that we moved over it so it can update the drag image. | |
| 61 IDropTargetHelper* drop_helper = DropHelper(); | |
| 62 if (drop_helper) | |
| 63 drop_helper->DragOver(reinterpret_cast<POINT*>(&cursor_position), *effect); | |
| 64 | |
| 65 POINT screen_pt = { cursor_position.x, cursor_position.y }; | |
| 66 *effect = OnDragOver(current_data_object_.get(), key_state, screen_pt, | |
| 67 *effect); | |
| 68 return S_OK; | |
| 69 } | |
| 70 | |
| 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(); | |
| 74 if (drop_helper) | |
| 75 drop_helper->DragLeave(); | |
| 76 | |
| 77 OnDragLeave(current_data_object_.get()); | |
| 78 | |
| 79 current_data_object_ = NULL; | |
| 80 return S_OK; | |
| 81 } | |
| 82 | |
| 83 HRESULT DropTargetWin::Drop(IDataObject* data_object, | |
| 84 DWORD key_state, | |
| 85 POINTL cursor_position, | |
| 86 DWORD* effect) { | |
| 87 // Tell the helper that we dropped onto it so it can update the drag image. | |
| 88 IDropTargetHelper* drop_helper = DropHelper(); | |
| 89 if (drop_helper) { | |
| 90 drop_helper->Drop(current_data_object_.get(), | |
| 91 reinterpret_cast<POINT*>(&cursor_position), *effect); | |
| 92 } | |
| 93 | |
| 94 POINT screen_pt = { cursor_position.x, cursor_position.y }; | |
| 95 *effect = OnDrop(current_data_object_.get(), key_state, screen_pt, *effect); | |
| 96 return S_OK; | |
| 97 } | |
| 98 | |
| 99 /////////////////////////////////////////////////////////////////////////////// | |
| 100 // DropTargetWin, IUnknown implementation: | |
| 101 | |
| 102 HRESULT DropTargetWin::QueryInterface(const IID& iid, void** object) { | |
| 103 *object = NULL; | |
| 104 if (IsEqualIID(iid, IID_IUnknown) || IsEqualIID(iid, IID_IDropTarget)) { | |
| 105 *object = this; | |
| 106 } else { | |
| 107 return E_NOINTERFACE; | |
| 108 } | |
| 109 AddRef(); | |
| 110 return S_OK; | |
| 111 } | |
| 112 | |
| 113 ULONG DropTargetWin::AddRef() { | |
| 114 return ++ref_count_; | |
| 115 } | |
| 116 | |
| 117 ULONG DropTargetWin::Release() { | |
| 118 if (--ref_count_ == 0) { | |
| 119 delete this; | |
| 120 return 0U; | |
| 121 } | |
| 122 return ref_count_; | |
| 123 } | |
| 124 | |
| 125 DWORD DropTargetWin::OnDragEnter(IDataObject* data_object, | |
| 126 DWORD key_state, | |
| 127 POINT cursor_position, | |
| 128 DWORD effect) { | |
| 129 return DROPEFFECT_NONE; | |
| 130 } | |
| 131 | |
| 132 DWORD DropTargetWin::OnDragOver(IDataObject* data_object, | |
| 133 DWORD key_state, | |
| 134 POINT cursor_position, | |
| 135 DWORD effect) { | |
| 136 return DROPEFFECT_NONE; | |
| 137 } | |
| 138 | |
| 139 void DropTargetWin::OnDragLeave(IDataObject* data_object) { | |
| 140 } | |
| 141 | |
| 142 DWORD DropTargetWin::OnDrop(IDataObject* data_object, | |
| 143 DWORD key_state, | |
| 144 POINT cursor_position, | |
| 145 DWORD effect) { | |
| 146 return DROPEFFECT_NONE; | |
| 147 } | |
| 148 | |
| 149 } // namespace ui | |
| OLD | NEW |