case nsIReflowCommand::ReflowDirty:
case eReflowType_ReflowDirty:
nsFieldSetFrame::Reflow(nsIPresContext*          aPresContext,                        nsHTMLReflowMetrics&     aDesiredSize,                        const nsHTMLReflowState& aReflowState,                        nsReflowStatus&          aStatus){  DO_GLOBAL_REFLOW_COUNT("nsFieldSetFrame", aReflowState.reason);  DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);   // Initialize OUT parameter   aStatus = NS_FRAME_COMPLETE;   //------------ Handle Incremental Reflow -----------------   nsIFrame* incrementalChild = nsnull;   PRBool reflowContent = PR_TRUE;   PRBool reflowLegend = PR_TRUE;   nsReflowReason reason = aReflowState.reason;    if ( aReflowState.reason == eReflowReason_Incremental ) {        nsIReflowCommand::ReflowType  reflowType;        aReflowState.reflowCommand->GetType(reflowType);        // See if it's targeted at us        nsIFrame* targetFrame;            aReflowState.reflowCommand->GetTarget(targetFrame);        if (this == targetFrame) {            switch (reflowType) {              case nsIReflowCommand::StyleChanged:                   {                    nsHTMLReflowState newState(aReflowState);                    newState.reason = eReflowReason_StyleChange;                    return Reflow(aPresContext, aDesiredSize, newState, aStatus);                  }                  break;                  // if its a dirty type then reflow us with a dirty reflow                  case nsIReflowCommand::ReflowDirty:                   {                    nsHTMLReflowState newState(aReflowState);                    newState.reason = eReflowReason_Dirty;                    return Reflow(aPresContext, aDesiredSize, newState, aStatus);                  }                  break;                  default:                    NS_ERROR("Unexpected Reflow Type");            }        } else {             aReflowState.reflowCommand->GetNext(incrementalChild);             reflowContent = PR_FALSE;             reflowLegend = PR_FALSE;             if (incrementalChild == mLegendFrame)                 reflowLegend = PR_TRUE;             else if (incrementalChild == mContentFrame)                 reflowContent = PR_TRUE;               }    }    // if dirty then check dirty flags    if (reason == eReflowReason_Dirty)     {        if (reflowContent) {              nsFrameState state;              mContentFrame->GetFrameState(&state);              reflowContent = (state & NS_FRAME_IS_DIRTY) || (state & NS_FRAME_HAS_DIRTY_CHILDREN);        }        if (reflowLegend) {              nsFrameState state;              mLegendFrame->GetFrameState(&state);              reflowLegend = (state & NS_FRAME_IS_DIRTY) || (state & NS_FRAME_HAS_DIRTY_CHILDREN);        }    }    // availSize could have unconstrained values, don't perform any addition on them    nsSize availSize(aReflowState.mComputedWidth, aReflowState.availableHeight);      // get our border and padding    const nsMargin &borderPadding = aReflowState.mComputedBorderPadding;    const nsMargin &padding       = aReflowState.mComputedPadding;    nsMargin border = borderPadding - padding;    // Figure out how big the legend is if there is one.     // get the legend's margin    nsMargin legendMargin(0,0,0,0);    // reflow the legend only if needed    if (mLegendFrame) {        const nsStyleMargin* marginStyle;        mLegendFrame->GetStyleData(eStyleStruct_Margin,                              (const nsStyleStruct*&) marginStyle);        marginStyle->GetMargin(legendMargin);        if (reflowLegend) {          nsHTMLReflowState legendReflowState(aPresContext, aReflowState,                                              mLegendFrame, nsSize(NS_INTRINSICSIZE,NS_INTRINSICSIZE));          // always give the legend as much size as it needs          legendReflowState.mComputedWidth = NS_INTRINSICSIZE;          legendReflowState.mComputedHeight = NS_INTRINSICSIZE;          legendReflowState.reason = reason;          nsHTMLReflowMetrics legendDesiredSize(0,0);          ReflowChild(mLegendFrame, aPresContext, legendDesiredSize, legendReflowState,                      0, 0, NS_FRAME_NO_MOVE_FRAME, aStatus);#ifdef NOISY_REFLOW          printf("  returned (%d, %d)\n", legendDesiredSize.width, legendDesiredSize.height);          if (legendDesiredSize.maxElementSize)            printf("  and maxES (%d, %d)\n",                    legendDesiredSize.maxElementSize->width, legendDesiredSize.maxElementSize->height);#endif          // figure out the legend's rectangle          mLegendRect.width  = legendDesiredSize.width + legendMargin.left + legendMargin.right;          mLegendRect.height = legendDesiredSize.height + legendMargin.top + legendMargin.bottom;          mLegendRect.x = borderPadding.left;          mLegendRect.y = 0;          nscoord oldSpace = mLegendSpace;          mLegendSpace = 0;          if (mLegendRect.height > border.top) {              // center the border on the legend              mLegendSpace = mLegendRect.height - borderPadding.top;          } else {              mLegendRect.y = (border.top - mLegendRect.height)/2;          }          // if the legend space changes then we need to reflow the           // content area as well.          if (mLegendSpace != oldSpace) {              if (reflowContent == PR_FALSE || reason == eReflowReason_Dirty) {                 reflowContent = PR_TRUE;                 reason = eReflowReason_Resize;              }          }          // if we are contrained then remove the legend from our available height.          if (NS_INTRINSICSIZE != availSize.height) {             if (availSize.height >= mLegendSpace)                 availSize.height -= mLegendSpace;          }            // don't get any smaller than the legend          if (NS_INTRINSICSIZE != availSize.width) {             if (availSize.width < mLegendRect.width)                 availSize.width = mLegendRect.width;          }          FinishReflowChild(mLegendFrame, aPresContext, &legendReflowState,                             legendDesiredSize, 0, 0, NS_FRAME_NO_MOVE_FRAME);            }    }    nsRect contentRect;    // reflow the content frame only if needed    if (mContentFrame) {        if (reflowContent) {            availSize.width = aReflowState.mComputedWidth;#if 0            if (aReflowState.mComputedHeight != NS_INTRINSICSIZE) {              availSize.height = aReflowState.mComputedHeight - mLegendSpace;            } else {              availSize.height = NS_INTRINSICSIZE;            }#endif            nsHTMLReflowState kidReflowState(aPresContext, aReflowState, mContentFrame,                                             availSize);            kidReflowState.reason = reason;            nsHTMLReflowMetrics kidDesiredSize(0,0);            // Reflow the frame            ReflowChild(mContentFrame, aPresContext, kidDesiredSize, kidReflowState,                        kidReflowState.mComputedMargin.left, kidReflowState.mComputedMargin.top,                        0, aStatus);#ifdef NOISY_REFLOW            printf("  returned (%d, %d)\n", kidDesiredSize.width, kidDesiredSize.height);            if (kidDesiredSize.maxElementSize)              printf("  and maxES (%d, %d)\n",                      kidDesiredSize.maxElementSize->width, kidDesiredSize.maxElementSize->height);#endif            /*            printf("*** %p computedHgt: %d ", this, aReflowState.mComputedHeight);              printf("Reason: ");              switch (aReflowState.reason) {                case eReflowReason_Initial:printf("Initil");break;                case eReflowReason_Incremental:printf("Increm");break;                case eReflowReason_Resize: printf("Resize");      break;                case eReflowReason_StyleChange:printf("eReflowReason_StyleChange");break;              }              */            // set the rect. make sure we add the margin back in.            contentRect.SetRect(borderPadding.left,borderPadding.top + mLegendSpace,kidDesiredSize.width ,kidDesiredSize.height);            if (aReflowState.mComputedHeight != NS_INTRINSICSIZE &&                borderPadding.top + mLegendSpace+kidDesiredSize.height > aReflowState.mComputedHeight) {              kidDesiredSize.height = aReflowState.mComputedHeight-(borderPadding.top + mLegendSpace);            }            FinishReflowChild(mContentFrame, aPresContext, &kidReflowState,                               kidDesiredSize, contentRect.x, contentRect.y, 0);            nsFrameState  kidState;            mContentFrame->GetFrameState(&kidState);           // printf("width: %d, height: %d\n", desiredSize.mCombinedArea.width, desiredSize.mCombinedArea.height);            /*            if (kidState & NS_FRAME_OUTSIDE_CHILDREN) {                 mState |= NS_FRAME_OUTSIDE_CHILDREN;                 aDesiredSize.mOverflowArea.width += borderPadding.left + borderPadding.right;                 aDesiredSize.mOverflowArea.height += borderPadding.top + borderPadding.bottom + mLegendSpace;            }            */            NS_FRAME_TRACE_REFLOW_OUT("FieldSet::Reflow", aStatus);        } else {            // if we don't need to reflow just get the old size            mContentFrame->GetRect(contentRect);            const nsStyleMargin* marginStyle;            mContentFrame->GetStyleData(eStyleStruct_Margin,                                  (const nsStyleStruct*&) marginStyle);            nsMargin m(0,0,0,0);            marginStyle->GetMargin(m);            contentRect.Inflate(m);        }    }    if (mLegendFrame) {      if (contentRect.width > mLegendRect.width) {        PRInt32 align = ((nsLegendFrame*)mLegendFrame)->GetAlign();          switch(align) {          case NS_STYLE_TEXT_ALIGN_RIGHT:            mLegendRect.x = contentRect.width - mLegendRect.width + borderPadding.left;            break;          case NS_STYLE_TEXT_ALIGN_CENTER:            mLegendRect.x = contentRect.width/2 - mLegendRect.width/2 + borderPadding.left;        }        } else {        contentRect.width = mLegendRect.width + borderPadding.left + borderPadding.right;        aDesiredSize.width = contentRect.width;      }      // place the legend      nsRect actualLegendRect(mLegendRect);      actualLegendRect.Deflate(legendMargin);      nsPoint curOrigin;      mLegendFrame->GetOrigin(curOrigin);      // only if the origin changed      if ((curOrigin.x != mLegendRect.x) || (curOrigin.y != mLegendRect.y)) {          mLegendFrame->MoveTo(aPresContext,  actualLegendRect.x , actualLegendRect.y);          nsContainerFrame::PositionFrameView(aPresContext, mLegendFrame);          // We need to recursively process the legend frame's          // children since we're moving the frame after Reflow.          nsContainerFrame::PositionChildViews(aPresContext, mLegendFrame);      }    }    // Return our size and our result    if (aReflowState.mComputedHeight == NS_INTRINSICSIZE) {       aDesiredSize.height = mLegendSpace +                              borderPadding.top +                             contentRect.height +                             borderPadding.bottom;    } else {       nscoord min = borderPadding.top + borderPadding.bottom + mLegendRect.height;       aDesiredSize.height = aReflowState.mComputedHeight + borderPadding.top + borderPadding.bottom;       if (aDesiredSize.height < min)           aDesiredSize.height = min;    }    if (aReflowState.mComputedWidth == NS_INTRINSICSIZE) {        aDesiredSize.width = borderPadding.left +                              contentRect.width +                             borderPadding.right;    } else {       nscoord min = borderPadding.left + borderPadding.right + mLegendRect.width;       aDesiredSize.width = aReflowState.mComputedWidth + borderPadding.left + borderPadding.right;       if (aDesiredSize.width < min)           aDesiredSize.width = min;    }    aDesiredSize.ascent  = aDesiredSize.height;    aDesiredSize.descent = 0;    aDesiredSize.mMaximumWidth = aDesiredSize.width;    if (nsnull != aDesiredSize.maxElementSize) {        // if the legend is wider use it        if (aDesiredSize.maxElementSize->width < mLegendRect.width)            aDesiredSize.maxElementSize->width = mLegendRect.width;        // add in padding.        aDesiredSize.maxElementSize->width += borderPadding.left + borderPadding.right;        // height is border + legend        aDesiredSize.maxElementSize->height += borderPadding.top + borderPadding.bottom + mLegendRect.height;    }#ifdef NOISY_REFLOW    printf("FIELDSET:  w=%d, maxWidth=%d, MES=%d\n",           aDesiredSize.width, aDesiredSize.mMaximumWidth,            aDesiredSize.maxElementSize ? aDesiredSize.maxElementSize->width : -1);    if (aDesiredSize.mFlags & NS_REFLOW_CALC_MAX_WIDTH)      printf("  and preferred size = %d\n", aDesiredSize.mMaximumWidth);#endif  return NS_OK;}