@@ -6,10 +6,15 @@ This API allows you to enable and configure the Webview2 Window Controls Overlay
66The Overlay is a region on the top right/left of the webview window which contains
77the caption buttons (minimize, maximize, restore, close). Enabing the Overlay allows
88for custom app title bars rendered completely inside the webview window.
9- The overlay Settings lives on the controller object.
109
1110This API is designed to be used in addition with the other non-client region APIs
1211and features. These include ` app-region: drag ` , and ` IsNonClientRegionSupportEnabled ` .
12+
13+ # Conceptual pages (How To)
14+ Here is a concept doc on the window controls overlay: https://wicg.github.io/window-controls-overlay/#concepts .
15+ This was written for the PWA counterpart for this feature. From the perspective of
16+ HTML & Javascript layers, everything there applies in Webview2 as well.
17+
1318# Examples
1419
1520## Win32 C++
@@ -27,15 +32,19 @@ AppWindow::AppWindow() {
2732
2833void AppWindow::OnCreateWebview2ControllerCompleted (HRESULT hr, ICoreWebview2Controller* controller)
2934{
30- wil::com_ptr<ICoreWebView2Controller5 > controller5;
31- CHECK_FAILURE(controller->QueryInterface(&controller5));
3235
33- wil::com_ptr<ICoreWebView2WindowControlsOverlaySettings> wco_config;
34- CHECK_FAILURE(controller5->get_WindowControlsOverlaySettings(&wco_config));
36+ wil::com_ptr<ICoreWebView2> coreWebView2;
37+ CHECK_FAILURE(m_controller->get_CoreWebView2(&coreWebView2));
38+
39+ wil::com_ptr<ICoreWebView2> coreWebView2_28;
40+ CHECK_FAILURE(coreWebView2->QueryInterface(&coreWebView2_28));
3541
36- wco_config->put_IsEnabled(true);
42+ wil::com_ptr<ICoreWebView2WindowControlsOverlaySettings> windowControlsOverlaySettings;
43+ CHECK_FAILURE(coreWebView2_28->get_WindowControlsOverlaySettings(&wco_config));
44+
45+ CHECK_FAILURE(wco_config->put_IsEnabled(true));
3746 COREWEBVIEW2_COLOR color {1, 0, 0, 225};
38- wco_config->put_TitleBarColor (color);
47+ CHECK_FAILURE( wco_config->put_TitleBarBackgroundColor (color) );
3948}
4049```
4150## .NET C#
@@ -47,7 +56,7 @@ public MainWindow()
4756 InitializeComponent();
4857 m_AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;
4958
50- CoreWebView2WindowControlsOverlaySettings config = _coreWebView2Controller .WindowControlsOverlaySettings;
59+ CoreWebView2WindowControlsOverlaySettings config = Webview2.CoreWebivew2 .WindowControlsOverlaySettings;
5160 config.IsEnabled = true;
5261 config.color = Color.FromARGB(0, 0, 255);
5362}
@@ -61,7 +70,7 @@ public MainWindow()
6170// / initialization errors appropriately. Provide your users with a way to close the window
6271// / or restart the App.
6372[uuid(101e36ca-7f75-5105 -b9be-fea2ba61a2fd), object, pointer_default(unique)]
64- interface ICoreWebView2Controller5 : IUnknown {
73+ interface ICoreWebView2_28 : IUnknown {
6574 /// Gets the ` WindowControlsOverlaySettings ` object.
6675 [ propget] HRESULT WindowControlsOverlaySettings([ out, retval] ICoreWebView2WindowControlsOverlaySettings** value);
6776}
@@ -74,7 +83,10 @@ interface ICoreWebView2WindowControlsOverlaySettings : IUnknown {
7483
7584
7685 /// The ` Height ` property in raw screen pixels, allows you to set the height of the overlay and
77- /// title bar area. Defaults to 48px.
86+ /// title bar area. Defaults to 48px. There is no minimum height restriction for this API,
87+ /// so it is up to the developer to make sure that the height of your window controls overlay
88+ /// is enough that users can see and interact with it. We recommend using GetSystemMetrics(SM_CYCAPTION)
89+ // as you minimum height.
7890 ///
7991 [ propput] HRESULT Height([ in] UINT32 value);
8092
@@ -97,22 +109,23 @@ interface ICoreWebView2WindowControlsOverlaySettings : IUnknown {
97109 ///
98110 /// The Overlay buttons will sit on top of the HTML content, and will prevent mouse interactions
99111 /// with any elements directly below it, so you should avoid placing content there.
100- /// To that end, there are four CSS environment vairables defined to help you
112+ /// To that end, there are four [ CSS environment vairables] ( https://developer.mozilla.org/en-US/docs/Web/API/Window_Controls_Overlay_API#css_environment_variables )
113+ /// titlebar-area-x, titlebar-area-y, titlebar-area-width defined to help you
101114 /// get the dimensions of the available titlebar area to the left of the overlay.
102115 /// Similarly the navigator object wil contain a [ WindowControlsOverlay property] ( https://developer.mozilla.org/en-US/docs/Web/API/WindowControlsOverlay )
103116 /// which can be used to get the titlebar area as a rect, and listen for changes
104117 /// to the size of that area.
105118 ///
106119 [ propput] HRESULT IsEnabled([ in] BOOL value);
107120
108- /// Gets the ` TitleBarColor ` property.
109- [ propget] HRESULT TitleBarColor ([ out, retval] COREWEBVIEW2_COLOR* value);
121+ /// Gets the ` TitleBarBackgroundColor ` property.
122+ [ propget] HRESULT TitleBarBackgroundColor ([ out, retval] COREWEBVIEW2_COLOR* value);
110123
111- /// The ` TitleBarColor ` property allows you to set a background color
124+ /// The ` TitleBarBackgroundColor ` property allows you to set a background color
112125 /// for the overlay. Based on the background color you choose, Webview2
113126 ///will automatically calculate a foreground and hover color that will
114127 /// provide you the best contrast while maintaining accessibility.
115- /// Defaults to #f3f3f3
128+ /// Defaults to #f3f3f3. This API supports transparency.
116129 [ propput] HRESULT TitleBarBackgroundColor([ in] COREWEBVIEW2_COLOR value);
117130}
118131```
@@ -121,9 +134,9 @@ interface ICoreWebView2WindowControlsOverlaySettings : IUnknown {
121134``` c#
122135namespace Microsoft .Web .WebView2 .Core
123136{
124- runtimeclass CoreWebView2Controller
137+ runtimeclass CoreWebView2
125138 {
126- [interface_name (" Microsoft.Web.WebView2.Core.ICoreWebView2Controller " )]
139+ [interface_name (" Microsoft.Web.WebView2.Core.ICoreWebView2_28 " )]
127140 {
128141 CoreWebView2WindowControlsOverlaySettings WindowControlsOverlaySettings { get; };
129142 }
@@ -135,8 +148,9 @@ namespace Microsoft.Web.WebView2.Core
135148 {
136149 Boolean IsEnabled { get ; set ; };
137150 UInt32 Height { get ; set ; };
138- Windows .UI .Color TitleBarColor { get ; set ; }
151+ Windows .UI .Color TitleBarBackgroundColor { get ; set ; }
139152 }
140153 }
141154}
142155```
156+
0 commit comments