Update the events, used with scripting, to use lower-case names and avoid using DOM events internally in the viewer

For DOM events all event names are lower-case, and the newly added PDF.js scripting-events thus "stick out" quite a bit. Even more so, considering that our internal `eventBus`-events follow the same naming convention.
Hence this patch, which changes the "updateFromSandbox"/"dispatchEventInSandbox" events to be lower-case instead.

Furthermore, using DOM events for communication *within* the PDF.js code itself (i.e. between code in `web/app.js` and `src/display/annotation_layer.js/`) feels *really* out of place.
That's exactly the reason that we have the `EventBus` abstraction, since it allowed us to remove prior use of DOM events, and this patch thus re-factors the code to make use of the `EventBus` instead for scripting-related events.
Obviously for events targeting a *specific element* using DOM events is still fine, but the "updatefromsandbox"/"dispatcheventinsandbox" ones should be using the `EventBus` internally.

*Drive-by change:* Use the `BaseViewer.currentScaleValue` setter unconditionally in `PDFViewerApplication._initializeJavaScript`, since it accepts either a string or a number.
This commit is contained in:
Jonas Jenwald 2020-12-17 14:10:56 +01:00
parent e2b6d79dee
commit eff4d8182d
4 changed files with 136 additions and 130 deletions

View file

@ -255,12 +255,12 @@ class FirefoxComDataRangeTransport extends PDFDataRangeTransport {
}
class FirefoxScripting {
static createSandbox(data) {
static async createSandbox(data) {
return new Promise(resolve => {
FirefoxCom.request("createSandbox", data, resolve);
}).then(success => {
if (!success) {
throw new Error("Cannot start sandbox");
throw new Error("Cannot create sandbox.");
}
});
}