mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 17:30:09 +02:00
[JS] Some functions (print, alert,...) must be called only after a user activation
- Some events, which require a user interaction, will allow those functions to be called. But after few seconds, if there are no more user interaction, it won't be possible anymore. The idea is to give an opportunity to the user to leave the pdf. - Disable print function when we're printing, the same with saving and disallow to save on open events.
This commit is contained in:
parent
27b251ac99
commit
0de804a256
4 changed files with 103 additions and 5 deletions
|
@ -13,6 +13,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { USERACTIVATION_CALLBACKID } from "./doc.js";
|
||||
|
||||
const USERACTIVATION_MAXTIME_VALIDITY = 5000;
|
||||
|
||||
class Event {
|
||||
constructor(data) {
|
||||
this.change = data.change || "";
|
||||
|
@ -39,10 +43,11 @@ class Event {
|
|||
}
|
||||
|
||||
class EventDispatcher {
|
||||
constructor(document, calculationOrder, objects) {
|
||||
constructor(document, calculationOrder, objects, externalCall) {
|
||||
this._document = document;
|
||||
this._calculationOrder = calculationOrder;
|
||||
this._objects = objects;
|
||||
this._externalCall = externalCall;
|
||||
|
||||
this._document.obj._eventDispatcher = this;
|
||||
this._isCalculating = false;
|
||||
|
@ -66,6 +71,14 @@ class EventDispatcher {
|
|||
return `${prefix}${event.change}${postfix}`;
|
||||
}
|
||||
|
||||
userActivation() {
|
||||
this._document.obj._userActivation = true;
|
||||
this._externalCall("setTimeout", [
|
||||
USERACTIVATION_CALLBACKID,
|
||||
USERACTIVATION_MAXTIME_VALIDITY,
|
||||
]);
|
||||
}
|
||||
|
||||
dispatch(baseEvent) {
|
||||
const id = baseEvent.id;
|
||||
if (!(id in this._objects)) {
|
||||
|
@ -76,19 +89,27 @@ class EventDispatcher {
|
|||
event.name = baseEvent.name;
|
||||
}
|
||||
if (id === "doc") {
|
||||
if (event.name === "Open") {
|
||||
const eventName = event.name;
|
||||
if (eventName === "Open") {
|
||||
// Before running the Open event, we format all the fields
|
||||
// (see bug 1766987).
|
||||
this.formatAll();
|
||||
}
|
||||
if (
|
||||
!["DidPrint", "DidSave", "WillPrint", "WillSave"].includes(eventName)
|
||||
) {
|
||||
this.userActivation();
|
||||
}
|
||||
this._document.obj._dispatchDocEvent(event.name);
|
||||
} else if (id === "page") {
|
||||
this.userActivation();
|
||||
this._document.obj._dispatchPageEvent(
|
||||
event.name,
|
||||
baseEvent.actions,
|
||||
baseEvent.pageNumber
|
||||
);
|
||||
} else if (id === "app" && baseEvent.name === "ResetForm") {
|
||||
this.userActivation();
|
||||
for (const fieldId of baseEvent.ids) {
|
||||
const obj = this._objects[fieldId];
|
||||
obj?.obj._reset();
|
||||
|
@ -102,6 +123,8 @@ class EventDispatcher {
|
|||
const event = (globalThis.event = new Event(baseEvent));
|
||||
let savedChange;
|
||||
|
||||
this.userActivation();
|
||||
|
||||
if (source.obj._isButton()) {
|
||||
source.obj._id = id;
|
||||
event.value = source.obj._getExportValue(event.value);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue