@@ -38,7 +38,9 @@ specifies which corresponding IDropTarget function was called.
3838
3939
4040# Examples
41+ ## Win32
4142``` c++
43+ // Win32 Sample
4244// Initialized elsewhere
4345wil::com_ptr<ICoreWebView2Controller> webViewController;
4446
@@ -120,9 +122,51 @@ HRESULT DropTarget::Drop(IDataObject* dataObject,
120122}
121123```
122124
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+
123167
124168# API Details
125- ## Win32 C++
169+ ## Win32
126170``` c++
127171[v1_enum]
128172typedef enum COREWEBVIEW2_DROP_TARGET_ACTION {
@@ -135,6 +179,15 @@ typedef enum COREWEBVIEW2_DROP_TARGET_ACTION {
135179
136180``` c++
137181interface 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+ ///
138191 /// This function corresponds to IDropTarget::DragEnter
139192 ///
140193 /// The hosting application must register as an IDropTarget and implement
@@ -152,6 +205,9 @@ interface ICoreWebView2CompositionController : IUnknown {
152205 [ in] POINT point,
153206 [ out, retval] DWORD* effect);
154207
208+ /// Please refer to DragEnter for more information on how Drag/Drop works with
209+ /// WebView2.
210+ ///
155211 /// This function corresponds to IDropTarget::DragLeave
156212 ///
157213 /// The hosting application must register as an IDropTarget and implement
@@ -162,6 +218,9 @@ interface ICoreWebView2CompositionController : IUnknown {
162218 /// object before forwarding the call to WebView.
163219 HRESULT DragLeave();
164220
221+ /// Please refer to DragEnter for more information on how Drag/Drop works with
222+ /// WebView2.
223+ ///
165224 /// This function corresponds to IDropTarget::DragOver
166225 ///
167226 /// The hosting application must register as an IDropTarget and implement
@@ -178,6 +237,9 @@ interface ICoreWebView2CompositionController : IUnknown {
178237 [ in] POINT point,
179238 [ out, retval] DWORD* effect);
180239
240+ /// Please refer to DragEnter for more information on how Drag/Drop works with
241+ /// WebView2.
242+ ///
181243 /// This function corresponds to IDropTarget::Drop
182244 ///
183245 /// The hosting application must register as an IDropTarget and implement
@@ -196,25 +258,26 @@ interface ICoreWebView2CompositionController : IUnknown {
196258 [ out, retval] DWORD* effect);
197259}
198260```
261+
199262## WinRT
200- ``` c++
263+ ``` c#
201264namespace Microsoft .Web .WebView2 .Core
202265{
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);
207270
208271 void DragLeave();
209272
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);
213276
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);
218281}
219282```
220283
0 commit comments