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 3d78e03
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions specs/CoreWebView2ControllerOptions.DefaultBackgroundColor.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,29 @@ applies the color too late.
wil::com_ptr<ICoreWebView2ControllerOptions> options;
HRESULT hr = m_environment->CreateCoreWebView2ControllerOptions(&options);

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

wil::com_ptr<ICoreWebView2ControllerOptions> stagingOptions;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, options.Get(),
Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
this, &AppWindow::OnCreateCoreWebView2ControllerCompleted).Get());

return S_OK;

}
```

Expand All @@ -59,9 +68,10 @@ 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 +97,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 3d78e03

Please sign in to comment.