Skip to content

Commit 3866c89

Browse files
Included a new API spec for Webview2 Window Controls Overlay
1 parent 5d6debb commit 3866c89

File tree

2 files changed

+132
-1
lines changed

2 files changed

+132
-1
lines changed

specs/IsWindowControlsOverlayEnabled.md

-1
This file was deleted.
+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
WebView2 Window Controls
2+
===
3+
4+
# Background
5+
This API allows devs to Enable and configure The Webview2 Window Controls overlay.
6+
The Overlay is a region on the top right/left of the webview window which contains
7+
the caption buttons (minimize, maximize, restore, close). Enabing the Overlay allows
8+
for custom app title bars rendered completly inside the webview window.
9+
10+
The overlay configuration lives on the controller options object. The intent is to
11+
configure it once, before creating the controller. The configuration cannot
12+
be changed after the controller/webview has been created.
13+
14+
This API is designed to be used in addition with the other non-client region APIs
15+
and features. These include `app-region: drag`, and `IsNonClientRegionSupportEnabled`.
16+
# Examples
17+
18+
## Win32 C++
19+
```cpp
20+
AppWindow::AppWindow() {
21+
m_mainWindow = CreateWindowExW(
22+
WS_EX_CONTROLPARENT,
23+
GetWindowClass(),
24+
L""
25+
WS_POPUPWINDOW,
26+
0,0, 800, 800,
27+
nullptr, nullptr,
28+
g_hInstance, nullptr);
29+
}
30+
31+
void AppWindow::OnCreateWebview2ControllerCompleted(HRESULT hr, ICoreWebview2Controller* controller)
32+
{
33+
wil::com_ptr<ICoreWebView2Controller5> controller5;
34+
35+
if (controller->QueryInterface(&controller5) == S_OK)
36+
{
37+
wil::com_ptr<ICoreWebView2WindowControlsOverlayConfiguration> wco_config;
38+
CHECK_FAILURE(controller5->(&wco_config));
39+
40+
wco_config->put_IsEnabled(true);
41+
COREWEBVIEW2_COLOR color {1, 0, 0, 225};
42+
wco_config->put_TitleBarColor(color);
43+
}
44+
}
45+
```
46+
## .NET C#
47+
```c#
48+
// WebView2 control is defined in the xaml
49+
// <wv2:WebView2 x:Name="webView" Source="https://www.microsoft.com/"/>
50+
public MainWindow()
51+
{
52+
InitializeComponent();
53+
m_AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;
54+
55+
CoreWebView2WindowControlsOverlayConfiguration config = _coreWebView2Controller.WindowControlsOverlayConfiguration;
56+
config.IsEnabled = true;
57+
config.color = Color.FromARGB(0, 0, 255);
58+
}
59+
```
60+
61+
# API Details
62+
## Win32 C++
63+
```cpp
64+
/// Controller Options API used to configure the window controls overlay.
65+
[uuid(101e36ca-7f75-5105-b9be-fea2ba61a2fd), object, pointer_default(unique)]
66+
interface ICoreWebView2Controller5 : IUnknown {
67+
/// Gets the `WindowControlsOverlayConfiguration` object.
68+
[propget] HRESULT WindowControlsOverlayConfiguration([out, retval] ICoreWebView2WindowControlsOverlayConfiguration** value);
69+
}
70+
71+
/// This is the ICoreWebView2WindowControlsOverlayConfiguration
72+
[uuid(c9f7378b-8dbb-5445-bacb-08a3fdf032f0), object, pointer_default(unique)]
73+
interface ICoreWebView2WindowControlsOverlayConfiguration : IUnknown {
74+
/// Gets the `Height` property.
75+
[propget] HRESULT Height([out, retval] UINT32* value);
76+
77+
/// The `Height` property in pixels, allows devs to set the height of the overlay and
78+
/// title bar area. Defaults to 48px
79+
///
80+
[propput] HRESULT Height([in] UINT32 value);
81+
82+
/// Gets the `IsEnabled` property.
83+
[propget] HRESULT IsEnabled([out, retval] BOOL* value);
84+
85+
/// The `IsEnabled` property allows devs to opt in/out of using
86+
/// the WV2 custom caption controls. Defaults to `FALSE`.
87+
///
88+
/// When this property is `TRUE`, WV2 will draw its own caption controls on the
89+
/// top right corner of the window.
90+
///
91+
[propput] HRESULT IsEnabled([in] BOOL value);
92+
93+
/// Gets the `TitleBarColor` property.
94+
[propget] HRESULT TitleBarColor([out, retval] COREWEBVIEW2_COLOR* value);
95+
96+
/// The `TitleBarColor` property allows devs to set a background color
97+
/// for the top of the webview window from (0,0, webview_ window_width, this Height property)
98+
///
99+
[propput] HRESULT TitleBarColor([in] COREWEBVIEW2_COLOR value);
100+
}
101+
```
102+
103+
## .NET and WinRT
104+
```c#
105+
namespace Microsoft.Web.WebView2.Core
106+
{
107+
runtimeclass CoreWebView2Controller
108+
{
109+
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2Controller")]
110+
{
111+
CoreWebView2WindowControlsOverlayConfiguration WindowControlsOverlayConfiguration { get; };
112+
}
113+
}
114+
115+
runtimeclass CoreWebView2WindowControlsOverlayConfiguration
116+
{
117+
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2WindowControlsOverlayConfiguration")]
118+
{
119+
Boolean IsEnabled { get; set; };
120+
UInt32 Height { get; set; };
121+
System.Drawing.Color TitleBarColor { get; set; }
122+
}
123+
}
124+
}
125+
```
126+
127+
128+
129+
# Appendix
130+
To provide your app users with the best experience, it is important to handle webview
131+
initialization errors appropriatly. Provide your users with a way to close the window
132+
or restart the App.

0 commit comments

Comments
 (0)