Convert FirefoxPrintService and PDFPrintService into standard classes

Note that both of the affected files are old enough to predate the general availability of `class`.
This commit is contained in:
Jonas Jenwald 2023-04-14 09:51:37 +02:00
parent ebf493f726
commit aeb8e36cdb
2 changed files with 52 additions and 52 deletions

View File

@ -114,7 +114,8 @@ function composePage(
}; };
} }
function FirefoxPrintService( class FirefoxPrintService {
constructor(
pdfDocument, pdfDocument,
pagesOverview, pagesOverview,
printContainer, printContainer,
@ -132,7 +133,6 @@ function FirefoxPrintService(
printAnnotationStoragePromise || Promise.resolve(); printAnnotationStoragePromise || Promise.resolve();
} }
FirefoxPrintService.prototype = {
layout() { layout() {
const { const {
pdfDocument, pdfDocument,
@ -179,7 +179,7 @@ FirefoxPrintService.prototype = {
_printAnnotationStoragePromise _printAnnotationStoragePromise
); );
} }
}, }
destroy() { destroy() {
this.printContainer.textContent = ""; this.printContainer.textContent = "";
@ -191,8 +191,8 @@ FirefoxPrintService.prototype = {
this.pageStyleSheet.remove(); this.pageStyleSheet.remove();
this.pageStyleSheet = null; this.pageStyleSheet = null;
} }
}, }
}; }
PDFPrintServiceFactory.instance = { PDFPrintServiceFactory.instance = {
get supportsPrinting() { get supportsPrinting() {

View File

@ -62,7 +62,8 @@ function renderPage(
}); });
} }
function PDFPrintService( class PDFPrintService {
constructor(
pdfDocument, pdfDocument,
pagesOverview, pagesOverview,
printContainer, printContainer,
@ -85,7 +86,6 @@ function PDFPrintService(
this.scratchCanvas = document.createElement("canvas"); this.scratchCanvas = document.createElement("canvas");
} }
PDFPrintService.prototype = {
layout() { layout() {
this.throwIfInactive(); this.throwIfInactive();
@ -114,7 +114,7 @@ PDFPrintService.prototype = {
this.pageStyleSheet = document.createElement("style"); this.pageStyleSheet = document.createElement("style");
this.pageStyleSheet.textContent = `@page { size: ${width}pt ${height}pt;}`; this.pageStyleSheet.textContent = `@page { size: ${width}pt ${height}pt;}`;
body.append(this.pageStyleSheet); body.append(this.pageStyleSheet);
}, }
destroy() { destroy() {
if (activeService !== this) { if (activeService !== this) {
@ -139,7 +139,7 @@ PDFPrintService.prototype = {
overlayManager.close(dialog); overlayManager.close(dialog);
} }
}); });
}, }
renderPages() { renderPages() {
if (this.pdfDocument.isPureXfa) { if (this.pdfDocument.isPureXfa) {
@ -172,7 +172,7 @@ PDFPrintService.prototype = {
}, reject); }, reject);
}; };
return new Promise(renderNextPage); return new Promise(renderNextPage);
}, }
useRenderedPage() { useRenderedPage() {
this.throwIfInactive(); this.throwIfInactive();
@ -195,7 +195,7 @@ PDFPrintService.prototype = {
img.onload = resolve; img.onload = resolve;
img.onerror = reject; img.onerror = reject;
}); });
}, }
performPrint() { performPrint() {
this.throwIfInactive(); this.throwIfInactive();
@ -213,18 +213,18 @@ PDFPrintService.prototype = {
setTimeout(resolve, 20); // Tidy-up. setTimeout(resolve, 20); // Tidy-up.
}, 0); }, 0);
}); });
}, }
get active() { get active() {
return this === activeService; return this === activeService;
}, }
throwIfInactive() { throwIfInactive() {
if (!this.active) { if (!this.active) {
throw new Error("This print request was cancelled or completed."); throw new Error("This print request was cancelled or completed.");
} }
}, }
}; }
const print = window.print; const print = window.print;
window.print = function () { window.print = function () {