From 54df769994759fb00610299fcbfa6e99ab6c3a42 Mon Sep 17 00:00:00 2001 From: Neil Deakin Date: Thu, 9 Dec 2010 13:20:00 -0800 Subject: [PATCH] Bug 617872 - Focus manager allows F6 to focus elements inside non-focusable iframes/browsers. r=smaug, a=blocking --- browser/base/content/test/browser_tabfocus.js | 18 +++++++++++++++++- dom/base/nsFocusManager.cpp | 11 +++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/browser/base/content/test/browser_tabfocus.js b/browser/base/content/test/browser_tabfocus.js index f63672819aba..01e1b65dc450 100644 --- a/browser/base/content/test/browser_tabfocus.js +++ b/browser/base/content/test/browser_tabfocus.js @@ -123,6 +123,22 @@ function test() { browser1.contentWindow, null, true, "focusedWindow after tab switch from no focus to no focus"); + gURLBar.focus(); + _browser_tabfocus_test_events = ""; + _browser_tabfocus_test_lastfocus = gURLBar; + _browser_tabfocus_test_lastfocuswindow = window; + + expectFocusShift(function () EventUtils.synthesizeKey("VK_F6", { }), + browser1.contentWindow, browser1.contentDocument.documentElement, + true, "switch document forward with f6"); + EventUtils.synthesizeKey("VK_F6", { }); + is(fm.focusedWindow, window, "switch document forward again with f6"); + + browser1.style.MozUserFocus = "ignore"; + browser1.clientWidth; + EventUtils.synthesizeKey("VK_F6", { }); + is(fm.focusedWindow, window, "switch document forward again with f6 when browser non-focusable"); + window.addEventListener("focus", _browser_tabfocus_test_eventOccured, true); window.addEventListener("blur", _browser_tabfocus_test_eventOccured, true); @@ -207,7 +223,7 @@ function expectFocusShift(callback, expectedWindow, expectedElement, focusChange "focus: " + windowid + "-window"; } - if (expectedElement) { + if (expectedElement && expectedElement != expectedElement.ownerDocument.documentElement) { if (expectedEvents) expectedEvents += " "; expectedEvents += "focus: " + getId(expectedElement); diff --git a/dom/base/nsFocusManager.cpp b/dom/base/nsFocusManager.cpp index e1f364f7f20b..8ebfa781f3c4 100644 --- a/dom/base/nsFocusManager.cpp +++ b/dom/base/nsFocusManager.cpp @@ -2878,8 +2878,15 @@ nsFocusManager::GetRootForFocus(nsPIDOMWindow* aWindow, if (aIsForDocNavigation) { nsCOMPtr docContent = do_QueryInterface(aWindow->GetFrameElementInternal()); - if (docContent && docContent->Tag() == nsGkAtoms::iframe) - return nsnull; + // document navigation skips iframes and frames that are specifically non-focusable + if (docContent) { + if (docContent->Tag() == nsGkAtoms::iframe) + return nsnull; + + nsIFrame* frame = docContent->GetPrimaryFrame(); + if (!frame || !frame->IsFocusable(nsnull, 0)) + return nsnull; + } } else { PRInt32 itemType;