Bug 1278294 - move accessible tree logging into separate method, part=6, r=yzen
authorAlexander Surkov <surkov.alexander@gmail.com>
Mon, 20 Jun 2016 11:35:38 -0400
changeset 302099 ac276f95b75118731e3ef913f2786858e7c7d206
parent 302098 8623823c103f0dfe35a4094f6e6752e65633deb8
child 302100 54d410626a98bfb517445a727c2683e81fa3105e
push id78590
push usersurkov.alexander@gmail.com
push dateMon, 20 Jun 2016 15:36:01 +0000
treeherdermozilla-inbound@ac276f95b751 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyzen
bugs1278294
milestone50.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 1278294 - move accessible tree logging into separate method, part=6, r=yzen
accessible/base/EventTree.cpp
accessible/base/EventTree.h
accessible/base/Logging.cpp
accessible/base/Logging.h
accessible/generic/Accessible.h
--- a/accessible/base/EventTree.cpp
+++ b/accessible/base/EventTree.cpp
@@ -31,62 +31,20 @@ TreeMutation::TreeMutation(Accessible* a
 
 #ifdef A11Y_LOG
   if (mEventTree != kNoEventTree && logging::IsEnabled(logging::eEventTree)) {
     logging::MsgBegin("EVENTS_TREE", "reordering tree before");
     logging::AccessibleInfo("reordering for", mParent);
     Controller()->RootEventTree().Log();
     logging::MsgEnd();
 
-    logging::MsgBegin("EVENTS_TREE", "Container tree");
     if (logging::IsEnabled(logging::eVerbose)) {
-      nsAutoString level;
-      Accessible* root = mParent->Document();
-      do {
-        const char* prefix = "";
-        if (mParent == root) {
-          prefix = "_X_";
-        }
-        else {
-          const EventTree& ret = Controller()->RootEventTree();
-          if (ret.Find(root)) {
-            prefix = "_с_";
-          }
-        }
-
-        printf("%s", NS_ConvertUTF16toUTF8(level).get());
-        logging::AccessibleInfo(prefix, root);
-        if (root->FirstChild() && !root->FirstChild()->IsDoc()) {
-          level.Append(NS_LITERAL_STRING("  "));
-          root = root->FirstChild();
-          continue;
-        }
-        int32_t idxInParent = root->mParent ?
-          root->mParent->mChildren.IndexOf(root) : -1;
-        if (idxInParent != -1 &&
-            idxInParent < static_cast<int32_t>(root->mParent->mChildren.Length() - 1)) {
-          root = root->mParent->mChildren.ElementAt(idxInParent + 1);
-          continue;
-        }
-
-        while ((root = root->Parent()) && !root->IsDoc()) {
-          level.Cut(0, 2);
-
-          int32_t idxInParent = root->mParent ?
-          root->mParent->mChildren.IndexOf(root) : -1;
-          if (idxInParent != -1 &&
-              idxInParent < static_cast<int32_t>(root->mParent->mChildren.Length() - 1)) {
-            root = root->mParent->mChildren.ElementAt(idxInParent + 1);
-            break;
-          }
-        }
-      }
-      while (root && !root->IsDoc());
+      logging::Tree("EVENTS_TREE", "Container tree", mParent->Document(),
+                    PrefixLog, static_cast<void*>(this));
     }
-    logging::MsgEnd();
   }
 #endif
 
   mParent->mStateFlags |= Accessible::eKidsMutating;
 }
 
 TreeMutation::~TreeMutation()
 {
@@ -168,16 +126,32 @@ TreeMutation::Done()
     logging::MsgBegin("EVENTS_TREE", "reordering tree after");
     logging::AccessibleInfo("reordering for", mParent);
     Controller()->RootEventTree().Log();
     logging::MsgEnd();
   }
 #endif
 }
 
+#ifdef A11Y_LOG
+const char*
+TreeMutation::PrefixLog(void* aData, Accessible* aAcc)
+{
+  TreeMutation* thisObj = reinterpret_cast<TreeMutation*>(aData);
+  if (thisObj->mParent == aAcc) {
+    return "_X_";
+  }
+  const EventTree& ret = thisObj->Controller()->RootEventTree();
+  if (ret.Find(aAcc)) {
+    return "_с_";
+  }
+  return "";
+}
+#endif
+
 
 ////////////////////////////////////////////////////////////////////////////////
 // EventTree
 
 void
 EventTree::Process(const RefPtr<DocAccessible>& aDeathGrip)
 {
   while (mFirst) {
--- a/accessible/base/EventTree.h
+++ b/accessible/base/EventTree.h
@@ -34,16 +34,20 @@ public:
   void Done();
 
 private:
   NotificationController* Controller() const
     { return mParent->Document()->Controller(); }
 
   static EventTree* const kNoEventTree;
 
+#ifdef A11Y_LOG
+  static const char* PrefixLog(void* aData, Accessible*);
+#endif
+
   Accessible* mParent;
   uint32_t mStartIdx;
   uint32_t mStateFlagsCopy;
   EventTree* mEventTree;
 
 #ifdef DEBUG
   bool mIsDone;
 #endif
--- a/accessible/base/Logging.cpp
+++ b/accessible/base/Logging.cpp
@@ -669,16 +669,57 @@ logging::TreeInfo(const char* aMsg, uint
     for (uint32_t idx = 0; idx < aParent->ChildCount(); idx++) {
       AccessibleInfo("child", aParent->GetChildAt(idx));
     }
     MsgEnd();
   }
 }
 
 void
+logging::Tree(const char* aTitle, const char* aMsgText,
+              DocAccessible* aDocument, GetTreePrefix aPrefixFunc,
+              void* aGetTreePrefixData)
+{
+  logging::MsgBegin(aTitle, aMsgText);
+
+  nsAutoString level;
+  Accessible* root = aDocument;
+  do {
+    const char* prefix = aPrefixFunc ? aPrefixFunc(aGetTreePrefixData, root) : "";
+    printf("%s", NS_ConvertUTF16toUTF8(level).get());
+    logging::AccessibleInfo(prefix, root);
+    if (root->FirstChild() && !root->FirstChild()->IsDoc()) {
+      level.Append(NS_LITERAL_STRING("  "));
+      root = root->FirstChild();
+      continue;
+    }
+    int32_t idxInParent = !root->IsDoc() && root->mParent ?
+      root->mParent->mChildren.IndexOf(root) : -1;
+    if (idxInParent != -1 &&
+        idxInParent < static_cast<int32_t>(root->mParent->mChildren.Length() - 1)) {
+      root = root->mParent->mChildren.ElementAt(idxInParent + 1);
+      continue;
+    }
+    while (!root->IsDoc() && (root = root->Parent())) {
+      level.Cut(0, 2);
+      int32_t idxInParent = !root->IsDoc() && root->mParent ?
+        root->mParent->mChildren.IndexOf(root) : -1;
+      if (idxInParent != -1 &&
+          idxInParent < static_cast<int32_t>(root->mParent->mChildren.Length() - 1)) {
+        root = root->mParent->mChildren.ElementAt(idxInParent + 1);
+        break;
+      }
+    }
+  }
+  while (root && !root->IsDoc());
+
+  logging::MsgEnd();
+}
+
+void
 logging::MsgBegin(const char* aTitle, const char* aMsgText, ...)
 {
   printf("\nA11Y %s: ", aTitle);
 
   va_list argptr;
   va_start(argptr, aMsgText);
   vprintf(aMsgText, argptr);
   va_end(argptr);
--- a/accessible/base/Logging.h
+++ b/accessible/base/Logging.h
@@ -135,16 +135,23 @@ void SelChange(nsISelection* aSelection,
  */
 void TreeInfo(const char* aMsg, uint32_t aExtraFlags, ...);
 void TreeInfo(const char* aMsg, uint32_t aExtraFlags,
               const char* aMsg1, Accessible* aAcc,
               const char* aMsg2, nsINode* aNode);
 void TreeInfo(const char* aMsg, uint32_t aExtraFlags, Accessible* aParent);
 
 /**
+ * Log the accessible tree.
+ */
+typedef const char* (*GetTreePrefix)(void* aData, Accessible*);
+void Tree(const char* aTitle, const char* aMsgText, DocAccessible* aDoc,
+          GetTreePrefix aPrefixFunc = nullptr, void* aGetTreePrefixData = nullptr);
+
+/**
  * 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();
 
 /**
--- a/accessible/generic/Accessible.h
+++ b/accessible/generic/Accessible.h
@@ -45,16 +45,24 @@ class ProxyAccessible;
 class Relation;
 class RootAccessible;
 class TableAccessible;
 class TableCellAccessible;
 class TextLeafAccessible;
 class XULLabelAccessible;
 class XULTreeAccessible;
 
+#ifdef A11Y_LOG
+namespace logging {
+  typedef const char* (*GetTreePrefix)(void* aData, Accessible*);
+  void Tree(const char* aTitle, const char* aMsgText, DocAccessible* aDoc,
+            GetTreePrefix aPrefixFunc, void* GetTreePrefixData);
+};
+#endif
+
 /**
  * Name type flags.
  */
 enum ENameValueFlag {
   /**
    * Name either
    *  a) present (not empty): !name.IsEmpty()
    *  b) no name (was missed): name.IsVoid()
@@ -1115,16 +1123,22 @@ protected:
    */
   uint32_t mStateFlags : kStateFlagsBits;
   uint32_t mContextFlags : kContextFlagsBits;
   uint32_t mType : kTypeBits;
   uint32_t mGenericTypes : kGenericTypesBits;
 
   void StaticAsserts() const;
 
+#ifdef A11Y_LOG
+  friend void logging::Tree(const char* aTitle, const char* aMsgText,
+                            DocAccessible* aDoc,
+                            logging::GetTreePrefix aPrefixFunc,
+                            void* aGetTreePrefixData);
+#endif
   friend class DocAccessible;
   friend class xpcAccessible;
   friend class TreeMutation;
 
   nsAutoPtr<mozilla::a11y::EmbeddedObjCollector> mEmbeddedObjCollector;
   union {
     int32_t mIndexOfEmbeddedChild;
     uint32_t mProxyInterfaces;