From d32906adc4424672493fe019fafa5bd9f15d51e5 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Thu, 12 Jul 2012 10:31:20 -0700 Subject: [PATCH] Add back basic printing support for non-moz browsers. Shadow/cache supports browsing. Destroy pages on error and only abort if supported. --- l10n/en-US/viewer.properties | 2 +- web/viewer.css | 30 +++++++++++++++++++++++++++--- web/viewer.js | 18 +++++++++++++++--- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/l10n/en-US/viewer.properties b/l10n/en-US/viewer.properties index ce268a113..1c4dd1cde 100644 --- a/l10n/en-US/viewer.properties +++ b/l10n/en-US/viewer.properties @@ -88,4 +88,4 @@ loading_error=An error occurred while loading the PDF. text_annotation_type=[{{type}} Annotation] request_password=PDF is protected by a password: -printing_not_supported=Warning: Printing is not supported by this browser. +printing_not_supported=Warning: Printing is not fully supported by this browser. diff --git a/web/viewer.css b/web/viewer.css index b57af0591..80a8c5a40 100644 --- a/web/viewer.css +++ b/web/viewer.css @@ -1122,13 +1122,37 @@ canvas { } @media print { - #outerContainer { + /* Rules for browsers that don't support mozPrintCallback. */ + #sidebarContainer, .toolbar, #loadingBox, #errorWrapper, .textLayer { display: none; } - #printContainer { + + #mainContainer, #viewerContainer, .page, .page canvas { + position: static; + padding: 0; + margin: 0; + } + + .page { + float: left; + display: none; + -webkit-box-shadow: none; + -moz-box-shadow: none; + box-shadow: none; + } + + .page[data-loaded] { display: block; } - canvas { + + /* Rules for browsers that support mozPrintCallback */ + body[data-mozPrintCallback] #outerContainer { + display: none; + } + body[data-mozPrintCallback] #printContainer { + display: block; + } + #printContainer canvas { position: relative; top: 0; left: 0; diff --git a/web/viewer.js b/web/viewer.js index 377a4fc7e..f75701816 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -381,7 +381,13 @@ var PDFView = { get supportsPrinting() { var canvas = document.createElement('canvas'); - return 'mozPrintCallback' in canvas; + var value = 'mozPrintCallback' in canvas; + // shadow + Object.defineProperty(this, 'supportsPrinting', { value: value, + enumerable: true, + configurable: true, + writable: false }); + return value; }, open: function pdfViewOpen(url, scale, password) { @@ -1051,10 +1057,12 @@ var PDFView = { beforePrint: function pdfViewSetupBeforePrint() { if (!this.supportsPrinting) { var printMessage = mozL10n.get('printing_not_supported', null, - 'Warning: Printing is not supported by this browser.'); + 'Warning: Printing is not fully supported by this browser.'); alert(printMessage); return; } + var body = document.querySelector('body'); + body.setAttribute('data-mozPrintCallback', true); for (var i = 0, ii = this.pages.length; i < ii; ++i) { this.pages[i].beforePrint(); } @@ -1412,7 +1420,11 @@ var PageView = function pageView(container, pdfPage, id, scale, console.error(error); // Tell the printEngine that rendering this canvas/page has failed. // This will make the print proces stop. - obj.abort(); + if ('abort' in object) + obj.abort(); + else + obj.done(); + self.pdfPage.destroy(); }); }; };