2008-07-22 04:38:52 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
2012-05-21 15:12:37 +04: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 04:38:52 +04:00
|
|
|
|
|
|
|
#include "nsTraversal.h"
|
|
|
|
|
|
|
|
#include "nsIDOMNode.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2012-07-02 03:45:59 +04:00
|
|
|
#include "nsINode.h"
|
2013-02-27 00:10:15 +04:00
|
|
|
#include "mozilla/AutoRestore.h"
|
2008-07-22 04:38:52 +04:00
|
|
|
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
|
2013-02-27 00:10:15 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2008-07-22 04:38:52 +04:00
|
|
|
nsTraversal::nsTraversal(nsINode *aRoot,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aWhatToShow,
|
2018-02-01 22:26:12 +03:00
|
|
|
NodeFilter* aFilter) :
|
2008-07-22 04:38:52 +04:00
|
|
|
mRoot(aRoot),
|
|
|
|
mWhatToShow(aWhatToShow),
|
2018-02-01 22:26:12 +03:00
|
|
|
mFilter(aFilter),
|
2011-10-17 18:59:28 +04:00
|
|
|
mInAcceptNode(false)
|
2008-07-22 04:38:52 +04: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 21:56:42 +04:00
|
|
|
* @param aResult Whether we succeeded
|
2018-02-01 22:26:12 +03:00
|
|
|
* @returns Filtervalue. See NodeFilter.webidl
|
2008-07-22 04:38:52 +04:00
|
|
|
*/
|
2013-02-28 21:56:42 +04:00
|
|
|
int16_t
|
|
|
|
nsTraversal::TestNode(nsINode* aNode, mozilla::ErrorResult& aResult)
|
2008-07-22 04:38:52 +04:00
|
|
|
{
|
2013-02-28 21:56:42 +04:00
|
|
|
if (mInAcceptNode) {
|
|
|
|
aResult.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-07-22 04:38:52 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t nodeType = aNode->NodeType();
|
2008-07-22 04:38:52 +04:00
|
|
|
|
|
|
|
if (nodeType <= 12 && !((1 << (nodeType-1)) & mWhatToShow)) {
|
2013-02-28 21:56:42 +04:00
|
|
|
return nsIDOMNodeFilter::FILTER_SKIP;
|
2008-07-22 04:38:52 +04:00
|
|
|
}
|
|
|
|
|
2018-02-01 22:26:12 +03:00
|
|
|
if (!mFilter) {
|
2013-02-27 00:10:15 +04:00
|
|
|
// No filter, just accept
|
2013-02-28 21:56:42 +04:00
|
|
|
return nsIDOMNodeFilter::FILTER_ACCEPT;
|
2013-02-27 00:10:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
AutoRestore<bool> inAcceptNode(mInAcceptNode);
|
|
|
|
mInAcceptNode = true;
|
2018-02-01 22:26:12 +03:00
|
|
|
// No need to pass in an execution reason, since the generated default,
|
|
|
|
// "NodeFilter.acceptNode", is pretty much exactly what we'd say anyway.
|
|
|
|
return mFilter->AcceptNode(*aNode, aResult, nullptr,
|
|
|
|
CallbackObject::eRethrowExceptions);
|
2008-07-22 04:38:52 +04:00
|
|
|
}
|