Skip to content

Commit

Permalink
For #11838: trigger fallback bar after user clicks in pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
emalysz committed Jun 2, 2020
1 parent 8fc1126 commit da201dd
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ const PDFViewerApplication = {
externalServices: DefaultExternalServices,
_boundEvents: {},
contentDispositionFilename: null,
_hasInteracted: false,
_delayedFallbackFeatureIds: [],

// Called once when the document is loaded.
async initialize(appConfig) {
Expand Down Expand Up @@ -867,11 +869,20 @@ const PDFViewerApplication = {
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("MOZCENTRAL || GENERIC")
) {
// For PDFs that contain script and form errors, we should only trigger
// the fallback once the user has interacted with the page.
if (this._delayedFallbackFeatureIds.length === 2 && this._hasInteracted) {
featureId = this._delayedFallbackFeatureIds[0];
// Reset to prevent all click events from showing fallback bar.
this._delayedFallbackFeatureIds = [];
}

// Only trigger the fallback once so we don't spam the user with messages
// for one PDF.
if (this.fellback) {
return;
}

this.fellback = true;
this.externalServices.fallback(
{
Expand Down Expand Up @@ -1235,7 +1246,7 @@ const PDFViewerApplication = {
return false;
}
console.warn("Warning: JavaScript is not supported");
this.fallback(UNSUPPORTED_FEATURES.javaScript);
this._delayedFallbackFeatureIds.push(UNSUPPORTED_FEATURES.javaScript);
return true;
});

Expand Down Expand Up @@ -1317,7 +1328,7 @@ const PDFViewerApplication = {

if (info.IsAcroFormPresent) {
console.warn("Warning: AcroForm/XFA is not supported");
this.fallback(UNSUPPORTED_FEATURES.forms);
this._delayedFallbackFeatureIds.push(UNSUPPORTED_FEATURES.forms);
}

if (
Expand Down Expand Up @@ -2473,6 +2484,17 @@ function webViewerWheel(evt) {
}

function webViewerClick(evt) {
PDFViewerApplication._hasInteracted = true;

// Avoid triggering the fallback bar when the user clicks on the
// toolbar or sidebar.
if (
PDFViewerApplication._delayedFallbackFeatureIds.length === 2 &&
PDFViewerApplication.pdfViewer.containsElement(evt.target)
) {
PDFViewerApplication.fallback();
}

if (!PDFViewerApplication.secondaryToolbar.isOpen) {
return;
}
Expand Down

0 comments on commit da201dd

Please sign in to comment.