--- navigator-16-ori.js 2004-01-26 22:31:17.000000000 -0300 +++ navigator.js 2004-01-26 22:33:46.000000000 -0300 @@ -1269,11 +1269,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. @@ -1292,50 +1292,79 @@ shiftPressed = aTriggeringEvent.shiftKey; } - var browser = getBrowser(); + // 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"); + + 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(); } - catch (ex) {} + else { + // Check if user requests Tabs instead of windows + var openTab = false; + try { + openTab = pref.getBoolPref("browser.tabs.opentabfor.urlbar"); + } + catch (ex) {} - if (openTab) { - // Open link in new tab - var t = browser.addTab(url); - - // Focus new tab unless shift is pressed - if (!shiftPressed) { - browser.userTypedValue = null; - browser.selectedTab = t; + 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; } - } 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 = browser.currentURI.spec; - if (oldURL != "about:blank") { - gURLBar.value = oldURL; - SetPageProxyState("valid", null); - } else - gURLBar.value = ""; - - browser.userTypedValue = null; - - // 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 (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 if (saveModifier) { + 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 { // Firstly, fixup the url so that (e.g.) "www.foo.com" works const nsIURIFixup = Components.interfaces.nsIURIFixup; @@ -1350,7 +1379,8 @@ // XXX Do nothing for now. // Do we want to put up an alert in the future? Mmm, l10n... } - } else { + } + else { // No modifier was pressed, load the URL normally and // focus the content area loadURI(url);