PRInt32 i, n = line->mChildCount;
PRInt32 i, n = line->ChildCount();
nsBlockFrame::InsertNewFrame(nsIPresContext& aPresContext,                             nsBlockFrame*   aParentFrame,                             nsIFrame*       aNewFrame,                             nsIFrame*       aPrevSibling){  const nsStyleDisplay* display;  aNewFrame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&) display);  const nsStylePosition* position;  aNewFrame->GetStyleData(eStyleStruct_Position, (const nsStyleStruct*&) position);  PRUint16 newFrameIsBlock = nsLineLayout::TreatFrameAsBlock(display, position)                               ? LINE_IS_BLOCK : 0;  // See if we need to move the frame outside of the flow, and insert a  // placeholder frame in its place  nsIFrame* placeholder;  if (MoveFrameOutOfFlow(aPresContext, aNewFrame, display, position, placeholder)) {    // Add the placeholder frame to the flow    aNewFrame = placeholder;    newFrameIsBlock = PR_FALSE;  // placeholder frame is always inline  }  else {    // Wrap the frame in a view if necessary    nsIStyleContext* kidSC;    aNewFrame->GetStyleContext(&aPresContext, kidSC);    nsresult rv = CreateViewForFrame(aPresContext, aNewFrame, kidSC, PR_FALSE);    NS_RELEASE(kidSC);    if (NS_OK != rv) {      return rv;    }  }  // Insert/append the frame into flows line list at the right spot  LineData* newLine;  LineData* line = aParentFrame->mLines;  if (nsnull == aPrevSibling) {    // Insert new frame into the sibling list    aNewFrame->SetNextSibling(line->mFirstChild);    if (line->IsBlock() || newFrameIsBlock) {      // Create a new line      newLine = new LineData(aNewFrame, 1, LINE_LAST_CONTENT_IS_COMPLETE |                             newFrameIsBlock);      if (nsnull == newLine) {        return NS_ERROR_OUT_OF_MEMORY;      }      newLine->mNext = aParentFrame->mLines;      aParentFrame->mLines = newLine;    } else {      // Insert frame at the front of the line      line->mFirstChild = aNewFrame;      line->mChildCount++;      line->MarkDirty();    }  }  else {    // Find line containing the previous sibling to the new frame    line = FindLineContaining(line, aPrevSibling);    NS_ASSERTION(nsnull != line, "no line contains the previous sibling");    if (nsnull != line) {      if (line->IsBlock()) {        // Create a new line just after line        newLine = new LineData(aNewFrame, 1, LINE_LAST_CONTENT_IS_COMPLETE |                               newFrameIsBlock);        if (nsnull == newLine) {          return NS_ERROR_OUT_OF_MEMORY;        }        newLine->mNext = line->mNext;        line->mNext = newLine;      }      else if (newFrameIsBlock) {        // Split line in two, if necessary. We can't allow a block to        // end up in an inline line.        if (line->IsLastChild(aPrevSibling)) {          // The new frame goes after prevSibling and prevSibling is          // the last frame on the line. Therefore we don't need to          // split the line, just create a new line.          newLine = new LineData(aNewFrame, 1, LINE_LAST_CONTENT_IS_COMPLETE |                                 newFrameIsBlock);          if (nsnull == newLine) {            return NS_ERROR_OUT_OF_MEMORY;          }          newLine->mNext = line->mNext;          line->mNext = newLine;        }        else {          // The new frame goes after prevSibling and prevSibling is          // somewhere in the line, but not at the end. Split the line          // just after prevSibling.          PRInt32 i, n = line->mChildCount;          nsIFrame* frame = line->mFirstChild;          for (i = 0; i < n; i++) {            if (frame == aPrevSibling) {              nsIFrame* nextSibling;              aPrevSibling->GetNextSibling(nextSibling);              // Create new line to hold the remaining frames              NS_ASSERTION(n - i - 1 > 0, "bad line count");              newLine = new LineData(nextSibling, n - i - 1,                               line->mState & LINE_LAST_CONTENT_IS_COMPLETE);              if (nsnull == newLine) {                return NS_ERROR_OUT_OF_MEMORY;              }              newLine->mNext = line->mNext;              line->mNext = newLine;              line->MarkDirty();              line->SetLastContentIsComplete();              line->mChildCount = i + 1;              break;            }            frame->GetNextSibling(frame);          }          // Now create a new line to hold the block          newLine = new LineData(aNewFrame, 1,                             newFrameIsBlock | LINE_LAST_CONTENT_IS_COMPLETE);          if (nsnull == newLine) {            return NS_ERROR_OUT_OF_MEMORY;          }          newLine->mNext = line->mNext;          line->mNext = newLine;        }      }      else {        // Insert frame into the line.        //XXX NS_ASSERTION(line->GetLastContentIsComplete(), "bad line LCIC");        line->mChildCount++;        line->MarkDirty();      }    }    // Insert new frame into the sibling list; note: this must be done    // after the above logic because the above logic depends on the    // sibling list being in the "before insertion" state.    nsIFrame* nextSibling;    aPrevSibling->GetNextSibling(nextSibling);    aNewFrame->SetNextSibling(nextSibling);    aPrevSibling->SetNextSibling(aNewFrame);  }  return NS_OK;}