wordLen = (mState & NS_FRAME_IS_BIDI) ? mContentOffset + mContentLength : -1;
if (aNextFrame->GetStateBits() & NS_FRAME_IS_BIDI) { PRInt32 nextFrameStart, nextFrameEnd; aNextFrame->GetOffsets(nextFrameStart, nextFrameEnd); wordLen = nextFrameEnd; } else { wordLen = -1; }
nsTextFrame::ComputeWordFragmentDimensions(nsPresContext* aPresContext,                                      nsILineBreaker* aLineBreaker,                                      nsLineLayout& aLineLayout,                                      const nsHTMLReflowState& aReflowState,                                      nsIFrame* aTextFrame,                                      nsIContent* aContent,                                      nsITextContent* aText,                                      PRBool* aStop,                                      const PRUnichar* aWordBuf,                                      PRUint32& aRunningWordLen,                                      PRUint32 aWordBufSize,                                      PRBool aCanBreakBefore){  nsTextTransformer tx(aLineBreaker, nsnull, aPresContext);  tx.Init(aTextFrame, aContent, 0);  PRBool isWhitespace, wasTransformed;  PRInt32 wordLen, contentLen;  nsTextDimensions dimensions;#ifdef IBMBIDI  wordLen = (mState & NS_FRAME_IS_BIDI) ? mContentOffset + mContentLength : -1;#endif // IBMBIDI  PRUnichar* bp = tx.GetNextWord(PR_TRUE, &wordLen, &contentLen, &isWhitespace, &wasTransformed);  if (!bp) {    //empty text node, but we need to continue lookahead measurement    // AND we need to remember the text frame for later so that we don't     // bother doing the word look ahead.    aLineLayout.RecordWordFrame(aTextFrame);    return dimensions; // 0  }  if (isWhitespace) {    // Don't bother measuring nothing    *aStop = PR_TRUE;    return dimensions; // 0  }  // We need to adjust the length by look at the two pieces together  // but if we have to grow aWordBuf, ask caller do it by return a negative value of size  if ((wordLen + aRunningWordLen) > aWordBufSize) {    dimensions.width = aWordBufSize - wordLen - aRunningWordLen;     return dimensions;  }  *aStop = contentLen < tx.GetContentLength();  // Convert any spaces in the current word back to nbsp's. This keeps  // the breaking logic happy.  RevertSpacesToNBSP(bp, wordLen);  if (aCanBreakBefore) {    if(wordLen > 0)    {      memcpy((void*)&(aWordBuf[aRunningWordLen]), bp, sizeof(PRUnichar)*wordLen);            PRUint32 breakP=0;      PRBool needMore=PR_TRUE;      nsresult lres = aLineBreaker->Next(aWordBuf, aRunningWordLen+wordLen,                                         0, &breakP, &needMore);      if(NS_SUCCEEDED(lres))         {          // when we look at two pieces text together, we might decide to break            // eariler than if we only look at the 2nd pieces of text          if(!needMore && (breakP < (aRunningWordLen + wordLen)))            {              wordLen = breakP - aRunningWordLen;               if(wordLen < 0)                  wordLen = 0;              *aStop = PR_TRUE;            }         }            // if we don't stop, we need to extend the buf so the next one can      // see this part otherwise, it does not matter since we will stop      // anyway      if(! *aStop)         aRunningWordLen += wordLen;    }  }  else {    // Even if the previous text fragment is not breakable, the connected pieces     // can be breakable in between. This especially true for CJK.    PRBool canBreak;    nsresult lres = aLineBreaker->BreakInBetween(aWordBuf, aRunningWordLen, bp, wordLen, &canBreak);    if (NS_SUCCEEDED(lres) && canBreak) {      wordLen = 0;      *aStop = PR_TRUE;    }  }  if((*aStop) && (wordLen == 0))    return dimensions; // 0;  nsStyleContext* sc = aTextFrame->GetStyleContext();  if (sc) {    // Measure the piece of text. Note that we have to select the    // appropriate font into the text first because the rendering    // context has our font in it, not the font that aText is using.    nsIRenderingContext& rc = *aReflowState.rendContext;    nsCOMPtr<nsIFontMetrics> oldfm;    rc.GetFontMetrics(*getter_AddRefs(oldfm));    TextStyle ts(aLineLayout.mPresContext, rc, sc);    if (ts.mSmallCaps) {      MeasureSmallCapsText(aReflowState, ts, bp, wordLen, PR_FALSE, &dimensions);    }    else {      rc.GetTextDimensions(bp, wordLen, dimensions);      // NOTE: Don't forget to add letter spacing for the word fragment!      dimensions.width += wordLen*ts.mLetterSpacing;    }    rc.SetFont(oldfm);#ifdef DEBUG_WORD_WRAPPING    nsAutoString tmp(bp, wordLen);    printf("  fragment='");    fputs(NS_LossyConvertUCS2toASCII(tmp).get(), stdout);    printf("' width=%d [wordLen=%d contentLen=%d ContentLength=%d]\n",           dimensions.width, wordLen, contentLen, tx.GetContentLength());#endif    // Remember the text frame for later so that we don't bother doing    // the word look ahead.    aLineLayout.RecordWordFrame(aTextFrame);    return dimensions;  }  *aStop = PR_TRUE;  return dimensions; // 0}