Skip to content

Commit c548bab

Browse files
authored
Create APIReview_AllowDrop.md
1 parent 623787d commit c548bab

1 file changed

Lines changed: 98 additions & 0 deletions

File tree

specs/APIReview_AllowDrop.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Background
2+
Currently the drag&drop functionality is default enabled in webview2 and there is no way to disable it. Some developers may want to disbale this functionality in their applications
3+
based upon their scenarios. According to such feature requirements, we add the new API to provide developers with the capability to configure the drag&drop functionality.
4+
5+
# Description
6+
We add a new `AllowDrop` property in `CoreWebView2Controller`. This API allows end developers to toggle the drag&drop functionality easily.
7+
If it's disabled, any drag&drop actions will keep out of work. By default, it's disabled to accommodate to conventions.
8+
9+
# Examples
10+
## C++
11+
12+
```cpp
13+
void ToggleAllowDrop()
14+
{
15+
// Get webView's controller
16+
wil::com_ptr<ICoreWebView2Controller> controller = m_appWindow->GetWebViewController();
17+
if (controller)
18+
{
19+
BOOL allowDrop;
20+
CHECK_FAILURE(controller->get_AllowDrop(&allowDrop));
21+
if (allowDrop)
22+
{
23+
CHECK_FAILURE(controller->put_AllowDrop(FALSE));
24+
MessageBox(
25+
nullptr, L"WebView disallows dropping files now.",
26+
L"WebView AllowDrop property changed", MB_OK);
27+
}
28+
else
29+
{
30+
CHECK_FAILURE(controller->put_AllowDrop(TRUE));
31+
MessageBox(
32+
nullptr, L"WebView allows dropping files now.",
33+
L"WebView AllowDrop property changed", MB_OK);
34+
}
35+
}
36+
}
37+
```
38+
39+
## C#
40+
```c#
41+
void ToggleAllowDrop(object target, ExecutedRoutedEventArgs e)
42+
{
43+
// Get webView's controller
44+
var controller = _webView.CoreWebView2Controller;
45+
if(controller.AllowDrop)
46+
{
47+
controller.AllowDrop = false;
48+
}
49+
else
50+
{
51+
controller.AllowDrop = true;
52+
}
53+
}
54+
```
55+
56+
# Remarks
57+
The `AllowDrop` property already exists in some controls of .net UI framework like WPF and WinForms.
58+
The .net control wrapper for webview2 natively inherits this property.
59+
But actually it doesn't really work until this new API is added.
60+
When the new API is promoted to public, we will adjust the WPF/WinForms webview2 control to consume the new API accordingly.
61+
62+
63+
# API Notes
64+
See [API Details](#api-details) section below for API reference.
65+
66+
# API Details
67+
68+
## Win32 C++
69+
```c#
70+
// This is the ICoreWebView2Controller interface.
71+
[uuid(6a360a1f-d1cf-4d90-a0ab-ae2e7d1a29f0), object, pointer_default(unique)]
72+
interface ICoreWebView2Controller : IUnknown {
73+
/// Gets the `AllowDrop` property which is used to configure the capability
74+
/// that dropping files into webview2 is allowed or permitted.
75+
[propget] HRESULT AllowDrop([out, retval] BOOL * allowDrop);
76+
/// Sets the `AllowDrop` property which is used to configure the capability
77+
/// that dropping files into webview2 is allowed or permitted.
78+
[propput] HRESULT AllowDrop([in] BOOL allowDrop);
79+
}
80+
```
81+
82+
## .NET and WinRT
83+
```c#
84+
namespace Microsoft.Web.WebView2.Core
85+
{
86+
public class CoreWebView2Controller
87+
{
88+
//
89+
// Summary:
90+
// Gets or sets the WebView allow drop property.
91+
//
92+
// Remarks:
93+
// The AllowDrop is to configure the capability that dropping files into webview2
94+
// is allowed or permitted.
95+
public bool AllowDrop { get; set; }
96+
}
97+
}
98+
```

0 commit comments

Comments
 (0)