diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /dom/base/ScriptableContentIterator.cpp | |
parent | Initial commit. (diff) | |
download | firefox-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/ScriptableContentIterator.cpp')
-rw-r--r-- | dom/base/ScriptableContentIterator.cpp | 189 |
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 |