nsCOMPtr<nsIContent> noNode; mCurNode = noNode; mFirst = noNode; mLast = noNode; mIsDone = PR_TRUE;
MakeEmpty();
nsresult nsContentIterator::Init(nsIDOMRange* aRange){  if (!aRange)     return NS_ERROR_NULL_POINTER;   // get the start node and offset, convert to nsIContent  nsCOMPtr<nsIContent> cN;  nsCOMPtr<nsIDOMNode> dN;  aRange->GetStartParent(getter_AddRefs(dN));  if (!dN)     return NS_ERROR_ILLEGAL_VALUE;  cN = do_QueryInterface(dN);  if (!cN)     return NS_ERROR_FAILURE;    PRInt32 indx;  aRange->GetStartOffset(&indx);    // find first node in range  nsCOMPtr<nsIContent> cChild;  cN->ChildAt(0,*getter_AddRefs(cChild));    if (!cChild) // no children, must be a text node  {    mFirst = cN;   }  else  {    cN->ChildAt(indx,*getter_AddRefs(cChild));    if (!cChild)  // offset after last child, parent is first node    {      mFirst = cN;    }    else    {      mFirst = GetDeepFirstChild(cChild);    }    // Does that first node really intersect the range?    // the range could be collapsed, or the range could be    // 'degenerate', ie not collapsed but still containing    // no content.  In this case, we want the iterator to    // not return a first or last node, and always answer     // 'true' to IsDone()      if (!IsNodeIntersectsRange(mFirst, aRange))    {      nsCOMPtr<nsIContent> noNode;      mCurNode = noNode;      mFirst = noNode;      mLast = noNode;      mIsDone = PR_TRUE;      return NS_OK;    }  }    aRange->GetEndParent(getter_AddRefs(dN));  if (!dN)     return NS_ERROR_ILLEGAL_VALUE;  cN = do_QueryInterface(dN);  if (!cN)     return NS_ERROR_FAILURE;  aRange->GetEndOffset(&indx);    // find last node in range  cN->ChildAt(0,*getter_AddRefs(cChild));  if (!cChild) // no children, must be a text node  {    mLast = cN;   }  else if (indx == 0) // before first child, parent is last node  {    mLast = cN;   }  else  {    cN->ChildAt(--indx,*getter_AddRefs(cChild));    if (!cChild)  // offset after last child, last child is last node    {      cN->ChildCount(indx);      cN->ChildAt(--indx,*getter_AddRefs(cChild));       if (!cChild)      {        NS_NOTREACHED("nsContentIterator::nsContentIterator");        return NS_ERROR_FAILURE;       }    }    mLast = cChild;    }    mCurNode = mFirst;  return NS_OK;}