summaryrefslogtreecommitdiffstats
path: root/dom/base/nsTraversal.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /dom/base/nsTraversal.cpp
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/nsTraversal.cpp')
-rw-r--r--dom/base/nsTraversal.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/dom/base/nsTraversal.cpp b/dom/base/nsTraversal.cpp
new file mode 100644
index 0000000000..33582a5e8d
--- /dev/null
+++ b/dom/base/nsTraversal.cpp
@@ -0,0 +1,66 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ *
+ * 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/. */
+
+#include "nsTraversal.h"
+
+#include "nsError.h"
+#include "nsINode.h"
+#include "mozilla/AutoRestore.h"
+#include "mozilla/dom/NodeFilterBinding.h"
+
+#include "nsGkAtoms.h"
+
+using namespace mozilla;
+using namespace mozilla::dom;
+
+nsTraversal::nsTraversal(nsINode* aRoot, uint32_t aWhatToShow,
+ NodeFilter* aFilter)
+ : mRoot(aRoot),
+ mWhatToShow(aWhatToShow),
+ mFilter(aFilter),
+ mInAcceptNode(false) {
+ 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 aResult Whether we succeeded
+ * @returns Filtervalue. See NodeFilter.webidl
+ */
+int16_t nsTraversal::TestNode(nsINode* aNode, mozilla::ErrorResult& aResult,
+ nsCOMPtr<nsINode>* aUnskippedNode) {
+ if (mInAcceptNode) {
+ aResult.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
+ return 0;
+ }
+
+ uint16_t nodeType = aNode->NodeType();
+
+ if (nodeType <= 12 && !((1 << (nodeType - 1)) & mWhatToShow)) {
+ return NodeFilter_Binding::FILTER_SKIP;
+ }
+
+ if (aUnskippedNode) {
+ *aUnskippedNode = aNode;
+ }
+
+ if (!mFilter) {
+ // No filter, just accept
+ return NodeFilter_Binding::FILTER_ACCEPT;
+ }
+
+ AutoRestore<bool> inAcceptNode(mInAcceptNode);
+ mInAcceptNode = true;
+ // 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);
+}