Skip to content

Commit

Permalink
Include the state in the "presentationmodechanged" event, and remov…
Browse files Browse the repository at this point in the history
…e the separate `active`/`switchInProgress` properties

Given that we already have a `PresentationModeState`-enumeration, we should use that with the "presentationmodechanged" event rather than including separate properties. Note that this new behaviour, of including an enumeration-value in the event, is consistent with lots of other existing viewer-events.

To hopefully avoid issues in custom implementations of the default viewer, any attempt to access the removed properties will now throw.
  • Loading branch information
Snuffleupagus committed Dec 28, 2020
1 parent df53e78 commit f3e31a7
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 31 deletions.
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(
"Removed parameter: `active`, please use `state` instead."
);
},
get switchInProgress() {
throw new Error(
"Removed 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

0 comments on commit f3e31a7

Please sign in to comment.