if (nsDebugTable::gRflTable) nsTableFrame::DebugReflow("T::Rfl en", this, &aReflowState, nsnull);   if (nsnull != aDesiredSize.maxElementSize) { aDesiredSize.maxElementSize->width = 0; aDesiredSize.maxElementSize->height = 0; } aStatus = NS_FRAME_COMPLETE;   if ((NS_UNCONSTRAINEDSIZE == aReflowState.availableWidth) && (this == (nsTableFrame *)GetFirstInFlow())) { InvalidateFirstPassCache(); }
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); #if defined DEBUG_TABLE_REFLOW_TIMING nsTableFrame::DebugReflow(this, (nsHTMLReflowState&)aReflowState); #endif PRBool isPaginated = aPresContext->IsPaginated();     if (IsPrematureSpecialHeightReflow(aReflowState, mRect, NeedSpecialReflow() || isPaginated, aDesiredSize)) return NS_OK;  aStatus = NS_FRAME_COMPLETE; if (!mPrevInFlow && !mTableLayoutStrategy) { NS_ASSERTION(PR_FALSE, "strategy should have been created in Init"); return NS_ERROR_NULL_POINTER; }
NS_METHOD nsTableFrame::Reflow(nsIPresContext* aPresContext,                               nsHTMLReflowMetrics& aDesiredSize,                               const nsHTMLReflowState& aReflowState,                               nsReflowStatus& aStatus){  DO_GLOBAL_REFLOW_COUNT("nsTableFrame", aReflowState.reason);  if (nsDebugTable::gRflTable) nsTableFrame::DebugReflow("T::Rfl en", this, &aReflowState, nsnull);  // Initialize out parameter  if (nsnull != aDesiredSize.maxElementSize) {    aDesiredSize.maxElementSize->width = 0;    aDesiredSize.maxElementSize->height = 0;  }  aStatus = NS_FRAME_COMPLETE;  // XXX yank this nasty code and see what happens, and then yank other  // similar calls to InvalidateFirstPassCache.  if ((NS_UNCONSTRAINEDSIZE == aReflowState.availableWidth) &&      (this == (nsTableFrame *)GetFirstInFlow())) {    InvalidateFirstPassCache();  }  nsresult rv = NS_OK;  nsSize* pass1MaxElementSize = aDesiredSize.maxElementSize;  if (eReflowReason_Incremental == aReflowState.reason) {    rv = IncrementalReflow(aPresContext, aDesiredSize, aReflowState, aStatus);  }  // If this is a style change reflow, then invalidate the pass 1 cache  if (eReflowReason_StyleChange == aReflowState.reason) {    InvalidateFirstPassCache();  }  // NeedsReflow and IsFirstPassValid take into account reflow type = Initial_Reflow  if (NeedsReflow(aReflowState)) {    PRBool needsRecalc = PR_FALSE;    if ((NS_UNCONSTRAINEDSIZE == aReflowState.availableWidth) ||         (PR_FALSE==IsFirstPassValid())) {      nsReflowReason reason = aReflowState.reason;      if ((eReflowReason_Initial != reason) &&          (eReflowReason_StyleChange != reason)) {        reason = eReflowReason_Resize;      }      if (mBorderCollapser) {        mBorderCollapser->ComputeVerticalBorders(aPresContext, 0, -1);      }      rv = ResizeReflowPass1(aPresContext, aDesiredSize, aReflowState, aStatus, nsnull, reason, PR_TRUE);      if (NS_FAILED(rv))        return rv;      needsRecalc = PR_TRUE;    }    if (mTableLayoutStrategy && (needsRecalc || !IsColumnWidthsValid())) {      nscoord boxWidth = CalcBorderBoxWidth(aReflowState);      mTableLayoutStrategy->Initialize(aPresContext, aDesiredSize.maxElementSize,                                        boxWidth, aReflowState);      mBits.mColumnWidthsValid = PR_TRUE; //so we don't do this a second time below    }    if (!mPrevInFlow) {       // only do this for a first-in-flow table frame      // assign column widths, and assign aMaxElementSize->width      BalanceColumnWidths(aPresContext, aReflowState, nsSize(aReflowState.availableWidth, aReflowState.availableHeight),                           aDesiredSize.maxElementSize);      // assign table width      SetTableWidth(aPresContext, aReflowState);    }    if ((eReflowReason_Initial == aReflowState.reason) &&        (NS_UNCONSTRAINEDSIZE == aReflowState.availableWidth)) {      // Don't bother doing a pass2 reflow. Use our pass1 width as our      // desired width      aDesiredSize.width = mRect.width;    } else {      // Constrain our reflow width to the computed table width. Note: this is based      // on the width of the first-in-flow      nsHTMLReflowState reflowState(aReflowState);      PRInt32 pass1Width = mRect.width;      if (mPrevInFlow) {        nsTableFrame* table = (nsTableFrame*)GetFirstInFlow();        pass1Width = table->mRect.width;      }      reflowState.availableWidth = pass1Width;      if (pass1MaxElementSize) {         // we already have the max element size, so don't request it during pass2        aDesiredSize.maxElementSize = nsnull;      }      rv = ResizeReflowPass2(aPresContext, aDesiredSize, reflowState, aStatus);      if (NS_FAILED(rv)) return rv;      aDesiredSize.width = PR_MIN(aDesiredSize.width, pass1Width);        // If this is an incremental reflow and we're here that means we had to      // reflow all the rows, e.g., the column widths changed. We need to make      // sure that any damaged areas are repainted      if (eReflowReason_Incremental == aReflowState.reason) {        nsRect  damageRect;          damageRect.x = 0;        damageRect.y = 0;        damageRect.width = mRect.width;        damageRect.height = mRect.height;        Invalidate(aPresContext, damageRect);      }    }  }  else {    // set aDesiredSize and aMaxElementSize  }  SetColumnDimensions(aPresContext, aDesiredSize.height, aReflowState.mComputedBorderPadding);  if (pass1MaxElementSize) {    aDesiredSize.maxElementSize = pass1MaxElementSize;  }  // See if we are supposed to compute our maximum width  if (aDesiredSize.mFlags & NS_REFLOW_CALC_MAX_WIDTH) {    PRBool  isAutoOrPctWidth = IsAutoLayout(&aReflowState) &&                               ((eStyleUnit_Auto == aReflowState.mStylePosition->mWidth.GetUnit() ||                                (eStyleUnit_Percent == aReflowState.mStylePosition->mWidth.GetUnit())));        // See if the pass1 maximum width is no longer valid because one of the    // cell maximum widths changed    if (isAutoOrPctWidth && !IsMaximumWidthValid()) {      // Initialize the strategy and have it compute the natural size of      // the table      mTableLayoutStrategy->Initialize(aPresContext, nsnull, NS_UNCONSTRAINEDSIZE, aReflowState);      // Now the maximum width is valid      mBits.mMaximumWidthValid = PR_TRUE;      // Initializing the table layout strategy assigns preliminary column      // widths. We can't leave the column widths this way, and so we need to      // balance the column widths to get them back to what we had previously.      // XXX It would be nice to have a cleaner way to calculate the updated      // maximum width      BalanceColumnWidths(aPresContext, aReflowState,                          nsSize(aReflowState.availableWidth, aReflowState.availableHeight),                           aDesiredSize.maxElementSize);    }    if (isAutoOrPctWidth) {      // Ask the strategy for the natural width of the content area       aDesiredSize.mMaximumWidth = mTableLayoutStrategy->GetTableMaxWidth();           // Add in space for border      nsMargin border;      GetTableBorder (border); // this gets the max border value at every edge      aDesiredSize.mMaximumWidth += border.left + border.right;      // Add in space for padding      aDesiredSize.mMaximumWidth += aReflowState.mComputedPadding.left +                                    aReflowState.mComputedPadding.right;    } else {      // We're not auto width so the natural width is the same as the desired width      aDesiredSize.mMaximumWidth = aDesiredSize.width;    }  }  if (nsDebugTable::gRflTable) nsTableFrame::DebugReflow("T::Rfl ex", this, nsnull, &aDesiredSize, aStatus);  return rv;}