Skip to content

Commit

Permalink
Accessibility: Add BoundingRects to UiaTextRanges (microsoft#2423)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora authored and DHowett committed Aug 21, 2019
1 parent e92efa5 commit be52880
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 9 deletions.
10 changes: 10 additions & 0 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion 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.GetUiaData(), std::bind(&TermControlAutomationPeer::GetBoundingRectWrapped, this) } {};
_uiaProvider{ owner, std::bind(&TermControlAutomationPeer::GetBoundingRectWrapped, this) } {};

winrt::hstring TermControlAutomationPeer::GetClassNameCore() const
{
Expand Down
18 changes: 15 additions & 3 deletions src/cascadia/TerminalControl/TermControlUiaProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
11 changes: 10 additions & 1 deletion src/cascadia/TerminalControl/TermControlUiaProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand All @@ -59,5 +67,6 @@ namespace Microsoft::Terminal

private:
std::function<RECT(void)> _getBoundingRect;
winrt::Microsoft::Terminal::TerminalControl::implementation::TermControl const& _termControl;
};
}
31 changes: 29 additions & 2 deletions src/cascadia/TerminalControl/UiaTextRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/UiaTextRange.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/types/UiaTextRangeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion src/types/UiaTextRangeBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit be52880

Please sign in to comment.