@@ -6,10 +6,15 @@ This API allows you to enable and configure the Webview2 Window Controls Overlay
6
6
The Overlay is a region on the top right/left of the webview window which contains
7
7
the caption buttons (minimize, maximize, restore, close). Enabing the Overlay allows
8
8
for custom app title bars rendered completely inside the webview window.
9
- The overlay Settings lives on the controller object.
10
9
11
10
This API is designed to be used in addition with the other non-client region APIs
12
11
and 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
+
13
18
# Examples
14
19
15
20
## Win32 C++
@@ -27,15 +32,19 @@ AppWindow::AppWindow() {
27
32
28
33
void AppWindow::OnCreateWebview2ControllerCompleted (HRESULT hr, ICoreWebview2Controller* controller)
29
34
{
30
- wil::com_ptr<ICoreWebView2Controller5 > controller5;
31
- CHECK_FAILURE(controller->QueryInterface(&controller5));
32
35
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));
35
41
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));
37
46
COREWEBVIEW2_COLOR color {1, 0, 0, 225};
38
- wco_config->put_TitleBarColor (color);
47
+ CHECK_FAILURE( wco_config->put_TitleBarBackgroundColor (color) );
39
48
}
40
49
```
41
50
## .NET C#
@@ -47,7 +56,7 @@ public MainWindow()
47
56
InitializeComponent();
48
57
m_AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;
49
58
50
- CoreWebView2WindowControlsOverlaySettings config = _coreWebView2Controller .WindowControlsOverlaySettings;
59
+ CoreWebView2WindowControlsOverlaySettings config = Webview2.CoreWebivew2 .WindowControlsOverlaySettings;
51
60
config.IsEnabled = true;
52
61
config.color = Color.FromARGB(0, 0, 255);
53
62
}
@@ -61,7 +70,7 @@ public MainWindow()
61
70
// / initialization errors appropriately. Provide your users with a way to close the window
62
71
// / or restart the App.
63
72
[uuid(101e36ca-7f75-5105 -b9be-fea2ba61a2fd), object, pointer_default(unique)]
64
- interface ICoreWebView2Controller5 : IUnknown {
73
+ interface ICoreWebView2_28 : IUnknown {
65
74
/// Gets the ` WindowControlsOverlaySettings ` object.
66
75
[ propget] HRESULT WindowControlsOverlaySettings([ out, retval] ICoreWebView2WindowControlsOverlaySettings** value);
67
76
}
@@ -74,7 +83,10 @@ interface ICoreWebView2WindowControlsOverlaySettings : IUnknown {
74
83
75
84
76
85
/// 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.
78
90
///
79
91
[ propput] HRESULT Height([ in] UINT32 value);
80
92
@@ -97,22 +109,23 @@ interface ICoreWebView2WindowControlsOverlaySettings : IUnknown {
97
109
///
98
110
/// The Overlay buttons will sit on top of the HTML content, and will prevent mouse interactions
99
111
/// 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
101
114
/// get the dimensions of the available titlebar area to the left of the overlay.
102
115
/// Similarly the navigator object wil contain a [ WindowControlsOverlay property] ( https://developer.mozilla.org/en-US/docs/Web/API/WindowControlsOverlay )
103
116
/// which can be used to get the titlebar area as a rect, and listen for changes
104
117
/// to the size of that area.
105
118
///
106
119
[ propput] HRESULT IsEnabled([ in] BOOL value);
107
120
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);
110
123
111
- /// The ` TitleBarColor ` property allows you to set a background color
124
+ /// The ` TitleBarBackgroundColor ` property allows you to set a background color
112
125
/// for the overlay. Based on the background color you choose, Webview2
113
126
///will automatically calculate a foreground and hover color that will
114
127
/// provide you the best contrast while maintaining accessibility.
115
- /// Defaults to #f3f3f3
128
+ /// Defaults to #f3f3f3. This API supports transparency.
116
129
[ propput] HRESULT TitleBarBackgroundColor([ in] COREWEBVIEW2_COLOR value);
117
130
}
118
131
```
@@ -121,9 +134,9 @@ interface ICoreWebView2WindowControlsOverlaySettings : IUnknown {
121
134
``` c#
122
135
namespace Microsoft .Web .WebView2 .Core
123
136
{
124
- runtimeclass CoreWebView2Controller
137
+ runtimeclass CoreWebView2
125
138
{
126
- [interface_name (" Microsoft.Web.WebView2.Core.ICoreWebView2Controller " )]
139
+ [interface_name (" Microsoft.Web.WebView2.Core.ICoreWebView2_28 " )]
127
140
{
128
141
CoreWebView2WindowControlsOverlaySettings WindowControlsOverlaySettings { get; };
129
142
}
@@ -135,8 +148,9 @@ namespace Microsoft.Web.WebView2.Core
135
148
{
136
149
Boolean IsEnabled { get ; set ; };
137
150
UInt32 Height { get ; set ; };
138
- Windows .UI .Color TitleBarColor { get ; set ; }
151
+ Windows .UI .Color TitleBarBackgroundColor { get ; set ; }
139
152
}
140
153
}
141
154
}
142
155
```
156
+
0 commit comments