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

Side by Side Diff: base/base_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 | « base/base_drop_target.h ('k') | chrome/browser/autocomplete/autocomplete_edit_view_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 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 "base/base_drop_target.h"
6
7 #include <shlobj.h>
8
9 #include "base/logging.h"
10
11 ///////////////////////////////////////////////////////////////////////////////
12
13 IDropTargetHelper* BaseDropTarget::cached_drop_target_helper_ = NULL;
14 int32 BaseDropTarget::drag_identity_ = 0;
15
16 BaseDropTarget::BaseDropTarget(HWND hwnd)
17 : hwnd_(hwnd),
18 suspended_(false),
19 ref_count_(0) {
20 DCHECK(hwnd);
21 HRESULT result = RegisterDragDrop(hwnd, this);
22 DCHECK(SUCCEEDED(result));
23 }
24
25 BaseDropTarget::~BaseDropTarget() {
26 }
27
28 // static
29 IDropTargetHelper* BaseDropTarget::DropHelper() {
30 if (!cached_drop_target_helper_) {
31 CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER,
32 IID_IDropTargetHelper,
33 reinterpret_cast<void**>(&cached_drop_target_helper_));
34 }
35 return cached_drop_target_helper_;
36 }
37
38 ///////////////////////////////////////////////////////////////////////////////
39 // BaseDropTarget, IDropTarget implementation:
40
41 HRESULT BaseDropTarget::DragEnter(IDataObject* data_object,
42 DWORD key_state,
43 POINTL cursor_position,
44 DWORD* effect) {
45 // Tell the helper that we entered so it can update the drag image.
46 IDropTargetHelper* drop_helper = DropHelper();
47 if (drop_helper) {
48 drop_helper->DragEnter(GetHWND(), data_object,
49 reinterpret_cast<POINT*>(&cursor_position), *effect);
50 }
51
52 // You can't drag and drop within the same HWND.
53 if (suspended_) {
54 *effect = DROPEFFECT_NONE;
55 return S_OK;
56 }
57
58 // Update the drag identity, skipping 0.
59 if (++drag_identity_ == 0)
60 ++drag_identity_;
61
62 current_data_object_ = data_object;
63 POINT screen_pt = { cursor_position.x, cursor_position.y };
64 *effect = OnDragEnter(current_data_object_, key_state, screen_pt, *effect);
65 return S_OK;
66 }
67
68 HRESULT BaseDropTarget::DragOver(DWORD key_state,
69 POINTL cursor_position,
70 DWORD* effect) {
71 // Tell the helper that we moved over it so it can update the drag image.
72 IDropTargetHelper* drop_helper = DropHelper();
73 if (drop_helper)
74 drop_helper->DragOver(reinterpret_cast<POINT*>(&cursor_position), *effect);
75
76 if (suspended_) {
77 *effect = DROPEFFECT_NONE;
78 return S_OK;
79 }
80
81 POINT screen_pt = { cursor_position.x, cursor_position.y };
82 *effect = OnDragOver(current_data_object_, key_state, screen_pt, *effect);
83 return S_OK;
84 }
85
86 HRESULT BaseDropTarget::DragLeave() {
87 // Tell the helper that we moved out of it so it can update the drag image.
88 IDropTargetHelper* drop_helper = DropHelper();
89 if (drop_helper)
90 drop_helper->DragLeave();
91
92 if (suspended_)
93 return S_OK;
94
95 OnDragLeave(current_data_object_);
96
97 current_data_object_ = NULL;
98 return S_OK;
99 }
100
101 HRESULT BaseDropTarget::Drop(IDataObject* data_object,
102 DWORD key_state,
103 POINTL cursor_position,
104 DWORD* effect) {
105 // Tell the helper that we dropped onto it so it can update the drag image.
106 IDropTargetHelper* drop_helper = DropHelper();
107 if (drop_helper) {
108 drop_helper->Drop(current_data_object_,
109 reinterpret_cast<POINT*>(&cursor_position), *effect);
110 }
111
112 if (suspended_) {
113 *effect = DROPEFFECT_NONE;
114 return S_OK;
115 }
116
117 POINT screen_pt = { cursor_position.x, cursor_position.y };
118 *effect = OnDrop(current_data_object_, key_state, screen_pt, *effect);
119 return S_OK;
120 }
121
122 ///////////////////////////////////////////////////////////////////////////////
123 // BaseDropTarget, IUnknown implementation:
124
125 HRESULT BaseDropTarget::QueryInterface(const IID& iid, void** object) {
126 *object = NULL;
127 if (IsEqualIID(iid, IID_IUnknown) || IsEqualIID(iid, IID_IDropTarget)) {
128 *object = this;
129 } else {
130 return E_NOINTERFACE;
131 }
132 AddRef();
133 return S_OK;
134 }
135
136 ULONG BaseDropTarget::AddRef() {
137 return ++ref_count_;
138 }
139
140 ULONG BaseDropTarget::Release() {
141 if (--ref_count_ == 0) {
142 delete this;
143 return 0U;
144 }
145 return ref_count_;
146 }
147
148 DWORD BaseDropTarget::OnDragEnter(IDataObject* data_object,
149 DWORD key_state,
150 POINT cursor_position,
151 DWORD effect) {
152 return DROPEFFECT_NONE;
153 }
154
155 DWORD BaseDropTarget::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,
167 POINT cursor_position,
168 DWORD effect) {
169 return DROPEFFECT_NONE;
170 }
OLDNEW
« no previous file with comments | « base/base_drop_target.h ('k') | chrome/browser/autocomplete/autocomplete_edit_view_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698