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

Accessibility: Refactor Providers #2414

Merged
merged 5 commits into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
4 changes: 2 additions & 2 deletions src/cascadia/TerminalControl/TermControlAutomationPeer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
{
TermControlAutomationPeer::TermControlAutomationPeer(winrt::Microsoft::Terminal::TerminalControl::implementation::TermControl const& owner) :
TermControlAutomationPeerT<TermControlAutomationPeer>(owner), // pass owner to FrameworkElementAutomationPeer
_uiaProvider{ owner.GetRenderData(), nullptr, std::bind(&TermControlAutomationPeer::GetBoundingRectWrapped, this) } {};
_uiaProvider{ owner.GetRenderData(), std::bind(&TermControlAutomationPeer::GetBoundingRectWrapped, this) } {};

winrt::hstring TermControlAutomationPeer::GetClassNameCore() const
{
Expand Down Expand Up @@ -135,7 +135,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
winrt::com_array<XamlAutomation::ITextRangeProvider> TermControlAutomationPeer::WrapArrayOfTextRangeProviders(SAFEARRAY* textRanges)
{
// transfer ownership of UiaTextRanges to this new vector
auto providers = SafeArrayToOwningVector<::Microsoft::Console::Types::UiaTextRange>(textRanges);
auto providers = SafeArrayToOwningVector<::Microsoft::Terminal::UiaTextRange>(textRanges);
int count = providers.size();

std::vector<XamlAutomation::ITextRangeProvider> vec;
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalControl/TermControlAutomationPeer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Author(s):
#include "TermControlAutomationPeer.g.h"
#include <winrt/Microsoft.Terminal.TerminalControl.h>
#include "../../renderer/inc/IRenderData.hpp"
#include "../types/ScreenInfoUiaProvider.h"
#include "../types/WindowUiaProviderBase.hpp"
#include "TermControlUiaProvider.hpp"

namespace winrt::Microsoft::Terminal::TerminalControl::implementation
{
Expand All @@ -56,7 +56,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
RECT GetBoundingRectWrapped();

private:
::Microsoft::Console::Types::ScreenInfoUiaProvider _uiaProvider;
::Microsoft::Terminal::TermControlUiaProvider _uiaProvider;

winrt::com_array<Windows::UI::Xaml::Automation::Provider::ITextRangeProvider> WrapArrayOfTextRangeProviders(SAFEARRAY* textRanges);
};
Expand Down
119 changes: 119 additions & 0 deletions src/cascadia/TerminalControl/TermControlUiaProvider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#include "pch.h"
#include "TermControlUiaProvider.hpp"

using namespace Microsoft::Terminal;
using namespace Microsoft::Console::Types;
using namespace Microsoft::Console::Render;

TermControlUiaProvider::TermControlUiaProvider(_In_ IRenderData* pData,
_In_ std::function<RECT(void)> GetBoundingRect) :
_getBoundingRect(GetBoundingRect),
ScreenInfoUiaProviderBase(THROW_HR_IF_NULL(E_INVALIDARG, pData))
{
// TODO GitHub #1914: Re-attach Tracing to UIA Tree
//Tracing::s_TraceUia(nullptr, ApiCall::Constructor, nullptr);
}

IFACEMETHODIMP TermControlUiaProvider::Navigate(_In_ NavigateDirection direction,
_COM_Outptr_result_maybenull_ IRawElementProviderFragment** ppProvider)
{
// TODO GitHub #1914: Re-attach Tracing to UIA Tree
/*ApiMsgNavigate apiMsg;
apiMsg.Direction = direction;
Tracing::s_TraceUia(this, ApiCall::Navigate, &apiMsg);*/
*ppProvider = nullptr;

if (direction == NavigateDirection_Parent)
{
try
{
// TODO GitHub #2102: UIA Tree Navigation
//_pUiaParent->QueryInterface(IID_PPV_ARGS(ppProvider));
}
catch (...)
{
*ppProvider = nullptr;
return wil::ResultFromCaughtException();
}
RETURN_IF_NULL_ALLOC(*ppProvider);
}

// For the other directions the default of nullptr is correct
return S_OK;
}

IFACEMETHODIMP TermControlUiaProvider::get_BoundingRectangle(_Out_ UiaRect* pRect)
{
// TODO GitHub #1914: Re-attach Tracing to UIA Tree
//Tracing::s_TraceUia(this, ApiCall::GetBoundingRectangle, nullptr);

RECT rc = _getBoundingRect();

pRect->left = rc.left;
pRect->top = rc.top;
pRect->width = rc.right - rc.left;
pRect->height = rc.bottom - rc.top;

return S_OK;
}

IFACEMETHODIMP TermControlUiaProvider::get_FragmentRoot(_COM_Outptr_result_maybenull_ IRawElementProviderFragmentRoot** ppProvider)
{
// TODO GitHub #1914: Re-attach Tracing to UIA Tree
//Tracing::s_TraceUia(this, ApiCall::GetFragmentRoot, nullptr);
try
{
// TODO GitHub #2102: UIA Tree Navigation - the special fragments that knows about all of its descendants is called a fragment root
//_pUiaParent->QueryInterface(IID_PPV_ARGS(ppProvider));
*ppProvider = nullptr;
}
catch (...)
{
*ppProvider = nullptr;
return wil::ResultFromCaughtException();
}
RETURN_IF_NULL_ALLOC(*ppProvider);
return S_OK;
}

std::deque<UiaTextRangeBase*> TermControlUiaProvider::GetSelectionRanges(_In_ IRawElementProviderSimple* pProvider)
{
std::deque<UiaTextRangeBase*> result;

auto ranges = UiaTextRange::GetSelectionRanges(_pData, pProvider);
while (!ranges.empty())
{
result.emplace_back(ranges.back());
ranges.pop_back();
}

return result;
}

UiaTextRangeBase* TermControlUiaProvider::CreateTextRange(_In_ IRawElementProviderSimple* const pProvider)
{
return UiaTextRange::Create(_pData, pProvider);
}

UiaTextRangeBase* TermControlUiaProvider::CreateTextRange(_In_ IRawElementProviderSimple* const pProvider,
const Cursor& cursor)
{
return UiaTextRange::Create(_pData, pProvider, cursor);
}

UiaTextRangeBase* TermControlUiaProvider::CreateTextRange(_In_ IRawElementProviderSimple* const pProvider,
const Endpoint start,
const Endpoint end,
const bool degenerate)
{
return UiaTextRange::Create(_pData, pProvider, start, end, degenerate);
}

UiaTextRangeBase* TermControlUiaProvider::CreateTextRange(_In_ IRawElementProviderSimple* const pProvider,
const UiaPoint point)
{
return UiaTextRange::Create(_pData, pProvider, point);
}
73 changes: 73 additions & 0 deletions src/cascadia/TerminalControl/TermControlUiaProvider.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.

Module Name:
- TermControlUiaProvider.hpp

Abstract:
- This module provides UI Automation access to the screen buffer to
support both automation tests and accessibility (screen reading)
applications.
- ConHost and Windows Terminal must use IRenderData to have access to the proper information
- Based on examples, sample code, and guidance from
https://msdn.microsoft.com/en-us/library/windows/desktop/ee671596(v=vs.85).aspx

Author(s):
- Carlos Zamora (CaZamor) 2019
--*/

#pragma once

#include "..\types\ScreenInfoUiaProviderBase.h"
#include "..\types\UiaTextRangeBase.hpp"
#include "UiaTextRange.hpp"

namespace Microsoft::Console::Render
{
class IRenderData;
}

namespace Microsoft::Console::Types
{
class WindowUiaProviderBase;
}

namespace Microsoft::Terminal
{
class TermControlUiaProvider : public Microsoft::Console::Types::ScreenInfoUiaProviderBase
{
public:
TermControlUiaProvider(_In_ Microsoft::Console::Render::IRenderData* pData,
_In_ std::function<RECT()> GetBoundingRect);

// IRawElementProviderFragment methods
IFACEMETHODIMP Navigate(_In_ NavigateDirection direction,
_COM_Outptr_result_maybenull_ IRawElementProviderFragment** ppProvider) override;
IFACEMETHODIMP get_BoundingRectangle(_Out_ UiaRect* pRect) override;
IFACEMETHODIMP get_FragmentRoot(_COM_Outptr_result_maybenull_ IRawElementProviderFragmentRoot** ppProvider) override;

protected:
std::deque<Microsoft::Console::Types::UiaTextRangeBase*> GetSelectionRanges(_In_ IRawElementProviderSimple* pProvider) override;

// degenerate range
Microsoft::Console::Types::UiaTextRangeBase* CreateTextRange(_In_ IRawElementProviderSimple* const pProvider) override;

// degenerate range at cursor position
Microsoft::Console::Types::UiaTextRangeBase* CreateTextRange(_In_ IRawElementProviderSimple* const pProvider,
const Cursor& cursor) override;

// specific endpoint range
Microsoft::Console::Types::UiaTextRangeBase* CreateTextRange(_In_ IRawElementProviderSimple* const pProvider,
const Endpoint start,
const Endpoint end,
const bool degenerate) override;

// range from a UiaPoint
Microsoft::Console::Types::UiaTextRangeBase* CreateTextRange(_In_ IRawElementProviderSimple* const pProvider,
const UiaPoint point) override;

private:
std::function<RECT(void)> _getBoundingRect;
};
}
4 changes: 4 additions & 0 deletions src/cascadia/TerminalControl/TerminalControl.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,30 @@
</PropertyGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="TermControlUiaProvider.hpp" />
<ClInclude Include="TermControl.h">
<DependentUpon>TermControl.idl</DependentUpon>
</ClInclude>
<ClInclude Include="TermControlAutomationPeer.h">
<DependentUpon>TermControlAutomationPeer.idl</DependentUpon>
</ClInclude>
<ClInclude Include="UiaTextRange.hpp" />
<ClInclude Include="XamlUiaTextRange.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="init.cpp" />
<ClCompile Include="TermControlUiaProvider.cpp" />
<ClCompile Include="TermControl.cpp">
<DependentUpon>TermControl.idl</DependentUpon>
</ClCompile>
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
<ClCompile Include="TermControlAutomationPeer.cpp">
<DependentUpon>TermControlAutomationPeer.idl</DependentUpon>
</ClCompile>
<ClCompile Include="UiaTextRange.cpp" />
<ClCompile Include="XamlUiaTextRange.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down
6 changes: 5 additions & 1 deletion src/cascadia/TerminalControl/TerminalControl.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
<ClCompile Include="TermControlAutomationPeer.cpp" />
<ClCompile Include="XamlUiaTextRange.cpp" />
<ClCompile Include="TermControlUiaProvider.cpp" />
<ClCompile Include="UiaTextRange.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="TermControl.h" />
<ClInclude Include="TermControlAP.h" />
<ClInclude Include="TermControlAutomationPeer.h" />
<ClInclude Include="XamlUiaTextRange.h" />
<ClInclude Include="TermControlUiaProvider.hpp" />
<ClInclude Include="UiaTextRange.hpp" />
</ItemGroup>
<ItemGroup>
<Midl Include="TermControl.idl" />
Expand Down
Loading