Merge pull request #15319 from Snuffleupagus/bug-1784850

Refresh the viewer if the window resolution changes (bug 1784850)
This commit is contained in:
Jonas Jenwald 2022-08-15 18:54:08 +02:00 committed by GitHub
commit 44f6b76365
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 0 deletions

View File

@ -2004,6 +2004,27 @@ const PDFViewerApplication = {
bindWindowEvents() {
const { eventBus, _boundEvents } = this;
function addWindowResolutionChange(evt = null) {
if (evt) {
webViewerResolutionChange(evt);
}
const mediaQueryList = window.matchMedia(
`(resolution: ${window.devicePixelRatio || 1}dppx)`
);
mediaQueryList.addEventListener("change", addWindowResolutionChange, {
once: true,
});
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
return;
}
_boundEvents.removeWindowResolutionChange ||= function () {
mediaQueryList.removeEventListener("change", addWindowResolutionChange);
_boundEvents.removeWindowResolutionChange = null;
};
}
addWindowResolutionChange();
_boundEvents.windowResize = () => {
eventBus.dispatch("resize", { source: window });
};
@ -2123,6 +2144,7 @@ const PDFViewerApplication = {
_boundEvents.windowUpdateFromSandbox
);
_boundEvents.removeWindowResolutionChange?.();
_boundEvents.windowResize = null;
_boundEvents.windowHashChange = null;
_boundEvents.windowBeforePrint = null;
@ -2689,6 +2711,10 @@ function webViewerPageChanging({ pageNumber, pageLabel }) {
}
}
function webViewerResolutionChange(evt) {
PDFViewerApplication.pdfViewer.refresh();
}
function webViewerVisibilityChange(evt) {
if (document.visibilityState === "visible") {
// Ignore mouse wheel zooming during tab switches (bug 1503412).

View File

@ -2247,6 +2247,17 @@ class BaseViewer {
}
this.#annotationEditorUIManager.updateParams(type, value);
}
refresh() {
if (!this.pdfDocument) {
return;
}
const updateArgs = {};
for (const pageView of this._pages) {
pageView.update(updateArgs);
}
this.update();
}
}
export { BaseViewer, PagesCountLimit, PDFPageViewBuffer };