Skip to content

Commit

Permalink
Merge pull request mozilla#17667 from Snuffleupagus/createPrintServic…
Browse files Browse the repository at this point in the history
…e-params

Change `PDFPrintServiceFactory.createPrintService` to take a parameter object
  • Loading branch information
timvandermeij authored Feb 17, 2024
2 parents 179a3ec + a204f43 commit fd5d040
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 55 deletions.
25 changes: 9 additions & 16 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1781,26 +1781,19 @@ const PDFViewerApplication = {
return;
}

const pagesOverview = this.pdfViewer.getPagesOverview();
const printContainer = this.appConfig.printContainer;
const printResolution = AppOptions.get("printResolution");
const optionalContentConfigPromise =
this.pdfViewer.optionalContentConfigPromise;

const printService = PDFPrintServiceFactory.createPrintService(
this.pdfDocument,
pagesOverview,
printContainer,
printResolution,
optionalContentConfigPromise,
this._printAnnotationStoragePromise
);
this.printService = printService;
this.printService = PDFPrintServiceFactory.createPrintService({
pdfDocument: this.pdfDocument,
pagesOverview: this.pdfViewer.getPagesOverview(),
printContainer: this.appConfig.printContainer,
printResolution: AppOptions.get("printResolution"),
optionalContentConfigPromise: this.pdfViewer.optionalContentConfigPromise,
printAnnotationStoragePromise: this._printAnnotationStoragePromise,
});
this.forceRendering();
// Disable the editor-indicator during printing (fixes bug 1790552).
this.setTitle();

printService.layout();
this.printService.layout();

if (this._hasAnnotationEditors) {
this.externalServices.reportTelemetry({
Expand Down
24 changes: 5 additions & 19 deletions web/firefox_print_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ function composePage(
}

class FirefoxPrintService {
constructor(
constructor({
pdfDocument,
pagesOverview,
printContainer,
printResolution,
optionalContentConfigPromise = null,
printAnnotationStoragePromise = null
) {
printAnnotationStoragePromise = null,
}) {
this.pdfDocument = pdfDocument;
this.pagesOverview = pagesOverview;
this.printContainer = printContainer;
Expand Down Expand Up @@ -202,22 +202,8 @@ class PDFPrintServiceFactory {
return shadow(this, "supportsPrinting", "mozPrintCallback" in canvas);
}

static createPrintService(
pdfDocument,
pagesOverview,
printContainer,
printResolution,
optionalContentConfigPromise,
printAnnotationStoragePromise
) {
return new FirefoxPrintService(
pdfDocument,
pagesOverview,
printContainer,
printResolution,
optionalContentConfigPromise,
printAnnotationStoragePromise
);
static createPrintService(params) {
return new FirefoxPrintService(params);
}
}

Expand Down
25 changes: 5 additions & 20 deletions web/pdf_print_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ function renderPage(
}

class PDFPrintService {
constructor(
constructor({
pdfDocument,
pagesOverview,
printContainer,
printResolution,
optionalContentConfigPromise = null,
printAnnotationStoragePromise = null
) {
printAnnotationStoragePromise = null,
}) {
this.pdfDocument = pdfDocument;
this.pagesOverview = pagesOverview;
this.printContainer = printContainer;
Expand Down Expand Up @@ -367,26 +367,11 @@ class PDFPrintServiceFactory {
return shadow(this, "supportsPrinting", true);
}

static createPrintService(
pdfDocument,
pagesOverview,
printContainer,
printResolution,
optionalContentConfigPromise,
printAnnotationStoragePromise
) {
static createPrintService(params) {
if (activeService) {
throw new Error("The print service is created and active.");
}
activeService = new PDFPrintService(
pdfDocument,
pagesOverview,
printContainer,
printResolution,
optionalContentConfigPromise,
printAnnotationStoragePromise
);
return activeService;
return (activeService = new PDFPrintService(params));
}
}

Expand Down

0 comments on commit fd5d040

Please sign in to comment.