Skip to content

Commit 5224864

Browse files
authored
Add Nonclient Region Support Setting API
1 parent 9fd09a6 commit 5224864

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Background
2+
3+
To improve the developer experience for customizing non-client regions, WebView2 is working to support using DOM elements as nonclient regions. We currently have limited support for title bar aka draggable regions, and are working on building out support for caption control and resize regions.
4+
5+
For security and flexibility, we want developers to be able to enable or disable all custom nonclient functionality per WebView. Nonclient functionality will affect that app window's size and position so it's important that developers can definitively toggle access. This can be achieved in a limited way using a feature flag, but feature flags are applied per WebView2 environment, thus, an API on the WebView2 to enable/disable nonclient support via a setting is the better solution.
6+
7+
# Description
8+
`IsNonClientRegionSupportEnabled` defaults to `false`. Disabling/Enabling `IsNonClientRegionSupportEnabled` takes effect after the next navigation.
9+
10+
When the setting is set to `true`, then the following non-client region support will be enabled:
11+
* Draggable Regions will support dragging of the app and webview, the title bar context menu upon right click, and the maximizing to fill the window and restoring the window size upon double click of the html element.
12+
13+
When set to `false`, then all non-client region support will be disabled.
14+
* Web pages will not be able to use the `app-region` CSS style.
15+
16+
# Examples
17+
```cpp
18+
wil::com_ptr<ICoreWebView2> webView;
19+
void SettingsComponent::ToggleNonClientRegionSupportEnabled()
20+
{
21+
// Get webView's current settings
22+
wil::com_ptr<ICoreWebView2Settings> coreWebView2Settings;
23+
CHECK_FAILURE(webView->get_Settings(&coreWebView2Settings));
24+
wil::com_ptr<ICoreWebView2Settings9> coreWebView2Settings9;
25+
coreWebView2Settings9 = coreWebView2Settings.try_query<ICoreWebView2Settings9>();
26+
if (coreWebView2Settings9)
27+
{
28+
BOOL enabled;
29+
CHECK_FAILURE(coreWebView2Settings9->get_IsNonClientRegionSupportEnabled(&enabled));
30+
CHECK_FAILURE(coreWebView2Settings9->put_IsNonClientRegionSupportEnabled(enabled ? FALSE : TRUE));
31+
}
32+
}
33+
```
34+
```c#
35+
private WebView2 _webView;
36+
void ToggleNonClientRegionSupportEnabled()
37+
{
38+
var coreWebView2Settings = _webView.CoreWebView2.Settings;
39+
coreWebView2Settings.IsNonClientRegionSupportEnabled = !coreWebView2Settings.IsNonClientRegionSupportEnabled;
40+
}
41+
```
42+
43+
# Remarks
44+
If the flag is used to enable draggable regions in additional browser arguments, draggable region support will remain enabled even if `IsNonClientRegionSupportEnabled` setting is `false`.
45+
46+
# API Notes
47+
See [API Details](#api-details) section below for API reference.
48+
49+
## Declaring Non-client App Regions
50+
Non-client regions are HTML elements that are marked with the css style `app-region`.
51+
* Draggable regions can be declared through the values `drag` or `no-drag`.
52+
53+
# API Details
54+
```cpp
55+
/// This is the ICoreWebView2Settings Staging interface.
56+
[uuid(436CA5E2-2D50-43C7-9735-E760F299439E), object, pointer_default(unique)]
57+
interface ICoreWebView2Settings9 : ICoreWebView2Settings8 {
58+
/// `IsNonClientRegionSupportEnabled` property enables web pages to use the
59+
/// `app-region` CSS style. Disabling/Enabling the `IsNonClientRegionSupportEnabled`
60+
/// takes effect after the next navigation. Defaults to `FALSE`.
61+
///
62+
/// When this property is `TRUE`, then all the following non-client region support
63+
/// will be enabled:
64+
/// 1. Draggable Regions will be enabled and treated as a window's title bar.
65+
/// Draggable Regions are non-client regions on a webpage that are exposed through the css
66+
/// attribute `app-region` and can take the values `drag` or `no-drag`. When set to
67+
/// `drag`, these regions will be treated like the window's title bar, supporting
68+
/// dragging of the entire WebView and its host app window, the title bar context menu
69+
/// upon right click, and the maximizing to fill the window and restoring the window size
70+
/// upon double click of the html element.
71+
/// Draggable region support will be enabled if either the `IsNonClientRegionSupportEnabled`
72+
/// property or the flag is used in additional browser arguments (See put_AdditionalBrowserArguments).
73+
///
74+
/// When set to `FALSE`, then all non-client region support will be disabled. Web
75+
/// pages will not be able to use the `app-region` CSS style.
76+
[propget] HRESULT IsNonClientRegionSupportEnabled([out, retval] BOOL* enabled);
77+
/// Set the IsNonClientRegionSupportEnabled property
78+
[propput] HRESULT IsNonClientRegionSupportEnabled([in] BOOL enabled);
79+
}
80+
```
81+
82+
# Appendix
83+
We considered implementing the APIs in the ControllerOptions class, which would establish whether non-client regions would be supported for the life of the webview at creation. To provide greater flexibility of use, we decided to implement it as a setting.

0 commit comments

Comments
 (0)