From e21d74c51e5a35b05a33651d5ec2ad5d7d7dd115 Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Wed, 5 Feb 2020 17:11:54 -0800 Subject: [PATCH 01/10] add tracing for UIA (UTR and SIUP) --- src/host/renderData.cpp | 2 +- src/host/tracing.cpp | 716 ------------------------ src/host/tracing.hpp | 39 -- src/types/ScreenInfoUiaProviderBase.cpp | 73 +-- src/types/ScreenInfoUiaProviderBase.h | 45 -- src/types/UiaTextRangeBase.cpp | 259 +++------ src/types/UiaTextRangeBase.hpp | 115 +--- src/types/UiaTracing.cpp | 509 +++++++++++++++++ src/types/UiaTracing.h | 96 ++++ src/types/lib/types.vcxproj | 2 + src/types/lib/types.vcxproj.filters | 8 +- 11 files changed, 709 insertions(+), 1155 deletions(-) create mode 100644 src/types/UiaTracing.cpp create mode 100644 src/types/UiaTracing.h diff --git a/src/host/renderData.cpp b/src/host/renderData.cpp index 0f652719fd6..4f0002855bf 100644 --- a/src/host/renderData.cpp +++ b/src/host/renderData.cpp @@ -12,7 +12,7 @@ #pragma hdrstop using namespace Microsoft::Console::Types; -using namespace Microsoft::Console::Interactivity::Win32; +using namespace Microsoft::Console::Interactivity; using Microsoft::Console::Interactivity::ServiceLocator; #pragma region IBaseData diff --git a/src/host/tracing.cpp b/src/host/tracing.cpp index 6c48a599fdd..a3b97e5670a 100644 --- a/src/host/tracing.cpp +++ b/src/host/tracing.cpp @@ -9,7 +9,6 @@ #include "../types/WindowUiaProviderBase.hpp" using namespace Microsoft::Console::Types; -using namespace Microsoft::Console::Interactivity::Win32; enum TraceKeywords { @@ -398,718 +397,3 @@ void __stdcall Tracing::TraceFailure(const wil::FailureInfo& failure) noexcept TraceLoggingString(failure.pszCode, "Code"), TraceLoggingLevel(WINEVENT_LEVEL_ERROR)); } - -// TODO GitHub #1914: Re-attach Tracing to UIA Tree -#if 0 -void Tracing::s_TraceUia(const UiaTextRange* const range, - const UiaTextRangeTracing::ApiCall apiCall, - const UiaTextRangeTracing::IApiMsg* const apiMsg) -{ - unsigned long long id = 0u; - bool degenerate = true; - Endpoint start = 0u; - Endpoint end = 0u; - if (range) - { - id = range->GetId(); - degenerate = range->IsDegenerate(); - start = range->GetStart(); - end = range->GetEnd(); - } - - switch (apiCall) - { - case UiaTextRangeTracing::ApiCall::Constructor: - { - id = static_cast(apiMsg)->Id; - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::Constructor", - TraceLoggingValue(id, "_id"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - } - case UiaTextRangeTracing::ApiCall::AddRef: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::AddRef", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case UiaTextRangeTracing::ApiCall::Release: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::Release", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case UiaTextRangeTracing::ApiCall::QueryInterface: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::QueryInterface", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case UiaTextRangeTracing::ApiCall::Clone: - { - if (apiMsg == nullptr) - { - return; - } - auto cloneId = reinterpret_cast(apiMsg)->CloneId; - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::Clone", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingValue(cloneId, "clone's _id"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - } - case UiaTextRangeTracing::ApiCall::Compare: - { - const UiaTextRangeTracing::ApiMsgCompare* const msg = static_cast(apiMsg); - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::Compare", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingValue(msg->OtherId, "Other's Id"), - TraceLoggingValue(msg->Equal, "Equal"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - } - case UiaTextRangeTracing::ApiCall::CompareEndpoints: - { - const UiaTextRangeTracing::ApiMsgCompareEndpoints* const msg = static_cast(apiMsg); - const wchar_t* const pEndpoint = _textPatternRangeEndpointToString(msg->Endpoint); - const wchar_t* const pTargetEndpoint = _textPatternRangeEndpointToString(msg->TargetEndpoint); - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::CompareEndpoints", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingValue(msg->OtherId, "Other's Id"), - TraceLoggingValue(pEndpoint, "endpoint"), - TraceLoggingValue(pTargetEndpoint, "targetEndpoint"), - TraceLoggingValue(msg->Result, "Result"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - } - case UiaTextRangeTracing::ApiCall::ExpandToEnclosingUnit: - { - const UiaTextRangeTracing::ApiMsgExpandToEnclosingUnit* const msg = static_cast(apiMsg); - const wchar_t* const pUnitName = _textUnitToString(msg->Unit); - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::ExpandToEnclosingUnit", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingValue(pUnitName, "Unit"), - TraceLoggingValue(msg->OriginalStart, "Original Start"), - TraceLoggingValue(msg->OriginalEnd, "Original End"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - } - case UiaTextRangeTracing::ApiCall::FindAttribute: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::FindAttribute", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case UiaTextRangeTracing::ApiCall::FindText: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::FindText", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case UiaTextRangeTracing::ApiCall::GetAttributeValue: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::GetAttributeValue", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case UiaTextRangeTracing::ApiCall::GetBoundingRectangles: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::GetBoundingRectangles", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case UiaTextRangeTracing::ApiCall::GetEnclosingElement: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::GetEnclosingElement", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case UiaTextRangeTracing::ApiCall::GetText: - { - const UiaTextRangeTracing::ApiMsgGetText* const msg = static_cast(apiMsg); - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::GetText", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingValue(msg->Text, "Text"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - } - case UiaTextRangeTracing::ApiCall::Move: - { - const UiaTextRangeTracing::ApiMsgMove* const msg = static_cast(apiMsg); - const wchar_t* const unitStr = _textUnitToString(msg->Unit); - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::Move", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingValue(msg->OriginalStart, "Original Start"), - TraceLoggingValue(msg->OriginalEnd, "Original End"), - TraceLoggingValue(unitStr, "unit"), - TraceLoggingValue(msg->RequestedCount, "Requested Count"), - TraceLoggingValue(msg->MovedCount, "Moved Count"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - } - case UiaTextRangeTracing::ApiCall::MoveEndpointByUnit: - { - const UiaTextRangeTracing::ApiMsgMoveEndpointByUnit* const msg = static_cast(apiMsg); - const wchar_t* const pEndpoint = _textPatternRangeEndpointToString(msg->Endpoint); - const wchar_t* const unitStr = _textUnitToString(msg->Unit); - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::MoveEndpointByUnit", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingValue(msg->OriginalStart, "Original Start"), - TraceLoggingValue(msg->OriginalEnd, "Original End"), - TraceLoggingValue(pEndpoint, "endpoint"), - TraceLoggingValue(unitStr, "unit"), - TraceLoggingValue(msg->RequestedCount, "Requested Count"), - TraceLoggingValue(msg->MovedCount, "Moved Count"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - } - case UiaTextRangeTracing::ApiCall::MoveEndpointByRange: - { - const UiaTextRangeTracing::ApiMsgMoveEndpointByRange* const msg = static_cast(apiMsg); - const wchar_t* const pEndpoint = _textPatternRangeEndpointToString(msg->Endpoint); - const wchar_t* const pTargetEndpoint = _textPatternRangeEndpointToString(msg->TargetEndpoint); - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::MoveEndpointByRange", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingValue(msg->OriginalStart, "Original Start"), - TraceLoggingValue(msg->OriginalEnd, "Original End"), - TraceLoggingValue(pEndpoint, "endpoint"), - TraceLoggingValue(pTargetEndpoint, "targetEndpoint"), - TraceLoggingValue(msg->OtherId, "Other's _id"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - } - case UiaTextRangeTracing::ApiCall::Select: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::Select", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case UiaTextRangeTracing::ApiCall::AddToSelection: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::AddToSelection", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case UiaTextRangeTracing::ApiCall::RemoveFromSelection: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::RemoveFromSelection", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case UiaTextRangeTracing::ApiCall::ScrollIntoView: - { - const UiaTextRangeTracing::ApiMsgScrollIntoView* const msg = static_cast(apiMsg); - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::ScrollIntoView", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingValue(msg->AlignToTop, "alignToTop"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - } - case UiaTextRangeTracing::ApiCall::GetChildren: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "UiaTextRange::GetChildren", - TraceLoggingValue(id, "_id"), - TraceLoggingValue(start, "_start"), - TraceLoggingValue(end, "_end"), - TraceLoggingValue(degenerate, "_degenerate"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - default: - break; - } -} - -void Tracing::s_TraceUia(const Microsoft::Console::Interactivity::Win32::ScreenInfoUiaProvider* const /*pProvider*/, - const ScreenInfoUiaProviderTracing::ApiCall apiCall, - const ScreenInfoUiaProviderTracing::IApiMsg* const apiMsg) -{ - switch (apiCall) - { - case ScreenInfoUiaProviderTracing::ApiCall::Constructor: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::Constructor", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case ScreenInfoUiaProviderTracing::ApiCall::Signal: - { - const ScreenInfoUiaProviderTracing::ApiMsgSignal* const msg = static_cast(apiMsg); - const wchar_t* const signalName = _eventIdToString(msg->Signal); - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::Signal", - TraceLoggingValue(msg->Signal), - TraceLoggingValue(signalName, "Event Name"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - } - case ScreenInfoUiaProviderTracing::ApiCall::AddRef: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::AddRef", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case ScreenInfoUiaProviderTracing::ApiCall::Release: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::Release", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case ScreenInfoUiaProviderTracing::ApiCall::QueryInterface: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::QueryInterface", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case ScreenInfoUiaProviderTracing::ApiCall::GetProviderOptions: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::GetProviderOptions", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case ScreenInfoUiaProviderTracing::ApiCall::GetPatternProvider: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::GetPatternProvider", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case ScreenInfoUiaProviderTracing::ApiCall::GetPropertyValue: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::GetPropertyValue", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case ScreenInfoUiaProviderTracing::ApiCall::GetHostRawElementProvider: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::GetHostRawElementProvider", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case ScreenInfoUiaProviderTracing::ApiCall::Navigate: - { - const ScreenInfoUiaProviderTracing::ApiMsgNavigate* const msg = static_cast(apiMsg); - const wchar_t* const direction = _directionToString(msg->Direction); - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::Navigate", - TraceLoggingValue(direction, "direction"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - } - case ScreenInfoUiaProviderTracing::ApiCall::GetRuntimeId: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::GetRuntimeId", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case ScreenInfoUiaProviderTracing::ApiCall::GetBoundingRectangle: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::GetBoundingRectangles", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case ScreenInfoUiaProviderTracing::ApiCall::GetEmbeddedFragmentRoots: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::GetEmbeddedFragmentRoots", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case ScreenInfoUiaProviderTracing::ApiCall::SetFocus: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::SetFocus", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case ScreenInfoUiaProviderTracing::ApiCall::GetFragmentRoot: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::GetFragmentRoot", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case ScreenInfoUiaProviderTracing::ApiCall::GetSelection: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::GetSelection", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case ScreenInfoUiaProviderTracing::ApiCall::GetVisibleRanges: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::GetVisibleRanges", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case ScreenInfoUiaProviderTracing::ApiCall::RangeFromChild: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::RangeFromChild", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case ScreenInfoUiaProviderTracing::ApiCall::RangeFromPoint: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::RangeFromPoint", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case ScreenInfoUiaProviderTracing::ApiCall::GetDocumentRange: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::GetDocumentRange", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case ScreenInfoUiaProviderTracing::ApiCall::GetSupportedTextSelection: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "ScreenInfoUiaProvider::GetSupportedTextSelection", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - default: - break; - } -} - -void Tracing::s_TraceUia(const Microsoft::Console::Types::WindowUiaProvider* const /*pProvider*/, - const Microsoft::Console::Types::WindowUiaProviderTracing::ApiCall apiCall, - const Microsoft::Console::Types::WindowUiaProviderTracing::IApiMsg* const apiMsg) -{ - switch (apiCall) - { - case Microsoft::Console::Types::WindowUiaProviderTracing::ApiCall::Create: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "WindowUiaProvider::Create", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case Microsoft::Console::Types::WindowUiaProviderTracing::ApiCall::Signal: - { - const Microsoft::Console::Types::WindowUiaProviderTracing::ApiMessageSignal* const msg = static_cast(apiMsg); - const wchar_t* const eventName = _eventIdToString(msg->Signal); - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "WindowUiaProvider::Signal", - TraceLoggingValue(msg->Signal, "Signal"), - TraceLoggingValue(eventName, "Signal Name"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - } - case Microsoft::Console::Types::WindowUiaProviderTracing::ApiCall::AddRef: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "WindowUiaProvider::AddRef", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case Microsoft::Console::Types::WindowUiaProviderTracing::ApiCall::Release: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "WindowUiaProvider::Release", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case Microsoft::Console::Types::WindowUiaProviderTracing::ApiCall::QueryInterface: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "WindowUiaProvider::QueryInterface", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case Microsoft::Console::Types::WindowUiaProviderTracing::ApiCall::GetProviderOptions: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "WindowUiaProvider::GetProviderOptions", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case Microsoft::Console::Types::WindowUiaProviderTracing::ApiCall::GetPatternProvider: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "WindowUiaProvider::GetPatternProvider", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case Microsoft::Console::Types::WindowUiaProviderTracing::ApiCall::GetPropertyValue: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "WindowUiaProvider::GetPropertyValue", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case Microsoft::Console::Types::WindowUiaProviderTracing::ApiCall::GetHostRawElementProvider: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "WindowUiaProvider::GetHostRawElementProvider", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case Microsoft::Console::Types::WindowUiaProviderTracing::ApiCall::Navigate: - { - const Microsoft::Console::Types::WindowUiaProviderTracing::ApiMsgNavigate* const msg = static_cast(apiMsg); - const wchar_t* const direction = _directionToString(msg->Direction); - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "WindowUiaProvider::Navigate", - TraceLoggingValue(direction, "direction"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - } - case Microsoft::Console::Types::WindowUiaProviderTracing::ApiCall::GetRuntimeId: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "WindowUiaProvider::GetRuntimeId", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case Microsoft::Console::Types::WindowUiaProviderTracing::ApiCall::GetBoundingRectangle: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "WindowUiaProvider::GetBoundingRectangle", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case Microsoft::Console::Types::WindowUiaProviderTracing::ApiCall::GetEmbeddedFragmentRoots: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "WindowUiaProvider::GetEmbeddedFragmentRoots", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case Microsoft::Console::Types::WindowUiaProviderTracing::ApiCall::SetFocus: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "WindowUiaProvider::SetFocus", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case Microsoft::Console::Types::WindowUiaProviderTracing::ApiCall::GetFragmentRoot: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "WindowUiaProvider::GetFragmentRoot", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case Microsoft::Console::Types::WindowUiaProviderTracing::ApiCall::ElementProviderFromPoint: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "WindowUiaProvider::ElementProviderFromPoint", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - case Microsoft::Console::Types::WindowUiaProviderTracing::ApiCall::GetFocus: - TraceLoggingWrite( - g_hConhostV2EventTraceProvider, - "WindowUiaProvider::GetFocus", - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TraceKeywords::UIA)); - break; - default: - break; - } -} -#endif - -const wchar_t* const Tracing::_textPatternRangeEndpointToString(int endpoint) -{ - switch (endpoint) - { - case TextPatternRangeEndpoint::TextPatternRangeEndpoint_Start: - return L"Start"; - case TextPatternRangeEndpoint::TextPatternRangeEndpoint_End: - return L"End"; - default: - return L"Unknown"; - } -} - -const wchar_t* const Tracing::_textUnitToString(int unit) -{ - switch (unit) - { - case TextUnit::TextUnit_Character: - return L"TextUnit_Character"; - case TextUnit::TextUnit_Format: - return L"TextUnit_Format"; - case TextUnit::TextUnit_Word: - return L"TextUnit_Word"; - case TextUnit::TextUnit_Line: - return L"TextUnit_Line"; - case TextUnit::TextUnit_Paragraph: - return L"TextUnit_Paragraph"; - case TextUnit::TextUnit_Page: - return L"TextUnit_Page"; - case TextUnit::TextUnit_Document: - return L"TextUnit_Document"; - default: - return L"Unknown"; - } -} - -const wchar_t* const Tracing::_eventIdToString(long eventId) -{ - switch (eventId) - { - case UIA_AutomationFocusChangedEventId: - return L"UIA_AutomationFocusChangedEventId"; - case UIA_Text_TextChangedEventId: - return L"UIA_Text_TextChangedEventId"; - case UIA_Text_TextSelectionChangedEventId: - return L"UIA_Text_TextSelectionChangedEventId"; - default: - return L"Unknown"; - } -} - -const wchar_t* const Tracing::_directionToString(int direction) -{ - switch (direction) - { - case NavigateDirection::NavigateDirection_FirstChild: - return L"NavigateDirection_FirstChild"; - case NavigateDirection::NavigateDirection_LastChild: - return L"NavigateDirection_LastChild"; - case NavigateDirection::NavigateDirection_NextSibling: - return L"NavigateDirection_NextSibling"; - case NavigateDirection::NavigateDirection_Parent: - return L"NavigateDirection_Parent"; - case NavigateDirection::NavigateDirection_PreviousSibling: - return L"NavigateDirection_PreviousSibling"; - default: - return L"Unknown"; - } -} diff --git a/src/host/tracing.hpp b/src/host/tracing.hpp index 4f5d8b44fcd..a44476b4acd 100644 --- a/src/host/tracing.hpp +++ b/src/host/tracing.hpp @@ -21,25 +21,6 @@ Author(s): #include "../types/inc/Viewport.hpp" -namespace Microsoft::Console::Interactivity::Win32 -{ - class UiaTextRange; - - namespace UiaTextRangeTracing - { - enum class ApiCall; - struct IApiMsg; - } - - class ScreenInfoUiaProvider; - - namespace ScreenInfoUiaProviderTracing - { - enum class ApiCall; - struct IApiMsg; - } -} - #if DBG #define DBGCHARS(_params_) \ { \ @@ -83,30 +64,10 @@ class Tracing static void __stdcall TraceFailure(const wil::FailureInfo& failure) noexcept; -// TODO GitHub #1914: Re-attach Tracing to UIA Tree -#if 0 - static void s_TraceUia(const Microsoft::Console::Interactivity::Win32::UiaTextRange* const range, - const Microsoft::Console::Interactivity::Win32::UiaTextRangeTracing::ApiCall apiCall, - const Microsoft::Console::Interactivity::Win32::UiaTextRangeTracing::IApiMsg* const apiMsg); - - static void s_TraceUia(const Microsoft::Console::Interactivity::Win32::ScreenInfoUiaProvider* const pProvider, - const Microsoft::Console::Interactivity::Win32::ScreenInfoUiaProviderTracing::ApiCall apiCall, - const Microsoft::Console::Interactivity::Win32::ScreenInfoUiaProviderTracing::IApiMsg* const apiMsg); - - static void s_TraceUia(const Microsoft::Console::Types::WindowUiaProvider* const pProvider, - const Microsoft::Console::Types::WindowUiaProviderTracing::ApiCall apiCall, - const Microsoft::Console::Types::WindowUiaProviderTracing::IApiMsg* const apiMsg); -#endif - private: static ULONG s_ulDebugFlag; Tracing(std::function onExit); std::function _onExit; - - static const wchar_t* const _textPatternRangeEndpointToString(int endpoint); - static const wchar_t* const _textUnitToString(int unit); - static const wchar_t* const _eventIdToString(long eventId); - static const wchar_t* const _directionToString(int direction); }; diff --git a/src/types/ScreenInfoUiaProviderBase.cpp b/src/types/ScreenInfoUiaProviderBase.cpp index bc95e3ba972..3af98864a02 100644 --- a/src/types/ScreenInfoUiaProviderBase.cpp +++ b/src/types/ScreenInfoUiaProviderBase.cpp @@ -5,9 +5,9 @@ #include "ScreenInfoUiaProviderBase.h" #include "WindowUiaProviderBase.hpp" +#include "UiaTracing.h" using namespace Microsoft::Console::Types; -using namespace Microsoft::Console::Types::ScreenInfoUiaProviderTracing; // A helper function to create a SafeArray Version of an int array of a specified length SAFEARRAY* BuildIntSafeArray(std::basic_string_view data) @@ -38,6 +38,7 @@ try RETURN_HR_IF_NULL(E_INVALIDARG, pData); _pData = pData; _wordDelimiters = wordDelimiters; + UiaTracing::TextProvider::Constructor(*this); return S_OK; } CATCH_RETURN(); @@ -62,11 +63,6 @@ CATCH_RETURN(); hr = UiaRaiseAutomationEvent(pProvider, id); _signalFiringMapping[id] = false; - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - // tracing - /*ApiMsgSignal apiMsg; - apiMsg.Signal = id; - Tracing::s_TraceUia(this, ApiCall::Signal, &apiMsg);*/ return hr; } @@ -78,9 +74,8 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::get_ProviderOptions(_Out_ ProviderOpti { RETURN_HR_IF_NULL(E_INVALIDARG, pOptions); - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::GetProviderOptions, nullptr); *pOptions = ProviderOptions_ServerSideProvider; + UiaTracing::TextProvider::get_ProviderOptions(*this, *pOptions); return S_OK; } @@ -92,12 +87,7 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetPatternProvider(_In_ PATTERNID patt RETURN_HR_IF(E_INVALIDARG, ppInterface == nullptr); *ppInterface = nullptr; - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::GetPatternProvider, nullptr); - - *ppInterface = nullptr; HRESULT hr = S_OK; - if (patternId == UIA_TextPatternId) { hr = QueryInterface(IID_PPV_ARGS(ppInterface)); @@ -106,6 +96,7 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetPatternProvider(_In_ PATTERNID patt *ppInterface = nullptr; } } + UiaTracing::TextProvider::GetPatternProvider(*this, patternId); return hr; } @@ -114,9 +105,6 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetPatternProvider(_In_ PATTERNID patt IFACEMETHODIMP ScreenInfoUiaProviderBase::GetPropertyValue(_In_ PROPERTYID propertyId, _Out_ VARIANT* pVariant) noexcept { - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::GetPropertyValue, nullptr); - pVariant->vt = VT_EMPTY; // Returning the default will leave the property as the default @@ -179,16 +167,15 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetPropertyValue(_In_ PROPERTYID prope pVariant->boolVal = VARIANT_TRUE; } + UiaTracing::TextProvider::GetPropertyValue(*this, propertyId); return S_OK; } IFACEMETHODIMP ScreenInfoUiaProviderBase::get_HostRawElementProvider(_COM_Outptr_result_maybenull_ IRawElementProviderSimple** ppProvider) noexcept { - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::GetHostRawElementProvider, nullptr); RETURN_HR_IF(E_INVALIDARG, ppProvider == nullptr); *ppProvider = nullptr; - + UiaTracing::TextProvider::get_HostRawElementProvider(*this); return S_OK; } #pragma endregion @@ -197,9 +184,6 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::get_HostRawElementProvider(_COM_Outptr IFACEMETHODIMP ScreenInfoUiaProviderBase::GetRuntimeId(_Outptr_result_maybenull_ SAFEARRAY** ppRuntimeId) { - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::GetRuntimeId, nullptr); - // Root defers this to host, others must implement it... RETURN_HR_IF(E_INVALIDARG, ppRuntimeId == nullptr); *ppRuntimeId = nullptr; @@ -212,24 +196,21 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetRuntimeId(_Outptr_result_maybenull_ *ppRuntimeId = BuildIntSafeArray(span); RETURN_IF_NULL_ALLOC(*ppRuntimeId); + UiaTracing::TextProvider::GetRuntimeId(*this); return S_OK; } IFACEMETHODIMP ScreenInfoUiaProviderBase::GetEmbeddedFragmentRoots(_Outptr_result_maybenull_ SAFEARRAY** ppRoots) noexcept { - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::GetEmbeddedFragmentRoots, nullptr); - RETURN_HR_IF(E_INVALIDARG, ppRoots == nullptr); *ppRoots = nullptr; + UiaTracing::TextProvider::GetEmbeddedFragmentRoots(*this); return S_OK; } IFACEMETHODIMP ScreenInfoUiaProviderBase::SetFocus() { - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::SetFocus, nullptr); - + UiaTracing::TextProvider::SetFocus(*this); return Signal(UIA_AutomationFocusChangedEventId); } @@ -239,9 +220,6 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::SetFocus() IFACEMETHODIMP ScreenInfoUiaProviderBase::GetSelection(_Outptr_result_maybenull_ SAFEARRAY** ppRetVal) { - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //ApiMsgGetSelection apiMsg; - _LockConsole(); auto Unlock = wil::scope_exit([&]() noexcept { _UnlockConsole(); @@ -253,10 +231,6 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetSelection(_Outptr_result_maybenull_ if (!_pData->IsSelectionActive()) { - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //apiMsg.AreaSelected = false; - //apiMsg.SelectionRowCount = 1; - // return a degenerate range at the cursor position const Cursor& cursor = _getTextBuffer().GetCursor(); @@ -298,10 +272,6 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetSelection(_Outptr_result_maybenull_ std::deque> ranges; RETURN_IF_FAILED(GetSelectionRanges(this, _wordDelimiters, ranges)); - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //apiMsg.AreaSelected = true; - //apiMsg.SelectionRowCount = static_cast(ranges.size()); - // make a safe array *ppRetVal = SafeArrayCreateVector(VT_UNKNOWN, 0, gsl::narrow(ranges.size())); if (*ppRetVal == nullptr) @@ -322,16 +292,12 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetSelection(_Outptr_result_maybenull_ } } - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::GetSelection, &apiMsg); + UiaTracing::TextProvider::GetSelection(*this); return S_OK; } IFACEMETHODIMP ScreenInfoUiaProviderBase::GetVisibleRanges(_Outptr_result_maybenull_ SAFEARRAY** ppRetVal) { - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::GetVisibleRanges, nullptr); - _LockConsole(); auto Unlock = wil::scope_exit([&]() noexcept { _UnlockConsole(); @@ -339,6 +305,7 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetVisibleRanges(_Outptr_result_mayben RETURN_HR_IF_NULL(E_INVALIDARG, ppRetVal); *ppRetVal = nullptr; + WRL::ComPtr range; const auto bufferSize = _pData->GetTextBuffer().GetSize(); const auto viewport = bufferSize.ConvertToOrigin(_getViewport()); @@ -359,7 +326,6 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetVisibleRanges(_Outptr_result_mayben const COORD end{ start.X, start.Y + 1 }; HRESULT hr = S_OK; - WRL::ComPtr range; hr = CreateTextRange(this, start, end, @@ -381,30 +347,26 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetVisibleRanges(_Outptr_result_mayben return hr; } } + UiaTracing::TextProvider::GetVisibleRanges(*this, *range.Get()); return S_OK; } IFACEMETHODIMP ScreenInfoUiaProviderBase::RangeFromChild(_In_ IRawElementProviderSimple* /*childElement*/, _COM_Outptr_result_maybenull_ ITextRangeProvider** ppRetVal) { - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::RangeFromChild, nullptr); - RETURN_HR_IF_NULL(E_INVALIDARG, ppRetVal); *ppRetVal = nullptr; WRL::ComPtr utr; RETURN_IF_FAILED(CreateTextRange(this, _wordDelimiters, &utr)); RETURN_IF_FAILED(utr.CopyTo(ppRetVal)); + UiaTracing::TextProvider::RangeFromChild(*this, *utr.Get()); return S_OK; } IFACEMETHODIMP ScreenInfoUiaProviderBase::RangeFromPoint(_In_ UiaPoint point, _COM_Outptr_result_maybenull_ ITextRangeProvider** ppRetVal) { - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::RangeFromPoint, nullptr); - RETURN_HR_IF_NULL(E_INVALIDARG, ppRetVal); *ppRetVal = nullptr; @@ -414,14 +376,12 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::RangeFromPoint(_In_ UiaPoint point, _wordDelimiters, &utr)); RETURN_IF_FAILED(utr.CopyTo(ppRetVal)); + UiaTracing::TextProvider::RangeFromPoint(*this, point, *utr.Get()); return S_OK; } IFACEMETHODIMP ScreenInfoUiaProviderBase::get_DocumentRange(_COM_Outptr_result_maybenull_ ITextRangeProvider** ppRetVal) { - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::GetDocumentRange, nullptr); - RETURN_HR_IF_NULL(E_INVALIDARG, ppRetVal); *ppRetVal = nullptr; @@ -429,6 +389,7 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::get_DocumentRange(_COM_Outptr_result_m RETURN_IF_FAILED(CreateTextRange(this, _wordDelimiters, &utr)); RETURN_IF_FAILED(utr->ExpandToEnclosingUnit(TextUnit::TextUnit_Document)); RETURN_IF_FAILED(utr.CopyTo(ppRetVal)); + UiaTracing::TextProvider::get_DocumentRange(*this, *utr.Get()); return S_OK; } @@ -436,10 +397,8 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::get_SupportedTextSelection(_Out_ Suppo { RETURN_HR_IF_NULL(E_INVALIDARG, pRetVal); - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::GetSupportedTextSelection, nullptr); - *pRetVal = SupportedTextSelection::SupportedTextSelection_Single; + UiaTracing::TextProvider::get_SupportedTextSelection(*this, *pRetVal); return S_OK; } diff --git a/src/types/ScreenInfoUiaProviderBase.h b/src/types/ScreenInfoUiaProviderBase.h index 82bdd31fcb0..8d548a4d7c3 100644 --- a/src/types/ScreenInfoUiaProviderBase.h +++ b/src/types/ScreenInfoUiaProviderBase.h @@ -127,49 +127,4 @@ namespace Microsoft::Console::Types void _LockConsole() noexcept; void _UnlockConsole() noexcept; }; - - namespace ScreenInfoUiaProviderTracing - { - enum class ApiCall - { - Constructor, - Signal, - GetProviderOptions, - GetPatternProvider, - GetPropertyValue, - GetHostRawElementProvider, - Navigate, - GetRuntimeId, - GetBoundingRectangle, - GetEmbeddedFragmentRoots, - SetFocus, - GetFragmentRoot, - GetSelection, - GetVisibleRanges, - RangeFromChild, - RangeFromPoint, - GetDocumentRange, - GetSupportedTextSelection - }; - - struct IApiMsg - { - }; - - struct ApiMsgSignal : public IApiMsg - { - EVENTID Signal; - }; - - struct ApiMsgNavigate : public IApiMsg - { - NavigateDirection Direction; - }; - - struct ApiMsgGetSelection : public IApiMsg - { - bool AreaSelected; - unsigned int SelectionRowCount; - }; - } } diff --git a/src/types/UiaTextRangeBase.cpp b/src/types/UiaTextRangeBase.cpp index 804d4758540..96c7caf280e 100644 --- a/src/types/UiaTextRangeBase.cpp +++ b/src/types/UiaTextRangeBase.cpp @@ -5,34 +5,12 @@ #include "UiaTextRangeBase.hpp" #include "ScreenInfoUiaProviderBase.h" #include "..\buffer\out\search.h" +#include "UiaTracing.h" using namespace Microsoft::Console::Types; -using namespace Microsoft::Console::Types::UiaTextRangeBaseTracing; - -// toggle these for additional logging in a debug build -//#define _DEBUG 1 -//#define UIATEXTRANGE_DEBUG_MSGS 1 -#undef UIATEXTRANGE_DEBUG_MSGS IdType UiaTextRangeBase::id = 1; -#if _DEBUG -#include -void UiaTextRangeBase::_outputObjectState() -{ - std::wstringstream ss; - ss << "Object State"; - ss << " _id: " << _id; - ss << " _start: { " << _start.X << ", " << _start.Y << " }"; - ss << " _end: { " << _end.X << ", " << _end.Y << " }"; - ss << " _degenerate: " << IsDegenerate(); - - std::wstring str = ss.str(); - OutputDebugString(str.c_str()); - OutputDebugString(L"\n"); -} -#endif // _DEBUG - // degenerate range constructor. #pragma warning(suppress : 26434) // WRL RuntimeClassInitialize base is a no-op and we need this for MakeAndInitialize HRESULT UiaTextRangeBase::RuntimeClassInitialize(_In_ IUiaData* pData, _In_ IRawElementProviderSimple* const pProvider, _In_ std::wstring_view wordDelimiters) noexcept @@ -50,12 +28,7 @@ try _id = id; ++id; - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - // tracing - /*ApiMsgConstructor apiMsg; - apiMsg.Id = _id; - Tracing::s_TraceUia(nullptr, ApiCall::Constructor, &apiMsg);*/ - + UiaTracing::TextRange::Constructor(*this); return S_OK; } CATCH_RETURN(); @@ -65,25 +38,17 @@ HRESULT UiaTextRangeBase::RuntimeClassInitialize(_In_ IUiaData* pData, _In_ IRawElementProviderSimple* const pProvider, _In_ const Cursor& cursor, _In_ std::wstring_view wordDelimiters) noexcept +try { RETURN_IF_FAILED(RuntimeClassInitialize(pData, pProvider, wordDelimiters)); - try - { - _start = cursor.GetPosition(); - _end = _start; + _start = cursor.GetPosition(); + _end = _start; -#if defined(_DEBUG) && defined(UIATEXTRANGE_DEBUG_MSGS) - OutputDebugString(L"Constructor\n"); - _outputObjectState(); -#endif - } - catch (...) - { - return E_INVALIDARG; - } + UiaTracing::TextRange::Constructor(*this); return S_OK; } +CATCH_RETURN(); #pragma warning(suppress : 26434) // WRL RuntimeClassInitialize base is a no-op and we need this for MakeAndInitialize HRESULT UiaTextRangeBase::RuntimeClassInitialize(_In_ IUiaData* pData, @@ -97,11 +62,7 @@ HRESULT UiaTextRangeBase::RuntimeClassInitialize(_In_ IUiaData* pData, _start = start; _end = end; -#if defined(_DEBUG) && defined(UIATEXTRANGE_DEBUG_MSGS) - OutputDebugString(L"Constructor\n"); - _outputObjectState(); -#endif - + UiaTracing::TextRange::Constructor(*this); return S_OK; } @@ -147,11 +108,7 @@ try _id = id; ++id; -#if defined(_DEBUG) && defined(UIATEXTRANGE_DEBUG_MSGS) - OutputDebugString(L"Copy Constructor\n"); - _outputObjectState(); -#endif - + UiaTracing::TextRange::Constructor(*this); return S_OK; } CATCH_RETURN(); @@ -165,9 +122,9 @@ const COORD UiaTextRangeBase::GetEndpoint(TextPatternRangeEndpoint endpoint) con { switch (endpoint) { - case TextPatternRangeEndpoint::TextPatternRangeEndpoint_End: + case TextPatternRangeEndpoint_End: return _end; - case TextPatternRangeEndpoint::TextPatternRangeEndpoint_Start: + case TextPatternRangeEndpoint_Start: default: return _start; } @@ -186,7 +143,7 @@ bool UiaTextRangeBase::SetEndpoint(TextPatternRangeEndpoint endpoint, const COOR const auto bufferSize = _pData->GetTextBuffer().GetSize(); switch (endpoint) { - case TextPatternRangeEndpoint::TextPatternRangeEndpoint_End: + case TextPatternRangeEndpoint_End: _end = val; // if end is before start... if (bufferSize.CompareInBounds(_end, _start, true) < 0) @@ -195,7 +152,7 @@ bool UiaTextRangeBase::SetEndpoint(TextPatternRangeEndpoint endpoint, const COOR _start = _end; } break; - case TextPatternRangeEndpoint::TextPatternRangeEndpoint_Start: + case TextPatternRangeEndpoint_Start: _start = val; // if start is after end... if (bufferSize.CompareInBounds(_start, _end, true) > 0) @@ -238,13 +195,8 @@ IFACEMETHODIMP UiaTextRangeBase::Compare(_In_opt_ ITextRangeProvider* pRange, _O *pRetVal = (_start == other->GetEndpoint(TextPatternRangeEndpoint_Start) && _end == other->GetEndpoint(TextPatternRangeEndpoint_End)); } - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - // tracing - /*ApiMsgCompare apiMsg; - apiMsg.OtherId = other == nullptr ? InvalidId : other->GetId(); - apiMsg.Equal = !!*pRetVal; - Tracing::s_TraceUia(this, ApiCall::Compare, &apiMsg);*/ + UiaTracing::TextRange::Compare(*this, *other, *pRetVal); return S_OK; } @@ -273,15 +225,7 @@ try // compare them *pRetVal = _pData->GetTextBuffer().GetSize().CompareInBounds(mine, other, true); - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - // tracing - /*ApiMsgCompareEndpoints apiMsg; - apiMsg.OtherId = range->GetId(); - apiMsg.Endpoint = endpoint; - apiMsg.TargetEndpoint = targetEndpoint; - apiMsg.Result = *pRetVal; - Tracing::s_TraceUia(this, ApiCall::CompareEndpoints, &apiMsg);*/ - + UiaTracing::TextRange::CompareEndpoints(*this, endpoint, *range, targetEndpoint, *pRetVal); return S_OK; } CATCH_RETURN(); @@ -293,29 +237,24 @@ IFACEMETHODIMP UiaTextRangeBase::ExpandToEnclosingUnit(_In_ TextUnit unit) noexc _pData->UnlockConsole(); }); - ApiMsgExpandToEnclosingUnit apiMsg; - apiMsg.Unit = unit; - apiMsg.OriginalStart = _start; - apiMsg.OriginalEnd = _end; - try { const auto& buffer = _pData->GetTextBuffer(); const auto bufferSize = buffer.GetSize(); const auto bufferEnd = bufferSize.EndExclusive(); - if (unit == TextUnit::TextUnit_Character) + if (unit == TextUnit_Character) { _end = _start; bufferSize.IncrementInBounds(_end, true); } - else if (unit <= TextUnit::TextUnit_Word) + else if (unit <= TextUnit_Word) { // expand to word _start = buffer.GetWordStart(_start, _wordDelimiters, true); _end = buffer.GetWordEnd(_start, _wordDelimiters, true); } - else if (unit <= TextUnit::TextUnit_Line) + else if (unit <= TextUnit_Line) { // expand to line _start.X = 0; @@ -329,8 +268,7 @@ IFACEMETHODIMP UiaTextRangeBase::ExpandToEnclosingUnit(_In_ TextUnit unit) noexc _end = bufferSize.EndExclusive(); } - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::ExpandToEnclosingUnit, &apiMsg); + UiaTracing::TextRange::ExpandToEnclosingUnit(unit, *this); return S_OK; } CATCH_RETURN(); @@ -342,8 +280,7 @@ IFACEMETHODIMP UiaTextRangeBase::FindAttribute(_In_ TEXTATTRIBUTEID /*textAttrib _In_ BOOL /*searchBackward*/, _Outptr_result_maybenull_ ITextRangeProvider** /*ppRetVal*/) noexcept { - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::FindAttribute, nullptr); + UiaTracing::TextRange::FindAttribute(*this); return E_NOTIMPL; } @@ -353,8 +290,6 @@ IFACEMETHODIMP UiaTextRangeBase::FindText(_In_ BSTR text, _Outptr_result_maybenull_ ITextRangeProvider** ppRetVal) noexcept try { - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::FindText, nullptr); RETURN_HR_IF(E_INVALIDARG, ppRetVal == nullptr); *ppRetVal = nullptr; @@ -393,6 +328,8 @@ try UiaTextRangeBase& range = static_cast(**ppRetVal); range._start = start; range._end = end; + + UiaTracing::TextRange::FindText(*this, queryText, searchBackward, ignoreCase, range); } } return S_OK; @@ -404,8 +341,6 @@ IFACEMETHODIMP UiaTextRangeBase::GetAttributeValue(_In_ TEXTATTRIBUTEID textAttr { RETURN_HR_IF(E_INVALIDARG, pRetVal == nullptr); - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::GetAttributeValue, nullptr); if (textAttributeId == UIA_IsReadOnlyAttributeId) { pRetVal->vt = VT_BOOL; @@ -416,6 +351,7 @@ IFACEMETHODIMP UiaTextRangeBase::GetAttributeValue(_In_ TEXTATTRIBUTEID textAttr pRetVal->vt = VT_UNKNOWN; UiaGetReservedNotSupportedValue(&pRetVal->punkVal); } + UiaTracing::TextRange::GetAttributeValue(*this, textAttributeId, *pRetVal); return S_OK; } @@ -516,9 +452,7 @@ IFACEMETHODIMP UiaTextRangeBase::GetBoundingRectangles(_Outptr_result_maybenull_ } CATCH_RETURN(); - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::GetBoundingRectangles, nullptr); - + UiaTracing::TextRange::GetBoundingRectangles(*this); return S_OK; } @@ -528,9 +462,11 @@ try RETURN_HR_IF(E_INVALIDARG, ppRetVal == nullptr); *ppRetVal = nullptr; - //Tracing::s_TraceUia(this, ApiCall::GetBoundingRectangles, nullptr); #pragma warning(suppress : 26447) // QueryInterface's exception should be caught by the try-CATCH_RETURN block to allow this to be noexcept - return _pProvider->QueryInterface(IID_PPV_ARGS(ppRetVal)); + auto hr = _pProvider->QueryInterface(IID_PPV_ARGS(ppRetVal)); + // TODO CARLOS: fix tracing call + //UiaTracing::TextRange::GetEnclosingElement(*this, static_cast(*ppRetVal)); + return hr; } CATCH_RETURN(); @@ -558,12 +494,6 @@ try if (!IsDegenerate()) { -#if defined(_DEBUG) && defined(UIATEXTRANGE_DEBUG_MSGS) - std::wstringstream ss; - ss << L"---Initial span start={" << _start.X << L", " << _start.Y << L"} and end={" << _end.X << ", " << _end.Y << L"}\n"; - OutputDebugString(ss.str().c_str()); -#endif - // if _end is at 0, we ignore that row because _end is exclusive const auto& buffer = _pData->GetTextBuffer(); const short totalRowsInRange = (_end.X == buffer.GetSize().Left()) ? @@ -616,19 +546,7 @@ try } *pRetVal = SysAllocString(wstr.c_str()); - - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - // tracing - /*ApiMsgGetText apiMsg; - apiMsg.Text = wstr.c_str(); - Tracing::s_TraceUia(this, ApiCall::GetText, &apiMsg);*/ - -#if defined(_DEBUG) && defined(UIATEXTRANGE_DEBUG_MSGS) - std::wstringstream ss; - ss << L"--------Retrieved Text Max Length(" << maxLength << L") [" << _id << L"]: " << wstr.c_str() << "\n"; - OutputDebugString(ss.str().c_str()); -#endif - + UiaTracing::TextRange::GetText(*this, maxLength, wstr); return S_OK; } CATCH_RETURN(); @@ -644,23 +562,6 @@ IFACEMETHODIMP UiaTextRangeBase::Move(_In_ TextUnit unit, return S_OK; } - ApiMsgMove apiMsg; - apiMsg.OriginalStart = _start; - apiMsg.OriginalEnd = _end; - apiMsg.Unit = unit; - apiMsg.RequestedCount = count; -#if defined(_DEBUG) && defined(UIATEXTRANGE_DEBUG_MSGS) - OutputDebugString(L"Move\n"); - _outputObjectState(); - - std::wstringstream ss; - ss << L" unit: " << unit; - ss << L" count: " << count; - std::wstring data = ss.str(); - OutputDebugString(data.c_str()); - OutputDebugString(L"\n"); -#endif - _pData->LockConsole(); auto Unlock = wil::scope_exit([&]() noexcept { _pData->UnlockConsole(); @@ -697,11 +598,7 @@ IFACEMETHODIMP UiaTextRangeBase::Move(_In_ TextUnit unit, ExpandToEnclosingUnit(unit); } - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - // tracing - /*apiMsg.MovedCount = *pRetVal; - Tracing::s_TraceUia(this, ApiCall::Move, &apiMsg);*/ - + UiaTracing::TextRange::Move(unit, count, *pRetVal, *this); return S_OK; } @@ -717,24 +614,6 @@ IFACEMETHODIMP UiaTextRangeBase::MoveEndpointByUnit(_In_ TextPatternRangeEndpoin return S_OK; } - ApiMsgMoveEndpointByUnit apiMsg; - apiMsg.OriginalStart = _start; - apiMsg.OriginalEnd = _end; - apiMsg.Endpoint = endpoint; - apiMsg.Unit = unit; - apiMsg.RequestedCount = count; -#if defined(_DEBUG) && defined(UIATEXTRANGE_DEBUG_MSGS) - OutputDebugString(L"MoveEndpointByUnit\n"); - _outputObjectState(); - - std::wstringstream ss; - ss << L" endpoint: " << endpoint; - ss << L" count: " << count; - std::wstring data = ss.str(); - OutputDebugString(data.c_str()); - OutputDebugString(L"\n"); -#endif - _pData->LockConsole(); auto Unlock = wil::scope_exit([&]() noexcept { _pData->UnlockConsole(); @@ -761,11 +640,7 @@ IFACEMETHODIMP UiaTextRangeBase::MoveEndpointByUnit(_In_ TextPatternRangeEndpoin } CATCH_RETURN(); - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - // tracing - /*apiMsg.MovedCount = *pRetVal; - Tracing::s_TraceUia(this, ApiCall::MoveEndpointByUnit, &apiMsg);*/ - + UiaTracing::TextRange::MoveEndpointByUnit(endpoint, unit, count, *pRetVal, *this); return S_OK; } @@ -785,29 +660,9 @@ try return E_INVALIDARG; } - ApiMsgMoveEndpointByRange apiMsg; - apiMsg.OriginalStart = _start; - apiMsg.OriginalEnd = _end; - apiMsg.Endpoint = endpoint; - apiMsg.TargetEndpoint = targetEndpoint; - apiMsg.OtherId = range->GetId(); -#if defined(_DEBUG) && defined(UIATEXTRANGE_DEBUG_MSGS) - OutputDebugString(L"MoveEndpointByRange\n"); - _outputObjectState(); - - std::wstringstream ss; - ss << L" endpoint: " << endpoint; - ss << L" targetRange: " << range->_id; - ss << L" targetEndpoint: " << targetEndpoint; - std::wstring data = ss.str(); - OutputDebugString(data.c_str()); - OutputDebugString(L"\n"); -#endif - SetEndpoint(endpoint, range->GetEndpoint(targetEndpoint)); - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::MoveEndpointByRange, &apiMsg); + UiaTracing::TextRange::MoveEndpointByRange(endpoint, *range, targetEndpoint, *this); return S_OK; } CATCH_RETURN(); @@ -832,8 +687,7 @@ try _pData->SelectNewRegion(_start, temp); } - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::Select, nullptr); + UiaTracing::TextRange::Select(*this); return S_OK; } CATCH_RETURN(); @@ -841,16 +695,14 @@ CATCH_RETURN(); // we don't support this IFACEMETHODIMP UiaTextRangeBase::AddToSelection() noexcept { - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::AddToSelection, nullptr); + UiaTracing::TextRange::AddToSelection(*this); return E_NOTIMPL; } // we don't support this IFACEMETHODIMP UiaTextRangeBase::RemoveFromSelection() noexcept { - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //Tracing::s_TraceUia(this, ApiCall::RemoveFromSelection, nullptr); + UiaTracing::TextRange::RemoveFromSelection(*this); return E_NOTIMPL; } @@ -917,12 +769,7 @@ try _ChangeViewport(newViewport); - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - // tracing - /*ApiMsgScrollIntoView apiMsg; - apiMsg.AlignToTop = !!alignToTop; - Tracing::s_TraceUia(this, ApiCall::ScrollIntoView, &apiMsg);*/ - + UiaTracing::TextRange::ScrollIntoView(alignToTop, *this); return S_OK; } CATCH_RETURN(); @@ -940,6 +787,7 @@ IFACEMETHODIMP UiaTextRangeBase::GetChildren(_Outptr_result_maybenull_ SAFEARRAY { return E_OUTOFMEMORY; } + UiaTracing::TextRange::GetChildren(*this); return S_OK; } @@ -1330,3 +1178,36 @@ RECT UiaTextRangeBase::_getTerminalRect() const gsl::narrow(result.top + result.height) }; } + +std::wstring UiaTextRangeBase::_getTextValue() const noexcept +{ + _pData->LockConsole(); + auto Unlock = wil::scope_exit([&]() noexcept { + _pData->UnlockConsole(); + }); + + if (IsDegenerate()) + { + return {}; + } + + try + { + std::wstringstream stream; + const auto& buffer = _pData->GetTextBuffer(); + const auto bufferSize = buffer.GetSize(); + + auto pos = _start; + while (bufferSize.CompareInBounds(pos, _end, true) != 0) + { + stream << buffer.GetTextDataAt(pos)->data(); + bufferSize.IncrementInBounds(pos, true); + } + + return stream.str(); + } + catch (...) + { + return {}; + } +} diff --git a/src/types/UiaTextRangeBase.hpp b/src/types/UiaTextRangeBase.hpp index 389807b0d31..be93536b548 100644 --- a/src/types/UiaTextRangeBase.hpp +++ b/src/types/UiaTextRangeBase.hpp @@ -33,15 +33,12 @@ class UiaTextRangeTests; #endif typedef unsigned long long IdType; - -// A Column is a row agnostic value that refers to the column an -// endpoint is equivalent to. It is 0-indexed. -typedef unsigned int Column; - constexpr IdType InvalidId = 0; namespace Microsoft::Console::Types { + class UiaTracing; + class UiaTextRangeBase : public WRL::RuntimeClass, ITextRangeProvider> { private: @@ -130,9 +127,6 @@ namespace Microsoft::Console::Types protected: UiaTextRangeBase() = default; -#if _DEBUG - void _outputObjectState(); -#endif IUiaData* _pData; IRawElementProviderSimple* _pProvider; @@ -155,6 +149,11 @@ namespace Microsoft::Console::Types COORD _start; COORD _end; + // This is used by tracing to extract the text value + // that the UiaTextRange currently encompasses. + // GetText() cannot be used as it's not const + std::wstring _getTextValue() const noexcept; + RECT _getTerminalRect() const; virtual const COORD _getScreenFontSize() const; @@ -189,104 +188,6 @@ namespace Microsoft::Console::Types #ifdef UNIT_TESTING friend class ::UiaTextRangeTests; #endif + friend class UiaTracing; }; - - namespace UiaTextRangeBaseTracing - { - enum class ApiCall - { - Constructor, - Clone, - Compare, - CompareEndpoints, - ExpandToEnclosingUnit, - FindAttribute, - FindText, - GetAttributeValue, - GetBoundingRectangles, - GetEnclosingElement, - GetText, - Move, - MoveEndpointByUnit, - MoveEndpointByRange, - Select, - AddToSelection, - RemoveFromSelection, - ScrollIntoView, - GetChildren - }; - - struct IApiMsg - { - }; - - struct ApiMsgConstructor : public IApiMsg - { - IdType Id; - }; - - struct ApiMsgClone : public IApiMsg - { - IdType CloneId; - }; - - struct ApiMsgCompare : public IApiMsg - { - IdType OtherId; - bool Equal; - }; - - struct ApiMsgCompareEndpoints : public IApiMsg - { - IdType OtherId; - TextPatternRangeEndpoint Endpoint; - TextPatternRangeEndpoint TargetEndpoint; - int Result; - }; - - struct ApiMsgExpandToEnclosingUnit : public IApiMsg - { - TextUnit Unit; - COORD OriginalStart; - COORD OriginalEnd; - }; - - struct ApiMsgGetText : IApiMsg - { - const wchar_t* Text; - }; - - struct ApiMsgMove : IApiMsg - { - COORD OriginalStart; - COORD OriginalEnd; - TextUnit Unit; - int RequestedCount; - int MovedCount; - }; - - struct ApiMsgMoveEndpointByUnit : IApiMsg - { - COORD OriginalStart; - COORD OriginalEnd; - TextPatternRangeEndpoint Endpoint; - TextUnit Unit; - int RequestedCount; - int MovedCount; - }; - - struct ApiMsgMoveEndpointByRange : IApiMsg - { - COORD OriginalStart; - COORD OriginalEnd; - TextPatternRangeEndpoint Endpoint; - TextPatternRangeEndpoint TargetEndpoint; - IdType OtherId; - }; - - struct ApiMsgScrollIntoView : IApiMsg - { - bool AlignToTop; - }; - } } diff --git a/src/types/UiaTracing.cpp b/src/types/UiaTracing.cpp new file mode 100644 index 00000000000..e7bd806ff32 --- /dev/null +++ b/src/types/UiaTracing.cpp @@ -0,0 +1,509 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#include "precomp.h" +#include "UiaTracing.h" + +TRACELOGGING_DEFINE_PROVIDER(g_UiaProviderTraceProvider, + "Microsoft.Windows.Console.UIA", + // tl:{e7ebce59-2161-572d-b263-2f16a6afb9e5} + (0xe7ebce59, 0x2161, 0x572d, 0xb2, 0x63, 0x2f, 0x16, 0xa6, 0xaf, 0xb9, 0xe5)); + +using namespace Microsoft::Console::Types; + +UiaTracing::UiaTracing() noexcept +{ + TraceLoggingRegister(g_UiaProviderTraceProvider); +} + +UiaTracing::~UiaTracing() noexcept +{ + TraceLoggingUnregister(g_UiaProviderTraceProvider); +} + +std::wstring UiaTracing::_getValue(const ScreenInfoUiaProviderBase& /*siup*/) +{ + std::wstringstream stream; + stream << " NO IDENTIFYING DATA"; + return stream.str(); +} + +std::wstring UiaTracing::_getValue(const UiaTextRangeBase& utr) +{ + const auto start = utr.GetEndpoint(TextPatternRangeEndpoint_Start); + const auto end = utr.GetEndpoint(TextPatternRangeEndpoint_End); + + std::wstringstream stream; + stream << " _id: " << utr.GetId(); + stream << " _start: { " << start.X << ", " << start.Y << " }"; + stream << " _end: { " << end.X << ", " << end.Y << " }"; + stream << " _degenerate: " << utr.IsDegenerate(); + stream << " _wordDelimiters: " << utr._wordDelimiters; + stream << " content: " << utr._getTextValue(); + return stream.str(); +} + +std::wstring UiaTracing::_getValue(const TextPatternRangeEndpoint endpoint) +{ + switch (endpoint) + { + case TextPatternRangeEndpoint_Start: + return L"Start"; + case TextPatternRangeEndpoint_End: + return L"End"; + default: + return L"UNKNOWN VALUE"; + } +} + +std::wstring UiaTracing::_getValue(const TextUnit unit) +{ + switch (unit) + { + case TextUnit_Character: + return L"Character"; + case TextUnit_Format: + return L"Format"; + case TextUnit_Word: + return L"Word"; + case TextUnit_Line: + return L"Line"; + case TextUnit_Paragraph: + return L"Paragraph"; + case TextUnit_Page: + return L"Page"; + case TextUnit_Document: + return L"Document"; + default: + return L"UNKNOWN VALUE"; + } +} + +void UiaTracing::TextRange::Constructor(const UiaTextRangeBase& result) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::Constructor", + TraceLoggingValue(_getValue(result).c_str(), "UiaTextRange"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::Clone(const UiaTextRangeBase& utr, const UiaTextRangeBase& result) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::Clone", + TraceLoggingValue(_getValue(utr).c_str(), "base"), + TraceLoggingValue(_getValue(result).c_str(), "clone"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::Compare(const UiaTextRangeBase& utr, const UiaTextRangeBase& other, bool result) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::Compare", + TraceLoggingValue(_getValue(utr).c_str(), "base"), + TraceLoggingValue(_getValue(other).c_str(), "other"), + TraceLoggingValue(result, "result"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::CompareEndpoints(const UiaTextRangeBase& utr, const TextPatternRangeEndpoint endpoint, const UiaTextRangeBase& other, TextPatternRangeEndpoint otherEndpoint, int result) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::CompareEndpoints", + TraceLoggingValue(_getValue(utr).c_str(), "base"), + TraceLoggingValue(_getValue(endpoint).c_str(), "baseEndpoint"), + TraceLoggingValue(_getValue(other).c_str(), "other"), + TraceLoggingValue(_getValue(otherEndpoint).c_str(), "otherEndpoint"), + TraceLoggingValue(result, "result"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::ExpandToEnclosingUnit(TextUnit unit, const UiaTextRangeBase& utr) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::ExpandToEnclosingUnit", + TraceLoggingValue(_getValue(unit).c_str(), "textUnit"), + TraceLoggingValue(_getValue(utr).c_str(), "result"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::FindAttribute(const UiaTextRangeBase& utr) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::FindAttribute (UNSUPPORTED)", + TraceLoggingValue(_getValue(utr).c_str(), "base"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::FindText(const UiaTextRangeBase& base, std::wstring text, bool searchBackward, bool ignoreCase, const UiaTextRangeBase& result) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::FindText", + TraceLoggingValue(_getValue(base).c_str(), "base"), + TraceLoggingValue(text.c_str(), "text"), + TraceLoggingValue(searchBackward, "searchBackward"), + TraceLoggingValue(ignoreCase, "ignoreCase"), + TraceLoggingValue(_getValue(result).c_str(), "result"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::GetAttributeValue(const UiaTextRangeBase& base, TEXTATTRIBUTEID id, VARIANT result) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::GetAttributeValue", + TraceLoggingValue(_getValue(base).c_str(), "base"), + TraceLoggingValue(id, "textAttributeId"), + TraceLoggingValue(result.vt, "result (type)"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::GetBoundingRectangles(const UiaTextRangeBase& utr) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::GetBoundingRectangles", + TraceLoggingValue(_getValue(utr).c_str(), "base"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::GetEnclosingElement(const UiaTextRangeBase& utr, const ScreenInfoUiaProviderBase& siup) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::GetEnclosingElement", + TraceLoggingValue(_getValue(utr).c_str(), "base"), + TraceLoggingValue(_getValue(siup).c_str(), "parent"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::GetText(const UiaTextRangeBase& utr, int maxLength, std::wstring result) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::GetText", + TraceLoggingValue(_getValue(utr).c_str(), "base"), + TraceLoggingValue(maxLength, "maxLength"), + TraceLoggingValue(result.c_str(), "result"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::Move(TextUnit unit, int count, int resultCount, const UiaTextRangeBase& result) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::Move", + TraceLoggingValue(_getValue(unit).c_str(), "textUnit"), + TraceLoggingValue(count, "count"), + TraceLoggingValue(resultCount, "resultCount"), + TraceLoggingValue(_getValue(result).c_str(), "result"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::MoveEndpointByUnit(TextPatternRangeEndpoint endpoint, TextUnit unit, int count, int resultCount, const UiaTextRangeBase& result) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::MoveEndpointByUnit", + TraceLoggingValue(_getValue(endpoint).c_str(), "endpoint"), + TraceLoggingValue(_getValue(unit).c_str(), "textUnit"), + TraceLoggingValue(count, "count"), + TraceLoggingValue(resultCount, "resultCount"), + TraceLoggingValue(_getValue(result).c_str(), "result"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::MoveEndpointByRange(TextPatternRangeEndpoint endpoint, const UiaTextRangeBase& other, TextPatternRangeEndpoint otherEndpoint, const UiaTextRangeBase& result) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::MoveEndpointByRange", + TraceLoggingValue(_getValue(endpoint).c_str(), "endpoint"), + TraceLoggingValue(_getValue(other).c_str(), "other"), + TraceLoggingValue(_getValue(otherEndpoint).c_str(), "otherEndpoint"), + TraceLoggingValue(_getValue(result).c_str(), "result"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::Select(const UiaTextRangeBase& result) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::Select", + TraceLoggingValue(_getValue(result).c_str(), "base"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::AddToSelection(const UiaTextRangeBase& result) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::AddToSelection (UNSUPPORTED)", + TraceLoggingValue(_getValue(result).c_str(), "base"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::RemoveFromSelection(const UiaTextRangeBase& result) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::RemoveFromSelection (UNSUPPORTED)", + TraceLoggingValue(_getValue(result).c_str(), "base"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} +void UiaTracing::TextRange::ScrollIntoView(bool alignToTop, const UiaTextRangeBase& result) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::ScrollIntoView", + TraceLoggingValue(alignToTop, "alignToTop"), + TraceLoggingValue(_getValue(result).c_str(), "result"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::GetChildren(const UiaTextRangeBase& result) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::AddToSelection (UNSUPPORTED)", + TraceLoggingValue(_getValue(result).c_str(), "base"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextProvider::Constructor(const ScreenInfoUiaProviderBase& result) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "ScreenInfoUiaProvider::Constructor", + TraceLoggingValue(_getValue(result).c_str(), "ScreenInfoUiaProvider"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextProvider::get_ProviderOptions(const ScreenInfoUiaProviderBase& siup, ProviderOptions options) +{ + auto getOptions = [options]() { + switch (options) + { + case ProviderOptions_ServerSideProvider: + return L"ServerSideProvider"; + default: + return L"UNKNOWN VALUE"; + } + }; + + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "ScreenInfoUiaProvider::get_ProviderOptions", + TraceLoggingValue(_getValue(siup).c_str(), "base"), + TraceLoggingValue(getOptions(), "providerOptions"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextProvider::GetPatternProvider(const ScreenInfoUiaProviderBase& siup, PATTERNID patternId) +{ + auto getPattern = [patternId]() { + switch (patternId) + { + case UIA_TextPatternId: + return L"TextPattern"; + default: + return L"UNKNOWN VALUE"; + } + }; + + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "ScreenInfoUiaProvider::get_ProviderOptions", + TraceLoggingValue(_getValue(siup).c_str(), "base"), + TraceLoggingValue(getPattern(), "patternId"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextProvider::GetPropertyValue(const ScreenInfoUiaProviderBase& siup, PROPERTYID propertyId) +{ + auto getProperty = [propertyId]() { + switch (propertyId) + { + case UIA_ControlTypePropertyId: + return L"ControlTypePropertyId"; + case UIA_NamePropertyId: + return L"NamePropertyId"; + case UIA_AutomationIdPropertyId: + return L"AutomationIdPropertyId"; + case UIA_IsControlElementPropertyId: + return L"IsControlElementPropertyId"; + case UIA_IsContentElementPropertyId: + return L"IsContentElementPropertyId"; + case UIA_IsKeyboardFocusablePropertyId: + return L"IsKeyboardFocusablePropertyId"; + case UIA_HasKeyboardFocusPropertyId: + return L"HasKeyboardFocusPropertyId"; + case UIA_ProviderDescriptionPropertyId: + return L"ProviderDescriptionPropertyId"; + case UIA_IsEnabledPropertyId: + return L"IsEnabledPropertyId"; + default: + return L"UNKNOWN VALUE"; + } + }; + + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "ScreenInfoUiaProvider::GetPropertyValue", + TraceLoggingValue(_getValue(siup).c_str(), "base"), + TraceLoggingValue(getProperty(), "propertyId"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextProvider::get_HostRawElementProvider(const ScreenInfoUiaProviderBase& siup) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "ScreenInfoUiaProvider::get_HostRawElementProvider (UNSUPPORTED)", + TraceLoggingValue(_getValue(siup).c_str(), "base"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextProvider::GetRuntimeId(const ScreenInfoUiaProviderBase& siup) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "ScreenInfoUiaProvider::GetRuntimeId", + TraceLoggingValue(_getValue(siup).c_str(), "base"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextProvider::GetEmbeddedFragmentRoots(const ScreenInfoUiaProviderBase& siup) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "ScreenInfoUiaProvider::GetEmbeddedFragmentRoots (UNSUPPORTED)", + TraceLoggingValue(_getValue(siup).c_str(), "base"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextProvider::SetFocus(const ScreenInfoUiaProviderBase& siup) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "ScreenInfoUiaProvider::SetFocus", + TraceLoggingValue(_getValue(siup).c_str(), "base"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextProvider::GetSelection(const ScreenInfoUiaProviderBase& siup) +{ + // TODO GH #4466: there's currently a PR out for this. Once that gets fixed, I'll update this appropriately + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "ScreenInfoUiaProvider::GetSelection", + TraceLoggingValue(_getValue(siup).c_str(), "base"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextProvider::GetVisibleRanges(const ScreenInfoUiaProviderBase& siup, const UiaTextRangeBase& result) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "ScreenInfoUiaProvider::GetVisibleRanges", + TraceLoggingValue(_getValue(siup).c_str(), "base"), + TraceLoggingValue(_getValue(result).c_str(), "result (utr)"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextProvider::RangeFromChild(const ScreenInfoUiaProviderBase& siup, const UiaTextRangeBase& result) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "ScreenInfoUiaProvider::GetVisibleRanges", + TraceLoggingValue(_getValue(siup).c_str(), "base"), + TraceLoggingValue(_getValue(result).c_str(), "result (utr)"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextProvider::RangeFromPoint(const ScreenInfoUiaProviderBase& siup, UiaPoint point, const UiaTextRangeBase& result) +{ + auto getPoint = [point]() { + std::wstringstream stream; + stream << "{ " << point.x << ", " << point.y << " }"; + return stream.str(); + }; + + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "ScreenInfoUiaProvider::RangeFromPoint", + TraceLoggingValue(_getValue(siup).c_str(), "base"), + TraceLoggingValue(getPoint().c_str(), "uiaPoint"), + TraceLoggingValue(_getValue(result).c_str(), "result (utr)"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextProvider::get_DocumentRange(const ScreenInfoUiaProviderBase& siup, const UiaTextRangeBase& result) +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "ScreenInfoUiaProvider::GetVisibleRanges", + TraceLoggingValue(_getValue(siup).c_str(), "base"), + TraceLoggingValue(_getValue(result).c_str(), "result (utr)"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextProvider::get_SupportedTextSelection(const ScreenInfoUiaProviderBase& siup, SupportedTextSelection result) +{ + auto getResult = [result]() { + switch (result) + { + case SupportedTextSelection_Single: + return L"Single"; + default: + return L"UNKNOWN VALUE"; + } + }; + + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "ScreenInfoUiaProvider::get_SupportedTextSelection", + TraceLoggingValue(_getValue(siup).c_str(), "base"), + TraceLoggingValue(getResult(), "result"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} diff --git a/src/types/UiaTracing.h b/src/types/UiaTracing.h new file mode 100644 index 00000000000..e6f853a26d7 --- /dev/null +++ b/src/types/UiaTracing.h @@ -0,0 +1,96 @@ +/*++ +Copyright (c) Microsoft Corporation +Licensed under the MIT license. + +Module Name: +- UiaTracing.hpp + +Abstract: +- This module is used for recording tracing/debugging information to the telemetry ETW channel +- The data is not automatically broadcast to telemetry backends as it does not set the TELEMETRY keyword. +- NOTE: Many functions in this file appear to be copy/pastes. This is because the TraceLog documentation warns + to not be "cute" in trying to reduce its macro usages with variables as it can cause unexpected behavior. + +Author(s): +- Carlos Zamora (cazamor) Feb 2020 +--*/ + +#pragma once + +#include +#include +#include "UiaTextRangeBase.hpp" +#include "ScreenInfoUiaProviderBase.h" + +TRACELOGGING_DECLARE_PROVIDER(g_UiaProviderTraceProvider); + +namespace Microsoft::Console::Types +{ + class UiaTracing final + { + public: + class TextRange final + { + public: + static void Constructor(const UiaTextRangeBase& result); + static void Clone(const UiaTextRangeBase& base, const UiaTextRangeBase& result); + static void Compare(const UiaTextRangeBase& base, const UiaTextRangeBase& other, bool result); + static void CompareEndpoints(const UiaTextRangeBase& base, const TextPatternRangeEndpoint endpoint, const UiaTextRangeBase& other, TextPatternRangeEndpoint otherEndpoint, int result); + static void ExpandToEnclosingUnit(TextUnit unit, const UiaTextRangeBase& result); + static void FindAttribute(const UiaTextRangeBase& base); + static void FindText(const UiaTextRangeBase& base, std::wstring text, bool searchBackward, bool ignoreCase, const UiaTextRangeBase& result); + static void GetAttributeValue(const UiaTextRangeBase& base, TEXTATTRIBUTEID id, VARIANT result); + static void GetBoundingRectangles(const UiaTextRangeBase& base); + static void GetEnclosingElement(const UiaTextRangeBase& base, const ScreenInfoUiaProviderBase& siup); + static void GetText(const UiaTextRangeBase& base, int maxLength, std::wstring result); + static void Move(TextUnit unit, int count, int resultCount, const UiaTextRangeBase& result); + static void MoveEndpointByUnit(TextPatternRangeEndpoint endpoint, TextUnit unit, int count, int resultCount, const UiaTextRangeBase& result); + static void MoveEndpointByRange(TextPatternRangeEndpoint endpoint, const UiaTextRangeBase& other, TextPatternRangeEndpoint otherEndpoint, const UiaTextRangeBase& result); + static void Select(const UiaTextRangeBase& base); + static void AddToSelection(const UiaTextRangeBase& base); + static void RemoveFromSelection(const UiaTextRangeBase& base); + static void ScrollIntoView(bool alignToTop, const UiaTextRangeBase& result); + static void GetChildren(const UiaTextRangeBase& base); + }; + + class TextProvider final + { + public: + static void Constructor(const ScreenInfoUiaProviderBase& result); + static void get_ProviderOptions(const ScreenInfoUiaProviderBase& base, ProviderOptions options); + static void GetPatternProvider(const ScreenInfoUiaProviderBase& base, PATTERNID patternId); + static void GetPropertyValue(const ScreenInfoUiaProviderBase& base, PROPERTYID propertyId); + static void get_HostRawElementProvider(const ScreenInfoUiaProviderBase& base); + static void GetRuntimeId(const ScreenInfoUiaProviderBase& base); + static void GetEmbeddedFragmentRoots(const ScreenInfoUiaProviderBase& base); + static void SetFocus(const ScreenInfoUiaProviderBase& base); + static void GetSelection(const ScreenInfoUiaProviderBase& base); + static void GetVisibleRanges(const ScreenInfoUiaProviderBase& base, const UiaTextRangeBase& result); + static void RangeFromChild(const ScreenInfoUiaProviderBase& base, const UiaTextRangeBase& result); + static void RangeFromPoint(const ScreenInfoUiaProviderBase& base, UiaPoint point, const UiaTextRangeBase& result); + static void get_DocumentRange(const ScreenInfoUiaProviderBase& base, const UiaTextRangeBase& result); + static void get_SupportedTextSelection(const ScreenInfoUiaProviderBase& base, SupportedTextSelection result); + }; + + private: + // Implement this as a singleton class. + static UiaTracing& EnsureRegistration() noexcept + { + static UiaTracing instance; + return instance; + } + + // Used to prevent multiple instances + UiaTracing() noexcept; + ~UiaTracing() noexcept; + UiaTracing(UiaTracing const&) = delete; + UiaTracing(UiaTracing&&) = delete; + 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); + }; +} diff --git a/src/types/lib/types.vcxproj b/src/types/lib/types.vcxproj index 0be89f36654..53c04a49c8b 100644 --- a/src/types/lib/types.vcxproj +++ b/src/types/lib/types.vcxproj @@ -23,6 +23,7 @@ + @@ -50,6 +51,7 @@ + diff --git a/src/types/lib/types.vcxproj.filters b/src/types/lib/types.vcxproj.filters index eacc3b11b73..6c45b62a65a 100644 --- a/src/types/lib/types.vcxproj.filters +++ b/src/types/lib/types.vcxproj.filters @@ -72,6 +72,9 @@ Source Files + + Source Files + @@ -155,8 +158,11 @@ Header Files + + Header Files + - + \ No newline at end of file From c4a2ac03322a2b57bd047734d523b371949c5697 Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Thu, 6 Feb 2020 15:11:43 -0800 Subject: [PATCH 02/10] abs fix --- src/types/UiaTextRangeBase.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/types/UiaTextRangeBase.cpp b/src/types/UiaTextRangeBase.cpp index 96c7caf280e..354c2306beb 100644 --- a/src/types/UiaTextRangeBase.cpp +++ b/src/types/UiaTextRangeBase.cpp @@ -901,7 +901,7 @@ void UiaTextRangeBase::_moveEndpointByUnitCharacter(_In_ const int moveCount, bool success = true; auto target = GetEndpoint(endpoint); - while (abs(*pAmountMoved) < abs(moveCount) && success) + while (std::abs(*pAmountMoved) < std::abs(moveCount) && success) { switch (moveDirection) { @@ -1043,7 +1043,7 @@ void UiaTextRangeBase::_moveEndpointByUnitLine(_In_ const int moveCount, bool success = true; auto resultPos = GetEndpoint(endpoint); - while (abs(*pAmountMoved) < abs(moveCount) && success) + while (std::abs(*pAmountMoved) < std::abs(moveCount) && success) { auto nextPos = resultPos; switch (moveDirection) @@ -1198,7 +1198,7 @@ std::wstring UiaTextRangeBase::_getTextValue() const noexcept const auto bufferSize = buffer.GetSize(); auto pos = _start; - while (bufferSize.CompareInBounds(pos, _end, true) != 0) + while (std::abs(bufferSize.CompareInBounds(pos, _end, true)) > 0) { stream << buffer.GetTextDataAt(pos)->data(); bufferSize.IncrementInBounds(pos, true); From 8a7998433987950940338d3507f7e6ec2e18663e Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Thu, 6 Feb 2020 16:08:09 -0800 Subject: [PATCH 03/10] static analysis fix --- src/types/UiaTracing.cpp | 66 ++++++++++++++++++++-------------------- src/types/UiaTracing.h | 66 ++++++++++++++++++++-------------------- 2 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/types/UiaTracing.cpp b/src/types/UiaTracing.cpp index e7bd806ff32..081fda84d80 100644 --- a/src/types/UiaTracing.cpp +++ b/src/types/UiaTracing.cpp @@ -79,7 +79,7 @@ std::wstring UiaTracing::_getValue(const TextUnit unit) } } -void UiaTracing::TextRange::Constructor(const UiaTextRangeBase& result) +void UiaTracing::TextRange::Constructor(const UiaTextRangeBase& result) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -89,7 +89,7 @@ void UiaTracing::TextRange::Constructor(const UiaTextRangeBase& result) TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextRange::Clone(const UiaTextRangeBase& utr, const UiaTextRangeBase& result) +void UiaTracing::TextRange::Clone(const UiaTextRangeBase& utr, const UiaTextRangeBase& result) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -100,7 +100,7 @@ void UiaTracing::TextRange::Clone(const UiaTextRangeBase& utr, const UiaTextRang TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextRange::Compare(const UiaTextRangeBase& utr, const UiaTextRangeBase& other, bool result) +void UiaTracing::TextRange::Compare(const UiaTextRangeBase& utr, const UiaTextRangeBase& other, bool result) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -112,7 +112,7 @@ void UiaTracing::TextRange::Compare(const UiaTextRangeBase& utr, const UiaTextRa TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextRange::CompareEndpoints(const UiaTextRangeBase& utr, const TextPatternRangeEndpoint endpoint, const UiaTextRangeBase& other, TextPatternRangeEndpoint otherEndpoint, int result) +void UiaTracing::TextRange::CompareEndpoints(const UiaTextRangeBase& utr, const TextPatternRangeEndpoint endpoint, const UiaTextRangeBase& other, TextPatternRangeEndpoint otherEndpoint, int result) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -126,7 +126,7 @@ void UiaTracing::TextRange::CompareEndpoints(const UiaTextRangeBase& utr, const TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextRange::ExpandToEnclosingUnit(TextUnit unit, const UiaTextRangeBase& utr) +void UiaTracing::TextRange::ExpandToEnclosingUnit(TextUnit unit, const UiaTextRangeBase& utr) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -137,7 +137,7 @@ void UiaTracing::TextRange::ExpandToEnclosingUnit(TextUnit unit, const UiaTextRa TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextRange::FindAttribute(const UiaTextRangeBase& utr) +void UiaTracing::TextRange::FindAttribute(const UiaTextRangeBase& utr) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -147,7 +147,7 @@ void UiaTracing::TextRange::FindAttribute(const UiaTextRangeBase& utr) TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextRange::FindText(const UiaTextRangeBase& base, std::wstring text, bool searchBackward, bool ignoreCase, const UiaTextRangeBase& result) +void UiaTracing::TextRange::FindText(const UiaTextRangeBase& base, std::wstring text, bool searchBackward, bool ignoreCase, const UiaTextRangeBase& result) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -161,7 +161,7 @@ void UiaTracing::TextRange::FindText(const UiaTextRangeBase& base, std::wstring TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextRange::GetAttributeValue(const UiaTextRangeBase& base, TEXTATTRIBUTEID id, VARIANT result) +void UiaTracing::TextRange::GetAttributeValue(const UiaTextRangeBase& base, TEXTATTRIBUTEID id, VARIANT result) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -173,7 +173,7 @@ void UiaTracing::TextRange::GetAttributeValue(const UiaTextRangeBase& base, TEXT TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextRange::GetBoundingRectangles(const UiaTextRangeBase& utr) +void UiaTracing::TextRange::GetBoundingRectangles(const UiaTextRangeBase& utr) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -183,7 +183,7 @@ void UiaTracing::TextRange::GetBoundingRectangles(const UiaTextRangeBase& utr) TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextRange::GetEnclosingElement(const UiaTextRangeBase& utr, const ScreenInfoUiaProviderBase& siup) +void UiaTracing::TextRange::GetEnclosingElement(const UiaTextRangeBase& utr, const ScreenInfoUiaProviderBase& siup) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -194,7 +194,7 @@ void UiaTracing::TextRange::GetEnclosingElement(const UiaTextRangeBase& utr, con TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextRange::GetText(const UiaTextRangeBase& utr, int maxLength, std::wstring result) +void UiaTracing::TextRange::GetText(const UiaTextRangeBase& utr, int maxLength, std::wstring result) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -206,7 +206,7 @@ void UiaTracing::TextRange::GetText(const UiaTextRangeBase& utr, int maxLength, TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextRange::Move(TextUnit unit, int count, int resultCount, const UiaTextRangeBase& result) +void UiaTracing::TextRange::Move(TextUnit unit, int count, int resultCount, const UiaTextRangeBase& result) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -219,7 +219,7 @@ void UiaTracing::TextRange::Move(TextUnit unit, int count, int resultCount, cons TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextRange::MoveEndpointByUnit(TextPatternRangeEndpoint endpoint, TextUnit unit, int count, int resultCount, const UiaTextRangeBase& result) +void UiaTracing::TextRange::MoveEndpointByUnit(TextPatternRangeEndpoint endpoint, TextUnit unit, int count, int resultCount, const UiaTextRangeBase& result) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -233,7 +233,7 @@ void UiaTracing::TextRange::MoveEndpointByUnit(TextPatternRangeEndpoint endpoint TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextRange::MoveEndpointByRange(TextPatternRangeEndpoint endpoint, const UiaTextRangeBase& other, TextPatternRangeEndpoint otherEndpoint, const UiaTextRangeBase& result) +void UiaTracing::TextRange::MoveEndpointByRange(TextPatternRangeEndpoint endpoint, const UiaTextRangeBase& other, TextPatternRangeEndpoint otherEndpoint, const UiaTextRangeBase& result) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -246,7 +246,7 @@ void UiaTracing::TextRange::MoveEndpointByRange(TextPatternRangeEndpoint endpoin TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextRange::Select(const UiaTextRangeBase& result) +void UiaTracing::TextRange::Select(const UiaTextRangeBase& result) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -256,7 +256,7 @@ void UiaTracing::TextRange::Select(const UiaTextRangeBase& result) TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextRange::AddToSelection(const UiaTextRangeBase& result) +void UiaTracing::TextRange::AddToSelection(const UiaTextRangeBase& result) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -266,7 +266,7 @@ void UiaTracing::TextRange::AddToSelection(const UiaTextRangeBase& result) TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextRange::RemoveFromSelection(const UiaTextRangeBase& result) +void UiaTracing::TextRange::RemoveFromSelection(const UiaTextRangeBase& result) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -275,7 +275,7 @@ void UiaTracing::TextRange::RemoveFromSelection(const UiaTextRangeBase& result) TraceLoggingValue(_getValue(result).c_str(), "base"), TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextRange::ScrollIntoView(bool alignToTop, const UiaTextRangeBase& result) +void UiaTracing::TextRange::ScrollIntoView(bool alignToTop, const UiaTextRangeBase& result) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -286,7 +286,7 @@ void UiaTracing::TextRange::ScrollIntoView(bool alignToTop, const UiaTextRangeBa TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextRange::GetChildren(const UiaTextRangeBase& result) +void UiaTracing::TextRange::GetChildren(const UiaTextRangeBase& result) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -296,7 +296,7 @@ void UiaTracing::TextRange::GetChildren(const UiaTextRangeBase& result) TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextProvider::Constructor(const ScreenInfoUiaProviderBase& result) +void UiaTracing::TextProvider::Constructor(const ScreenInfoUiaProviderBase& result) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -306,7 +306,7 @@ void UiaTracing::TextProvider::Constructor(const ScreenInfoUiaProviderBase& resu TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextProvider::get_ProviderOptions(const ScreenInfoUiaProviderBase& siup, ProviderOptions options) +void UiaTracing::TextProvider::get_ProviderOptions(const ScreenInfoUiaProviderBase& siup, ProviderOptions options) noexcept { auto getOptions = [options]() { switch (options) @@ -327,7 +327,7 @@ void UiaTracing::TextProvider::get_ProviderOptions(const ScreenInfoUiaProviderBa TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextProvider::GetPatternProvider(const ScreenInfoUiaProviderBase& siup, PATTERNID patternId) +void UiaTracing::TextProvider::GetPatternProvider(const ScreenInfoUiaProviderBase& siup, PATTERNID patternId) noexcept { auto getPattern = [patternId]() { switch (patternId) @@ -348,7 +348,7 @@ void UiaTracing::TextProvider::GetPatternProvider(const ScreenInfoUiaProviderBas TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextProvider::GetPropertyValue(const ScreenInfoUiaProviderBase& siup, PROPERTYID propertyId) +void UiaTracing::TextProvider::GetPropertyValue(const ScreenInfoUiaProviderBase& siup, PROPERTYID propertyId) noexcept { auto getProperty = [propertyId]() { switch (propertyId) @@ -385,7 +385,7 @@ void UiaTracing::TextProvider::GetPropertyValue(const ScreenInfoUiaProviderBase& TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextProvider::get_HostRawElementProvider(const ScreenInfoUiaProviderBase& siup) +void UiaTracing::TextProvider::get_HostRawElementProvider(const ScreenInfoUiaProviderBase& siup) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -395,7 +395,7 @@ void UiaTracing::TextProvider::get_HostRawElementProvider(const ScreenInfoUiaPro TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextProvider::GetRuntimeId(const ScreenInfoUiaProviderBase& siup) +void UiaTracing::TextProvider::GetRuntimeId(const ScreenInfoUiaProviderBase& siup) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -405,7 +405,7 @@ void UiaTracing::TextProvider::GetRuntimeId(const ScreenInfoUiaProviderBase& siu TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextProvider::GetEmbeddedFragmentRoots(const ScreenInfoUiaProviderBase& siup) +void UiaTracing::TextProvider::GetEmbeddedFragmentRoots(const ScreenInfoUiaProviderBase& siup) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -415,7 +415,7 @@ void UiaTracing::TextProvider::GetEmbeddedFragmentRoots(const ScreenInfoUiaProvi TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextProvider::SetFocus(const ScreenInfoUiaProviderBase& siup) +void UiaTracing::TextProvider::SetFocus(const ScreenInfoUiaProviderBase& siup) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -425,7 +425,7 @@ void UiaTracing::TextProvider::SetFocus(const ScreenInfoUiaProviderBase& siup) TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextProvider::GetSelection(const ScreenInfoUiaProviderBase& siup) +void UiaTracing::TextProvider::GetSelection(const ScreenInfoUiaProviderBase& siup) noexcept { // TODO GH #4466: there's currently a PR out for this. Once that gets fixed, I'll update this appropriately EnsureRegistration(); @@ -436,7 +436,7 @@ void UiaTracing::TextProvider::GetSelection(const ScreenInfoUiaProviderBase& siu TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextProvider::GetVisibleRanges(const ScreenInfoUiaProviderBase& siup, const UiaTextRangeBase& result) +void UiaTracing::TextProvider::GetVisibleRanges(const ScreenInfoUiaProviderBase& siup, const UiaTextRangeBase& result) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -447,7 +447,7 @@ void UiaTracing::TextProvider::GetVisibleRanges(const ScreenInfoUiaProviderBase& TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextProvider::RangeFromChild(const ScreenInfoUiaProviderBase& siup, const UiaTextRangeBase& result) +void UiaTracing::TextProvider::RangeFromChild(const ScreenInfoUiaProviderBase& siup, const UiaTextRangeBase& result) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -458,7 +458,7 @@ void UiaTracing::TextProvider::RangeFromChild(const ScreenInfoUiaProviderBase& s TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextProvider::RangeFromPoint(const ScreenInfoUiaProviderBase& siup, UiaPoint point, const UiaTextRangeBase& result) +void UiaTracing::TextProvider::RangeFromPoint(const ScreenInfoUiaProviderBase& siup, UiaPoint point, const UiaTextRangeBase& result) noexcept { auto getPoint = [point]() { std::wstringstream stream; @@ -476,7 +476,7 @@ void UiaTracing::TextProvider::RangeFromPoint(const ScreenInfoUiaProviderBase& s TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextProvider::get_DocumentRange(const ScreenInfoUiaProviderBase& siup, const UiaTextRangeBase& result) +void UiaTracing::TextProvider::get_DocumentRange(const ScreenInfoUiaProviderBase& siup, const UiaTextRangeBase& result) noexcept { EnsureRegistration(); TraceLoggingWrite( @@ -487,7 +487,7 @@ void UiaTracing::TextProvider::get_DocumentRange(const ScreenInfoUiaProviderBase TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextProvider::get_SupportedTextSelection(const ScreenInfoUiaProviderBase& siup, SupportedTextSelection result) +void UiaTracing::TextProvider::get_SupportedTextSelection(const ScreenInfoUiaProviderBase& siup, SupportedTextSelection result) noexcept { auto getResult = [result]() { switch (result) diff --git a/src/types/UiaTracing.h b/src/types/UiaTracing.h index e6f853a26d7..27c672be568 100644 --- a/src/types/UiaTracing.h +++ b/src/types/UiaTracing.h @@ -32,44 +32,44 @@ namespace Microsoft::Console::Types class TextRange final { public: - static void Constructor(const UiaTextRangeBase& result); - static void Clone(const UiaTextRangeBase& base, const UiaTextRangeBase& result); - static void Compare(const UiaTextRangeBase& base, const UiaTextRangeBase& other, bool result); - static void CompareEndpoints(const UiaTextRangeBase& base, const TextPatternRangeEndpoint endpoint, const UiaTextRangeBase& other, TextPatternRangeEndpoint otherEndpoint, int result); - static void ExpandToEnclosingUnit(TextUnit unit, const UiaTextRangeBase& result); - static void FindAttribute(const UiaTextRangeBase& base); - static void FindText(const UiaTextRangeBase& base, std::wstring text, bool searchBackward, bool ignoreCase, const UiaTextRangeBase& result); - static void GetAttributeValue(const UiaTextRangeBase& base, TEXTATTRIBUTEID id, VARIANT result); - static void GetBoundingRectangles(const UiaTextRangeBase& base); - static void GetEnclosingElement(const UiaTextRangeBase& base, const ScreenInfoUiaProviderBase& siup); - static void GetText(const UiaTextRangeBase& base, int maxLength, std::wstring result); - static void Move(TextUnit unit, int count, int resultCount, const UiaTextRangeBase& result); - static void MoveEndpointByUnit(TextPatternRangeEndpoint endpoint, TextUnit unit, int count, int resultCount, const UiaTextRangeBase& result); - static void MoveEndpointByRange(TextPatternRangeEndpoint endpoint, const UiaTextRangeBase& other, TextPatternRangeEndpoint otherEndpoint, const UiaTextRangeBase& result); - static void Select(const UiaTextRangeBase& base); - static void AddToSelection(const UiaTextRangeBase& base); - static void RemoveFromSelection(const UiaTextRangeBase& base); - static void ScrollIntoView(bool alignToTop, const UiaTextRangeBase& result); - static void GetChildren(const UiaTextRangeBase& base); + static void Constructor(const UiaTextRangeBase& result) noexcept; + static void Clone(const UiaTextRangeBase& base, const UiaTextRangeBase& result) noexcept; + static void Compare(const UiaTextRangeBase& base, const UiaTextRangeBase& other, bool result) noexcept; + static void CompareEndpoints(const UiaTextRangeBase& base, const TextPatternRangeEndpoint endpoint, const UiaTextRangeBase& other, TextPatternRangeEndpoint otherEndpoint, int result) noexcept; + static void ExpandToEnclosingUnit(TextUnit unit, const UiaTextRangeBase& result) noexcept; + static void FindAttribute(const UiaTextRangeBase& base) noexcept; + static void FindText(const UiaTextRangeBase& base, std::wstring text, bool searchBackward, bool ignoreCase, const UiaTextRangeBase& result) noexcept; + static void GetAttributeValue(const UiaTextRangeBase& base, TEXTATTRIBUTEID id, VARIANT result) noexcept; + static void GetBoundingRectangles(const UiaTextRangeBase& base) noexcept; + static void GetEnclosingElement(const UiaTextRangeBase& base, const ScreenInfoUiaProviderBase& siup) noexcept; + static void GetText(const UiaTextRangeBase& base, int maxLength, std::wstring result) noexcept; + static void Move(TextUnit unit, int count, int resultCount, const UiaTextRangeBase& result) noexcept; + static void MoveEndpointByUnit(TextPatternRangeEndpoint endpoint, TextUnit unit, int count, int resultCount, const UiaTextRangeBase& result) noexcept; + static void MoveEndpointByRange(TextPatternRangeEndpoint endpoint, const UiaTextRangeBase& other, TextPatternRangeEndpoint otherEndpoint, const UiaTextRangeBase& result) noexcept; + static void Select(const UiaTextRangeBase& base) noexcept; + static void AddToSelection(const UiaTextRangeBase& base) noexcept; + static void RemoveFromSelection(const UiaTextRangeBase& base) noexcept; + static void ScrollIntoView(bool alignToTop, const UiaTextRangeBase& result) noexcept; + static void GetChildren(const UiaTextRangeBase& base) noexcept; }; class TextProvider final { public: - static void Constructor(const ScreenInfoUiaProviderBase& result); - static void get_ProviderOptions(const ScreenInfoUiaProviderBase& base, ProviderOptions options); - static void GetPatternProvider(const ScreenInfoUiaProviderBase& base, PATTERNID patternId); - static void GetPropertyValue(const ScreenInfoUiaProviderBase& base, PROPERTYID propertyId); - static void get_HostRawElementProvider(const ScreenInfoUiaProviderBase& base); - static void GetRuntimeId(const ScreenInfoUiaProviderBase& base); - static void GetEmbeddedFragmentRoots(const ScreenInfoUiaProviderBase& base); - static void SetFocus(const ScreenInfoUiaProviderBase& base); - static void GetSelection(const ScreenInfoUiaProviderBase& base); - static void GetVisibleRanges(const ScreenInfoUiaProviderBase& base, const UiaTextRangeBase& result); - static void RangeFromChild(const ScreenInfoUiaProviderBase& base, const UiaTextRangeBase& result); - static void RangeFromPoint(const ScreenInfoUiaProviderBase& base, UiaPoint point, const UiaTextRangeBase& result); - static void get_DocumentRange(const ScreenInfoUiaProviderBase& base, const UiaTextRangeBase& result); - static void get_SupportedTextSelection(const ScreenInfoUiaProviderBase& base, SupportedTextSelection result); + static void Constructor(const ScreenInfoUiaProviderBase& result) noexcept; + static void get_ProviderOptions(const ScreenInfoUiaProviderBase& base, ProviderOptions options) noexcept; + static void GetPatternProvider(const ScreenInfoUiaProviderBase& base, PATTERNID patternId) noexcept; + static void GetPropertyValue(const ScreenInfoUiaProviderBase& base, PROPERTYID propertyId) noexcept; + static void get_HostRawElementProvider(const ScreenInfoUiaProviderBase& base) noexcept; + static void GetRuntimeId(const ScreenInfoUiaProviderBase& base) noexcept; + static void GetEmbeddedFragmentRoots(const ScreenInfoUiaProviderBase& base) noexcept; + static void SetFocus(const ScreenInfoUiaProviderBase& base) noexcept; + static void GetSelection(const ScreenInfoUiaProviderBase& base) noexcept; + static void GetVisibleRanges(const ScreenInfoUiaProviderBase& base, const UiaTextRangeBase& result) noexcept; + static void RangeFromChild(const ScreenInfoUiaProviderBase& base, const UiaTextRangeBase& result) noexcept; + static void RangeFromPoint(const ScreenInfoUiaProviderBase& base, UiaPoint point, const UiaTextRangeBase& result) noexcept; + static void get_DocumentRange(const ScreenInfoUiaProviderBase& base, const UiaTextRangeBase& result) noexcept; + static void get_SupportedTextSelection(const ScreenInfoUiaProviderBase& base, SupportedTextSelection result) noexcept; }; private: From e0d0f82d419d6c336b4a38052daff110d1a8a68d Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Thu, 6 Feb 2020 16:30:18 -0800 Subject: [PATCH 04/10] static analysis fix --- src/types/UiaTextRangeBase.cpp | 35 +++++++++++++++++----------------- src/types/UiaTracing.cpp | 29 ++++++++++++++++++++++++---- src/types/UiaTracing.h | 8 ++++---- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/types/UiaTextRangeBase.cpp b/src/types/UiaTextRangeBase.cpp index 354c2306beb..c0576ce70fb 100644 --- a/src/types/UiaTextRangeBase.cpp +++ b/src/types/UiaTextRangeBase.cpp @@ -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)); // TODO CARLOS: fix tracing call //UiaTracing::TextRange::GetEnclosingElement(*this, static_cast(*ppRetVal)); return hr; @@ -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 +try { _pData->LockConsole(); auto Unlock = wil::scope_exit([&]() noexcept { @@ -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 {}; } +#pragma warning(pop) diff --git a/src/types/UiaTracing.cpp b/src/types/UiaTracing.cpp index 081fda84d80..80dcf9dd904 100644 --- a/src/types/UiaTracing.cpp +++ b/src/types/UiaTracing.cpp @@ -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) +#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} @@ -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); @@ -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) { @@ -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) { @@ -507,3 +527,4 @@ void UiaTracing::TextProvider::get_SupportedTextSelection(const ScreenInfoUiaPro TraceLoggingValue(getResult(), "result"), TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } +#pragma warning(pop) diff --git a/src/types/UiaTracing.h b/src/types/UiaTracing.h index 27c672be568..63d63baef53 100644 --- a/src/types/UiaTracing.h +++ b/src/types/UiaTracing.h @@ -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; }; } From 44a0ff1744429a9247679744f2bddf40243f6728 Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Fri, 7 Feb 2020 17:53:04 -0800 Subject: [PATCH 05/10] PR comments --- src/types/ScreenInfoUiaProviderBase.cpp | 6 +- src/types/UiaTextRangeBase.cpp | 166 +++++++++++------------- src/types/UiaTextRangeBase.hpp | 2 +- src/types/UiaTracing.cpp | 19 +-- src/types/UiaTracing.h | 10 +- 5 files changed, 95 insertions(+), 108 deletions(-) diff --git a/src/types/ScreenInfoUiaProviderBase.cpp b/src/types/ScreenInfoUiaProviderBase.cpp index 3af98864a02..c50f8555dc8 100644 --- a/src/types/ScreenInfoUiaProviderBase.cpp +++ b/src/types/ScreenInfoUiaProviderBase.cpp @@ -347,7 +347,11 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetVisibleRanges(_Outptr_result_mayben return hr; } } - UiaTracing::TextProvider::GetVisibleRanges(*this, *range.Get()); + + // TODO GH #4507: This returns the wrong result. + // No point in putting effort to trace something + // that's wrong right now, that will be fixed soon. + //UiaTracing::TextProvider::GetVisibleRanges(*this, *range.Get()); return S_OK; } diff --git a/src/types/UiaTextRangeBase.cpp b/src/types/UiaTextRangeBase.cpp index c0576ce70fb..3455b5eee45 100644 --- a/src/types/UiaTextRangeBase.cpp +++ b/src/types/UiaTextRangeBase.cpp @@ -462,10 +462,8 @@ try RETURN_HR_IF(E_INVALIDARG, ppRetVal == nullptr); *ppRetVal = nullptr; -#pragma warning(suppress : 26447) // QueryInterface's exception should be caught by the try-CATCH_RETURN block to allow this to be noexcept const auto hr = _pProvider->QueryInterface(IID_PPV_ARGS(ppRetVal)); - // TODO CARLOS: fix tracing call - //UiaTracing::TextRange::GetEnclosingElement(*this, static_cast(*ppRetVal)); + UiaTracing::TextRange::GetEnclosingElement(*this); return hr; } CATCH_RETURN(); @@ -473,83 +471,109 @@ CATCH_RETURN(); IFACEMETHODIMP UiaTextRangeBase::GetText(_In_ int maxLength, _Out_ BSTR* pRetVal) noexcept try { - _pData->LockConsole(); - auto Unlock = wil::scope_exit([&]() noexcept { - _pData->UnlockConsole(); - }); - RETURN_HR_IF(E_INVALIDARG, pRetVal == nullptr); *pRetVal = nullptr; - std::wstring wstr = L""; - if (maxLength < -1) { return E_INVALIDARG; } + + const auto text = _getTextValue(maxLength); + + *pRetVal = SysAllocString(text.c_str()); + UiaTracing::TextRange::GetText(*this, maxLength, text); + return S_OK; +} +CATCH_RETURN(); + +// Method Description: +// - Helper method for GetText(). Retrieves the text that the UiaTextRange encompasses as a wstring +// Arguments: +// - maxLength - the maximum size of the retrieved text. -1 means we don't care about the size. +// Return Value: +// - the text that the UiaTextRange encompasses +#pragma warning(push) +#pragma warning(disable : 26447) // compiler isn't filtering throws inside the try/catch +std::wstring UiaTextRangeBase::_getTextValue(int maxLength) const noexcept +try +{ + _pData->LockConsole(); + auto Unlock = wil::scope_exit([&]() noexcept { + _pData->UnlockConsole(); + }); + + if (IsDegenerate()) + { + return {}; + } + + std::wstring result{}; + // the caller must pass in a value for the max length of the text // to retrieve. a value of -1 means they don't want the text // truncated. const bool getPartialText = maxLength != -1; - if (!IsDegenerate()) - { - // if _end is at 0, we ignore that row because _end is exclusive - const auto& buffer = _pData->GetTextBuffer(); - const short totalRowsInRange = (_end.X == buffer.GetSize().Left()) ? - base::ClampSub(_end.Y, _start.Y) : - base::ClampAdd(base::ClampSub(_end.Y, _start.Y), base::ClampedNumeric(1)); - const short lastRowInRange = _start.Y + totalRowsInRange - 1; + // if _end is at 0, we ignore that row because _end is exclusive + const auto& buffer = _pData->GetTextBuffer(); + const short totalRowsInRange = (_end.X == buffer.GetSize().Left()) ? + base::ClampSub(_end.Y, _start.Y) : + base::ClampAdd(base::ClampSub(_end.Y, _start.Y), base::ClampedNumeric(1)); + const short lastRowInRange = _start.Y + totalRowsInRange - 1; - short currentScreenInfoRow = 0; - for (short i = 0; i < totalRowsInRange; ++i) + short currentScreenInfoRow = 0; + for (short i = 0; i < totalRowsInRange; ++i) + { + currentScreenInfoRow = _start.Y + i; + const ROW& row = buffer.GetRowByOffset(currentScreenInfoRow); + if (row.GetCharRow().ContainsText()) { - currentScreenInfoRow = _start.Y + i; - const ROW& row = buffer.GetRowByOffset(currentScreenInfoRow); - if (row.GetCharRow().ContainsText()) + const size_t rowRight = row.GetCharRow().MeasureRight(); + size_t startIndex = 0; + size_t endIndex = rowRight; + if (currentScreenInfoRow == _start.Y) { - const size_t rowRight = row.GetCharRow().MeasureRight(); - size_t startIndex = 0; - size_t endIndex = rowRight; - if (currentScreenInfoRow == _start.Y) - { - startIndex = _start.X; - } - - if (currentScreenInfoRow == _end.Y) - { - // prevent the end from going past the last non-whitespace char in the row - endIndex = std::max(startIndex + 1, std::min(gsl::narrow_cast(_end.X), rowRight)); - } - - // if startIndex >= endIndex then _start is - // further to the right than the last - // non-whitespace char in the row so there - // wouldn't be any text to grab. - if (startIndex < endIndex) - { - wstr += row.GetText().substr(startIndex, endIndex - startIndex); - } + startIndex = _start.X; } - if (currentScreenInfoRow != lastRowInRange) + if (currentScreenInfoRow == _end.Y) { - wstr += L"\r\n"; + // prevent the end from going past the last non-whitespace char in the row + endIndex = std::max(startIndex + 1, std::min(gsl::narrow_cast(_end.X), rowRight)); } - if (getPartialText && wstr.size() > static_cast(maxLength)) + // if startIndex >= endIndex then _start is + // further to the right than the last + // non-whitespace char in the row so there + // wouldn't be any text to grab. + if (startIndex < endIndex) { - wstr.resize(maxLength); - break; + result += row.GetText().substr(startIndex, endIndex - startIndex); } } + + if (currentScreenInfoRow != lastRowInRange) + { + result += L"\r\n"; + } + + if (getPartialText && result.size() > static_cast(maxLength)) + { + result.resize(maxLength); + break; + } } - *pRetVal = SysAllocString(wstr.c_str()); - UiaTracing::TextRange::GetText(*this, maxLength, wstr); - return S_OK; + return result; } -CATCH_RETURN(); +catch (...) +{ + LOG_CAUGHT_EXCEPTION(); + return {}; +} +#pragma warning(pop) + IFACEMETHODIMP UiaTextRangeBase::Move(_In_ TextUnit unit, _In_ int count, @@ -1178,37 +1202,3 @@ RECT UiaTextRangeBase::_getTerminalRect() const gsl::narrow(result.top + result.height) }; } - -#pragma warning(push) -#pragma warning(disable : 26447) // compiler isn't filtering throws inside the try/catch -std::wstring UiaTextRangeBase::_getTextValue() const noexcept -try -{ - _pData->LockConsole(); - auto Unlock = wil::scope_exit([&]() noexcept { - _pData->UnlockConsole(); - }); - - if (IsDegenerate()) - { - return {}; - } - - 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); - } - - return stream.str(); -} -catch (...) -{ - return {}; -} -#pragma warning(pop) diff --git a/src/types/UiaTextRangeBase.hpp b/src/types/UiaTextRangeBase.hpp index be93536b548..bcfc64aacaf 100644 --- a/src/types/UiaTextRangeBase.hpp +++ b/src/types/UiaTextRangeBase.hpp @@ -152,7 +152,7 @@ namespace Microsoft::Console::Types // This is used by tracing to extract the text value // that the UiaTextRange currently encompasses. // GetText() cannot be used as it's not const - std::wstring _getTextValue() const noexcept; + std::wstring _getTextValue(int maxLength = -1) const noexcept; RECT _getTerminalRect() const; diff --git a/src/types/UiaTracing.cpp b/src/types/UiaTracing.cpp index 80dcf9dd904..e1b000ba7ef 100644 --- a/src/types/UiaTracing.cpp +++ b/src/types/UiaTracing.cpp @@ -7,13 +7,7 @@ // we need to disable a few warnings because // the TraceLogging code is out of our control #pragma warning(push) -#pragma warning(disable : 26447) -#pragma warning(disable : 26477) -#pragma warning(disable : 26482) -#pragma warning(disable : 26496) -#pragma warning(disable : 26485) -#pragma warning(disable : 26494) -#pragma warning(disable : 26446) +#pragma warning(disable : 26446 26447 26477 26482 26485 26494 26496) TRACELOGGING_DEFINE_PROVIDER(g_UiaProviderTraceProvider, "Microsoft.Windows.Console.UIA", // tl:{e7ebce59-2161-572d-b263-2f16a6afb9e5} @@ -31,7 +25,7 @@ UiaTracing::~UiaTracing() noexcept TraceLoggingUnregister(g_UiaProviderTraceProvider); } -std::wstring UiaTracing::_getValue(const ScreenInfoUiaProviderBase& /*siup*/) noexcept +inline std::wstring UiaTracing::_getValue(const ScreenInfoUiaProviderBase& /*siup*/) noexcept try { std::wstringstream stream; @@ -43,7 +37,7 @@ catch (...) return {}; } -std::wstring UiaTracing::_getValue(const UiaTextRangeBase& utr) noexcept +inline std::wstring UiaTracing::_getValue(const UiaTextRangeBase& utr) noexcept try { const auto start = utr.GetEndpoint(TextPatternRangeEndpoint_Start); @@ -63,7 +57,7 @@ catch (...) return {}; } -std::wstring UiaTracing::_getValue(const TextPatternRangeEndpoint endpoint) noexcept +inline std::wstring UiaTracing::_getValue(const TextPatternRangeEndpoint endpoint) noexcept { switch (endpoint) { @@ -76,7 +70,7 @@ std::wstring UiaTracing::_getValue(const TextPatternRangeEndpoint endpoint) noex } } -std::wstring UiaTracing::_getValue(const TextUnit unit) noexcept +inline std::wstring UiaTracing::_getValue(const TextUnit unit) noexcept { switch (unit) { @@ -203,14 +197,13 @@ void UiaTracing::TextRange::GetBoundingRectangles(const UiaTextRangeBase& utr) n TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } -void UiaTracing::TextRange::GetEnclosingElement(const UiaTextRangeBase& utr, const ScreenInfoUiaProviderBase& siup) noexcept +void UiaTracing::TextRange::GetEnclosingElement(const UiaTextRangeBase& utr) noexcept { EnsureRegistration(); TraceLoggingWrite( g_UiaProviderTraceProvider, "UiaTextRange::GetEnclosingElement", TraceLoggingValue(_getValue(utr).c_str(), "base"), - TraceLoggingValue(_getValue(siup).c_str(), "parent"), TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); } diff --git a/src/types/UiaTracing.h b/src/types/UiaTracing.h index 63d63baef53..d054cd5b9e2 100644 --- a/src/types/UiaTracing.h +++ b/src/types/UiaTracing.h @@ -41,7 +41,7 @@ namespace Microsoft::Console::Types static void FindText(const UiaTextRangeBase& base, std::wstring text, bool searchBackward, bool ignoreCase, const UiaTextRangeBase& result) noexcept; static void GetAttributeValue(const UiaTextRangeBase& base, TEXTATTRIBUTEID id, VARIANT result) noexcept; static void GetBoundingRectangles(const UiaTextRangeBase& base) noexcept; - static void GetEnclosingElement(const UiaTextRangeBase& base, const ScreenInfoUiaProviderBase& siup) noexcept; + static void GetEnclosingElement(const UiaTextRangeBase& base) noexcept; static void GetText(const UiaTextRangeBase& base, int maxLength, std::wstring result) noexcept; static void Move(TextUnit unit, int count, int resultCount, const UiaTextRangeBase& result) noexcept; static void MoveEndpointByUnit(TextPatternRangeEndpoint endpoint, TextUnit unit, int count, int resultCount, const UiaTextRangeBase& result) noexcept; @@ -88,9 +88,9 @@ namespace Microsoft::Console::Types UiaTracing& operator=(const UiaTracing&) = delete; UiaTracing& operator=(UiaTracing&&) = delete; - 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; + static inline std::wstring _getValue(const ScreenInfoUiaProviderBase& siup) noexcept; + static inline std::wstring _getValue(const UiaTextRangeBase& utr) noexcept; + static inline std::wstring _getValue(const TextPatternRangeEndpoint endpoint) noexcept; + static inline std::wstring _getValue(const TextUnit unit) noexcept; }; } From af514b6aa9d44246d0341c0812bbec13adcde512 Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Fri, 7 Feb 2020 20:36:52 -0800 Subject: [PATCH 06/10] code format --- src/types/UiaTextRangeBase.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/types/UiaTextRangeBase.cpp b/src/types/UiaTextRangeBase.cpp index 3455b5eee45..ef318d4f7cd 100644 --- a/src/types/UiaTextRangeBase.cpp +++ b/src/types/UiaTextRangeBase.cpp @@ -574,7 +574,6 @@ catch (...) } #pragma warning(pop) - IFACEMETHODIMP UiaTextRangeBase::Move(_In_ TextUnit unit, _In_ int count, _Out_ int* pRetVal) noexcept From be125b4e5465c0a5c11628f9330059fd00bf6561 Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Tue, 11 Feb 2020 13:59:48 -0800 Subject: [PATCH 07/10] Make GetVisibleRanges() return one range (and add tracing for it). (#4526) ## Summary of the Pull Request `ScreenInfoUiaProvider::GetVisibleRanges()` used to return one range per line of visible text. The documentation for this function says that we should return one per contiguous span of text. Since all of the text in the TermControl will always be contiguous (at least by our standards), we should only ever be returning one range. ## PR Checklist * [X] Closes #4507 * [X] CLA signed. ## Validation Steps Performed Verified using Accessibility Insights. --- src/types/ScreenInfoUiaProviderBase.cpp | 60 ++++++++++--------------- 1 file changed, 23 insertions(+), 37 deletions(-) diff --git a/src/types/ScreenInfoUiaProviderBase.cpp b/src/types/ScreenInfoUiaProviderBase.cpp index c50f8555dc8..cdfca31de20 100644 --- a/src/types/ScreenInfoUiaProviderBase.cpp +++ b/src/types/ScreenInfoUiaProviderBase.cpp @@ -304,54 +304,40 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetVisibleRanges(_Outptr_result_mayben }); RETURN_HR_IF_NULL(E_INVALIDARG, ppRetVal); - *ppRetVal = nullptr; - WRL::ComPtr range; - - const auto bufferSize = _pData->GetTextBuffer().GetSize(); - const auto viewport = bufferSize.ConvertToOrigin(_getViewport()); // make a safe array - const auto rowCount = viewport.Height(); - *ppRetVal = SafeArrayCreateVector(VT_UNKNOWN, 0, gsl::narrow(rowCount)); + *ppRetVal = SafeArrayCreateVector(VT_UNKNOWN, 0, 1); if (*ppRetVal == nullptr) { return E_OUTOFMEMORY; } - // stuff each visible line in the safearray - for (short i = 0; i < rowCount; ++i) + WRL::ComPtr range; + const auto bufferSize = _pData->GetTextBuffer().GetSize(); + const auto viewport = bufferSize.ConvertToOrigin(_getViewport()); + + const COORD start{ viewport.Left(), viewport.Top() }; + const COORD end{ viewport.Left(), viewport.BottomExclusive() }; + + auto hr = CreateTextRange(this, start, end, _wordDelimiters, &range); + if (FAILED(hr)) { - // end is exclusive so add 1 - const COORD start{ viewport.Left(), viewport.Top() + i }; - const COORD end{ start.X, start.Y + 1 }; - - HRESULT hr = S_OK; - hr = CreateTextRange(this, - start, - end, - _wordDelimiters, - &range); - if (FAILED(hr)) - { - SafeArrayDestroy(*ppRetVal); - *ppRetVal = nullptr; - return hr; - } + SafeArrayDestroy(*ppRetVal); + *ppRetVal = nullptr; + return hr; + } - LONG currentIndex = gsl::narrow(i); - hr = SafeArrayPutElement(*ppRetVal, ¤tIndex, range.Detach()); - if (FAILED(hr)) - { - SafeArrayDestroy(*ppRetVal); - *ppRetVal = nullptr; - return hr; - } + UiaTracing::TextProvider::GetVisibleRanges(*this, *range.Get()); + + LONG currentIndex = 0; + hr = SafeArrayPutElement(*ppRetVal, ¤tIndex, range.Detach()); + if (FAILED(hr)) + { + SafeArrayDestroy(*ppRetVal); + *ppRetVal = nullptr; + return hr; } - // TODO GH #4507: This returns the wrong result. - // No point in putting effort to trace something - // that's wrong right now, that will be fixed soon. - //UiaTracing::TextProvider::GetVisibleRanges(*this, *range.Get()); return S_OK; } From e1842994811b785f80691314838218ec61297366 Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Wed, 12 Feb 2020 16:56:08 -0800 Subject: [PATCH 08/10] PR nit --- src/types/UiaTracing.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/types/UiaTracing.cpp b/src/types/UiaTracing.cpp index e1b000ba7ef..e67e147c957 100644 --- a/src/types/UiaTracing.cpp +++ b/src/types/UiaTracing.cpp @@ -26,17 +26,11 @@ UiaTracing::~UiaTracing() noexcept } inline std::wstring UiaTracing::_getValue(const ScreenInfoUiaProviderBase& /*siup*/) noexcept -try -{ - std::wstringstream stream; - stream << " NO IDENTIFYING DATA"; - return stream.str(); -} -catch (...) { - return {}; + return L" NO IDENTIFYING DATA"; } + inline std::wstring UiaTracing::_getValue(const UiaTextRangeBase& utr) noexcept try { From a8f7d1c659dcea8730199aa5054fd3cfdf8fadc2 Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Thu, 13 Feb 2020 09:04:55 -0800 Subject: [PATCH 09/10] Code format --- src/types/UiaTracing.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/types/UiaTracing.cpp b/src/types/UiaTracing.cpp index e67e147c957..aed65e2ea77 100644 --- a/src/types/UiaTracing.cpp +++ b/src/types/UiaTracing.cpp @@ -30,7 +30,6 @@ inline std::wstring UiaTracing::_getValue(const ScreenInfoUiaProviderBase& /*siu return L" NO IDENTIFYING DATA"; } - inline std::wstring UiaTracing::_getValue(const UiaTextRangeBase& utr) noexcept try { From 54c10a575f28609e0a7e1c0a74262871d540980d Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Thu, 20 Feb 2020 15:34:14 -0800 Subject: [PATCH 10/10] fix bad merge --- OpenConsole.sln | 7 ------- 1 file changed, 7 deletions(-) diff --git a/OpenConsole.sln b/OpenConsole.sln index ec14469741b..530f602b1a1 100644 --- a/OpenConsole.sln +++ b/OpenConsole.sln @@ -1421,13 +1421,6 @@ Global {A602A555-BAAC-46E1-A91D-3DAB0475C5A1}.Release|x64.Build.0 = Release|x64 {A602A555-BAAC-46E1-A91D-3DAB0475C5A1}.Release|x86.ActiveCfg = Release|Win32 {A602A555-BAAC-46E1-A91D-3DAB0475C5A1}.Release|x86.Build.0 = Release|Win32 - {024052DE-83FB-4653-AEA4-90790D29D5BD}.AuditMode|Any CPU.ActiveCfg = AuditMode|Win32 - {024052DE-83FB-4653-AEA4-90790D29D5BD}.AuditMode|ARM64.ActiveCfg = AuditMode|ARM64 - {024052DE-83FB-4653-AEA4-90790D29D5BD}.AuditMode|ARM64.Build.0 = AuditMode|ARM64 - {024052DE-83FB-4653-AEA4-90790D29D5BD}.AuditMode|x64.ActiveCfg = AuditMode|x64 - {024052DE-83FB-4653-AEA4-90790D29D5BD}.AuditMode|x64.Build.0 = AuditMode|x64 - {024052DE-83FB-4653-AEA4-90790D29D5BD}.AuditMode|x86.ActiveCfg = AuditMode|Win32 - {024052DE-83FB-4653-AEA4-90790D29D5BD}.AuditMode|x86.Build.0 = AuditMode|Win32 {024052DE-83FB-4653-AEA4-90790D29D5BD}.Debug|Any CPU.ActiveCfg = Debug|Win32 {024052DE-83FB-4653-AEA4-90790D29D5BD}.Debug|ARM64.ActiveCfg = Debug|ARM64 {024052DE-83FB-4653-AEA4-90790D29D5BD}.Debug|ARM64.Build.0 = Debug|ARM64