From 8e5aa484fb09c2495bbdccf8c9e27b3dfe3296a5 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 17 Jul 2019 11:59:56 +0200 Subject: [PATCH 1/2] [Firefox] Re-factor the 'zoomreset' message handling in the viewer (PR 10652 follow-up) Given that this special-case only matters for the Firefox PDF viewer, it's probably better to just move it into `firefoxcom.js` instead to reduce unnecessary confusion. --- web/app.js | 11 +++-------- web/firefoxcom.js | 12 ++++++++---- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/web/app.js b/web/app.js index fd42d2bfa..e1a04c4a8 100644 --- a/web/app.js +++ b/web/app.js @@ -437,14 +437,9 @@ let PDFViewerApplication = { this.pdfViewer.currentScaleValue = newScale; }, - zoomReset(ignoreDuplicate = false) { + zoomReset() { if (this.pdfViewer.isInPresentationMode) { return; - } else if (ignoreDuplicate && - this.pdfViewer.currentScaleValue === DEFAULT_SCALE_VALUE) { - // Avoid attempting to needlessly reset the zoom level *twice* in a row, - // when using the `Ctrl + 0` keyboard shortcut in `MOZCENTRAL` builds. - return; } this.pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE; }, @@ -1965,8 +1960,8 @@ function webViewerZoomIn() { function webViewerZoomOut() { PDFViewerApplication.zoomOut(); } -function webViewerZoomReset(evt) { - PDFViewerApplication.zoomReset(evt && evt.ignoreDuplicate); +function webViewerZoomReset() { + PDFViewerApplication.zoomReset(); } function webViewerPageNumberChanged(evt) { let pdfViewer = PDFViewerApplication.pdfViewer; diff --git a/web/firefoxcom.js b/web/firefoxcom.js index 22e044801..d5a39685e 100644 --- a/web/firefoxcom.js +++ b/web/firefoxcom.js @@ -16,6 +16,7 @@ import '../extensions/firefox/tools/l10n'; import { createObjectURL, PDFDataRangeTransport, shadow, URL } from 'pdfjs-lib'; import { BasePreferences } from './preferences'; +import { DEFAULT_SCALE_VALUE } from './ui_utils'; import { PDFViewerApplication } from './app'; if (typeof PDFJSDev === 'undefined' || @@ -208,10 +209,13 @@ class MozL10n { if (!PDFViewerApplication.initialized) { return; } - PDFViewerApplication.eventBus.dispatch(type, { - source: window, - ignoreDuplicate: (type === 'zoomreset' ? true : undefined), - }); + // Avoid attempting to needlessly reset the zoom level *twice* in a row, + // when using the `Ctrl + 0` keyboard shortcut. + if (type === 'zoomreset' && // eslint-disable-next-line max-len + PDFViewerApplication.pdfViewer.currentScaleValue === DEFAULT_SCALE_VALUE) { + return; + } + PDFViewerApplication.eventBus.dispatch(type, { source: window, }); }; for (const event of events) { From d1af8bd196a4f5a90afc45de557e8d54f169776f Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 18 Jul 2019 14:28:49 +0200 Subject: [PATCH 2/2] Slightly more simplified dispatching of the 'findbarclose' events in `firefoxcom.js` --- web/firefoxcom.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/web/firefoxcom.js b/web/firefoxcom.js index d5a39685e..9aaea80ba 100644 --- a/web/firefoxcom.js +++ b/web/firefoxcom.js @@ -177,9 +177,7 @@ class MozL10n { return; } if (type === 'findbarclose') { - PDFViewerApplication.eventBus.dispatch('findbarclose', { - source: window, - }); + PDFViewerApplication.eventBus.dispatch(type, { source: window, }); return; } PDFViewerApplication.eventBus.dispatch('find', {