Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Spec for IsWindowControlsOverlayEnabled.md #4613

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5d6debb
Create IsWindowControlsOverlayEnabled.md
tochukwuIbeEkeocha Jun 3, 2024
5a4eb5f
Included a new API spec for Webview2 Window Controls Overlay
tochukwuIbeEkeocha Jun 4, 2024
4bc0b7a
Update specs/WindowControlsOverlayConfiguration.md
tochukwuIbeEkeocha Nov 1, 2024
a4026d9
Update specs/WindowControlsOverlayConfiguration.md
tochukwuIbeEkeocha Nov 1, 2024
1714578
Update specs/WindowControlsOverlayConfiguration.md
tochukwuIbeEkeocha Nov 1, 2024
b89c178
Update specs/WindowControlsOverlayConfiguration.md
tochukwuIbeEkeocha Nov 1, 2024
1221980
Update specs/WindowControlsOverlayConfiguration.md
tochukwuIbeEkeocha Nov 1, 2024
8ff7c9e
Update specs/WindowControlsOverlayConfiguration.md
tochukwuIbeEkeocha Nov 1, 2024
01a2caf
Update specs/WindowControlsOverlayConfiguration.md
tochukwuIbeEkeocha Nov 1, 2024
abbe2c2
Fix Typo in specs/WindowControlsOverlayConfiguration.md
venky8951 Feb 18, 2025
fa8e6e5
Fix Grammer in specs/WindowControlsOverlayConfiguration.md
venky8951 Feb 18, 2025
f3c9cf3
Fix Typo specs/WindowControlsOverlayConfiguration.md
venky8951 Feb 18, 2025
ba722a8
Fix Spacing issue in specs/WindowControlsOverlayConfiguration.md
venky8951 Feb 18, 2025
964f28b
Casing fix specs/WindowControlsOverlayConfiguration.md
venky8951 Feb 18, 2025
cfefaae
Fix Casing in specs/WindowControlsOverlayConfiguration.md
venky8951 Feb 18, 2025
12b8134
Update specs/WindowControlsOverlayConfiguration.md
venky8951 Feb 18, 2025
f34e47c
Fix Varibale names
Feb 20, 2025
9790a1e
Add height Varibale in the comments line 113
Feb 20, 2025
0390596
Change TitleBarBackgroundColor to BackgroundColor
Feb 20, 2025
3d5d006
Remove uncliamed statements
Feb 20, 2025
2397d9f
fix typo
Feb 20, 2025
c880f4a
rename WindowControlsOverlaySettings to WindowControlsOverlay
Feb 20, 2025
b7f2a97
rename IsEnabled to IsVisible
Feb 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 155 additions & 0 deletions specs/WindowControlsOverlayConfiguration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
WebView2 Window Controls
===

# Background
This API allows you to enable and configure the Webview2 Window Controls Overlay.
The Overlay is a region on the top right/left of the webview window which contains
the caption buttons (minimize, maximize, restore, close). Enabling the Overlay allows
for custom app title bars rendered completely inside the webview window.

This API is designed to be used in addition with the other non-client region APIs
and features. These include `app-region: drag`, and `IsNonClientRegionSupportEnabled`.

# Conceptual pages (How To)
Here is a concept doc on the window controls overlay: https://wicg.github.io/window-controls-overlay/#concepts.
This was written for the PWA counterpart for this feature. From the perspective of
HTML & Javascript layers, everything there applies in Webview2 as well.

# Examples

## Win32 C++
```cpp
AppWindow::AppWindow() {
m_mainWindow = CreateWindowExW(
WS_EX_CONTROLPARENT,
GetWindowClass(),
L""
WS_POPUPWINDOW,
0,0, 800, 800,
nullptr, nullptr,
g_hInstance, nullptr);
}

void AppWindow::OnCreateWebview2ControllerCompleted(HRESULT hr, ICoreWebview2Controller* controller)
{

wil::com_ptr<ICoreWebView2> coreWebView2;
CHECK_FAILURE(m_controller->get_CoreWebView2(&coreWebView2));

wil::com_ptr<ICoreWebView2> coreWebView2_28;
CHECK_FAILURE(coreWebView2->QueryInterface(&coreWebView2_28));

wil::com_ptr<ICoreWebView2WindowControlsOverlay> windowControlsOverlay;
CHECK_FAILURE(coreWebView2_28->get_WindowControlsOverlay(&windowControlsOverlay));

CHECK_FAILURE(windowControlsOverlay->put_IsVisible(true));
COREWEBVIEW2_COLOR color {1, 0, 0, 225};
CHECK_FAILURE(windowControlsOverlay->put_BackgroundColor(color));
}
```
## .NET C#
```c#
// WebView2 control is defined in the xaml
// <wv2:WebView2 x:Name="webView" Source="https://www.microsoft.com/"/>
public MainWindow()
{
InitializeComponent();
m_AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;

CoreWebView2WindowControlsOverlay config = Webview2.CoreWebView2.WindowControlsOverlay;
config.IsVisible = true;
config.Color = Color.FromARGB(0, 0, 255);
}
```

# API Details
## Win32 C++
```cpp
/// Controller API used to configure the window controls overlay.
/// To provide your app users with the best experience, it is important to handle webview
/// initialization errors appropriately. Provide your users with a way to close the window
/// or restart the App.
[uuid(101e36ca-7f75-5105-b9be-fea2ba61a2fd), object, pointer_default(unique)]
interface ICoreWebView2_28 : IUnknown {
/// Gets the `WindowControlsOverlay` object.
[propget] HRESULT WindowControlsOverlay([out, retval] ICoreWebView2WindowControlsOverlay** value);
}

/// This is the ICoreWebView2WindowControlsOverlay
[uuid(c9f7378b-8dbb-5445-bacb-08a3fdf032f0), object, pointer_default(unique)]
interface ICoreWebView2WindowControlsOverlay : IUnknown {
/// Gets the `Height` property.
[propget] HRESULT Height([out, retval] UINT32* value);


/// The `Height` property in raw screen pixels, allows you to set the height of the overlay and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bradp0721 Does it make sense to use raw screen pixels here vs view pixels?

Also, we should ensure that different DPI awareness doesn't create bugs with real raw pixels vs virtual DPI scaled raw pixels.

/// title bar area. Defaults to 48px. There is no minimum height restriction for this API,
/// so it is up to the developer to make sure that the height of your window controls overlay
/// is enough that users can see and interact with it. We recommend using GetSystemMetrics(SM_CYCAPTION)
// as your minimum height.
///
[propput] HRESULT Height([in] UINT32 value);


/// Gets the `IsVisible` property.
[propget] HRESULT IsVisible([out, retval] BOOL* value);


/// The `IsVisible` property allows you to opt in to using
/// the WebView2 window controls overlay. Defaults to `FALSE`.
///
/// When this property is `TRUE`, WebView2 will draw its own minimize, maximize,
/// and close buttons on the top right corner of the Webview2.
///
/// When using this you should configure your app window to not display its default
/// window control buttons. You are responsible for creating a title bar for your app
/// by using the available space to the left of the controls overlay. In doing so,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this right or left conditional on the reading direction of the UI root?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document what happens for RTL locales - does the controls overlay render on the left instead of right?

In the text here say 'before' instead of 'left'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In RTL locales, the caption buttons still appear on the right side of the window, just like in LTR. The ordering of the buttons themselves is mirrored (Close | Maximize | Minimize), but their position remains on the right side of the window.

keeping that in mind 'left' actually fits correctly in the statement? please let me know if you still want it to be 'before' ?

/// you can utilize the [IsNonClientRegionSupportEnabled](https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings9?view=webview2-1.0.2739.15)
/// API to enable draggable regions for your custom title bar.
///
/// The Overlay buttons will cover the HTML content, and will prevent mouse interactions
/// with any elements directly below it, so you should avoid placing content there.
/// To that end, there are four [CSS environment variables](https://developer.mozilla.org/en-US/docs/Web/API/Window_Controls_Overlay_API#css_environment_variables)
/// titlebar-area-x, titlebar-area-y, titlebar-area-width, titlebar-area-height defined to help you
/// get the dimensions of the available titlebar area to the left of the overlay.
/// Similarly the navigator object will contain a [WindowControlsOverlay property](https://developer.mozilla.org/en-US/docs/Web/API/WindowControlsOverlay)
/// which can be used to get the titlebar area as a rect, and listen for changes
/// to the size of that area.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update this text to suggest either using CSS directly or using the event described in here: https://developer.mozilla.org/en-US/docs/Web/API/WindowControlsOverlay#examples

Please also consider adding appropriate HTML/CSS to our sample code.

///
[propput] HRESULT IsVisible([in] BOOL value);

/// Gets the `BackgroundColor` property.
[propget] HRESULT BackgroundColor([out, retval] COREWEBVIEW2_COLOR* value);

/// The `BackgroundColor` property allows you to set a background color
/// for the overlay. Based on the background color you choose, Webview2
/// will automatically calculate a foreground and hover color.
/// Defaults to #f3f3f3. This API supports transparency.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document that it does not support changing the default color or default height for OS theming (dark/light mode and high contrast) and height.

[propput] HRESULT BackgroundColor([in] COREWEBVIEW2_COLOR value);
}
```

## .NET and WinRT
```c#
namespace Microsoft.Web.WebView2.Core
{
runtimeclass CoreWebView2
{
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2_28")]
{
CoreWebView2WindowControlsOverlay WindowControlsOverlay { get; };
}
}

runtimeclass CoreWebView2WindowControlsOverlay
{
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2WindowControlsOverlay")]
{
Boolean IsVisible { get; set; };
UInt32 Height { get; set; };
Windows.UI.Color BackgroundColor { get; set; }
}
}
}
```