childFrame->WillReflow(aPresContext);  if (aMoveFrame) { childFrame->MoveTo(aPresContext, aX + margin.left, aY + margin.top);  nsIView*  view; childFrame->GetView(aPresContext, &view); if (view) { nsContainerFrame::PositionFrameView(aPresContext, childFrame, view);
if (!(aInfo.mFlags & NS_FRAME_IS_BOX)) { nsHTMLReflowState   reflowState(aPresContext, aReflowState, childFrame, nsSize(size.width, NS_INTRINSICSIZE)); reflowState.reason = reason;  if (size.height != NS_INTRINSICSIZE) size.height -= (border.top + border.bottom);  if (size.width != NS_INTRINSICSIZE) size.width -= (border.left + border.right);  reflowState.mComputedWidth = size.width; reflowState.mComputedHeight = size.height;   childFrame->WillReflow(aPresContext);  if (aMoveFrame) { PlaceChild(aPresContext, childFrame, aX + margin.left, aY + margin.top);
nsBoxFrameInner::FlowChildAt(nsIFrame* childFrame,                              nsIPresContext* aPresContext,                             nsHTMLReflowMetrics&     desiredSize,                             const nsHTMLReflowState& aReflowState,                             nsReflowStatus&          aStatus,                             nsCalculatedBoxInfo&     aInfo,                             nscoord                  aX,                             nscoord                  aY,                             PRBool                   aMoveFrame,                             nsIFrame*&               aIncrementalChild,                             PRBool& aRedraw,                             const nsString& aReason){      aStatus = NS_FRAME_COMPLETE;      PRBool needsReflow = PR_FALSE;      nsReflowReason reason = aReflowState.reason;      nsFrameState childState;      aInfo.frame->GetFrameState(&childState);      if (childState & NS_FRAME_FIRST_REFLOW) {          NS_ASSERTION(reason != eReflowReason_Incremental,"Error should not be incremental!!");          reason = eReflowReason_Initial;      } else if (reason == eReflowReason_Initial) {          reason = eReflowReason_Resize;      }             switch(reason)      {         // if the child we are reflowing is the child we popped off the incremental          // reflow chain then we need to reflow it no matter what.         // if its not the child we got from the reflow chain then this child needs reflow         // because as a side effect of the incremental child changing aize andit needs to be resized.         // This will happen with a lot when a box that contains 2 children with different flexabilities         // if on child gets bigger the other is affected because it is proprotional to the first.         // so it might need to be resized. But we don't need to reflow it. If it is already the         // needed size then we will do nothing.          case eReflowReason_Incremental:             if (aIncrementalChild == aInfo.frame) {               needsReflow = PR_TRUE;               aIncrementalChild = nsnull;             } else {               reason = eReflowReason_Resize;               needsReflow = PR_FALSE;             }                    break;                  // if its dirty then see if the child we want to reflow is dirty. If it is then         // mark it as needing to be reflowed.         case eReflowReason_Dirty:              // get the frame state to see if it needs reflow              needsReflow = (childState & NS_FRAME_IS_DIRTY) || (childState & NS_FRAME_HAS_DIRTY_CHILDREN);         break;         // if the a resize reflow then it doesn't need to be reflowed. Only if the size is different         // from the new size would we actually do a reflow         case eReflowReason_Resize:             needsReflow = PR_FALSE;         break;         // if its an initial reflow we must place the child.         // otherwise we might think it was already placed when it wasn't         case eReflowReason_Initial:             aMoveFrame = PR_TRUE;             needsReflow = PR_TRUE;         break;         default:             needsReflow = PR_TRUE;                   }      // subtract out the childs margin and border       const nsStyleSpacing* spacing;      nsresult rv = childFrame->GetStyleData(eStyleStruct_Spacing,                     (const nsStyleStruct*&) spacing);      nsMargin margin(0,0,0,0);      spacing->GetMargin(margin);      // get the current size of the child      nsRect currentRect(0,0,0,0);      childFrame->GetRect(currentRect);      // if we don't need a reflow then       // lets see if we are already that size. Yes? then don't even reflow. We are done.      if (!needsReflow) {                    if (aInfo.calculatedSize.width != NS_INTRINSICSIZE && aInfo.calculatedSize.height != NS_INTRINSICSIZE) {                        // if the new calculated size has a 0 width or a 0 height              if ((currentRect.width == 0 || currentRect.height == 0) && (aInfo.calculatedSize.width == 0 || aInfo.calculatedSize.height == 0)) {                   needsReflow = PR_FALSE;                   desiredSize.width = aInfo.calculatedSize.width - (margin.left + margin.right);                   desiredSize.height = aInfo.calculatedSize.height - (margin.top + margin.bottom);                   childFrame->SizeTo(aPresContext, desiredSize.width, desiredSize.height);              } else {                desiredSize.width = currentRect.width;                desiredSize.height = currentRect.height;                // remove the margin. The rect of our child does not include it but our calculated size does.                nscoord calcWidth = aInfo.calculatedSize.width - (margin.left + margin.right);                nscoord calcHeight = aInfo.calculatedSize.height - (margin.top + margin.bottom);                // don't reflow if we are already the right size                if (currentRect.width == calcWidth && currentRect.height == calcHeight)                      needsReflow = PR_FALSE;                else                      needsReflow = PR_TRUE;                     }          } else {              // if the width or height are intrinsic alway reflow because              // we don't know what it should be.             needsReflow = PR_TRUE;          }      }                                   // ok now reflow the child into the springs calculated space      if (needsReflow) {        nsMargin border(0,0,0,0);        spacing->GetBorderPadding(border);        const nsStylePosition* position;        rv = childFrame->GetStyleData(eStyleStruct_Position,                       (const nsStyleStruct*&) position);        desiredSize.width = 0;        desiredSize.height = 0;        nsSize size(aInfo.calculatedSize.width, aInfo.calculatedSize.height);        /*        // lets also look at our intrinsic flag. This flag is to make things like HR work.        // hr is funny if you flow it intrinsically you will get a size that is the height of        // the current font size. But if you then flow the hr with a computed height of what was returned the        // hr will be stretched out to fit. So basically the hr lays itself out differently depending         // on if you use intrinsic or or computed size. So to fix this we follow this policy. If any child        // does not Innerement nsIBox then we set this flag. Then on a flow if we decide to flow at the preferred width        // we flow it with a intrinsic width. This goes for height as well.        if (aInfo.prefWidthIntrinsic && size.width == aInfo.prefSize.width)            size.width = NS_INTRINSICSIZE;        if (aInfo.prefHeightIntrinsic && size.height == aInfo.prefSize.height)            size.height = NS_INTRINSICSIZE;        */        // only subrtact margin        if (size.height != NS_INTRINSICSIZE)            size.height -= (margin.top + margin.bottom);        if (size.width != NS_INTRINSICSIZE)            size.width -= (margin.left + margin.right);        // create a reflow state to tell our child to flow at the given size.        nsHTMLReflowState   reflowState(aPresContext, aReflowState, childFrame, nsSize(size.width, NS_INTRINSICSIZE));        reflowState.reason = reason;        if (size.height != NS_INTRINSICSIZE)            size.height -= (border.top + border.bottom);        if (size.width != NS_INTRINSICSIZE)            size.width -= (border.left + border.right);        reflowState.mComputedWidth = size.width;        reflowState.mComputedHeight = size.height;    //    nsSize maxElementSize(0, 0);      //  desiredSize.maxElementSize = &maxElementSize;       /* #if DEBUG_REFLOW  ListTag(stdout);   if (reason == eReflowReason_Incremental && aInfo.isIncremental)      printf(": INCREMENTALLY reflowing ");  else     printf(": reflowing ");   nsFrame::ListTag(stdout, childFrame);   char ch[100];   aReason.ToCString(ch,100);   printf("because (%s)\n", ch);#endif */#ifdef DEBUG_REFLOW   char* reflowReasonString;    switch(reflowState.reason)     {        case eReflowReason_Initial:          reflowReasonString = "initial";          break;        case eReflowReason_Resize:          reflowReasonString = "resize";          break;        case eReflowReason_Dirty:          reflowReasonString = "dirty";          break;        case eReflowReason_StyleChange:          reflowReasonString = "stylechange";          break;        case eReflowReason_Incremental:          reflowReasonString = "incremental";          break;        default:          reflowReasonString = "unknown";          break;    }    AddIndents();    nsFrame::ListTag(stdout, childFrame);    char ch[100];    aReason.ToCString(ch,100);    printf(" reason=%s %s\n",reflowReasonString,ch);#endif    // place the child and reflow        childFrame->WillReflow(aPresContext);        if (aMoveFrame) {            childFrame->MoveTo(aPresContext, aX + margin.left, aY + margin.top);            nsIView*  view;            childFrame->GetView(aPresContext, &view);            if (view) {                nsContainerFrame::PositionFrameView(aPresContext, childFrame, view);            }        }        childFrame->Reflow(aPresContext, desiredSize, reflowState, aStatus);        NS_ASSERTION(NS_FRAME_IS_COMPLETE(aStatus), "bad status");        nsFrameState  kidState;        childFrame->GetFrameState(&kidState);       // printf("width: %d, height: %d\n", desiredSize.mCombinedArea.width, desiredSize.mCombinedArea.height);        if (kidState & NS_FRAME_OUTSIDE_CHILDREN) {             desiredSize.width = desiredSize.mOverflowArea.width;             desiredSize.height = desiredSize.mOverflowArea.height;        }        //        if (maxElementSize.width > desiredSize.width)  //          desiredSize.width = maxElementSize.width;        PRBool changedSize = PR_FALSE;        if (currentRect.width != desiredSize.width || currentRect.height != desiredSize.height)           changedSize = PR_TRUE;                // if the child got bigger then make sure the new size in our min max range        if (changedSize) {                    // redraw if we changed size.          aRedraw = PR_TRUE;          if (aInfo.maxSize.width != NS_INTRINSICSIZE && desiredSize.width > aInfo.maxSize.width - (margin.left + margin.right))              desiredSize.width = aInfo.maxSize.width - (margin.left + margin.right);          // if the child was bigger than anticipated and there was a min size set thennn          if (aInfo.calculatedSize.width != NS_INTRINSICSIZE && position->mMinWidth.GetUnit() == eStyleUnit_Coord) {             nscoord min = position->mMinWidth.GetCoordValue();             if (min != 0)                 desiredSize.width = aInfo.calculatedSize.width - (margin.left + margin.right);          }          if (aInfo.maxSize.height != NS_INTRINSICSIZE && desiredSize.height > aInfo.maxSize.height - (margin.top + margin.bottom))              desiredSize.height = aInfo.maxSize.height - (margin.top + margin.bottom);          // if a min size was set we will always get the desired height          if (aInfo.calculatedSize.height != NS_INTRINSICSIZE && position->mMinHeight.GetUnit() == eStyleUnit_Coord) {             nscoord min = position->mMinHeight.GetCoordValue();             if (min != 0)                 desiredSize.height = aInfo.calculatedSize.height - (margin.top + margin.bottom);          }        }         nsContainerFrame::FinishReflowChild(childFrame, aPresContext, desiredSize, aX + margin.left, aY + margin.top, NS_FRAME_NO_MOVE_FRAME);        /*        // set the rect and size the view (if it has one).. Don't position the view        // and sync its properties (like opacity) until later when we know its final        // position        childFrame->SizeTo(aPresContext, desiredSize.width, desiredSize.height);        nsIView*  view;        childFrame->GetView(aPresContext, &view);        if (view) {          nsIViewManager  *vm;          view->GetViewManager(vm);          vm->ResizeView(view, desiredSize.width, desiredSize.height);          NS_RELEASE(vm);        }        childFrame->DidReflow(aPresContext, NS_FRAME_REFLOW_FINISHED);        */        // Stub out desiredSize.maxElementSize so that when go out of        // scope, nothing bad happens!        //desiredSize.maxElementSize = nsnull;            } else {          if (aMoveFrame) {              nsPoint curOrigin;              childFrame->GetOrigin(curOrigin);              // only if the origin changed              //if ((curOrigin.x != aX + margin.left) || (curOrigin.y != aY + margin.top)) {                  childFrame->MoveTo(aPresContext,  aX + margin.left, aY + margin.top);                  nsIView*  view;                  childFrame->GetView(aPresContext, &view);                  if (view)                       nsContainerFrame::PositionFrameView(aPresContext, childFrame, view);                  else                      nsContainerFrame::PositionChildViews(aPresContext, childFrame);             // }          }      }                // add the margin back in. The child should add its border automatically      desiredSize.height += (margin.top + margin.bottom);      desiredSize.width += (margin.left + margin.right);#ifdef DEBUG_REFLOW      if (aInfo.calculatedSize.height != NS_INTRINSICSIZE && desiredSize.height != aInfo.calculatedSize.height)      {              AddIndents();              printf("**** Child ");              nsFrame::ListTag(stdout, childFrame);              printf(" got taller!******\n");                   }      if (aInfo.calculatedSize.width != NS_INTRINSICSIZE && desiredSize.width != aInfo.calculatedSize.width)      {              AddIndents();              printf("**** Child ");              nsFrame::ListTag(stdout, childFrame);              printf(" got wider!******\n");                   }#endif      if (aInfo.calculatedSize.width == NS_INTRINSICSIZE)         aInfo.calculatedSize.width = desiredSize.width;      if (aInfo.calculatedSize.height == NS_INTRINSICSIZE)         aInfo.calculatedSize.height = desiredSize.height;      return NS_OK;}