Bug 450554 - focus restoring for panels uses a wonky timeout during popuphiding, should wait for popuphidden instead. r=neil

This commit is contained in:
Dão Gottwald 2008-10-10 13:47:17 +02:00
Родитель b04bd307c2
Коммит 1ac04835d0
1 изменённых файлов: 20 добавлений и 12 удалений

Просмотреть файл

@ -221,8 +221,10 @@
this._prevFocus = document.commandDispatcher.focusedElement; this._prevFocus = document.commandDispatcher.focusedElement;
if (!this._prevFocus) // Content window has focus if (!this._prevFocus) // Content window has focus
this._prevFocus = document.commandDispatcher.focusedWindow; this._prevFocus = document.commandDispatcher.focusedWindow;
} catch (ex) {} } catch (ex) {
]]></handler> this._prevFocus = document.activeElement;
}
]]></handler>
<handler event="popupshown"><![CDATA[ <handler event="popupshown"><![CDATA[
// Fire event for accessibility APIs // Fire event for accessibility APIs
var alertEvent = document.createEvent("Events"); var alertEvent = document.createEvent("Events");
@ -230,27 +232,33 @@
this.dispatchEvent(alertEvent); this.dispatchEvent(alertEvent);
]]></handler> ]]></handler>
<handler event="popuphiding"><![CDATA[ <handler event="popuphiding"><![CDATA[
function restoreFocusIfInPanel(aPanel, currentFocus, prevFocus) { try {
this._currentFocus = document.commandDispatcher.focusedElement;
} catch (e) {
this._currentFocus = document.activeElement;
}
]]></handler>
<handler event="popuphidden"><![CDATA[
var currentFocus = this._currentFocus;
var prevFocus = this._prevFocus;
this._currentFocus = null;
this._prevFocus = null;
if (prevFocus && currentFocus && this.getAttribute("norestorefocus") != "true") {
// Try to restore focus
try { try {
if (document.commandDispatcher.focusedWindow != window) if (document.commandDispatcher.focusedWindow != window)
return; // Focus has already been set to a window outside of this panel return; // Focus has already been set to a window outside of this panel
} catch(ex) {} } catch(ex) {}
var ancestorOfFocus = currentFocus; while (currentFocus) {
while (ancestorOfFocus) { if (currentFocus == this) {
if (ancestorOfFocus == aPanel) {
// Focus was set on an element inside this panel, // Focus was set on an element inside this panel,
// so we need to move it back to where it was previously // so we need to move it back to where it was previously
prevFocus.focus(); prevFocus.focus();
return; return;
} }
ancestorOfFocus = ancestorOfFocus.parentNode; currentFocus = currentFocus.parentNode;
} }
} }
try {
if (this._prevFocus && this.getAttribute("norestorefocus") != "true")
setTimeout(restoreFocusIfInPanel, 0, this, document.commandDispatcher.focusedElement,
this._prevFocus);
} catch(ex) { }
]]></handler> ]]></handler>
</handlers> </handlers>
</binding> </binding>