Backout bug 1251218
authorAlexander Surkov <surkov.alexander@gmail.com>
Fri, 26 Feb 2016 11:04:05 -0500
changeset 322159 dc371929fada4561a0bf36525a4bab5a0f3505d3
parent 322158 857849a7a3ebdaf0bb995979fbe39438b708553c
child 322160 73c742908f3fa81180be5df7d8b051260af5c5d2
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1251218
milestone47.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
Backout bug 1251218
accessible/base/TreeWalker.cpp
accessible/base/TreeWalker.h
accessible/generic/Accessible.cpp
accessible/generic/DocAccessible.cpp
accessible/generic/DocAccessible.h
--- a/accessible/base/TreeWalker.cpp
+++ b/accessible/base/TreeWalker.cpp
@@ -16,44 +16,28 @@
 using namespace mozilla;
 using namespace mozilla::a11y;
 
 ////////////////////////////////////////////////////////////////////////////////
 // TreeWalker
 ////////////////////////////////////////////////////////////////////////////////
 
 TreeWalker::
-  TreeWalker(Accessible* aContext) :
-  mDoc(aContext->Document()), mContext(aContext), mAnchorNode(nullptr),
-  mChildFilter(nsIContent::eSkipPlaceholderContent), mFlags(0)
-{
-  mChildFilter |= mContext->NoXBLKids() ?
-    nsIContent::eAllButXBL | nsIContent::eAllChildren;
-
-  mAnchorNode = mContext->IsDoc() ?
-    mDoc->DocumentNode()->GetRootElement() : mContext->GetContent();
-
-  if (mAnchorNode) {
-    PushState(mAnchorNode);
-  }
-
-  MOZ_COUNT_CTOR(TreeWalker);
-}
-
-TreeWalker::
   TreeWalker(Accessible* aContext, nsIContent* aContent, uint32_t aFlags) :
   mDoc(aContext->Document()), mContext(aContext), mAnchorNode(aContent),
-  mChildFilter(nsIContent::eSkipPlaceholderContent), mFlags(aFlags)
+  mFlags(aFlags)
 {
-  MOZ_ASSERT(aContent, "No anchor node for the accessible tree walker");
+  NS_ASSERTION(aContent, "No node for the accessible tree walker!");
 
-  mChildFilter |= mContext->NoXBLKids() ?
-    nsIContent::eAllButXBL | nsIContent::eAllChildren;
+  mChildFilter = mContext->NoXBLKids() ?
+    nsIContent::eAllButXBL : nsIContent::eAllChildren;
+  mChildFilter |= nsIContent::eSkipPlaceholderContent;
 
-  PushState(aContent);
+  if (aContent)
+    PushState(aContent);
 
   MOZ_COUNT_CTOR(TreeWalker);
 }
 
 TreeWalker::~TreeWalker()
 {
   MOZ_COUNT_DTOR(TreeWalker);
 }
--- a/accessible/base/TreeWalker.h
+++ b/accessible/base/TreeWalker.h
@@ -28,30 +28,24 @@ public:
   enum {
     // used to walk the existing tree of the given node
     eWalkCache = 1,
     // used to walk the context tree starting from given node
     eWalkContextTree = 2 | eWalkCache
   };
 
   /**
-   * Used to navigate and create if needed the accessible children.
-   */
-  explicit TreeWalker(Accessible* aContext);
-
-  /**
-   * Used to navigate the accessible children relative to the anchor.
+   * Constructor
    *
    * @param aContext [in] container accessible for the given node, used to
    *                   define accessible context
-   * @param aAnchorNode [in] the node the search will be prepared relative to
+   * @param aNode    [in] the node the search will be prepared relative to
    * @param aFlags   [in] flags (see enum above)
    */
-  TreeWalker(Accessible* aContext, nsIContent* aAnchorNode, uint32_t aFlags = 0);
-
+  TreeWalker(Accessible* aContext, nsIContent* aNode, uint32_t aFlags = 0);
   ~TreeWalker();
 
   /**
    * Return the next accessible.
    *
    * @note Returned accessible is bound to the document, if the accessible is
    *       rejected during tree creation then the caller should be unbind it
    *       from the document.
--- a/accessible/generic/Accessible.cpp
+++ b/accessible/generic/Accessible.cpp
@@ -2536,19 +2536,20 @@ Accessible::LastRelease()
   }
   // ... then die.
   delete this;
 }
 
 void
 Accessible::CacheChildren()
 {
-  NS_ENSURE_TRUE_VOID(Document());
-
-  TreeWalker walker(this);
+  DocAccessible* doc = Document();
+  NS_ENSURE_TRUE_VOID(doc);
+
+  TreeWalker walker(this, mContent);
 
   Accessible* child = nullptr;
   while ((child = walker.Next()) && AppendChild(child));
 }
 
 void
 Accessible::TestChildCache(Accessible* aCachedChild) const
 {
--- a/accessible/generic/DocAccessible.cpp
+++ b/accessible/generic/DocAccessible.cpp
@@ -1414,16 +1414,35 @@ if (!aNode->IsContent() || !aNode->AsCon
       return nullptr;
     }
   }
 
   return GetAccessible(aNode);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+// Accessible protected
+
+void
+DocAccessible::CacheChildren()
+{
+  // Search for accessible children starting from the document element since
+  // some web pages tend to insert elements under it rather than document body.
+  dom::Element* rootElm = mDocumentNode->GetRootElement();
+  if (!rootElm)
+    return;
+
+  TreeWalker walker(this, rootElm);
+  Accessible* child = nullptr;
+  while ((child = walker.Next())) {
+    AppendChild(child);
+  }
+}
+
+////////////////////////////////////////////////////////////////////////////////
 // Protected members
 
 void
 DocAccessible::NotifyOfLoading(bool aIsReloading)
 {
   // Mark the document accessible as loading, if it stays alive then we'll mark
   // it as loaded when we receive proper notification.
   mLoadState &= ~eDOMLoaded;
--- a/accessible/generic/DocAccessible.h
+++ b/accessible/generic/DocAccessible.h
@@ -354,16 +354,19 @@ public:
    */
   DocAccessibleChild* IPCDoc() const { return mIPCDoc; }
 
 protected:
   virtual ~DocAccessible();
 
   void LastRelease();
 
+  // Accessible
+  virtual void CacheChildren() override;
+
   // DocAccessible
   virtual nsresult AddEventListeners();
   virtual nsresult RemoveEventListeners();
 
   /**
    * Marks this document as loaded or loading.
    */
   void NotifyOfLoad(uint32_t aLoadEventType);