@@ -38,7 +38,9 @@ specifies which corresponding IDropTarget function was called.
38
38
39
39
40
40
# Examples
41
+ ## Win32
41
42
``` c++
43
+ // Win32 Sample
42
44
// Initialized elsewhere
43
45
wil::com_ptr<ICoreWebView2Controller> webViewController;
44
46
@@ -120,9 +122,51 @@ HRESULT DropTarget::Drop(IDataObject* dataObject,
120
122
}
121
123
```
122
124
125
+ ## WinRT
126
+ ```c#
127
+ // WinRT Sample
128
+ private void WebView_DragEnter(object sender, DragEventArgs e)
129
+ {
130
+ uint keyboardState =
131
+ ConvertDragDropModifiersToWin32KeyboardState(e.Modifiers);
132
+ Point pointerPosition = CoreWindow.GetForCurrentThread().PointerPosition;
133
+ DataPackageOperation operation =
134
+ (DataPackageOperation)webView2CompositionController.DragEnter(
135
+ e.Data, keyboardState, pointerPosition);
136
+ e.AcceptedOperation = operation;
137
+ }
138
+
139
+ private void WebView_DragOver(object sender, DragEventArgs e)
140
+ {
141
+ uint keyboardState =
142
+ ConvertDragDropModifiersToWin32KeyboardState(e.Modifiers);
143
+ Point pointerPosition = CoreWindow.GetForCurrentThread().PointerPosition;
144
+ DataPackageOperation operation =
145
+ (DataPackageOperation)webView2CompositionController.DragOver(
146
+ keyboardState, pointerPosition);
147
+ e.AcceptedOperation = operation;
148
+ }
149
+
150
+ private void WebView_DragLeave(object sender, DragEventArgs e)
151
+ {
152
+ webView2CompositionController.DragLeave();
153
+ }
154
+
155
+ private void WebView_Drop(object sender, DragEventArgs e)
156
+ {
157
+ uint keyboardState =
158
+ ConvertDragDropModifiersToWin32KeyboardState(e.Modifiers);
159
+ Point pointerPosition = CoreWindow.GetForCurrentThread().PointerPosition;
160
+ DataPackageOperation operation =
161
+ (DataPackageOperation)webView2CompositionController.Drop(
162
+ e.Data, keyboardState, pointerPosition);
163
+ e.AcceptedOperation = operation;
164
+ }
165
+ ```
166
+
123
167
124
168
# API Details
125
- ## Win32 C++
169
+ ## Win32
126
170
``` c++
127
171
[v1_enum]
128
172
typedef enum COREWEBVIEW2_DROP_TARGET_ACTION {
@@ -135,6 +179,15 @@ typedef enum COREWEBVIEW2_DROP_TARGET_ACTION {
135
179
136
180
``` c++
137
181
interface ICoreWebView2CompositionController : IUnknown {
182
+ /// This set of APIs (DragEnter, DragLeave, DragOver, and Drop) will allow
183
+ /// users to drop things such as images, text, and links into the WebView as
184
+ /// part of a drag/drop operation. The reason that we need a separate API for
185
+ /// this with composition hosting is because we don't have an HWND to call
186
+ /// RegisterDragDrop on. The hosting app needs to call RegisterDragDrop on the
187
+ /// HWND that contains the WebView and implement IDropTarget so it can forward
188
+ /// the calls (IDropTarget::DragEnter, DragMove, DragLeave, and Drop) to the
189
+ /// WebView.
190
+ ///
138
191
/// This function corresponds to IDropTarget::DragEnter
139
192
///
140
193
/// The hosting application must register as an IDropTarget and implement
@@ -152,6 +205,9 @@ interface ICoreWebView2CompositionController : IUnknown {
152
205
[ in] POINT point,
153
206
[ out, retval] DWORD* effect);
154
207
208
+ /// Please refer to DragEnter for more information on how Drag/Drop works with
209
+ /// WebView2.
210
+ ///
155
211
/// This function corresponds to IDropTarget::DragLeave
156
212
///
157
213
/// The hosting application must register as an IDropTarget and implement
@@ -162,6 +218,9 @@ interface ICoreWebView2CompositionController : IUnknown {
162
218
/// object before forwarding the call to WebView.
163
219
HRESULT DragLeave();
164
220
221
+ /// Please refer to DragEnter for more information on how Drag/Drop works with
222
+ /// WebView2.
223
+ ///
165
224
/// This function corresponds to IDropTarget::DragOver
166
225
///
167
226
/// The hosting application must register as an IDropTarget and implement
@@ -178,6 +237,9 @@ interface ICoreWebView2CompositionController : IUnknown {
178
237
[ in] POINT point,
179
238
[ out, retval] DWORD* effect);
180
239
240
+ /// Please refer to DragEnter for more information on how Drag/Drop works with
241
+ /// WebView2.
242
+ ///
181
243
/// This function corresponds to IDropTarget::Drop
182
244
///
183
245
/// The hosting application must register as an IDropTarget and implement
@@ -196,25 +258,26 @@ interface ICoreWebView2CompositionController : IUnknown {
196
258
[ out, retval] DWORD* effect);
197
259
}
198
260
```
261
+
199
262
## WinRT
200
- ``` c++
263
+ ``` c#
201
264
namespace Microsoft .Web .WebView2 .Core
202
265
{
203
- uint32_t DragEnter(
204
- winrt. Windows.ApplicationModel.DataTransfer.DataPackage const& dataObject,
205
- uint32_t keyState,
206
- winrt.Windows.Foundation. Point point);
266
+ uint DragEnter(
267
+ Windows.ApplicationModel.DataTransfer.DataPackage dataObject,
268
+ uint keyState,
269
+ Point point);
207
270
208
271
void DragLeave();
209
272
210
- uint32_t DragOver(
211
- uint32_t keyState,
212
- winrt:: Windows.Foundation.Point point);
273
+ uint DragOver(
274
+ uint keyState,
275
+ Windows.Foundation.Point point);
213
276
214
- uint32_t Drop(
215
- winrt. Windows.ApplicationModel.DataTransfer.DataPackage const& dataObject,
216
- uint32_t keyState,
217
- winrt. Windows.Foundation.Point point);
277
+ uint Drop(
278
+ Windows.ApplicationModel.DataTransfer.DataPackage dataObject,
279
+ uint keyState,
280
+ Windows.Foundation.Point point);
218
281
}
219
282
```
220
283
0 commit comments