Skip to content

Commit

Permalink
Merge pull request #10652 from Snuffleupagus/browser-find-events
Browse files Browse the repository at this point in the history
Prepare the `MOZCENTRAL` viewer for receiving zoom events from the browser UI (bug 786674, bug 1177385)
  • Loading branch information
timvandermeij authored Mar 21, 2019
2 parents 844aecf + 2e044bf commit bce9ff7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
21 changes: 19 additions & 2 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
25 changes: 23 additions & 2 deletions web/firefoxcom.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class MozL10n {
'findentirewordchange',
'findbarclose',
];
let handleEvent = function({ type, detail, }) {
const handleEvent = function({ type, detail, }) {
if (!PDFViewerApplication.initialized) {
return;
}
Expand All @@ -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);
}
})();
Expand Down

0 comments on commit bce9ff7

Please sign in to comment.