frame = GetNextInFlow();
GetNextInFlow(&frame);
nsTextFrame::SetSelected(nsPresContext* aPresContext,                         nsIDOMRange *aRange,                         PRBool aSelected,                         nsSpread aSpread){  DEBUG_VERIFY_NOT_DIRTY(mState);#if 0 //XXXrbs disable due to bug 310318  if (mState & NS_FRAME_IS_DIRTY)    return NS_ERROR_UNEXPECTED;#endif  if (aSelected && ParentDisablesSelection())    return NS_OK;#if 0  PRBool isSelected = ((GetStateBits() & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT);  if (!aSelected && !isSelected) //already set thanks  {    return NS_OK;  }#endif  // check whether style allows selection  PRBool selectable;  IsSelectable(&selectable, nsnull);  if (!selectable)    return NS_OK;//do not continue no selection for this frame.  PRBool found = PR_FALSE;  if (aRange) {    //lets see if the range contains us, if so we must redraw!    nsCOMPtr<nsIDOMNode> endNode;    PRInt32 endOffset;    nsCOMPtr<nsIDOMNode> startNode;    PRInt32 startOffset;    aRange->GetEndContainer(getter_AddRefs(endNode));    aRange->GetEndOffset(&endOffset);    aRange->GetStartContainer(getter_AddRefs(startNode));    aRange->GetStartOffset(&startOffset);    nsCOMPtr<nsIDOMNode> thisNode = do_QueryInterface(GetContent());    if (thisNode == startNode)    {      if ((mContentOffset + mContentLength) >= startOffset)      {        found = PR_TRUE;        if (thisNode == endNode)        { //special case          if (endOffset == startOffset) //no need to redraw since drawing takes place with cursor            found = PR_FALSE;          if (mContentOffset > endOffset)            found = PR_FALSE;        }      }    }    else if (thisNode == endNode)    {      if (mContentOffset < endOffset)        found = PR_TRUE;      else      {        found = PR_FALSE;      }    }    else    {      found = PR_TRUE;    }  }  else {    // null range means the whole thing    found = PR_TRUE;  }  if ( aSelected )    AddStateBits(NS_FRAME_SELECTED_CONTENT);  else  {//we need to see if any other selection available.    SelectionDetails *details = nsnull;    nsCOMPtr<nsIFrameSelection> frameSelection;    nsIPresShell *shell = aPresContext->GetPresShell();    if (shell) {      nsCOMPtr<nsISelectionController> selCon;      nsresult rv = GetSelectionController(aPresContext,                                           getter_AddRefs(selCon));      if (NS_SUCCEEDED(rv) && selCon)      {        frameSelection = do_QueryInterface(selCon); //this MAY implement      }      if (!frameSelection)        frameSelection = shell->FrameSelection();      nsCOMPtr<nsIContent> content;      PRInt32 offset;      PRInt32 length;      rv = GetContentAndOffsetsForSelection(aPresContext,                                            getter_AddRefs(content),                                            &offset, &length);      if (NS_SUCCEEDED(rv) && content) {        rv = frameSelection->LookUpSelection(content, offset,                                             length, &details, PR_TRUE);        // PR_TRUE last param used here! we need to see if we are still selected. so no shortcut      }    }    if (!details)      RemoveStateBits(NS_FRAME_SELECTED_CONTENT);    else    {      SelectionDetails *sdptr = details;      while ((sdptr = details->mNext) != nsnull) {        delete details;        details = sdptr;      }      delete details;    }  }  if (found){ //if range contains this frame...    // Selection might change our border, content and outline appearance    // But textframes can't have an outline. So just use the simple    // bounds    Invalidate(nsRect(0, 0, mRect.width, mRect.height), PR_FALSE);  }  if (aSpread == eSpreadDown)  {    nsIFrame* frame = GetPrevInFlow();    while(frame){      frame->SetSelected(aPresContext, aRange,aSelected,eSpreadNone);      frame = frame->GetPrevInFlow();    }    frame = GetNextInFlow();    while (frame){      frame->SetSelected(aPresContext, aRange,aSelected,eSpreadNone);      frame = frame->GetNextInFlow();    }#ifdef IBMBIDI    if ((mState & NS_FRAME_IS_BIDI) &&        (frame = NS_STATIC_CAST(nsIFrame*,                                aPresContext->PropertyTable()->GetProperty(this, nsLayoutAtoms::nextBidi)))) {      frame->SetSelected(aPresContext, aRange, aSelected, aSpread);    }#endif // IBMBIDI  }  return NS_OK;}