2008-07-22 00:38:52 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
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/. */
|
2008-07-22 00:38:52 +00:00
|
|
|
|
|
|
|
#include "nsTraversal.h"
|
|
|
|
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIDOMNodeFilter.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2012-07-01 23:45:59 +00:00
|
|
|
#include "nsINode.h"
|
2008-07-22 00:38:52 +00:00
|
|
|
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
|
|
|
|
nsTraversal::nsTraversal(nsINode *aRoot,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aWhatToShow,
|
2013-02-26 20:34:25 +00:00
|
|
|
nsIDOMNodeFilter *aFilter) :
|
2008-07-22 00:38:52 +00:00
|
|
|
mRoot(aRoot),
|
|
|
|
mWhatToShow(aWhatToShow),
|
|
|
|
mFilter(aFilter),
|
2011-10-17 14:59:28 +00:00
|
|
|
mInAcceptNode(false)
|
2008-07-22 00:38:52 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aRoot, "invalid root in call to nsTraversal constructor");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTraversal::~nsTraversal()
|
|
|
|
{
|
|
|
|
/* destructor code */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tests if and how a node should be filtered. Uses mWhatToShow and
|
|
|
|
* mFilter to test the node.
|
|
|
|
* @param aNode Node to test
|
|
|
|
* @param _filtered Returned filtervalue. See nsIDOMNodeFilter.idl
|
|
|
|
* @returns Errorcode
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
nsresult nsTraversal::TestNode(nsINode* aNode, int16_t* _filtered)
|
2008-07-22 00:38:52 +00:00
|
|
|
{
|
2010-04-16 18:45:13 +00:00
|
|
|
NS_ENSURE_TRUE(!mInAcceptNode, NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
|
2013-02-26 20:34:25 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2008-07-22 00:38:52 +00:00
|
|
|
*_filtered = nsIDOMNodeFilter::FILTER_SKIP;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t nodeType = aNode->NodeType();
|
2008-07-22 00:38:52 +00:00
|
|
|
|
|
|
|
if (nodeType <= 12 && !((1 << (nodeType-1)) & mWhatToShow)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-02-26 20:34:25 +00:00
|
|
|
if (mFilter) {
|
|
|
|
nsCOMPtr<nsIDOMNode> domNode = do_QueryInterface(aNode);
|
2011-10-17 14:59:28 +00:00
|
|
|
mInAcceptNode = true;
|
2013-02-26 20:34:25 +00:00
|
|
|
rv = mFilter->AcceptNode(domNode, _filtered);
|
|
|
|
mInAcceptNode = false;
|
|
|
|
return rv;
|
2008-07-22 00:38:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-26 20:34:25 +00:00
|
|
|
*_filtered = nsIDOMNodeFilter::FILTER_ACCEPT;
|
|
|
|
return NS_OK;
|
2008-07-22 00:38:52 +00:00
|
|
|
}
|