Bug 1765655 - Introduce Accessible::DebugDescription in debug builds. r=morgan

Depends on D144234

Differential Revision: https://phabricator.services.mozilla.com/D144235
This commit is contained in:
Eitan Isaacson 2022-04-26 16:44:54 +00:00
parent 58c7b70e1e
commit 03381c5118
2 changed files with 44 additions and 0 deletions

View File

@ -11,6 +11,10 @@
#include "mozilla/Components.h"
#include "nsIStringBundle.h"
#ifdef A11Y_LOG
# include "nsAccessibilityService.h"
#endif
using namespace mozilla;
using namespace mozilla::a11y;
@ -294,6 +298,38 @@ void Accessible::GetPositionAndSetSize(int32_t* aPosInSet, int32_t* aSetSize) {
}
}
#ifdef A11Y_LOG
void Accessible::DebugDescription(nsCString& aDesc) {
aDesc.Truncate();
aDesc.AppendPrintf("[%p] ", this);
nsAutoString role;
GetAccService()->GetStringRole(Role(), role);
aDesc.Append(NS_ConvertUTF16toUTF8(role));
if (nsAtom* tagAtom = TagName()) {
nsAutoCString tag;
tagAtom->ToUTF8String(tag);
aDesc.AppendPrintf(" %s", tag.get());
nsAutoString id;
DOMNodeID(id);
if (!id.IsEmpty()) {
aDesc.Append("#");
aDesc.Append(NS_ConvertUTF16toUTF8(id));
}
}
nsAutoString id;
nsAutoString name;
Name(name);
if (!name.IsEmpty()) {
aDesc.Append(" '");
aDesc.Append(NS_ConvertUTF16toUTF8(name));
aDesc.Append("'");
}
}
#endif
void Accessible::TranslateString(const nsString& aKey, nsAString& aStringOut) {
nsCOMPtr<nsIStringBundleService> stringBundleService =
components::StringBundle::Service();

View File

@ -453,6 +453,14 @@ class Accessible {
virtual TableAccessibleBase* AsTableBase() { return nullptr; }
virtual TableCellAccessibleBase* AsTableCellBase() { return nullptr; }
#ifdef A11Y_LOG
/**
* Provide a human readable description of the accessible,
* including memory address, role, name, DOM tag and DOM ID.
*/
void DebugDescription(nsCString& aDesc);
#endif
/**
* Return the localized string for the given key.
*/