mPrt->mShrinkRatio = PR_MAX(mPrt->mShrinkRatio, 0.5f);
DocumentViewerImpl::SetupToPrintContent(nsIWebShell*          aParent,                                        nsIDeviceContext*     aDContext,                                        nsIDOMWindowInternal* aCurrentFocusedDOMWin){  NS_ENSURE_ARG_POINTER(aParent);  NS_ENSURE_ARG_POINTER(aDContext);  // NOTE: aCurrentFocusedDOMWin may be null (which is OK)  mPrt->mPrintDocDC = aDContext;  // In this step we figure out which documents should be printed  // i.e. if we are printing the selection then only enable that PrintObject  // for printing  if (NS_FAILED(EnablePOsForPrinting())) {    return NS_ERROR_FAILURE;  }  DUMP_DOC_LIST("\nAfter Enable------------------------------------------");  // This is an Optimization  // If we are in PP then we already know all the shrinkage information  // so just transfer it to the PrintData and we will skip the extra shrinkage reflow  //  // doSetPixelScale tells Reflow whether to set the shrinkage value into the DC  // The first tru we do not want to do this, the second time thru we do  PRBool doSetPixelScale = PR_FALSE;  PRBool ppIsShrinkToFit = mPrtPreview && mPrtPreview->mShrinkToFit;  if (ppIsShrinkToFit) {    mPrt->mShrinkRatio = mPrtPreview->mShrinkRatio;    doSetPixelScale = PR_TRUE;  }  // Here we reflow all the PrintObjects  if (NS_FAILED(ReflowDocList(mPrt->mPrintObject, doSetPixelScale, mPrt->mShrinkToFit))) {    return NS_ERROR_FAILURE;  }  // Here is where we do the extra reflow for shrinking the content  // But skip this step if we are in PrintPreview  if (mPrt->mShrinkToFit && !ppIsShrinkToFit) {    if (mPrt->mPrintDocList->Count() > 1 && mPrt->mPrintObject->mFrameType == eFrameSet) {      PrintObject* xMostPO = FindXMostPO();      NS_ASSERTION(xMostPO, "There must always be an XMost PO!");      if (xMostPO) {        // The margin is included in the PO's mRect so we need to subtract it        nsMargin margin(0,0,0,0);        mPrt->mPrintSettings->GetMarginInTwips(margin);        nsRect rect = xMostPO->mRect;        rect.x -= margin.left;        // Calc the shrinkage based on the entire content area        mPrt->mShrinkRatio = float(rect.XMost()) / float(rect.x + xMostPO->mXMost);      }    } else {      // Single document so use the Shrink as calculated for the PO      mPrt->mShrinkRatio = mPrt->mPrintObject->mShrinkRatio;    }    // Only Shrink if we are smaller    if (mPrt->mShrinkRatio < 1.0f) {      for (PRInt32 i=0;i<mPrt->mPrintDocList->Count();i++) {        PrintObject* po = (PrintObject*)mPrt->mPrintDocList->ElementAt(i);        NS_ASSERTION(po, "PrintObject can't be null!");        // Wipe out the presentation before we reflow        po->DestroyPresentation();      }      // Here we reflow all the PrintObjects a second time      // this time using the shrinkage values      // The last param here tells reflow to NOT calc the shrinkage values      if (NS_FAILED(ReflowDocList(mPrt->mPrintObject, PR_TRUE, PR_FALSE))) {        return NS_ERROR_FAILURE;      }    }  }  DUMP_DOC_LIST("\nAfter Reflow------------------------------------------");  PRINT_DEBUG_MSG1("\n-------------------------------------------------------\n\n");  // Set up the clipping rectangle for all documents  // When frames are being printed as part of a frame set and also IFrames,   // they are reflowed with a very large page height. We need to setup the  // clipping so they do not rpint over top of anything else  PRINT_DEBUG_MSG1("SetClipRect-------------------------------------------------------\n");  nsRect clipRect(-1,-1,-1, -1);  SetClipRect(mPrt->mPrintObject, clipRect, 0, 0, PR_FALSE);  CalcNumPrintableDocsAndPages(mPrt->mNumPrintableDocs, mPrt->mNumPrintablePages);  PRINT_DEBUG_MSG3("--- Printing %d docs and %d pages\n", mPrt->mNumPrintableDocs, mPrt->mNumPrintablePages);  DUMP_DOC_TREELAYOUT;  PRINT_DEBUG_FLUSH;#ifdef DEBUG_PRINTING_X#if defined(XP_PC)  for (PRInt32 i=0;i<mPrt->mPrintDocList->Count();i++) {    PrintObject* po = (PrintObject*)mPrt->mPrintDocList->ElementAt(i);    NS_ASSERTION(po, "PrintObject can't be null!");    if (po->mPresShell) {      nsIPageSequenceFrame* pageSequence;      po->mPresShell->GetPageSequenceFrame(&pageSequence);      if (pageSequence != nsnull) {        // install the debugging file pointer        nsSimplePageSequenceFrame * sf = NS_STATIC_CAST(nsSimplePageSequenceFrame*, pageSequence);        sf->SetDebugFD(mPrt->mDebugFD);      }    }  }#endif#endif  mPrt->mPrintDocDW = aCurrentFocusedDOMWin;  // This will print the webshell document  // when it completes asynchronously in the DonePrintingPages method  // it will check to see if there are more webshells to be printed and   // then PrintDocContent will be called again.  nsresult rv = NS_OK;  if (mIsDoingPrinting) {    PrintDocContent(mPrt->mPrintObject, rv); // ignore return value  }  return rv;}