зеркало из https://github.com/mozilla/pjs.git
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:
Родитель
78e425ba44
Коммит
478b35f99d
|
@ -1945,22 +1945,28 @@ function loadURI(uri, referrer, postData, allowThirdPartyFixup)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function BrowserLoadURL(aTriggeringEvent, aPostData)
|
function BrowserLoadURL(aTriggeringEvent, aPostData) {
|
||||||
{
|
|
||||||
var url = gURLBar.value;
|
var url = gURLBar.value;
|
||||||
if (gBrowser.localName == "tabbrowser" &&
|
|
||||||
aTriggeringEvent && 'altKey' in aTriggeringEvent &&
|
if (aTriggeringEvent instanceof MouseEvent) {
|
||||||
aTriggeringEvent.altKey) {
|
// 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();
|
handleURLBarRevert();
|
||||||
content.focus();
|
content.focus();
|
||||||
gBrowser.loadOneTab(url, null, null, aPostData, false,
|
gBrowser.loadOneTab(url, null, null, aPostData, false,
|
||||||
true /* allow third party fixup */);
|
true /* allow third party fixup */);
|
||||||
gURLBar.value = url;
|
|
||||||
aTriggeringEvent.preventDefault();
|
aTriggeringEvent.preventDefault();
|
||||||
aTriggeringEvent.stopPropagation();
|
aTriggeringEvent.stopPropagation();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
loadURI(url, null, aPostData, true /* allow third party fixup */);
|
loadURI(url, null, aPostData, true /* allow third party fixup */);
|
||||||
|
|
||||||
content.focus();
|
content.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2275,8 +2281,7 @@ function handleURLBarRevert()
|
||||||
return !isScrolling;
|
return !isScrolling;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleURLBarCommand(aTriggeringEvent)
|
function handleURLBarCommand(aTriggeringEvent) {
|
||||||
{
|
|
||||||
var postData = { };
|
var postData = { };
|
||||||
canonizeUrl(aTriggeringEvent, postData);
|
canonizeUrl(aTriggeringEvent, postData);
|
||||||
|
|
||||||
|
@ -2290,48 +2295,49 @@ function handleURLBarCommand(aTriggeringEvent)
|
||||||
BrowserLoadURL(aTriggeringEvent, postData.value);
|
BrowserLoadURL(aTriggeringEvent, postData.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function canonizeUrl(aTriggeringEvent, aPostDataRef)
|
function canonizeUrl(aTriggeringEvent, aPostDataRef) {
|
||||||
{
|
|
||||||
if (!gURLBar || !gURLBar.value)
|
if (!gURLBar || !gURLBar.value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var url = gURLBar.value;
|
var url = gURLBar.value;
|
||||||
|
|
||||||
// Prevent suffix when already exists www , http , /
|
// Only add the suffix when the URL bar value isn't already "URL-like".
|
||||||
if (!/^(www|http)|\/\s*$/i.test(url) && aTriggeringEvent) {
|
// Since this function is called from handleURLBarCommand, which receives
|
||||||
var suffix = null;
|
// 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
|
#ifdef XP_MACOSX
|
||||||
var accelPressed = 'metaKey' in aTriggeringEvent &&
|
var accel = aTriggeringEvent.metaKey;
|
||||||
aTriggeringEvent.metaKey;
|
|
||||||
#else
|
#else
|
||||||
var accelPressed = 'ctrlKey' in aTriggeringEvent &&
|
var accel = aTriggeringEvent.ctrlKey;
|
||||||
aTriggeringEvent.ctrlKey;
|
|
||||||
#endif
|
#endif
|
||||||
var shiftPressed = 'shiftKey' in aTriggeringEvent &&
|
var shift = aTriggeringEvent.shiftKey;
|
||||||
aTriggeringEvent.shiftKey;
|
|
||||||
|
|
||||||
if (accelPressed && shiftPressed)
|
var suffix = "";
|
||||||
|
|
||||||
|
switch (true) {
|
||||||
|
case (accel && shift):
|
||||||
suffix = ".org/";
|
suffix = ".org/";
|
||||||
|
break;
|
||||||
else if (accelPressed)
|
case (shift):
|
||||||
{
|
suffix = ".net/";
|
||||||
|
break;
|
||||||
|
case (accel):
|
||||||
try {
|
try {
|
||||||
suffix = gPrefService.getCharPref("browser.fixup.alternate.suffix");
|
suffix = gPrefService.getCharPref("browser.fixup.alternate.suffix");
|
||||||
if (suffix.charAt(suffix.length - 1) != '/')
|
if (suffix.charAt(suffix.length - 1) != "/")
|
||||||
suffix += "/";
|
suffix += "/";
|
||||||
}
|
} catch(e) {
|
||||||
catch(e) {
|
|
||||||
suffix = ".com/";
|
suffix = ".com/";
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (shiftPressed)
|
if (suffix) {
|
||||||
suffix = ".net/";
|
|
||||||
|
|
||||||
if (suffix != null) {
|
|
||||||
// trim leading/trailing spaces (bug 233205)
|
// trim leading/trailing spaces (bug 233205)
|
||||||
url = url.replace( /^\s+/, "");
|
url = url.replace(/^\s+/, "").replace(/\s+$/, "");
|
||||||
url = url.replace( /\s+$/, "");
|
|
||||||
// Tack www. and suffix on. If user has appended directories, insert
|
// Tack www. and suffix on. If user has appended directories, insert
|
||||||
// suffix before them (bug 279035). Be careful not to get two slashes.
|
// suffix before them (bug 279035). Be careful not to get two slashes.
|
||||||
var firstSlash = url.indexOf("/");
|
var firstSlash = url.indexOf("/");
|
||||||
|
|
|
@ -278,7 +278,7 @@
|
||||||
<toolbarbutton id="go-button"
|
<toolbarbutton id="go-button"
|
||||||
chromedir="&locale.dir;"
|
chromedir="&locale.dir;"
|
||||||
label="&goButton.label;"
|
label="&goButton.label;"
|
||||||
onclick="if (event.button != 2) openUILink(gURLBar.value, event);"
|
onclick="handleURLBarCommand(event);"
|
||||||
ondragover="nsDragAndDrop.dragOver(event, goButtonObserver);"
|
ondragover="nsDragAndDrop.dragOver(event, goButtonObserver);"
|
||||||
ondragdrop="nsDragAndDrop.drop(event, goButtonObserver);"
|
ondragdrop="nsDragAndDrop.drop(event, goButtonObserver);"
|
||||||
ondragexit="nsDragAndDrop.dragExit(event, goButtonObserver);"
|
ondragexit="nsDragAndDrop.dragExit(event, goButtonObserver);"
|
||||||
|
|
|
@ -67,14 +67,9 @@ function goToggleToolbar( id, elementID )
|
||||||
|
|
||||||
function getTopWin()
|
function getTopWin()
|
||||||
{
|
{
|
||||||
var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
|
var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1']
|
||||||
var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
|
.getService(Components.interfaces.nsIWindowMediator);
|
||||||
var topWindowOfType = windowManagerInterface.getMostRecentWindow( "navigator:browser" );
|
return windowManager.getMostRecentWindow("navigator:browser");
|
||||||
|
|
||||||
if (topWindowOfType) {
|
|
||||||
return topWindowOfType;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function openTopWin( url )
|
function openTopWin( url )
|
||||||
|
@ -82,8 +77,6 @@ function openTopWin( url )
|
||||||
openUILink(url, {})
|
openUILink(url, {})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function getBoolPref ( prefname, def )
|
function getBoolPref ( prefname, def )
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
@ -96,12 +89,11 @@ function getBoolPref ( prefname, def )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// openUILink handles clicks on UI elements that cause URLs to load.
|
// 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);
|
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
|
* I Feel Lucky are allowed to interpret this URL. This parameter may be
|
||||||
* undefined, which is treated as false.
|
* undefined, which is treated as false.
|
||||||
*/
|
*/
|
||||||
function openUILinkIn( url, where, allowThirdPartyFixup )
|
function openUILinkIn( url, where, allowThirdPartyFixup, postData )
|
||||||
{
|
{
|
||||||
if (!where)
|
if (!where || !url)
|
||||||
return;
|
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") {
|
if (where == "save") {
|
||||||
saveURL(url, null, null, true);
|
saveURL(url, null, null, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var w = (where == "window") ? null : getTopWin();
|
var w = getTopWin();
|
||||||
if (!w) {
|
|
||||||
openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no", url);
|
if (!w || where == "window") {
|
||||||
|
openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no", url,
|
||||||
|
null, null, postData, allowThirdPartyFixup);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var browser = w.document.getElementById("content");
|
|
||||||
var loadInBackground = getBoolPref("browser.tabs.loadBookmarksInBackground", false);
|
var loadInBackground = getBoolPref("browser.tabs.loadBookmarksInBackground", false);
|
||||||
|
|
||||||
switch (where) {
|
switch (where) {
|
||||||
case "current":
|
case "current":
|
||||||
browser.loadURI(url);
|
w.loadURI(url, null, postData, allowThirdPartyFixup);
|
||||||
w.content.focus();
|
w.content.focus();
|
||||||
break;
|
break;
|
||||||
case "tabshifted":
|
case "tabshifted":
|
||||||
loadInBackground = !loadInBackground;
|
loadInBackground = !loadInBackground;
|
||||||
// fall through
|
// fall through
|
||||||
case "tab":
|
case "tab":
|
||||||
browser.loadOneTab(url, null, null, null, loadInBackground,
|
var browser = w.getBrowser();
|
||||||
|
browser.loadOneTab(url, null, null, postData, loadInBackground,
|
||||||
allowThirdPartyFixup || false);
|
allowThirdPartyFixup || false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -496,4 +480,3 @@ function buildHelpMenu()
|
||||||
else
|
else
|
||||||
checkForUpdates.removeAttribute("loading");
|
checkForUpdates.removeAttribute("loading");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче