Bug 776536 part 1. Rename nsNodeIterator to mozilla::dom::NodeIterator. r=peterv

--HG--
rename : content/base/src/nsNodeIterator.cpp => content/base/src/NodeIterator.cpp
rename : content/base/src/nsNodeIterator.h => content/base/src/NodeIterator.h
This commit is contained in:
Boris Zbarsky 2013-02-28 12:56:41 -05:00
parent 3875ee73e3
commit d46a52933e
5 changed files with 66 additions and 56 deletions

View File

@ -51,6 +51,7 @@ EXPORTS_mozilla/dom = \
DOMImplementation.h \ DOMImplementation.h \
EventSource.h \ EventSource.h \
Link.h \ Link.h \
NodeIterator.h \
Text.h \ Text.h \
$(NULL) $(NULL)
@ -107,7 +108,7 @@ CPPSRCS = \
nsNoDataProtocolContentPolicy.cpp \ nsNoDataProtocolContentPolicy.cpp \
nsNodeInfo.cpp \ nsNodeInfo.cpp \
nsNodeInfoManager.cpp \ nsNodeInfoManager.cpp \
nsNodeIterator.cpp \ NodeIterator.cpp \
nsNodeUtils.cpp \ nsNodeUtils.cpp \
nsObjectLoadingContent.cpp \ nsObjectLoadingContent.cpp \
nsPlainTextSerializer.cpp \ nsPlainTextSerializer.cpp \

View File

@ -8,7 +8,7 @@
* Implementation of DOM Traversal's nsIDOMNodeIterator * Implementation of DOM Traversal's nsIDOMNodeIterator
*/ */
#include "nsNodeIterator.h" #include "mozilla/dom/NodeIterator.h"
#include "nsIDOMNode.h" #include "nsIDOMNode.h"
#include "nsIDOMNodeFilter.h" #include "nsIDOMNodeFilter.h"
@ -21,19 +21,21 @@
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "mozilla/dom/NodeFilterBinding.h" #include "mozilla/dom/NodeFilterBinding.h"
using namespace mozilla::dom; DOMCI_DATA(NodeIterator, mozilla::dom::NodeIterator)
namespace mozilla {
namespace dom {
/* /*
* NodePointer implementation * NodePointer implementation
*/ */
nsNodeIterator::NodePointer::NodePointer(nsINode *aNode, NodeIterator::NodePointer::NodePointer(nsINode *aNode, bool aBeforeNode) :
bool aBeforeNode) :
mNode(aNode), mNode(aNode),
mBeforeNode(aBeforeNode) mBeforeNode(aBeforeNode)
{ {
} }
bool nsNodeIterator::NodePointer::MoveToNext(nsINode *aRoot) bool NodeIterator::NodePointer::MoveToNext(nsINode *aRoot)
{ {
if (!mNode) if (!mNode)
return false; return false;
@ -52,7 +54,7 @@ bool nsNodeIterator::NodePointer::MoveToNext(nsINode *aRoot)
return MoveForward(aRoot, mNode); return MoveForward(aRoot, mNode);
} }
bool nsNodeIterator::NodePointer::MoveToPrevious(nsINode *aRoot) bool NodeIterator::NodePointer::MoveToPrevious(nsINode *aRoot)
{ {
if (!mNode) if (!mNode)
return false; return false;
@ -70,10 +72,10 @@ bool nsNodeIterator::NodePointer::MoveToPrevious(nsINode *aRoot)
return true; return true;
} }
void nsNodeIterator::NodePointer::AdjustAfterRemoval(nsINode *aRoot, void NodeIterator::NodePointer::AdjustAfterRemoval(nsINode *aRoot,
nsINode *aContainer, nsINode *aContainer,
nsIContent *aChild, nsIContent *aChild,
nsIContent *aPreviousSibling) nsIContent *aPreviousSibling)
{ {
// If mNode is null or the root there is nothing to do. // If mNode is null or the root there is nothing to do.
if (!mNode || mNode == aRoot) if (!mNode || mNode == aRoot)
@ -105,7 +107,7 @@ void nsNodeIterator::NodePointer::AdjustAfterRemoval(nsINode *aRoot,
MoveBackward(aContainer, aPreviousSibling); MoveBackward(aContainer, aPreviousSibling);
} }
bool nsNodeIterator::NodePointer::MoveForward(nsINode *aRoot, nsINode *aNode) bool NodeIterator::NodePointer::MoveForward(nsINode *aRoot, nsINode *aNode)
{ {
while (1) { while (1) {
if (aNode == aRoot) if (aNode == aRoot)
@ -122,7 +124,7 @@ bool nsNodeIterator::NodePointer::MoveForward(nsINode *aRoot, nsINode *aNode)
return false; return false;
} }
void nsNodeIterator::NodePointer::MoveBackward(nsINode *aParent, nsINode *aNode) void NodeIterator::NodePointer::MoveBackward(nsINode *aParent, nsINode *aNode)
{ {
if (aNode) { if (aNode) {
do { do {
@ -138,9 +140,9 @@ void nsNodeIterator::NodePointer::MoveBackward(nsINode *aParent, nsINode *aNode)
* Factories, constructors and destructors * Factories, constructors and destructors
*/ */
nsNodeIterator::nsNodeIterator(nsINode *aRoot, NodeIterator::NodeIterator(nsINode *aRoot,
uint32_t aWhatToShow, uint32_t aWhatToShow,
const NodeFilterHolder &aFilter) : const NodeFilterHolder &aFilter) :
nsTraversal(aRoot, aWhatToShow, aFilter), nsTraversal(aRoot, aWhatToShow, aFilter),
mDetached(false), mDetached(false),
mPointer(mRoot, true) mPointer(mRoot, true)
@ -148,7 +150,7 @@ nsNodeIterator::nsNodeIterator(nsINode *aRoot,
aRoot->AddMutationObserver(this); aRoot->AddMutationObserver(this);
} }
nsNodeIterator::~nsNodeIterator() NodeIterator::~NodeIterator()
{ {
/* destructor code */ /* destructor code */
if (!mDetached && mRoot) if (!mDetached && mRoot)
@ -159,32 +161,30 @@ nsNodeIterator::~nsNodeIterator()
* nsISupports and cycle collection stuff * nsISupports and cycle collection stuff
*/ */
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsNodeIterator) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(NodeIterator)
if (!tmp->mDetached && tmp->mRoot) if (!tmp->mDetached && tmp->mRoot)
tmp->mRoot->RemoveMutationObserver(tmp); tmp->mRoot->RemoveMutationObserver(tmp);
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRoot) NS_IMPL_CYCLE_COLLECTION_UNLINK(mRoot)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFilter) NS_IMPL_CYCLE_COLLECTION_UNLINK(mFilter)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsNodeIterator) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(NodeIterator)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRoot) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRoot)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFilter) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFilter)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
DOMCI_DATA(NodeIterator, nsNodeIterator) // QueryInterface implementation for NodeIterator
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(NodeIterator)
// QueryInterface implementation for nsNodeIterator
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsNodeIterator)
NS_INTERFACE_MAP_ENTRY(nsIDOMNodeIterator) NS_INTERFACE_MAP_ENTRY(nsIDOMNodeIterator)
NS_INTERFACE_MAP_ENTRY(nsIMutationObserver) NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNodeIterator) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNodeIterator)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(NodeIterator) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(NodeIterator)
NS_INTERFACE_MAP_END NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsNodeIterator) NS_IMPL_CYCLE_COLLECTING_ADDREF(NodeIterator)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsNodeIterator) NS_IMPL_CYCLE_COLLECTING_RELEASE(NodeIterator)
/* readonly attribute nsIDOMNode root; */ /* readonly attribute nsIDOMNode root; */
NS_IMETHODIMP nsNodeIterator::GetRoot(nsIDOMNode * *aRoot) NS_IMETHODIMP NodeIterator::GetRoot(nsIDOMNode * *aRoot)
{ {
if (mRoot) if (mRoot)
return CallQueryInterface(mRoot, aRoot); return CallQueryInterface(mRoot, aRoot);
@ -195,14 +195,14 @@ NS_IMETHODIMP nsNodeIterator::GetRoot(nsIDOMNode * *aRoot)
} }
/* readonly attribute unsigned long whatToShow; */ /* readonly attribute unsigned long whatToShow; */
NS_IMETHODIMP nsNodeIterator::GetWhatToShow(uint32_t *aWhatToShow) NS_IMETHODIMP NodeIterator::GetWhatToShow(uint32_t *aWhatToShow)
{ {
*aWhatToShow = mWhatToShow; *aWhatToShow = mWhatToShow;
return NS_OK; return NS_OK;
} }
/* readonly attribute nsIDOMNodeFilter filter; */ /* readonly attribute nsIDOMNodeFilter filter; */
NS_IMETHODIMP nsNodeIterator::GetFilter(nsIDOMNodeFilter **aFilter) NS_IMETHODIMP NodeIterator::GetFilter(nsIDOMNodeFilter **aFilter)
{ {
NS_ENSURE_ARG_POINTER(aFilter); NS_ENSURE_ARG_POINTER(aFilter);
@ -212,20 +212,20 @@ NS_IMETHODIMP nsNodeIterator::GetFilter(nsIDOMNodeFilter **aFilter)
} }
/* nsIDOMNode nextNode () raises (DOMException); */ /* nsIDOMNode nextNode () raises (DOMException); */
NS_IMETHODIMP nsNodeIterator::NextNode(nsIDOMNode **_retval) NS_IMETHODIMP NodeIterator::NextNode(nsIDOMNode **_retval)
{ {
return NextOrPrevNode(&NodePointer::MoveToNext, _retval); return NextOrPrevNode(&NodePointer::MoveToNext, _retval);
} }
/* nsIDOMNode previousNode () raises (DOMException); */ /* nsIDOMNode previousNode () raises (DOMException); */
NS_IMETHODIMP nsNodeIterator::PreviousNode(nsIDOMNode **_retval) NS_IMETHODIMP NodeIterator::PreviousNode(nsIDOMNode **_retval)
{ {
return NextOrPrevNode(&NodePointer::MoveToPrevious, _retval); return NextOrPrevNode(&NodePointer::MoveToPrevious, _retval);
} }
nsresult nsresult
nsNodeIterator::NextOrPrevNode(NodePointer::MoveToMethodType aMove, NodeIterator::NextOrPrevNode(NodePointer::MoveToMethodType aMove,
nsIDOMNode **_retval) nsIDOMNode **_retval)
{ {
nsresult rv; nsresult rv;
int16_t filtered; int16_t filtered;
@ -261,7 +261,7 @@ nsNodeIterator::NextOrPrevNode(NodePointer::MoveToMethodType aMove,
} }
/* void detach (); */ /* void detach (); */
NS_IMETHODIMP nsNodeIterator::Detach(void) NS_IMETHODIMP NodeIterator::Detach(void)
{ {
if (!mDetached) { if (!mDetached) {
mRoot->RemoveMutationObserver(this); mRoot->RemoveMutationObserver(this);
@ -275,7 +275,7 @@ NS_IMETHODIMP nsNodeIterator::Detach(void)
} }
/* readonly attribute nsIDOMNode referenceNode; */ /* readonly attribute nsIDOMNode referenceNode; */
NS_IMETHODIMP nsNodeIterator::GetReferenceNode(nsIDOMNode * *aRefNode) NS_IMETHODIMP NodeIterator::GetReferenceNode(nsIDOMNode * *aRefNode)
{ {
if (mPointer.mNode) if (mPointer.mNode)
return CallQueryInterface(mPointer.mNode, aRefNode); return CallQueryInterface(mPointer.mNode, aRefNode);
@ -285,7 +285,7 @@ NS_IMETHODIMP nsNodeIterator::GetReferenceNode(nsIDOMNode * *aRefNode)
} }
/* readonly attribute boolean pointerBeforeReferenceNode; */ /* readonly attribute boolean pointerBeforeReferenceNode; */
NS_IMETHODIMP nsNodeIterator::GetPointerBeforeReferenceNode(bool *aBeforeNode) NS_IMETHODIMP NodeIterator::GetPointerBeforeReferenceNode(bool *aBeforeNode)
{ {
*aBeforeNode = mPointer.mBeforeNode; *aBeforeNode = mPointer.mBeforeNode;
return NS_OK; return NS_OK;
@ -295,14 +295,17 @@ NS_IMETHODIMP nsNodeIterator::GetPointerBeforeReferenceNode(bool *aBeforeNode)
* nsIMutationObserver interface * nsIMutationObserver interface
*/ */
void nsNodeIterator::ContentRemoved(nsIDocument *aDocument, void NodeIterator::ContentRemoved(nsIDocument *aDocument,
nsIContent *aContainer, nsIContent *aContainer,
nsIContent *aChild, nsIContent *aChild,
int32_t aIndexInContainer, int32_t aIndexInContainer,
nsIContent *aPreviousSibling) nsIContent *aPreviousSibling)
{ {
nsINode *container = NODE_FROM(aContainer, aDocument); nsINode *container = NODE_FROM(aContainer, aDocument);
mPointer.AdjustAfterRemoval(mRoot, container, aChild, aPreviousSibling); mPointer.AdjustAfterRemoval(mRoot, container, aChild, aPreviousSibling);
mWorkingPointer.AdjustAfterRemoval(mRoot, container, aChild, aPreviousSibling); mWorkingPointer.AdjustAfterRemoval(mRoot, container, aChild, aPreviousSibling);
} }
} // namespace dom
} // namespace mozilla

View File

@ -8,8 +8,8 @@
* Implementation of DOM Traversal's nsIDOMNodeIterator * Implementation of DOM Traversal's nsIDOMNodeIterator
*/ */
#ifndef nsNodeIterator_h___ #ifndef mozilla_dom_NodeIterator_h
#define nsNodeIterator_h___ #define mozilla_dom_NodeIterator_h
#include "nsIDOMNodeIterator.h" #include "nsIDOMNodeIterator.h"
#include "nsTraversal.h" #include "nsTraversal.h"
@ -20,22 +20,25 @@ class nsINode;
class nsIDOMNode; class nsIDOMNode;
class nsIDOMNodeFilter; class nsIDOMNodeFilter;
class nsNodeIterator : public nsIDOMNodeIterator, namespace mozilla {
public nsTraversal, namespace dom {
public nsStubMutationObserver
class NodeIterator : public nsIDOMNodeIterator,
public nsTraversal,
public nsStubMutationObserver
{ {
public: public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIDOMNODEITERATOR NS_DECL_NSIDOMNODEITERATOR
nsNodeIterator(nsINode *aRoot, NodeIterator(nsINode *aRoot,
uint32_t aWhatToShow, uint32_t aWhatToShow,
const mozilla::dom::NodeFilterHolder &aFilter); const NodeFilterHolder &aFilter);
virtual ~nsNodeIterator(); virtual ~NodeIterator();
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsNodeIterator, nsIDOMNodeIterator) NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(NodeIterator, nsIDOMNodeIterator)
private: private:
struct NodePointer { struct NodePointer {
@ -66,4 +69,7 @@ private:
NodePointer mWorkingPointer; NodePointer mWorkingPointer;
}; };
#endif } // namespace dom
} // namespace mozilla
#endif // mozilla_dom_NodeIterator_h

View File

@ -57,7 +57,7 @@
#include "nsIDOMText.h" #include "nsIDOMText.h"
#include "nsIDOMComment.h" #include "nsIDOMComment.h"
#include "DocumentType.h" #include "DocumentType.h"
#include "nsNodeIterator.h" #include "mozilla/dom/NodeIterator.h"
#include "nsTreeWalker.h" #include "nsTreeWalker.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
@ -5386,8 +5386,8 @@ nsIDocument::CreateNodeIterator(nsINode& aRoot, uint32_t aWhatToShow,
return nullptr; return nullptr;
} }
nsRefPtr<nsNodeIterator> iterator = new nsNodeIterator(root, aWhatToShow, nsRefPtr<NodeIterator> iterator = new NodeIterator(root, aWhatToShow,
aFilter); aFilter);
return iterator.forget(); return iterator.forget();
} }

View File

@ -36,7 +36,7 @@
#include "nsISelectionPrivate.h" #include "nsISelectionPrivate.h"
#include "nsISupportsBase.h" #include "nsISupportsBase.h"
#include "nsLiteralString.h" #include "nsLiteralString.h"
#include "nsNodeIterator.h" #include "mozilla/dom/NodeIterator.h"
#include "nsTextEditRules.h" #include "nsTextEditRules.h"
#include "nsTextEditUtils.h" #include "nsTextEditUtils.h"
#include "nsUnicharUtils.h" #include "nsUnicharUtils.h"
@ -450,7 +450,7 @@ GetTextNode(nsISelection *selection, nsEditor *editor) {
NS_ENSURE_TRUE(node, nullptr); NS_ENSURE_TRUE(node, nullptr);
// This should be the root node, walk the tree looking for text nodes // This should be the root node, walk the tree looking for text nodes
mozilla::dom::NodeFilterHolder filter; mozilla::dom::NodeFilterHolder filter;
nsNodeIterator iter(node, nsIDOMNodeFilter::SHOW_TEXT, filter); mozilla::dom::NodeIterator iter(node, nsIDOMNodeFilter::SHOW_TEXT, filter);
while (!editor->IsTextNode(selNode)) { while (!editor->IsTextNode(selNode)) {
if (NS_FAILED(res = iter.NextNode(getter_AddRefs(selNode))) || !selNode) { if (NS_FAILED(res = iter.NextNode(getter_AddRefs(selNode))) || !selNode) {
return nullptr; return nullptr;