nsCOMPtr<nsIContent> content;
nsTextFrame::IsTextInSelection(nsIPresContext* aPresContext,                               nsIRenderingContext& aRenderingContext){  nsCOMPtr<nsISelectionController> selCon;  nsCOMPtr<nsIPresShell> shell;  PRBool  displaySelection;  PRBool  isPaginated;  PRBool  isSelected;  PRInt16 selectionValue;  nsCOMPtr<nsILineBreaker> lb;  if (NS_FAILED(GetTextInfoForPainting(aPresContext,                                        aRenderingContext,                                       getter_AddRefs(shell),                                       getter_AddRefs(selCon),                                       displaySelection,                                       isPaginated,                                       isSelected,                                       selectionValue,                                       getter_AddRefs(lb)))) {    return PR_FALSE;  }  // Make enough space to transform  nsAutoTextBuffer paintBuffer;  nsAutoIndexBuffer indexBuffer;  if (NS_FAILED(indexBuffer.GrowTo(mContentLength + 1))) {    return PR_FALSE;  }  TextStyle ts(aPresContext, aRenderingContext, mStyleContext);  // Transform text from content into renderable form  // XXX If the text fragment is already Unicode and the text wasn't  // transformed when we formatted it, then there's no need to do all  // this and we should just render the text fragment directly. See  // PaintAsciiText()...  nsTextTransformer tx(lb, nsnull, aPresContext);  PRInt32 textLength;  // no need to worry about justification, that's always on the slow path  PrepareUnicodeText(tx, &indexBuffer, &paintBuffer, &textLength);  PRInt32* ip     = indexBuffer.mBuffer;  PRUnichar* text = paintBuffer.mBuffer;  if (0 != textLength) {    SelectionDetails *details = nsnull;    nsCOMPtr<nsIFrameSelection> frameSelection;    //get the frameSelection from the selection controller    if (selCon) {      frameSelection = do_QueryInterface(selCon); //this MAY implement    }    nsresult rv = NS_OK;    //if that failed get it from the pres shell    if (!frameSelection)      rv = shell->GetFrameSelection(getter_AddRefs(frameSelection));    if (NS_SUCCEEDED(rv) && 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, mContentOffset,                               mContentLength , &details, PR_FALSE);      }    }          //where are the selection points "really"    SelectionDetails *sdptr = details;    while (sdptr){      sdptr->mStart = ip[sdptr->mStart] - mContentOffset;      sdptr->mEnd = ip[sdptr->mEnd]  - mContentOffset;      sdptr = sdptr->mNext;    }    //while we have substrings...    //PRBool drawn = PR_FALSE;    DrawSelectionIterator iter(details,text,(PRUint32)textLength, ts, nsISelectionController::SELECTION_NORMAL, aPresContext);    if (!iter.IsDone() && iter.First()) {      return PR_TRUE;    }    sdptr = details;    if (details) {      while ((sdptr = details->mNext) != nsnull) {        delete details;        details = sdptr;      }      delete details;    }  }  return PR_FALSE;}