Refresh the viewer if the window resolution changes (bug 1784850)
*Please note:* This probably fixes bug 1784850, however I don't have the necessary hardware to reproduce the situation described in https://bugzilla.mozilla.org/show_bug.cgi?id=1784850#c0 Unfortunately it doesn't, as far as I can tell, appear possible to detect *all* resolution changes with a single media query. Instead we have to update it, and its listener, on every resolution change as outlined in [this MDN example](https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio#monitoring_screen_resolution_or_zoom_level_changes).
This commit is contained in:
parent
e6fe127433
commit
4919dae294
26
web/app.js
26
web/app.js
@ -2004,6 +2004,27 @@ const PDFViewerApplication = {
|
|||||||
bindWindowEvents() {
|
bindWindowEvents() {
|
||||||
const { eventBus, _boundEvents } = this;
|
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 = () => {
|
_boundEvents.windowResize = () => {
|
||||||
eventBus.dispatch("resize", { source: window });
|
eventBus.dispatch("resize", { source: window });
|
||||||
};
|
};
|
||||||
@ -2123,6 +2144,7 @@ const PDFViewerApplication = {
|
|||||||
_boundEvents.windowUpdateFromSandbox
|
_boundEvents.windowUpdateFromSandbox
|
||||||
);
|
);
|
||||||
|
|
||||||
|
_boundEvents.removeWindowResolutionChange?.();
|
||||||
_boundEvents.windowResize = null;
|
_boundEvents.windowResize = null;
|
||||||
_boundEvents.windowHashChange = null;
|
_boundEvents.windowHashChange = null;
|
||||||
_boundEvents.windowBeforePrint = null;
|
_boundEvents.windowBeforePrint = null;
|
||||||
@ -2689,6 +2711,10 @@ function webViewerPageChanging({ pageNumber, pageLabel }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function webViewerResolutionChange(evt) {
|
||||||
|
PDFViewerApplication.pdfViewer.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
function webViewerVisibilityChange(evt) {
|
function webViewerVisibilityChange(evt) {
|
||||||
if (document.visibilityState === "visible") {
|
if (document.visibilityState === "visible") {
|
||||||
// Ignore mouse wheel zooming during tab switches (bug 1503412).
|
// Ignore mouse wheel zooming during tab switches (bug 1503412).
|
||||||
|
@ -2247,6 +2247,17 @@ class BaseViewer {
|
|||||||
}
|
}
|
||||||
this.#annotationEditorUIManager.updateParams(type, value);
|
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 };
|
export { BaseViewer, PagesCountLimit, PDFPageViewBuffer };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user