Bug 339710: fix keywords/fixup when using the Go button (regression from bug 279687), and tidy up/remove some crufty code, r=mconnor

This commit is contained in:
gavin%gavinsharp.com 2006-06-26 17:40:49 +00:00
Родитель 78e425ba44
Коммит 478b35f99d
3 изменённых файлов: 62 добавлений и 73 удалений

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

@ -1945,22 +1945,28 @@ function loadURI(uri, referrer, postData, allowThirdPartyFixup)
}
}
function BrowserLoadURL(aTriggeringEvent, aPostData)
{
function BrowserLoadURL(aTriggeringEvent, aPostData) {
var url = gURLBar.value;
if (gBrowser.localName == "tabbrowser" &&
aTriggeringEvent && 'altKey' in aTriggeringEvent &&
aTriggeringEvent.altKey) {
if (aTriggeringEvent instanceof MouseEvent) {
// We have a mouse event (from the go button), so use the standard
// UI link behaviors
openUILink(url, aTriggeringEvent, false, false,
true /* allow third party fixup */, aPostData);
return;
}
if (aTriggeringEvent && aTriggeringEvent.altKey) {
handleURLBarRevert();
content.focus();
gBrowser.loadOneTab(url, null, null, aPostData, false,
true /* allow third party fixup */);
gURLBar.value = url;
aTriggeringEvent.preventDefault();
aTriggeringEvent.stopPropagation();
}
else
else
loadURI(url, null, aPostData, true /* allow third party fixup */);
content.focus();
}
@ -2275,8 +2281,7 @@ function handleURLBarRevert()
return !isScrolling;
}
function handleURLBarCommand(aTriggeringEvent)
{
function handleURLBarCommand(aTriggeringEvent) {
var postData = { };
canonizeUrl(aTriggeringEvent, postData);
@ -2290,48 +2295,49 @@ function handleURLBarCommand(aTriggeringEvent)
BrowserLoadURL(aTriggeringEvent, postData.value);
}
function canonizeUrl(aTriggeringEvent, aPostDataRef)
{
function canonizeUrl(aTriggeringEvent, aPostDataRef) {
if (!gURLBar || !gURLBar.value)
return;
var url = gURLBar.value;
// Prevent suffix when already exists www , http , /
if (!/^(www|http)|\/\s*$/i.test(url) && aTriggeringEvent) {
var suffix = null;
// Only add the suffix when the URL bar value isn't already "URL-like".
// Since this function is called from handleURLBarCommand, which receives
// both mouse (from the go button) and keyboard events, we also make sure not
// to do the fixup unless we get a keyboard event, to match user expectations.
if (!/^(www|http)|\/\s*$/i.test(url) &&
(aTriggeringEvent instanceof KeyEvent)) {
#ifdef XP_MACOSX
var accelPressed = 'metaKey' in aTriggeringEvent &&
aTriggeringEvent.metaKey;
var accel = aTriggeringEvent.metaKey;
#else
var accelPressed = 'ctrlKey' in aTriggeringEvent &&
aTriggeringEvent.ctrlKey;
var accel = aTriggeringEvent.ctrlKey;
#endif
var shiftPressed = 'shiftKey' in aTriggeringEvent &&
aTriggeringEvent.shiftKey;
var shift = aTriggeringEvent.shiftKey;
if (accelPressed && shiftPressed)
suffix = ".org/";
var suffix = "";
else if (accelPressed)
{
try {
suffix = gPrefService.getCharPref("browser.fixup.alternate.suffix");
if (suffix.charAt(suffix.length - 1) != '/')
suffix += "/";
}
catch(e) {
suffix = ".com/";
}
switch (true) {
case (accel && shift):
suffix = ".org/";
break;
case (shift):
suffix = ".net/";
break;
case (accel):
try {
suffix = gPrefService.getCharPref("browser.fixup.alternate.suffix");
if (suffix.charAt(suffix.length - 1) != "/")
suffix += "/";
} catch(e) {
suffix = ".com/";
}
break;
}
else if (shiftPressed)
suffix = ".net/";
if (suffix != null) {
if (suffix) {
// trim leading/trailing spaces (bug 233205)
url = url.replace( /^\s+/, "");
url = url.replace( /\s+$/, "");
url = url.replace(/^\s+/, "").replace(/\s+$/, "");
// Tack www. and suffix on. If user has appended directories, insert
// suffix before them (bug 279035). Be careful not to get two slashes.
var firstSlash = url.indexOf("/");

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

@ -278,7 +278,7 @@
<toolbarbutton id="go-button"
chromedir="&locale.dir;"
label="&goButton.label;"
onclick="if (event.button != 2) openUILink(gURLBar.value, event);"
onclick="handleURLBarCommand(event);"
ondragover="nsDragAndDrop.dragOver(event, goButtonObserver);"
ondragdrop="nsDragAndDrop.drop(event, goButtonObserver);"
ondragexit="nsDragAndDrop.dragExit(event, goButtonObserver);"

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

@ -67,23 +67,16 @@ function goToggleToolbar( id, elementID )
function getTopWin()
{
var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
var topWindowOfType = windowManagerInterface.getMostRecentWindow( "navigator:browser" );
if (topWindowOfType) {
return topWindowOfType;
}
return null;
var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1']
.getService(Components.interfaces.nsIWindowMediator);
return windowManager.getMostRecentWindow("navigator:browser");
}
function openTopWin( url )
{
openUILink(url, {})
openUILink(url, {})
}
function getBoolPref ( prefname, def )
{
try {
@ -95,13 +88,12 @@ function getBoolPref ( prefname, def )
return def;
}
}
// openUILink handles clicks on UI elements that cause URLs to load.
function openUILink( url, e, ignoreButton, ignoreAlt )
function openUILink( url, e, ignoreButton, ignoreAlt, allowKeywordFixup, postData )
{
var where = whereToOpenLink(e, ignoreButton, ignoreAlt);
openUILinkIn(url, where, false);
openUILinkIn(url, where, allowKeywordFixup, postData);
}
@ -179,45 +171,37 @@ function whereToOpenLink( e, ignoreButton, ignoreAlt )
* I Feel Lucky are allowed to interpret this URL. This parameter may be
* undefined, which is treated as false.
*/
function openUILinkIn( url, where, allowThirdPartyFixup )
function openUILinkIn( url, where, allowThirdPartyFixup, postData )
{
if (!where)
if (!where || !url)
return;
if ((url == null) || (url == ""))
return;
// xlate the URL if necessary
if (url.indexOf("urn:") == 0) {
url = xlateURL(url); // does RDF urn expansion
}
// avoid loading "", since this loads a directory listing
if (url == "") {
url = "about:blank";
}
if (where == "save") {
saveURL(url, null, null, true);
return;
}
var w = (where == "window") ? null : getTopWin();
if (!w) {
openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no", url);
var w = getTopWin();
if (!w || where == "window") {
openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no", url,
null, null, postData, allowThirdPartyFixup);
return;
}
var browser = w.document.getElementById("content");
var loadInBackground = getBoolPref("browser.tabs.loadBookmarksInBackground", false);
switch (where) {
case "current":
browser.loadURI(url);
w.loadURI(url, null, postData, allowThirdPartyFixup);
w.content.focus();
break;
case "tabshifted":
loadInBackground = !loadInBackground;
// fall through
case "tab":
browser.loadOneTab(url, null, null, null, loadInBackground,
var browser = w.getBrowser();
browser.loadOneTab(url, null, null, postData, loadInBackground,
allowThirdPartyFixup || false);
break;
}
@ -496,4 +480,3 @@ function buildHelpMenu()
else
checkForUpdates.removeAttribute("loading");
}