Bug 897554 - Update pdf.js to version 0.8.377. r=bdahl

This commit is contained in:
Ryan VanderMeulen 2013-07-24 17:48:29 -04:00
parent a692880c23
commit 66dc5c6e4b
6 changed files with 824 additions and 881 deletions

View File

@ -1,4 +1,4 @@
This is the pdf.js project output, https://github.com/mozilla/pdf.js
Current extension version is: 0.8.291
Current extension version is: 0.8.377

View File

@ -206,6 +206,10 @@ ChromeActions.prototype = {
// The data may not be downloaded so we need just retry getting the pdf with
// the original url.
var originalUri = NetUtil.newURI(data.originalUrl);
var filename = data.filename;
if (typeof filename !== 'string' || !/\.pdf$/i.test(filename)) {
filename = 'document.pdf';
}
var blobUri = data.blobUrl ? NetUtil.newURI(data.blobUrl) : originalUri;
var extHelperAppSvc =
Cc['@mozilla.org/uriloader/external-helper-app-service;1'].
@ -234,7 +238,9 @@ ChromeActions.prototype = {
// contentDisposition/contentDispositionFilename is readonly before FF18
channel.contentDisposition = Ci.nsIChannel.DISPOSITION_ATTACHMENT;
if (self.contentDispositionFilename) {
channel.contentDispositionFilename = self.contentDispositionFilename;
channel.contentDispositionFilename = self.contentDispositionFilename;
} else {
channel.contentDispositionFilename = filename;
}
} catch (e) {}
channel.setURI(originalUri);

File diff suppressed because it is too large Load Diff

View File

@ -42,17 +42,6 @@ select {
display: none !important;
}
#viewerContainer:-webkit-full-screen {
top: 0px;
border-top: 2px solid transparent;
background-color: #404040;
background-image: url(images/texture.png);
width: 100%;
height: 100%;
overflow: hidden;
cursor: none;
}
#viewerContainer:-moz-full-screen {
top: 0px;
border-top: 2px solid transparent;
@ -76,10 +65,6 @@ select {
}
:-webkit-full-screen .page {
margin-bottom: 100%;
}
:-moz-full-screen .page {
margin-bottom: 100%;
}
@ -88,10 +73,6 @@ select {
margin-bottom: 100%;
}
:-webkit-full-screen a:not(.internalLink) {
display: none;
}
:-moz-full-screen a:not(.internalLink) {
display: none;
}
@ -137,30 +118,15 @@ html[dir='rtl'] .innerCenter {
bottom: 0;
width: 200px;
visibility: hidden;
-webkit-transition-duration: 200ms;
-webkit-transition-timing-function: ease;
-moz-transition-duration: 200ms;
-moz-transition-timing-function: ease;
-ms-transition-duration: 200ms;
-ms-transition-timing-function: ease;
-o-transition-duration: 200ms;
-o-transition-timing-function: ease;
transition-duration: 200ms;
transition-timing-function: ease;
}
html[dir='ltr'] #sidebarContainer {
-webkit-transition-property: left;
-moz-transition-property: left;
-ms-transition-property: left;
-o-transition-property: left;
transition-property: left;
left: -200px;
}
html[dir='rtl'] #sidebarContainer {
-webkit-transition-property: right;
-ms-transition-property: right;
-o-transition-property: right;
transition-property: right;
right: -200px;
}
@ -183,30 +149,14 @@ html[dir='rtl'] #outerContainer.sidebarOpen > #sidebarContainer {
bottom: 0;
left: 0;
min-width: 320px;
-webkit-transition-duration: 200ms;
-webkit-transition-timing-function: ease;
-moz-transition-duration: 200ms;
-moz-transition-timing-function: ease;
-ms-transition-duration: 200ms;
-ms-transition-timing-function: ease;
-o-transition-duration: 200ms;
-o-transition-timing-function: ease;
transition-duration: 200ms;
transition-timing-function: ease;
}
html[dir='ltr'] #outerContainer.sidebarOpen > #mainContainer {
-webkit-transition-property: left;
-moz-transition-property: left;
-ms-transition-property: left;
-o-transition-property: left;
transition-property: left;
left: 200px;
}
html[dir='rtl'] #outerContainer.sidebarOpen > #mainContainer {
-webkit-transition-property: right;
-moz-transition-property: right;
-ms-transition-property: right;
-o-transition-property: right;
transition-property: right;
right: 200px;
}
@ -236,9 +186,7 @@ html[dir='rtl'] #sidebarContent {
right: 0;
bottom: 0;
left: 0;
}
.loadingInProgress #viewerContainer {
top: 39px;
outline: none;
}
.toolbar {
@ -299,30 +247,9 @@ html[dir='rtl'] #sidebarContent {
height: 100%;
background-color: #ddd;
overflow: hidden;
-moz-transition: width 200ms;
-ms-transition: width 200ms;
-webkit-transition: width 200ms;
transition: width 200ms;
}
@-moz-keyframes progressIndeterminate {
0% { left: 0%; }
50% { left: 100%; }
100% { left: 100%; }
}
@-ms-keyframes progressIndeterminate {
0% { left: 0%; }
50% { left: 100%; }
100% { left: 100%; }
}
@-webkit-keyframes progressIndeterminate {
0% { left: 0%; }
50% { left: 100%; }
100% { left: 100%; }
}
@keyframes progressIndeterminate {
0% { left: 0%; }
50% { left: 100%; }
@ -331,9 +258,6 @@ html[dir='rtl'] #sidebarContent {
#loadingBar .progress.indeterminate {
background-color: #999;
-moz-transition: none;
-ms-transition: none;
-webkit-transition: none;
transition: none;
}
@ -345,11 +269,9 @@ html[dir='rtl'] #sidebarContent {
width: 50px;
background-image: linear-gradient(to right, #999 0%, #fff 50%, #999 100%);
background-size: 100% 100% no-repeat;
background-size: 100% 100%;
background-repeat: no-repeat;
-moz-animation: progressIndeterminate 2s linear infinite;
-ms-animation: progressIndeterminate 2s linear infinite;
-webkit-animation: progressIndeterminate 2s linear infinite;
animation: progressIndeterminate 2s linear infinite;
}
@ -378,7 +300,6 @@ html[dir='rtl'] .findbar {
}
.findbar label {
-webkit-user-select: none;
-moz-user-select: none;
}
@ -530,18 +451,6 @@ html[dir='rtl'] .splitToolbarButton > .toolbarButton {
box-shadow: 0 1px 0 hsla(0,0%,100%,.05) inset,
0 0 1px hsla(0,0%,100%,.15) inset,
0 1px 0 hsla(0,0%,100%,.05);
-webkit-transition-property: background-color, border-color, box-shadow;
-webkit-transition-duration: 150ms;
-webkit-transition-timing-function: ease;
-moz-transition-property: background-color, border-color, box-shadow;
-moz-transition-duration: 150ms;
-moz-transition-timing-function: ease;
-ms-transition-property: background-color, border-color, box-shadow;
-ms-transition-duration: 150ms;
-ms-transition-timing-function: ease;
-o-transition-property: background-color, border-color, box-shadow;
-o-transition-duration: 150ms;
-o-transition-timing-function: ease;
transition-property: background-color, border-color, box-shadow;
transition-duration: 150ms;
transition-timing-function: ease;
@ -596,18 +505,6 @@ html[dir='rtl'] .splitToolbarButtonSeparator {
padding: 12px 0;
margin: 1px 0;
box-shadow: 0 0 0 1px hsla(0,0%,100%,.03);
-webkit-transition-property: padding;
-webkit-transition-duration: 10ms;
-webkit-transition-timing-function: ease;
-moz-transition-property: padding;
-moz-transition-duration: 10ms;
-moz-transition-timing-function: ease;
-ms-transition-property: padding;
-ms-transition-duration: 10ms;
-ms-transition-timing-function: ease;
-o-transition-property: padding;
-o-transition-duration: 10ms;
-o-transition-timing-function: ease;
transition-property: padding;
transition-duration: 10ms;
transition-timing-function: ease;
@ -622,23 +519,9 @@ html[dir='rtl'] .splitToolbarButtonSeparator {
color: hsl(0,0%,95%);
font-size: 12px;
line-height: 14px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
/* Opera does not support user-select, use <... unselectable="on"> instead */
cursor: default;
-webkit-transition-property: background-color, border-color, box-shadow;
-webkit-transition-duration: 150ms;
-webkit-transition-timing-function: ease;
-moz-transition-property: background-color, border-color, box-shadow;
-moz-transition-duration: 150ms;
-moz-transition-timing-function: ease;
-ms-transition-property: background-color, border-color, box-shadow;
-ms-transition-duration: 150ms;
-ms-transition-timing-function: ease;
-o-transition-property: background-color, border-color, box-shadow;
-o-transition-duration: 150ms;
-o-transition-timing-function: ease;
transition-property: background-color, border-color, box-shadow;
transition-duration: 150ms;
transition-timing-function: ease;
@ -674,18 +557,6 @@ html[dir='rtl'] .dropdownToolbarButton {
box-shadow: 0 1px 1px hsla(0,0%,0%,.1) inset,
0 0 1px hsla(0,0%,0%,.2) inset,
0 1px 0 hsla(0,0%,100%,.05);
-webkit-transition-property: background-color, border-color, box-shadow;
-webkit-transition-duration: 10ms;
-webkit-transition-timing-function: linear;
-moz-transition-property: background-color, border-color, box-shadow;
-moz-transition-duration: 10ms;
-moz-transition-timing-function: linear;
-ms-transition-property: background-color, border-color, box-shadow;
-ms-transition-duration: 10ms;
-ms-transition-timing-function: linear;
-o-transition-property: background-color, border-color, box-shadow;
-o-transition-duration: 10ms;
-o-transition-timing-function: linear;
transition-property: background-color, border-color, box-shadow;
transition-duration: 10ms;
transition-timing-function: linear;
@ -699,18 +570,6 @@ html[dir='rtl'] .dropdownToolbarButton {
box-shadow: 0 1px 1px hsla(0,0%,0%,.1) inset,
0 0 1px hsla(0,0%,0%,.2) inset,
0 1px 0 hsla(0,0%,100%,.05);
-webkit-transition-property: background-color, border-color, box-shadow;
-webkit-transition-duration: 10ms;
-webkit-transition-timing-function: linear;
-moz-transition-property: background-color, border-color, box-shadow;
-moz-transition-duration: 10ms;
-moz-transition-timing-function: linear;
-ms-transition-property: background-color, border-color, box-shadow;
-ms-transition-duration: 10ms;
-ms-transition-timing-function: linear;
-o-transition-property: background-color, border-color, box-shadow;
-o-transition-duration: 10ms;
-o-transition-timing-function: linear;
transition-property: background-color, border-color, box-shadow;
transition-duration: 10ms;
transition-timing-function: linear;
@ -740,7 +599,6 @@ html[dir='rtl'] .dropdownToolbarButton {
}
.dropdownToolbarButton > select {
-webkit-appearance: none;
-moz-appearance: none; /* in the future this might matter, see bugzilla bug #649849 */
min-width: 140px;
font-size: 12px;
@ -783,7 +641,6 @@ html[dir='rtl'] .toolbarButton:first-child {
}
.toolbarButtonFlexibleSpacer {
-webkit-box-flex: 1;
-moz-box-flex: 1;
min-width: 30px;
}
@ -887,7 +744,6 @@ html[dir='rtl'] .toolbarButton.pageDown::before {
}
.toolbarButton.bookmark {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin-top: 3px;
@ -935,9 +791,9 @@ html[dir='rtl'] .toolbarButton.pageDown::before {
font-size: 12px;
line-height: 14px;
outline-style: none;
-moz-transition-property: background-color, border-color, box-shadow;
-moz-transition-duration: 150ms;
-moz-transition-timing-function: ease;
transition-property: background-color, border-color, box-shadow;
transition-duration: 150ms;
transition-timing-function: ease;
}
.toolbarField[type=checkbox] {
@ -951,12 +807,6 @@ html[dir='rtl'] .toolbarButton.pageDown::before {
width: 40px;
}
.toolbarField.pageNumber::-webkit-inner-spin-button,
.toolbarField.pageNumber::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
.toolbarField:hover {
background-color: hsla(0,0%,100%,.11);
border-color: hsla(0,0%,0%,.4) hsla(0,0%,0%,.43) hsla(0,0%,0%,.45);
@ -977,7 +827,6 @@ html[dir='rtl'] .toolbarButton.pageDown::before {
font-size: 12px;
line-height: 14px;
text-align: left;
-webkit-user-select: none;
-moz-user-select: none;
cursor: default;
}
@ -1001,7 +850,7 @@ html[dir='rtl'] .toolbarButton.pageDown::before {
}
.thumbnailImage {
-moz-transition-duration: 150ms;
transition-duration: 150ms;
border: 1px solid transparent;
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
opacity: 0.8;
@ -1011,7 +860,7 @@ html[dir='rtl'] .toolbarButton.pageDown::before {
.thumbnailSelectionRing {
border-radius: 2px;
padding: 7px;
-moz-transition-duration: 150ms;
transition-duration: 150ms;
}
a:focus > .thumbnail > .thumbnailSelectionRing > .thumbnailImage,
@ -1052,7 +901,6 @@ a:focus > .thumbnail > .thumbnailSelectionRing,
bottom: 0;
padding: 4px 4px 0;
overflow: auto;
-webkit-user-select: none;
-moz-user-select: none;
}
@ -1361,6 +1209,9 @@ canvas {
#sidebarContainer, .toolbar, #loadingBox, #errorWrapper, .textLayer {
display: none;
}
#viewerContainer {
overflow: visible;
}
#mainContainer, #viewerContainer, .page, .page canvas {
position: static;
@ -1371,6 +1222,7 @@ canvas {
.page {
float: left;
display: none;
border: none;
box-shadow: none;
}

View File

@ -174,22 +174,22 @@ limitations under the License.
data-l10n-id="page_rotate_cw" ></menuitem>
</menu>
<div id="viewerContainer">
<div id="viewerContainer">
<div id="viewer" contextmenu="viewerContextMenu"></div>
</div>
<div id="errorWrapper" hidden='true'>
<div id="errorMessageLeft">
<span id="errorMessage"></span>
<button id="errorShowMore" onclick="" oncontextmenu="return false;" data-l10n-id="error_more_info">
<button id="errorShowMore" data-l10n-id="error_more_info">
More Information
</button>
<button id="errorShowLess" onclick="" oncontextmenu="return false;" data-l10n-id="error_less_info" hidden='true'>
<button id="errorShowLess" data-l10n-id="error_less_info" hidden='true'>
Less Information
</button>
</div>
<div id="errorMessageRight">
<button id="errorClose" oncontextmenu="return false;" data-l10n-id="error_close">
<button id="errorClose" data-l10n-id="error_close">
Close
</button>
</div>

View File

@ -14,9 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals PDFJS, PDFBug, FirefoxCom, Stats, Cache, PDFFindBar */
/* globals PDFFindController, ProgressBar, getFileName, CustomStyle */
/* globals getOutputScale, TextLayerBuilder */
/* globals PDFJS, PDFBug, FirefoxCom, Stats, Cache, PDFFindBar, CustomStyle,
PDFFindController, ProgressBar, TextLayerBuilder, DownloadManager,
getFileName, getOutputScale, scrollIntoView, getPDFFileNameFromURL,
PDFHistory */
'use strict';
@ -46,6 +47,7 @@ var FindStates = {
FIND_PENDING: 3
};
PDFJS.imageResourcesPath = './images/';
PDFJS.workerSrc = '../build/pdf.js';
var mozL10n = document.mozL10n || document.webL10n;
@ -126,6 +128,61 @@ function getOutputScale() {
};
}
/**
* Scrolls specified element into view of its parent.
* element {Object} The element to be visible.
* spot {Object} The object with the top property -- offset from the top edge.
*/
function scrollIntoView(element, spot) {
// Assuming offsetParent is available (it's not available when viewer is in
// hidden iframe or object). We have to scroll: if the offsetParent is not set
// producing the error. See also animationStartedClosure.
var parent = element.offsetParent;
var offsetY = element.offsetTop + element.clientTop;
if (!parent) {
console.error('offsetParent is not set -- cannot scroll');
return;
}
while (parent.clientHeight == parent.scrollHeight) {
offsetY += parent.offsetTop;
parent = parent.offsetParent;
if (!parent)
return; // no need to scroll
}
if (spot)
offsetY += spot.top;
parent.scrollTop = offsetY;
}
/**
* Returns the filename or guessed filename from the url (see issue 3455).
* url {String} The original PDF location.
* @return {String} Guessed PDF file name.
*/
function getPDFFileNameFromURL(url) {
var reURI = /^(?:([^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
// SCHEME HOST 1.PATH 2.QUERY 3.REF
// Pattern to get last matching NAME.pdf
var reFilename = /[^\/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
var splitURI = reURI.exec(url);
var suggestedFilename = reFilename.exec(splitURI[1]) ||
reFilename.exec(splitURI[2]) ||
reFilename.exec(splitURI[3]);
if (suggestedFilename) {
suggestedFilename = suggestedFilename[0];
if (suggestedFilename.indexOf('%') != -1) {
// URL-encoded %2Fpath%2Fto%2Ffile.pdf should be file.pdf
try {
suggestedFilename =
reFilename.exec(decodeURIComponent(suggestedFilename))[0];
} catch(e) { // Possible (extremely rare) errors:
// URIError "Malformed URI", e.g. for "%AA.pdf"
// TypeError "null has no properties", e.g. for "%2F.pdf"
}
}
}
return suggestedFilename || 'document.pdf';
}
var ProgressBar = (function ProgressBarClosure() {
@ -135,15 +192,18 @@ var ProgressBar = (function ProgressBarClosure() {
function ProgressBar(id, opts) {
// Fetch the sub-elements for later
// Fetch the sub-elements for later.
this.div = document.querySelector(id + ' .progress');
// Get options, with sensible defaults
// Get the loading bar element, so it can be resized to fit the viewer.
this.bar = this.div.parentNode;
// Get options, with sensible defaults.
this.height = opts.height || 100;
this.width = opts.width || 100;
this.units = opts.units || '%';
// Initialize heights
// Initialize heights.
this.div.style.height = this.height + this.units;
this.percent = 0;
}
@ -170,6 +230,22 @@ var ProgressBar = (function ProgressBarClosure() {
this._indeterminate = isNaN(val);
this._percent = clamp(val, 0, 100);
this.updateBar();
},
setWidth: function ProgressBar_setWidth(viewer) {
if (viewer) {
var container = viewer.parentNode;
var scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
if (scrollbarWidth > 0) {
this.bar.setAttribute('style', 'width: calc(100% - ' +
scrollbarWidth + 'px);');
}
}
},
hide: function ProgressBar_hide() {
this.bar.classList.add('hidden');
this.bar.removeAttribute('style');
}
};
@ -190,46 +266,8 @@ var Cache = function cacheCache(size) {
function scrollIntoView(element, spot) {
// Assuming offsetParent is available (it's not available when viewer is in
// hidden iframe or object). We have to scroll: if the offsetParent is not set
// producing the error. See also animationStartedClosure.
var parent = element.offsetParent;
var offsetY = element.offsetTop + element.clientTop;
if (!parent) {
console.error('offsetParent is not set -- cannot scroll');
return;
}
while (parent.clientHeight == parent.scrollHeight) {
offsetY += parent.offsetTop;
parent = parent.offsetParent;
if (!parent)
return; // no need to scroll
}
if (spot)
offsetY += spot.top;
parent.scrollTop = offsetY;
}
/* Copyright 2012 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var FirefoxCom = (function FirefoxComClosure() {
'use strict';
return {
/**
* Creates an event that the extension is listening for and will
@ -284,6 +322,38 @@ var FirefoxCom = (function FirefoxComClosure() {
};
})();
var DownloadManager = (function DownloadManagerClosure() {
function DownloadManager() {}
DownloadManager.prototype = {
downloadUrl: function DownloadManager_downloadUrl(url, filename) {
FirefoxCom.request('download', {
originalUrl: url,
filename: filename
});
},
download: function DownloadManager_download(blob, url, filename) {
var blobUrl = window.URL.createObjectURL(blob);
FirefoxCom.request('download', {
blobUrl: blobUrl,
originalUrl: url,
filename: filename
},
function response(err) {
if (err && this.onerror) {
this.onerror(err);
}
window.URL.revokeObjectURL(blobUrl);
}.bind(this)
);
}
};
return DownloadManager;
})();
// Settings Manager - This is a utility for saving settings
// First we see if localStorage is available
@ -874,7 +944,7 @@ var PDFHistory = {
var state = window.history.state;
if (this._isStateObjectDefined(state)) {
// This case corresponds to navigating back to the document
// This corresponds to navigating back to the document
// from another page in the browser history.
if (state.target.dest) {
this.initialDestination = state.target.dest;
@ -885,7 +955,7 @@ var PDFHistory = {
this.uid = state.uid + 1;
this.current = state.target;
} else {
// This case corresponds to the loading of a new document.
// This corresponds to the loading of a new document.
if (state && state.fingerprint &&
this.fingerprint !== state.fingerprint) {
// Reinitialize the browsing history when a new document
@ -909,10 +979,14 @@ var PDFHistory = {
} else {
// Handle the user modifying the hash of a loaded document.
self.previousHash = window.location.hash.substring(1);
// If the history is empty when the hash changes,
// update the previous entry in the browser history.
if (self.uid === 0) {
var previousParams = (self.previousHash && self.currentBookmark &&
self.previousHash !== self.currentBookmark) ?
{ hash: self.currentBookmark } : { page: 1 };
{ hash: self.currentBookmark, page: self.currentPage } :
{ page: 1 };
self.historyUnlocked = false;
self.allowHashChange = false;
window.history.back();
@ -921,23 +995,29 @@ var PDFHistory = {
self.historyUnlocked = true;
}
self._pushToHistory({ hash: self.previousHash }, false, true);
if (self.currentBookmark) {
self.previousBookmark = self.currentBookmark;
}
self._updatePreviousBookmark();
}
}, false);
window.addEventListener('beforeunload',
function pdfHistoryBeforeunload(evt) {
function pdfHistoryBeforeUnload() {
var previousParams = self._getPreviousParams(null, true);
if (previousParams) {
self._pushToHistory(previousParams, false);
}
if (PDFView.isPresentationMode) {
// Prevent the user from accidentally navigating away from
// the document when presentation mode is active.
evt.preventDefault();
var replacePrevious = (!self.current.dest &&
self.current.hash !== self.previousHash);
self._pushToHistory(previousParams, false, replacePrevious);
self._updatePreviousBookmark();
}
// Remove the event listener when navigating away from the document,
// since 'beforeunload' prevents Firefox from caching the document.
window.removeEventListener('beforeunload', pdfHistoryBeforeUnload, false);
}
window.addEventListener('beforeunload', pdfHistoryBeforeUnload, false);
window.addEventListener('pageshow', function pdfHistoryPageShow(evt) {
// If the entire viewer (including the PDF file) is cached in the browser,
// we need to reattach the 'beforeunload' event listener since
// the 'DOMContentLoaded' event is not fired on 'pageshow'.
window.addEventListener('beforeunload', pdfHistoryBeforeUnload, false);
}, false);
},
@ -966,16 +1046,21 @@ var PDFHistory = {
return temp;
},
_updatePreviousBookmark: function pdfHistory_updatePreviousBookmark() {
if (this.updatePreviousBookmark &&
this.currentBookmark && this.currentPage) {
this.previousBookmark = this.currentBookmark;
this.previousPage = this.currentPage;
this.updatePreviousBookmark = false;
}
},
updateCurrentBookmark: function pdfHistoryUpdateCurrentBookmark(bookmark,
pageNum) {
if (this.initialized) {
this.currentBookmark = bookmark.substring(1);
this.currentPage = pageNum | 0;
if (this.updatePreviousBookmark) {
this.previousBookmark = this.currentBookmark;
this.previousPage = this.currentPage;
this.updatePreviousBookmark = false;
}
this._updatePreviousBookmark();
}
},
@ -998,10 +1083,20 @@ var PDFHistory = {
if (params.page) {
params.page |= 0;
}
if (isInitialBookmark && this.uid === 0) {
this._pushToHistory(params, false);
this.previousHash = window.location.hash.substring(1);
if (isInitialBookmark) {
var target = window.history.state.target;
if (!target) {
// Invoked when the user specifies an initial bookmark,
// thus setting PDFView.initialBookmark, when the document is loaded.
this._pushToHistory(params, false);
this.previousHash = window.location.hash.substring(1);
}
this.updatePreviousBookmark = this.nextHashParam ? false : true;
if (target) {
// If the current document is reloaded,
// avoid creating duplicate entries in the history.
this._updatePreviousBookmark();
}
return;
}
if (this.nextHashParam && this.nextHashParam === params.hash) {
@ -1014,8 +1109,11 @@ var PDFHistory = {
if (this.current.hash) {
if (this.current.hash !== params.hash) {
this._pushToHistory(params, true);
} else if (!this.current.page && params.page) {
this._pushToHistory(params, false, true);
} else {
if (!this.current.page && params.page) {
this._pushToHistory(params, false, true);
}
this.updatePreviousBookmark = true;
}
} else {
this._pushToHistory(params, true);
@ -1064,7 +1162,8 @@ var PDFHistory = {
if (addPrevious && !overwrite) {
var previousParams = this._getPreviousParams();
if (previousParams) {
this._pushToHistory(previousParams, false);
var replacePrevious = (this.current.hash !== this.previousHash);
this._pushToHistory(previousParams, false, replacePrevious);
}
}
if (overwrite || this.uid === 0) {
@ -1135,6 +1234,7 @@ var PDFHistory = {
}
};
var PDFView = {
pages: [],
thumbnails: [],
@ -1387,16 +1487,21 @@ var PDFView = {
return support;
},
get loadingBar() {
var bar = new ProgressBar('#loadingBar', {});
Object.defineProperty(this, 'loadingBar', { value: bar,
enumerable: true,
configurable: true,
writable: false });
return bar;
},
get isHorizontalScrollbarEnabled() {
var div = document.getElementById('viewerContainer');
return div.scrollWidth > div.clientWidth;
},
initPassiveLoading: function pdfViewInitPassiveLoading() {
if (!PDFView.loadingBar) {
PDFView.loadingBar = new ProgressBar('#loadingBar', {});
}
var pdfDataRangeTransport = {
rangeListeners: [],
progressListeners: [],
@ -1495,10 +1600,6 @@ var PDFView = {
}
}
if (!PDFView.loadingBar) {
PDFView.loadingBar = new ProgressBar('#loadingBar', {});
}
this.pdfDocument = null;
var self = this;
self.loading = true;
@ -1555,32 +1656,30 @@ var PDFView = {
download: function pdfViewDownload() {
function noData() {
FirefoxCom.request('download', { originalUrl: url });
downloadManager.downloadUrl(url, filename);
}
var url = this.url.split('#')[0];
// Document isn't ready just try to download with the url.
if (!this.pdfDocument) {
var filename = getPDFFileNameFromURL(url);
var downloadManager = new DownloadManager();
downloadManager.onerror = function (err) {
// This error won't really be helpful because it's likely the
// fallback won't work either (or is already open).
PDFView.error('PDF failed to download.');
};
if (!this.pdfDocument) { // the PDF is not ready yet
noData();
return;
}
this.pdfDocument.getData().then(
function getDataSuccess(data) {
var blob = PDFJS.createBlob(data.buffer, 'application/pdf');
var blobUrl = window.URL.createObjectURL(blob);
FirefoxCom.request('download', { blobUrl: blobUrl, originalUrl: url },
function response(err) {
if (err) {
// This error won't really be helpful because it's likely the
// fallback won't work either (or is already open).
PDFView.error('PDF failed to download.');
}
window.URL.revokeObjectURL(blobUrl);
}
);
downloadManager.download(blob, url, filename);
},
noData // Error occurred try downloading with just the url.
);
).then(null, noData);
},
fallback: function pdfViewFallback() {
@ -1598,19 +1697,12 @@ var PDFView = {
},
navigateTo: function pdfViewNavigateTo(dest) {
var destString = '';
var self = this;
PDFJS.Promise.all([this.pagesPromise,
this.destinationsPromise]).then(function() {
var destString = '';
if (typeof dest === 'string') {
destString = dest;
dest = self.destinations[dest];
}
if (!(dest instanceof Array)) {
return; // invalid destination
}
var goToDestination = function(destRef) {
self.pendingRefStr = null;
// dest array looks like that: <page-ref> </XYZ|FitXXX> <args..>
var destRef = dest[0];
var pageNumber = destRef instanceof Object ?
self.pagesRefMap[destRef.num + ' ' + destRef.gen + ' R'] :
(destRef + 1);
@ -1623,7 +1715,24 @@ var PDFView = {
// Update the browsing history.
PDFHistory.push({ dest: dest, hash: destString, page: pageNumber });
} else {
self.pendingRefStrLoaded = new PDFJS.Promise();
self.pendingRefStr = destRef.num + ' ' + destRef.gen + ' R';
self.pendingRefStrLoaded.then(function() {
goToDestination(destRef);
});
}
};
this.destinationsPromise.then(function() {
if (typeof dest === 'string') {
destString = dest;
dest = self.destinations[dest];
}
if (!(dest instanceof Array)) {
return; // invalid destination
}
goToDestination(dest[0]);
});
},
@ -1728,8 +1837,7 @@ var PDFView = {
errorWrapper.setAttribute('hidden', 'true');
pdfDocument.dataLoaded().then(function() {
var loadingBar = document.getElementById('loadingBar');
loadingBar.classList.add('hidden');
PDFView.loadingBar.hide();
var outerContainer = document.getElementById('outerContainer');
outerContainer.classList.remove('loadingInProgress');
});
@ -1791,6 +1899,8 @@ var PDFView = {
event.initCustomEvent('documentload', true, true, {});
window.dispatchEvent(event);
PDFView.loadingBar.setWidth(container);
for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
var pagePromise = pdfDocument.getPage(pageNum);
pagePromise.then(function(pdfPage) {
@ -1809,6 +1919,10 @@ var PDFView = {
var pageRef = pdfPage.ref;
var refStr = pageRef.num + ' ' + pageRef.gen + ' R';
pagesRefMap[refStr] = pdfPage.pageNumber;
if (self.pendingRefStr && self.pendingRefStr === refStr) {
self.pendingRefStrLoaded.resolve();
}
});
pagePromises.push(pagePromise);
}
@ -3097,11 +3211,9 @@ var TextLayerBuilder = function textLayerBuilder(options) {
if (width > 0) {
var textScale = textDiv.dataset.canvasWidth / width;
var rotation = textDiv.dataset.angle;
var transform = 'scale(' + textScale + ', 1)';
if (bidiTexts[i].dir === 'ttb') {
transform = 'rotate(90deg) ' + transform;
}
transform = 'rotate(' + rotation + 'deg) ' + transform;
CustomStyle.setProp('transform' , textDiv, transform);
CustomStyle.setProp('transformOrigin' , textDiv, '0% 0%');
@ -3141,13 +3253,14 @@ var TextLayerBuilder = function textLayerBuilder(options) {
// vScale and hScale already contain the scaling to pixel units
var fontHeight = geom.fontSize * Math.abs(geom.vScale);
textDiv.dataset.canvasWidth = geom.canvasWidth * geom.hScale;
textDiv.dataset.canvasWidth = geom.canvasWidth * Math.abs(geom.hScale);
textDiv.dataset.fontName = geom.fontName;
textDiv.dataset.angle = geom.angle * (180 / Math.PI);
textDiv.style.fontSize = fontHeight + 'px';
textDiv.style.fontFamily = geom.fontFamily;
textDiv.style.left = geom.x + 'px';
textDiv.style.top = (geom.y - fontHeight) + 'px';
textDiv.style.left = (geom.x + (fontHeight * Math.sin(geom.angle))) + 'px';
textDiv.style.top = (geom.y - (fontHeight * Math.cos(geom.angle))) + 'px';
// The content of the div is set in the `setTextContent` function.
@ -3175,7 +3288,7 @@ var TextLayerBuilder = function textLayerBuilder(options) {
textDiv.textContent = bidiText.str;
// bidiText.dir may be 'ttb' for vertical texts.
textDiv.dir = bidiText.dir === 'rtl' ? 'rtl' : 'ltr';
textDiv.dir = bidiText.dir;
}
this.setupRenderLayoutTimer();
@ -3877,12 +3990,18 @@ window.addEventListener('keydown', function keydown(evt) {
if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
// either CTRL or META key with optional SHIFT.
switch (evt.keyCode) {
case 70:
case 70: // f
if (!PDFView.supportsIntegratedFind) {
PDFFindBar.toggle();
handled = true;
}
break;
case 71: // g
if (!PDFView.supportsIntegratedFind) {
PDFFindBar.dispatchEvent('again', cmd === 5 || cmd === 12);
handled = true;
}
break;
case 61: // FF/Mac '='
case 107: // FF '+' and '='
case 187: // Chrome '+'
@ -3904,14 +4023,12 @@ window.addEventListener('keydown', function keydown(evt) {
}
}
// CTRL or META with or without SHIFT.
if (cmd == 1 || cmd == 8 || cmd == 5 || cmd == 12) {
// CTRL+ALT or Option+Command
if (cmd === 3 || cmd === 10) {
switch (evt.keyCode) {
case 71: // g
if (!PDFView.supportsIntegratedFind) {
PDFFindBar.dispatchEvent('again', cmd == 5 || cmd == 12);
handled = true;
}
case 80: // p
PDFView.presentationMode();
handled = true;
break;
}
}