aDonePrinting = PrintPage(poPresContext, printService, aPO);
aDonePrinting = PrintPage(poPresContext, mPrt->mPrintSettings, aPO);
DocumentViewerImpl::DoPrint(PrintObject * aPO, PRBool aDoSyncPrinting, PRBool& aDonePrinting){  NS_ASSERTION(mPrt->mPrintDocList, "Pointer is null!");  PRINT_DEBUG_MSG2("\n**************************** %s ****************************\n", gFrameTypesStr[aPO->mFrameType]);  PRINT_DEBUG_MSG3("****** In DV::DoPrint   PO: %p aDoSyncPrinting: %s \n", aPO, PRT_YESNO(aDoSyncPrinting));  nsIWebShell*    webShell      = aPO->mWebShell.get();  nsIPresShell*   poPresShell   = aPO->mPresShell;  nsIPresContext* poPresContext = aPO->mPresContext;  nsIView*        poRootView    = aPO->mRootView;  nsCOMPtr<nsIWebShell> webContainer(do_QueryInterface(mContainer));  NS_ASSERTION(webShell, "The WebShell can't be NULL!");  if (webShell != nsnull) {    PRInt16 printRangeType = nsIPrintOptions::kRangeAllPages;    nsresult rv;    nsCOMPtr<nsIPrintOptions> printService =              do_GetService(kPrintOptionsCID, &rv);    if (NS_SUCCEEDED(rv) && printService) {      printService->GetPrintRange(&printRangeType);    }    // Ask the page sequence frame to print all the pages    nsIPageSequenceFrame* pageSequence;    poPresShell->GetPageSequenceFrame(&pageSequence);    NS_ASSERTION(nsnull != pageSequence, "no page sequence frame");    // Now, depending how we are printing and what type of doc we are printing    // we must configure the sequencer correctly.    // so we are about to be very explicit about the whole process    PRBool skipPageEjectOnly      = PR_FALSE;    PRBool skipAllPageAdjustments = PR_FALSE;    PRBool doOffsetting           = PR_FALSE;    PRBool doAddInParentsOffset   = PR_TRUE;    PRBool skipSetTitle           = PR_FALSE;    if (aPO->mFrameType == eFrame) {      switch (mPrt->mPrintFrameType) {      case nsIPrintOptions::kFramesAsIs:           skipAllPageAdjustments = PR_TRUE;          doOffsetting           = PR_TRUE;          break;        case nsIPrintOptions::kSelectedFrame:          if (aPO->mKids.Count() > 0) {            skipPageEjectOnly = PR_TRUE;          }          break;        case nsIPrintOptions::kEachFrameSep:          if (aPO->mKids.Count() > 0) {            skipPageEjectOnly = PR_TRUE;          }          break;      } // switch    } else if (aPO->mFrameType == eIFrame) {      switch (mPrt->mPrintFrameType) {        case nsIPrintOptions::kFramesAsIs:          skipAllPageAdjustments = PR_TRUE;          doOffsetting           = PR_TRUE;          skipSetTitle           = PR_TRUE;          break;        case nsIPrintOptions::kSelectedFrame:          if (aPO != mPrt->mSelectedPO) {            skipAllPageAdjustments = PR_TRUE;            doOffsetting           = PR_TRUE;            doAddInParentsOffset   = aPO->mParent != nsnull && aPO->mParent->mFrameType == eIFrame && aPO->mParent != mPrt->mSelectedPO;            skipSetTitle           = PR_TRUE;          } else {            skipPageEjectOnly = aPO->mKids.Count() > 0;          }          break;        case nsIPrintOptions::kEachFrameSep:          skipAllPageAdjustments = PR_TRUE;          doOffsetting           = PR_TRUE;          doAddInParentsOffset   = aPO->mParent != nsnull && aPO->mParent->mFrameType == eIFrame;          skipSetTitle           = PR_TRUE;          break;      } // switch    } else {      // FrameSets skip page eject only if printing AsIs      skipPageEjectOnly = aPO->mPrintAsIs;    }    // That we are all configured,     // let's set everything up to print    if (skipPageEjectOnly) {      pageSequence->SkipPageEnd();      aPO->mSkippedPageEject = PR_TRUE;    } else {      if (skipAllPageAdjustments) {        pageSequence->SuppressHeadersAndFooters(PR_TRUE);        pageSequence->SkipPageBegin();        pageSequence->SkipPageEnd();        aPO->mSkippedPageEject = PR_TRUE;      } else {        aPO->mSkippedPageEject = PR_FALSE;      }      if (doOffsetting) {        nscoord x = 0;        nscoord y = 0;        PrintObject * po = aPO;        while (po != nsnull) {          //if (mPrt->mPrintFrameType != nsIPrintOptions::kSelectedFrame || po != aPO->mParent) {          PRBool isParent = po == aPO->mParent;          if (!isParent || (isParent && doAddInParentsOffset)) {            x += po->mRect.x;            y += po->mRect.y;          }          po = po->mParent;        }        pageSequence->SetOffset(x, y);      }    }    PRINT_DEBUG_MSG5("*** skipPageEjectOnly: %s  skipAllPageAdjustments: %s  doOffsetting: %s  doAddInParentsOffset: %s\n",                       PRT_YESNO(skipPageEjectOnly), PRT_YESNO(skipAllPageAdjustments),                       PRT_YESNO(doOffsetting), PRT_YESNO(doAddInParentsOffset));    if (nsnull != mPrt->mFilePointer) {      // output the regression test      nsIFrameDebug* fdbg;      nsIFrame* root;      poPresShell->GetRootFrame(&root);      if (NS_SUCCEEDED(CallQueryInterface(root, &fdbg))) {        fdbg->DumpRegressionData(poPresContext, mPrt->mFilePointer, 0, PR_TRUE);      }      fclose(mPrt->mFilePointer);          } else {      nsIFrame* rootFrame;      poPresShell->GetRootFrame(&rootFrame);#if defined(DEBUG_rods) || defined(DEBUG_dconeX)      {        char * docStr;        char * urlStr;        GetDocTitleAndURL(aPO, docStr, urlStr);        DumpLayoutData(docStr, urlStr, poPresContext, mPrt->mPrintDocDC, rootFrame, webShell);        if (docStr) nsMemory::Free(docStr);        if (urlStr) nsMemory::Free(urlStr);      }#endif      if (printService) {        if (!skipSetTitle) {          PRUnichar * docTitleStr;          PRUnichar * docURLStr;          GetWebShellTitleAndURL(webShell, &docTitleStr, &docURLStr);           if (!docTitleStr) {            docTitleStr = ToNewUnicode(NS_LITERAL_STRING(""));          }          if (docTitleStr) {            printService->SetTitle(docTitleStr);            nsMemory::Free(docTitleStr);          }          if (docURLStr) {            printService->SetDocURL(docURLStr);            nsMemory::Free(docURLStr);          }        }        if (nsIPrintOptions::kRangeSelection == printRangeType) {          poPresContext->SetIsRenderingOnlySelection(PR_TRUE);          // temporarily creating rendering context          // which is needed to dinf the selection frames          nsCOMPtr<nsIRenderingContext> rc;          mPrt->mPrintDocDC->CreateRenderingContext(*getter_AddRefs(rc));          // find the starting and ending page numbers          // via the selection          nsIFrame* startFrame;          nsIFrame* endFrame;          PRInt32   startPageNum;          PRInt32   endPageNum;          nsRect    startRect;          nsRect    endRect;          nsCOMPtr<nsISelection> selectionPS;          nsresult rvv = GetDocumentSelection(getter_AddRefs(selectionPS), poPresShell);          if (NS_SUCCEEDED(rvv) && selectionPS) {          }          rv = GetPageRangeForSelection(poPresShell, poPresContext, *rc, selectionPS, pageSequence,                                         &startFrame, startPageNum, startRect,                                         &endFrame, endPageNum, endRect);          if (NS_SUCCEEDED(rv)) {            printService->SetStartPageRange(startPageNum);            printService->SetEndPageRange(endPageNum);            nsMargin margin(0,0,0,0);            printService->GetMarginInTwips(margin);            if (startPageNum == endPageNum) {              nsIFrame * seqFrame;              if (NS_FAILED(CallQueryInterface(pageSequence, &seqFrame))) {                mIsDoingPrinting = PR_FALSE;                return NS_ERROR_FAILURE;              }              nsRect rect(0,0,0,0);              nsRect areaRect;              nsIFrame * areaFrame = FindFrameByType(poPresContext, startFrame, nsHTMLAtoms::body, rect, areaRect);              if (areaFrame) {                startRect.y -= margin.top;                endRect.y   -= margin.top;                areaRect.y -= startRect.y;                areaRect.x -= margin.left;                // XXX This is temporary fix for printing more than one page of a selection                pageSequence->SetSelectionHeight(startRect.y, endRect.y+endRect.height-startRect.y);              }            }          }        }        nsCOMPtr<nsIPrintPreviewContext> ppContext = do_QueryInterface(poPresContext);        if (!ppContext) {          nsIFrame * seqFrame;          if (NS_FAILED(CallQueryInterface(pageSequence, &seqFrame))) {            mIsDoingPrinting = PR_FALSE;            return NS_ERROR_FAILURE;          }          nsRect srect;          seqFrame->GetRect(srect);          nsRect r;          poRootView->GetBounds(r);          r.x = r.y = 0;          r.height = srect.height;          aPO->mViewManager->ResizeView(poRootView, r, PR_FALSE);          rootFrame->GetRect(r);          r.height = srect.height;          rootFrame->SetRect(poPresContext, r);          mPageSeqFrame = pageSequence;          mPageSeqFrame->StartPrint(poPresContext, printService);          if (!aDoSyncPrinting) {            // Get the delay time in between the printing of each page            // this gives the user more time to press cancel            PRInt32 printPageDelay = 500;            printService->GetPrintPageDelay(&printPageDelay);            // Schedule Page to Print            PRINT_DEBUG_MSG3("Scheduling Print of PO: %p (%s) \n", aPO, gFrameTypesStr[aPO->mFrameType]);            StartPagePrintTimer(poPresContext, printService, aPO, printPageDelay);          } else {            DoProgressForAsIsFrames();            // Print the page synchronously            PRINT_DEBUG_MSG3("Async Print of PO: %p (%s) \n", aPO, gFrameTypesStr[aPO->mFrameType]);            aDonePrinting = PrintPage(poPresContext, printService, aPO);          }        }      } else {        // not sure what to do here!        mIsDoingPrinting = PR_FALSE;        return NS_ERROR_FAILURE;      }    }  } else {    aPO->mDontPrint = PR_TRUE;    aDonePrinting = PR_FALSE;  }  return NS_OK;}