--- navigator-14a-ori.js Wed Apr 2 22:46:14 2003 +++ navigator.js Wed Apr 2 22:46:27 2003 @@ -1175,11 +1175,11 @@ if (url.match(/^view-source:/)) { BrowserViewSourceOfURL(url.replace(/^view-source:/, ""), null, null); } else { - // Check the pressed modifiers: (also see bug 97123) + // Check the pressed modifiers: (also see bug 97123, 37867) // Modifier Mac | Modifier PC | Action // -------------+-------------+----------- - // Command | Control | New Window/Tab - // Shift+Cmd | Shift+Ctrl | New Window/Tab behind current one + // Command | Control | New Window/Tab and/or URL AutoCompletion(reads settings from prefs) + // Shift+Cmd | Shift+Ctrl | New Window/Tab and URL AutoCompletion(reads settings from prefs) behind current one // Option | Shift | Save URL (show Filepicker) // If false, the save modifier is Alt, which is Option on Mac. @@ -1198,45 +1198,77 @@ shiftPressed = aTriggeringEvent.shiftKey; } + // Read user settings from preferences for what to do with Ctrl+Enter. + // Turn both variables to false for old behavior of open new window/tab. + var useAutoCompletionOnly = false; // use autocompletion and no new window/tab for Ctrl+Enter + var useAutoCompletionNewWindow = false; // use autocompletion with new window/tab for Ctrl+Enter + // Read from the prefs(all.js) section "URI fixup prefs" + try { + useAutoCompletionOnly = pref.getBoolPref("browser.fixup.ctrl_enter.autocompletion_only"); + useAutoCompletionNewWindow = pref.getBoolPref("browser.fixup.ctrl_enter.autocompletion_newwindow"); + } + catch (ex) {} + url = getShortcutOrURI(url); - // Accept both Control and Meta (=Command) as New-Window-Modifiers + // for URL autocompletion, URL parsing + const knsIURIFixup = Components.interfaces.nsIURIFixup; + const kURIFixup = Components.classes["@mozilla.org/docshell/urifixup;1"].getService(knsIURIFixup); + + // Accept both Control and Meta (=Command) as New Window/Tab or AutoCompletion Modifiers if (aTriggeringEvent && (('ctrlKey' in aTriggeringEvent && aTriggeringEvent.ctrlKey) || ('metaKey' in aTriggeringEvent && aTriggeringEvent.metaKey))) { - // Check if user requests Tabs instead of windows - var openTab = false; - try { - openTab = pref.getBoolPref("browser.tabs.opentabfor.urlbar"); - } - catch (ex) {} - if (openTab && getBrowser().localName == "tabbrowser") { - // Open link in new tab - var t = getBrowser().addTab(url); - // Focus new tab unless shift is pressed - if (!shiftPressed) - getBrowser().selectedTab = t; + if (useAutoCompletionOnly && !useAutoCompletionNewWindow && !shiftPressed) { + // only Ctrl+Enter was pressed + // Autocomplete the string entered by the user. + // Do domain-autocompletion before page load. If we don't autocomplete before page loads, then + // Mozilla will autocomplete the URL after the first DNS lookup failed. + // So, this save a DNS lookup and time. Also, makes an IE like Ctrl+Enter feature. + url = kURIFixup.createFixupURI(url, knsIURIFixup.FIXUP_FLAGS_MAKE_ALTERNATE_URI).spec; + // Display the new URL in the URL bar + gURLBar.value = url; + + // Load the new URL + loadURI(url); + content.focus(); } - else { - // Open a new window with the URL - var newWin = openDialog(getBrowserURL(), "_blank", "all,dialog=no", url); - // Reset url in the urlbar, copied from handleURLBarRevert() - var oldURL = getWebNavigation().currentURI.spec; - if (oldURL != "about:blank") { - gURLBar.value = oldURL; - SetPageProxyState("valid", null); + else { + // Check if user requests Tabs instead of windows + var openTab = false; + try { + openTab = pref.getBoolPref("browser.tabs.opentabfor.urlbar"); } - else - gURLBar.value = ""; + catch (ex) {} - // Focus old window if shift was pressed, as there's no - // way to open a new window in the background - // XXX this doesn't seem to work - if (shiftPressed) { - //newWin.blur(); - content.focus(); + if (useAutoCompletionNewWindow) { + // Autocomplete the string entered by the user before opening the new window/tab. + url = kURIFixup.createFixupURI(url, knsIURIFixup.FIXUP_FLAGS_MAKE_ALTERNATE_URI).spec; } - } + + if (openTab && getBrowser().localName == "tabbrowser") { + // Open link in new tab + var t = getBrowser().addTab(url); + // Focus new tab unless shift is pressed + if (!shiftPressed) + getBrowser().selectedTab = t; + } + else { + // Open a new window with the URL + var newWin = openDialog(getBrowserURL(), "_blank", "all,dialog=no", url); + // Reset url in the urlbar, copied from handleURLBarRevert() + var oldURL = getWebNavigation().currentURI.spec; + if (oldURL != "about:blank") { + gURLBar.value = oldURL; + SetPageProxyState("valid", null); + } + else + gURLBar.value = ""; + + // Here we should check whether to open the window in the background(give focus to the old window), + // but opening windows in the background is not possible (yet) + } + } } else if (saveModifier) { try {