Bug 759133 - turn focus logging macros into standard a11y logging, r=tbsaunde
authorAlexander Surkov <surkov.alexander@gmail.com>
Thu, 27 Sep 2012 08:53:23 +0900
changeset 115085 ccdb0107dd618dd56d4f6f65f5cde515709e7f31
parent 115084 9f8dc0d8eb25af44def943dfd1bc6a10eacc346c
child 115086 b2afb3c28c6e53691c36dd22609486e81320f49f
push id239
push userakeybl@mozilla.com
push dateThu, 03 Jan 2013 21:54:43 +0000
treeherdermozilla-release@3a7b66445659 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstbsaunde
bugs759133
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 759133 - turn focus logging macros into standard a11y logging, r=tbsaunde
accessible/src/base/FocusManager.cpp
accessible/src/base/FocusManager.h
accessible/src/base/Logging.cpp
accessible/src/base/Logging.h
accessible/src/generic/DocAccessible.cpp
accessible/src/generic/RootAccessible.cpp
--- a/accessible/src/base/FocusManager.cpp
+++ b/accessible/src/base/FocusManager.cpp
@@ -109,18 +109,20 @@ FocusManager::IsInOrContainsFocus(const 
   }
 
   return eNone;
 }
 
 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;
 
   nsCOMPtr<nsINode> targetNode(do_QueryInterface(aTarget));
   if (targetNode) {
     DocAccessible* document =
       GetAccService()->GetDocAccessible(targetNode->OwnerDoc());
     if (document) {
@@ -135,18 +137,20 @@ FocusManager::NotifyOfDOMFocus(nsISuppor
         (this, &FocusManager::ProcessDOMFocus, targetNode);
     }
   }
 }
 
 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;
 
   // If DOM document stays focused then fire accessible focus event to process
   // the case when no element within this DOM document will be focused.
   nsCOMPtr<nsINode> targetNode(do_QueryInterface(aTarget));
   if (targetNode && targetNode->OwnerDoc() == FocusedDOMDocument()) {
     nsIDocument* DOMDoc = targetNode->OwnerDoc();
@@ -157,28 +161,33 @@ FocusManager::NotifyOfDOMBlur(nsISupport
         (this, &FocusManager::ProcessDOMFocus, DOMDoc);
     }
   }
 }
 
 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)
     return;
 
   mActiveItem = nullptr;
 
   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;
   }
   mActiveItem = aItem;
 
   // If active item is changed then fire accessible focus event on it, otherwise
   // if there's no an active item then fire focus event to accessible having
   // DOM focus.
@@ -207,25 +216,30 @@ FocusManager::DispatchFocusEvent(DocAcce
 {
   NS_PRECONDITION(aDocument, "No document for focused accessible!");
   if (aDocument) {
     nsRefPtr<AccEvent> event =
       new AccEvent(nsIAccessibleEvent::EVENT_FOCUS, aTarget,
                    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());
 
   Accessible* target = document->GetAccessibleOrContainer(aTarget);
   if (target && document) {
     // Check if still focused. Otherwise we can end up with storing the active
     // item for control that isn't focused anymore.
@@ -303,18 +317,20 @@ FocusManager::ProcessFocusEvent(AccEvent
     nsRefPtr<AccEvent> menuEndEvent =
       new AccEvent(nsIAccessibleEvent::EVENT_MENU_END, mActiveARIAMenubar,
                    fromUserInputFlag);
     nsEventShell::FireEvent(menuEndEvent);
 
     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);
   nsEventShell::FireEvent(focusEvent);
 
   // Fire scrolling_start event when the document receives the focus if it has
   // an anchor jump. If an accessible within the document receive the focus
   // then null out the anchor jump because it no longer applies.
--- a/accessible/src/base/FocusManager.h
+++ b/accessible/src/base/FocusManager.h
@@ -123,131 +123,9 @@ private:
 private:
   nsRefPtr<Accessible> mActiveItem;
   nsRefPtr<Accessible> mActiveARIAMenubar;
 };
 
 } // 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
--- a/accessible/src/base/Logging.cpp
+++ b/accessible/src/base/Logging.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "Logging.h"
 
+#include "Accessible-inl.h"
 #include "AccEvent.h"
 #include "DocAccessible.h"
 #include "nsAccessibilityService.h"
 #include "nsCoreUtils.h"
 #include "OuterDocAccessible.h"
 
 #include "nsDocShellLoadTypes.h"
 #include "nsIChannel.h"
@@ -345,16 +346,17 @@ GetDocLoadEventType(AccEvent* aEvent, ns
 
 ////////////////////////////////////////////////////////////////////////////////
 // namespace logging:: document life cycle logging methods
 
 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,
                  nsIRequest* aRequest, uint32_t aStateFlags)
 {
   MsgBegin(sDocLoadTitle, aMsg);
 
   nsCOMPtr<nsIDOMWindow> DOMWindow;
@@ -461,16 +463,82 @@ void
 logging::OuterDocDestroy(OuterDocAccessible* aOuterDoc)
 {
   MsgBegin(sDocDestroyTitle, "outerdoc shutdown");
   logging::Address("outerdoc", 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)
 {
   nsCOMPtr<nsISelectionPrivate> privSel(do_QueryInterface(aSelection));
 
   int16_t type = 0;
   privSel->GetType(&type);
 
   const char* strType = 0;
@@ -491,26 +559,44 @@ logging::MsgBegin(const char* aTitle, co
 {
   printf("\nA11Y %s: ", aTitle);
 
   va_list argptr;
   va_start(argptr, 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");
 }
 
 void
 logging::MsgEnd()
 {
   printf("  }\n");
 }
 
 void
+logging::SubMsgBegin()
+{
+  printf("  {\n");
+}
+
+void
+logging::SubMsgEnd()
+{
+  printf("  }\n");
+}
+
+void
 logging::MsgEntry(const char* aEntryText, ...)
 {
   printf("    ");
 
   va_list argptr;
   va_start(argptr, aEntryText);
   vprintf(aEntryText, argptr);
   va_end(argptr);
@@ -582,16 +668,44 @@ logging::Node(const char* aDescr, nsINod
   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::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()
 {
   if (IsEnabled(eStack)) {
     printf("  stack: \n");
     nsTraceRefcntImpl::WalkTheStack(stdout);
   }
 }
 
--- a/accessible/src/base/Logging.h
+++ b/accessible/src/base/Logging.h
@@ -80,29 +80,61 @@ void DocDestroy(const char* aMsg, nsIDoc
                 DocAccessible* aDocument = nullptr);
 
 /**
  * Log the outer document was destroyed.
  */
 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.
  */
 void SelChange(nsISelection* aSelection, DocAccessible* aDocument);
 
 /**
  * Log the message ('title: text' format) on new line. Print the start and end
  * boundaries of the message body designated by '{' and '}' (2 spaces indent for
  * body).
  */
 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).
  */
 void MsgEntry(const char* aEntryText, ...);
 
 /**
  * Log the text, two spaces offset is used.
  */
 void Text(const char* aText);
@@ -113,16 +145,21 @@ void Text(const char* aText);
 void Address(const char* aDescr, Accessible* aAcc);
 
 /**
  * Log the DOM node info as message entry.
  */
 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.
  */
 void Stack();
 
 /**
  * Enable logging of the specified modules, all other modules aren't logged.
  */
 void Enable(const nsAFlatCString& aModules);
--- a/accessible/src/generic/DocAccessible.cpp
+++ b/accessible/src/generic/DocAccessible.cpp
@@ -1225,18 +1225,21 @@ DocAccessible::ARIAActiveDescendantChang
   if (widget && widget->IsActiveWidget()) {
     nsAutoString id;
     if (aElm->GetAttr(kNameSpaceID_None, nsGkAtoms::aria_activedescendant, id)) {
       dom::Element* activeDescendantElm = aElm->OwnerDoc()->GetElementById(id);
       if (activeDescendantElm) {
         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
         }
       }
     }
   }
 }
 
 void
 DocAccessible::ContentAppended(nsIDocument* aDocument,
@@ -1408,17 +1411,20 @@ DocAccessible::UnbindFromDocument(Access
 {
   NS_ASSERTION(mAccessibleCache.GetWeak(aAccessible->UniqueID()),
                "Unbinding the unbound accessible!");
 
   // Fire focus event on accessible having DOM focus if active item was removed
   // 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.
   if (aAccessible->IsPrimaryForNode() &&
       mNodeToAccessibleMap.Get(aAccessible->GetNode()) == aAccessible)
     mNodeToAccessibleMap.Remove(aAccessible->GetNode());
 
   void* uniqueID = aAccessible->UniqueID();
--- a/accessible/src/generic/RootAccessible.cpp
+++ b/accessible/src/generic/RootAccessible.cpp
@@ -337,17 +337,20 @@ RootAccessible::ProcessDOMEvent(nsIDOMEv
     bool isEnabled = (state & (states::CHECKED | states::SELECTED)) != 0;
 
     nsRefPtr<AccEvent> accEvent =
       new AccStateChangeEvent(accessible, states::CHECKED, isEnabled);
     nsEventShell::FireEvent(accEvent);
 
     if (isEnabled) {
       FocusMgr()->ActiveItemChanged(accessible);
-      A11YDEBUG_FOCUS_ACTIVEITEMCHANGE_CAUSE("RadioStateChange", accessible)
+#ifdef DEBUG
+      if (logging::IsEnabled(logging::eFocus))
+        logging::ActiveItemChangeCausedBy("RadioStateChange", accessible);
+#endif
     }
 
     return;
   }
 
   if (eventType.EqualsLiteral("CheckboxStateChange")) {
     uint64_t state = accessible->State();
 
@@ -416,52 +419,64 @@ RootAccessible::ProcessDOMEvent(nsIDOMEv
   else if (eventType.EqualsLiteral("DOMMenuInactive")) {
     if (accessible->Role() == roles::MENUPOPUP) {
       nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_MENUPOPUP_END,
                               accessible);
     }
   }
   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
     // unique widget that may acquire focus from autocomplete popup while popup
     // stays open and has no active item. In case of XUL tree autocomplete
     // popup this event is fired for tree accessible.
     Accessible* widget =
       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
     nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_MENU_START,
                             accessible, eFromUserInput);
 
     // Notify of active item change when menubar gets active and if it has
     // current item. This is a case of mouseover (set current menuitem) and
     // mouse click (activate the menubar). If menubar doesn't have current item
     // (can be a case of menubar activation from keyboard) then ignore this
     // notification because later we'll receive DOMMenuItemActive event after
     // current menuitem is set.
     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
     nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_MENU_END,
                             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->
       FireDelayedAccessibleEvent(nsIAccessibleEvent::EVENT_VALUE_CHANGE,
                                  targetNode, AccEvent::eRemoveDupes);
   }
 #ifdef DEBUG_DRAGDROPSTART
   else if (eventType.EqualsLiteral("mouseover")) {
@@ -642,17 +657,20 @@ RootAccessible::HandlePopupHidingEvent(n
     // For menubars processing we listen DOMMenubarActive/Inactive
     // notifications.
     notifyOf = kNotifyOfFocus;
   }
 
   // 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.
   if (notifyOf & kNotifyOfState) {
     nsRefPtr<AccEvent> event =
       new AccStateChangeEvent(widget, states::EXPANDED, false);
     document->FireDelayedAccessibleEvent(event);
   }