From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- dom/base/ScriptableContentIterator.cpp | 189 +++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 dom/base/ScriptableContentIterator.cpp (limited to 'dom/base/ScriptableContentIterator.cpp') 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(*tmp->mContentIterator)); + break; + case PRE_ORDER_ITERATOR: + ImplCycleCollectionUnlink( + static_cast(*tmp->mContentIterator)); + break; + case SUBTREE_ITERATOR: + ImplCycleCollectionUnlink( + static_cast(*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(*tmp->mContentIterator), + "mContentIterator"); + break; + case PRE_ORDER_ITERATOR: + ImplCycleCollectionTraverse( + cb, static_cast(*tmp->mContentIterator), + "mContentIterator"); + break; + case SUBTREE_ITERATOR: + ImplCycleCollectionTraverse( + cb, static_cast(*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(); + break; + case PRE_ORDER_ITERATOR: + mContentIterator = MakeUnique(); + break; + case SUBTREE_ITERATOR: + mContentIterator = MakeUnique(); + 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 -- cgit v1.2.3