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

@ -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
@ -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."
);
},
});
}
}
/**