Attempt to delay disabling of the attachment view until FileAttachment annotations of the *initial* page has been parsed

As discussed in PR 8673, we cannot solve the general issue (since that would require parsing every single page). However, we can mitigate the effect somewhat, by waiting for the FileAttachment annotations of the initially rendered page.
This commit is contained in:
Jonas Jenwald 2017-08-17 14:12:42 +02:00
parent 96fb0c0370
commit 9273350c6b
2 changed files with 24 additions and 10 deletions

View File

@ -62,12 +62,12 @@ class PDFAttachmentViewer {
* @private
*/
_dispatchEvent(attachmentsCount) {
this._renderedCapability.resolve();
this.eventBus.dispatch('attachmentsloaded', {
source: this,
attachmentsCount,
});
this._renderedCapability.resolve();
}
/**

View File

@ -420,17 +420,31 @@ class PDFSidebar {
});
this.eventBus.on('attachmentsloaded', (evt) => {
let attachmentsCount = evt.attachmentsCount;
if (evt.attachmentsCount) {
this.attachmentsButton.disabled = false;
this.attachmentsButton.disabled = !attachmentsCount;
if (attachmentsCount) {
this._showUINotification(SidebarView.ATTACHMENTS);
} else if (this.active === SidebarView.ATTACHMENTS) {
// If the attachment view was opened during document load, switch away
// from it if it turns out that the document has no attachments.
this.switchView(SidebarView.THUMBS);
return;
}
// Attempt to avoid temporarily disabling, and switching away from, the
// attachment view for documents that do not contain proper attachments
// but *only* FileAttachment annotations. Hence we defer those operations
// slightly to allow time for parsing any FileAttachment annotations that
// may be present on the *initially* rendered page of the document.
Promise.resolve().then(() => {
if (this.attachmentsView.hasChildNodes()) {
// FileAttachment annotations were appended to the attachment view.
return;
}
this.attachmentsButton.disabled = true;
if (this.active === SidebarView.ATTACHMENTS) {
// If the attachment view was opened during document load, switch away
// from it if it turns out that the document has no attachments.
this.switchView(SidebarView.THUMBS);
}
});
});
// Update the thumbnailViewer, if visible, when exiting presentation mode.