Skip to content

Commit ef3d0a1

Browse files
authored
Update BackgroundColor.md
1 parent 635ca02 commit ef3d0a1

1 file changed

Lines changed: 62 additions & 47 deletions

File tree

specs/BackgroundColor.md

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ WebView2 developers have provided feedback that there is a 'white flicker' when
33

44

55
# Description
6-
The `BackgroundColor` property allows developers to set the color that shows when WebView has not loaded any web content and when a webpage does not specify a background color. Color is specified by the COREWEBVIEW2_COLOR value meaning the background color can also be transparent. The WebView background color will show before the initial navigation, between navigations before the next page has rendered, and for pages with no `background` style properties set. To clarify the latter case, WebView will always honor a webpage's background content. `BackgroundColor` will only show in the absence of css `background` style properties. In that case, WebView will render web content over the `BackgroundColor` color. For a transparent background, web content will render over hosting app content. WebView's default background color is white to match the browser experience. It is important to note that while COREWEBVIEW2_COLOR has `A` an alpha value, semi-transparent colors are not supported by this API and setting `BackgroundColor` to a semi-transparent color will fail with E_INVALIDARG. Any alpha value above 0 and below 255 will result in an E_INVALIDARG error. `BackgroundColor` can only be an opaque color or transparent. The `BackgroundColor` property enables a seamless UI experience. Developers can replace the 'white flash' between loading pages with a color better suited to their application. For websites with no specified background color, developers can display web contents over a color of their choosing. They can also do away with the background color entirely with transparency and have the 'in between pages color' just be hosting content, or have hosting app content be the backdrop for webpages without a background color specified.
6+
The `BackgroundColor` property enables a seamless UI experience. Developers can replace the 'white flash' between loading pages with a color better suited to their application. For websites with no specified background color, developers can display web contents over a color of their choosing. They can also do away with the background color entirely with transparency and have the 'in between pages color' just be hosting content, or have hosting app content be the backdrop for webpages without a background color specified.
77

88
# Examples
99
## Win32 C++
@@ -19,78 +19,93 @@ void ViewComponent::SetBackgroundColor(COLORREF color, bool transparent)
1919
m_controller->put_BackgroundColor(wvColor);
2020
}
2121
```
22-
## .WinForms
23-
Set the background color of the WinForms WebView control with the BackColor property on every WinForms control.
22+
## C#
2423
```c#
25-
private void backgroundColorMenuItem_Click(object sender, EventArgs e)
24+
private void SetBackgroundColor(Windows.UI.Color color)
2625
{
27-
System.Drawing.KnownColor backgroundColor;
28-
var menuItem = (System.Windows.Forms.ToolStripMenuItem)sender;
29-
if (menuItem.Text == "Red")
30-
{
31-
backgroundColor = System.Drawing.KnownColor.Red;
32-
}
33-
else if (menuItem.Text == "Blue")
34-
{
35-
backgroundColor = System.Drawing.KnownColor.Blue;
36-
}
37-
else if (menuItem.Text == "Transparent")
38-
{
39-
backgroundColor = System.Drawing.KnownColor.Transparent;
40-
}
41-
else
42-
{
43-
// Default to white
44-
backgroundColor = System.Drawing.KnownColor.White;
45-
}
46-
this.webView2Control.BackColor = System.Drawing.Color.FromKnownColor(backgroundColor);
26+
_coreWebView2Controller.BackgroundColor = color;
4727
}
4828
```
4929

5030

5131
# Remarks
52-
Currently translucent colors are not supported by the API. This work is being tracked and will be added later.
53-
54-
55-
# API Notes
32+
Currently only colors with an A set to 0 or 255 are supported by the API. The work to support semi-transparent colors is being tracked and will be added later
5633

5734

5835
# API Details
5936
## Win32 C++
6037
```cpp
61-
[uuid(4d00c0d1-9434-4eb6-8078-8697a560334f), object, pointer_default(unique)]
38+
// This is the ICoreWebView2Controller2 interface
6239
interface ICoreWebView2Controller2 : ICoreWebView2Controller {
6340

64-
// ...
41+
/// The `BackgroundColor` property allows developers to set the color that
42+
/// shows when WebView has not loaded any web content and when a webpage
43+
/// does not specify a background color. Color is specified by the
44+
/// COREWEBVIEW2_COLOR value meaning the background color can also be
45+
/// transparent.
46+
/// The WebView background color will show before the initial navigation,
47+
/// between navigations before the next page has rendered, and for pages with
48+
/// no `background` style properties set. To clarify the latter case, WebView
49+
/// will always honor a webpage's background content. `BackgroundColor` will
50+
/// only show in the absence of css `background` style properties. In that
51+
/// case, WebView will render web content over the `BackgroundColor` color.
52+
/// For a transparent background, web content will render over hosting app
53+
/// content. WebView's default background color is white to match the browser
54+
/// experience.
55+
/// It is important to note that while COREWEBVIEW2_COLOR has `A` an alpha
56+
/// value, semi-transparent colors are not supported by this API and setting
57+
/// `BackgroundColor` to a semi-transparent color will fail with E_INVALIDARG.
58+
/// Any alpha value above 0 and below 255 will result in an E_INVALIDARG
59+
/// error.`BackgroundColor` can only be an opaque color or transparent.
60+
///
61+
/// The `BackgroundColor` property enables a seamless UI experience.
62+
/// Developers can replace the 'white flash' between loading pages with a
63+
/// color better suited to their application. For websites with no specified
64+
/// background color, developers can display web contents over a color of
65+
/// their choosing. They can also do away with the background color entirely
66+
/// with transparency and have the 'in between pages color' just be hosting
67+
/// content, or have hosting app content be the backdrop for webpages without
68+
/// a background color specified.
69+
///
70+
/// \snippet ViewComponent.cpp BackgroundColor
6571

66-
/// This property can be modified to get and set the color that shows before the WebView
67-
/// has loaded any web content.
6872
[propget] HRESULT BackgroundColor([out, retval] COREWEBVIEW2_COLOR* backgroundColor);
69-
[propput] HRESULT BackgroundColor([in] COREWEBVIEW2_COLOR backgroundColor);
7073

71-
// ...
74+
/// Sets the `BackgroundColor` property.
75+
76+
[propput] HRESULT BackgroundColor([in] COREWEBVIEW2_COLOR backgroundColor);
7277
}
7378

7479

75-
/// A value representing color for WebView2
80+
/// A value representing RGBA color (Red, Green, Blue, Alpha) for WebView2.
81+
/// Each component takes a value from 0 to 255, with 0 being no intensity
82+
/// and 255 being the highest intensity.
83+
7684
typedef struct COREWEBVIEW2_COLOR {
85+
86+
/// Specifies the intensity of the Alpha ie. opacity value. 0 is transparent,
87+
/// 255 is opaque.
88+
7789
BYTE A;
90+
91+
/// Specifies the intensity of the Red color
92+
7893
BYTE R;
94+
95+
/// Specifies the intensity of the Green color
96+
7997
BYTE G;
98+
99+
/// Specifies the intensity of the Blue color
100+
80101
BYTE B;
81102
} COREWEBVIEW2_COLOR;
82103
```
83-
## .NET
104+
## .NET and WinRT
84105
```c#
85-
public partial class CoreWebView2Controller
86-
{
87-
public Color BackgroundColor { get; set; }
88-
}
89-
```
90-
## WinRT C++
91-
```cpp
92-
winrt::Windows::UI::Color BackgroundColor();
93-
void BackgroundColor(winrt::Windows::UI::Color valueIn);
106+
unsealed runtimeclass CoreWebView2Controller
107+
{
108+
// ..
109+
Windows.UI.Color BackgroundColor { get; set; };
110+
}
94111
```
95-
96-
# Appendix

0 commit comments

Comments
 (0)