nscoord width, height; CalculateFixedContainingBlockSize(aPresContext, aReflowState, width, height);
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;  PRBool    isHandled = PR_FALSE;    nsReflowType reflowType = eReflowType_ContentChanged;  if (aReflowState.path) {    // XXXwaterson this is more restrictive than the previous code    // was: it insists that the UserDefined reflow be targeted at    // _this_ frame.    nsHTMLReflowCommand *command = aReflowState.path->mReflowCommand;    if (command)      command->GetType(reflowType);  }  if (reflowType == eReflowType_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    nsHTMLReflowCommand *command = aReflowState.path->mReflowCommand;    if (command) {      nsIAtom*  listName;      PRBool    isFixedChild;            // It's targeted at us. It better be for the fixed child list      command->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);      }    }  }  nsRect kidRect(0,0,aReflowState.availableWidth,aReflowState.availableHeight);  if (eReflowReason_Incremental == aReflowState.reason) {    nsReflowPath::iterator iter = aReflowState.path->FirstChild();    nsReflowPath::iterator end = aReflowState.path->EndChildren();    for ( ; iter != end; ++iter) {      if (mFixedFrames.ContainsFrame(*iter)) {        // Reflow the 'fixed' frame that's the next frame in the reflow path              // Calculate how much room is available for the fixed frame. That means        // determining if the viewport is scrollable and whether the vertical and/or        // horizontal scrollbars are visible        nscoord width, height;        CalculateFixedContainingBlockSize(aPresContext, aReflowState, width, height);          // Make a copy of the reflow state and change the computed width and height        // to reflect the available space for the fixed items        // XXX Find a cleaner way to do this...        nsHTMLReflowState reflowState(aReflowState);        reflowState.mComputedWidth = width;        reflowState.mComputedHeight = height;              nsReflowStatus  kidStatus;        ReflowFixedFrame(aPresContext, reflowState, *iter, PR_FALSE,                         kidStatus);      }    }  }  if (mFrames.NotEmpty()) {    // Deal with a non-incremental reflow or an incremental reflow    // targeted at our one-and-only principal child frame.    if (eReflowReason_Incremental != aReflowState.reason ||        aReflowState.path->HasChild(mFrames.FirstChild())) {      // Reflow our one-and-only principal child frame      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 (eReflowReason_Incremental != aReflowState.reason) {    // If it's anything but an incremental reflow, then reflow all the    // fixed positioned child frames.    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;}