Simplify the signature of BaseViewer._scrollIntoView and make the method private

In PR 14112 usage of this *internal* method was reduced, and it thus can't hurt to clean-up things a little bit more.
Note in particular that we can simplify the call-sites by directly passing in the already available `PDFPageView`-instance, since the `id`-property those contain can replace the previous `pageNumber`-parameter[1].

Given that the method name has always been prefixed with an underscore it was thus never intended to be "public", hence we can now enforce that with modern ECMAScript features.

---
[1] There's already a bunch of other spots, throughout the viewer-code, where we assume that the `PDFPageView.id`-property contains proper page *numbers* (and not e.g. indices); note how we initialize the `PDFPageView`-instances in the `BaseViewer.setDocument`-method.
This commit is contained in:
Jonas Jenwald 2022-05-04 11:35:04 +02:00
parent 7d6d6f9151
commit 54410d5e41

View File

@ -943,10 +943,12 @@ class BaseViewer {
this.update();
}
_scrollIntoView({ pageDiv, pageNumber, pageSpot = null }) {
#scrollIntoView(pageView, pageSpot = null) {
const { div, id } = pageView;
if (this._scrollMode === ScrollMode.PAGE) {
// Ensure that `this._currentPageNumber` is correct.
this._setCurrentPageNumber(pageNumber);
this._setCurrentPageNumber(id);
this.#ensurePageViewVisible();
// Ensure that rendering always occurs, to avoid showing a blank page,
@ -955,8 +957,8 @@ class BaseViewer {
}
if (!pageSpot && !this.isInPresentationMode) {
const left = pageDiv.offsetLeft + pageDiv.clientLeft;
const right = left + pageDiv.clientWidth;
const left = div.offsetLeft + div.clientLeft,
right = left + div.clientWidth;
const { scrollLeft, clientWidth } = this.container;
if (
this._scrollMode === ScrollMode.HORIZONTAL ||
@ -966,7 +968,7 @@ class BaseViewer {
pageSpot = { left: 0, top: 0 };
}
}
scrollIntoView(pageDiv, pageSpot);
scrollIntoView(div, pageSpot);
}
/**
@ -1120,15 +1122,13 @@ class BaseViewer {
* Refreshes page view: scrolls to the current page and updates the scale.
*/
#resetCurrentPageView() {
const pageNumber = this._currentPageNumber;
const pageView = this._pages[this._currentPageNumber - 1];
if (this.isInPresentationMode) {
// Fixes the case when PDF has different page sizes.
this._setScale(this._currentScaleValue, true);
}
const pageView = this._pages[pageNumber - 1];
this._scrollIntoView({ pageDiv: pageView.div, pageNumber });
this.#scrollIntoView(pageView);
}
/**
@ -1272,10 +1272,7 @@ class BaseViewer {
}
if (scale === "page-fit" && !destArray[4]) {
this._scrollIntoView({
pageDiv: pageView.div,
pageNumber,
});
this.#scrollIntoView(pageView);
return;
}
@ -1293,11 +1290,7 @@ class BaseViewer {
left = Math.max(left, 0);
top = Math.max(top, 0);
}
this._scrollIntoView({
pageDiv: pageView.div,
pageSpot: { left, top },
pageNumber,
});
this.#scrollIntoView(pageView, /* pageSpot = */ { left, top });
}
_updateLocation(firstPage) {