this._focusTimer = null; this.startOnFocusDelay(); event.preventDefault(); } break; case "blur": this.onBlur(); break; case "focus": this.onFocus(); break; case "unload": this.onUnload(); break; } }, onBlur() { this.disableDialog(); // If we blur while waiting to enable the buttons, just cancel the // timer to ensure the delay doesn't fire while not focused. if (this._focusTimer) { this._focusTimer.cancel(); this._focusTimer = null; } }, onFocus() { this.startOnFocusDelay(); }, onUnload() { this.focusTarget.removeEventListener("blur", this); this.focusTarget.removeEventListener("focus", this); this.focusTarget.removeEventListener("keyup", this, true); this.focusTarget.removeEventListener("keydown", this, true); this.focusTarget.removeEventListener("unload", this); if (this._focusTimer) { this._focusTimer.cancel(); this._focusTimer = null; } this.focusTarget = this.enableDialog = this.disableDialog = null; }, startOnFocusDelay() { if (this._focusTimer) { return; } this._focusTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); this._focusTimer.initWithCallback( () => { this.onFocusTimeout(); }, this.delayTime, Ci.nsITimer.TYPE_ONE_SHOT ); }, onFocusTimeout() { this._focusTimer = null; this.enableDialog(); }, }; function makeSafe(fn) { return function () { // The dialog could be gone by now (if the user closed it), // which makes it likely that the given fn might throw. try { fn(); } catch (e) { console.error(e); } }; } PK