diff --git a/accessible/base/TreeWalker.cpp b/accessible/base/TreeWalker.cpp index 34f21d08a97..de3d1554690 100644 --- a/accessible/base/TreeWalker.cpp +++ b/accessible/base/TreeWalker.cpp @@ -20,35 +20,19 @@ 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); } diff --git a/accessible/base/TreeWalker.h b/accessible/base/TreeWalker.h index c5fa8cae30e..d35c8147ce1 100644 --- a/accessible/base/TreeWalker.h +++ b/accessible/base/TreeWalker.h @@ -33,20 +33,14 @@ public: }; /** - * 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(); /** diff --git a/accessible/generic/Accessible.cpp b/accessible/generic/Accessible.cpp index da70dcaf65a..960823ae511 100644 --- a/accessible/generic/Accessible.cpp +++ b/accessible/generic/Accessible.cpp @@ -2541,9 +2541,10 @@ Accessible::LastRelease() void Accessible::CacheChildren() { - NS_ENSURE_TRUE_VOID(Document()); + DocAccessible* doc = Document(); + NS_ENSURE_TRUE_VOID(doc); - TreeWalker walker(this); + TreeWalker walker(this, mContent); Accessible* child = nullptr; while ((child = walker.Next()) && AppendChild(child)); diff --git a/accessible/generic/DocAccessible.cpp b/accessible/generic/DocAccessible.cpp index ae610e353db..49993d8c94b 100644 --- a/accessible/generic/DocAccessible.cpp +++ b/accessible/generic/DocAccessible.cpp @@ -1418,6 +1418,25 @@ if (!aNode->IsContent() || !aNode->AsContent()->IsHTMLElement(nsGkAtoms::area)) 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 diff --git a/accessible/generic/DocAccessible.h b/accessible/generic/DocAccessible.h index d889572c631..d42af922203 100644 --- a/accessible/generic/DocAccessible.h +++ b/accessible/generic/DocAccessible.h @@ -359,6 +359,9 @@ protected: void LastRelease(); + // Accessible + virtual void CacheChildren() override; + // DocAccessible virtual nsresult AddEventListeners(); virtual nsresult RemoveEventListeners();