mIsDone = PR_FALSE;
nsresult nsContentIterator::Init(nsIDOMRange* aRange){  if (!aRange)     return NS_ERROR_NULL_POINTER;   nsCOMPtr<nsIDOMNode> dN;  nsCOMPtr<nsIContent> cChild;    nsCOMPtr<nsIContent> startCon;  nsCOMPtr<nsIDOMNode> startDOM;  nsCOMPtr<nsIContent> endCon;  nsCOMPtr<nsIDOMNode> endDOM;  PRInt32 startIndx;  PRInt32 endIndx;    // get common content parent  if (NS_FAILED(aRange->GetCommonParent(getter_AddRefs(dN))) || !dN)    return NS_ERROR_FAILURE;  mCommonParent = do_QueryInterface(dN);  // get the start node and offset, convert to nsIContent  aRange->GetStartParent(getter_AddRefs(startDOM));  if (!startDOM)     return NS_ERROR_ILLEGAL_VALUE;  startCon = do_QueryInterface(startDOM);  if (!startCon)     return NS_ERROR_FAILURE;    aRange->GetStartOffset(&startIndx);    // get the end node and offset, convert to nsIContent  aRange->GetEndParent(getter_AddRefs(endDOM));  if (!endDOM)     return NS_ERROR_ILLEGAL_VALUE;  endCon = do_QueryInterface(endDOM);  if (!endCon)     return NS_ERROR_FAILURE;  aRange->GetEndOffset(&endIndx);    // short circuit when start node == end node  if (startDOM == endDOM)  {    startCon->ChildAt(0,*getter_AddRefs(cChild));      if (!cChild) // no children, must be a text node or empty container    {      mFirst = startCon;      mLast = startCon;      mCurNode = startCon;      return NS_OK;    }    else    {      if (startIndx == endIndx)  // collapsed range      {        MakeEmpty();        return NS_OK;      }    }  }    // find first node in range  startCon->ChildAt(0,*getter_AddRefs(cChild));    if (!cChild) // no children, must be a text node  {    mFirst = startCon;   }  else  {    startCon->ChildAt(startIndx,*getter_AddRefs(cChild));    if (!cChild)  // offset after last child, parent is first node    {      mFirst = startCon;    }    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    // be empty      if (!IsNodeIntersectsRange(mFirst, aRange))    {      MakeEmpty();      return NS_OK;    }  }    // find last node in range  endCon->ChildAt(0,*getter_AddRefs(cChild));  if (!cChild) // no children, must be a text node  {    mLast = endCon;   }  else if (endIndx == 0) // before first child, parent is last node  {    mLast = endCon;   }  else  {    endCon->ChildAt(--endIndx,*getter_AddRefs(cChild));    if (!cChild)  // offset after last child, last child is last node    {      endCon->ChildCount(endIndx);      endCon->ChildAt(--endIndx,*getter_AddRefs(cChild));       if (!cChild)      {        NS_NOTREACHED("nsContentIterator::nsContentIterator");        return NS_ERROR_FAILURE;       }    }    mLast = cChild;    }    mCurNode = mFirst;  return NS_OK;}