Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: app/win/drop_target.cc

Issue 3822007: Move BaseDropTarget and BaseDragSource from base to app/win. Remove the "Base... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « app/win/drop_target.h ('k') | base/base.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/base_drop_target.h" 5 #include "app/win/drop_target.h"
6 6
7 #include <shlobj.h> 7 #include <shlobj.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
11 /////////////////////////////////////////////////////////////////////////////// 11 namespace app {
12 namespace win {
12 13
13 IDropTargetHelper* BaseDropTarget::cached_drop_target_helper_ = NULL; 14 IDropTargetHelper* DropTarget::cached_drop_target_helper_ = NULL;
14 int32 BaseDropTarget::drag_identity_ = 0; 15 int32 DropTarget::drag_identity_ = 0;
15 16
16 BaseDropTarget::BaseDropTarget(HWND hwnd) 17 DropTarget::DropTarget(HWND hwnd)
17 : hwnd_(hwnd), 18 : hwnd_(hwnd),
18 suspended_(false), 19 suspended_(false),
19 ref_count_(0) { 20 ref_count_(0) {
20 DCHECK(hwnd); 21 DCHECK(hwnd);
21 HRESULT result = RegisterDragDrop(hwnd, this); 22 HRESULT result = RegisterDragDrop(hwnd, this);
22 DCHECK(SUCCEEDED(result)); 23 DCHECK(SUCCEEDED(result));
23 } 24 }
24 25
25 BaseDropTarget::~BaseDropTarget() { 26 DropTarget::~DropTarget() {
26 } 27 }
27 28
28 // static 29 // static
29 IDropTargetHelper* BaseDropTarget::DropHelper() { 30 IDropTargetHelper* DropTarget::DropHelper() {
30 if (!cached_drop_target_helper_) { 31 if (!cached_drop_target_helper_) {
31 CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER, 32 CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER,
32 IID_IDropTargetHelper, 33 IID_IDropTargetHelper,
33 reinterpret_cast<void**>(&cached_drop_target_helper_)); 34 reinterpret_cast<void**>(&cached_drop_target_helper_));
34 } 35 }
35 return cached_drop_target_helper_; 36 return cached_drop_target_helper_;
36 } 37 }
37 38
38 /////////////////////////////////////////////////////////////////////////////// 39 ///////////////////////////////////////////////////////////////////////////////
39 // BaseDropTarget, IDropTarget implementation: 40 // DropTarget, IDropTarget implementation:
40 41
41 HRESULT BaseDropTarget::DragEnter(IDataObject* data_object, 42 HRESULT DropTarget::DragEnter(IDataObject* data_object,
42 DWORD key_state, 43 DWORD key_state,
43 POINTL cursor_position, 44 POINTL cursor_position,
44 DWORD* effect) { 45 DWORD* effect) {
45 // Tell the helper that we entered so it can update the drag image. 46 // Tell the helper that we entered so it can update the drag image.
46 IDropTargetHelper* drop_helper = DropHelper(); 47 IDropTargetHelper* drop_helper = DropHelper();
47 if (drop_helper) { 48 if (drop_helper) {
48 drop_helper->DragEnter(GetHWND(), data_object, 49 drop_helper->DragEnter(GetHWND(), data_object,
49 reinterpret_cast<POINT*>(&cursor_position), *effect); 50 reinterpret_cast<POINT*>(&cursor_position), *effect);
50 } 51 }
51 52
52 // You can't drag and drop within the same HWND. 53 // You can't drag and drop within the same HWND.
53 if (suspended_) { 54 if (suspended_) {
54 *effect = DROPEFFECT_NONE; 55 *effect = DROPEFFECT_NONE;
55 return S_OK; 56 return S_OK;
56 } 57 }
57 58
58 // Update the drag identity, skipping 0. 59 // Update the drag identity, skipping 0.
59 if (++drag_identity_ == 0) 60 if (++drag_identity_ == 0)
60 ++drag_identity_; 61 ++drag_identity_;
61 62
62 current_data_object_ = data_object; 63 current_data_object_ = data_object;
63 POINT screen_pt = { cursor_position.x, cursor_position.y }; 64 POINT screen_pt = { cursor_position.x, cursor_position.y };
64 *effect = OnDragEnter(current_data_object_, key_state, screen_pt, *effect); 65 *effect = OnDragEnter(current_data_object_, key_state, screen_pt, *effect);
65 return S_OK; 66 return S_OK;
66 } 67 }
67 68
68 HRESULT BaseDropTarget::DragOver(DWORD key_state, 69 HRESULT DropTarget::DragOver(DWORD key_state,
69 POINTL cursor_position, 70 POINTL cursor_position,
70 DWORD* effect) { 71 DWORD* effect) {
71 // Tell the helper that we moved over it so it can update the drag image. 72 // Tell the helper that we moved over it so it can update the drag image.
72 IDropTargetHelper* drop_helper = DropHelper(); 73 IDropTargetHelper* drop_helper = DropHelper();
73 if (drop_helper) 74 if (drop_helper)
74 drop_helper->DragOver(reinterpret_cast<POINT*>(&cursor_position), *effect); 75 drop_helper->DragOver(reinterpret_cast<POINT*>(&cursor_position), *effect);
75 76
76 if (suspended_) { 77 if (suspended_) {
77 *effect = DROPEFFECT_NONE; 78 *effect = DROPEFFECT_NONE;
78 return S_OK; 79 return S_OK;
79 } 80 }
80 81
81 POINT screen_pt = { cursor_position.x, cursor_position.y }; 82 POINT screen_pt = { cursor_position.x, cursor_position.y };
82 *effect = OnDragOver(current_data_object_, key_state, screen_pt, *effect); 83 *effect = OnDragOver(current_data_object_, key_state, screen_pt, *effect);
83 return S_OK; 84 return S_OK;
84 } 85 }
85 86
86 HRESULT BaseDropTarget::DragLeave() { 87 HRESULT DropTarget::DragLeave() {
87 // Tell the helper that we moved out of it so it can update the drag image. 88 // Tell the helper that we moved out of it so it can update the drag image.
88 IDropTargetHelper* drop_helper = DropHelper(); 89 IDropTargetHelper* drop_helper = DropHelper();
89 if (drop_helper) 90 if (drop_helper)
90 drop_helper->DragLeave(); 91 drop_helper->DragLeave();
91 92
92 if (suspended_) 93 if (suspended_)
93 return S_OK; 94 return S_OK;
94 95
95 OnDragLeave(current_data_object_); 96 OnDragLeave(current_data_object_);
96 97
97 current_data_object_ = NULL; 98 current_data_object_ = NULL;
98 return S_OK; 99 return S_OK;
99 } 100 }
100 101
101 HRESULT BaseDropTarget::Drop(IDataObject* data_object, 102 HRESULT DropTarget::Drop(IDataObject* data_object,
102 DWORD key_state, 103 DWORD key_state,
103 POINTL cursor_position, 104 POINTL cursor_position,
104 DWORD* effect) { 105 DWORD* effect) {
105 // Tell the helper that we dropped onto it so it can update the drag image. 106 // Tell the helper that we dropped onto it so it can update the drag image.
106 IDropTargetHelper* drop_helper = DropHelper(); 107 IDropTargetHelper* drop_helper = DropHelper();
107 if (drop_helper) { 108 if (drop_helper) {
108 drop_helper->Drop(current_data_object_, 109 drop_helper->Drop(current_data_object_,
109 reinterpret_cast<POINT*>(&cursor_position), *effect); 110 reinterpret_cast<POINT*>(&cursor_position), *effect);
110 } 111 }
111 112
112 if (suspended_) { 113 if (suspended_) {
113 *effect = DROPEFFECT_NONE; 114 *effect = DROPEFFECT_NONE;
114 return S_OK; 115 return S_OK;
115 } 116 }
116 117
117 POINT screen_pt = { cursor_position.x, cursor_position.y }; 118 POINT screen_pt = { cursor_position.x, cursor_position.y };
118 *effect = OnDrop(current_data_object_, key_state, screen_pt, *effect); 119 *effect = OnDrop(current_data_object_, key_state, screen_pt, *effect);
119 return S_OK; 120 return S_OK;
120 } 121 }
121 122
122 /////////////////////////////////////////////////////////////////////////////// 123 ///////////////////////////////////////////////////////////////////////////////
123 // BaseDropTarget, IUnknown implementation: 124 // DropTarget, IUnknown implementation:
124 125
125 HRESULT BaseDropTarget::QueryInterface(const IID& iid, void** object) { 126 HRESULT DropTarget::QueryInterface(const IID& iid, void** object) {
126 *object = NULL; 127 *object = NULL;
127 if (IsEqualIID(iid, IID_IUnknown) || IsEqualIID(iid, IID_IDropTarget)) { 128 if (IsEqualIID(iid, IID_IUnknown) || IsEqualIID(iid, IID_IDropTarget)) {
128 *object = this; 129 *object = this;
129 } else { 130 } else {
130 return E_NOINTERFACE; 131 return E_NOINTERFACE;
131 } 132 }
132 AddRef(); 133 AddRef();
133 return S_OK; 134 return S_OK;
134 } 135 }
135 136
136 ULONG BaseDropTarget::AddRef() { 137 ULONG DropTarget::AddRef() {
137 return ++ref_count_; 138 return ++ref_count_;
138 } 139 }
139 140
140 ULONG BaseDropTarget::Release() { 141 ULONG DropTarget::Release() {
141 if (--ref_count_ == 0) { 142 if (--ref_count_ == 0) {
142 delete this; 143 delete this;
143 return 0U; 144 return 0U;
144 } 145 }
145 return ref_count_; 146 return ref_count_;
146 } 147 }
147 148
148 DWORD BaseDropTarget::OnDragEnter(IDataObject* data_object, 149 DWORD DropTarget::OnDragEnter(IDataObject* data_object,
149 DWORD key_state, 150 DWORD key_state,
150 POINT cursor_position, 151 POINT cursor_position,
151 DWORD effect) { 152 DWORD effect) {
152 return DROPEFFECT_NONE; 153 return DROPEFFECT_NONE;
153 } 154 }
154 155
155 DWORD BaseDropTarget::OnDragOver(IDataObject* data_object, 156 DWORD DropTarget::OnDragOver(IDataObject* data_object,
156 DWORD key_state,
157 POINT cursor_position,
158 DWORD effect) {
159 return DROPEFFECT_NONE;
160 }
161
162 void BaseDropTarget::OnDragLeave(IDataObject* data_object) {
163 }
164
165 DWORD BaseDropTarget::OnDrop(IDataObject* data_object,
166 DWORD key_state, 157 DWORD key_state,
167 POINT cursor_position, 158 POINT cursor_position,
168 DWORD effect) { 159 DWORD effect) {
169 return DROPEFFECT_NONE; 160 return DROPEFFECT_NONE;
170 } 161 }
162
163 void DropTarget::OnDragLeave(IDataObject* data_object) {
164 }
165
166 DWORD DropTarget::OnDrop(IDataObject* data_object,
167 DWORD key_state,
168 POINT cursor_position,
169 DWORD effect) {
170 return DROPEFFECT_NONE;
171 }
172
173 } // namespace win
174 } // namespace app
OLDNEW
« no previous file with comments | « app/win/drop_target.h ('k') | base/base.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698