GetView(&view);
nsTextFrame::GetPosition(nsIPresContext& aCX,                         nscoord         aXCoord,                         nsIContent **   aNewContent,                         PRInt32&        aContentOffset,                         PRInt32&        aContentOffsetEnd){  nsCOMPtr<nsIPresShell> shell;  nsresult rv = aCX.GetShell(getter_AddRefs(shell));  if (NS_SUCCEEDED(rv) && shell) {    nsCOMPtr<nsIRenderingContext> acx;          rv = shell->CreateRenderingContext(this, getter_AddRefs(acx));    if (NS_SUCCEEDED(rv)) {      TextStyle ts(&aCX, *acx, mStyleContext);      if (ts.mSmallCaps || ts.mWordSpacing || ts.mLetterSpacing) {        nsresult result = GetPositionSlowly(aCX, acx, aXCoord, aNewContent,                                 aContentOffset);        aContentOffsetEnd = aContentOffset;        return result;      }      PRUnichar wordBufMem[WORD_BUF_SIZE];      PRUnichar paintBufMem[TEXT_BUF_SIZE];      PRInt32 indicies[TEXT_BUF_SIZE];      PRInt32* ip = indicies;      PRUnichar* paintBuf = paintBufMem;      if (mContentLength >= TEXT_BUF_SIZE) {        ip = new PRInt32[mContentLength+1];        paintBuf = new PRUnichar[mContentLength];      }      PRInt32 textLength;      // Find the font metrics for this text      nsIStyleContext* styleContext;      GetStyleContext(&styleContext);      const nsStyleFont *font = (const nsStyleFont*)        styleContext->GetStyleData(eStyleStruct_Font);      NS_RELEASE(styleContext);      nsCOMPtr<nsIFontMetrics> fm;      aCX.GetMetricsFor(font->mFont, getter_AddRefs(fm));      acx->SetFont(fm);      // Get the document      nsCOMPtr<nsIDocument> doc(getter_AddRefs(GetDocument(&aCX)));      // Get the renderable form of the text      nsCOMPtr<nsILineBreaker> lb;      doc->GetLineBreaker(getter_AddRefs(lb));      //nsCOMPtr<nsIWordBreaker> wb;      //doc->GetWordBreaker(getter_AddRefs(wb));      nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE,lb,nsnull);      PrepareUnicodeText(tx, ip, paintBuf, &textLength);      if (textLength <=0) //invalid frame to get position on        return NS_ERROR_FAILURE;      ip[mContentLength] = ip[mContentLength-1];      if ((ip[mContentLength]-mContentOffset) < textLength) {        //must set up last one for selection beyond edge if in boundary        ip[mContentLength]++;      }      PRInt32 index;      PRInt32 textWidth = 0;      PRUnichar* text = paintBuf;      nsPoint origin;      nsIView * view;      GetView(&view);      GetOffsetFromView(origin, &view);      PRBool found = BinarySearchForPosition(acx, text, origin.x, 0, 0,                                             PRInt32(textLength),                                             PRInt32(aXCoord) , //go to local coordinates                                             index, textWidth);      if (found) {        PRInt32 charWidth;        acx->GetWidth(text[index], charWidth);        charWidth /= 2;        if (PRInt32(aXCoord) - origin.x > textWidth+charWidth) {          index++;        }        /*offset = 0;        PRInt32 j;        PRInt32* ptr = ip;        for (j=0;j<=PRInt32(mContentLength);j++) {          if (*ptr == index+mContentOffset) {            offset = j;//+mContentOffset;            break;          }          ptr++;        }      */      }      if (ip != indicies) {        delete [] ip;      }      if (paintBuf != paintBufMem) {        delete [] paintBuf;      }      aContentOffset = index + mContentOffset;      //reusing wordBufMem      PRInt32 i;      for (i = 0;i <= mContentLength; i ++){        if (ip[i] == aContentOffset){ //reverse mapping            aContentOffset = i + mContentOffset;            break;        }      }      aContentOffsetEnd = aContentOffset;      NS_ASSERTION(i<= mContentLength, "offset we got from binary search is messed up");            *aNewContent = mContent;      if (*aNewContent) {        (*aNewContent)->AddRef();      }    }  }  return NS_OK;}