diff --git a/src/host/renderData.cpp b/src/host/renderData.cpp index 36c3fb259fb..f6e1451938e 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 18520ff2994..8752867540a 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(); @@ -261,18 +239,12 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetSelection(_Outptr_result_maybenull_ WRL::ComPtr range; if (!_pData->IsSelectionActive()) { - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //apiMsg.AreaSelected = false; - // return a degenerate range at the cursor position const Cursor& cursor = _getTextBuffer().GetCursor(); hr = CreateTextRange(this, cursor, _wordDelimiters, &range); } else { - // TODO GitHub #1914: Re-attach Tracing to UIA Tree - //apiMsg.AreaSelected = true; - // get the selection range hr = GetSelectionRange(this, _wordDelimiters, &range); } @@ -293,89 +265,71 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetSelection(_Outptr_result_maybenull_ return hr; } - // 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(); }); RETURN_HR_IF_NULL(E_INVALIDARG, ppRetVal); - *ppRetVal = nullptr; - - 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; - WRL::ComPtr range; - 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; } + 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; @@ -385,14 +339,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; @@ -400,6 +352,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; } @@ -407,10 +360,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 c57419a6789..7f4e315adce 100644 --- a/src/types/ScreenInfoUiaProviderBase.h +++ b/src/types/ScreenInfoUiaProviderBase.h @@ -128,49 +128,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 3b16177242a..690c1fd2606 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, @@ -108,11 +73,7 @@ try _end = start; } -#if defined(_DEBUG) && defined(UIATEXTRANGE_DEBUG_MSGS) - OutputDebugString(L"Constructor\n"); - _outputObjectState(); -#endif - + UiaTracing::TextRange::Constructor(*this); return S_OK; } CATCH_RETURN(); @@ -159,11 +120,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(); @@ -177,9 +134,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; } @@ -198,7 +155,7 @@ bool UiaTextRangeBase::SetEndpoint(TextPatternRangeEndpoint endpoint, const COOR const auto bufferSize = _getBufferSize(); switch (endpoint) { - case TextPatternRangeEndpoint::TextPatternRangeEndpoint_End: + case TextPatternRangeEndpoint_End: _end = val; // if end is before start... if (bufferSize.CompareInBounds(_end, _start, true) < 0) @@ -207,7 +164,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) @@ -250,13 +207,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; } @@ -285,15 +237,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(); @@ -305,23 +249,18 @@ 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 = _getBufferSize(); 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); @@ -334,7 +273,7 @@ IFACEMETHODIMP UiaTextRangeBase::ExpandToEnclosingUnit(_In_ TextUnit unit) noexc _end = bufferEnd; } } - else if (unit <= TextUnit::TextUnit_Line) + else if (unit <= TextUnit_Line) { // expand to line _start.X = 0; @@ -348,8 +287,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(); @@ -361,8 +299,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; } @@ -372,8 +309,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; @@ -412,6 +347,8 @@ try UiaTextRangeBase& range = static_cast(**ppRetVal); range._start = start; range._end = end; + + UiaTracing::TextRange::FindText(*this, queryText, searchBackward, ignoreCase, range); } } return S_OK; @@ -423,8 +360,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; @@ -435,6 +370,7 @@ IFACEMETHODIMP UiaTextRangeBase::GetAttributeValue(_In_ TEXTATTRIBUTEID textAttr pRetVal->vt = VT_UNKNOWN; UiaGetReservedNotSupportedValue(&pRetVal->punkVal); } + UiaTracing::TextRange::GetAttributeValue(*this, textAttributeId, *pRetVal); return S_OK; } @@ -535,9 +471,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; } @@ -547,110 +481,117 @@ 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)); + const auto hr = _pProvider->QueryInterface(IID_PPV_ARGS(ppRetVal)); + UiaTracing::TextRange::GetEnclosingElement(*this); + return hr; } 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 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()) ? - 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); } } - } - *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 (currentScreenInfoRow != lastRowInRange) + { + result += L"\r\n"; + } -#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 + if (getPartialText && result.size() > static_cast(maxLength)) + { + result.resize(maxLength); + break; + } + } - return S_OK; + return result; } -CATCH_RETURN(); +catch (...) +{ + LOG_CAUGHT_EXCEPTION(); + return {}; +} +#pragma warning(pop) IFACEMETHODIMP UiaTextRangeBase::Move(_In_ TextUnit unit, _In_ int count, @@ -663,23 +604,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(); @@ -716,11 +640,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; } @@ -736,24 +656,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(); @@ -780,11 +682,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; } @@ -804,29 +702,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(); @@ -851,8 +729,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(); @@ -860,16 +737,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; } @@ -936,12 +811,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(); @@ -959,6 +829,7 @@ IFACEMETHODIMP UiaTextRangeBase::GetChildren(_Outptr_result_maybenull_ SAFEARRAY { return E_OUTOFMEMORY; } + UiaTracing::TextRange::GetChildren(*this); return S_OK; } @@ -1091,7 +962,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) { @@ -1233,7 +1104,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) diff --git a/src/types/UiaTextRangeBase.hpp b/src/types/UiaTextRangeBase.hpp index aa56a3c4261..17480ec1ba8 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(int maxLength = -1) const noexcept; + RECT _getTerminalRect() const; virtual const COORD _getScreenFontSize() const; @@ -190,104 +189,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..aed65e2ea77 --- /dev/null +++ b/src/types/UiaTracing.cpp @@ -0,0 +1,516 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#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 : 26446 26447 26477 26482 26485 26494 26496) +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); +} + +inline std::wstring UiaTracing::_getValue(const ScreenInfoUiaProviderBase& /*siup*/) noexcept +{ + return L" NO IDENTIFYING DATA"; +} + +inline std::wstring UiaTracing::_getValue(const UiaTextRangeBase& utr) noexcept +try +{ + 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(); +} +catch (...) +{ + return {}; +} + +inline std::wstring UiaTracing::_getValue(const TextPatternRangeEndpoint endpoint) noexcept +{ + switch (endpoint) + { + case TextPatternRangeEndpoint_Start: + return L"Start"; + case TextPatternRangeEndpoint_End: + return L"End"; + default: + return L"UNKNOWN VALUE"; + } +} + +inline std::wstring UiaTracing::_getValue(const TextUnit unit) noexcept +{ + 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) noexcept +{ + 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) noexcept +{ + 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) noexcept +{ + 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) noexcept +{ + 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) noexcept +{ + 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) noexcept +{ + 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) noexcept +{ + 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) noexcept +{ + 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) noexcept +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::GetBoundingRectangles", + TraceLoggingValue(_getValue(utr).c_str(), "base"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::GetEnclosingElement(const UiaTextRangeBase& utr) noexcept +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::GetEnclosingElement", + TraceLoggingValue(_getValue(utr).c_str(), "base"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::GetText(const UiaTextRangeBase& utr, int maxLength, std::wstring result) noexcept +{ + 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) noexcept +{ + 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) noexcept +{ + 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) noexcept +{ + 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) noexcept +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::Select", + TraceLoggingValue(_getValue(result).c_str(), "base"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::AddToSelection(const UiaTextRangeBase& result) noexcept +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::AddToSelection (UNSUPPORTED)", + TraceLoggingValue(_getValue(result).c_str(), "base"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextRange::RemoveFromSelection(const UiaTextRangeBase& result) noexcept +{ + 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) noexcept +{ + 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) noexcept +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "UiaTextRange::AddToSelection (UNSUPPORTED)", + TraceLoggingValue(_getValue(result).c_str(), "base"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextProvider::Constructor(const ScreenInfoUiaProviderBase& result) noexcept +{ + 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) noexcept +{ + 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) noexcept +{ + 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) noexcept +{ + 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) noexcept +{ + 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) noexcept +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "ScreenInfoUiaProvider::GetRuntimeId", + TraceLoggingValue(_getValue(siup).c_str(), "base"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextProvider::GetEmbeddedFragmentRoots(const ScreenInfoUiaProviderBase& siup) noexcept +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "ScreenInfoUiaProvider::GetEmbeddedFragmentRoots (UNSUPPORTED)", + TraceLoggingValue(_getValue(siup).c_str(), "base"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +void UiaTracing::TextProvider::SetFocus(const ScreenInfoUiaProviderBase& siup) noexcept +{ + EnsureRegistration(); + TraceLoggingWrite( + g_UiaProviderTraceProvider, + "ScreenInfoUiaProvider::SetFocus", + TraceLoggingValue(_getValue(siup).c_str(), "base"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); +} + +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(); + 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) noexcept +{ + 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) noexcept +{ + 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) noexcept +{ + 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) noexcept +{ + 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) noexcept +{ + 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)); +} +#pragma warning(pop) diff --git a/src/types/UiaTracing.h b/src/types/UiaTracing.h new file mode 100644 index 00000000000..d054cd5b9e2 --- /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) 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) 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) 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: + // 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 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; + }; +} 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