Merge pull request #14750 from Snuffleupagus/rm-_getCurrentVisiblePage

Remove the `BaseViewer._getCurrentVisiblePage` helper method
This commit is contained in:
Tim van der Meij 2022-04-08 20:05:51 +02:00 committed by GitHub
commit 2b673a6941
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 48 deletions

View File

@ -1321,8 +1321,6 @@ class BaseViewer {
: currentScaleValue; : currentScaleValue;
const pageNumber = firstPage.id; const pageNumber = firstPage.id;
let pdfOpenParams = "#page=" + pageNumber;
pdfOpenParams += "&zoom=" + normalizedScaleValue;
const currentPageView = this._pages[pageNumber - 1]; const currentPageView = this._pages[pageNumber - 1];
const container = this.container; const container = this.container;
const topLeft = currentPageView.getPagePoint( const topLeft = currentPageView.getPagePoint(
@ -1331,7 +1329,11 @@ class BaseViewer {
); );
const intLeft = Math.round(topLeft[0]); const intLeft = Math.round(topLeft[0]);
const intTop = Math.round(topLeft[1]); const intTop = Math.round(topLeft[1]);
pdfOpenParams += "," + intLeft + "," + intTop;
let pdfOpenParams = `#page=${pageNumber}`;
if (!this.isInPresentationMode) {
pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
}
this._location = { this._location = {
pageNumber, pageNumber,
@ -1418,37 +1420,7 @@ class BaseViewer {
: this.container.scrollHeight > this.container.clientHeight; : this.container.scrollHeight > this.container.clientHeight;
} }
/**
* Helper method for `this._getVisiblePages`. Should only ever be used when
* the viewer can only display a single page at a time, for example:
* - When PresentationMode is active.
*/
_getCurrentVisiblePage() {
if (!this.pagesCount) {
return { views: [] };
}
const pageView = this._pages[this._currentPageNumber - 1];
// NOTE: Compute the `x` and `y` properties of the current view,
// since `this._updateLocation` depends of them being available.
const element = pageView.div;
const view = {
id: pageView.id,
x: element.offsetLeft + element.clientLeft,
y: element.offsetTop + element.clientTop,
view: pageView,
};
const ids = new Set([pageView.id]);
return { first: view, last: view, views: [view], ids };
}
_getVisiblePages() { _getVisiblePages() {
if (this.isInPresentationMode) {
// The algorithm in `getVisibleElements` doesn't work in all browsers and
// configurations (e.g. Chrome) when PresentationMode is active.
return this._getCurrentVisiblePage();
}
const views = const views =
this._scrollMode === ScrollMode.PAGE this._scrollMode === ScrollMode.PAGE
? this.#scrollModePageState.pages ? this.#scrollModePageState.pages

View File

@ -16,11 +16,7 @@
/** @typedef {import("./event_utils").EventBus} EventBus */ /** @typedef {import("./event_utils").EventBus} EventBus */
/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ /** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */
import { import { isValidRotation, parseQueryString } from "./ui_utils.js";
isValidRotation,
parseQueryString,
PresentationModeState,
} from "./ui_utils.js";
import { waitOnEventOrTimeout } from "./event_utils.js"; import { waitOnEventOrTimeout } from "./event_utils.js";
// Heuristic value used when force-resetting `this._blockHashChange`. // Heuristic value used when force-resetting `this._blockHashChange`.
@ -69,13 +65,8 @@ class PDFHistory {
this.reset(); this.reset();
this._boundEvents = null; this._boundEvents = null;
this._isViewerInPresentationMode = false; // Ensure that we don't miss a "pagesinit" event,
// Ensure that we don't miss either a 'presentationmodechanged' or a // by registering the listener immediately.
// 'pagesinit' event, by registering the listeners immediately.
this.eventBus._on("presentationmodechanged", evt => {
this._isViewerInPresentationMode =
evt.state !== PresentationModeState.NORMAL;
});
this.eventBus._on("pagesinit", () => { this.eventBus._on("pagesinit", () => {
this._isPagesLoaded = false; this._isPagesLoaded = false;
@ -566,9 +557,7 @@ class PDFHistory {
} }
this._position = { this._position = {
hash: this._isViewerInPresentationMode hash: location.pdfOpenParams.substring(1),
? `page=${location.pageNumber}`
: location.pdfOpenParams.substring(1),
page: this.linkService.page, page: this.linkService.page,
first: location.pageNumber, first: location.pageNumber,
rotation: location.rotation, rotation: location.rotation,