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); window.addEventListener("fullscreen", onFullScreen, true);
if (isLoadingBlank && gURLBar && isElementVisible(gURLBar)) if (isLoadingBlank && gURLBar && isElementVisible(gURLBar))
focusElement(gURLBar); gURLBar.focus();
else else
focusElement(content); gBrowser.selectedBrowser.focus();
if (gURLBar) if (gURLBar)
gURLBar.emptyText = gURLBarEmptyText.value; gURLBar.emptyText = gURLBarEmptyText.value;

View File

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

View File

@ -95,16 +95,29 @@ function getBoolPref ( prefname, def )
// window itself. // window itself.
function focusElement(aElement) function focusElement(aElement)
{ {
var msg;
// if a content window, focus the <browser> instead as window.focus() // if a content window, focus the <browser> instead as window.focus()
// raises the window // raises the window
if (aElement instanceof Window) { if (aElement instanceof Window) {
var browser = getBrowserFromContentWindow(aElement); var browser = getBrowserFromContentWindow(aElement);
if (browser) if (!browser)
browser.focus(); throw "aElement is not a content window";
browser.focus();
msg = "focusElement(content) is deprecated. Use gBrowser.selectedBrowser.focus() instead.";
} }
else { else {
aElement.focus(); 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. // 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('');"). // resulted in a new frontmost window (e.g. "javascript:window.open('');").
var fm = Components.classes["@mozilla.org/focus-manager;1"]. var fm = Components.classes["@mozilla.org/focus-manager;1"].
getService(Components.interfaces.nsIFocusManager); getService(Components.interfaces.nsIFocusManager);
if (window == fm.activeWindow) { if (window == fm.activeWindow)
w.content.focus(); w.content.focus();
} else
else { w.gBrowser.selectedBrowser.focus();
let browser = w.getBrowserFromContentWindow(w.content);
if (browser)
browser.focus();
}
} }
// Used as an onclick handler for UI elements with link-like behavior. // Used as an onclick handler for UI elements with link-like behavior.

View File

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

View File

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