(nsTableColGroupFrame*)GetFrameAtOrBefore(aPresContext, this, aPrevFrame,
(nsTableColGroupFrame*)GetFrameAtOrBefore(this, aPrevFrame,
nsTableFrame::InsertFrames(nsIPresContext* aPresContext,                           nsIPresShell&   aPresShell,                           nsIAtom*        aListName,                           nsIFrame*       aPrevFrame,                           nsIFrame*       aFrameList){  // Asssume there's only one frame being inserted. The problem is that  // row group frames and col group frames go in separate child lists and  // so if there's more than one this gets messy...  // XXX The frame construction code should be separating out child frames  // based on the type...  nsIFrame* nextSibling;  aFrameList->GetNextSibling(&nextSibling);  NS_PRECONDITION(!nextSibling, "expected only one child frame");  // See what kind of frame we have  const nsStyleDisplay *display=nsnull;  aFrameList->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)display));  if (NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP == display->mDisplay) {    // Insert the column group frame    nsFrameList frames(aFrameList); // convience for getting last frame    nsIFrame* lastFrame = frames.LastChild();    mColGroups.InsertFrame(nsnull, aPrevFrame, aFrameList);    // find the starting col index for the first new col group    PRInt32 startColIndex = 0;    if (aPrevFrame) {      nsTableColGroupFrame* prevColGroup =         (nsTableColGroupFrame*)GetFrameAtOrBefore(aPresContext, this, aPrevFrame,                                                  nsLayoutAtoms::tableColGroupFrame);      if (prevColGroup) {        startColIndex = prevColGroup->GetStartColumnIndex() + prevColGroup->GetColCount();      }    }    InsertColGroups(*aPresContext, startColIndex, aFrameList, lastFrame);  } else if (IsRowGroup(display->mDisplay)) {    // get the starting row index of the new rows and insert them into the table    PRInt32 rowIndex = 0;    nsTableRowGroupFrame* prevRowGroup = (nsTableRowGroupFrame *)nsTableFrame::GetFrameAtOrBefore(aPresContext, this, aPrevFrame, nsLayoutAtoms::tableRowGroupFrame);    if (prevRowGroup) {      PRInt32 numRows;      prevRowGroup->GetRowCount(numRows);      rowIndex = prevRowGroup->GetStartRowIndex() + numRows;    }    InsertRowGroups(*aPresContext, aFrameList, rowIndex);    // Insert the frames in the sibling chain    mFrames.InsertFrame(nsnull, aPrevFrame, aFrameList);  } else {    // Just insert the frame and don't worry about reflowing it    mFrames.InsertFrame(nsnull, aPrevFrame, aFrameList);    return NS_OK;  }  // Because the number of columns may have changed invalidate them  InvalidateColumnWidths();    InvalidateFirstPassCache(); // XXX fix this    // Mark the table as dirty and generate a reflow command targeted at the  // outer table frame  nsIReflowCommand* reflowCmd;  nsresult          rv;    mState |= NS_FRAME_IS_DIRTY;  rv = NS_NewHTMLReflowCommand(&reflowCmd, mParent, nsIReflowCommand::ReflowDirty);  if (NS_SUCCEEDED(rv)) {    // Add the reflow command    rv = aPresShell.AppendReflowCommand(reflowCmd);    NS_RELEASE(reflowCmd);  }  return rv;  return NS_OK;}