Skip to content

Commit 7bd8887

Browse files
committed
Merge pull request mozilla#2613 from yurydelendik/wait-animation
Wait for animation frame before displaying stuff
2 parents 9af6e05 + 9a5ecae commit 7bd8887

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

web/viewer.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ function getFileName(url) {
5959
}
6060

6161
function scrollIntoView(element, spot) {
62+
// Assuming offsetParent is available (it's not available when viewer is in
63+
// hidden iframe or object). We have to scroll: if the offsetParent is not set
64+
// producing the error. See also animationStartedClosure.
6265
var parent = element.offsetParent, offsetY = element.offsetTop;
66+
if (!parent) {
67+
error('offsetParent is not set -- cannot scroll');
68+
}
6369
while (parent.clientHeight == parent.scrollHeight) {
6470
offsetY += parent.offsetTop;
6571
parent = parent.offsetParent;
@@ -1286,7 +1292,8 @@ var PDFView = {
12861292
});
12871293

12881294
// outline and initial view depends on destinations and pagesRefMap
1289-
var promises = [pagesPromise, destinationsPromise, storePromise];
1295+
var promises = [pagesPromise, destinationsPromise, storePromise,
1296+
PDFView.animationStartedPromise];
12901297
PDFJS.Promise.all(promises).then(function() {
12911298
pdfDocument.getOutline().then(function(outline) {
12921299
self.outline = new DocumentOutlineView(outline);
@@ -3321,6 +3328,21 @@ window.addEventListener('afterprint', function afterPrint(evt) {
33213328
window.addEventListener('webkitfullscreenchange', fullscreenChange, false);
33223329
})();
33233330

3331+
(function animationStartedClosure() {
3332+
// The offsetParent is not set until the pdf.js iframe or object is visible.
3333+
// Waiting for first animation.
3334+
var requestAnimationFrame = window.requestAnimationFrame ||
3335+
window.mozRequestAnimationFrame ||
3336+
window.webkitRequestAnimationFrame ||
3337+
window.oRequestAnimationFrame ||
3338+
window.msRequestAnimationFrame ||
3339+
function startAtOnce(callback) { callback(); };
3340+
PDFView.animationStartedPromise = new PDFJS.Promise();
3341+
requestAnimationFrame(function onAnimationFrame() {
3342+
PDFView.animationStartedPromise.resolve();
3343+
});
3344+
})();
3345+
33243346
//#if B2G
33253347
//window.navigator.mozSetMessageHandler('activity', function(activity) {
33263348
// var url = activity.source.data.url;

0 commit comments

Comments
 (0)