From 4db505431f8574c7b5e0849b6fe443370df676c9 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 28 Feb 2013 12:56:41 -0500 Subject: [PATCH] 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 --- content/base/src/Makefile.in | 3 +- .../{nsNodeIterator.cpp => NodeIterator.cpp} | 81 ++++++++++--------- .../src/{nsNodeIterator.h => NodeIterator.h} | 28 ++++--- content/base/src/nsDocument.cpp | 6 +- editor/libeditor/text/nsTextEditRules.cpp | 4 +- 5 files changed, 66 insertions(+), 56 deletions(-) rename content/base/src/{nsNodeIterator.cpp => NodeIterator.cpp} (71%) rename content/base/src/{nsNodeIterator.h => NodeIterator.h} (72%) diff --git a/content/base/src/Makefile.in b/content/base/src/Makefile.in index 9456cf22fd8e..788bef98e9c4 100644 --- a/content/base/src/Makefile.in +++ b/content/base/src/Makefile.in @@ -51,6 +51,7 @@ EXPORTS_mozilla/dom = \ DOMImplementation.h \ EventSource.h \ Link.h \ + NodeIterator.h \ Text.h \ $(NULL) @@ -107,7 +108,7 @@ CPPSRCS = \ nsNoDataProtocolContentPolicy.cpp \ nsNodeInfo.cpp \ nsNodeInfoManager.cpp \ - nsNodeIterator.cpp \ + NodeIterator.cpp \ nsNodeUtils.cpp \ nsObjectLoadingContent.cpp \ nsPlainTextSerializer.cpp \ diff --git a/content/base/src/nsNodeIterator.cpp b/content/base/src/NodeIterator.cpp similarity index 71% rename from content/base/src/nsNodeIterator.cpp rename to content/base/src/NodeIterator.cpp index fe821a366a5e..ef900aefa55d 100644 --- a/content/base/src/nsNodeIterator.cpp +++ b/content/base/src/NodeIterator.cpp @@ -8,7 +8,7 @@ * Implementation of DOM Traversal's nsIDOMNodeIterator */ -#include "nsNodeIterator.h" +#include "mozilla/dom/NodeIterator.h" #include "nsIDOMNode.h" #include "nsIDOMNodeFilter.h" @@ -21,19 +21,21 @@ #include "nsCOMPtr.h" #include "mozilla/dom/NodeFilterBinding.h" -using namespace mozilla::dom; +DOMCI_DATA(NodeIterator, mozilla::dom::NodeIterator) + +namespace mozilla { +namespace dom { /* * NodePointer implementation */ -nsNodeIterator::NodePointer::NodePointer(nsINode *aNode, - bool aBeforeNode) : +NodeIterator::NodePointer::NodePointer(nsINode *aNode, bool aBeforeNode) : mNode(aNode), mBeforeNode(aBeforeNode) { } -bool nsNodeIterator::NodePointer::MoveToNext(nsINode *aRoot) +bool NodeIterator::NodePointer::MoveToNext(nsINode *aRoot) { if (!mNode) return false; @@ -52,7 +54,7 @@ bool nsNodeIterator::NodePointer::MoveToNext(nsINode *aRoot) return MoveForward(aRoot, mNode); } -bool nsNodeIterator::NodePointer::MoveToPrevious(nsINode *aRoot) +bool NodeIterator::NodePointer::MoveToPrevious(nsINode *aRoot) { if (!mNode) return false; @@ -70,10 +72,10 @@ bool nsNodeIterator::NodePointer::MoveToPrevious(nsINode *aRoot) return true; } -void nsNodeIterator::NodePointer::AdjustAfterRemoval(nsINode *aRoot, - nsINode *aContainer, - nsIContent *aChild, - nsIContent *aPreviousSibling) +void NodeIterator::NodePointer::AdjustAfterRemoval(nsINode *aRoot, + nsINode *aContainer, + nsIContent *aChild, + nsIContent *aPreviousSibling) { // If mNode is null or the root there is nothing to do. if (!mNode || mNode == aRoot) @@ -105,7 +107,7 @@ void nsNodeIterator::NodePointer::AdjustAfterRemoval(nsINode *aRoot, MoveBackward(aContainer, aPreviousSibling); } -bool nsNodeIterator::NodePointer::MoveForward(nsINode *aRoot, nsINode *aNode) +bool NodeIterator::NodePointer::MoveForward(nsINode *aRoot, nsINode *aNode) { while (1) { if (aNode == aRoot) @@ -122,7 +124,7 @@ bool nsNodeIterator::NodePointer::MoveForward(nsINode *aRoot, nsINode *aNode) return false; } -void nsNodeIterator::NodePointer::MoveBackward(nsINode *aParent, nsINode *aNode) +void NodeIterator::NodePointer::MoveBackward(nsINode *aParent, nsINode *aNode) { if (aNode) { do { @@ -138,9 +140,9 @@ void nsNodeIterator::NodePointer::MoveBackward(nsINode *aParent, nsINode *aNode) * Factories, constructors and destructors */ -nsNodeIterator::nsNodeIterator(nsINode *aRoot, - uint32_t aWhatToShow, - const NodeFilterHolder &aFilter) : +NodeIterator::NodeIterator(nsINode *aRoot, + uint32_t aWhatToShow, + const NodeFilterHolder &aFilter) : nsTraversal(aRoot, aWhatToShow, aFilter), mDetached(false), mPointer(mRoot, true) @@ -148,7 +150,7 @@ nsNodeIterator::nsNodeIterator(nsINode *aRoot, aRoot->AddMutationObserver(this); } -nsNodeIterator::~nsNodeIterator() +NodeIterator::~NodeIterator() { /* destructor code */ if (!mDetached && mRoot) @@ -159,32 +161,30 @@ nsNodeIterator::~nsNodeIterator() * nsISupports and cycle collection stuff */ -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsNodeIterator) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(NodeIterator) if (!tmp->mDetached && tmp->mRoot) tmp->mRoot->RemoveMutationObserver(tmp); NS_IMPL_CYCLE_COLLECTION_UNLINK(mRoot) NS_IMPL_CYCLE_COLLECTION_UNLINK(mFilter) 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(mFilter) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END -DOMCI_DATA(NodeIterator, nsNodeIterator) - -// QueryInterface implementation for nsNodeIterator -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsNodeIterator) +// QueryInterface implementation for NodeIterator +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(NodeIterator) NS_INTERFACE_MAP_ENTRY(nsIDOMNodeIterator) NS_INTERFACE_MAP_ENTRY(nsIMutationObserver) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNodeIterator) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(NodeIterator) NS_INTERFACE_MAP_END -NS_IMPL_CYCLE_COLLECTING_ADDREF(nsNodeIterator) -NS_IMPL_CYCLE_COLLECTING_RELEASE(nsNodeIterator) +NS_IMPL_CYCLE_COLLECTING_ADDREF(NodeIterator) +NS_IMPL_CYCLE_COLLECTING_RELEASE(NodeIterator) /* readonly attribute nsIDOMNode root; */ -NS_IMETHODIMP nsNodeIterator::GetRoot(nsIDOMNode * *aRoot) +NS_IMETHODIMP NodeIterator::GetRoot(nsIDOMNode * *aRoot) { if (mRoot) return CallQueryInterface(mRoot, aRoot); @@ -195,14 +195,14 @@ NS_IMETHODIMP nsNodeIterator::GetRoot(nsIDOMNode * *aRoot) } /* readonly attribute unsigned long whatToShow; */ -NS_IMETHODIMP nsNodeIterator::GetWhatToShow(uint32_t *aWhatToShow) +NS_IMETHODIMP NodeIterator::GetWhatToShow(uint32_t *aWhatToShow) { *aWhatToShow = mWhatToShow; return NS_OK; } /* readonly attribute nsIDOMNodeFilter filter; */ -NS_IMETHODIMP nsNodeIterator::GetFilter(nsIDOMNodeFilter **aFilter) +NS_IMETHODIMP NodeIterator::GetFilter(nsIDOMNodeFilter **aFilter) { NS_ENSURE_ARG_POINTER(aFilter); @@ -212,20 +212,20 @@ NS_IMETHODIMP nsNodeIterator::GetFilter(nsIDOMNodeFilter **aFilter) } /* nsIDOMNode nextNode () raises (DOMException); */ -NS_IMETHODIMP nsNodeIterator::NextNode(nsIDOMNode **_retval) +NS_IMETHODIMP NodeIterator::NextNode(nsIDOMNode **_retval) { return NextOrPrevNode(&NodePointer::MoveToNext, _retval); } /* nsIDOMNode previousNode () raises (DOMException); */ -NS_IMETHODIMP nsNodeIterator::PreviousNode(nsIDOMNode **_retval) +NS_IMETHODIMP NodeIterator::PreviousNode(nsIDOMNode **_retval) { return NextOrPrevNode(&NodePointer::MoveToPrevious, _retval); } nsresult -nsNodeIterator::NextOrPrevNode(NodePointer::MoveToMethodType aMove, - nsIDOMNode **_retval) +NodeIterator::NextOrPrevNode(NodePointer::MoveToMethodType aMove, + nsIDOMNode **_retval) { nsresult rv; int16_t filtered; @@ -261,7 +261,7 @@ nsNodeIterator::NextOrPrevNode(NodePointer::MoveToMethodType aMove, } /* void detach (); */ -NS_IMETHODIMP nsNodeIterator::Detach(void) +NS_IMETHODIMP NodeIterator::Detach(void) { if (!mDetached) { mRoot->RemoveMutationObserver(this); @@ -275,7 +275,7 @@ NS_IMETHODIMP nsNodeIterator::Detach(void) } /* readonly attribute nsIDOMNode referenceNode; */ -NS_IMETHODIMP nsNodeIterator::GetReferenceNode(nsIDOMNode * *aRefNode) +NS_IMETHODIMP NodeIterator::GetReferenceNode(nsIDOMNode * *aRefNode) { if (mPointer.mNode) return CallQueryInterface(mPointer.mNode, aRefNode); @@ -285,7 +285,7 @@ NS_IMETHODIMP nsNodeIterator::GetReferenceNode(nsIDOMNode * *aRefNode) } /* readonly attribute boolean pointerBeforeReferenceNode; */ -NS_IMETHODIMP nsNodeIterator::GetPointerBeforeReferenceNode(bool *aBeforeNode) +NS_IMETHODIMP NodeIterator::GetPointerBeforeReferenceNode(bool *aBeforeNode) { *aBeforeNode = mPointer.mBeforeNode; return NS_OK; @@ -295,14 +295,17 @@ NS_IMETHODIMP nsNodeIterator::GetPointerBeforeReferenceNode(bool *aBeforeNode) * nsIMutationObserver interface */ -void nsNodeIterator::ContentRemoved(nsIDocument *aDocument, - nsIContent *aContainer, - nsIContent *aChild, - int32_t aIndexInContainer, - nsIContent *aPreviousSibling) +void NodeIterator::ContentRemoved(nsIDocument *aDocument, + nsIContent *aContainer, + nsIContent *aChild, + int32_t aIndexInContainer, + nsIContent *aPreviousSibling) { nsINode *container = NODE_FROM(aContainer, aDocument); mPointer.AdjustAfterRemoval(mRoot, container, aChild, aPreviousSibling); mWorkingPointer.AdjustAfterRemoval(mRoot, container, aChild, aPreviousSibling); } + +} // namespace dom +} // namespace mozilla diff --git a/content/base/src/nsNodeIterator.h b/content/base/src/NodeIterator.h similarity index 72% rename from content/base/src/nsNodeIterator.h rename to content/base/src/NodeIterator.h index e1f727b843c5..47ac10c85b7a 100644 --- a/content/base/src/nsNodeIterator.h +++ b/content/base/src/NodeIterator.h @@ -8,8 +8,8 @@ * Implementation of DOM Traversal's nsIDOMNodeIterator */ -#ifndef nsNodeIterator_h___ -#define nsNodeIterator_h___ +#ifndef mozilla_dom_NodeIterator_h +#define mozilla_dom_NodeIterator_h #include "nsIDOMNodeIterator.h" #include "nsTraversal.h" @@ -20,22 +20,25 @@ class nsINode; class nsIDOMNode; class nsIDOMNodeFilter; -class nsNodeIterator : public nsIDOMNodeIterator, - public nsTraversal, - public nsStubMutationObserver +namespace mozilla { +namespace dom { + +class NodeIterator : public nsIDOMNodeIterator, + public nsTraversal, + public nsStubMutationObserver { public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_NSIDOMNODEITERATOR - nsNodeIterator(nsINode *aRoot, - uint32_t aWhatToShow, - const mozilla::dom::NodeFilterHolder &aFilter); - virtual ~nsNodeIterator(); + NodeIterator(nsINode *aRoot, + uint32_t aWhatToShow, + const NodeFilterHolder &aFilter); + virtual ~NodeIterator(); NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED - NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsNodeIterator, nsIDOMNodeIterator) + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(NodeIterator, nsIDOMNodeIterator) private: struct NodePointer { @@ -66,4 +69,7 @@ private: NodePointer mWorkingPointer; }; -#endif +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_NodeIterator_h diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 90c21afb9d88..39e1f5ff7869 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -57,7 +57,7 @@ #include "nsIDOMText.h" #include "nsIDOMComment.h" #include "DocumentType.h" -#include "nsNodeIterator.h" +#include "mozilla/dom/NodeIterator.h" #include "nsTreeWalker.h" #include "nsIServiceManager.h" @@ -5386,8 +5386,8 @@ nsIDocument::CreateNodeIterator(nsINode& aRoot, uint32_t aWhatToShow, return nullptr; } - nsRefPtr iterator = new nsNodeIterator(root, aWhatToShow, - aFilter); + nsRefPtr iterator = new NodeIterator(root, aWhatToShow, + aFilter); return iterator.forget(); } diff --git a/editor/libeditor/text/nsTextEditRules.cpp b/editor/libeditor/text/nsTextEditRules.cpp index ac48e0b7d131..2912298980e7 100644 --- a/editor/libeditor/text/nsTextEditRules.cpp +++ b/editor/libeditor/text/nsTextEditRules.cpp @@ -36,7 +36,7 @@ #include "nsISelectionPrivate.h" #include "nsISupportsBase.h" #include "nsLiteralString.h" -#include "nsNodeIterator.h" +#include "mozilla/dom/NodeIterator.h" #include "nsTextEditRules.h" #include "nsTextEditUtils.h" #include "nsUnicharUtils.h" @@ -450,7 +450,7 @@ GetTextNode(nsISelection *selection, nsEditor *editor) { NS_ENSURE_TRUE(node, nullptr); // This should be the root node, walk the tree looking for text nodes mozilla::dom::NodeFilterHolder filter; - nsNodeIterator iter(node, nsIDOMNodeFilter::SHOW_TEXT, filter); + mozilla::dom::NodeIterator iter(node, nsIDOMNodeFilter::SHOW_TEXT, filter); while (!editor->IsTextNode(selNode)) { if (NS_FAILED(res = iter.NextNode(getter_AddRefs(selNode))) || !selNode) { return nullptr;