Bug 743877 - tab switching shouldn't occur off a timeout; r=gavin

This commit is contained in:
Tim Taubert 2012-05-05 01:32:34 +02:00
parent 948aeb036b
commit f15f57520c
3 changed files with 28 additions and 13 deletions

View File

@ -183,15 +183,13 @@ function test_tabbox_focus()
var tabbox = $("tabbox-nofocus");
var tab = $("tab-nofocus");
tab.addEventListener("focus", function () {
tab.removeEventListener("focus", arguments.callee, true);
when_tab_focused(tab, function () {
ok(document.activeElement, tab, "focus in tab with no focusable elements");
tabbox.selectedIndex = 0;
$("tab-nofocus-button").focus();
tab.addEventListener("focus", function () {
tab.removeEventListener("focus", arguments.callee, true);
when_tab_focused(tab, function () {
ok(document.activeElement, tab, "focus in tab with no focusable elements, but with something in another tab focused");
var textboxExtra = $("textbox-extra");
@ -205,14 +203,21 @@ function test_tabbox_focus()
tabbox.selectedIndex = 0;
textboxExtra.hidden = false;
synthesizeMouseAtCenter(tab, { });
}, true);
});
synthesizeMouseAtCenter(tab, { });
}, true);
});
synthesizeMouseAtCenter(tab, { });
}
function when_tab_focused(tab, callback) {
tab.addEventListener("focus", function onFocused() {
tab.removeEventListener("focus", onFocused, true);
SimpleTest.executeSoon(callback);
}, true);
}
]]>
</script>

View File

@ -791,13 +791,23 @@
return;
if (this != this.parentNode.selectedItem) { // Not selected yet
// Select new tab after short delay so that PostHandleEvent() doesn't see
// the tab as selected yet, otherwise it will focus the tab for us --
// the CSS for tab has -moz-user-focus: normal only for selected="true".
function setTab(tab) {
tab.parentNode._selectNewTab(tab);
// Call this before setting the 'ignorefocus' attribute because this
// will pass on focus if the formerly selected tab was focused as well.
this.parentNode._selectNewTab(this);
var isTabFocused = false;
try {
isTabFocused = (document.commandDispatcher.focusedElement == this);
} catch (e) {}
// Set '-moz-user-focus' to 'ignore' so that PostHandleEvent() can't
// focus the tab; we only want tabs to be focusable by the mouse if
// they are already focused. After a short timeout we'll reset
// '-moz-user-focus' so that tabs can be focused by keyboard again.
if (!isTabFocused) {
this.setAttribute("ignorefocus", "true");
setTimeout(function (tab) tab.removeAttribute("ignorefocus"), 0, this);
}
setTimeout(setTab, 0, this);
}
// Otherwise this tab is already selected and we will fall
// through to mousedown behavior which sets focus on the current tab,

View File

@ -652,7 +652,7 @@ tab {
-moz-box-pack: center;
}
tab[selected="true"] {
tab[selected="true"]:not([ignorefocus="true"]) {
-moz-user-focus: normal;
}