Include the state in the "presentationmodechanged" event, and remove 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.
This commit is contained in:
Jonas Jenwald 2020-12-28 17:03:27 +01:00
parent 50303fc8f4
commit c185061757
5 changed files with 55 additions and 31 deletions

View file

@ -14,6 +14,7 @@
*/
import { GrabToPan } from "./grab_to_pan.js";
import { PresentationModeState } from "./ui_utils.js";
const CursorTool = {
SELECT: 0, // The default value.
@ -127,21 +128,23 @@ class PDFCursorTools {
});
this.eventBus._on("presentationmodechanged", evt => {
if (evt.switchInProgress) {
return;
}
let previouslyActive;
switch (evt.state) {
case PresentationModeState.CHANGING:
break;
case PresentationModeState.FULLSCREEN: {
const previouslyActive = this.active;
if (evt.active) {
previouslyActive = this.active;
this.switchTool(CursorTool.SELECT);
this.activeBeforePresentationMode = previouslyActive;
break;
}
case PresentationModeState.NORMAL: {
const previouslyActive = this.activeBeforePresentationMode;
this.switchTool(CursorTool.SELECT);
this.activeBeforePresentationMode = previouslyActive;
} else {
previouslyActive = this.activeBeforePresentationMode;
this.activeBeforePresentationMode = null;
this.switchTool(previouslyActive);
this.activeBeforePresentationMode = null;
this.switchTool(previouslyActive);
break;
}
}
});
}