@@ -41,11 +41,6 @@ specifies which corresponding IDropTarget function was called.
41
41
## Win32
42
42
``` c++
43
43
// Win32 Sample
44
- // Initialized elsewhere
45
- wil::com_ptr<ICoreWebView2Controller> webViewController;
46
-
47
- webViewCompositionController =
48
- webViewController.query<ICoreWebView2CompositionController>();
49
44
50
45
// Implementation for IDropTarget
51
46
HRESULT DropTarget::DragEnter (IDataObject* dataObject,
@@ -64,7 +59,7 @@ HRESULT DropTarget::DragEnter(IDataObject* dataObject,
64
59
65
60
// Convert the screen point to client coordinates add the WebView's offset.
66
61
m_viewComponent->OffsetPointToWebView(&point);
67
- return webViewCompositionController ->DragEnter(
62
+ return m_webViewCompositionController ->DragEnter(
68
63
dataObject, keyState, point, effect);
69
64
}
70
65
@@ -84,7 +79,7 @@ HRESULT DropTarget::DragOver(DWORD keyState,
84
79
// Convert the screen point to client coordinates add the WebView's offset.
85
80
// This returns whether the resultant point is over the WebView visual.
86
81
m_viewComponent->OffsetPointToWebView(&point);
87
- return webViewCompositionController ->DragOver(
82
+ return m_webViewCompositionController ->DragOver(
88
83
keyState, point, effect);
89
84
}
90
85
@@ -97,7 +92,7 @@ HRESULT DropTarget::DragLeave()
97
92
dropHelper->DragLeave();
98
93
}
99
94
100
- return webViewCompositionController ->DragLeave();
95
+ return m_webViewCompositionController ->DragLeave();
101
96
}
102
97
103
98
HRESULT DropTarget::Drop(IDataObject* dataObject,
@@ -117,7 +112,7 @@ HRESULT DropTarget::Drop(IDataObject* dataObject,
117
112
// Convert the screen point to client coordinates add the WebView's offset.
118
113
// This returns whether the resultant point is over the WebView visual.
119
114
m_viewComponent->OffsetPointToWebView(&point);
120
- return webViewCompositionController ->Drop(
115
+ return m_webViewCompositionController ->Drop(
121
116
dataObject, keyState, point, effect);
122
117
}
123
118
```
@@ -162,6 +157,35 @@ private void WebView_Drop(object sender, DragEventArgs e)
162
157
e.Data, keyboardState, pointerPosition);
163
158
e.AcceptedOperation = operation;
164
159
}
160
+
161
+ // Win32 keyboard state modifiers that are relevant during drag and drop.
162
+ public const uint MK_LBUTTON = 1;
163
+ public const uint MK_RBUTTON = 2;
164
+ public const uint MK_SHIFT = 4;
165
+ public const uint MK_CONTROL = 8;
166
+ public const uint MK_MBUTTON = 16;
167
+ public const uint MK_ALT = 32;
168
+
169
+ // Helper function to convert DragDropModifiers to win32 keyboard state
170
+ // modifiers that WebView2 uses during drag and drop operation.
171
+ private uint ConvertDragDropModifiersToWin32KeyboardState(
172
+ Windows.ApplicationModel.DataTransfer.DragDrop.DragDropModifiers modifiers)
173
+ {
174
+ uint win32DragDropModifiers = 0;
175
+ if ((modifiers & DragDropModifiers.Shift) == DragDropModifiers.Shift)
176
+ win32DragDropModifiers |= MK_SHIFT;
177
+ if ((modifiers & DragDropModifiers.Control) == DragDropModifiers.Control)
178
+ win32DragDropModifiers |= MK_CONTROL;
179
+ if ((modifiers & DragDropModifiers.Alt) == DragDropModifiers.Alt)
180
+ win32DragDropModifiers |= MK_ALT;
181
+ if ((modifiers & DragDropModifiers.LeftButton) == DragDropModifiers.LeftButton)
182
+ win32DragDropModifiers |= MK_LBUTTON;
183
+ if ((modifiers & DragDropModifiers.MiddleButton) == DragDropModifiers.MiddleButton)
184
+ win32DragDropModifiers |= MK_MBUTTON;
185
+ if ((modifiers & DragDropModifiers.RightButton) == DragDropModifiers.RightButton)
186
+ win32DragDropModifiers |= MK_RBUTTON;
187
+ return win32DragDropModifiers;
188
+ }
165
189
```
166
190
167
191
@@ -263,21 +287,24 @@ interface ICoreWebView2CompositionController : IUnknown {
263
287
``` c#
264
288
namespace Microsoft .Web .WebView2 .Core
265
289
{
266
- uint DragEnter(
267
- Windows.ApplicationModel.DataTransfer.DataPackage dataObject,
268
- uint keyState,
269
- Point point);
270
-
271
- void DragLeave();
272
-
273
- uint DragOver(
274
- uint keyState,
275
- Windows.Foundation.Point point);
276
-
277
- uint Drop(
278
- Windows.ApplicationModel.DataTransfer.DataPackage dataObject,
279
- uint keyState,
280
- Windows.Foundation.Point point);
290
+ public sealed class CoreWebView2CompositionController : CoreWebView2Controller , ICoreWebView2CompositionController
291
+ {
292
+ uint DragEnter (
293
+ Windows.ApplicationModel.DataTransfer.DataPackage dataObject ,
294
+ uint keyState ,
295
+ Point point );
296
+
297
+ void DragLeave ();
298
+
299
+ uint DragOver (
300
+ uint keyState ,
301
+ Windows.Foundation.Point point );
302
+
303
+ uint Drop (
304
+ Windows.ApplicationModel.DataTransfer.DataPackage dataObject ,
305
+ uint keyState ,
306
+ Windows.Foundation.Point point );
307
+ }
281
308
}
282
309
```
283
310
0 commit comments