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

UIA: Fix GetVisibleRanges() and add Tracing #4495

Merged
11 commits merged into from
Feb 20, 2020
35 changes: 18 additions & 17 deletions src/types/UiaTextRangeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ try
*ppRetVal = nullptr;

#pragma warning(suppress : 26447) // QueryInterface's exception should be caught by the try-CATCH_RETURN block to allow this to be noexcept
auto hr = _pProvider->QueryInterface(IID_PPV_ARGS(ppRetVal));
const auto hr = _pProvider->QueryInterface(IID_PPV_ARGS(ppRetVal));
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
// TODO CARLOS: fix tracing call
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
//UiaTracing::TextRange::GetEnclosingElement(*this, static_cast<ScreenInfoUiaProviderBase*>(*ppRetVal));
return hr;
Expand Down Expand Up @@ -1179,7 +1179,10 @@ RECT UiaTextRangeBase::_getTerminalRect() const
};
}

#pragma warning(push)
#pragma warning(disable : 26447) // compiler isn't filtering throws inside the try/catch
std::wstring UiaTextRangeBase::_getTextValue() const noexcept
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
try
{
_pData->LockConsole();
auto Unlock = wil::scope_exit([&]() noexcept {
Expand All @@ -1191,23 +1194,21 @@ std::wstring UiaTextRangeBase::_getTextValue() const noexcept
return {};
}

try
{
std::wstringstream stream;
const auto& buffer = _pData->GetTextBuffer();
const auto bufferSize = buffer.GetSize();

auto pos = _start;
while (std::abs(bufferSize.CompareInBounds(pos, _end, true)) > 0)
{
stream << buffer.GetTextDataAt(pos)->data();
bufferSize.IncrementInBounds(pos, true);
}
std::wstringstream stream;
const auto& buffer = _pData->GetTextBuffer();
const auto bufferSize = buffer.GetSize();

return stream.str();
}
catch (...)
auto pos = _start;
while (std::abs(bufferSize.CompareInBounds(pos, _end, true)) > 0)
{
return {};
stream << buffer.GetTextDataAt(pos)->data();
bufferSize.IncrementInBounds(pos, true);
}

return stream.str();
}
catch (...)
{
return {};
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
}
#pragma warning(pop)
29 changes: 25 additions & 4 deletions src/types/UiaTracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
#include "precomp.h"
#include "UiaTracing.h"

// we need to disable a few warnings because
// the TraceLogging code is out of our control
#pragma warning(push)
#pragma warning(disable : 26447)
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
#pragma warning(disable : 26477)
#pragma warning(disable : 26482)
#pragma warning(disable : 26496)
#pragma warning(disable : 26485)
#pragma warning(disable : 26494)
#pragma warning(disable : 26446)
TRACELOGGING_DEFINE_PROVIDER(g_UiaProviderTraceProvider,
"Microsoft.Windows.Console.UIA",
// tl:{e7ebce59-2161-572d-b263-2f16a6afb9e5}
Expand All @@ -21,14 +31,20 @@ UiaTracing::~UiaTracing() noexcept
TraceLoggingUnregister(g_UiaProviderTraceProvider);
}

std::wstring UiaTracing::_getValue(const ScreenInfoUiaProviderBase& /*siup*/)
std::wstring UiaTracing::_getValue(const ScreenInfoUiaProviderBase& /*siup*/) noexcept
try
{
std::wstringstream stream;
stream << " NO IDENTIFYING DATA";
return stream.str();
}
catch (...)
{
return {};
}

std::wstring UiaTracing::_getValue(const UiaTextRangeBase& utr)
std::wstring UiaTracing::_getValue(const UiaTextRangeBase& utr) noexcept
try
{
const auto start = utr.GetEndpoint(TextPatternRangeEndpoint_Start);
const auto end = utr.GetEndpoint(TextPatternRangeEndpoint_End);
Expand All @@ -42,8 +58,12 @@ std::wstring UiaTracing::_getValue(const UiaTextRangeBase& utr)
stream << " content: " << utr._getTextValue();
return stream.str();
}
catch (...)
{
return {};
}

std::wstring UiaTracing::_getValue(const TextPatternRangeEndpoint endpoint)
std::wstring UiaTracing::_getValue(const TextPatternRangeEndpoint endpoint) noexcept
{
switch (endpoint)
{
Expand All @@ -56,7 +76,7 @@ std::wstring UiaTracing::_getValue(const TextPatternRangeEndpoint endpoint)
}
}

std::wstring UiaTracing::_getValue(const TextUnit unit)
std::wstring UiaTracing::_getValue(const TextUnit unit) noexcept
{
switch (unit)
{
Expand Down Expand Up @@ -507,3 +527,4 @@ void UiaTracing::TextProvider::get_SupportedTextSelection(const ScreenInfoUiaPro
TraceLoggingValue(getResult(), "result"),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
}
#pragma warning(pop)
8 changes: 4 additions & 4 deletions src/types/UiaTracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ namespace Microsoft::Console::Types
UiaTracing& operator=(const UiaTracing&) = delete;
UiaTracing& operator=(UiaTracing&&) = delete;

static std::wstring _getValue(const ScreenInfoUiaProviderBase& siup);
static std::wstring _getValue(const UiaTextRangeBase& utr);
static std::wstring _getValue(const TextPatternRangeEndpoint endpoint);
static std::wstring _getValue(const TextUnit unit);
static std::wstring _getValue(const ScreenInfoUiaProviderBase& siup) noexcept;
static std::wstring _getValue(const UiaTextRangeBase& utr) noexcept;
static std::wstring _getValue(const TextPatternRangeEndpoint endpoint) noexcept;
static std::wstring _getValue(const TextUnit unit) noexcept;
};
}