Skip to content

Commit 454106e

Browse files
authored
Merge pull request #1512 from MicrosoftEdge/api-allowdrop-draft
Add spec for the new AllowDrop API
2 parents 623787d + d8535f8 commit 454106e

1 file changed

Lines changed: 103 additions & 0 deletions

File tree

specs/APIReview_AllowDrop.md

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

0 commit comments

Comments
 (0)