Skip to content

Commit

Permalink
Update to adress latest comments
Browse files Browse the repository at this point in the history
  • Loading branch information
citlalli-z committed Nov 12, 2024
1 parent bad09b9 commit 8c25360
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions specs/CoreWebView2ControllerOptions.DefaultBackgroundColor.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,31 @@ applies the color too late.
```cpp
 HRESULT AppWindow::CreateControllerWithOptions()
{
wil::com_ptr<ICoreWebView2ControllerOptions> options;
wil::com_ptr<ICoreWebView2ControllerOptions4> options4;
HRESULT hr = m_environment->CreateCoreWebView2ControllerOptions(&options);

wil::com_ptr<ICoreWebView2ControllerOptions> stagingOptions;
if (hr == E_INVALIDARG)
{
return S_OK;
}

wil::com_ptr<ICoreWebView2ControllerOptions4> options4;
auto result = options->QueryInterface(IID_PPV_ARGS(&stagingOptions));

if (SUCCEEDED(result))
{
COREWEBVIEW2_COLOR wvColor{255, 223, 225, 225};
stagingOptions->put_DefaultBackgroundColor(wvColor);

m_environment->CreateCoreWebView2Controller(
m_mainWindow, options.Get(),
Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
this, &AppWindow::OnCreateCoreWebView2ControllerCompleted).Get());
}

m_environment->CreateCoreWebView2Controller(
m_mainWindow,
SUCCEEDED(result) ? stagingOptions.Get() : options.Get(),
Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
this, &AppWindow::OnCreateCoreWebView2ControllerCompleted).Get());

return S_OK;

}
```

Expand All @@ -53,15 +61,16 @@ applies the color too late.
```c#
public MainWindow()
{
InitializeComponent();
SetDefaultBackgroundColor();
InitializeComponent();
SetDefaultBackgroundColor();
}

private void SetDefaultBackgroundColor()
{
CoreWebView2ControllerOptions options = WebView2.CoreWebView2.Environment.CreateCoreWebView2ControllerOptions();
CoreWebView2Environment environment = CoreWebView2Environment.CreateAsync();
CoreWebView2ControllerOptions options = environment.CreateCoreWebView2ControllerOptions();
options.DefaultBackgroundColor = Color.FromArgb(0, 0, 255);
WebView2.CoreWebView2.Environment.CreateCoreWebView2ControllerAsync(parentHwnd, options);
WebView2.EnsureCoreWebView2Async(environment, options);
}

```
Expand All @@ -87,15 +96,14 @@ interface ICoreWebView2ControllerOptions4 : IUnknown {
///
/// The `DefaultBackgroundColor` is the color that renders underneath all web
/// content. This means WebView renders this color when there is no web
/// content loaded. It is important to note that the default color is white.
/// content loaded. When no background color is defined in WebView2, it uses
/// the `DefaultBackgroundColor` property to render the background.
/// By default, this color is set to white.
///
/// Currently this API only supports opaque colors and transparency. It will
/// fail for colors with alpha values that don't equal 0 or 255 ie. translucent
/// colors are not supported. It also does not support transparency on Windows 7.
/// On Windows 7, setting DefaultBackgroundColor to a Color with an Alpha value
/// other than 255 will result in failure. On any OS above Win7, choosing a
/// transparent color will result in showing hosting app content. This means
/// webpages without explicit background properties defined will render web
/// content over hosting app content.
/// colors are not supported. When WebView2 is set to have a transparent background,
/// it renders the content of the parent window behind it.

[propget] HRESULT DefaultBackgroundColor([out, retval] COREWEBVIEW2_COLOR* value);
[propput] HRESULT DefaultBackgroundColor([in] COREWEBVIEW2_COLOR value);
Expand Down

0 comments on commit 8c25360

Please sign in to comment.