JS -- Send events to the sandbox from annotation layer

This commit is contained in:
Calixte Denizet 2020-11-18 14:59:57 +01:00
parent 640a08444c
commit 6502ae889d
11 changed files with 647 additions and 113 deletions

View file

@ -258,6 +258,7 @@ const PDFViewerApplication = {
_wheelUnusedTicks: 0,
_idleCallbacks: new Set(),
_scriptingInstance: null,
_mouseState: Object.create(null),
// Called once when the document is loaded.
async initialize(appConfig) {
@ -501,6 +502,7 @@ const PDFViewerApplication = {
useOnlyCssZoom: AppOptions.get("useOnlyCssZoom"),
maxCanvasPixels: AppOptions.get("maxCanvasPixels"),
enableScripting: AppOptions.get("enableScripting"),
mouseState: this._mouseState,
});
pdfRenderingQueue.setViewer(this.pdfViewer);
pdfLinkService.setViewer(this.pdfViewer);
@ -1538,6 +1540,17 @@ const PDFViewerApplication = {
dispatchEventInSandbox
);
const mouseDown = event => {
this._mouseState.isDown = true;
};
const mouseUp = event => {
this._mouseState.isDown = false;
};
window.addEventListener("mousedown", mouseDown);
this._scriptingInstance.events.set("mousedown", mouseDown);
window.addEventListener("mouseup", mouseUp);
this._scriptingInstance.events.set("mouseup", mouseUp);
const dispatchEventName = generateRandomStringForSandbox(objects);
if (!this._contentLength) {