NS_PRECONDITION(nsnull == aDesiredSize.maxElementSize, "unexpected request");
NS_PRECONDITION(!aDesiredSize.mComputeMEW, "unexpected request");
ViewportFrame::Reflow(nsIPresContext*          aPresContext,                      nsHTMLReflowMetrics&     aDesiredSize,                      const nsHTMLReflowState& aReflowState,                      nsReflowStatus&          aStatus){  DO_GLOBAL_REFLOW_COUNT("ViewportFrame", aReflowState.reason);  DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);  NS_FRAME_TRACE_REFLOW_IN("ViewportFrame::Reflow");  NS_PRECONDITION(nsnull == aDesiredSize.maxElementSize, "unexpected request");  // Initialize OUT parameter  aStatus = NS_FRAME_COMPLETE;  nsIFrame* nextFrame = nsnull;  PRBool    isHandled = PR_FALSE;    nsIReflowCommand::ReflowType reflowType = nsIReflowCommand::ContentChanged;  if (aReflowState.reflowCommand) {    aReflowState.reflowCommand->GetType(reflowType);  }  if (reflowType == nsIReflowCommand::UserDefined) {    // Reflow the fixed frames to account for changed scrolled area size    ReflowFixedFrames(aPresContext, aReflowState);    isHandled = PR_TRUE;    // Otherwise check for an incremental reflow  } else if (eReflowReason_Incremental == aReflowState.reason) {    // See if we're the target frame    nsIFrame* targetFrame;    aReflowState.reflowCommand->GetTarget(targetFrame);    if (this == targetFrame) {      nsIAtom*  listName;      PRBool    isFixedChild;            // It's targeted at us. It better be for the fixed child list      aReflowState.reflowCommand->GetChildListName(listName);      isFixedChild = nsLayoutAtoms::fixedList == listName;      NS_IF_RELEASE(listName);      NS_ASSERTION(isFixedChild, "unexpected child list");            if (isFixedChild) {        // Handle the incremental reflow command        IncrementalReflow(aPresContext, aReflowState);        isHandled = PR_TRUE;      }    } else {      // Get the next frame in the reflow chain      aReflowState.reflowCommand->GetNext(nextFrame);    }  }  nsRect kidRect(0,0,aReflowState.availableWidth,aReflowState.availableHeight);  if (!isHandled) {    if ((eReflowReason_Incremental == aReflowState.reason) &&        (mFixedFrames.ContainsFrame(nextFrame))) {      // Reflow the 'fixed' frame that's the next frame in the reflow path      nsReflowStatus  kidStatus;      ReflowFixedFrame(aPresContext, aReflowState, nextFrame, PR_FALSE,                       kidStatus);    } else {      // Reflow our one and only principal child frame      if (mFrames.NotEmpty()) {        nsIFrame*           kidFrame = mFrames.FirstChild();        nsHTMLReflowMetrics kidDesiredSize(nsnull);        nsSize              availableSpace(aReflowState.availableWidth,                                           aReflowState.availableHeight);        nsHTMLReflowState   kidReflowState(aPresContext, aReflowState,                                           kidFrame, availableSpace);        // Reflow the frame        kidReflowState.mComputedHeight = aReflowState.availableHeight;        ReflowChild(kidFrame, aPresContext, kidDesiredSize, kidReflowState,                    0, 0, 0, aStatus);        kidRect.width = kidDesiredSize.width;        kidRect.height = kidDesiredSize.height;        FinishReflowChild(kidFrame, aPresContext, nsnull, kidDesiredSize, 0, 0, 0);      }      // If it's a 'initial', 'resize', or 'style change' reflow command (anything      // but incremental), then reflow all the fixed positioned child frames      if (eReflowReason_Incremental != aReflowState.reason) {        ReflowFixedFrames(aPresContext, aReflowState);      }    }  }  // If we were flowed initially at both an unconstrained width and height,   // this is a hint that we should return our child's intrinsic size.  if ((eReflowReason_Initial == aReflowState.reason ||       eReflowReason_Resize == aReflowState.reason) &&      aReflowState.availableWidth == NS_UNCONSTRAINEDSIZE &&      aReflowState.availableHeight == NS_UNCONSTRAINEDSIZE) {    aDesiredSize.width = kidRect.width;    aDesiredSize.height = kidRect.height;    aDesiredSize.ascent = kidRect.height;    aDesiredSize.descent = 0;  }  else {    // Return the max size as our desired size    aDesiredSize.width = aReflowState.availableWidth;    aDesiredSize.height = aReflowState.availableHeight;    aDesiredSize.ascent = aReflowState.availableHeight;    aDesiredSize.descent = 0;  }  // If this is an initial reflow, resize reflow, or style change reflow  // then do a repaint  if ((eReflowReason_Initial == aReflowState.reason) ||      (eReflowReason_Resize == aReflowState.reason) ||      (eReflowReason_StyleChange == aReflowState.reason)) {    nsRect  damageRect(0, 0, aDesiredSize.width, aDesiredSize.height);    if (!damageRect.IsEmpty()) {      Invalidate(aPresContext, damageRect, PR_FALSE);    }  }  NS_FRAME_TRACE_REFLOW_OUT("ViewportFrame::Reflow", aStatus);  return NS_OK;}