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; }
nsFieldSetFrame::Reflow(nsIPresContext&          aPresContext,                        nsHTMLReflowMetrics&     aDesiredSize,                        const nsHTMLReflowState& aReflowState,                        nsReflowStatus&          aStatus){  // availSize could have unconstrained values, don't perform any addition on them  nsSize availSize(aReflowState.mComputedWidth, aReflowState.mComputedHeight);    // get our border and padding  const nsMargin &borderPadding = aReflowState.mComputedBorderPadding;  // 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, 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 > borderPadding.top) {      // center the border on the legend      mLegendSpace = mLegendRect.height - borderPadding.top;  } else {      mLegendRect.y = (borderPadding.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;  }    /*  // get the content's margin  nsMargin contentMargin(0,0,0,0);  nsCOMPtr<nsIStyleContext> contentSC;  mContentFrame->GetStyleContext(getter_AddRefs(contentSC));  if (contentSC) {    const nsStyleSpacing* spacing =      (const nsStyleSpacing*)contentSC->GetStyleData(eStyleStruct_Spacing);    spacing->GetMargin(contentMargin);  }  // remove it from our size if we are not intrinsic  if (NS_INTRINSICSIZE != availSize.height)     availSize.height -= (contentMargin.top + contentMargin.bottom);    if (NS_INTRINSICSIZE != availSize.width)     availSize.width -= (contentMargin.left + contentMargin.right);*/    // Try to reflow the area frame into the available space.  nsHTMLReflowState contentReflowState(aPresContext, aReflowState,                                       mContentFrame, availSize);  ReflowChild(mContentFrame, aPresContext, aDesiredSize, contentReflowState, aStatus);  //aDesiredSize.width += contentMargin.left + contentMargin.right;  //aDesiredSize.height += contentMargin.top + contentMargin.bottom;  // set the rect. make sure we add the margin back in.  nsRect contentRect(borderPadding.left,borderPadding.top + mLegendSpace,aDesiredSize.width ,aDesiredSize.height);  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 content area frame.  mContentFrame->SetRect(contentRect);  // place the legend  nsRect actualLegendRect(mLegendRect);  actualLegendRect.Deflate(legendMargin);  mLegendFrame->SetRect(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;  return NS_OK;}