Accessibility: Add BoundingRects to UiaTextRanges (#2423)

This commit is contained in:
Carlos Zamora 2019-08-20 17:50:34 -07:00 committed by Dustin L. Howett (MSFT)
parent e92efa5bc0
commit be52880620
9 changed files with 70 additions and 9 deletions

View file

@ -352,6 +352,16 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
return _terminal.get();
}
const FontInfo TermControl::GetActualFont() const
{
return _actualFont;
}
const Windows::UI::Xaml::Thickness TermControl::GetPadding() const
{
return _swapChainPanel.Margin();
}
void TermControl::SwapChainChanged()
{
if (!_initializedTerminal)

View file

@ -73,6 +73,8 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
Windows::UI::Xaml::Automation::Peers::AutomationPeer OnCreateAutomationPeer();
::Microsoft::Console::Types::IUiaData* GetUiaData() const;
const FontInfo GetActualFont() const;
const Windows::UI::Xaml::Thickness GetPadding() const;
static Windows::Foundation::Point GetProposedDimensions(Microsoft::Terminal::Settings::IControlSettings const& settings, const uint32_t dpi);

View file

@ -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.GetUiaData(), std::bind(&TermControlAutomationPeer::GetBoundingRectWrapped, this) } {};
_uiaProvider{ owner, std::bind(&TermControlAutomationPeer::GetBoundingRectWrapped, this) } {};
winrt::hstring TermControlAutomationPeer::GetClassNameCore() const
{

View file

@ -3,14 +3,16 @@
#include "pch.h"
#include "TermControlUiaProvider.hpp"
#include "TermControl.h"
using namespace Microsoft::Terminal;
using namespace Microsoft::Console::Types;
TermControlUiaProvider::TermControlUiaProvider(_In_ IUiaData* pData,
TermControlUiaProvider::TermControlUiaProvider(_In_ winrt::Microsoft::Terminal::TerminalControl::implementation::TermControl const& termControl,
_In_ std::function<RECT(void)> GetBoundingRect) :
_getBoundingRect(GetBoundingRect),
ScreenInfoUiaProviderBase(THROW_HR_IF_NULL(E_INVALIDARG, pData))
_termControl(termControl),
ScreenInfoUiaProviderBase(THROW_HR_IF_NULL(E_INVALIDARG, termControl.GetUiaData()))
{
// TODO GitHub #1914: Re-attach Tracing to UIA Tree
//Tracing::s_TraceUia(nullptr, ApiCall::Constructor, nullptr);
@ -78,7 +80,17 @@ IFACEMETHODIMP TermControlUiaProvider::get_FragmentRoot(_COM_Outptr_result_maybe
return S_OK;
}
std::deque<UiaTextRangeBase*> TermControlUiaProvider::GetSelectionRanges(_In_ IRawElementProviderSimple* pProvider)
const COORD TermControlUiaProvider::GetFontSize() const
{
return _termControl.GetActualFont().GetSize();
}
const winrt::Windows::UI::Xaml::Thickness TermControlUiaProvider::GetPadding() const
{
return _termControl.GetPadding();
}
std::deque<UiaTextRangeBase*> TermControlUiaProvider::GetSelectionRanges(_In_ IRawElementProviderSimple* const pProvider)
{
std::deque<UiaTextRangeBase*> result;

View file

@ -23,12 +23,17 @@ Author(s):
#include "..\types\UiaTextRangeBase.hpp"
#include "UiaTextRange.hpp"
namespace winrt::Microsoft::Terminal::TerminalControl::implementation
{
struct TermControl;
}
namespace Microsoft::Terminal
{
class TermControlUiaProvider : public Microsoft::Console::Types::ScreenInfoUiaProviderBase
{
public:
TermControlUiaProvider(_In_ Microsoft::Console::Types::IUiaData* pData,
TermControlUiaProvider(_In_ winrt::Microsoft::Terminal::TerminalControl::implementation::TermControl const& termControl,
_In_ std::function<RECT()> GetBoundingRect);
// IRawElementProviderFragment methods
@ -37,6 +42,9 @@ namespace Microsoft::Terminal
IFACEMETHODIMP get_BoundingRectangle(_Out_ UiaRect* pRect) override;
IFACEMETHODIMP get_FragmentRoot(_COM_Outptr_result_maybenull_ IRawElementProviderFragmentRoot** ppProvider) override;
const COORD GetFontSize() const;
const winrt::Windows::UI::Xaml::Thickness GetPadding() const;
protected:
std::deque<Microsoft::Console::Types::UiaTextRangeBase*> GetSelectionRanges(_In_ IRawElementProviderSimple* pProvider) override;
@ -59,5 +67,6 @@ namespace Microsoft::Terminal
private:
std::function<RECT(void)> _getBoundingRect;
winrt::Microsoft::Terminal::TerminalControl::implementation::TermControl const& _termControl;
};
}

View file

@ -186,12 +186,39 @@ void UiaTextRange::_ChangeViewport(const SMALL_RECT /*NewWindow*/)
// TODO GitHub #2361: Update viewport when calling UiaTextRangeBase::ScrollIntoView()
}
void UiaTextRange::_TranslatePointToScreen(LPPOINT /*clientPoint*/) const
// Method Description:
// - Transform coordinates relative to the client to relative to the screen
// Arguments:
// - clientPoint: coordinates relative to the client where
// (0,0) is the top-left of the app window
// Return Value:
// - <none>
void UiaTextRange::_TranslatePointToScreen(LPPOINT clientPoint) const
{
// TODO GitHub #2103: NON-HWND IMPLEMENTATION OF CLIENTTOSCREEN()
auto provider = static_cast<TermControlUiaProvider*>(_pProvider.get());
// update based on TermControl location (important for Panes)
UiaRect boundingRect;
THROW_IF_FAILED(provider->get_BoundingRectangle(&boundingRect));
clientPoint->x += gsl::narrow<LONG>(boundingRect.left);
clientPoint->y += gsl::narrow<LONG>(boundingRect.top);
// update based on TermControl padding
auto padding = provider->GetPadding();
clientPoint->x += gsl::narrow<LONG>(padding.Left);
clientPoint->y += gsl::narrow<LONG>(padding.Top);
}
void UiaTextRange::_TranslatePointFromScreen(LPPOINT /*screenPoint*/) const
{
// TODO GitHub #2103: NON-HWND IMPLEMENTATION OF SCREENTOCLIENT()
}
const COORD UiaTextRange::_getScreenFontSize() const
{
// Do NOT get the font info from IRenderData. It is a dummy font info.
// Instead, the font info is saved in the TermControl. So we have to
// ask our parent to get it for us.
auto provider = static_cast<TermControlUiaProvider*>(_pProvider.get());
return provider->GetFontSize();
}

View file

@ -57,6 +57,7 @@ namespace Microsoft::Terminal
void _ChangeViewport(const SMALL_RECT NewWindow) override;
void _TranslatePointToScreen(LPPOINT clientPoint) const override;
void _TranslatePointFromScreen(LPPOINT screenPoint) const override;
const COORD _getScreenFontSize() const override;
private:
// degenerate range

View file

@ -1020,7 +1020,7 @@ const COORD UiaTextRangeBase::_getScreenBufferCoords(IUiaData* pData)
return pData->GetTextBuffer().GetSize().Dimensions();
}
COORD UiaTextRangeBase::_getScreenFontSize() const
const COORD UiaTextRangeBase::_getScreenFontSize() const
{
COORD coordRet = _pData->GetFontInfo().GetSize();

View file

@ -260,7 +260,7 @@ namespace Microsoft::Console::Types
RECT _getTerminalRect() const;
static const COORD _getScreenBufferCoords(IUiaData* pData);
COORD _getScreenFontSize() const;
virtual const COORD _getScreenFontSize() const;
static const unsigned int _getTotalRows(IUiaData* pData);
static const unsigned int _getRowWidth(IUiaData* pData);