2008-07-21 17:38:52 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
2012-05-21 04:12:37 -07: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-21 17:38:52 -07:00
|
|
|
|
|
|
|
#include "nsTraversal.h"
|
|
|
|
|
|
|
|
#include "nsIDOMNode.h"
|
2013-02-28 11:41:30 -08:00
|
|
|
#include "nsIDOMNodeFilter.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2012-07-01 16:45:59 -07:00
|
|
|
#include "nsINode.h"
|
2013-02-28 11:41:30 -08:00
|
|
|
#include "mozilla/dom/NodeFilterBinding.h"
|
2013-02-26 12:10:15 -08:00
|
|
|
#include "mozilla/AutoRestore.h"
|
2008-07-21 17:38:52 -07:00
|
|
|
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
|
2013-02-26 12:10:15 -08:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2008-07-21 17:38:52 -07:00
|
|
|
nsTraversal::nsTraversal(nsINode *aRoot,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aWhatToShow,
|
2013-02-26 12:10:15 -08:00
|
|
|
const NodeFilterHolder &aFilter) :
|
2008-07-21 17:38:52 -07:00
|
|
|
mRoot(aRoot),
|
|
|
|
mWhatToShow(aWhatToShow),
|
|
|
|
mFilter(aFilter),
|
2011-10-17 07:59:28 -07:00
|
|
|
mInAcceptNode(false)
|
2008-07-21 17:38:52 -07: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
|
2013-02-28 11:41:30 -08:00
|
|
|
* @param _filtered Returned filtervalue. See nsIDOMNodeFilter.idl
|
|
|
|
* @returns Errorcode
|
2008-07-21 17:38:52 -07:00
|
|
|
*/
|
2013-02-28 11:41:30 -08:00
|
|
|
nsresult nsTraversal::TestNode(nsINode* aNode, int16_t* _filtered)
|
2008-07-21 17:38:52 -07:00
|
|
|
{
|
2013-02-28 11:41:30 -08:00
|
|
|
NS_ENSURE_TRUE(!mInAcceptNode, NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
|
|
|
|
*_filtered = nsIDOMNodeFilter::FILTER_SKIP;
|
2008-07-21 17:38:52 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t nodeType = aNode->NodeType();
|
2008-07-21 17:38:52 -07:00
|
|
|
|
|
|
|
if (nodeType <= 12 && !((1 << (nodeType-1)) & mWhatToShow)) {
|
2013-02-28 11:41:30 -08:00
|
|
|
return NS_OK;
|
2008-07-21 17:38:52 -07:00
|
|
|
}
|
|
|
|
|
2013-02-26 12:10:15 -08:00
|
|
|
if (!mFilter.GetISupports()) {
|
|
|
|
// No filter, just accept
|
2013-02-28 11:41:30 -08:00
|
|
|
*_filtered = nsIDOMNodeFilter::FILTER_ACCEPT;
|
|
|
|
return NS_OK;
|
2013-02-26 12:10:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mFilter.HasWebIDLCallback()) {
|
|
|
|
AutoRestore<bool> inAcceptNode(mInAcceptNode);
|
2011-10-17 07:59:28 -07:00
|
|
|
mInAcceptNode = true;
|
2013-02-28 11:41:30 -08:00
|
|
|
ErrorResult res;
|
|
|
|
*_filtered = mFilter.GetWebIDLCallback()->AcceptNode(*aNode, res);
|
|
|
|
return res.ErrorCode();
|
2008-07-21 17:38:52 -07:00
|
|
|
}
|
|
|
|
|
2013-02-26 12:10:15 -08:00
|
|
|
nsCOMPtr<nsIDOMNode> domNode = do_QueryInterface(aNode);
|
|
|
|
AutoRestore<bool> inAcceptNode(mInAcceptNode);
|
|
|
|
mInAcceptNode = true;
|
2013-02-28 11:41:30 -08:00
|
|
|
return mFilter.GetXPCOMCallback()->AcceptNode(domNode, _filtered);
|
2008-07-21 17:38:52 -07:00
|
|
|
}
|