Skip to content

Commit bce67e9

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

File tree

2 files changed

+120
-1
lines changed

2 files changed

+120
-1
lines changed

specs/IsWindowControlsOverlayEnabled.md

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

0 commit comments

Comments
 (0)