PRUint32&       aAcutalContentOffset,
PRUint32&       aActualContentOffset,
TextFrame::GetPosition(nsIPresContext& aCX,                       nsIRenderingContext * aRendContext,                       nsGUIEvent*     aEvent,                       nsIFrame*       aNewFrame,                       PRUint32&       aAcutalContentOffset,                       PRInt32&        aOffset){  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];  }  nscoord width = 0;  PRInt32 textLength;  // Find the font metrics for this text  nsIStyleContext* styleContext;  aNewFrame->GetStyleContext(&styleContext);  const nsStyleFont *font = (const nsStyleFont*)    styleContext->GetStyleData(eStyleStruct_Font);  NS_RELEASE(styleContext);  nsCOMPtr<nsIFontMetrics> fm;  aCX.GetMetricsFor(font->mFont, getter_AddRefs(fm));  aRendContext->SetFont(fm);  nsCOMPtr<nsIPresShell> shell;  aCX.GetShell(getter_AddRefs(shell));  nsCOMPtr<nsIDocument> doc;  shell->GetDocument(getter_AddRefs(doc));  // Get the renderable form of the text  nsCOMPtr<nsILineBreaker> lb;  doc->GetLineBreaker(getter_AddRefs(lb));  nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE,lb);  PrepareUnicodeText(tx,                     ip, paintBuf, textLength, width);  ip[mContentLength] = ip[mContentLength-1]+1;  PRInt32 offset = mContentOffset + mContentLength;  PRInt32 index;  PRInt32 textWidth;  PRUnichar* text = paintBuf;  nsPoint origin;  //GetOrigin(origin);  nsIView * view;  GetView(&view);  GetOffsetFromView(origin, &view);  PRBool found = BinarySearchForPosition(aRendContext, text, origin.x, 0, 0,                                         PRInt32(textLength),                                         PRInt32(aEvent->point.x) , //go to local coordinates                                         index, textWidth);  if (found) {    PRInt32 charWidth;    aRendContext->GetWidth(text[index], charWidth);    charWidth /= 2;    if (PRInt32(aEvent->point.x) - 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;  }  aAcutalContentOffset = mContentOffset;//offset;//((TextFrame *)aNewFrame)->mContentOffset;  aOffset = index;  //reusing wordBufMem  PRInt32 i;  for (i = 0;i <= mContentLength; i ++){    if (ip[i] == aOffset + mContentOffset){ //reverse mapping        aOffset = i;        break;    }  }  NS_ASSERTION(i<= mContentLength, "offset we got from binary search is messed up");  return NS_OK;}