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 "Window to Visual" in "Windowed vs. Visual hosting of WebView2" #3271

Merged
merged 40 commits into from
Oct 3, 2024
Merged
Changes from 3 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
4c7f8b1
Adding documentation for Window to Visual hosting mode
johna-ms Sep 16, 2024
9b3a615
Applying suggested edits. Shortening content in table and consolidati…
johna-ms Sep 18, 2024
a1a254e
Merge branch 'main' into user/johna/window-to-visual-hosting
mikehoffms Sep 18, 2024
c215952
Writer/Editor pass, incorp cmts
mikehoffms Sep 19, 2024
75cbfa2
linkfix etc
mikehoffms Sep 19, 2024
bb69505
move todo cmts
mikehoffms Sep 19, 2024
88a42e1
adjust api section levels
mikehoffms Sep 19, 2024
f9add9b
include "mode" in term introduction
mikehoffms Sep 19, 2024
9475616
remove Overview link from outline cmt
mikehoffms Sep 19, 2024
e3ae82b
link to equiv section in Overview APIs
mikehoffms Sep 19, 2024
998ef46
Merge branch 'main' into user/johna/window-to-visual-hosting
mikehoffms Sep 20, 2024
b7d1c28
Remove api tabset in windowed-vs-visual-hosting.md that is duplicated…
johna-ms Sep 24, 2024
f09366c
edit pass after API tabsets removed
mikehoffms Sep 24, 2024
64a7252
missing: focus is *on* the WebView
mikehoffms Sep 24, 2024
98ff9a8
## linkfix
mikehoffms Sep 24, 2024
3ce0797
promoted to h2s, linked from table
mikehoffms Sep 24, 2024
6a66995
move long h2 links from table to topmost list
mikehoffms Sep 24, 2024
1d0c69a
.
mikehoffms Sep 24, 2024
4b4c791
DPI: consider Window to Visual hosting
mikehoffms Sep 24, 2024
ae9919e
apply champnic cmts
mikehoffms Sep 24, 2024
e1ecec7
unlink initial list of modes
mikehoffms Sep 25, 2024
2ca4895
clarify cases recomm
mikehoffms Sep 25, 2024
7654254
consistent ext links
mikehoffms Sep 25, 2024
336e223
trim needless "docs" in ext links list
mikehoffms Sep 25, 2024
b1034cb
simplify/consistent ext link docset
mikehoffms Sep 25, 2024
97b62db
remove keyboard accel list item
mikehoffms Sep 25, 2024
c7ee6e8
"External:" more transparent than "doc sets"
mikehoffms Sep 25, 2024
b748a09
Updating references to pen input to be Windows Shell Handwriting
johna-ms Sep 26, 2024
4c628a9
Merge branch 'user/johna/window-to-visual-hosting' of https://github.…
johna-ms Sep 26, 2024
71c5a0f
a Visual
mikehoffms Sep 26, 2024
cffdc7d
link to handwriting
mikehoffms Sep 27, 2024
dd56310
Addressing todos about visual hosting. Leaving one remaining because …
johna-ms Sep 30, 2024
3b535f3
Addressing final todo regarding constraints
johna-ms Oct 1, 2024
107537c
Writer pass on resolved todos
mikehoffms Oct 1, 2024
157494b
linkfix
mikehoffms Oct 1, 2024
e16319d
incorp final rvw/approval cmts
mikehoffms Oct 2, 2024
443020a
enjoys benefits
mikehoffms Oct 2, 2024
1ae2507
isn't
mikehoffms Oct 2, 2024
b60e579
break up "by but by" sentence
mikehoffms Oct 2, 2024
918a03e
apply 3 final nic cmts
mikehoffms Oct 2, 2024
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
35 changes: 27 additions & 8 deletions microsoft-edge/webview2/concepts/windowed-vs-visual-hosting.md
mikehoffms marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ ms.date: 10/24/2022
---
# Windowed vs. visual hosting of WebView2

There are two options for hosting the Microsoft Edge WebView2 control in your app: windowed hosting and visual hosting.
There are three options for hosting the Microsoft Edge WebView2 control in your app:
* Windowed Hosting
* Window to Visual Hosting
* Visual Hosting

If you use windowed hosting, which is a good starting point for most apps, you don't need to read this article. If you want to provide a more custom user experience (UX), and want to use visual hosting, read this article.
If you use windowed hosting, which is a good starting point for most apps, you don't need to read this article. If you want to provide a more custom user experience (UX) and want to use visual hosting, or if you are using windowed mode in specific scenarios and are experiencing persistent issues with DPI and scaling, read this article.
mikehoffms marked this conversation as resolved.
Show resolved Hide resolved

| Approach | Description | Optimized for |
|---|---|---|
| Windowed hosting | The WebView2 control takes input from the operating system (OS). The OS sends the input to the WebView2. | Displaying web content quickly and easily, without having to include features for inputs, outputs, and accessibility. |
| Window to Visual hosting | A combination of windowed and visual modes. Similar to windowed mode except that it outputs content to a visual that is hosted in a window rather than hosting content in a window directly. | A developer experience nearly identical to windowed mode but with improved DPI/scaling handling and the caveat that pen input and handwriting is unsupported. |
| Visual hosting | Your host app takes spatial input (such as mouse or touch input) from the user. Your app sends this input to the WebView2 control. | More granular control over layout. For example, you can control the positioning of the WebView2 control in the page. The app needs to do specific handling of window management and rendering APIs. |
mikehoffms marked this conversation as resolved.
Show resolved Hide resolved

These approaches have different requirements, constraints, and benefits. Windowed hosting is simpler to implement than visual hosting. Visual hosting requires all the API calls that Windowed hosting requires, and visual hosting has additional requirements for it to render properly. The API calls are listed in [Windowed hosting](#windowed-hosting) and [Visual hosting](#visual-hosting), below.
Expand All @@ -32,8 +36,13 @@ Both approaches for hosting the WebView2 control in your app are similar in func

"Windowed" means that in your app, an HWND inherits many default properties from the operating system.

There are instances where you might want to focus on displaying web content as quickly and easily as possible in your app. Windowed hosting allows for a solution that quickly displays web content without having to include features for inputs, outputs, and accessibility.
There are instances where you might want to focus on displaying web content as quickly and easily as possible in your app. Windowed hosting allows for a solution that quickly displays web content without having to include features for inputs, outputs, and accessibility. However this hosting mode can run into DPI issues in specific scenarios such as sharing a user data folder across different applications.

#### Window to Visual hosting: For a similar experience to Windowed hosting with some added benefits and a tradeoff

Window-to-Visual hosting means the WebView2 content is displayed using a visual that is hosted in an HWND. As opposed to hosting the content in a window directly or in a visual directly.

By hosting content in an HWND, this hosting mode enjoys the same ease of adoption benefits as Windowed mode. But by displaying that content using a visual, this hosting mode avoids some specific DPI issues that can result when using Windowed mode. To enable it, users must set this environment variable: `COREWEBVIEW2_FORCED_HOSTING_MODE` to the value: `COREWEBVIEW2_HOSTING_MODE_WINDOW_TO_VISUAL`. It does not require use of the visual hosting APIs. Enabling this hosting mode removes support for pen input and handwriting.

#### Visual hosting: For more granular control over layout

Expand All @@ -51,7 +60,7 @@ Key compatibility limitations include the operating system and rendering in fram
<!-- ------------------------------ -->
#### Operating systems

Windows 7 and Windows 8 can only do windowed hosting, not visual hosting.
All hosting modes are supported wherever WebView2 is supported ie. Windows 10 and up and certain Windows Server versions. Windows 7, 8 and 8.1 are no longer supported. For those still on those platforms Windows 7 and Windows 8 can only do windowed hosting, not visual hosting.

See [Windows 7 and 8](../index.md#windows-7-and-8) in _Introduction to Microsoft Edge WebView2_.

Expand Down Expand Up @@ -87,9 +96,9 @@ The `CoreWebView2Controller` properties and methods:


<!-- ====================================================================== -->
## Windowed hosting
## Windowed and Window to Visual hosting

Windowed hosting can be described as an HWND that stores information. You can have multiple HWNDs in your app that will each be used as a WebView component to access web content. Some of the Output/Input commands are handled for you by the framework you choose; however, you will still need to handle window management.
In the Windowed hosting mode, WebView2 content is hosted directly in a window. You can have multiple HWNDs in your app that will each be used as a WebView component to access web content. The benefit of this is that some of the Input/Output commands are handled for you by the OS or by the framework. However, you will still need to handle some aspects of window management. In the Window to Visual mode, content is hosted slightly differently, but has the same benefits and window management requirements as Windowed.

Benefits for Windowed hosting include:

Expand All @@ -99,13 +108,23 @@ Benefits for Windowed hosting include:

* You don't have to manage the various composition-based rendering (for example, Inputs, Outputs, and Accessibility controls) if you don't want to.

Benefits for Window to Visual hosting include:

* Different apps that share a WebView2 user data folder can have different DPI awarenesses.

* Different apps that share a WebView2 user data folder can have different integrity levels.

* Different apps that share a WebView2 user data folder will no longer be able to cause each other to hang.
mikehoffms marked this conversation as resolved.
Show resolved Hide resolved

* Changing monitor scale when hosting a WebView2 in a VSTO add-in no longer sporadically hang the application.

For general information regarding Window management and `HWND` functionality, see [About Windows](/windows/win32/winmsg/about-windows).


<!-- ------------------------------ -->
#### Window management

The following aspects of window management are handled in a windowed hosting environment.
The following aspects of window management need to be handled in a windowed hosting environment.


<!-- ---------- -->
Expand Down Expand Up @@ -283,7 +302,7 @@ When WebView2 has focus, it receives input directly from the user. An app may wa
<!-- ---------- -->
###### Default background color

WebView2 can specify a default background color. This can be any opaque color or transparent color. This color will be used if the webpage doesn't set its own background color.
WebView2 can specify a default background color. This can be any opaque color or transparent color. This color will be used if the webpage doesn't set a background color, or sets a transparent background color.

##### [.NET/C#](#tab/dotnetcsharp)

Expand Down