RootContentFrame::Reflow(nsIPresContext&          aPresContext, nsHTMLReflowMetrics&     aDesiredSize, const nsHTMLReflowState& aReflowState, nsReflowStatus&          aStatus)
RootFrame::Reflow(nsIPresContext&          aPresContext, nsHTMLReflowMetrics&     aDesiredSize, const nsHTMLReflowState& aReflowState, nsReflowStatus&          aStatus)
RootContentFrame::Reflow(nsIPresContext&          aPresContext,                         nsHTMLReflowMetrics&     aDesiredSize,                         const nsHTMLReflowState& aReflowState,                         nsReflowStatus&          aStatus){  NS_FRAME_TRACE_REFLOW_IN("RootContentFrame::Reflow");  aStatus = NS_FRAME_COMPLETE;  // XXX Need a copy of this margin and border handling code in nsPageFrame  // Calculate margin around our child  nsMargin margin;  ComputeChildMargins(margin);  // Calculate our border and padding. Note that we use our parents  // style context since we have a pseudo-style.  nsMargin borderPadding(0, 0, 0, 0);  const nsStyleSpacing* spacing;  mGeometricParent->GetStyleData(eStyleStruct_Spacing,                                 (const nsStyleStruct*&) spacing);  if (nsnull != spacing) {    spacing->CalcBorderPaddingFor(this, borderPadding);  }  // Calculate the inner area available for reflowing the child  nscoord top = margin.top + borderPadding.top;  nscoord right = margin.right + borderPadding.right;  nscoord bottom = margin.bottom + borderPadding.bottom;  nscoord left = margin.left + borderPadding.left;  nscoord availWidth = aReflowState.maxSize.width - left - right;  // If this is not a paginated view then (maybe) subtract out space  // reserved for the scroll bar. We check our child and see if it  // wants to be scrolled (overflow: auto/scroll) and if so then we  // reserve some space for the scrollbar.  nscoord sbarWidth = 0;  if (!aPresContext.IsPaginated()) {    const nsStyleDisplay* display;    mFirstChild->GetStyleData(eStyleStruct_Display,                              (const nsStyleStruct*&) display);    if ((NS_STYLE_OVERFLOW_AUTO == display->mOverflow) ||        (NS_STYLE_OVERFLOW_SCROLL == display->mOverflow)) {      nsIDeviceContext* dc = aPresContext.GetDeviceContext();      float sbWidth, sbHeight;      dc->GetScrollBarDimensions(sbWidth, sbHeight);      sbarWidth = NSToCoordRound(sbWidth);      availWidth -= sbarWidth;      NS_RELEASE(dc);    }  }  // XXX Incremental reflow code doesn't handle page mode at all...  if (eReflowReason_Incremental == aReflowState.reason) {    // We don't expect the target of the reflow command to be the root    // content frame#ifdef NS_DEBUG    nsIFrame* target;    aReflowState.reflowCommand->GetTarget(target);    NS_ASSERTION(target != this, "root content frame is reflow command target");#endif      // Verify the next frame in the reflow chain is our child frame    nsIFrame* next;    aReflowState.reflowCommand->GetNext(next);    NS_ASSERTION(next == mFirstChild, "unexpected next reflow command frame");    nsSize            maxSize(availWidth, NS_UNCONSTRAINEDSIZE);    nsHTMLReflowState kidReflowState(aPresContext, next, aReflowState,                                     maxSize);      // Dispatch the reflow command to our child frame. Allow it to be as high    // as it wants    ReflowChild(mFirstChild, aPresContext, aDesiredSize, kidReflowState, aStatus);      // Place and size the child    nsRect  rect(left, top, aDesiredSize.width, aDesiredSize.height);    mFirstChild->SetRect(rect);    // Compute our desired size    aDesiredSize.width += left + right + sbarWidth;    aDesiredSize.height += top + bottom;    if (aDesiredSize.height < aReflowState.maxSize.height) {      aDesiredSize.height = aReflowState.maxSize.height;    }  } else {    nsReflowReason  reflowReason = aReflowState.reason;    // Resize our frames    if (nsnull != mFirstChild) {      if (aPresContext.IsPaginated()) {        nscoord             y = PAGE_SPACING_TWIPS;        nsHTMLReflowMetrics kidSize(aDesiredSize.maxElementSize);        // Compute the size of each page and the x coordinate within        // ourselves that the pages will be placed at.        nsSize          pageSize(aPresContext.GetPageWidth(),                                 aPresContext.GetPageHeight());        nsIDeviceContext *dx = aPresContext.GetDeviceContext();        float             sbWidth, sbHeight;        dx->GetScrollBarDimensions(sbWidth, sbHeight);        PRInt32 extra = aReflowState.maxSize.width - PAGE_SPACING_TWIPS*2 -          pageSize.width - NSToCoordRound(sbWidth);        NS_RELEASE(dx);        // Note: nscoord is an unsigned type so don't combine these        // two statements or the extra will be promoted to unsigned        // and the >0 won't work!        nscoord x = PAGE_SPACING_TWIPS;        if (extra > 0) {          x += extra / 2;        }          // Tile the pages vertically        for (nsIFrame* kidFrame = mFirstChild; nsnull != kidFrame; ) {          // Reflow the page          nsHTMLReflowState kidReflowState(aPresContext, kidFrame,                                           aReflowState, pageSize,                                           reflowReason);          nsReflowStatus  status;          // Place and size the page. If the page is narrower than our          // max width then center it horizontally          ReflowChild(kidFrame, aPresContext, kidSize, kidReflowState, status);          kidFrame->SetRect(nsRect(x, y, kidSize.width, kidSize.height));          y += kidSize.height;            // Leave a slight gap between the pages          y += PAGE_SPACING_TWIPS;            // Is the page complete?          nsIFrame* kidNextInFlow;                     kidFrame->GetNextInFlow(kidNextInFlow);          if (NS_FRAME_IS_COMPLETE(status)) {            NS_ASSERTION(nsnull == kidNextInFlow, "bad child flow list");          } else if (nsnull == kidNextInFlow) {            // The page isn't complete and it doesn't have a next-in-flow so            // create a continuing page            nsIStyleContext* kidSC;            kidFrame->GetStyleContext(&aPresContext, kidSC);            nsIFrame*  continuingPage;            nsresult rv = kidFrame->CreateContinuingFrame(aPresContext, this,                                                          kidSC, continuingPage);            NS_RELEASE(kidSC);            reflowReason = eReflowReason_Initial;              // Add it to our child list#ifdef NS_DEBUG            nsIFrame* kidNextSibling;            kidFrame->GetNextSibling(kidNextSibling);            NS_ASSERTION(nsnull == kidNextSibling, "unexpected sibling");#endif            kidFrame->SetNextSibling(continuingPage);          }            // Get the next page          kidFrame->GetNextSibling(kidFrame);        }          // Return our desired size        aDesiredSize.height = y;        if (aDesiredSize.height < aReflowState.maxSize.height) {          aDesiredSize.height = aReflowState.maxSize.height;        }        aDesiredSize.width = PAGE_SPACING_TWIPS*2 + pageSize.width;        if (aDesiredSize.width < aReflowState.maxSize.width) {          aDesiredSize.width = aReflowState.maxSize.width;        }        } else {        nsSize            maxSize(availWidth, NS_UNCONSTRAINEDSIZE);        nsHTMLReflowState kidReflowState(aPresContext, mFirstChild,                                         aReflowState, maxSize,                                         reflowReason);          // Get the child's desired size. Our child's desired height is our        // desired size        ReflowChild(mFirstChild, aPresContext, aDesiredSize, kidReflowState, aStatus);        NS_ASSERTION(NS_FRAME_IS_COMPLETE(aStatus), "bad status");          // Place and size the child        nsRect  rect(left, top, aDesiredSize.width, aDesiredSize.height);        mFirstChild->SetRect(rect);        // Compute our desired size        aDesiredSize.width += left + right + sbarWidth;        aDesiredSize.height += top + bottom;        if (aDesiredSize.height < aReflowState.maxSize.height) {          aDesiredSize.height = aReflowState.maxSize.height;        }        // Do the necessary repainting        if (eReflowReason_Initial == reflowReason) {          // Repaint the visible area          Invalidate(nsRect(0, 0, aReflowState.maxSize.width, aReflowState.maxSize.height));        } else if (eReflowReason_Resize == aReflowState.reason) {          // Repaint the entire frame          Invalidate(nsRect(0, 0, aReflowState.maxSize.width, aDesiredSize.height));        }      }    }    else {      aDesiredSize.width = aReflowState.maxSize.width;      aDesiredSize.height = aReflowState.maxSize.height;      aDesiredSize.ascent = aDesiredSize.height;      aDesiredSize.descent = 0;      if (nsnull != aDesiredSize.maxElementSize) {        aDesiredSize.maxElementSize->width = 0;        aDesiredSize.maxElementSize->height = 0;      }    }  }  // We are always a pseudo-frame; make sure our content offset is  // properly pushed upwards  nsContainerFrame* parent = (nsContainerFrame*) mGeometricParent;  NS_FRAME_TRACE_REFLOW_OUT("RootContentFrame::Reflow", aStatus);  return NS_OK;}