nsTextTransformer tx(lb, nsnull);
nsTextTransformer tx(lb, nsnull, aCX);
nsTextFrame::GetPosition(nsIPresContext* aCX,                         const nsPoint&  aPoint,                         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 || 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      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 renderable form of the text      nsCOMPtr<nsIDocument> doc(getter_AddRefs(GetDocument(aCX)));      nsCOMPtr<nsILineBreaker> lb;      doc->GetLineBreaker(getter_AddRefs(lb));      nsTextTransformer tx(lb, nsnull);      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...      nsCOMPtr<nsIPref>     prefs;      PRInt32 prefInt = 0;      rv = nsServiceManager::GetService(kPrefCID,                                         NS_GET_IID(nsIPref),                                         (nsISupports**)&prefs);       PRBool outofstylehandled = PR_FALSE;      if (NS_SUCCEEDED(rv) && prefs)       {         if (NS_SUCCEEDED(prefs->GetIntPref("browser.drag_out_of_frame_style", &prefInt)) && 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;        PRBool found = BinarySearchForPosition(acx, text, origin.x, 0, 0,                                               PRInt32(textLength),                                               PRInt32(aPoint.x) , //go to local coordinates                                               indx, textWidth);        if (found) {          PRInt32 charWidth;          acx->GetWidth(text[indx], charWidth);          charWidth /= 2;          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              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;}