Skip to content

Commit 46283be

Browse files
authored
Merge pull request #992 from MicrosoftEdge/automationprovider
API Review: AutomationProvider.md
2 parents 4e42f18 + 1d58a21 commit 46283be

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

specs/AutomationProvider.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Background
2+
WebView has two hosting modes, windowed (which uses the ICoreWebView2Controller) and visual (which uses the ICoreWebView2CompositionController). Accessibility for the windowed WebView is able to walk the HWND tree to know where to place the WebView in the accessibility tree. For visual hosting, accessibility is not able to know where within the accessibility tree to place the WebView. This results in a WebView being a sibling to the rest of the app content.
3+
4+
In this document we describe the updated API so visual-hosted WebViews are correctly managed by accessibility. We'd appreciate your feedback.
5+
6+
7+
# Description
8+
To give apps using the ICoreWebView2CompositionController more control over how the WebView is positioned in the accessibility tree, we are adding new APIs to let the app retrieve the automation provider for the WebView. This let's the app return the automation provider as part of its accessibility tree.
9+
10+
While traversing child elements, when the app reaches the WebView, it can use the `UIAProvider` property to get the automation provider for the WebView and return it.
11+
12+
When accessibility is traversing parent elements, the app needs to implement IRawElementProviderHwndOverride. The HWND parameter from GetOverrideProviderForHwnd can be passed to `GetProviderForHwnd` to get the automation provider for the corresponding WebView.
13+
14+
# Examples
15+
```cpp
16+
HRESULT WebView2AutomationPeer::GetRawElementProviderSimple(IRawElementProviderSimple** value)
17+
{
18+
wil::com_ptr<IUnknown> provider;
19+
CHECK_FAILURE(m_controller->get_AutomationProvider(&provider));
20+
return provider->QueryInterface(IID_PPV_ARGS(value));
21+
}
22+
23+
// Find the WebView2AutomationPeer for the HWND from
24+
// IRawElementProviderHwndOverride::GetOverrideProviderForHwnd
25+
bool WebView2AutomationPeer::IsAutomationPeerForWindow(HWND window)
26+
{
27+
wil::com_ptr<IUnknown> provider;
28+
CHECK_FAILURE(m_controller->get_AutomationProvider(&provider));
29+
30+
wil::com_ptr<IUnknown> providerForWindow;
31+
CHECK_FAILURE(m_environment->GetAutomationProviderForWindow(window, &providerForWindow));
32+
33+
return (provider == providerForWindow);
34+
}
35+
```
36+
37+
# API Notes
38+
See [API Details](#api_details) section below for API reference.
39+
40+
# API Details
41+
## Win32 C++
42+
``` c#
43+
interface ICoreWebView2Environment4 : ICoreWebView2Environment3 {
44+
/// Returns the Automation Provider for the WebView that matches the provided window.
45+
/// Host apps are expected to implement IRawElementProviderHwndOverride. When GetOverrideProviderForHwnd
46+
/// is called, the app can pass the HWND to GetAutomationProviderForWindow to find the matching WebView
47+
/// automation provider.
48+
HRESULT GetAutomationProviderForWindow([in] HWND window,
49+
[out, retval] IUnknown** provider);
50+
}
51+
52+
interface ICoreWebView2CompositionController2 : ICoreWebView2CompositionController {
53+
/// Returns the Automation Provider for the WebView. This object implements IRawElementProviderSimple.
54+
[propget] HRESULT AutomationProvider([out, retval] IUnknown** provider);
55+
}
56+
```
57+
## .Net and WinRT
58+
API is not natively supported in .Net and WinRT. The Win32 COM API is exposed using an interop interface.

0 commit comments

Comments
 (0)