Skip to content

Commit

Permalink
Fix Voice Access 'Show Bubbles' annotation of WebView2 Content (#8551)
Browse files Browse the repository at this point in the history
* wv2 changes

* Make IRawElementProviderFragmentRoot::GetFocus return S_OK instead of E_NOTIMPL

* Add null check to _Outptr_opt_ arg of GetRawElementProviderSimple

---------
Co-authored-by: Ranjesh Jaganathan <[email protected]>
  • Loading branch information
DmitriyKomin authored and Keith Mahoney committed Jun 22, 2023
1 parent e30572d commit 2422301
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
21 changes: 17 additions & 4 deletions dev/WebView2/WebView2AutomationPeer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,27 @@ winrt::Rect WebView2AutomationPeer::GetBoundingRectangleCore()
return boundingRect;
}

#if WINUI3
HRESULT WebView2AutomationPeer::GetRawElementProviderSimple(_Outptr_opt_ IRawElementProviderSimple** value)
{
if (value == nullptr) return S_OK;

*value = nullptr;

InitProvider();
m_provider.copy_to(value);

auto wrapperSimple = m_providerWrapper.try_as<IRawElementProviderSimple>();
if (wrapperSimple)
{
wrapperSimple.copy_to(value);
}

return S_OK;
}

HRESULT WebView2AutomationPeer::IsCorrectPeerForHwnd(HWND hwnd, _Out_ bool* value)
{
*value = false;

if (!InitProvider())
{
return S_OK;
Expand All @@ -63,9 +73,9 @@ HRESULT WebView2AutomationPeer::IsCorrectPeerForHwnd(HWND hwnd, _Out_ bool* valu
{
*value = true;
}

return S_OK;
}
#endif

struct ProviderWrapper : winrt::implements<ProviderWrapper, winrt::IInspectable, ::IRawElementProviderSimple, ::IRawElementProviderSimple2, ::IRawElementProviderFragment, ::IRawElementProviderFragmentRoot>
{
Expand Down Expand Up @@ -212,7 +222,10 @@ struct ProviderWrapper : winrt::implements<ProviderWrapper, winrt::IInspectable,
HRESULT STDMETHODCALLTYPE GetFocus(
/* [retval][out] */ __RPC__deref_out_opt IRawElementProviderFragment** pRetVal) noexcept override
{
return E_NOTIMPL;
// We don't answer the question about a current focus. We return NULL here since if we return
// an error UIA will bail out the entire focus operation rather than continueing its search.
*pRetVal = nullptr;
return S_OK;
}

private:
Expand Down
20 changes: 13 additions & 7 deletions dev/WebView2/WebView2AutomationPeer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@
#include "WebView2.h"
#include "UIAutomationCore.h"

MIDL_INTERFACE("865F5B88-6506-4E64-A4C5-4B7723650731")
IAutomationPeerHwndInterop : public IUnknown
{
public:
virtual /* [propput] */ HRESULT STDMETHODCALLTYPE GetRawElementProviderSimple(
/* [retval][out] */ _Outptr_opt_ IRawElementProviderSimple * *value) = 0;

virtual /* [propget] */ HRESULT STDMETHODCALLTYPE IsCorrectPeerForHwnd(
HWND hwnd,
/* [retval][out] */ _Out_ bool* value) = 0;
};

class WebView2AutomationPeer :
public ReferenceTracker<WebView2AutomationPeer, winrt::implementation::WebView2AutomationPeerT
#if WINUI3
, IAutomationPeerHwndInterop
#endif
>
public ReferenceTracker<WebView2AutomationPeer, winrt::implementation::WebView2AutomationPeerT, IAutomationPeerHwndInterop>
{
public:
WebView2AutomationPeer(winrt::WebView2 const& owner);
Expand All @@ -27,10 +35,8 @@ class WebView2AutomationPeer :
winrt::IInspectable GetElementFromPointCore(winrt::Point pointInWindowCoordinates);

// IAutomationPeerHwndInterop
#if WINUI3
HRESULT STDMETHODCALLTYPE GetRawElementProviderSimple(_Outptr_opt_ IRawElementProviderSimple** value);
HRESULT STDMETHODCALLTYPE IsCorrectPeerForHwnd(HWND hwnd, _Out_ bool* value);
#endif

private:
com_ptr<WebView2> GetImpl();
Expand Down

0 comments on commit 2422301

Please sign in to comment.