Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include the state in the "presentationmodechanged" event, and remove the separate active/switchInProgress properties #12788

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
noContextMenuHandler,
normalizeWheelEventDirection,
parseQueryString,
PresentationModeState,
ProgressBar,
RendererType,
ScrollMode,
Expand Down Expand Up @@ -2620,14 +2619,8 @@ function webViewerNamedAction(evt) {
}
}

function webViewerPresentationModeChanged({ active, switchInProgress }) {
let state = PresentationModeState.NORMAL;
if (switchInProgress) {
state = PresentationModeState.CHANGING;
} else if (active) {
state = PresentationModeState.FULLSCREEN;
}
PDFViewerApplication.pdfViewer.presentationModeState = state;
function webViewerPresentationModeChanged(evt) {
PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
}

function webViewerSidebarViewChanged(evt) {
Expand Down
29 changes: 16 additions & 13 deletions web/pdf_cursor_tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

import { GrabToPan } from "./grab_to_pan.js";
import { PresentationModeState } from "./ui_utils.js";

const CursorTool = {
SELECT: 0, // The default value.
Expand Down Expand Up @@ -127,21 +128,23 @@ class PDFCursorTools {
});

this.eventBus._on("presentationmodechanged", evt => {
if (evt.switchInProgress) {
return;
}
let previouslyActive;

if (evt.active) {
previouslyActive = this.active;
switch (evt.state) {
case PresentationModeState.CHANGING:
break;
case PresentationModeState.FULLSCREEN: {
const previouslyActive = this.active;

this.switchTool(CursorTool.SELECT);
this.activeBeforePresentationMode = previouslyActive;
} else {
previouslyActive = this.activeBeforePresentationMode;
this.switchTool(CursorTool.SELECT);
this.activeBeforePresentationMode = previouslyActive;
break;
}
case PresentationModeState.NORMAL: {
const previouslyActive = this.activeBeforePresentationMode;

this.activeBeforePresentationMode = null;
this.switchTool(previouslyActive);
this.activeBeforePresentationMode = null;
this.switchTool(previouslyActive);
break;
}
}
});
}
Expand Down
4 changes: 3 additions & 1 deletion web/pdf_history.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import {
isValidRotation,
parseQueryString,
PresentationModeState,
waitOnEventOrTimeout,
} from "./ui_utils.js";

Expand Down Expand Up @@ -69,7 +70,8 @@ class PDFHistory {
// Ensure that we don't miss either a 'presentationmodechanged' or a
// 'pagesinit' event, by registering the listeners immediately.
this.eventBus._on("presentationmodechanged", evt => {
this._isViewerInPresentationMode = evt.active || evt.switchInProgress;
this._isViewerInPresentationMode =
evt.state !== PresentationModeState.NORMAL;
});
this.eventBus._on("pagesinit", () => {
this._isPagesLoaded = false;
Expand Down
35 changes: 29 additions & 6 deletions web/pdf_presentation_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import { normalizeWheelEventDelta } from "./ui_utils.js";
import { normalizeWheelEventDelta, PresentationModeState } from "./ui_utils.js";

const DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1500; // in ms
const DELAY_BEFORE_HIDING_CONTROLS = 3000; // in ms
Expand Down Expand Up @@ -183,11 +183,34 @@ class PDFPresentationMode {
* @private
*/
_notifyStateChange() {
this.eventBus.dispatch("presentationmodechanged", {
source: this,
active: this.active,
switchInProgress: !!this.switchInProgress,
});
let state = PresentationModeState.NORMAL;
if (this.switchInProgress) {
state = PresentationModeState.CHANGING;
} else if (this.active) {
state = PresentationModeState.FULLSCREEN;
}

if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
this.eventBus.dispatch("presentationmodechanged", {
source: this,
state,
});
} else {
this.eventBus.dispatch("presentationmodechanged", {
source: this,
state,
get active() {
throw new Error(
"Deprecated parameter: `active`, please use `state` instead."
);
},
get switchInProgress() {
throw new Error(
"Deprecated parameter: `switchInProgress`, please use `state` instead."
);
},
});
}
}

/**
Expand Down
7 changes: 5 additions & 2 deletions web/pdf_sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import { NullL10n } from "./ui_utils.js";
import { NullL10n, PresentationModeState } from "./ui_utils.js";
import { RenderingStates } from "./pdf_rendering_queue.js";

const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
Expand Down Expand Up @@ -491,7 +491,10 @@ class PDFSidebar {

// Update the thumbnailViewer, if visible, when exiting presentation mode.
this.eventBus._on("presentationmodechanged", evt => {
if (!evt.active && !evt.switchInProgress && this.isThumbnailViewVisible) {
if (
evt.state === PresentationModeState.NORMAL &&
this.isThumbnailViewVisible
) {
this._updateThumbnailViewer();
}
});
Expand Down