2009-10-20 17:27:46 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=79: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2006-05-17 02:22:04 +00:00
|
|
|
|
|
|
|
#include "inDeepTreeWalker.h"
|
|
|
|
#include "inLayoutUtils.h"
|
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMNodeFilter.h"
|
|
|
|
#include "nsIDOMNodeList.h"
|
2006-05-17 02:38:46 +00:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2006-05-17 02:38:00 +00:00
|
|
|
#include "inIDOMUtils.h"
|
2011-04-08 01:04:40 +00:00
|
|
|
#include "nsIContent.h"
|
2013-05-01 22:50:08 +00:00
|
|
|
#include "nsContentList.h"
|
|
|
|
#include "ChildIterator.h"
|
|
|
|
#include "mozilla/dom/Element.h"
|
2006-05-17 02:22:04 +00:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* This implementation does not currently operaate according to the W3C spec.
|
2009-10-20 17:27:46 +00:00
|
|
|
* In particular it does NOT handle DOM mutations during the walk. It also
|
|
|
|
* ignores whatToShow and the filter.
|
2006-05-17 02:22:04 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
|
|
|
2014-09-24 05:20:43 +00:00
|
|
|
inDeepTreeWalker::inDeepTreeWalker()
|
2011-10-17 14:59:28 +00:00
|
|
|
: mShowAnonymousContent(false),
|
|
|
|
mShowSubDocuments(false),
|
2014-09-24 05:20:43 +00:00
|
|
|
mShowDocumentsAsNodes(false),
|
2006-05-17 02:38:15 +00:00
|
|
|
mWhatToShow(nsIDOMNodeFilter::SHOW_ALL)
|
2006-05-17 02:22:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-09-24 05:20:43 +00:00
|
|
|
inDeepTreeWalker::~inDeepTreeWalker()
|
|
|
|
{
|
2006-05-17 02:22:04 +00:00
|
|
|
}
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(inDeepTreeWalker,
|
2014-05-20 18:17:27 +00:00
|
|
|
inIDeepTreeWalker)
|
2006-05-17 02:22:04 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
|
|
// inIDeepTreeWalker
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
inDeepTreeWalker::GetShowAnonymousContent(bool *aShowAnonymousContent)
|
2006-05-17 02:22:04 +00:00
|
|
|
{
|
|
|
|
*aShowAnonymousContent = mShowAnonymousContent;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
inDeepTreeWalker::SetShowAnonymousContent(bool aShowAnonymousContent)
|
2006-05-17 02:22:04 +00:00
|
|
|
{
|
|
|
|
mShowAnonymousContent = aShowAnonymousContent;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
inDeepTreeWalker::GetShowSubDocuments(bool *aShowSubDocuments)
|
2006-05-17 02:22:04 +00:00
|
|
|
{
|
|
|
|
*aShowSubDocuments = mShowSubDocuments;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
inDeepTreeWalker::SetShowSubDocuments(bool aShowSubDocuments)
|
2006-05-17 02:22:04 +00:00
|
|
|
{
|
|
|
|
mShowSubDocuments = aShowSubDocuments;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-24 05:20:43 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
inDeepTreeWalker::GetShowDocumentsAsNodes(bool *aShowDocumentsAsNodes)
|
|
|
|
{
|
|
|
|
*aShowDocumentsAsNodes = mShowDocumentsAsNodes;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
inDeepTreeWalker::SetShowDocumentsAsNodes(bool aShowDocumentsAsNodes)
|
|
|
|
{
|
|
|
|
mShowDocumentsAsNodes = aShowDocumentsAsNodes;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-17 02:22:04 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
inDeepTreeWalker::Init(nsIDOMNode* aRoot, uint32_t aWhatToShow)
|
2006-05-17 02:22:04 +00:00
|
|
|
{
|
2014-09-24 05:20:43 +00:00
|
|
|
if (!aRoot) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2006-05-17 02:22:04 +00:00
|
|
|
mRoot = aRoot;
|
2014-09-24 05:20:43 +00:00
|
|
|
mCurrentNode = aRoot;
|
2006-05-17 02:22:04 +00:00
|
|
|
mWhatToShow = aWhatToShow;
|
|
|
|
|
2014-09-24 05:20:43 +00:00
|
|
|
mDOMUtils = do_GetService("@mozilla.org/inspector/dom-utils;1");
|
|
|
|
return mDOMUtils ? NS_OK : NS_ERROR_UNEXPECTED;
|
2006-05-17 02:22:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
|
|
// nsIDOMTreeWalker
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
inDeepTreeWalker::GetRoot(nsIDOMNode** aRoot)
|
|
|
|
{
|
|
|
|
*aRoot = mRoot;
|
|
|
|
NS_IF_ADDREF(*aRoot);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
inDeepTreeWalker::GetWhatToShow(uint32_t* aWhatToShow)
|
2006-05-17 02:22:04 +00:00
|
|
|
{
|
|
|
|
*aWhatToShow = mWhatToShow;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
inDeepTreeWalker::GetFilter(nsIDOMNodeFilter** aFilter)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
inDeepTreeWalker::GetCurrentNode(nsIDOMNode** aCurrentNode)
|
|
|
|
{
|
|
|
|
*aCurrentNode = mCurrentNode;
|
|
|
|
NS_IF_ADDREF(*aCurrentNode);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-24 05:20:43 +00:00
|
|
|
already_AddRefed<nsIDOMNode>
|
|
|
|
inDeepTreeWalker::GetParent()
|
2006-05-17 02:22:04 +00:00
|
|
|
{
|
2014-09-24 05:20:43 +00:00
|
|
|
if (mCurrentNode == mRoot) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> parent;
|
|
|
|
MOZ_ASSERT(mDOMUtils, "mDOMUtils should have been initiated already in Init");
|
|
|
|
mDOMUtils->GetParentForNode(mCurrentNode, mShowAnonymousContent,
|
|
|
|
getter_AddRefs(parent));
|
|
|
|
|
|
|
|
uint16_t nodeType = 0;
|
|
|
|
if (parent) {
|
|
|
|
parent->GetNodeType(&nodeType);
|
|
|
|
}
|
|
|
|
// For compatibility reasons by default we skip the document nodes
|
|
|
|
// from the walk.
|
|
|
|
if (!mShowDocumentsAsNodes &&
|
|
|
|
nodeType == nsIDOMNode::DOCUMENT_NODE &&
|
|
|
|
parent != mRoot) {
|
|
|
|
mDOMUtils->GetParentForNode(parent, mShowAnonymousContent,
|
|
|
|
getter_AddRefs(parent));
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent.forget();
|
2006-05-17 02:22:04 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 05:20:43 +00:00
|
|
|
static already_AddRefed<nsINodeList>
|
|
|
|
GetChildren(nsIDOMNode* aParent,
|
|
|
|
bool aShowAnonymousContent,
|
|
|
|
bool aShowSubDocuments)
|
2006-05-17 02:22:04 +00:00
|
|
|
{
|
2014-09-24 05:20:43 +00:00
|
|
|
MOZ_ASSERT(aParent);
|
2006-05-17 02:22:04 +00:00
|
|
|
|
2014-09-24 05:20:43 +00:00
|
|
|
nsCOMPtr<nsINodeList> ret;
|
|
|
|
if (aShowSubDocuments) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc = inLayoutUtils::GetSubDocumentFor(aParent);
|
|
|
|
if (domdoc) {
|
|
|
|
aParent = domdoc;
|
|
|
|
}
|
2006-05-17 02:22:04 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 05:20:43 +00:00
|
|
|
nsCOMPtr<nsIContent> parentAsContent = do_QueryInterface(aParent);
|
|
|
|
if (parentAsContent && aShowAnonymousContent) {
|
|
|
|
ret = parentAsContent->GetChildren(nsIContent::eAllChildren);
|
|
|
|
} else {
|
|
|
|
// If it's not a content, then it's a document (or an attribute but we can ignore that
|
|
|
|
// case here). If aShowAnonymousContent is false we also want to fall back to ChildNodes
|
|
|
|
// so we can skip any native anon content that GetChildren would return.
|
|
|
|
nsCOMPtr<nsINode> parentNode = do_QueryInterface(aParent);
|
|
|
|
MOZ_ASSERT(parentNode);
|
|
|
|
ret = parentNode->ChildNodes();
|
|
|
|
}
|
|
|
|
return ret.forget();
|
2006-05-17 02:22:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-09-24 05:20:43 +00:00
|
|
|
inDeepTreeWalker::SetCurrentNode(nsIDOMNode* aCurrentNode)
|
2006-05-17 02:22:04 +00:00
|
|
|
{
|
2014-09-24 05:20:43 +00:00
|
|
|
// mCurrentNode can only be null if init either failed, or has not been
|
|
|
|
// called yet.
|
|
|
|
if (!mCurrentNode || !aCurrentNode) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2009-10-20 17:27:46 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 05:20:43 +00:00
|
|
|
// If Document nodes are skipped by the walk, we should not allow
|
|
|
|
// one to set one as the current node either.
|
|
|
|
uint16_t nodeType = 0;
|
|
|
|
aCurrentNode->GetNodeType(&nodeType);
|
|
|
|
if (!mShowDocumentsAsNodes && nodeType == nsIDOMNode::DOCUMENT_NODE) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SetCurrentNode(aCurrentNode, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
inDeepTreeWalker::SetCurrentNode(nsIDOMNode* aCurrentNode,
|
|
|
|
nsINodeList* aSiblings)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aCurrentNode);
|
|
|
|
|
|
|
|
// We want to store the original state so in case of error
|
|
|
|
// we can restore that.
|
|
|
|
nsCOMPtr<nsINodeList> tmpSiblings = mSiblings;
|
|
|
|
nsCOMPtr<nsIDOMNode> tmpCurrent = mCurrentNode;
|
|
|
|
mSiblings = aSiblings;
|
|
|
|
mCurrentNode = aCurrentNode;
|
|
|
|
|
|
|
|
// If siblings were not passed in as argument we have to
|
|
|
|
// get them from the parent node of aCurrentNode.
|
|
|
|
// Note: in the mShowDoucmentsAsNodes case when a sub document
|
|
|
|
// is set as the current, we don't want to get the children
|
|
|
|
// from the iframe accidentally here, so let's just skip this
|
|
|
|
// part for document nodes, they should never have siblings.
|
|
|
|
uint16_t nodeType = 0;
|
|
|
|
aCurrentNode->GetNodeType(&nodeType);
|
|
|
|
if (!mSiblings && nodeType != nsIDOMNode::DOCUMENT_NODE) {
|
|
|
|
nsCOMPtr<nsIDOMNode> parent = GetParent();
|
|
|
|
if (parent) {
|
|
|
|
mSiblings = GetChildren(parent,
|
|
|
|
mShowAnonymousContent,
|
|
|
|
mShowSubDocuments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSiblings && mSiblings->Length()) {
|
|
|
|
// We cached all the siblings (if there are any) of the current node, but we
|
|
|
|
// still have to set the index too, to be able to iterate over them.
|
|
|
|
nsCOMPtr<nsIContent> currentAsContent = do_QueryInterface(mCurrentNode);
|
|
|
|
MOZ_ASSERT(currentAsContent);
|
|
|
|
int32_t index = mSiblings->IndexOf(currentAsContent);
|
|
|
|
if (index < 0) {
|
|
|
|
// If someone tries to set current node to some value that is not reachable
|
|
|
|
// otherwise, let's throw. (For example mShowAnonymousContent is false and some
|
|
|
|
// XBL anon content was passed in)
|
|
|
|
|
|
|
|
// Restore state first.
|
|
|
|
mCurrentNode = tmpCurrent;
|
|
|
|
mSiblings = tmpSiblings;
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
mCurrentIndex = index;
|
|
|
|
} else {
|
|
|
|
mCurrentIndex = -1;
|
2009-10-20 17:27:46 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
2006-05-17 02:22:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-09-24 05:20:43 +00:00
|
|
|
inDeepTreeWalker::ParentNode(nsIDOMNode** _retval)
|
2006-05-17 02:22:04 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*_retval = nullptr;
|
2014-09-24 05:20:43 +00:00
|
|
|
if (!mCurrentNode || mCurrentNode == mRoot) {
|
2009-10-20 17:27:46 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-24 05:20:43 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> parent = GetParent();
|
|
|
|
|
|
|
|
if (!parent) {
|
2009-10-20 17:27:46 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-09-24 05:20:43 +00:00
|
|
|
|
|
|
|
nsresult rv = SetCurrentNode(parent);
|
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
|
|
|
|
parent.forget(_retval);
|
2009-10-20 17:27:46 +00:00
|
|
|
return NS_OK;
|
2006-05-17 02:22:04 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 05:20:43 +00:00
|
|
|
// FirstChild and LastChild are very similar methods, this is the generic
|
|
|
|
// version for internal use. With aReverse = true it returns the LastChild.
|
|
|
|
nsresult
|
|
|
|
inDeepTreeWalker::EdgeChild(nsIDOMNode** _retval, bool aFront)
|
2006-05-17 02:22:04 +00:00
|
|
|
{
|
2009-10-20 17:27:46 +00:00
|
|
|
if (!mCurrentNode) {
|
2014-09-24 05:20:43 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-10-20 17:27:46 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 05:20:43 +00:00
|
|
|
*_retval = nullptr;
|
2009-10-20 17:27:46 +00:00
|
|
|
|
2014-09-24 05:20:43 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> echild;
|
|
|
|
if (mShowSubDocuments && mShowDocumentsAsNodes) {
|
|
|
|
// GetChildren below, will skip the document node from
|
|
|
|
// the walk. But if mShowDocumentsAsNodes is set to true
|
|
|
|
// we want to include the (sub)document itself too.
|
|
|
|
echild = inLayoutUtils::GetSubDocumentFor(mCurrentNode);
|
2009-10-20 17:27:46 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 05:20:43 +00:00
|
|
|
nsCOMPtr<nsINodeList> children;
|
|
|
|
if (!echild) {
|
|
|
|
children = GetChildren(mCurrentNode,
|
|
|
|
mShowAnonymousContent,
|
|
|
|
mShowSubDocuments);
|
|
|
|
if (children && children->Length() > 0) {
|
|
|
|
nsINode* childNode = children->Item(aFront ? 0 : children->Length() - 1);
|
|
|
|
echild = childNode ? childNode->AsDOMNode() : nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (echild) {
|
|
|
|
nsresult rv = SetCurrentNode(echild, children);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ADDREF(*_retval = mCurrentNode);
|
2009-10-20 17:27:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2006-05-17 02:22:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-09-24 05:20:43 +00:00
|
|
|
inDeepTreeWalker::FirstChild(nsIDOMNode** _retval)
|
2006-05-17 02:22:04 +00:00
|
|
|
{
|
2014-09-24 05:20:43 +00:00
|
|
|
return EdgeChild(_retval, /* aFront = */ true);
|
|
|
|
}
|
2009-10-20 17:27:46 +00:00
|
|
|
|
2014-09-24 05:20:43 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
inDeepTreeWalker::LastChild(nsIDOMNode **_retval)
|
|
|
|
{
|
|
|
|
return EdgeChild(_retval, /* aFront = */ false);
|
|
|
|
}
|
2009-10-20 17:27:46 +00:00
|
|
|
|
2014-09-24 05:20:43 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
inDeepTreeWalker::PreviousSibling(nsIDOMNode **_retval)
|
|
|
|
{
|
|
|
|
*_retval = nullptr;
|
|
|
|
if (!mCurrentNode || !mSiblings || mCurrentIndex < 1) {
|
2009-10-20 17:27:46 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-24 05:20:43 +00:00
|
|
|
nsIContent* prev = mSiblings->Item(--mCurrentIndex);
|
|
|
|
mCurrentNode = prev->AsDOMNode();
|
|
|
|
NS_ADDREF(*_retval = mCurrentNode);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
inDeepTreeWalker::NextSibling(nsIDOMNode **_retval)
|
|
|
|
{
|
|
|
|
*_retval = nullptr;
|
|
|
|
if (!mCurrentNode || !mSiblings ||
|
|
|
|
mCurrentIndex + 1 >= (int32_t) mSiblings->Length()) {
|
2009-10-20 17:27:46 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-24 05:20:43 +00:00
|
|
|
nsIContent* next = mSiblings->Item(++mCurrentIndex);
|
|
|
|
mCurrentNode = next->AsDOMNode();
|
|
|
|
NS_ADDREF(*_retval = mCurrentNode);
|
2009-10-20 17:27:46 +00:00
|
|
|
return NS_OK;
|
2006-05-17 02:22:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
inDeepTreeWalker::PreviousNode(nsIDOMNode **_retval)
|
|
|
|
{
|
2014-09-24 05:20:43 +00:00
|
|
|
if (!mCurrentNode || mCurrentNode == mRoot) {
|
2009-10-20 17:27:46 +00:00
|
|
|
// Nowhere to go from here
|
2012-07-30 14:20:58 +00:00
|
|
|
*_retval = nullptr;
|
2009-10-20 17:27:46 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
PreviousSibling(getter_AddRefs(node));
|
|
|
|
|
|
|
|
if (!node) {
|
|
|
|
return ParentNode(_retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now we're positioned at our previous sibling. But since the DOM tree
|
|
|
|
// traversal is depth-first, the previous node is its most deeply nested last
|
|
|
|
// child. Just loop until LastChild() returns null; since the LastChild()
|
|
|
|
// call that returns null won't affect our position, we will then be
|
|
|
|
// positioned at the correct node.
|
|
|
|
while (node) {
|
|
|
|
LastChild(getter_AddRefs(node));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*_retval = mCurrentNode);
|
|
|
|
return NS_OK;
|
2006-05-17 02:22:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
inDeepTreeWalker::NextNode(nsIDOMNode **_retval)
|
|
|
|
{
|
2014-09-24 05:20:43 +00:00
|
|
|
if (!mCurrentNode) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-20 17:27:46 +00:00
|
|
|
// First try our kids
|
|
|
|
FirstChild(_retval);
|
|
|
|
|
|
|
|
if (*_retval) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now keep trying next siblings up the parent chain, but if we
|
|
|
|
// discover there's nothing else restore our state.
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsIDOMNode* origCurrentNode = mCurrentNode;
|
|
|
|
#endif
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t lastChildCallsToMake = 0;
|
2006-05-17 02:22:04 +00:00
|
|
|
while (1) {
|
2009-10-20 17:27:46 +00:00
|
|
|
NextSibling(_retval);
|
|
|
|
|
|
|
|
if (*_retval) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> parent;
|
|
|
|
ParentNode(getter_AddRefs(parent));
|
|
|
|
if (!parent) {
|
|
|
|
// Nowhere else to go; we're done. Restore our state.
|
|
|
|
while (lastChildCallsToMake--) {
|
|
|
|
nsCOMPtr<nsIDOMNode> dummy;
|
|
|
|
LastChild(getter_AddRefs(dummy));
|
2006-05-17 02:22:04 +00:00
|
|
|
}
|
2009-10-20 17:27:46 +00:00
|
|
|
NS_ASSERTION(mCurrentNode == origCurrentNode,
|
|
|
|
"Didn't go back to the right node?");
|
2012-07-30 14:20:58 +00:00
|
|
|
*_retval = nullptr;
|
2009-10-20 17:27:46 +00:00
|
|
|
return NS_OK;
|
2006-05-17 02:22:04 +00:00
|
|
|
}
|
2009-10-20 17:27:46 +00:00
|
|
|
++lastChildCallsToMake;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_NOTREACHED("how did we get here?");
|
2006-05-17 02:22:04 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|