Bug 502239 - fix focusElement() misuse. r=enn

This commit is contained in:
Dão Gottwald 2009-08-10 18:27:10 +02:00
parent 37602b8380
commit 1e32437863
5 changed files with 23 additions and 14 deletions

View File

@ -1211,9 +1211,9 @@ function delayedStartup(isLoadingBlank, mustLoadSidebar) {
window.addEventListener("fullscreen", onFullScreen, true);
if (isLoadingBlank && gURLBar && isElementVisible(gURLBar))
focusElement(gURLBar);
gURLBar.focus();
else
focusElement(content);
gBrowser.selectedBrowser.focus();
if (gURLBar)
gURLBar.emptyText = gURLBarEmptyText.value;

View File

@ -132,7 +132,7 @@
else
loadURI(url, null, postData, true /* allow third party fixup */);
focusElement(content);
gBrowser.selectedBrowser.focus();
]]></body>
</method>

View File

@ -95,16 +95,29 @@ function getBoolPref ( prefname, def )
// window itself.
function focusElement(aElement)
{
var msg;
// if a content window, focus the <browser> instead as window.focus()
// raises the window
if (aElement instanceof Window) {
var browser = getBrowserFromContentWindow(aElement);
if (browser)
browser.focus();
if (!browser)
throw "aElement is not a content window";
browser.focus();
msg = "focusElement(content) is deprecated. Use gBrowser.selectedBrowser.focus() instead.";
}
else {
aElement.focus();
msg = "focusElement(element) is deprecated. Use element.focus() instead.";
}
var scriptError = Components.classes["@mozilla.org/scripterror;1"]
.createInstance(Components.interfaces.nsIScriptError);
scriptError.init(msg, document.location.href, null, null,
null, scriptError.warningFlag, "chrome javascript");
Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService)
.logMessage(scriptError);
}
// openUILink handles clicks on UI elements that cause URLs to load.
@ -253,14 +266,10 @@ function openUILinkIn( url, where, allowThirdPartyFixup, postData, referrerUrl )
// resulted in a new frontmost window (e.g. "javascript:window.open('');").
var fm = Components.classes["@mozilla.org/focus-manager;1"].
getService(Components.interfaces.nsIFocusManager);
if (window == fm.activeWindow) {
if (window == fm.activeWindow)
w.content.focus();
}
else {
let browser = w.getBrowserFromContentWindow(w.content);
if (browser)
browser.focus();
}
else
w.gBrowser.selectedBrowser.focus();
}
// Used as an onclick handler for UI elements with link-like behavior.

View File

@ -116,7 +116,7 @@
// Focus the location bar
if (mainWindow.gURLBar)
mainWindow.focusElement(mainWindow.gURLBar);
mainWindow.gURLBar.focus();
}
]]></script>
</head>

View File

@ -50,7 +50,7 @@ function test() {
browser.removeEventListener("load", arguments.callee, true);
// ensure that the URL bar is not focused initially
focusElement(content);
browser.focus();
isnot(document.commandDispatcher.focusedElement, gURLBar.inputField,
"URL Bar should not be focused before entering the private browsing mode");
// ensure that the URL bar is not empty initially