aStatus = NS_FRAME_COMPLETE;  PRBool     isStyleChange      = PR_FALSE; PRBool     isDirtyChildReflow = PR_FALSE; PRBool     needResizeReflow   = PR_FALSE; nsIFrame * lastReflowFrame    = nsnull;   if (eReflowReason_Incremental == aReflowState.reason) {  nsIFrame* targetFrame; aReflowState.reflowCommand->GetTarget(targetFrame); if (this == targetFrame) {  nsIReflowCommand::ReflowType  reflowType; aReflowState.reflowCommand->GetType(reflowType);  switch (reflowType) { case nsIReflowCommand::ReflowDirty: isDirtyChildReflow = PR_TRUE; break;  case nsIReflowCommand::StyleChanged:  isStyleChange = PR_TRUE; break;  default: NS_ASSERTION(PR_FALSE, "unexpected reflow command type"); }  } else { nsIFrame* nextFrame;  aReflowState.reflowCommand->GetNext(nextFrame);   nsSize availSize(aReflowState.mComputedWidth, aReflowState.availableHeight); nsRect currentRect; nextFrame->GetRect(currentRect);    nsHTMLReflowState kidReflowState(aPresContext, aReflowState, nextFrame, availSize);  ReflowChild(nextFrame, aPresContext, aDesiredSize, kidReflowState, kidReflowState.mComputedMargin.left, kidReflowState.mComputedMargin.top, 0, aStatus); if (currentRect.width != aDesiredSize.width || currentRect.height != aDesiredSize.height) { needResizeReflow = PR_TRUE; } lastReflowFrame = nextFrame; nextFrame->DidReflow(aPresContext, NS_FRAME_REFLOW_FINISHED); } }   if (mFrames.IsEmpty()) {  aDesiredSize.width = aDesiredSize.height = 0; aDesiredSize.ascent = aDesiredSize.descent = 0;  } else {
aStatus = NS_FRAME_COMPLETE;   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);   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;   case nsIReflowCommand::ReflowDirty: { nsHTMLReflowState newState(aReflowState); newState.reason = eReflowReason_Dirty; return Reflow(aPresContext, aDesiredSize, newState, aStatus); } break; } } 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 (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); } }
nsFieldSetFrame::Reflow(nsIPresContext*          aPresContext,                        nsHTMLReflowMetrics&     aDesiredSize,                        const nsHTMLReflowState& aReflowState,                        nsReflowStatus&          aStatus){ #ifdef DO_NEWFIELDSET  // Initialize OUT parameter  aStatus = NS_FRAME_COMPLETE;  PRBool     isStyleChange      = PR_FALSE;  PRBool     isDirtyChildReflow = PR_FALSE;  PRBool     needResizeReflow   = PR_FALSE;  nsIFrame * lastReflowFrame    = nsnull;  // Check for an incremental reflow  if (eReflowReason_Incremental == aReflowState.reason) {    // See if we're the target frame    nsIFrame* targetFrame;    aReflowState.reflowCommand->GetTarget(targetFrame);    if (this == targetFrame) {      // Get the reflow type      nsIReflowCommand::ReflowType  reflowType;      aReflowState.reflowCommand->GetType(reflowType);      switch (reflowType) {      case nsIReflowCommand::ReflowDirty:        isDirtyChildReflow = PR_TRUE;        break;      case nsIReflowCommand::StyleChanged:        // Remember it's a style change so we can set the reflow reason below        isStyleChange = PR_TRUE;        break;      default:        NS_ASSERTION(PR_FALSE, "unexpected reflow command type");      }    } else {      nsIFrame* nextFrame;      // Get the next frame in the reflow chain      aReflowState.reflowCommand->GetNext(nextFrame);      //NS_ASSERTION(nextFrame == mFrames.FirstChild(), "unexpected next reflow command frame");      nsSize availSize(aReflowState.mComputedWidth, aReflowState.availableHeight);      nsRect currentRect;      nextFrame->GetRect(currentRect);      // We must specify an unconstrained available height, because constrained      // is only for when we're paginated...      nsHTMLReflowState kidReflowState(aPresContext, aReflowState, nextFrame,                                       availSize);      // Reflow the frame      ReflowChild(nextFrame, aPresContext, aDesiredSize, kidReflowState,                  kidReflowState.mComputedMargin.left, kidReflowState.mComputedMargin.top,                  0, aStatus);      if (currentRect.width != aDesiredSize.width ||          currentRect.height != aDesiredSize.height) {        needResizeReflow = PR_TRUE;      }      lastReflowFrame = nextFrame;      nextFrame->DidReflow(aPresContext, NS_FRAME_REFLOW_FINISHED);    }  }  // XXX NOT OPTIMIZED - This code always reflows the legend and the area frame  if (mFrames.IsEmpty()) {    // We have no child frame, so return an empty size    aDesiredSize.width = aDesiredSize.height = 0;    aDesiredSize.ascent = aDesiredSize.descent = 0;  } else {    // 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.     nsMargin legendMargin(0,0,0,0);      // if there is a legend frame flow it.    if (mLegendFrame) {      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 = eReflowReason_Resize;      ReflowChild(mLegendFrame, aPresContext, aDesiredSize, legendReflowState,                  0, 0, NS_FRAME_NO_MOVE_FRAME, aStatus);      // get the legend's margin      nsIStyleContext* legendSC = nsnull;      mLegendFrame->GetStyleContext(&legendSC);      if (legendSC) {        const nsStyleSpacing* legendSpacing =          (const nsStyleSpacing*)legendSC->GetStyleData(eStyleStruct_Spacing);        legendSpacing->GetMargin(legendMargin);        NS_RELEASE(legendSC);      }      // figure out the legend's rectangle      mLegendRect.width  = aDesiredSize.width + legendMargin.left + legendMargin.right;      mLegendRect.height = aDesiredSize.height + legendMargin.top + legendMargin.bottom;      mLegendRect.x = borderPadding.left;      mLegendRect.y = 0;      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 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;      }      // Tell the legend we're done with the reflow. We'll size and place it later on      mLegendFrame->DidReflow(aPresContext, NS_FRAME_REFLOW_FINISHED);    }    nsIFrame* kidFrame = mFrames.FirstChild();#if 0    availSize.width = aReflowState.mComputedWidth;    if (aReflowState.mComputedHeight != NS_INTRINSICSIZE) {      availSize.height = aReflowState.mComputedHeight - mLegendSpace;    } else {      availSize.height = NS_INTRINSICSIZE;    }#endif    nsHTMLReflowState kidReflowState(aPresContext, aReflowState, kidFrame,                                     availSize);    if (isDirtyChildReflow) {      // Note: the only reason the frame would be dirty would be if it had      // just been inserted or appended      kidReflowState.reason = eReflowReason_Initial;      kidReflowState.reflowCommand = nsnull;    } else if (isStyleChange) {      kidReflowState.reason = eReflowReason_StyleChange;      kidReflowState.reflowCommand = nsnull;    } else {      kidReflowState.reason = eReflowReason_Resize;    }    // Reflow the frame    ReflowChild(kidFrame, aPresContext, aDesiredSize, kidReflowState,                kidReflowState.mComputedMargin.left, kidReflowState.mComputedMargin.top,                0, aStatus);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.    nsRect contentRect(borderPadding.left,borderPadding.top + mLegendSpace,aDesiredSize.width ,aDesiredSize.height);    if (aReflowState.mComputedHeight != NS_INTRINSICSIZE &&        borderPadding.top + mLegendSpace+aDesiredSize.height > aReflowState.mComputedHeight) {      aDesiredSize.height = aReflowState.mComputedHeight-(borderPadding.top + mLegendSpace);printf(" areaHgt: %d", aDesiredSize.height);    }    FinishReflowChild(kidFrame, aPresContext, aDesiredSize, contentRect.x, contentRect.y, 0);    // If the child frame was just inserted, then we're responsible for making sure    // it repaints    //if (isDirtyChildReflow) {      // Damage the area occupied by the deleted frame    //  Invalidate(aPresContext, rect, PR_FALSE);    //}    NS_FRAME_TRACE_REFLOW_OUT("FieldSet::Reflow", aStatus);    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);      mLegendFrame->SetRect(aPresContext, actualLegendRect);    }      // Return our size and our result    if (aReflowState.mComputedHeight == NS_INTRINSICSIZE) {       aDesiredSize.height = mLegendSpace +                              borderPadding.top +                             aDesiredSize.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 +                              aDesiredSize.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;    if (nsnull != aDesiredSize.maxElementSize) {        // if the legend it 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;    }    }printf(" desiredHgt: %d\n", aDesiredSize.height);#else  // 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.   nsMargin legendMargin(0,0,0,0);    // if there is a legend frame flow it.  if (mLegendFrame) {    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;    ReflowChild(mLegendFrame, aPresContext, aDesiredSize, legendReflowState,                0, 0, NS_FRAME_NO_MOVE_FRAME, aStatus);    // get the legend's margin    nsIStyleContext* legendSC = nsnull;    mLegendFrame->GetStyleContext(&legendSC);    if (legendSC) {      const nsStyleSpacing* legendSpacing =        (const nsStyleSpacing*)legendSC->GetStyleData(eStyleStruct_Spacing);      legendSpacing->GetMargin(legendMargin);      NS_RELEASE(legendSC);    }    // figure out the legend's rectangle    mLegendRect.width  = aDesiredSize.width + legendMargin.left + legendMargin.right;    mLegendRect.height = aDesiredSize.height + legendMargin.top + legendMargin.bottom;    mLegendRect.x = borderPadding.left;    mLegendRect.y = 0;    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 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;    }    // Tell the legend we're done with the reflow. We'll size and place it later on    mLegendFrame->DidReflow(aPresContext, NS_FRAME_REFLOW_FINISHED);  }  mContentFrame = mFrames.FirstChild();    // Try to reflow the area frame into the available space.  nsHTMLReflowState contentReflowState(aPresContext, aReflowState,                                       mContentFrame, availSize);  ReflowChild(mContentFrame, aPresContext, aDesiredSize, contentReflowState,              borderPadding.left, borderPadding.top + mLegendSpace, 0, aStatus);  // set the rect. make sure we add the margin back in.  nsRect contentRect(borderPadding.left,borderPadding.top + mLegendSpace,aDesiredSize.width ,aDesiredSize.height);  // Place the content area frame.  FinishReflowChild(mContentFrame, aPresContext, aDesiredSize, contentRect.x, contentRect.y, 0);  if (mLegendFrame)   {    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;    }      // place the legend    nsRect actualLegendRect(mLegendRect);    actualLegendRect.Deflate(legendMargin);    mLegendFrame->SetRect(aPresContext, actualLegendRect);  }    // Return our size and our result  if (aReflowState.mComputedHeight == NS_INTRINSICSIZE) {     aDesiredSize.height = mLegendSpace +                            borderPadding.top +                           aDesiredSize.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 +                            aDesiredSize.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;  if (nsnull != aDesiredSize.maxElementSize) {      // if the legend it 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;  }  aStatus = NS_FRAME_COMPLETE;#endif  return NS_OK;}