Bug 181137 - part 1: Move nsContentIterator and nsContentSubtreeIterator into mozilla namespace r=smaug

First, we should move nsContentIterator and nsContentSubtreeIterator into
mozilla namespace and then, remove "ns" prefix.

Additionally, this patch separates the definition of the classes into
ContentIterator.h and exposes it as "mozilla/ContentIterator.h".  This allows
everybody access those concrete classes.

Differential Revision: https://phabricator.services.mozilla.com/D15917

--HG--
rename : dom/base/nsContentIterator.cpp => dom/base/ContentIterator.cpp
rename : dom/base/nsContentIterator.cpp => dom/base/ContentIterator.h
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-01-11 01:47:15 +00:00
parent 0de25813f2
commit 2d75b78552
7 changed files with 237 additions and 256 deletions

View File

@ -4,22 +4,32 @@
* 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 "ContentIterator.h"
#include "mozilla/DebugOnly.h"
#include "nsISupports.h"
#include "nsIContentIterator.h"
#include "nsRange.h"
#include "nsIContent.h"
#include "nsCOMPtr.h"
#include "nsTArray.h"
#include "mozilla/RangeBoundary.h"
#include "nsContentUtils.h"
#include "nsINode.h"
#include "nsCycleCollectionParticipant.h"
#include "nsElementTable.h"
#include "nsIContent.h"
#include "nsRange.h"
using mozilla::DebugOnly;
using mozilla::RawRangeBoundary;
already_AddRefed<nsIContentIterator> NS_NewContentIterator() {
nsCOMPtr<nsIContentIterator> iter = new mozilla::ContentIterator(false);
return iter.forget();
}
// couple of utility static functs
already_AddRefed<nsIContentIterator> NS_NewPreContentIterator() {
nsCOMPtr<nsIContentIterator> iter = new mozilla::ContentIterator(true);
return iter.forget();
}
already_AddRefed<nsIContentIterator> NS_NewContentSubtreeIterator() {
nsCOMPtr<nsIContentIterator> iter = new mozilla::ContentSubtreeIterator();
return iter.forget();
}
namespace mozilla {
///////////////////////////////////////////////////////////////////////////
// NodeIsInTraversalRange: returns true if content is visited during
@ -73,139 +83,33 @@ static bool NodeIsInTraversalRange(nsINode* aNode, bool aIsPreMode,
nsContentUtils::ComparePoints(aEnd, beforeNode) > 0;
}
/*
* A simple iterator class for traversing the content in "close tag" order
*/
class nsContentIterator : public nsIContentIterator {
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS(nsContentIterator)
explicit nsContentIterator(bool aPre);
// nsIContentIterator interface methods ------------------------------
virtual nsresult Init(nsINode* aRoot) override;
virtual nsresult Init(nsRange* aRange) override;
virtual nsresult Init(nsINode* aStartContainer, uint32_t aStartOffset,
nsINode* aEndContainer, uint32_t aEndOffset) override;
virtual nsresult Init(const RawRangeBoundary& aStart,
const RawRangeBoundary& aEnd) override;
virtual void First() override;
virtual void Last() override;
virtual void Next() override;
virtual void Prev() override;
virtual nsINode* GetCurrentNode() override;
virtual bool IsDone() override;
virtual nsresult PositionAt(nsINode* aCurNode) override;
protected:
virtual ~nsContentIterator();
/**
* Callers must guarantee that:
* - Neither aStartContainer nor aEndContainer is nullptr.
* - aStartOffset and aEndOffset are valid for its container.
* - The start point and the end point are in document order.
*/
nsresult InitInternal(const RawRangeBoundary& aStart,
const RawRangeBoundary& aEnd);
// Recursively get the deepest first/last child of aRoot. This will return
// aRoot itself if it has no children.
nsINode* GetDeepFirstChild(nsINode* aRoot);
nsIContent* GetDeepFirstChild(nsIContent* aRoot);
nsINode* GetDeepLastChild(nsINode* aRoot);
nsIContent* GetDeepLastChild(nsIContent* aRoot);
// Get the next/previous sibling of aNode, or its parent's, or grandparent's,
// etc. Returns null if aNode and all its ancestors have no next/previous
// sibling.
nsIContent* GetNextSibling(nsINode* aNode);
nsIContent* GetPrevSibling(nsINode* aNode);
nsINode* NextNode(nsINode* aNode);
nsINode* PrevNode(nsINode* aNode);
void MakeEmpty();
virtual void LastRelease();
nsCOMPtr<nsINode> mCurNode;
nsCOMPtr<nsINode> mFirst;
nsCOMPtr<nsINode> mLast;
nsCOMPtr<nsINode> mCommonParent;
bool mIsDone;
bool mPre;
private:
// no copies or assigns FIX ME
nsContentIterator(const nsContentIterator&);
nsContentIterator& operator=(const nsContentIterator&);
};
/******************************************************
* repository cruft
******************************************************/
already_AddRefed<nsIContentIterator> NS_NewContentIterator() {
nsCOMPtr<nsIContentIterator> iter = new nsContentIterator(false);
return iter.forget();
}
already_AddRefed<nsIContentIterator> NS_NewPreContentIterator() {
nsCOMPtr<nsIContentIterator> iter = new nsContentIterator(true);
return iter.forget();
}
/******************************************************
* XPCOM cruft
******************************************************/
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsContentIterator)
NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(nsContentIterator,
NS_IMPL_CYCLE_COLLECTING_ADDREF(ContentIterator)
NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(ContentIterator,
LastRelease())
NS_INTERFACE_MAP_BEGIN(nsContentIterator)
NS_INTERFACE_MAP_BEGIN(ContentIterator)
NS_INTERFACE_MAP_ENTRY(nsIContentIterator)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContentIterator)
NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsContentIterator)
NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(ContentIterator)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTION(nsContentIterator, mCurNode, mFirst, mLast,
NS_IMPL_CYCLE_COLLECTION(ContentIterator, mCurNode, mFirst, mLast,
mCommonParent)
void nsContentIterator::LastRelease() {
void ContentIterator::LastRelease() {
mCurNode = nullptr;
mFirst = nullptr;
mLast = nullptr;
mCommonParent = nullptr;
}
/******************************************************
* constructor/destructor
******************************************************/
nsContentIterator::nsContentIterator(bool aPre) : mIsDone(false), mPre(aPre) {}
nsContentIterator::~nsContentIterator() {}
ContentIterator::ContentIterator(bool aPre) : mIsDone(false), mPre(aPre) {}
/******************************************************
* Init routines
******************************************************/
nsresult nsContentIterator::Init(nsINode* aRoot) {
nsresult ContentIterator::Init(nsINode* aRoot) {
if (NS_WARN_IF(!aRoot)) {
return NS_ERROR_NULL_POINTER;
}
@ -227,7 +131,7 @@ nsresult nsContentIterator::Init(nsINode* aRoot) {
return NS_OK;
}
nsresult nsContentIterator::Init(nsRange* aRange) {
nsresult ContentIterator::Init(nsRange* aRange) {
mIsDone = false;
if (NS_WARN_IF(!aRange)) {
@ -241,9 +145,8 @@ nsresult nsContentIterator::Init(nsRange* aRange) {
return InitInternal(aRange->StartRef().AsRaw(), aRange->EndRef().AsRaw());
}
nsresult nsContentIterator::Init(nsINode* aStartContainer,
uint32_t aStartOffset, nsINode* aEndContainer,
uint32_t aEndOffset) {
nsresult ContentIterator::Init(nsINode* aStartContainer, uint32_t aStartOffset,
nsINode* aEndContainer, uint32_t aEndOffset) {
mIsDone = false;
if (NS_WARN_IF(!nsRange::IsValidPoints(aStartContainer, aStartOffset,
@ -255,8 +158,8 @@ nsresult nsContentIterator::Init(nsINode* aStartContainer,
RawRangeBoundary(aEndContainer, aEndOffset));
}
nsresult nsContentIterator::Init(const RawRangeBoundary& aStart,
const RawRangeBoundary& aEnd) {
nsresult ContentIterator::Init(const RawRangeBoundary& aStart,
const RawRangeBoundary& aEnd) {
mIsDone = false;
if (NS_WARN_IF(!nsRange::IsValidPoints(aStart.Container(), aStart.Offset(),
@ -267,8 +170,8 @@ nsresult nsContentIterator::Init(const RawRangeBoundary& aStart,
return InitInternal(aStart, aEnd);
}
nsresult nsContentIterator::InitInternal(const RawRangeBoundary& aStart,
const RawRangeBoundary& aEnd) {
nsresult ContentIterator::InitInternal(const RawRangeBoundary& aStart,
const RawRangeBoundary& aEnd) {
// get common content parent
mCommonParent =
nsContentUtils::GetCommonAncestor(aStart.Container(), aEnd.Container());
@ -420,7 +323,7 @@ nsresult nsContentIterator::InitInternal(const RawRangeBoundary& aStart,
if (NS_WARN_IF(!cChild)) {
// No child at offset!
MOZ_ASSERT_UNREACHABLE("nsContentIterator::nsContentIterator");
MOZ_ASSERT_UNREACHABLE("ContentIterator::ContentIterator");
return NS_ERROR_FAILURE;
}
@ -450,7 +353,7 @@ nsresult nsContentIterator::InitInternal(const RawRangeBoundary& aStart,
return NS_OK;
}
void nsContentIterator::MakeEmpty() {
void ContentIterator::MakeEmpty() {
mCurNode = nullptr;
mFirst = nullptr;
mLast = nullptr;
@ -458,7 +361,7 @@ void nsContentIterator::MakeEmpty() {
mIsDone = true;
}
nsINode* nsContentIterator::GetDeepFirstChild(nsINode* aRoot) {
nsINode* ContentIterator::GetDeepFirstChild(nsINode* aRoot) {
if (NS_WARN_IF(!aRoot) || !aRoot->HasChildren()) {
return aRoot;
}
@ -466,7 +369,7 @@ nsINode* nsContentIterator::GetDeepFirstChild(nsINode* aRoot) {
return GetDeepFirstChild(aRoot->GetFirstChild());
}
nsIContent* nsContentIterator::GetDeepFirstChild(nsIContent* aRoot) {
nsIContent* ContentIterator::GetDeepFirstChild(nsIContent* aRoot) {
if (NS_WARN_IF(!aRoot)) {
return nullptr;
}
@ -482,7 +385,7 @@ nsIContent* nsContentIterator::GetDeepFirstChild(nsIContent* aRoot) {
return node;
}
nsINode* nsContentIterator::GetDeepLastChild(nsINode* aRoot) {
nsINode* ContentIterator::GetDeepLastChild(nsINode* aRoot) {
if (NS_WARN_IF(!aRoot) || !aRoot->HasChildren()) {
return aRoot;
}
@ -490,7 +393,7 @@ nsINode* nsContentIterator::GetDeepLastChild(nsINode* aRoot) {
return GetDeepLastChild(aRoot->GetLastChild());
}
nsIContent* nsContentIterator::GetDeepLastChild(nsIContent* aRoot) {
nsIContent* ContentIterator::GetDeepLastChild(nsIContent* aRoot) {
if (NS_WARN_IF(!aRoot)) {
return nullptr;
}
@ -504,7 +407,7 @@ nsIContent* nsContentIterator::GetDeepLastChild(nsIContent* aRoot) {
}
// Get the next sibling, or parent's next sibling, or grandpa's next sibling...
nsIContent* nsContentIterator::GetNextSibling(nsINode* aNode) {
nsIContent* ContentIterator::GetNextSibling(nsINode* aNode) {
if (NS_WARN_IF(!aNode)) {
return nullptr;
}
@ -529,7 +432,7 @@ nsIContent* nsContentIterator::GetNextSibling(nsINode* aNode) {
}
// Get the prev sibling, or parent's prev sibling, or grandpa's prev sibling...
nsIContent* nsContentIterator::GetPrevSibling(nsINode* aNode) {
nsIContent* ContentIterator::GetPrevSibling(nsINode* aNode) {
if (NS_WARN_IF(!aNode)) {
return nullptr;
}
@ -553,7 +456,7 @@ nsIContent* nsContentIterator::GetPrevSibling(nsINode* aNode) {
return GetPrevSibling(parent);
}
nsINode* nsContentIterator::NextNode(nsINode* aNode) {
nsINode* ContentIterator::NextNode(nsINode* aNode) {
nsINode* node = aNode;
// if we are a Pre-order iterator, use pre-order
@ -587,7 +490,7 @@ nsINode* nsContentIterator::NextNode(nsINode* aNode) {
return parent;
}
nsINode* nsContentIterator::PrevNode(nsINode* aNode) {
nsINode* ContentIterator::PrevNode(nsINode* aNode) {
nsINode* node = aNode;
// if we are a Pre-order iterator, use pre-order
@ -620,7 +523,7 @@ nsINode* nsContentIterator::PrevNode(nsINode* aNode) {
* ContentIterator routines
******************************************************/
void nsContentIterator::First() {
void ContentIterator::First() {
if (mFirst) {
mozilla::DebugOnly<nsresult> rv = PositionAt(mFirst);
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to position iterator!");
@ -629,7 +532,7 @@ void nsContentIterator::First() {
mIsDone = mFirst == nullptr;
}
void nsContentIterator::Last() {
void ContentIterator::Last() {
// Note that mLast can be nullptr if MakeEmpty() is called in Init() since
// at that time, Init() returns NS_OK.
if (!mLast) {
@ -643,7 +546,7 @@ void nsContentIterator::Last() {
mIsDone = mLast == nullptr;
}
void nsContentIterator::Next() {
void ContentIterator::Next() {
if (mIsDone || NS_WARN_IF(!mCurNode)) {
return;
}
@ -656,7 +559,7 @@ void nsContentIterator::Next() {
mCurNode = NextNode(mCurNode);
}
void nsContentIterator::Prev() {
void ContentIterator::Prev() {
if (NS_WARN_IF(mIsDone) || NS_WARN_IF(!mCurNode)) {
return;
}
@ -669,11 +572,11 @@ void nsContentIterator::Prev() {
mCurNode = PrevNode(mCurNode);
}
bool nsContentIterator::IsDone() { return mIsDone; }
bool ContentIterator::IsDone() { return mIsDone; }
// Keeping arrays of indexes for the stack of nodes makes PositionAt
// interesting...
nsresult nsContentIterator::PositionAt(nsINode* aCurNode) {
nsresult ContentIterator::PositionAt(nsINode* aCurNode) {
if (NS_WARN_IF(!aCurNode)) {
return NS_ERROR_NULL_POINTER;
}
@ -732,7 +635,7 @@ nsresult nsContentIterator::PositionAt(nsINode* aCurNode) {
return NS_OK;
}
nsINode* nsContentIterator::GetCurrentNode() {
nsINode* ContentIterator::GetCurrentNode() {
if (mIsDone) {
return nullptr;
}
@ -742,106 +645,33 @@ nsINode* nsContentIterator::GetCurrentNode() {
return mCurNode;
}
/*====================================================================================*/
/*====================================================================================*/
/******************************************************
* nsContentSubtreeIterator
* ContentSubtreeIterator
******************************************************/
/*
* A simple iterator class for traversing the content in "top subtree" order
*/
class nsContentSubtreeIterator : public nsContentIterator {
public:
nsContentSubtreeIterator() : nsContentIterator(false) {}
NS_IMPL_ADDREF_INHERITED(ContentSubtreeIterator, ContentIterator)
NS_IMPL_RELEASE_INHERITED(ContentSubtreeIterator, ContentIterator)
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsContentSubtreeIterator,
nsContentIterator)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ContentSubtreeIterator)
NS_INTERFACE_MAP_END_INHERITING(ContentIterator)
// nsContentIterator overrides ------------------------------
virtual nsresult Init(nsINode* aRoot) override;
virtual nsresult Init(nsRange* aRange) override;
virtual nsresult Init(nsINode* aStartContainer, uint32_t aStartOffset,
nsINode* aEndContainer, uint32_t aEndOffset) override;
virtual nsresult Init(const RawRangeBoundary& aStart,
const RawRangeBoundary& aEnd) override;
virtual void Next() override;
virtual void Prev() override;
virtual nsresult PositionAt(nsINode* aCurNode) override;
// Must override these because we don't do PositionAt
virtual void First() override;
// Must override these because we don't do PositionAt
virtual void Last() override;
protected:
virtual ~nsContentSubtreeIterator() {}
/**
* Callers must guarantee that mRange isn't nullptr and is positioned.
*/
nsresult InitWithRange();
// Returns the highest inclusive ancestor of aNode that's in the range
// (possibly aNode itself). Returns null if aNode is null, or is not itself
// in the range. A node is in the range if (node, 0) comes strictly after
// the range endpoint, and (node, node.length) comes strictly before it, so
// the range's start and end nodes will never be considered "in" it.
nsIContent* GetTopAncestorInRange(nsINode* aNode);
// no copy's or assigns FIX ME
nsContentSubtreeIterator(const nsContentSubtreeIterator&);
nsContentSubtreeIterator& operator=(const nsContentSubtreeIterator&);
virtual void LastRelease() override;
RefPtr<nsRange> mRange;
AutoTArray<nsIContent*, 8> mEndNodes;
};
NS_IMPL_ADDREF_INHERITED(nsContentSubtreeIterator, nsContentIterator)
NS_IMPL_RELEASE_INHERITED(nsContentSubtreeIterator, nsContentIterator)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsContentSubtreeIterator)
NS_INTERFACE_MAP_END_INHERITING(nsContentIterator)
NS_IMPL_CYCLE_COLLECTION_INHERITED(nsContentSubtreeIterator, nsContentIterator,
NS_IMPL_CYCLE_COLLECTION_INHERITED(ContentSubtreeIterator, ContentIterator,
mRange)
void nsContentSubtreeIterator::LastRelease() {
void ContentSubtreeIterator::LastRelease() {
mRange = nullptr;
nsContentIterator::LastRelease();
}
/******************************************************
* repository cruft
******************************************************/
already_AddRefed<nsIContentIterator> NS_NewContentSubtreeIterator() {
nsCOMPtr<nsIContentIterator> iter = new nsContentSubtreeIterator();
return iter.forget();
ContentIterator::LastRelease();
}
/******************************************************
* Init routines
******************************************************/
nsresult nsContentSubtreeIterator::Init(nsINode* aRoot) {
nsresult ContentSubtreeIterator::Init(nsINode* aRoot) {
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsContentSubtreeIterator::Init(nsRange* aRange) {
nsresult ContentSubtreeIterator::Init(nsRange* aRange) {
MOZ_ASSERT(aRange);
mIsDone = false;
@ -855,16 +685,16 @@ nsresult nsContentSubtreeIterator::Init(nsRange* aRange) {
return InitWithRange();
}
nsresult nsContentSubtreeIterator::Init(nsINode* aStartContainer,
uint32_t aStartOffset,
nsINode* aEndContainer,
uint32_t aEndOffset) {
nsresult ContentSubtreeIterator::Init(nsINode* aStartContainer,
uint32_t aStartOffset,
nsINode* aEndContainer,
uint32_t aEndOffset) {
return Init(RawRangeBoundary(aStartContainer, aStartOffset),
RawRangeBoundary(aEndContainer, aEndOffset));
}
nsresult nsContentSubtreeIterator::Init(const RawRangeBoundary& aStart,
const RawRangeBoundary& aEnd) {
nsresult ContentSubtreeIterator::Init(const RawRangeBoundary& aStart,
const RawRangeBoundary& aEnd) {
mIsDone = false;
RefPtr<nsRange> range;
@ -884,7 +714,7 @@ nsresult nsContentSubtreeIterator::Init(const RawRangeBoundary& aStart,
return InitWithRange();
}
nsresult nsContentSubtreeIterator::InitWithRange() {
nsresult ContentSubtreeIterator::InitWithRange() {
MOZ_ASSERT(mRange);
MOZ_ASSERT(mRange->IsPositioned());
@ -983,7 +813,7 @@ nsresult nsContentSubtreeIterator::InitWithRange() {
lastCandidate = mRange->EndRef().Ref();
MOZ_ASSERT(lastCandidate == endContainer->GetChildAt_Deprecated(--offset));
NS_ASSERTION(lastCandidate,
"tree traversal trouble in nsContentSubtreeIterator::Init");
"tree traversal trouble in ContentSubtreeIterator::Init");
}
if (!lastCandidate) {
@ -1020,24 +850,24 @@ nsresult nsContentSubtreeIterator::InitWithRange() {
}
/****************************************************************
* nsContentSubtreeIterator overrides of ContentIterator routines
* ContentSubtreeIterator overrides of ContentIterator routines
****************************************************************/
// we can't call PositionAt in a subtree iterator...
void nsContentSubtreeIterator::First() {
void ContentSubtreeIterator::First() {
mIsDone = mFirst == nullptr;
mCurNode = mFirst;
}
// we can't call PositionAt in a subtree iterator...
void nsContentSubtreeIterator::Last() {
void ContentSubtreeIterator::Last() {
mIsDone = mLast == nullptr;
mCurNode = mLast;
}
void nsContentSubtreeIterator::Next() {
void ContentSubtreeIterator::Next() {
if (mIsDone || !mCurNode) {
return;
}
@ -1072,7 +902,7 @@ void nsContentSubtreeIterator::Next() {
mIsDone = mCurNode == nullptr;
}
void nsContentSubtreeIterator::Prev() {
void ContentSubtreeIterator::Prev() {
// Prev should be optimized to use the mStartNodes, just as Next
// uses mEndNodes.
if (mIsDone || !mCurNode) {
@ -1100,17 +930,17 @@ void nsContentSubtreeIterator::Prev() {
mIsDone = mCurNode == nullptr;
}
nsresult nsContentSubtreeIterator::PositionAt(nsINode* aCurNode) {
nsresult ContentSubtreeIterator::PositionAt(nsINode* aCurNode) {
NS_ERROR("Not implemented!");
return NS_ERROR_NOT_IMPLEMENTED;
}
/****************************************************************
* nsContentSubtreeIterator helper routines
* ContentSubtreeIterator helper routines
****************************************************************/
nsIContent* nsContentSubtreeIterator::GetTopAncestorInRange(nsINode* aNode) {
nsIContent* ContentSubtreeIterator::GetTopAncestorInRange(nsINode* aNode) {
if (!aNode || !aNode->GetParentNode()) {
return nullptr;
}
@ -1150,3 +980,5 @@ nsIContent* nsContentSubtreeIterator::GetTopAncestorInRange(nsINode* aNode) {
MOZ_CRASH("This should only be possible if aNode was null");
}
} // namespace mozilla

148
dom/base/ContentIterator.h Normal file
View File

@ -0,0 +1,148 @@
/* -*- 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/. */
#ifndef mozilla_ContentIterator_h
#define mozilla_ContentIterator_h
#include "mozilla/RangeBoundary.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIContent.h"
#include "nsIContentIterator.h"
#include "nsRange.h"
#include "nsTArray.h"
namespace mozilla {
/**
* A simple iterator class for traversing the content in "close tag" order.
*/
class ContentIterator : public nsIContentIterator {
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS(ContentIterator)
explicit ContentIterator(bool aPre);
virtual nsresult Init(nsINode* aRoot) override;
virtual nsresult Init(nsRange* aRange) override;
virtual nsresult Init(nsINode* aStartContainer, uint32_t aStartOffset,
nsINode* aEndContainer, uint32_t aEndOffset) override;
virtual nsresult Init(const RawRangeBoundary& aStart,
const RawRangeBoundary& aEnd) override;
virtual void First() override;
virtual void Last() override;
virtual void Next() override;
virtual void Prev() override;
virtual nsINode* GetCurrentNode() override;
virtual bool IsDone() override;
virtual nsresult PositionAt(nsINode* aCurNode) override;
protected:
virtual ~ContentIterator() = default;
/**
* Callers must guarantee that:
* - Neither aStartContainer nor aEndContainer is nullptr.
* - aStartOffset and aEndOffset are valid for its container.
* - The start point and the end point are in document order.
*/
nsresult InitInternal(const RawRangeBoundary& aStart,
const RawRangeBoundary& aEnd);
// Recursively get the deepest first/last child of aRoot. This will return
// aRoot itself if it has no children.
nsINode* GetDeepFirstChild(nsINode* aRoot);
nsIContent* GetDeepFirstChild(nsIContent* aRoot);
nsINode* GetDeepLastChild(nsINode* aRoot);
nsIContent* GetDeepLastChild(nsIContent* aRoot);
// Get the next/previous sibling of aNode, or its parent's, or grandparent's,
// etc. Returns null if aNode and all its ancestors have no next/previous
// sibling.
nsIContent* GetNextSibling(nsINode* aNode);
nsIContent* GetPrevSibling(nsINode* aNode);
nsINode* NextNode(nsINode* aNode);
nsINode* PrevNode(nsINode* aNode);
void MakeEmpty();
virtual void LastRelease();
nsCOMPtr<nsINode> mCurNode;
nsCOMPtr<nsINode> mFirst;
nsCOMPtr<nsINode> mLast;
nsCOMPtr<nsINode> mCommonParent;
bool mIsDone;
bool mPre;
private:
ContentIterator(const ContentIterator&) = delete;
ContentIterator& operator=(const ContentIterator&) = delete;
};
/**
* A simple iterator class for traversing the content in "top subtree" order.
*/
class ContentSubtreeIterator final : public ContentIterator {
public:
ContentSubtreeIterator() : ContentIterator(false) {}
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ContentSubtreeIterator,
ContentIterator)
virtual nsresult Init(nsINode* aRoot) override;
virtual nsresult Init(nsRange* aRange) override;
virtual nsresult Init(nsINode* aStartContainer, uint32_t aStartOffset,
nsINode* aEndContainer, uint32_t aEndOffset) override;
virtual nsresult Init(const RawRangeBoundary& aStart,
const RawRangeBoundary& aEnd) override;
virtual void Next() override;
virtual void Prev() override;
// Must override these because we don't do PositionAt
virtual void First() override;
// Must override these because we don't do PositionAt
virtual void Last() override;
virtual nsresult PositionAt(nsINode* aCurNode) override;
protected:
virtual ~ContentSubtreeIterator() = default;
/**
* Callers must guarantee that mRange isn't nullptr and is positioned.
*/
nsresult InitWithRange();
// Returns the highest inclusive ancestor of aNode that's in the range
// (possibly aNode itself). Returns null if aNode is null, or is not itself
// in the range. A node is in the range if (node, 0) comes strictly after
// the range endpoint, and (node, node.length) comes strictly before it, so
// the range's start and end nodes will never be considered "in" it.
nsIContent* GetTopAncestorInRange(nsINode* aNode);
// no copy's or assigns FIX ME
ContentSubtreeIterator(const ContentSubtreeIterator&) = delete;
ContentSubtreeIterator& operator=(const ContentSubtreeIterator&) = delete;
virtual void LastRelease() override;
RefPtr<nsRange> mRange;
AutoTArray<nsIContent*, 8> mEndNodes;
};
} // namespace mozilla
#endif // #ifndef mozilla_ContentIterator_h

View File

@ -125,6 +125,7 @@ if CONFIG['MOZ_WEBRTC']:
]
EXPORTS.mozilla += [
'ContentIterator.h',
'CORSMode.h',
'FlushType.h',
'FullscreenChange.h',
@ -261,6 +262,7 @@ UNIFIED_SOURCES += [
'ChromeUtils.cpp',
'Comment.cpp',
'ContentFrameMessageManager.cpp',
'ContentIterator.cpp',
'ContentProcessMessageManager.cpp',
'Crypto.cpp',
'CustomElementRegistry.cpp',
@ -310,7 +312,6 @@ UNIFIED_SOURCES += [
'nsAttrValueOrString.cpp',
'nsCCUncollectableMarker.cpp',
'nsContentAreaDragDrop.cpp',
'nsContentIterator.cpp',
'nsContentList.cpp',
'nsContentPermissionHelper.cpp',
'nsContentPolicy.cpp',

View File

@ -28,7 +28,7 @@ SimpleTest.waitForExplicitFinish();
// In e10s mode, ContentCacheInChild tries to retrieve selected text and
// caret position when IMEContentObserver notifies IME of focus. At this time,
// we hit assertion in nsContentIterator.
// we hit assertion in ContentIterator.
SimpleTest.expectAssertions(0, 6);
window.addEventListener("mousedown", function (aEvent) { aEvent.preventDefault(); });

View File

@ -80,7 +80,7 @@ SimpleTest.waitForFocus(function () {
let iter = createContentIterator();
/**
* FYI: nsContentSubtreeIterator does not support initWithRootNode() nor positionAt().
* FYI: ContentSubtreeIterator does not support initWithRootNode() nor positionAt().
*/
/**

View File

@ -199,7 +199,7 @@ nsresult ContentEventHandler::RawRange::SelectNodeContents(
// When before an element node (meaning before the open tag of the
// element) is end of a range, end node is previous node causing text.
// Note that this case shouldn't be handled directly. If rule 2.1 and
// 2.3 are handled correctly, the loop with nsContentIterator shouldn't
// 2.3 are handled correctly, the loop with ContentIterator shouldn't
// reach the element node since the loop should've finished already at
// handling the last node which caused some text.
// 2.3. Case: <element>]
@ -2653,7 +2653,7 @@ nsresult ContentEventHandler::OnQueryDOMWidgetHittest(
return NS_OK;
}
// Don't create nsContentIterator instance until it's really necessary since
// Don't create ContentIterator instance until it's really necessary since
// destroying without initializing causes unexpected NS_ASSERTION() call.
nsCOMPtr<nsIContentIterator> iter;
@ -2792,7 +2792,7 @@ nsresult ContentEventHandler::OnQueryDOMWidgetHittest(
nsresult ContentEventHandler::GetStartOffset(const RawRange& aRawRange,
uint32_t* aOffset,
LineBreakType aLineBreakType) {
// To match the "no skip start" hack in nsContentIterator::Init, when range
// To match the "no skip start" hack in ContentIterator::Init, when range
// offset is 0 and the range node is not a container, we have to assume the
// range _includes_ the node, which means the start offset should _not_
// include the node.

View File

@ -1551,7 +1551,7 @@ void IMEContentObserver::FlushMergeableNotifications() {
this));
// If contents in selection range is modified, the selection range still
// has removed node from the tree. In such case, nsContentIterator won't
// has removed node from the tree. In such case, ContentIterator won't
// work well. Therefore, we shouldn't use AddScriptRunnder() here since
// it may kick runnable event immediately after DOM tree is changed but
// the selection range isn't modified yet.