From 3d78e036fc65cb711bc5f9b61812cb30c4d8bb24 Mon Sep 17 00:00:00 2001 From: Citlalli Zarate Date: Tue, 5 Nov 2024 21:54:04 +0000 Subject: [PATCH] Update to adress latest comments --- ...ontrollerOptions.DefaultBackgroundColor.md | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/specs/CoreWebView2ControllerOptions.DefaultBackgroundColor.md b/specs/CoreWebView2ControllerOptions.DefaultBackgroundColor.md index 00fa26d5..4c25f889 100644 --- a/specs/CoreWebView2ControllerOptions.DefaultBackgroundColor.md +++ b/specs/CoreWebView2ControllerOptions.DefaultBackgroundColor.md @@ -30,20 +30,29 @@ applies the color too late. wil::com_ptr options; HRESULT hr = m_environment->CreateCoreWebView2ControllerOptions(&options); - wil::com_ptr stagingOptions; + if (hr == E_INVALIDARG) + { + return S_OK; + } + + wil::com_ptr stagingOptions;wil::com_ptr 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( - this, &AppWindow::OnCreateCoreWebView2ControllerCompleted).Get()); } + m_environment->CreateCoreWebView2Controller( + m_mainWindow, options.Get(), + Callback( + this, &AppWindow::OnCreateCoreWebView2ControllerCompleted).Get()); + + return S_OK; + } ``` @@ -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); } ``` @@ -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);