Merge pull request #14606 from Snuffleupagus/standard-FullscreenAPI
Only support the standard, unprefixed, Fullscreen API in the default viewer
This commit is contained in:
commit
620174a23c
@ -671,14 +671,7 @@ const PDFViewerApplication = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
get supportsFullscreen() {
|
get supportsFullscreen() {
|
||||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
return shadow(this, "supportsFullscreen", document.fullscreenEnabled);
|
||||||
return shadow(this, "supportsFullscreen", document.fullscreenEnabled);
|
|
||||||
}
|
|
||||||
return shadow(
|
|
||||||
this,
|
|
||||||
"supportsFullscreen",
|
|
||||||
document.fullscreenEnabled || document.webkitFullscreenEnabled
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
get supportsIntegratedFind() {
|
get supportsIntegratedFind() {
|
||||||
|
@ -63,28 +63,19 @@ class PDFPresentationMode {
|
|||||||
* @returns {boolean} Indicating if the request was successful.
|
* @returns {boolean} Indicating if the request was successful.
|
||||||
*/
|
*/
|
||||||
request() {
|
request() {
|
||||||
if (this.switchInProgress || this.active || !this.pdfViewer.pagesCount) {
|
if (
|
||||||
|
this.switchInProgress ||
|
||||||
|
this.active ||
|
||||||
|
!this.pdfViewer.pagesCount ||
|
||||||
|
!this.container.requestFullscreen
|
||||||
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this._addFullscreenChangeListeners();
|
this.#addFullscreenChangeListeners();
|
||||||
this._setSwitchInProgress();
|
this.#setSwitchInProgress();
|
||||||
this._notifyStateChange();
|
this.#notifyStateChange();
|
||||||
|
|
||||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
this.container.requestFullscreen();
|
||||||
if (this.container.requestFullscreen) {
|
|
||||||
this.container.requestFullscreen();
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (this.container.requestFullscreen) {
|
|
||||||
this.container.requestFullscreen();
|
|
||||||
} else if (this.container.webkitRequestFullscreen) {
|
|
||||||
this.container.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.args = {
|
this.args = {
|
||||||
pageNumber: this.pdfViewer.currentPageNumber,
|
pageNumber: this.pdfViewer.currentPageNumber,
|
||||||
@ -92,14 +83,10 @@ class PDFPresentationMode {
|
|||||||
scrollMode: this.pdfViewer.scrollMode,
|
scrollMode: this.pdfViewer.scrollMode,
|
||||||
spreadMode: this.pdfViewer.spreadMode,
|
spreadMode: this.pdfViewer.spreadMode,
|
||||||
};
|
};
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
#mouseWheel(evt) {
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
_mouseWheel(evt) {
|
|
||||||
if (!this.active) {
|
if (!this.active) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -122,13 +109,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()
|
||||||
@ -139,17 +126,7 @@ class PDFPresentationMode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get isFullscreen() {
|
#notifyStateChange() {
|
||||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
|
||||||
return !!document.fullscreenElement;
|
|
||||||
}
|
|
||||||
return !!(document.fullscreenElement || document.webkitIsFullScreen);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
_notifyStateChange() {
|
|
||||||
let state = PresentationModeState.NORMAL;
|
let state = PresentationModeState.NORMAL;
|
||||||
if (this.switchInProgress) {
|
if (this.switchInProgress) {
|
||||||
state = PresentationModeState.CHANGING;
|
state = PresentationModeState.CHANGING;
|
||||||
@ -168,37 +145,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 +179,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 +189,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 +197,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 +207,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 +237,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 +253,7 @@ class PDFPresentationMode {
|
|||||||
}, DELAY_BEFORE_HIDING_CONTROLS);
|
}, DELAY_BEFORE_HIDING_CONTROLS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
#hideControls() {
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
_hideControls() {
|
|
||||||
if (!this.controlsTimeout) {
|
if (!this.controlsTimeout) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -310,18 +264,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 +330,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 +348,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,44 +368,21 @@ class PDFPresentationMode {
|
|||||||
delete this.touchSwipeBind;
|
delete this.touchSwipeBind;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
#fullscreenChange() {
|
||||||
* @private
|
if (/* isFullscreen = */ document.fullscreenElement) {
|
||||||
*/
|
this.#enter();
|
||||||
_fullscreenChange() {
|
|
||||||
if (this.isFullscreen) {
|
|
||||||
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")) {
|
|
||||||
window.addEventListener(
|
|
||||||
"webkitfullscreenchange",
|
|
||||||
this.fullscreenChangeBind
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
#removeFullscreenChangeListeners() {
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
_removeFullscreenChangeListeners() {
|
|
||||||
window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
|
window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
|
||||||
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
|
|
||||||
window.removeEventListener(
|
|
||||||
"webkitfullscreenchange",
|
|
||||||
this.fullscreenChangeBind
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete this.fullscreenChangeBind;
|
delete this.fullscreenChangeBind;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user