Merge pull request #15830 from calixteman/dont_compute_rect
Avoid to compute the client rect of the viewer
This commit is contained in:
commit
1ab711e2ac
@ -2366,7 +2366,6 @@ function webViewerResize() {
|
|||||||
// Work-around issue 15324 by ignoring "resize" events during printing.
|
// Work-around issue 15324 by ignoring "resize" events during printing.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pdfViewer.updateContainerHeightCss();
|
|
||||||
|
|
||||||
if (!pdfDocument) {
|
if (!pdfDocument) {
|
||||||
return;
|
return;
|
||||||
@ -2649,9 +2648,9 @@ function webViewerWheel(evt) {
|
|||||||
// left corner is restored. When the mouse wheel is used, the position
|
// left corner is restored. When the mouse wheel is used, the position
|
||||||
// under the cursor should be restored instead.
|
// under the cursor should be restored instead.
|
||||||
const scaleCorrectionFactor = currentScale / previousScale - 1;
|
const scaleCorrectionFactor = currentScale / previousScale - 1;
|
||||||
const rect = pdfViewer.container.getBoundingClientRect();
|
const [top, left] = pdfViewer.containerTopLeft;
|
||||||
const dx = evt.clientX - rect.left;
|
const dx = evt.clientX - left;
|
||||||
const dy = evt.clientY - rect.top;
|
const dy = evt.clientY - top;
|
||||||
pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
|
pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
|
||||||
pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
|
pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
|
||||||
}
|
}
|
||||||
|
@ -227,10 +227,14 @@ class PDFViewer {
|
|||||||
|
|
||||||
#annotationMode = AnnotationMode.ENABLE_FORMS;
|
#annotationMode = AnnotationMode.ENABLE_FORMS;
|
||||||
|
|
||||||
|
#containerTopLeft = null;
|
||||||
|
|
||||||
#enablePermissions = false;
|
#enablePermissions = false;
|
||||||
|
|
||||||
#previousContainerHeight = 0;
|
#previousContainerHeight = 0;
|
||||||
|
|
||||||
|
#resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this));
|
||||||
|
|
||||||
#scrollModePageState = null;
|
#scrollModePageState = null;
|
||||||
|
|
||||||
#onVisibilityChange = null;
|
#onVisibilityChange = null;
|
||||||
@ -247,6 +251,8 @@ class PDFViewer {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
this.container = options.container;
|
this.container = options.container;
|
||||||
|
this.#resizeObserver.observe(this.container);
|
||||||
|
|
||||||
this.viewer = options.viewer || options.container.firstElementChild;
|
this.viewer = options.viewer || options.container.firstElementChild;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -330,7 +336,8 @@ class PDFViewer {
|
|||||||
if (this.removePageBorders) {
|
if (this.removePageBorders) {
|
||||||
this.viewer.classList.add("removePageBorders");
|
this.viewer.classList.add("removePageBorders");
|
||||||
}
|
}
|
||||||
this.updateContainerHeightCss();
|
|
||||||
|
this.#updateContainerHeightCss();
|
||||||
}
|
}
|
||||||
|
|
||||||
get pagesCount() {
|
get pagesCount() {
|
||||||
@ -1137,7 +1144,6 @@ class PDFViewer {
|
|||||||
if (this.defaultRenderingQueue) {
|
if (this.defaultRenderingQueue) {
|
||||||
this.update();
|
this.update();
|
||||||
}
|
}
|
||||||
this.updateContainerHeightCss();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2186,16 +2192,32 @@ class PDFViewer {
|
|||||||
this.currentScaleValue = newScale;
|
this.currentScaleValue = newScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateContainerHeightCss() {
|
#updateContainerHeightCss(height = this.container.clientHeight) {
|
||||||
const height = this.container.clientHeight;
|
|
||||||
|
|
||||||
if (height !== this.#previousContainerHeight) {
|
if (height !== this.#previousContainerHeight) {
|
||||||
this.#previousContainerHeight = height;
|
this.#previousContainerHeight = height;
|
||||||
|
|
||||||
docStyle.setProperty("--viewer-container-height", `${height}px`);
|
docStyle.setProperty("--viewer-container-height", `${height}px`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#resizeObserverCallback(entries) {
|
||||||
|
for (const entry of entries) {
|
||||||
|
if (entry.target === this.container) {
|
||||||
|
this.#updateContainerHeightCss(
|
||||||
|
Math.floor(entry.borderBoxSize[0].blockSize)
|
||||||
|
);
|
||||||
|
this.#containerTopLeft = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get containerTopLeft() {
|
||||||
|
return (this.#containerTopLeft ||= [
|
||||||
|
this.container.offsetTop,
|
||||||
|
this.container.offsetLeft,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user