moreWidth = ComputeWordFragmentWidth(aPresContext, aLineBreaker, aLineLayout, aReflowState, aNextFrame, content, tc, &stop, newWordBuf, aWordLen, newWordBufSize); NS_ASSERTION((moreWidth >= 0), "ComputeWordFragmentWidth is returning negative");
if(newWordBuf)  { moreWidth = ComputeWordFragmentWidth(aPresContext, aLineBreaker, aLineLayout, aReflowState, aNextFrame, content, tc, &stop, newWordBuf, aWordLen, newWordBufSize); NS_ASSERTION((moreWidth >= 0), "ComputeWordFragmentWidth is returning negative"); } else { stop = PR_TRUE; moreWidth = 0; }
nsTextFrame::ComputeTotalWordWidth(nsIPresContext* aPresContext,                                   nsILineBreaker* aLineBreaker,                                   nsLineLayout& aLineLayout,                                   const nsHTMLReflowState& aReflowState,                                   nsIFrame* aNextFrame,                                   nscoord aBaseWidth,                                   PRUnichar* aWordBuf,                                   PRUint32 aWordLen,                                   PRUint32 aWordBufSize){  // Before we get going, convert any spaces in the current word back  // to nbsp's. This keeps the breaking logic happy.  RevertSpacesToNBSP(aWordBuf, (PRInt32) aWordLen);  nscoord addedWidth = 0;  PRUnichar *newWordBuf = aWordBuf;  PRUint32 newWordBufSize = aWordBufSize;  while (nsnull != aNextFrame) {    nsIContent* content = nsnull;    if ((NS_OK == aNextFrame->GetContent(&content)) && (nsnull != content)) {#ifdef DEBUG_WORD_WRAPPING      printf("  next textRun=");      nsFrame::ListTag(stdout, aNextFrame);      printf("\n");#endif      nsITextContent* tc;      if (NS_OK == content->QueryInterface(kITextContentIID, (void**)&tc)) {        PRBool stop = PR_FALSE;        nscoord moreWidth;        moreWidth = ComputeWordFragmentWidth(aPresContext,                                                   aLineBreaker,                                                   aLineLayout,                                                   aReflowState,                                                   aNextFrame, content, tc,                                                   &stop,                                                   newWordBuf,                                                   aWordLen,                                                   newWordBufSize);        if (moreWidth < 0) {          PRUint32 moreSize = -moreWidth;          //Oh, wordBuf is too small, we have to grow it          newWordBufSize += moreSize;          if (newWordBuf != aWordBuf) {            newWordBuf = (PRUnichar*)nsMemory::Realloc(newWordBuf, sizeof(PRUnichar)*newWordBufSize);          } else {            newWordBuf = (PRUnichar*)nsMemory::Alloc(sizeof(PRUnichar)*newWordBufSize);            nsCRT::memcpy((void*)newWordBuf, aWordBuf, sizeof(PRUnichar)*newWordBufSize-moreSize);          }          moreWidth = ComputeWordFragmentWidth(aPresContext,                                                   aLineBreaker,                                                   aLineLayout,                                                   aReflowState,                                                   aNextFrame, content, tc,                                                   &stop,                                                   newWordBuf,                                                   aWordLen,                                                   newWordBufSize);          NS_ASSERTION((moreWidth >= 0), "ComputeWordFragmentWidth is returning negative");        }        NS_RELEASE(tc);        NS_RELEASE(content);        addedWidth += moreWidth;#ifdef DEBUG_WORD_WRAPPING        printf("  moreWidth=%d (addedWidth=%d) stop=%c\n", moreWidth,               addedWidth, stop?'T':'F');#endif        if (stop) {          goto done;        }      }      else {        // It claimed it was text but it doesn't implement the        // nsITextContent API. Therefore I don't know what to do with it        // and can't look inside it. Oh well.        NS_RELEASE(content);        goto done;      }    }    // Move on to the next frame in the text-run    aNextFrame = aLineLayout.FindNextText(aPresContext, aNextFrame);  } done:;#ifdef DEBUG_WORD_WRAPPING  printf("  total word width=%d\n", aBaseWidth + addedWidth);#endif  if (newWordBuf != aWordBuf)    nsMemory::Free(newWordBuf);  return aBaseWidth + addedWidth;}