Bug 759645 - enable extended logging for a11y tree and text changes, r=tbsaunde

This commit is contained in:
Alexander Surkov 2012-06-01 13:27:25 +09:00
parent 1da923c89a
commit 55a0007f12
6 changed files with 156 additions and 137 deletions

View File

@ -45,7 +45,9 @@ EnableLogging(const char* aModulesStr)
{ "docdestroy", logging::eDocDestroy },
{ "doclifecycle", logging::eDocLifeCycle },
{ "platforms", logging::ePlatforms },
{ "stack", logging::eStack }
{ "stack", logging::eStack },
{ "text", logging::eText },
{ "tree", logging::eTree }
};
const char* token = aModulesStr;
@ -451,21 +453,6 @@ logging::OuterDocDestroy(OuterDocAccessible* aOuterDoc)
MsgEnd();
}
void
logging::Address(const char* aDescr, Accessible* aAcc)
{
nsINode* node = aAcc->GetNode();
nsIDocument* docNode = aAcc->GetDocumentNode();
DocAccessible* doc = GetAccService()->GetDocAccessibleFromCache(docNode);
printf(" %s accessible: %p, node: %p\n", aDescr,
static_cast<void*>(aAcc), static_cast<void*>(node));
printf(" docacc for %s accessible: %p, node: %p\n", aDescr,
static_cast<void*>(doc), static_cast<void*>(docNode));
printf(" ");
LogDocURI(docNode);
printf("\n");
}
void
logging::MsgBegin(const char* aTitle, const char* aMsgText, ...)
{
@ -485,12 +472,84 @@ logging::MsgEnd()
printf(" }\n");
}
void
logging::MsgEntry(const char* aEntryText, ...)
{
printf(" ");
va_list argptr;
va_start(argptr, aEntryText);
vprintf(aEntryText, argptr);
va_end(argptr);
printf("\n");
}
void
logging::Text(const char* aText)
{
printf(" %s\n", aText);
}
void
logging::Address(const char* aDescr, Accessible* aAcc)
{
nsINode* node = aAcc->GetNode();
nsIDocument* docNode = aAcc->GetDocumentNode();
DocAccessible* doc = GetAccService()->GetDocAccessibleFromCache(docNode);
printf(" %s accessible: %p, node: %p\n", aDescr,
static_cast<void*>(aAcc), static_cast<void*>(node));
printf(" docacc for %s accessible: %p, node: %p\n", aDescr,
static_cast<void*>(doc), static_cast<void*>(docNode));
printf(" ");
LogDocURI(docNode);
printf("\n");
}
void
logging::Node(const char* aDescr, nsINode* aNode)
{
printf(" ");
if (!aNode) {
printf("%s: null\n", aDescr);
return;
}
if (aNode->IsNodeOfType(nsINode::eDOCUMENT)) {
printf("%s: %p, document\n", aDescr, static_cast<void*>(aNode));
return;
}
nsINode* parentNode = aNode->GetNodeParent();
PRInt32 idxInParent = parentNode ? parentNode->IndexOf(aNode) : - 1;
if (aNode->IsNodeOfType(nsINode::eTEXT)) {
printf("%s: %p, text node, idx in parent: %d\n",
aDescr, static_cast<void*>(aNode), idxInParent);
return;
}
if (!aNode->IsElement()) {
printf("%s: %p, not accessible node type, idx in parent: %d\n",
aDescr, static_cast<void*>(aNode), idxInParent);
return;
}
dom::Element* elm = aNode->AsElement();
nsCAutoString tag;
elm->Tag()->ToUTF8String(tag);
nsIAtom* idAtom = elm->GetID();
nsCAutoString id;
if (idAtom)
idAtom->ToUTF8String(id);
printf("%s: %p, %s@id='%s', idx in parent: %d\n",
aDescr, static_cast<void*>(elm), tag.get(), id.get(), idxInParent);
}
void
logging::Stack()
{

View File

@ -13,7 +13,9 @@
class AccEvent;
class Accessible;
class DocAccessible;
class nsIDocument;
class nsINode;
class nsIRequest;
class nsIWebProgress;
@ -30,13 +32,15 @@ enum EModules {
eDocDestroy = 1 << 2,
eDocLifeCycle = eDocLoad | eDocCreate | eDocDestroy,
ePlatforms = 1 << 3,
eStack = 1 << 4
eStack = 1 << 4,
eText = 1 << 5,
eTree = 1 << 6
};
/**
* Return true if the given module is logged.
* Return true if any of the given modules is logged.
*/
bool IsEnabled(PRUint32 aModule);
bool IsEnabled(PRUint32 aModules);
/**
* Log the document loading progress.
@ -80,6 +84,11 @@ void OuterDocDestroy(OuterDocAccessible* OuterDoc);
void MsgBegin(const char* aTitle, const char* aMsgText, ...);
void MsgEnd();
/**
* Log the entry into message body (4 spaces offset).
*/
void MsgEntry(const char* aEntryText, ...);
/**
* Log the text, two spaces offset is used.
*/
@ -90,6 +99,11 @@ void Text(const char* aText);
*/
void Address(const char* aDescr, Accessible* aAcc);
/**
* Log the DOM node info.
*/
void Node(const char* aDescr, nsINode* aNode);
/**
* Log the call stack, two spaces offset is used.
*/

View File

@ -16,6 +16,10 @@
#include "TextLeafAccessible.h"
#include "TextUpdater.h"
#ifdef DEBUG
#include "Logging.h"
#endif
#include "mozilla/dom/Element.h"
using namespace mozilla::a11y;
@ -190,9 +194,12 @@ NotificationController::WillRefresh(mozilla::TimeStamp aTime)
return;
}
#ifdef DEBUG_NOTIFICATIONS
printf("\ninitial tree created, document: %p, document node: %p\n",
mDocument.get(), mDocument->GetDocumentNode());
#ifdef DEBUG
if (logging::IsEnabled(logging::eTree)) {
logging::MsgBegin("TREE", "initial tree created");
logging::Address("document", mDocument);
logging::MsgEnd();
}
#endif
mDocument->DoInitialUpdate();
@ -709,20 +716,13 @@ NotificationController::TextEnumerator(nsCOMPtrHashKey<nsIContent>* aEntry,
// Remove text accessible if rendered text is empty.
if (textAcc) {
if (text.IsEmpty()) {
#ifdef DEBUG_NOTIFICATIONS
PRUint32 index = containerNode->IndexOf(textNode);
nsCAutoString tag;
nsCAutoString id;
if (containerElm) {
containerElm->Tag()->ToUTF8String(tag);
nsIAtom* atomid = containerElm->GetID();
if (atomid)
atomid->ToUTF8String(id);
#ifdef DEBUG
if (logging::IsEnabled(logging::eTree | logging::eText)) {
logging::MsgBegin("TREE", "text node lost its content");
logging::Node("container", containerElm);
logging::Node("content", textNode);
logging::MsgEnd();
}
printf("\npending text node removal: container: %s@id='%s', index in container: %d\n\n",
tag.get(), id.get(), index);
#endif
document->ContentRemoved(containerElm, textNode);
@ -730,22 +730,17 @@ NotificationController::TextEnumerator(nsCOMPtrHashKey<nsIContent>* aEntry,
}
// Update text of the accessible and fire text change events.
#ifdef DEBUG_TEXTCHANGE
PRUint32 index = containerNode->IndexOf(textNode);
nsCAutoString tag;
nsCAutoString id;
if (containerElm) {
containerElm->Tag()->ToUTF8String(tag);
nsIAtom* atomid = containerElm->GetID();
if (atomid)
atomid->ToUTF8String(id);
}
printf("\ntext may be changed: container: %s@id='%s', index in container: %d, old text '%s', new text: '%s'\n\n",
tag.get(), id.get(), index,
NS_ConvertUTF16toUTF8(textAcc->AsTextLeaf()->Text()).get(),
NS_ConvertUTF16toUTF8(text).get());
#ifdef DEBUG
if (logging::IsEnabled(logging::eText)) {
logging::MsgBegin("TEXT", "text may be changed");
logging::Node("container", containerElm);
logging::Node("content", textNode);
logging::MsgEntry("old text '%s'",
NS_ConvertUTF16toUTF8(textAcc->AsTextLeaf()->Text()).get());
logging::MsgEntry("new text: '%s'",
NS_ConvertUTF16toUTF8(text).get());
logging::MsgEnd();
}
#endif
TextUpdater::Run(document, textAcc->AsTextLeaf(), text);
@ -754,20 +749,13 @@ NotificationController::TextEnumerator(nsCOMPtrHashKey<nsIContent>* aEntry,
// Append an accessible if rendered text is not empty.
if (!text.IsEmpty()) {
#ifdef DEBUG_NOTIFICATIONS
PRUint32 index = containerNode->IndexOf(textNode);
nsCAutoString tag;
nsCAutoString id;
if (containerElm) {
containerElm->Tag()->ToUTF8String(tag);
nsIAtom* atomid = containerElm->GetID();
if (atomid)
atomid->ToUTF8String(id);
}
printf("\npending text node insertion: container: %s@id='%s', index in container: %d\n\n",
tag.get(), id.get(), index);
#ifdef DEBUG
if (logging::IsEnabled(logging::eTree | logging::eText)) {
logging::MsgBegin("TREE", "text node gains new content");
logging::Node("container", containerElm);
logging::Node("content", textNode);
logging::MsgEnd();
}
#endif
// Make sure the text node is in accessible document still.
@ -835,31 +823,6 @@ NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(NotificationController::ContentInsertion,
void
NotificationController::ContentInsertion::Process()
{
#ifdef DEBUG_NOTIFICATIONS
nsIContent* firstChildNode = mInsertedContent[0];
nsCAutoString tag;
firstChildNode->Tag()->ToUTF8String(tag);
nsIAtom* atomid = firstChildNode->GetID();
nsCAutoString id;
if (atomid)
atomid->ToUTF8String(id);
nsCAutoString ctag;
nsCAutoString cid;
nsIAtom* catomid = nsnull;
if (mContainer->IsContent()) {
mContainer->GetContent()->Tag()->ToUTF8String(ctag);
catomid = mContainer->GetContent()->GetID();
if (catomid)
catomid->ToUTF8String(cid);
}
printf("\npending content insertion: %s@id='%s', container: %s@id='%s', inserted content amount: %d\n\n",
tag.get(), id.get(), ctag.get(), cid.get(), mInsertedContent.Length());
#endif
mDocument->ProcessContentInserted(mContainer, &mInsertedContent);
mDocument = nsnull;

View File

@ -17,11 +17,6 @@ class nsIContent;
// Uncomment to log notifications processing.
//#define DEBUG_NOTIFICATIONS
#ifdef DEBUG_NOTIFICATIONS
#define DEBUG_CONTENTMUTATION
#define DEBUG_TEXTCHANGE
#endif
/**
* Notification interface.
*/

View File

@ -475,28 +475,16 @@ nsAccessibilityService::ContentRangeInserted(nsIPresShell* aPresShell,
nsIContent* aStartChild,
nsIContent* aEndChild)
{
#ifdef DEBUG_CONTENTMUTATION
nsAutoString tag;
aStartChild->Tag()->ToString(tag);
nsIAtom* atomid = aStartChild->GetID();
nsCAutoString id;
if (atomid)
atomid->ToUTF8String(id);
nsAutoString ctag;
nsCAutoString cid;
nsIAtom* catomid = nsnull;
if (aContainer) {
aContainer->Tag()->ToString(ctag);
catomid = aContainer->GetID();
if (catomid)
catomid->ToUTF8String(cid);
#ifdef DEBUG
if (logging::IsEnabled(logging::eTree)) {
logging::MsgBegin("TREE", "content inserted");
logging::Node("container", aContainer);
for (nsIContent* child = aStartChild; child != aEndChild;
child = child->GetNextSibling()) {
logging::Node("content", child);
}
logging::MsgEnd();
}
printf("\ncontent inserted: %s@id='%s', container: %s@id='%s', end node: %p\n\n",
NS_ConvertUTF16toUTF8(tag).get(), id.get(),
NS_ConvertUTF16toUTF8(ctag).get(), cid.get(), aEndChild);
#endif
DocAccessible* docAccessible = GetDocAccessible(aPresShell);
@ -509,28 +497,13 @@ nsAccessibilityService::ContentRemoved(nsIPresShell* aPresShell,
nsIContent* aContainer,
nsIContent* aChild)
{
#ifdef DEBUG_CONTENTMUTATION
nsAutoString tag;
aChild->Tag()->ToString(tag);
nsIAtom* atomid = aChild->GetID();
nsCAutoString id;
if (atomid)
atomid->ToUTF8String(id);
nsAutoString ctag;
nsCAutoString cid;
nsIAtom* catomid = nsnull;
if (aContainer) {
aContainer->Tag()->ToString(ctag);
catomid = aContainer->GetID();
if (catomid)
catomid->ToUTF8String(cid);
#ifdef DEBUG
if (logging::IsEnabled(logging::eTree)) {
logging::MsgBegin("TREE", "content removed");
logging::Node("container", aContainer);
logging::Node("content", aChild);
logging::MsgEnd();
}
printf("\ncontent removed: %s@id='%s', container: %s@id='%s'\n\n",
NS_ConvertUTF16toUTF8(tag).get(), id.get(),
NS_ConvertUTF16toUTF8(ctag).get(), cid.get());
#endif
DocAccessible* docAccessible = GetDocAccessible(aPresShell);

View File

@ -1836,6 +1836,21 @@ DocAccessible::UpdateTree(Accessible* aContainer, nsIContent* aChildNode,
// If child node is not accessible then look for its accessible children.
Accessible* child = GetAccessible(aChildNode);
#ifdef DEBUG
if (logging::IsEnabled(logging::eTree)) {
logging::MsgBegin("TREE", "process content %s",
(aIsInsert ? "insertion" : "removal"));
logging::Node("container", aContainer->GetNode());
logging::Node("child", aChildNode);
if (child)
logging::Address("child", child);
else
logging::MsgEntry("child accessible: null");
logging::MsgEnd();
}
#endif
if (child) {
updateFlags |= UpdateTreeInternal(child, aIsInsert);