acx->GetWidth(text[indx], charWidth);
if (IS_HIGH_SURROGATE(text[indx])) acx->GetWidth(&text[indx], 2, charWidth); else acx->GetWidth(text[indx], charWidth);
nsTextFrame::GetPosition(nsPresContext* aCX,                         const nsPoint&  aPoint,                         nsIContent **   aNewContent,                         PRInt32&        aContentOffset,                         PRInt32&        aContentOffsetEnd){  // pre-condition tests  NS_PRECONDITION(aCX && aNewContent, "null arg");  if (!aCX || !aNewContent) {    return NS_ERROR_NULL_POINTER;  }  // initialize out param  *aNewContent = nsnull;  nsIPresShell *shell = aCX->GetPresShell();  if (shell) {    nsCOMPtr<nsIRenderingContext> acx;          nsresult rv = shell->CreateRenderingContext(this, getter_AddRefs(acx));    if (NS_SUCCEEDED(rv)) {      TextStyle ts(aCX, *acx, mStyleContext);      if (ts.mSmallCaps || ts.mWordSpacing || ts.mLetterSpacing || ts.mJustifying) {        nsresult result = GetPositionSlowly(aCX, acx, aPoint, aNewContent,                                 aContentOffset);        aContentOffsetEnd = aContentOffset;        return result;      }      // Make enough space to transform      nsAutoTextBuffer paintBuffer;      nsAutoIndexBuffer indexBuffer;      rv = indexBuffer.GrowTo(mContentLength + 1);      if (NS_FAILED(rv)) {        return rv;      }      // Find the font metrics for this text      SetFontFromStyle(acx, mStyleContext);      // Get the renderable form of the text      nsIDocument *doc = GetDocument(aCX);      nsTextTransformer tx(doc->GetLineBreaker(), nsnull, aCX);      PRInt32 textLength;      // no need to worry about justification, that's always on the slow path      PrepareUnicodeText(tx, &indexBuffer, &paintBuffer, &textLength);      if (textLength <=0) {        //invalid frame to get position on        return NS_ERROR_FAILURE;      }      nsPoint origin;      nsIView * view;      GetOffsetFromView(aCX, origin, &view);//IF STYLE SAYS TO SELECT TO END OF FRAME HERE...      PRInt32 prefInt =        nsContentUtils::GetIntPref("browser.drag_out_of_frame_style");      PRBool outofstylehandled = PR_FALSE;      if (prefInt)      {        if ((aPoint.y - origin.y) < 0)//above rectangle        {          aContentOffset = mContentOffset;          aContentOffsetEnd = aContentOffset;          outofstylehandled = PR_TRUE;        }        else if ((aPoint.y - origin.y) > mRect.height)        {          aContentOffset = mContentOffset + mContentLength;          aContentOffsetEnd = aContentOffset;          outofstylehandled = PR_TRUE;        }      }      if (!outofstylehandled) //then we need to track based on the X coord only      {//END STYLE IF        PRInt32* ip = indexBuffer.mBuffer;        PRInt32 indx;        PRInt32 textWidth = 0;        PRUnichar* text = paintBuffer.mBuffer;#ifdef IBMBIDI        PRBool getReversedPos = NS_GET_EMBEDDING_LEVEL(this) & 1;        nscoord posX = (getReversedPos) ?                       (mRect.width + origin.x) - (aPoint.x - origin.x) : aPoint.x;        PRBool found = BinarySearchForPosition(acx, text, origin.x, 0, 0,                                               PRInt32(textLength),                                               PRInt32(posX) , //go to local coordinates                                               indx, textWidth);#else        PRBool found = BinarySearchForPosition(acx, text, origin.x, 0, 0,                                               PRInt32(textLength),                                               PRInt32(aPoint.x) , //go to local coordinates                                               indx, textWidth);#endif // IBMBIDI        if (found) {          PRInt32 charWidth;          acx->GetWidth(text[indx], charWidth);          charWidth /= 2;#ifdef IBMBIDI          if (getReversedPos) {            if (mRect.width - aPoint.x + origin.x > textWidth+charWidth ) {              indx++;            }          }          else#endif // IBMBIDI          if ((aPoint.x - origin.x) > textWidth+charWidth) {            indx++;          }        }        aContentOffset = indx + mContentOffset;        //reusing wordBufMem        PRInt32 i;        for (i = 0; i < mContentLength; i ++){          if ((ip[i] >= aContentOffset) && //reverse mapping              (! IS_LOW_SURROGATE(paintBuffer.mBuffer[ip[i]-mContentOffset]))) {              break;          }        }        aContentOffset = i + mContentOffset;#ifdef IBMBIDI        PRInt32 bidiStopOffset = mContentOffset + mContentLength;        if (aContentOffset >= mContentOffset && aContentOffset < bidiStopOffset) {          PRInt32 curindx = ip[aContentOffset - mContentOffset] - mContentOffset;          while (curindx < textLength && IS_BIDI_DIACRITIC(text[curindx])) {            if (++aContentOffset >= bidiStopOffset)              break;            curindx = ip[aContentOffset - mContentOffset] - mContentOffset;          }        }#endif // IBMBIDI        aContentOffsetEnd = aContentOffset;        NS_ASSERTION(i<= mContentLength, "offset we got from binary search is messed up");      }            *aNewContent = mContent;      if (*aNewContent) {        (*aNewContent)->AddRef();      }    }  }  return NS_OK;}