if (maxSize.width == NS_UNCONSTRAINEDSIZE && maxSize.height == NS_UNCONSTRAINEDSIZE) {   mPresContext->SetVisibleArea(nsRect(0,0,desiredSize.width, desiredSize.height));   nsCOMPtr<nsIWebShell> webShell; nsCOMPtr<nsISupports> container; mPresContext->GetContainer(getter_AddRefs(container)); if (container) { webShell = do_QueryInterface(container); if (webShell) {  nsCOMPtr<nsIWebShellContainer> rootContainer; webShell->GetContainer(*getter_AddRefs(rootContainer)); if (rootContainer) { nsCOMPtr<nsIBrowserWindow> browserWindow = do_QueryInterface(rootContainer); if (browserWindow) { PRInt32 chromeX,chromeY,chromeWidth,chromeHeight; webShell->GetBounds(chromeX,chromeY,chromeWidth,chromeHeight);  float t2p; mPresContext->GetTwipsToPixels(&t2p); PRInt32 width = PRInt32((float)desiredSize.width*t2p); PRInt32 height = PRInt32((float)desiredSize.height*t2p);  PRInt32 widthDelta = width - chromeWidth; PRInt32 heightDelta = height - chromeHeight;  nsRect windowBounds; browserWindow->GetWindowBounds(windowBounds); browserWindow->SizeWindowTo(windowBounds.width + widthDelta, windowBounds.height + heightDelta); } } } } }
mPresContext->SetVisibleArea(nsRect(0,0,desiredSize.width,desiredSize.height));
PresShell::InitialReflow(nscoord aWidth, nscoord aHeight){  nsIContent* root = nsnull;  SuspendCaret();  EnterReflowLock();  if (mPresContext) {    nsRect r(0, 0, aWidth, aHeight);    mPresContext->SetVisibleArea(r);  }  if (mDocument) {    root = mDocument->GetRootContent();  }  if (nsnull != root) {    if (nsnull == mRootFrame) {      // Have style sheet processor construct a frame for the      // precursors to the root content object's frame      mStyleSet->ConstructRootFrame(mPresContext, root, mRootFrame);    }    // Have the style sheet processor construct frame for the root    // content object down    mStyleSet->ContentInserted(mPresContext, nsnull, root, 0);    NS_RELEASE(root);  }  if (nsnull != mRootFrame) {    // Kick off a top-down reflow    NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,                 ("enter nsPresShell::InitialReflow: %d,%d", aWidth, aHeight));#ifdef NS_DEBUG    if (nsIFrame::GetVerifyTreeEnable()) {      mRootFrame->VerifyTree();    }#endif    nsRect                bounds;    mPresContext->GetVisibleArea(bounds);    nsSize                maxSize(bounds.width, bounds.height);    nsHTMLReflowMetrics   desiredSize(nsnull);    nsReflowStatus        status;    nsIHTMLReflow*        htmlReflow;    nsIRenderingContext*  rcx = nsnull;    CreateRenderingContext(mRootFrame, &rcx);    nsHTMLReflowState reflowState(*mPresContext, mRootFrame,                                  eReflowReason_Initial, rcx, maxSize);    if (NS_OK == mRootFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) {      htmlReflow->Reflow(*mPresContext, desiredSize, reflowState, status);      mRootFrame->SizeTo(desiredSize.width, desiredSize.height);      if (maxSize.width == NS_UNCONSTRAINEDSIZE && maxSize.height == NS_UNCONSTRAINEDSIZE) {        // We were flowed intrinsically. Set our new visible area to our intrinsic        // size.        mPresContext->SetVisibleArea(nsRect(0,0,desiredSize.width, desiredSize.height));                // Provide our window with the hint that it needs to resize.        nsCOMPtr<nsIWebShell> webShell;        nsCOMPtr<nsISupports> container;        mPresContext->GetContainer(getter_AddRefs(container));        if (container) {          webShell = do_QueryInterface(container);          if (webShell) {            // Retrieve our container and see if it's a browser window.            nsCOMPtr<nsIWebShellContainer> rootContainer;            webShell->GetContainer(*getter_AddRefs(rootContainer));            if (rootContainer) {              nsCOMPtr<nsIBrowserWindow> browserWindow = do_QueryInterface(rootContainer);              if (browserWindow) {                PRInt32 chromeX,chromeY,chromeWidth,chromeHeight;                webShell->GetBounds(chromeX,chromeY,chromeWidth,chromeHeight);                float t2p;                mPresContext->GetTwipsToPixels(&t2p);                PRInt32 width = PRInt32((float)desiredSize.width*t2p);                PRInt32 height = PRInt32((float)desiredSize.height*t2p);                                PRInt32 widthDelta = width - chromeWidth;                PRInt32 heightDelta = height - chromeHeight;                nsRect windowBounds;                browserWindow->GetWindowBounds(windowBounds);                browserWindow->SizeWindowTo(windowBounds.width + widthDelta,                                             windowBounds.height + heightDelta);              }            }          }        }      }#ifdef NS_DEBUG      if (nsIFrame::GetVerifyTreeEnable()) {        mRootFrame->VerifyTree();      }#endif    }    NS_IF_RELEASE(rcx);    NS_FRAME_LOG(NS_FRAME_TRACE_CALLS, ("exit nsPresShell::InitialReflow"));  }  ExitReflowLock();  ResumeCaret();  return NS_OK; //XXX this needs to be real. MMP}