PRUint32 aWordBufSize, PRBool aCanBreakBefore)
PRUint32 aWordBufSize)
nsTextFrame::ComputeTotalWordDimensions(nsPresContext* aPresContext,                                   nsLineLayout& aLineLayout,                                   const nsHTMLReflowState& aReflowState,                                   nsIFrame* aNextFrame,                                   const nsTextDimensions& aBaseDimensions,                                   PRUnichar* aWordBuf,                                   PRUint32 aWordLen,                                   PRUint32 aWordBufSize,                                   PRBool aCanBreakBefore){  // 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);  nsTextDimensions addedDimensions;  PRUnichar *newWordBuf = aWordBuf;  PRUint32 newWordBufSize = aWordBufSize;  while (aNextFrame) {    nsIContent* content = aNextFrame->GetContent();#ifdef DEBUG_WORD_WRAPPING    printf("  next textRun=");    nsFrame::ListTag(stdout, aNextFrame);    printf("\n");#endif    nsCOMPtr<nsITextContent> tc(do_QueryInterface(content));    if (tc) {      PRBool stop = PR_FALSE;      nsTextDimensions moreDimensions;      moreDimensions = ComputeWordFragmentDimensions(aPresContext,                                                     aLineLayout,                                                     aReflowState,                                                     aNextFrame, content, tc,                                                     &stop,                                                     newWordBuf,                                                     aWordLen,                                                     newWordBufSize,                                                     aCanBreakBefore);      if (moreDimensions.width < 0) {        PRUint32 moreSize = -moreDimensions.width;        //Oh, wordBuf is too small, we have to grow it        newWordBufSize += moreSize;        if (newWordBuf != aWordBuf) {          newWordBuf = (PRUnichar*)nsMemory::Realloc(newWordBuf, sizeof(PRUnichar)*newWordBufSize);          NS_ASSERTION(newWordBuf, "not enough memory");        } else {          newWordBuf = (PRUnichar*)nsMemory::Alloc(sizeof(PRUnichar)*newWordBufSize);          NS_ASSERTION(newWordBuf, "not enough memory");          if(newWordBuf)  {            memcpy((void*)newWordBuf, aWordBuf, sizeof(PRUnichar)*(newWordBufSize-moreSize));          }        }        if(newWordBuf)  {          moreDimensions =            ComputeWordFragmentDimensions(aPresContext,                                          aLineLayout, aReflowState,                                          aNextFrame, content, tc, &stop,                                          newWordBuf, aWordLen, newWordBufSize,                                          aCanBreakBefore);          NS_ASSERTION((moreDimensions.width >= 0),                       "ComputeWordFragmentWidth is returning negative");        } else {          stop = PR_TRUE;          moreDimensions.Clear();        }        }      addedDimensions.Combine(moreDimensions);#ifdef DEBUG_WORD_WRAPPING      printf("  moreWidth=%d (addedWidth=%d) stop=%c\n", moreDimensions.width,             addedDimensions.width, 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.      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", aBaseDimensions.width + addedDimensions.width);#endif  if (newWordBuf && (newWordBuf != aWordBuf)) {    nsMemory::Free(newWordBuf);  }  addedDimensions.Combine(aBaseDimensions);  return addedDimensions;}