Prepare the MOZCENTRAL viewer for receiving zoom events from the browser UI (bug 786674, bug 1177385)

This lays the necessary foundation for handling zoom events originating within the browser itself, rather than in the viewer. Please note that this will also require a follow-up patch to `mozilla-central`, such that the viewer is actually notified when zooming occurs.
This commit is contained in:
Jonas Jenwald 2019-03-19 10:45:27 +01:00
parent 844aecf9e3
commit 2e044bf646
2 changed files with 42 additions and 4 deletions

View File

@ -431,6 +431,18 @@ let PDFViewerApplication = {
this.pdfViewer.currentScaleValue = newScale;
},
zoomReset(ignoreDuplicate = false) {
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;
},
get pagesCount() {
return this.pdfDocument ? this.pdfDocument.numPages : 0;
},
@ -1343,6 +1355,7 @@ let PDFViewerApplication = {
eventBus.on('previouspage', webViewerPreviousPage);
eventBus.on('zoomin', webViewerZoomIn);
eventBus.on('zoomout', webViewerZoomOut);
eventBus.on('zoomreset', webViewerZoomReset);
eventBus.on('pagenumberchanged', webViewerPageNumberChanged);
eventBus.on('scalechanged', webViewerScaleChanged);
eventBus.on('rotatecw', webViewerRotateCw);
@ -1417,6 +1430,7 @@ let PDFViewerApplication = {
eventBus.off('previouspage', webViewerPreviousPage);
eventBus.off('zoomin', webViewerZoomIn);
eventBus.off('zoomout', webViewerZoomOut);
eventBus.off('zoomreset', webViewerZoomReset);
eventBus.off('pagenumberchanged', webViewerPageNumberChanged);
eventBus.off('scalechanged', webViewerScaleChanged);
eventBus.off('rotatecw', webViewerRotateCw);
@ -1940,6 +1954,9 @@ function webViewerZoomIn() {
function webViewerZoomOut() {
PDFViewerApplication.zoomOut();
}
function webViewerZoomReset(evt) {
PDFViewerApplication.zoomReset(evt && evt.ignoreDuplicate);
}
function webViewerPageNumberChanged(evt) {
let pdfViewer = PDFViewerApplication.pdfViewer;
// Note that for `<input type="number">` HTML elements, an empty string will
@ -2189,9 +2206,9 @@ function webViewerKeyDown(evt) {
case 96: // '0' on Numpad of Swedish keyboard
if (!isViewerInPresentationMode) {
// keeping it unhandled (to restore page zoom to 100%)
setTimeout(function () {
setTimeout(function() {
// ... and resetting the scale after browser adjusts its scale
pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE;
PDFViewerApplication.zoomReset();
});
handled = false;
}

View File

@ -171,7 +171,7 @@ class MozL10n {
'findentirewordchange',
'findbarclose',
];
let handleEvent = function({ type, detail, }) {
const handleEvent = function({ type, detail, }) {
if (!PDFViewerApplication.initialized) {
return;
}
@ -193,7 +193,28 @@ class MozL10n {
});
};
for (let event of events) {
for (const event of events) {
window.addEventListener(event, handleEvent);
}
})();
(function listenZoomEvents() {
const events = [
'zoomin',
'zoomout',
'zoomreset',
];
const handleEvent = function({ type, detail, }) {
if (!PDFViewerApplication.initialized) {
return;
}
PDFViewerApplication.eventBus.dispatch(type, {
source: window,
ignoreDuplicate: (type === 'zoomreset' ? true : undefined),
});
};
for (const event of events) {
window.addEventListener(event, handleEvent);
}
})();