From 5d8f7afa5ca0371f31ec23f8b1401d1d16241d2e Mon Sep 17 00:00:00 2001 From: "bsmedberg%covad.net" Date: Tue, 16 Aug 2005 13:25:40 +0000 Subject: [PATCH] Bug 302136 - Two clicks on "Install Now" button are necessary to install an extension r=beng --- .../xpinstall/content/xpinstallConfirm.js | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/toolkit/mozapps/xpinstall/content/xpinstallConfirm.js b/toolkit/mozapps/xpinstall/content/xpinstallConfirm.js index 1bb7fa4cc0f..dddae54d966 100644 --- a/toolkit/mozapps/xpinstall/content/xpinstallConfirm.js +++ b/toolkit/mozapps/xpinstall/content/xpinstallConfirm.js @@ -100,22 +100,33 @@ XPInstallConfirm.init = function () okButton.label = bundle.getFormattedString("installButtonDisabledLabel", [_installCountdown.toFixed(1)]); } - function myfocus() { + function myfocus(event) { if (_installCountdownInterval == -1) _installCountdownInterval = setInterval(okButtonCountdown, 100); + + // When the dialog is focused, we get *three* focus events, two targeted + // at the document itself and one at the internal XUL element. Only reset + // the counter if the document itself is the target. + if (event.target == document) { + _installCountdown = 2; + okButton.label = bundle.getFormattedString("installButtonDisabledLabel", [_installCountdown.toFixed(1)]); + okButton.disabled = true; + } } - function myblur() { - if (_installCountdownInterval != -1) + function myblur() { + // When the dialog is blurred, we only get one blur event, targeted + // a the currently focused XUL element. We cannot distinguish between + // an internal focus change and a window change. Stop the countdown, but + // don't disable. + if (_installCountdownInterval != -1) { clearInterval(_installCountdownInterval); - - _installCountdown = 2; - okButton.label = bundle.getFormattedString("installButtonDisabledLabel", [_installCountdown.toFixed(1)]); - okButton.disabled = true; + _installCountdownInterval = -1; + } } - window.addEventListener("focus", myfocus, true); - window.addEventListener("blur", myblur, true); + document.addEventListener("focus", myfocus, true); + document.addEventListener("blur", myblur, true); _installCountdownInterval = setInterval(okButtonCountdown, 100); }