Re-factor how PDFPresentationMode
, internally, tracks the current PresentationModeState
With the changes in the previous patch, we can simplify the state-tracking by using the `PresentationModeState`-values directly in the `PDFPresentationMode` class.
This commit is contained in:
parent
8d61b7c088
commit
bde6d9ffba
@ -41,6 +41,8 @@ const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class PDFPresentationMode {
|
class PDFPresentationMode {
|
||||||
|
#state = PresentationModeState.UNKNOWN;
|
||||||
|
|
||||||
#args = null;
|
#args = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,7 +53,6 @@ class PDFPresentationMode {
|
|||||||
this.pdfViewer = pdfViewer;
|
this.pdfViewer = pdfViewer;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
|
|
||||||
this.active = false;
|
|
||||||
this.contextMenuOpen = false;
|
this.contextMenuOpen = false;
|
||||||
this.mouseScrollTimeStamp = 0;
|
this.mouseScrollTimeStamp = 0;
|
||||||
this.mouseScrollDelta = 0;
|
this.mouseScrollDelta = 0;
|
||||||
@ -63,25 +64,21 @@ class PDFPresentationMode {
|
|||||||
* @returns {Promise<boolean>} Indicating if the request was successful.
|
* @returns {Promise<boolean>} Indicating if the request was successful.
|
||||||
*/
|
*/
|
||||||
async request() {
|
async request() {
|
||||||
if (
|
const { container, pdfViewer } = this;
|
||||||
this.switchInProgress ||
|
|
||||||
this.active ||
|
if (this.active || !pdfViewer.pagesCount || !container.requestFullscreen) {
|
||||||
!this.pdfViewer.pagesCount ||
|
|
||||||
!this.container.requestFullscreen
|
|
||||||
) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.#addFullscreenChangeListeners();
|
this.#addFullscreenChangeListeners();
|
||||||
this.#setSwitchInProgress();
|
this.#notifyStateChange(PresentationModeState.CHANGING);
|
||||||
this.#notifyStateChange();
|
|
||||||
|
|
||||||
const promise = this.container.requestFullscreen();
|
const promise = container.requestFullscreen();
|
||||||
|
|
||||||
this.#args = {
|
this.#args = {
|
||||||
pageNumber: this.pdfViewer.currentPageNumber,
|
pageNumber: pdfViewer.currentPageNumber,
|
||||||
scaleValue: this.pdfViewer.currentScaleValue,
|
scaleValue: pdfViewer.currentScaleValue,
|
||||||
scrollMode: this.pdfViewer.scrollMode,
|
scrollMode: pdfViewer.scrollMode,
|
||||||
spreadMode: this.pdfViewer.spreadMode,
|
spreadMode: pdfViewer.spreadMode,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -89,12 +86,18 @@ class PDFPresentationMode {
|
|||||||
return true;
|
return true;
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
this.#removeFullscreenChangeListeners();
|
this.#removeFullscreenChangeListeners();
|
||||||
this.#resetSwitchInProgress();
|
this.#notifyStateChange(PresentationModeState.NORMAL);
|
||||||
this.#notifyStateChange();
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get active() {
|
||||||
|
return (
|
||||||
|
this.#state === PresentationModeState.CHANGING ||
|
||||||
|
this.#state === PresentationModeState.FULLSCREEN
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#mouseWheel(evt) {
|
#mouseWheel(evt) {
|
||||||
if (!this.active) {
|
if (!this.active) {
|
||||||
return;
|
return;
|
||||||
@ -134,31 +137,14 @@ class PDFPresentationMode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#notifyStateChange() {
|
#notifyStateChange(state) {
|
||||||
let state = PresentationModeState.NORMAL;
|
this.#state = state;
|
||||||
if (this.switchInProgress) {
|
|
||||||
state = PresentationModeState.CHANGING;
|
|
||||||
} else if (this.active) {
|
|
||||||
state = PresentationModeState.FULLSCREEN;
|
|
||||||
}
|
|
||||||
this.eventBus.dispatch("presentationmodechanged", {
|
|
||||||
source: this,
|
|
||||||
state,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#setSwitchInProgress() {
|
this.eventBus.dispatch("presentationmodechanged", { source: this, state });
|
||||||
this.switchInProgress = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#resetSwitchInProgress() {
|
|
||||||
this.switchInProgress = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#enter() {
|
#enter() {
|
||||||
this.active = true;
|
this.#notifyStateChange(PresentationModeState.FULLSCREEN);
|
||||||
this.#resetSwitchInProgress();
|
|
||||||
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
|
||||||
@ -187,9 +173,8 @@ class PDFPresentationMode {
|
|||||||
// Ensure that the correct page is scrolled into view when exiting
|
// Ensure that the correct page is scrolled into view when exiting
|
||||||
// Presentation Mode, by waiting until fullscreen mode is disabled.
|
// Presentation Mode, by waiting until fullscreen mode is disabled.
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.active = false;
|
|
||||||
this.#removeFullscreenChangeListeners();
|
this.#removeFullscreenChangeListeners();
|
||||||
this.#notifyStateChange();
|
this.#notifyStateChange(PresentationModeState.NORMAL);
|
||||||
|
|
||||||
this.pdfViewer.scrollMode = this.#args.scrollMode;
|
this.pdfViewer.scrollMode = this.#args.scrollMode;
|
||||||
this.pdfViewer.spreadMode = this.#args.spreadMode;
|
this.pdfViewer.spreadMode = this.#args.spreadMode;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user