2019-01-04 01:19:04 +03:00
|
|
|
/* -*- 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"
|
2019-01-11 04:49:00 +03:00
|
|
|
|
|
|
|
#include "mozilla/ContentIterator.h"
|
2019-01-04 01:19:04 +03:00
|
|
|
#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
|
|
|
|
|
2019-01-10 12:42:27 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION(ScriptableContentIterator, mContentIterator)
|
2019-01-04 01:19:04 +03:00
|
|
|
|
|
|
|
ScriptableContentIterator::ScriptableContentIterator()
|
|
|
|
: mIteratorType(NOT_INITIALIZED) {}
|
|
|
|
|
|
|
|
void ScriptableContentIterator::EnsureContentIterator() {
|
|
|
|
if (mContentIterator) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (mIteratorType) {
|
|
|
|
case POST_ORDER_ITERATOR:
|
|
|
|
default:
|
2019-01-11 04:50:19 +03:00
|
|
|
mContentIterator = new PostContentIterator();
|
2019-01-04 01:19:04 +03:00
|
|
|
break;
|
|
|
|
case PRE_ORDER_ITERATOR:
|
2019-01-11 04:49:36 +03:00
|
|
|
mContentIterator = new PreContentIterator();
|
2019-01-04 01:19:04 +03:00
|
|
|
break;
|
|
|
|
case SUBTREE_ITERATOR:
|
2019-01-11 04:49:00 +03:00
|
|
|
mContentIterator = new ContentSubtreeIterator();
|
2019-01-04 01:19:04 +03:00
|
|
|
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
|