summaryrefslogtreecommitdiffstats
path: root/dom/base/ScriptableContentIterator.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/base/ScriptableContentIterator.cpp
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/ScriptableContentIterator.cpp')
-rw-r--r--dom/base/ScriptableContentIterator.cpp189
1 files changed, 189 insertions, 0 deletions
diff --git a/dom/base/ScriptableContentIterator.cpp b/dom/base/ScriptableContentIterator.cpp
new file mode 100644
index 0000000000..d10c4e68f8
--- /dev/null
+++ b/dom/base/ScriptableContentIterator.cpp
@@ -0,0 +1,189 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* 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 "ScriptableContentIterator.h"
+
+#include "mozilla/ContentIterator.h"
+#include "nsINode.h"
+#include "nsRange.h"
+
+namespace mozilla {
+
+NS_IMPL_CYCLE_COLLECTING_ADDREF(ScriptableContentIterator)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(ScriptableContentIterator)
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ScriptableContentIterator)
+ NS_INTERFACE_MAP_ENTRY(nsIScriptableContentIterator)
+ NS_INTERFACE_MAP_ENTRY(nsISupports)
+NS_INTERFACE_MAP_END
+
+NS_IMPL_CYCLE_COLLECTION_CLASS(ScriptableContentIterator)
+
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ScriptableContentIterator)
+ if (tmp->mContentIterator) {
+ switch (tmp->mIteratorType) {
+ case POST_ORDER_ITERATOR:
+ default:
+ ImplCycleCollectionUnlink(
+ static_cast<PostContentIterator&>(*tmp->mContentIterator));
+ break;
+ case PRE_ORDER_ITERATOR:
+ ImplCycleCollectionUnlink(
+ static_cast<PreContentIterator&>(*tmp->mContentIterator));
+ break;
+ case SUBTREE_ITERATOR:
+ ImplCycleCollectionUnlink(
+ static_cast<ContentSubtreeIterator&>(*tmp->mContentIterator));
+ break;
+ }
+ }
+NS_IMPL_CYCLE_COLLECTION_UNLINK_END
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(ScriptableContentIterator)
+ if (tmp->mContentIterator) {
+ switch (tmp->mIteratorType) {
+ case POST_ORDER_ITERATOR:
+ default:
+ ImplCycleCollectionTraverse(
+ cb, static_cast<PostContentIterator&>(*tmp->mContentIterator),
+ "mContentIterator");
+ break;
+ case PRE_ORDER_ITERATOR:
+ ImplCycleCollectionTraverse(
+ cb, static_cast<PreContentIterator&>(*tmp->mContentIterator),
+ "mContentIterator");
+ break;
+ case SUBTREE_ITERATOR:
+ ImplCycleCollectionTraverse(
+ cb, static_cast<ContentSubtreeIterator&>(*tmp->mContentIterator),
+ "mContentIterator");
+ break;
+ }
+ }
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
+
+ScriptableContentIterator::ScriptableContentIterator()
+ : mIteratorType(NOT_INITIALIZED) {}
+
+void ScriptableContentIterator::EnsureContentIterator() {
+ if (mContentIterator) {
+ return;
+ }
+ switch (mIteratorType) {
+ case POST_ORDER_ITERATOR:
+ default:
+ mContentIterator = MakeUnique<PostContentIterator>();
+ break;
+ case PRE_ORDER_ITERATOR:
+ mContentIterator = MakeUnique<PreContentIterator>();
+ break;
+ case SUBTREE_ITERATOR:
+ mContentIterator = MakeUnique<ContentSubtreeIterator>();
+ break;
+ }
+}
+
+NS_IMETHODIMP
+ScriptableContentIterator::InitWithRootNode(IteratorType aType,
+ nsINode* aRoot) {
+ if (aType == NOT_INITIALIZED ||
+ (mIteratorType != NOT_INITIALIZED && aType != mIteratorType)) {
+ return NS_ERROR_INVALID_ARG;
+ }
+ mIteratorType = aType;
+ EnsureContentIterator();
+ return mContentIterator->Init(aRoot);
+}
+
+NS_IMETHODIMP
+ScriptableContentIterator::InitWithRange(IteratorType aType, nsRange* aRange) {
+ if (aType == NOT_INITIALIZED ||
+ (mIteratorType != NOT_INITIALIZED && aType != mIteratorType)) {
+ return NS_ERROR_INVALID_ARG;
+ }
+ mIteratorType = aType;
+ EnsureContentIterator();
+ return mContentIterator->Init(aRange);
+}
+
+NS_IMETHODIMP
+ScriptableContentIterator::InitWithPositions(IteratorType aType,
+ nsINode* aStartContainer,
+ uint32_t aStartOffset,
+ nsINode* aEndContainer,
+ uint32_t aEndOffset) {
+ if (aType == NOT_INITIALIZED ||
+ (mIteratorType != NOT_INITIALIZED && aType != mIteratorType)) {
+ return NS_ERROR_INVALID_ARG;
+ }
+ mIteratorType = aType;
+ EnsureContentIterator();
+ return mContentIterator->Init(aStartContainer, aStartOffset, aEndContainer,
+ aEndOffset);
+}
+
+NS_IMETHODIMP
+ScriptableContentIterator::First() {
+ if (!mContentIterator) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
+ mContentIterator->First();
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+ScriptableContentIterator::Last() {
+ if (!mContentIterator) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
+ mContentIterator->Last();
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+ScriptableContentIterator::Next() {
+ if (!mContentIterator) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
+ mContentIterator->Next();
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+ScriptableContentIterator::Prev() {
+ if (!mContentIterator) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
+ mContentIterator->Prev();
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+ScriptableContentIterator::GetCurrentNode(nsINode** aNode) {
+ if (!mContentIterator) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
+ NS_IF_ADDREF(*aNode = mContentIterator->GetCurrentNode());
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+ScriptableContentIterator::GetIsDone(bool* aIsDone) {
+ if (!mContentIterator) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
+ *aIsDone = mContentIterator->IsDone();
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+ScriptableContentIterator::PositionAt(nsINode* aNode) {
+ if (!mContentIterator) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
+ return mContentIterator->PositionAt(aNode);
+}
+
+} // namespace mozilla