Bug 1399787 - Part 11.b. Use PrintTargetEMF to print chrome documents. draft
authorcku <cku@mozilla.com>
Mon, 13 Nov 2017 15:29:32 +0800
changeset 710608 f4fa7e4d01d6764a7a6db897c76fd26736779f94
parent 710607 a5b102aafbc368f7550338d51ce1848ada4cb299
child 710609 4c5759e18b3f28f49e4298c0831b84a6def382e6
push id92855
push usercku@mozilla.com
push dateMon, 11 Dec 2017 02:44:26 +0000
bugs1399787
milestone59.0a1
Bug 1399787 - Part 11.b. Use PrintTargetEMF to print chrome documents. MozReview-Commit-ID: 9BjQ8PIZAWL
layout/printing/nsPrintEngine.cpp
layout/printing/nsPrintEngine.h
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -675,16 +675,21 @@ nsPrintEngine::DoCommonPrint(bool       
 
   rv = devspec->Init(nullptr, printData->mPrintSettings, aIsPrintPreview);
   NS_ENSURE_SUCCESS(rv, rv);
 
   printData->mPrintDC = new nsDeviceContext();
   rv = printData->mPrintDC->InitForPrinting(devspec);
   NS_ENSURE_SUCCESS(rv, rv);
 
+  if (XRE_IsParentProcess() && !printData->mPrintDC->IsSyncPagePrinting()) {
+    RefPtr<nsPrintEngine> self(this);
+    printData->mPrintDC->RegisterPageDoneCallback([self](nsresult aResult) { self->PageDone(aResult); });
+  }
+
   if (aIsPrintPreview) {
     printData->mPrintSettings->SetPrintFrameType(nsIPrintSettings::kFramesAsIs);
 
     // override any UI that wants to PrintPreview any selection or page range
     // we want to view every page in PrintPreview each time
     printData->mPrintSettings->SetPrintRange(nsIPrintSettings::kRangeAllPages);
   } else {
     // Always check and set the print settings first and then fall back
@@ -2834,16 +2839,20 @@ nsPrintEngine::PrintPage(nsPrintObject* 
   printData->DoOnProgressChange(++printData->mNumPagesPrinted,
                                 endPage, false, 0);
   if (NS_WARN_IF(mPrt != printData)) {
     // If current printing is canceled or new print is started, let's return
     // true to notify the caller of current printing is done.
     return true;
   }
 
+  if (XRE_IsParentProcess() && !printData->mPrintDC->IsSyncPagePrinting()) {
+    mPagePrintTimer->WaitForRemotePrint();
+  }
+
   // Print the Page
   // if a print job was cancelled externally, an EndPage or BeginPage may
   // fail and the failure is passed back here.
   // Returning true means we are done printing.
   //
   // When rv == NS_ERROR_ABORT, it means we want out of the
   // print job without displaying any error messages
   nsresult rv = pageSeqFrame->PrintNextPage();
@@ -2855,17 +2864,16 @@ nsPrintEngine::PrintPage(nsPrintObject* 
     return true;
   }
 
   pageSeqFrame->DoPageEnd();
 
   return donePrinting;
 }
 
-
 //-----------------------------------------------------------------
 //-- Done: Printing Methods
 //-----------------------------------------------------------------
 
 
 //-----------------------------------------------------------------
 //-- Section: Misc Support Methods
 //-----------------------------------------------------------------
@@ -3012,16 +3020,18 @@ nsPrintEngine::DonePrintingPages(nsPrint
     nsresult rv;
     bool didPrint = PrintDocContent(printData->mPrintObject, rv);
     if (NS_SUCCEEDED(rv) && didPrint) {
       PR_PL(("****** In DV::DonePrintingPages PO: %p (%s) didPrint:%s (Not Done Printing)\n", aPO, gFrameTypesStr[aPO->mFrameType], PRT_YESNO(didPrint)));
       return false;
     }
   }
 
+  printData->mPrintDC->UnregisterPageDoneCallback();
+
   if (NS_SUCCEEDED(aResult)) {
     FirePrintCompletionEvent();
     // XXX mPrt may be cleared or replaced with new instance here.
     //     However, the following methods will clean up with new mPrt or will
     //     do nothing due to no proper nsPrintData instance.
   }
 
   TurnScriptingOn(true);
--- a/layout/printing/nsPrintEngine.h
+++ b/layout/printing/nsPrintEngine.h
@@ -274,11 +274,12 @@ protected:
   void UpdateZoomRatio(nsPrintObject* aPO, bool aSetPixelScale);
   nsresult ReconstructAndReflow(bool aDoSetPixelScale);
   nsresult UpdateSelectionAndShrinkPrintObject(nsPrintObject* aPO,
                                                bool aDocumentIsTopLevel);
   nsresult InitPrintDocConstruction(bool aHandleError);
   void FirePrintPreviewUpdateEvent();
 private:
   nsPrintEngine& operator=(const nsPrintEngine& aOther) = delete;
+  void PageDone(nsresult aResult);
 };
 
 #endif /* nsPrintEngine_h___ */