Replace all "private" methods in PDFPresentationMode with proper ones

Now that the there's ECMAScript support for properly private methods on `class`es, we can use that instead and thus remove all of the `@private` JSDocs comments.
This commit is contained in:
Jonas Jenwald 2022-02-25 14:49:12 +01:00
parent b753271ca6
commit cadc4d2f61

View File

@ -66,9 +66,9 @@ class PDFPresentationMode {
if (this.switchInProgress || this.active || !this.pdfViewer.pagesCount) { if (this.switchInProgress || this.active || !this.pdfViewer.pagesCount) {
return false; return false;
} }
this._addFullscreenChangeListeners(); this.#addFullscreenChangeListeners();
this._setSwitchInProgress(); this.#setSwitchInProgress();
this._notifyStateChange(); this.#notifyStateChange();
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
if (this.container.requestFullscreen) { if (this.container.requestFullscreen) {
@ -96,10 +96,7 @@ class PDFPresentationMode {
return true; return true;
} }
/** #mouseWheel(evt) {
* @private
*/
_mouseWheel(evt) {
if (!this.active) { if (!this.active) {
return; return;
} }
@ -122,13 +119,13 @@ class PDFPresentationMode {
(this.mouseScrollDelta > 0 && delta < 0) || (this.mouseScrollDelta > 0 && delta < 0) ||
(this.mouseScrollDelta < 0 && delta > 0) (this.mouseScrollDelta < 0 && delta > 0)
) { ) {
this._resetMouseScrollState(); this.#resetMouseScrollState();
} }
this.mouseScrollDelta += delta; this.mouseScrollDelta += delta;
if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) { if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
const totalDelta = this.mouseScrollDelta; const totalDelta = this.mouseScrollDelta;
this._resetMouseScrollState(); this.#resetMouseScrollState();
const success = const success =
totalDelta > 0 totalDelta > 0
? this.pdfViewer.previousPage() ? this.pdfViewer.previousPage()
@ -146,10 +143,7 @@ class PDFPresentationMode {
return !!(document.fullscreenElement || document.webkitIsFullScreen); return !!(document.fullscreenElement || document.webkitIsFullScreen);
} }
/** #notifyStateChange() {
* @private
*/
_notifyStateChange() {
let state = PresentationModeState.NORMAL; let state = PresentationModeState.NORMAL;
if (this.switchInProgress) { if (this.switchInProgress) {
state = PresentationModeState.CHANGING; state = PresentationModeState.CHANGING;
@ -168,37 +162,29 @@ class PDFPresentationMode {
* This timeout is used to prevent the current page from being scrolled * This timeout is used to prevent the current page from being scrolled
* partially, or completely, out of view when entering Presentation Mode. * partially, or completely, out of view when entering Presentation Mode.
* NOTE: This issue seems limited to certain zoom levels (e.g. page-width). * NOTE: This issue seems limited to certain zoom levels (e.g. page-width).
*
* @private
*/ */
_setSwitchInProgress() { #setSwitchInProgress() {
if (this.switchInProgress) { if (this.switchInProgress) {
clearTimeout(this.switchInProgress); clearTimeout(this.switchInProgress);
} }
this.switchInProgress = setTimeout(() => { this.switchInProgress = setTimeout(() => {
this._removeFullscreenChangeListeners(); this.#removeFullscreenChangeListeners();
delete this.switchInProgress; delete this.switchInProgress;
this._notifyStateChange(); this.#notifyStateChange();
}, DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS); }, DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS);
} }
/** #resetSwitchInProgress() {
* @private
*/
_resetSwitchInProgress() {
if (this.switchInProgress) { if (this.switchInProgress) {
clearTimeout(this.switchInProgress); clearTimeout(this.switchInProgress);
delete this.switchInProgress; delete this.switchInProgress;
} }
} }
/** #enter() {
* @private
*/
_enter() {
this.active = true; this.active = true;
this._resetSwitchInProgress(); this.#resetSwitchInProgress();
this._notifyStateChange(); this.#notifyStateChange();
this.container.classList.add(ACTIVE_SELECTOR); this.container.classList.add(ACTIVE_SELECTOR);
// Ensure that the correct page is scrolled into view when entering // Ensure that the correct page is scrolled into view when entering
@ -210,8 +196,8 @@ class PDFPresentationMode {
this.pdfViewer.currentScaleValue = "page-fit"; this.pdfViewer.currentScaleValue = "page-fit";
}, 0); }, 0);
this._addWindowListeners(); this.#addWindowListeners();
this._showControls(); this.#showControls();
this.contextMenuOpen = false; this.contextMenuOpen = false;
// Text selection is disabled in Presentation Mode, thus it's not possible // Text selection is disabled in Presentation Mode, thus it's not possible
@ -220,10 +206,7 @@ class PDFPresentationMode {
window.getSelection().removeAllRanges(); window.getSelection().removeAllRanges();
} }
/** #exit() {
* @private
*/
_exit() {
const pageNumber = this.pdfViewer.currentPageNumber; const pageNumber = this.pdfViewer.currentPageNumber;
this.container.classList.remove(ACTIVE_SELECTOR); this.container.classList.remove(ACTIVE_SELECTOR);
@ -231,8 +214,8 @@ class PDFPresentationMode {
// Presentation Mode, by waiting until fullscreen mode is disabled. // Presentation Mode, by waiting until fullscreen mode is disabled.
setTimeout(() => { setTimeout(() => {
this.active = false; this.active = false;
this._removeFullscreenChangeListeners(); this.#removeFullscreenChangeListeners();
this._notifyStateChange(); this.#notifyStateChange();
this.pdfViewer.scrollMode = this.args.scrollMode; this.pdfViewer.scrollMode = this.args.scrollMode;
this.pdfViewer.spreadMode = this.args.spreadMode; this.pdfViewer.spreadMode = this.args.spreadMode;
@ -241,16 +224,13 @@ class PDFPresentationMode {
this.args = null; this.args = null;
}, 0); }, 0);
this._removeWindowListeners(); this.#removeWindowListeners();
this._hideControls(); this.#hideControls();
this._resetMouseScrollState(); this.#resetMouseScrollState();
this.contextMenuOpen = false; this.contextMenuOpen = false;
} }
/** #mouseDown(evt) {
* @private
*/
_mouseDown(evt) {
if (this.contextMenuOpen) { if (this.contextMenuOpen) {
this.contextMenuOpen = false; this.contextMenuOpen = false;
evt.preventDefault(); evt.preventDefault();
@ -274,17 +254,11 @@ class PDFPresentationMode {
} }
} }
/** #contextMenu() {
* @private
*/
_contextMenu() {
this.contextMenuOpen = true; this.contextMenuOpen = true;
} }
/** #showControls() {
* @private
*/
_showControls() {
if (this.controlsTimeout) { if (this.controlsTimeout) {
clearTimeout(this.controlsTimeout); clearTimeout(this.controlsTimeout);
} else { } else {
@ -296,10 +270,7 @@ class PDFPresentationMode {
}, DELAY_BEFORE_HIDING_CONTROLS); }, DELAY_BEFORE_HIDING_CONTROLS);
} }
/** #hideControls() {
* @private
*/
_hideControls() {
if (!this.controlsTimeout) { if (!this.controlsTimeout) {
return; return;
} }
@ -310,18 +281,13 @@ class PDFPresentationMode {
/** /**
* Resets the properties used for tracking mouse scrolling events. * Resets the properties used for tracking mouse scrolling events.
*
* @private
*/ */
_resetMouseScrollState() { #resetMouseScrollState() {
this.mouseScrollTimeStamp = 0; this.mouseScrollTimeStamp = 0;
this.mouseScrollDelta = 0; this.mouseScrollDelta = 0;
} }
/** #touchSwipe(evt) {
* @private
*/
_touchSwipe(evt) {
if (!this.active) { if (!this.active) {
return; return;
} }
@ -381,16 +347,13 @@ class PDFPresentationMode {
} }
} }
/** #addWindowListeners() {
* @private this.showControlsBind = this.#showControls.bind(this);
*/ this.mouseDownBind = this.#mouseDown.bind(this);
_addWindowListeners() { this.mouseWheelBind = this.#mouseWheel.bind(this);
this.showControlsBind = this._showControls.bind(this); this.resetMouseScrollStateBind = this.#resetMouseScrollState.bind(this);
this.mouseDownBind = this._mouseDown.bind(this); this.contextMenuBind = this.#contextMenu.bind(this);
this.mouseWheelBind = this._mouseWheel.bind(this); this.touchSwipeBind = this.#touchSwipe.bind(this);
this.resetMouseScrollStateBind = this._resetMouseScrollState.bind(this);
this.contextMenuBind = this._contextMenu.bind(this);
this.touchSwipeBind = this._touchSwipe.bind(this);
window.addEventListener("mousemove", this.showControlsBind); window.addEventListener("mousemove", this.showControlsBind);
window.addEventListener("mousedown", this.mouseDownBind); window.addEventListener("mousedown", this.mouseDownBind);
@ -402,10 +365,7 @@ class PDFPresentationMode {
window.addEventListener("touchend", this.touchSwipeBind); window.addEventListener("touchend", this.touchSwipeBind);
} }
/** #removeWindowListeners() {
* @private
*/
_removeWindowListeners() {
window.removeEventListener("mousemove", this.showControlsBind); window.removeEventListener("mousemove", this.showControlsBind);
window.removeEventListener("mousedown", this.mouseDownBind); window.removeEventListener("mousedown", this.mouseDownBind);
window.removeEventListener("wheel", this.mouseWheelBind, { window.removeEventListener("wheel", this.mouseWheelBind, {
@ -425,22 +385,16 @@ class PDFPresentationMode {
delete this.touchSwipeBind; delete this.touchSwipeBind;
} }
/** #fullscreenChange() {
* @private
*/
_fullscreenChange() {
if (this.isFullscreen) { if (this.isFullscreen) {
this._enter(); this.#enter();
} else { } else {
this._exit(); this.#exit();
} }
} }
/** #addFullscreenChangeListeners() {
* @private this.fullscreenChangeBind = this.#fullscreenChange.bind(this);
*/
_addFullscreenChangeListeners() {
this.fullscreenChangeBind = this._fullscreenChange.bind(this);
window.addEventListener("fullscreenchange", this.fullscreenChangeBind); window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) { if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
@ -451,10 +405,7 @@ class PDFPresentationMode {
} }
} }
/** #removeFullscreenChangeListeners() {
* @private
*/
_removeFullscreenChangeListeners() {
window.removeEventListener("fullscreenchange", this.fullscreenChangeBind); window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) { if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
window.removeEventListener( window.removeEventListener(