Skip to content

Commit 13a20c2

Browse files
authored
Create APIReview_BackgroundColor
1 parent 5941905 commit 13a20c2

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

specs/APIReview_BackgroundColor

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Background
2+
WebView2 developers have provided feedback that there is a 'white flicker' when navigating between pages. This flicker comes from WebView briefly showing its default background color for when no web page is loaded. Developers should be able to set a custom background color for the WebView that matches the color scheme of their app and avoids this flicker. We have also received feedback requesting the ability to set the WebView's background color transparent. This way developers can create a seamless UI experience where the WebView displays web content directly over host app content. The BackgroundColor API addresses this need.
3+
4+
5+
# Description
6+
The `BackgroundColor` property allows users to set the color that shows before WebView loads any web content - the default is white. This API uses the `CoreWebView2Color` value which is used to specify an RGBA color. Important to note is the A value which allows users to set transparency. Semi-transparent colors are not currently supported, but the work is pending. The `BackgroundColor` property enables a seamless UI experience. Developers can choose a color to show between loading pages that matches the scheme of the hosting application. Or do away with the color entirely and just show the hosting app's content.
7+
8+
# Examples
9+
The fields of CoreWebView2Color can be set with plain old integer values between 0 and 255. In the following example, we see the app reading color values from a COLORREF (which are integers under the covers) into a CoreWebView2Color. It then sets the CoreWebView2Color.A value to 0 or 255. Once the CoreWebView2Color value is filled out, it is passed to the controller's put_BackgroundColor API.
10+
```cpp
11+
void ViewComponent::SetBackgroundColor(COLORREF color, bool transparent)
12+
{
13+
CoreWebView2Color wvColor;
14+
wvColor.R = GetRValue(color);
15+
wvColor.G = GetGValue(color);
16+
wvColor.B = GetBValue(color);
17+
wvColor.A = transparent ? 0 : 255;
18+
m_controller->put_BackgroundColor(wvColor);
19+
}
20+
```
21+
22+
23+
# Remarks
24+
Currently translucent colors are not supported by the API. This work is being tracked and will be added later. Passing a CoreWebView2Color value with an A value greater than 0 or less than 255 will result in an error.
25+
26+
27+
# API Notes
28+
29+
30+
# API Details
31+
```cpp
32+
[uuid(4d00c0d1-9434-4eb6-8078-8697a560334f), object, pointer_default(unique)]
33+
interface ICoreWebView2Controller : IUnknown {
34+
35+
// ...
36+
37+
/// This property can be modified to get and set the color that shows before the WebView
38+
/// has loaded any web content.
39+
[propget] HRESULT BackgroundColor([out, retval] CoreWebView2Color* backgroundColor);
40+
[propput] HRESULT BackgroundColor([in] CoreWebView2Color backgroundColor);
41+
}
42+
43+
44+
/// A value representing color for WebView2
45+
typedef struct CoreWebView2Color {
46+
BYTE A;
47+
BYTE R;
48+
BYTE G;
49+
BYTE B;
50+
} CoreWebView2Color;
51+
```
52+
53+
# Appendix

0 commit comments

Comments
 (0)