Bug 759133 - turn focus logging macros into standard a11y logging, r=tbsaunde

This commit is contained in:
Alexander Surkov 2012-09-27 08:53:23 +09:00
parent 9b90089db8
commit 7b9c191f81
6 changed files with 212 additions and 143 deletions

View File

@ -114,8 +114,10 @@ FocusManager::IsInOrContainsFocus(const Accessible* aAccessible) const
void
FocusManager::NotifyOfDOMFocus(nsISupports* aTarget)
{
A11YDEBUG_FOCUS_NOTIFICATION_SUPPORTSTARGET("DOM focus", "DOM focus target",
aTarget)
#ifdef DEBUG
if (logging::IsEnabled(logging::eFocus))
logging::FocusNotificationTarget("DOM focus", "Target", aTarget);
#endif
mActiveItem = nullptr;
@ -140,8 +142,10 @@ FocusManager::NotifyOfDOMFocus(nsISupports* aTarget)
void
FocusManager::NotifyOfDOMBlur(nsISupports* aTarget)
{
A11YDEBUG_FOCUS_NOTIFICATION_SUPPORTSTARGET("DOM blur", "DOM blur target",
aTarget)
#ifdef DEBUG
if (logging::IsEnabled(logging::eFocus))
logging::FocusNotificationTarget("DOM blur", "Target", aTarget);
#endif
mActiveItem = nullptr;
@ -162,8 +166,10 @@ FocusManager::NotifyOfDOMBlur(nsISupports* aTarget)
void
FocusManager::ActiveItemChanged(Accessible* aItem, bool aCheckIfActive)
{
A11YDEBUG_FOCUS_NOTIFICATION_ACCTARGET("active item changed",
"Active item", aItem)
#ifdef DEBUG
if (logging::IsEnabled(logging::eFocus))
logging::FocusNotificationTarget("active item changed", "Item", aItem);
#endif
// Nothing changed, happens for XUL trees and HTML selects.
if (aItem && aItem == mActiveItem)
@ -173,7 +179,10 @@ FocusManager::ActiveItemChanged(Accessible* aItem, bool aCheckIfActive)
if (aItem && aCheckIfActive) {
Accessible* widget = aItem->ContainerWidget();
A11YDEBUG_FOCUS_LOG_WIDGET("Active item widget", widget)
#ifdef DEBUG
if (logging::IsEnabled(logging::eFocus))
logging::ActiveWidget(widget);
#endif
if (!widget || !widget->IsActiveWidget() || !widget->AreItemsOperable())
return;
}
@ -212,15 +221,20 @@ FocusManager::DispatchFocusEvent(DocAccessible* aDocument,
eAutoDetect, AccEvent::eCoalesceOfSameType);
aDocument->FireDelayedAccessibleEvent(event);
A11YDEBUG_FOCUS_LOG_ACCTARGET("Focus notification", aTarget)
#ifdef DEBUG
if (logging::IsEnabled(logging::eFocus))
logging::FocusDispatched(aTarget);
#endif
}
}
void
FocusManager::ProcessDOMFocus(nsINode* aTarget)
{
A11YDEBUG_FOCUS_NOTIFICATION_DOMTARGET("Process DOM focus",
"Notification target", aTarget)
#ifdef DEBUG
if (logging::IsEnabled(logging::eFocus))
logging::FocusNotificationTarget("process DOM focus", "Target", aTarget);
#endif
DocAccessible* document =
GetAccService()->GetDocAccessible(aTarget->OwnerDoc());
@ -308,8 +322,10 @@ FocusManager::ProcessFocusEvent(AccEvent* aEvent)
mActiveARIAMenubar = nullptr;
}
A11YDEBUG_FOCUS_NOTIFICATION_ACCTARGET("FIRE FOCUS EVENT", "Focus target",
target)
#ifdef DEBUG
if (logging::IsEnabled(logging::eFocus))
logging::FocusNotificationTarget("fire focus event", "Target", target);
#endif
nsRefPtr<AccEvent> focusEvent =
new AccEvent(nsIAccessibleEvent::EVENT_FOCUS, target, fromUserInputFlag);

View File

@ -128,126 +128,4 @@ private:
} // namespace a11y
} // namespace mozilla
//#define A11YDEBUG_FOCUS
#ifdef A11YDEBUG_FOCUS
// Util macros (don't use them directly)
#define A11YDEBUG_FOCUS_STARTBLOCK \
printf(" {\n ");
#define A11YDEBUG_FOCUS_ENDBLOCK \
printf("\n }\n");
#define A11YDEBUG_FOCUS_BLOCKOFFSET \
printf(" ");
#define A11YDEBUG_FOCUS_LOG_TIME \
{ \
PRIntervalTime time = PR_IntervalNow(); \
uint32_t mins = (PR_IntervalToSeconds(time) / 60) % 60; \
uint32_t secs = PR_IntervalToSeconds(time) % 60; \
uint32_t msecs = PR_IntervalToMilliseconds(time) % 1000; \
printf("Time: %2d:%2d.%3d\n", mins, secs, msecs); \
}
#define A11YDEBUG_FOCUS_LOG_DOMNODE(aNode) \
if (aNode) { \
if (aNode->IsElement()) { \
dom::Element* targetElm = aNode->AsElement(); \
nsAutoCString tag; \
targetElm->Tag()->ToUTF8String(tag); \
nsAutoCString id; \
nsIAtom* atomid = targetElm->GetID(); \
if (atomid) \
atomid->ToUTF8String(id); \
printf("element %s@id='%s': %p", tag.get(), id.get(), (void*)aNode); \
} else if (aNode->IsNodeOfType(nsINode::eDOCUMENT)) { \
nsCOMPtr<nsIDocument> document = do_QueryInterface(aNode); \
nsIURI* uri = document->GetDocumentURI(); \
nsAutoCString spec; \
uri->GetSpec(spec); \
printf("document: %p; uri: %s", (void*)aNode, spec.get()); \
} \
}
#define A11YDEBUG_FOCUS_LOG_ACCESSIBLE(aAccessible) \
printf("accessible: %p; ", (void*)aAccessible); \
if (aAccessible) { \
nsAutoString role; \
GetAccService()->GetStringRole(aAccessible->Role(), role); \
nsAutoString name; \
aAccessible->Name(name); \
printf(" role: %s, name: %s; ", NS_ConvertUTF16toUTF8(role).get(), \
NS_ConvertUTF16toUTF8(name).get()); \
A11YDEBUG_FOCUS_LOG_DOMNODE(aAccessible->GetNode()) \
}
// Public macros
#define A11YDEBUG_FOCUS_LOG_DOMTARGET(aMsg, aTarget) \
A11YDEBUG_FOCUS_STARTBLOCK \
printf(aMsg "\n"); \
if (aTarget) { \
A11YDEBUG_FOCUS_BLOCKOFFSET \
A11YDEBUG_FOCUS_LOG_DOMNODE(aTarget) \
} \
A11YDEBUG_FOCUS_ENDBLOCK
#define A11YDEBUG_FOCUS_LOG_ACCTARGET(aMsg, aTarget) \
A11YDEBUG_FOCUS_STARTBLOCK \
printf(aMsg "\n"); \
A11YDEBUG_FOCUS_BLOCKOFFSET \
A11YDEBUG_FOCUS_LOG_ACCESSIBLE(aTarget) \
A11YDEBUG_FOCUS_ENDBLOCK
#define A11YDEBUG_FOCUS_LOG_WIDGET(aMsg, aWidget) \
A11YDEBUG_FOCUS_STARTBLOCK \
printf(aMsg "\n"); \
A11YDEBUG_FOCUS_BLOCKOFFSET \
A11YDEBUG_FOCUS_LOG_ACCESSIBLE(aWidget) \
printf("; widget is active: %s, has operable items: %s", \
(aWidget && aWidget->IsActiveWidget() ? "true" : "false"), \
(aWidget && aWidget->AreItemsOperable() ? "true" : "false")); \
A11YDEBUG_FOCUS_ENDBLOCK
#define A11YDEBUG_FOCUS_NOTIFICATION_SUPPORTSTARGET(aMsg, aTargetMsg, aTarget) \
printf("\nA11Y FOCUS: " aMsg ". "); \
A11YDEBUG_FOCUS_LOG_TIME \
if (aTarget) { \
A11YDEBUG_FOCUS_STARTBLOCK \
printf(aTargetMsg "\n"); \
A11YDEBUG_FOCUS_BLOCKOFFSET \
nsCOMPtr<nsINode> targetNode(do_QueryInterface(aTarget)); \
if (targetNode) { \
A11YDEBUG_FOCUS_LOG_DOMNODE(targetNode) \
} else { \
printf("window: %p", (void*)aTarget); \
} \
A11YDEBUG_FOCUS_ENDBLOCK \
}
#define A11YDEBUG_FOCUS_NOTIFICATION_DOMTARGET(aMsg, aTargetMsg, aTarget) \
printf("\nA11Y FOCUS: " aMsg ". "); \
A11YDEBUG_FOCUS_LOG_TIME \
A11YDEBUG_FOCUS_LOG_DOMTARGET(aTargetMsg, aTarget)
#define A11YDEBUG_FOCUS_NOTIFICATION_ACCTARGET(aMsg, aTargetMsg, aTarget) \
printf("\nA11Y FOCUS: " aMsg ". "); \
A11YDEBUG_FOCUS_LOG_TIME \
A11YDEBUG_FOCUS_LOG_ACCTARGET(aTargetMsg, aTarget)
#define A11YDEBUG_FOCUS_ACTIVEITEMCHANGE_CAUSE(aMsg, aTarget) \
A11YDEBUG_FOCUS_LOG_ACCTARGET("Caused by: " aMsg, aTarget)
#else
#define A11YDEBUG_FOCUS_LOG_DOMTARGET(aMsg, aTarget)
#define A11YDEBUG_FOCUS_LOG_ACCTARGET(aMsg, aTarget)
#define A11YDEBUG_FOCUS_LOG_WIDGET(aMsg, aWidget)
#define A11YDEBUG_FOCUS_NOTIFICATION_SUPPORTSTARGET(aMsg, aTargetMsg, aTarget)
#define A11YDEBUG_FOCUS_NOTIFICATION_DOMTARGET(aMsg, aTargetMsg, aTarget)
#define A11YDEBUG_FOCUS_NOTIFICATION_ACCTARGET(aMsg, aTargetMsg, aTarget)
#define A11YDEBUG_FOCUS_ACTIVEITEMCHANGE_CAUSE(aMsg, aTarget)
#endif
#endif

View File

@ -6,6 +6,7 @@
#include "Logging.h"
#include "Accessible-inl.h"
#include "AccEvent.h"
#include "DocAccessible.h"
#include "nsAccessibilityService.h"
@ -350,6 +351,7 @@ static const char* sDocLoadTitle = "DOCLOAD";
static const char* sDocCreateTitle = "DOCCREATE";
static const char* sDocDestroyTitle = "DOCDESTROY";
static const char* sDocEventTitle = "DOCEVENT";
static const char* sFocusTitle = "FOCUS";
void
logging::DocLoad(const char* aMsg, nsIWebProgress* aWebProgress,
@ -465,6 +467,72 @@ logging::OuterDocDestroy(OuterDocAccessible* aOuterDoc)
MsgEnd();
}
void
logging::FocusNotificationTarget(const char* aMsg, const char* aTargetDescr,
Accessible* aTarget)
{
MsgBegin(sFocusTitle, aMsg);
AccessibleNNode(aTargetDescr, aTarget);
MsgEnd();
}
void
logging::FocusNotificationTarget(const char* aMsg, const char* aTargetDescr,
nsINode* aTargetNode)
{
MsgBegin(sFocusTitle, aMsg);
Node(aTargetDescr, aTargetNode);
MsgEnd();
}
void
logging::FocusNotificationTarget(const char* aMsg, const char* aTargetDescr,
nsISupports* aTargetThing)
{
MsgBegin(sFocusTitle, aMsg);
if (aTargetThing) {
nsCOMPtr<nsINode> targetNode(do_QueryInterface(aTargetThing));
if (targetNode)
Node(aTargetDescr, targetNode);
else
printf(" %s: %p, window\n", aTargetDescr,
static_cast<void*>(aTargetThing));
}
MsgEnd();
}
void
logging::ActiveItemChangeCausedBy(const char* aCause, Accessible* aTarget)
{
SubMsgBegin();
printf(" Caused by: %s\n", aCause);
AccessibleNNode("Item", aTarget);
SubMsgEnd();
}
void
logging::ActiveWidget(Accessible* aWidget)
{
SubMsgBegin();
AccessibleNNode("Widget", aWidget);
printf(" Widget is active: %s, has operable items: %s\n",
(aWidget && aWidget->IsActiveWidget() ? "true" : "false"),
(aWidget && aWidget->AreItemsOperable() ? "true" : "false"));
SubMsgEnd();
}
void
logging::FocusDispatched(Accessible* aTarget)
{
SubMsgBegin();
AccessibleNNode("A11y target", aTarget);
SubMsgEnd();
}
void
logging::SelChange(nsISelection* aSelection, DocAccessible* aDocument)
{
@ -496,6 +564,12 @@ logging::MsgBegin(const char* aTitle, const char* aMsgText, ...)
vprintf(aMsgText, argptr);
va_end(argptr);
PRIntervalTime time = PR_IntervalNow();
uint32_t mins = (PR_IntervalToSeconds(time) / 60) % 60;
uint32_t secs = PR_IntervalToSeconds(time) % 60;
uint32_t msecs = PR_IntervalToMilliseconds(time) % 1000;
printf("; %02d:%02d.%03d", mins, secs, msecs);
printf("\n {\n");
}
@ -505,6 +579,18 @@ logging::MsgEnd()
printf(" }\n");
}
void
logging::SubMsgBegin()
{
printf(" {\n");
}
void
logging::SubMsgEnd()
{
printf(" }\n");
}
void
logging::MsgEntry(const char* aEntryText, ...)
{
@ -586,6 +672,34 @@ logging::Node(const char* aDescr, nsINode* aNode)
aDescr, static_cast<void*>(elm), tag.get(), id.get(), idxInParent);
}
void
logging::AccessibleNNode(const char* aDescr, Accessible* aAccessible)
{
printf(" %s: %p; ", aDescr, static_cast<void*>(aAccessible));
if (!aAccessible)
return;
nsAutoString role;
GetAccService()->GetStringRole(aAccessible->Role(), role);
nsAutoString name;
aAccessible->Name(name);
printf("role: %s, name: '%s';\n", NS_ConvertUTF16toUTF8(role).get(),
NS_ConvertUTF16toUTF8(name).get());
nsAutoCString nodeDescr(aDescr);
nodeDescr.AppendLiteral(" node");
Node(nodeDescr.get(), aAccessible->GetNode());
printf(" Document: %p, document node: %p\n",
static_cast<void*>(aAccessible->Document()),
static_cast<void*>(aAccessible->GetDocumentNode()));
printf(" Document");
LogDocURI(static_cast<nsIDocument*>(aAccessible->GetDocumentNode()));
printf("\n");
}
void
logging::Stack()
{

View File

@ -84,6 +84,31 @@ void DocDestroy(const char* aMsg, nsIDocument* aDocumentNode,
*/
void OuterDocDestroy(OuterDocAccessible* OuterDoc);
/**
* Log the focus notification target.
*/
void FocusNotificationTarget(const char* aMsg, const char* aTargetDescr,
Accessible* aTarget);
void FocusNotificationTarget(const char* aMsg, const char* aTargetDescr,
nsINode* aTargetNode);
void FocusNotificationTarget(const char* aMsg, const char* aTargetDescr,
nsISupports* aTargetThing);
/**
* Log a cause of active item descendant change (submessage).
*/
void ActiveItemChangeCausedBy(const char* aMsg, Accessible* aTarget);
/**
* Log the active widget (submessage).
*/
void ActiveWidget(Accessible* aWidget);
/**
* Log the focus event was dispatched (submessage).
*/
void FocusDispatched(Accessible* aTarget);
/**
* Log the selection change.
*/
@ -97,6 +122,13 @@ void SelChange(nsISelection* aSelection, DocAccessible* aDocument);
void MsgBegin(const char* aTitle, const char* aMsgText, ...);
void MsgEnd();
/**
* Print start and end boundaries of the message body designated by '{' and '}'
* (2 spaces indent for body).
*/
void SubMsgBegin();
void SubMsgEnd();
/**
* Log the entry into message body (4 spaces indent).
*/
@ -117,6 +149,11 @@ void Address(const char* aDescr, Accessible* aAcc);
*/
void Node(const char* aDescr, nsINode* aNode);
/**
* Log the accessible and its DOM node as a message entry.
*/
void AccessibleNNode(const char* aDescr, Accessible* aAccessible);
/**
* Log the call stack, two spaces offset is used.
*/

View File

@ -1230,8 +1230,11 @@ DocAccessible::ARIAActiveDescendantChanged(nsIContent* aElm)
Accessible* activeDescendant = GetAccessible(activeDescendantElm);
if (activeDescendant) {
FocusMgr()->ActiveItemChanged(activeDescendant, false);
A11YDEBUG_FOCUS_ACTIVEITEMCHANGE_CAUSE("ARIA activedescedant changed",
activeDescendant)
#ifdef DEBUG
if (logging::IsEnabled(logging::eFocus))
logging::ActiveItemChangeCausedBy("ARIA activedescedant changed",
activeDescendant);
#endif
}
}
}
@ -1413,7 +1416,10 @@ DocAccessible::UnbindFromDocument(Accessible* aAccessible)
// from the tree.
if (FocusMgr()->IsActiveItem(aAccessible)) {
FocusMgr()->ActiveItemChanged(nullptr);
A11YDEBUG_FOCUS_ACTIVEITEMCHANGE_CAUSE("tree shutdown", aAccessible)
#ifdef DEBUG
if (logging::IsEnabled(logging::eFocus))
logging::ActiveItemChangeCausedBy("tree shutdown", aAccessible);
#endif
}
// Remove an accessible from node-to-accessible map if it exists there.

View File

@ -342,7 +342,10 @@ RootAccessible::ProcessDOMEvent(nsIDOMEvent* aDOMEvent)
if (isEnabled) {
FocusMgr()->ActiveItemChanged(accessible);
A11YDEBUG_FOCUS_ACTIVEITEMCHANGE_CAUSE("RadioStateChange", accessible)
#ifdef DEBUG
if (logging::IsEnabled(logging::eFocus))
logging::ActiveItemChangeCausedBy("RadioStateChange", accessible);
#endif
}
return;
@ -421,7 +424,10 @@ RootAccessible::ProcessDOMEvent(nsIDOMEvent* aDOMEvent)
}
else if (eventType.EqualsLiteral("DOMMenuItemActive")) {
FocusMgr()->ActiveItemChanged(accessible);
A11YDEBUG_FOCUS_ACTIVEITEMCHANGE_CAUSE("DOMMenuItemActive", accessible)
#ifdef DEBUG
if (logging::IsEnabled(logging::eFocus))
logging::ActiveItemChangeCausedBy("DOMMenuItemActive", accessible);
#endif
}
else if (eventType.EqualsLiteral("DOMMenuItemInactive")) {
// Process DOMMenuItemInactive event for autocomplete only because this is
@ -432,7 +438,10 @@ RootAccessible::ProcessDOMEvent(nsIDOMEvent* aDOMEvent)
accessible->IsWidget() ? accessible : accessible->ContainerWidget();
if (widget && widget->IsAutoCompletePopup()) {
FocusMgr()->ActiveItemChanged(nullptr);
A11YDEBUG_FOCUS_ACTIVEITEMCHANGE_CAUSE("DOMMenuItemInactive", accessible)
#ifdef DEBUG
if (logging::IsEnabled(logging::eFocus))
logging::ActiveItemChangeCausedBy("DOMMenuItemInactive", accessible);
#endif
}
}
else if (eventType.EqualsLiteral("DOMMenuBarActive")) { // Always from user input
@ -448,7 +457,10 @@ RootAccessible::ProcessDOMEvent(nsIDOMEvent* aDOMEvent)
Accessible* activeItem = accessible->CurrentItem();
if (activeItem) {
FocusMgr()->ActiveItemChanged(activeItem);
A11YDEBUG_FOCUS_ACTIVEITEMCHANGE_CAUSE("DOMMenuBarActive", accessible)
#ifdef DEBUG
if (logging::IsEnabled(logging::eFocus))
logging::ActiveItemChangeCausedBy("DOMMenuBarActive", accessible);
#endif
}
}
else if (eventType.EqualsLiteral("DOMMenuBarInactive")) { // Always from user input
@ -456,7 +468,10 @@ RootAccessible::ProcessDOMEvent(nsIDOMEvent* aDOMEvent)
accessible, eFromUserInput);
FocusMgr()->ActiveItemChanged(nullptr);
A11YDEBUG_FOCUS_ACTIVEITEMCHANGE_CAUSE("DOMMenuBarInactive", accessible)
#ifdef DEBUG
if (logging::IsEnabled(logging::eFocus))
logging::ActiveItemChangeCausedBy("DOMMenuBarInactive", accessible);
#endif
}
else if (eventType.EqualsLiteral("ValueChange")) {
targetDocument->
@ -647,7 +662,10 @@ RootAccessible::HandlePopupHidingEvent(nsINode* aPopupNode)
// Restore focus to where it was.
if (notifyOf & kNotifyOfFocus) {
FocusMgr()->ActiveItemChanged(nullptr);
A11YDEBUG_FOCUS_ACTIVEITEMCHANGE_CAUSE("popuphiding", popup)
#ifdef DEBUG
if (logging::IsEnabled(logging::eFocus))
logging::ActiveItemChangeCausedBy("popuphiding", popup);
#endif
}
// Fire expanded state change event.