Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more object ID tracing for Accessibility #5215

Merged
5 commits merged into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/types/IUiaTraceable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.

Module Name:
- IUiaTraceable.hpp

Abstract:
- This module is used for assigning and retrieving IDs to UIA objects

Author(s):
- Carlos Zamora (cazamor) Apr 2020
--*/

#pragma once

namespace Microsoft::Console::Types
{
typedef unsigned long long IdType;
constexpr IdType InvalidId = 0;

class IUiaTraceable
{
public:
const IdType GetId() const noexcept
{
return _id;
}

// Routine Description:
// - assigns an ID to the IUiaTraceable object if it doesn't have one
// Arguments:
// - id - the id value that we are trying to assign
// Return Value:
// - true if the assignment was successful, false otherwise (it already has an id).
bool AssignId(IdType id) noexcept
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
{
if (_id == InvalidId)
{
_id = id;
return true;
}
else
{
return false;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the next thing you need in IUiaTraceable is, of course, ToTracingString :P


private:
// used to debug objects passed back and forth
// between the provider and the client
IdType _id{};
};
}
13 changes: 7 additions & 6 deletions src/types/ScreenInfoUiaProviderBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,31 @@ try
RETURN_HR_IF_NULL(E_INVALIDARG, pData);
_pData = pData;
_wordDelimiters = wordDelimiters;

UiaTracing::TextProvider::Constructor(*this);
return S_OK;
}
CATCH_RETURN();

[[nodiscard]] HRESULT ScreenInfoUiaProviderBase::Signal(_In_ EVENTID id)
[[nodiscard]] HRESULT ScreenInfoUiaProviderBase::Signal(_In_ EVENTID eventId)
{
HRESULT hr = S_OK;
// check to see if we're already firing this particular event
if (_signalFiringMapping.find(id) != _signalFiringMapping.end() &&
_signalFiringMapping[id] == true)
if (_signalFiringMapping.find(eventId) != _signalFiringMapping.end() &&
_signalFiringMapping[eventId] == true)
{
return hr;
}

try
{
_signalFiringMapping[id] = true;
_signalFiringMapping[eventId] = true;
}
CATCH_RETURN();

IRawElementProviderSimple* pProvider = this;
hr = UiaRaiseAutomationEvent(pProvider, id);
_signalFiringMapping[id] = false;
hr = UiaRaiseAutomationEvent(pProvider, eventId);
_signalFiringMapping[eventId] = false;

return hr;
}
Expand Down
4 changes: 3 additions & 1 deletion src/types/ScreenInfoUiaProviderBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Author(s):
#include "../buffer/out/textBuffer.hpp"
#include "UiaTextRangeBase.hpp"
#include "IUiaData.h"
#include "IUiaTraceable.h"

#include <UIAutomationCore.h>

Expand All @@ -35,7 +36,8 @@ namespace Microsoft::Console::Types
class Viewport;

class ScreenInfoUiaProviderBase :
public WRL::RuntimeClass<WRL::RuntimeClassFlags<WRL::ClassicCom | WRL::InhibitFtmBase>, IRawElementProviderSimple, IRawElementProviderFragment, ITextProvider>
public WRL::RuntimeClass<WRL::RuntimeClassFlags<WRL::ClassicCom | WRL::InhibitFtmBase>, IRawElementProviderSimple, IRawElementProviderFragment, ITextProvider>,
public IUiaTraceable
{
public:
virtual HRESULT RuntimeClassInitialize(_In_ IUiaData* pData, _In_ std::wstring_view wordDelimiters = UiaTextRangeBase::DefaultWordDelimiter) noexcept;
Expand Down
13 changes: 0 additions & 13 deletions src/types/UiaTextRangeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

using namespace Microsoft::Console::Types;

IdType UiaTextRangeBase::id = 1;

// 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
Expand All @@ -26,9 +24,6 @@ try
_blockRange = false;
_wordDelimiters = wordDelimiters;

_id = id;
++id;

UiaTracing::TextRange::Constructor(*this);
return S_OK;
}
Expand Down Expand Up @@ -123,19 +118,11 @@ try
_pData = a._pData;
_wordDelimiters = a._wordDelimiters;

_id = id;
++id;

UiaTracing::TextRange::Constructor(*this);
return S_OK;
}
CATCH_RETURN();

const IdType UiaTextRangeBase::GetId() const noexcept
{
return _id;
}

const COORD UiaTextRangeBase::GetEndpoint(TextPatternRangeEndpoint endpoint) const noexcept
{
switch (endpoint)
Expand Down
16 changes: 2 additions & 14 deletions src/types/UiaTextRangeBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Author(s):
#include "../buffer/out/textBuffer.hpp"
#include "IUiaData.h"
#include "unicode.hpp"
#include "IUiaTraceable.h"

#include <UIAutomationCore.h>
#include <deque>
Expand All @@ -32,18 +33,10 @@ Author(s):
class UiaTextRangeTests;
#endif

typedef unsigned long long IdType;
constexpr IdType InvalidId = 0;

namespace Microsoft::Console::Types
{
class UiaTracing;

class UiaTextRangeBase : public WRL::RuntimeClass<WRL::RuntimeClassFlags<WRL::ClassicCom | WRL::InhibitFtmBase>, ITextRangeProvider>
class UiaTextRangeBase : public WRL::RuntimeClass<WRL::RuntimeClassFlags<WRL::ClassicCom | WRL::InhibitFtmBase>, ITextRangeProvider>, public IUiaTraceable
{
private:
static IdType id;

protected:
// indicates which direction a movement operation
// is going
Expand Down Expand Up @@ -84,7 +77,6 @@ namespace Microsoft::Console::Types
UiaTextRangeBase& operator=(UiaTextRangeBase&&) = delete;
~UiaTextRangeBase() = default;

const IdType GetId() const noexcept;
const COORD GetEndpoint(TextPatternRangeEndpoint endpoint) const noexcept;
bool SetEndpoint(TextPatternRangeEndpoint endpoint, const COORD val) noexcept;
const bool IsDegenerate() const noexcept;
Expand Down Expand Up @@ -141,10 +133,6 @@ namespace Microsoft::Console::Types

void Initialize(_In_ const UiaPoint point);

// used to debug objects passed back and forth
// between the provider and the client
IdType _id{};

// measure units in the form [_start, _end).
// These are in the TextBuffer coordinate space.
// NOTE: _start is inclusive, but _end is exclusive
Expand Down
53 changes: 48 additions & 5 deletions src/types/UiaTracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,44 @@ TRACELOGGING_DEFINE_PROVIDER(g_UiaProviderTraceProvider,

using namespace Microsoft::Console::Types;

// The first valid ID is 1 for each of our traced UIA object types
// ID assignment is handled between UiaTracing and IUiaTraceable to...
// - prevent multiple objects with the same ID
// - only assign IDs if UiaTracing is enabled
// - ensure objects are only assigned an ID once
IdType UiaTracing::_utrId = 1;
IdType UiaTracing::_siupId = 1;

// Routine Description:
// - assign an ID to the UiaTextRange, if it doesn't have one already
// Arguments:
// - utr - the UiaTextRange we are assigning an ID to
// Return Value:
// - N/A
void UiaTracing::_assignId(UiaTextRangeBase& utr) noexcept
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
{
auto temp = utr.AssignId(_utrId);
if (temp)
{
++_utrId;
}
}

// Routine Description:
// - assign an ID to the ScreenInfoUiaProvider, if it doesn't have one already
// Arguments:
// - siup - the ScreenInfoUiaProvider we are assigning an ID to
// Return Value:
// - N/A
void UiaTracing::_assignId(ScreenInfoUiaProviderBase& siup) noexcept
{
auto temp = siup.AssignId(_siupId);
if (temp)
{
++_siupId;
}
}

UiaTracing::UiaTracing() noexcept
{
TraceLoggingRegister(g_UiaProviderTraceProvider);
Expand All @@ -25,9 +63,11 @@ UiaTracing::~UiaTracing() noexcept
TraceLoggingUnregister(g_UiaProviderTraceProvider);
}

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

inline std::wstring UiaTracing::_getValue(const UiaTextRangeBase& utr) noexcept
Expand Down Expand Up @@ -86,11 +126,12 @@ inline std::wstring UiaTracing::_getValue(const TextUnit unit) noexcept
}
}

void UiaTracing::TextRange::Constructor(const UiaTextRangeBase& result) noexcept
void UiaTracing::TextRange::Constructor(UiaTextRangeBase& result) noexcept
{
EnsureRegistration();
if (TraceLoggingProviderEnabled(g_UiaProviderTraceProvider, WINEVENT_LEVEL_VERBOSE, 0))
{
_assignId(result);
TraceLoggingWrite(
g_UiaProviderTraceProvider,
"UiaTextRange::Constructor",
Expand All @@ -99,11 +140,12 @@ void UiaTracing::TextRange::Constructor(const UiaTextRangeBase& result) noexcept
}
}

void UiaTracing::TextRange::Clone(const UiaTextRangeBase& utr, const UiaTextRangeBase& result) noexcept
void UiaTracing::TextRange::Clone(const UiaTextRangeBase& utr, UiaTextRangeBase& result) noexcept
{
EnsureRegistration();
if (TraceLoggingProviderEnabled(g_UiaProviderTraceProvider, WINEVENT_LEVEL_VERBOSE, 0))
{
_assignId(result);
TraceLoggingWrite(
g_UiaProviderTraceProvider,
"UiaTextRange::Clone",
Expand Down Expand Up @@ -360,11 +402,12 @@ void UiaTracing::TextRange::GetChildren(const UiaTextRangeBase& result) noexcept
}
}

void UiaTracing::TextProvider::Constructor(const ScreenInfoUiaProviderBase& result) noexcept
void UiaTracing::TextProvider::Constructor(ScreenInfoUiaProviderBase& result) noexcept
{
EnsureRegistration();
if (TraceLoggingProviderEnabled(g_UiaProviderTraceProvider, WINEVENT_LEVEL_VERBOSE, 0))
{
_assignId(result);
TraceLoggingWrite(
g_UiaProviderTraceProvider,
"ScreenInfoUiaProvider::Constructor",
Expand Down
13 changes: 10 additions & 3 deletions src/types/UiaTracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ namespace Microsoft::Console::Types
class TextRange final
{
public:
static void Constructor(const UiaTextRangeBase& result) noexcept;
static void Clone(const UiaTextRangeBase& base, const UiaTextRangeBase& result) noexcept;
static void Constructor(UiaTextRangeBase& result) noexcept;
static void Clone(const UiaTextRangeBase& base, 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;
Expand All @@ -56,7 +56,7 @@ namespace Microsoft::Console::Types
class TextProvider final
{
public:
static void Constructor(const ScreenInfoUiaProviderBase& result) noexcept;
static void Constructor(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;
Expand Down Expand Up @@ -100,5 +100,12 @@ namespace Microsoft::Console::Types
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;

// these are used to assign IDs to new UiaTextRanges and ScreenInfoUiaProviders respectively
static IdType _utrId;
static IdType _siupId;

static void _assignId(UiaTextRangeBase& utr) noexcept;
static void _assignId(ScreenInfoUiaProviderBase& siup) noexcept;
};
}
1 change: 1 addition & 0 deletions src/types/lib/types.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<ClInclude Include="..\inc\Utf16Parser.hpp" />
<ClInclude Include="..\IUiaData.h" />
<ClInclude Include="..\IUiaEventDispatcher.h" />
<ClInclude Include="..\IUiaTraceable.h" />
<ClInclude Include="..\IUiaWindow.h" />
<ClInclude Include="..\TermControlUiaTextRange.hpp" />
<ClInclude Include="..\TermControlUiaProvider.hpp" />
Expand Down
3 changes: 3 additions & 0 deletions src/types/lib/types.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@
<ClInclude Include="..\UiaTracing.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\IUiaTraceable.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Natvis Include="$(SolutionDir)tools\ConsoleTypes.natvis" />
Expand Down