Add back basic printing support for non-moz browsers.

Shadow/cache supports browsing.
Destroy pages on error and only abort if supported.
This commit is contained in:
Brendan Dahl 2012-07-12 10:31:20 -07:00
parent 4655ec0c75
commit d32906adc4
3 changed files with 43 additions and 7 deletions

View File

@ -88,4 +88,4 @@ loading_error=An error occurred while loading the PDF.
text_annotation_type=[{{type}} Annotation] text_annotation_type=[{{type}} Annotation]
request_password=PDF is protected by a password: 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.

View File

@ -1122,13 +1122,37 @@ canvas {
} }
@media print { @media print {
#outerContainer { /* Rules for browsers that don't support mozPrintCallback. */
#sidebarContainer, .toolbar, #loadingBox, #errorWrapper, .textLayer {
display: none; 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; 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; position: relative;
top: 0; top: 0;
left: 0; left: 0;

View File

@ -381,7 +381,13 @@ var PDFView = {
get supportsPrinting() { get supportsPrinting() {
var canvas = document.createElement('canvas'); 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) { open: function pdfViewOpen(url, scale, password) {
@ -1051,10 +1057,12 @@ var PDFView = {
beforePrint: function pdfViewSetupBeforePrint() { beforePrint: function pdfViewSetupBeforePrint() {
if (!this.supportsPrinting) { if (!this.supportsPrinting) {
var printMessage = mozL10n.get('printing_not_supported', null, 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); alert(printMessage);
return; return;
} }
var body = document.querySelector('body');
body.setAttribute('data-mozPrintCallback', true);
for (var i = 0, ii = this.pages.length; i < ii; ++i) { for (var i = 0, ii = this.pages.length; i < ii; ++i) {
this.pages[i].beforePrint(); this.pages[i].beforePrint();
} }
@ -1412,7 +1420,11 @@ var PageView = function pageView(container, pdfPage, id, scale,
console.error(error); console.error(error);
// Tell the printEngine that rendering this canvas/page has failed. // Tell the printEngine that rendering this canvas/page has failed.
// This will make the print proces stop. // This will make the print proces stop.
obj.abort(); if ('abort' in object)
obj.abort();
else
obj.done();
self.pdfPage.destroy();
}); });
}; };
}; };