Merge pull request #10652 from Snuffleupagus/browser-find-events
Prepare the `MOZCENTRAL` viewer for receiving zoom events from the browser UI (bug 786674, bug 1177385)
This commit is contained in:
commit
bce9ff7347
21
web/app.js
21
web/app.js
@ -431,6 +431,18 @@ let PDFViewerApplication = {
|
|||||||
this.pdfViewer.currentScaleValue = newScale;
|
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() {
|
get pagesCount() {
|
||||||
return this.pdfDocument ? this.pdfDocument.numPages : 0;
|
return this.pdfDocument ? this.pdfDocument.numPages : 0;
|
||||||
},
|
},
|
||||||
@ -1343,6 +1355,7 @@ let PDFViewerApplication = {
|
|||||||
eventBus.on('previouspage', webViewerPreviousPage);
|
eventBus.on('previouspage', webViewerPreviousPage);
|
||||||
eventBus.on('zoomin', webViewerZoomIn);
|
eventBus.on('zoomin', webViewerZoomIn);
|
||||||
eventBus.on('zoomout', webViewerZoomOut);
|
eventBus.on('zoomout', webViewerZoomOut);
|
||||||
|
eventBus.on('zoomreset', webViewerZoomReset);
|
||||||
eventBus.on('pagenumberchanged', webViewerPageNumberChanged);
|
eventBus.on('pagenumberchanged', webViewerPageNumberChanged);
|
||||||
eventBus.on('scalechanged', webViewerScaleChanged);
|
eventBus.on('scalechanged', webViewerScaleChanged);
|
||||||
eventBus.on('rotatecw', webViewerRotateCw);
|
eventBus.on('rotatecw', webViewerRotateCw);
|
||||||
@ -1417,6 +1430,7 @@ let PDFViewerApplication = {
|
|||||||
eventBus.off('previouspage', webViewerPreviousPage);
|
eventBus.off('previouspage', webViewerPreviousPage);
|
||||||
eventBus.off('zoomin', webViewerZoomIn);
|
eventBus.off('zoomin', webViewerZoomIn);
|
||||||
eventBus.off('zoomout', webViewerZoomOut);
|
eventBus.off('zoomout', webViewerZoomOut);
|
||||||
|
eventBus.off('zoomreset', webViewerZoomReset);
|
||||||
eventBus.off('pagenumberchanged', webViewerPageNumberChanged);
|
eventBus.off('pagenumberchanged', webViewerPageNumberChanged);
|
||||||
eventBus.off('scalechanged', webViewerScaleChanged);
|
eventBus.off('scalechanged', webViewerScaleChanged);
|
||||||
eventBus.off('rotatecw', webViewerRotateCw);
|
eventBus.off('rotatecw', webViewerRotateCw);
|
||||||
@ -1940,6 +1954,9 @@ function webViewerZoomIn() {
|
|||||||
function webViewerZoomOut() {
|
function webViewerZoomOut() {
|
||||||
PDFViewerApplication.zoomOut();
|
PDFViewerApplication.zoomOut();
|
||||||
}
|
}
|
||||||
|
function webViewerZoomReset(evt) {
|
||||||
|
PDFViewerApplication.zoomReset(evt && evt.ignoreDuplicate);
|
||||||
|
}
|
||||||
function webViewerPageNumberChanged(evt) {
|
function webViewerPageNumberChanged(evt) {
|
||||||
let pdfViewer = PDFViewerApplication.pdfViewer;
|
let pdfViewer = PDFViewerApplication.pdfViewer;
|
||||||
// Note that for `<input type="number">` HTML elements, an empty string will
|
// 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
|
case 96: // '0' on Numpad of Swedish keyboard
|
||||||
if (!isViewerInPresentationMode) {
|
if (!isViewerInPresentationMode) {
|
||||||
// keeping it unhandled (to restore page zoom to 100%)
|
// keeping it unhandled (to restore page zoom to 100%)
|
||||||
setTimeout(function () {
|
setTimeout(function() {
|
||||||
// ... and resetting the scale after browser adjusts its scale
|
// ... and resetting the scale after browser adjusts its scale
|
||||||
pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE;
|
PDFViewerApplication.zoomReset();
|
||||||
});
|
});
|
||||||
handled = false;
|
handled = false;
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ class MozL10n {
|
|||||||
'findentirewordchange',
|
'findentirewordchange',
|
||||||
'findbarclose',
|
'findbarclose',
|
||||||
];
|
];
|
||||||
let handleEvent = function({ type, detail, }) {
|
const handleEvent = function({ type, detail, }) {
|
||||||
if (!PDFViewerApplication.initialized) {
|
if (!PDFViewerApplication.initialized) {
|
||||||
return;
|
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);
|
window.addEventListener(event, handleEvent);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
Loading…
Reference in New Issue
Block a user