mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-28 21:28:55 +00:00
Bug 811406 - Work - Trim http:// and single trailing slash from location text in the Firefox app bar. r=fryn
This commit is contained in:
parent
7fd6f5b4f1
commit
834467796d
@ -46,6 +46,13 @@
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="trimValue">
|
||||
<parameter name="aURL"/>
|
||||
<body><![CDATA[
|
||||
return BrowserUI.trimURL(aURL);
|
||||
]]></body>
|
||||
</method>
|
||||
</implementation>
|
||||
|
||||
<handlers>
|
||||
|
@ -98,7 +98,10 @@ var BrowserUI = {
|
||||
|
||||
Services.prefs.addObserver("browser.cache.disk_cache_ssl", this, false);
|
||||
Services.prefs.addObserver("browser.urlbar.formatting.enabled", this, false);
|
||||
Services.prefs.addObserver("browser.urlbar.trimURLs", this, false);
|
||||
Services.obs.addObserver(this, "metro_viewstate_changed", false);
|
||||
|
||||
this._edit.inputField.controllers.insertControllerAt(0, this._copyCutURIController);
|
||||
|
||||
// Init core UI modules
|
||||
ContextUI.init();
|
||||
@ -564,6 +567,9 @@ var BrowserUI = {
|
||||
case "browser.urlbar.formatting.enabled":
|
||||
this._formattingEnabled = Services.prefs.getBookPref(aData);
|
||||
break;
|
||||
case "browser.urlbar.trimURLs":
|
||||
this._mayTrimURLs = Services.prefs.getBoolPref(aData);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "metro_viewstate_changed":
|
||||
@ -654,11 +660,120 @@ var BrowserUI = {
|
||||
Elements.urlbarState.setAttribute("mode", "view");
|
||||
},
|
||||
|
||||
_trimURL: function _trimURL(aURL) {
|
||||
// This function must not modify the given URL such that calling
|
||||
// nsIURIFixup::createFixupURI with the result will produce a different URI.
|
||||
return aURL /* remove single trailing slash for http/https/ftp URLs */
|
||||
.replace(/^((?:http|https|ftp):\/\/[^/]+)\/$/, "$1")
|
||||
/* remove http:// unless the host starts with "ftp\d*\." or contains "@" */
|
||||
.replace(/^http:\/\/((?!ftp\d*\.)[^\/@]+(?:\/|$))/, "$1");
|
||||
},
|
||||
|
||||
trimURL: function trimURL(aURL) {
|
||||
return this.mayTrimURLs ? this._trimURL(aURL) : aURL;
|
||||
},
|
||||
|
||||
_setURI: function _setURI(aURL) {
|
||||
this._edit.value = aURL;
|
||||
this.lastKnownGoodURL = aURL;
|
||||
},
|
||||
|
||||
_getSelectedURIForClipboard: function _getSelectedURIForClipboard() {
|
||||
// Grab the actual input field's value, not our value, which could include moz-action:
|
||||
let inputVal = this._edit.inputField.value;
|
||||
let selectedVal = inputVal.substring(this._edit.selectionStart, this._edit.electionEnd);
|
||||
|
||||
// If the selection doesn't start at the beginning or doesn't span the full domain or
|
||||
// the URL bar is modified, nothing else to do here.
|
||||
if (this._edit.selectionStart > 0 || this._edit.valueIsTyped)
|
||||
return selectedVal;
|
||||
// The selection doesn't span the full domain if it doesn't contain a slash and is
|
||||
// followed by some character other than a slash.
|
||||
if (!selectedVal.contains("/")) {
|
||||
let remainder = inputVal.replace(selectedVal, "");
|
||||
if (remainder != "" && remainder[0] != "/")
|
||||
return selectedVal;
|
||||
}
|
||||
|
||||
let uriFixup = Cc["@mozilla.org/docshell/urifixup;1"].getService(Ci.nsIURIFixup);
|
||||
|
||||
let uri;
|
||||
try {
|
||||
uri = uriFixup.createFixupURI(inputVal, Ci.nsIURIFixup.FIXUP_FLAG_USE_UTF8);
|
||||
} catch (e) {}
|
||||
if (!uri)
|
||||
return selectedVal;
|
||||
|
||||
// Only copy exposable URIs
|
||||
try {
|
||||
uri = uriFixup.createExposableURI(uri);
|
||||
} catch (ex) {}
|
||||
|
||||
// If the entire URL is selected, just use the actual loaded URI.
|
||||
if (inputVal == selectedVal) {
|
||||
// ... but only if isn't a javascript: or data: URI, since those
|
||||
// are hard to read when encoded
|
||||
if (!uri.schemeIs("javascript") && !uri.schemeIs("data")) {
|
||||
// Parentheses are known to confuse third-party applications (bug 458565).
|
||||
selectedVal = uri.spec.replace(/[()]/g, function (c) escape(c));
|
||||
}
|
||||
|
||||
return selectedVal;
|
||||
}
|
||||
|
||||
// Just the beginning of the URL is selected, check for a trimmed value
|
||||
let spec = uri.spec;
|
||||
let trimmedSpec = this.trimURL(spec);
|
||||
if (spec != trimmedSpec) {
|
||||
// Prepend the portion that trimURL removed from the beginning.
|
||||
// This assumes trimURL will only truncate the URL at
|
||||
// the beginning or end (or both).
|
||||
let trimmedSegments = spec.split(trimmedSpec);
|
||||
selectedVal = trimmedSegments[0] + selectedVal;
|
||||
}
|
||||
|
||||
return selectedVal;
|
||||
},
|
||||
|
||||
_copyCutURIController: {
|
||||
doCommand: function(aCommand) {
|
||||
let urlbar = BrowserUI._edit;
|
||||
let val = BrowserUI._getSelectedURIForClipboard();
|
||||
if (!val)
|
||||
return;
|
||||
|
||||
if (aCommand == "cmd_cut" && this.isCommandEnabled(aCommand)) {
|
||||
let start = urlbar.selectionStart;
|
||||
let end = urlbar.selectionEnd;
|
||||
urlbar.inputField.value = urlbar.inputField.value.substring(0, start) +
|
||||
urlbar.inputField.value.substring(end);
|
||||
urlbar.selectionStart = urlbar.selectionEnd = start;
|
||||
}
|
||||
|
||||
Cc["@mozilla.org/widget/clipboardhelper;1"]
|
||||
.getService(Ci.nsIClipboardHelper)
|
||||
.copyString(val, document);
|
||||
},
|
||||
|
||||
supportsCommand: function(aCommand) {
|
||||
switch (aCommand) {
|
||||
case "cmd_copy":
|
||||
case "cmd_cut":
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
isCommandEnabled: function(aCommand) {
|
||||
let urlbar = BrowserUI._edit;
|
||||
return this.supportsCommand(aCommand) &&
|
||||
(aCommand != "cmd_cut" || !urlbar.readOnly) &&
|
||||
urlbar.selectionStart < urlbar.selectionEnd;
|
||||
},
|
||||
|
||||
onEvent: function(aEventName) {}
|
||||
},
|
||||
|
||||
_urlbarClicked: function _urlbarClicked() {
|
||||
// If the urlbar is not already focused, focus it and select the contents.
|
||||
if (Elements.urlbarState.getAttribute("mode") != "edit")
|
||||
@ -1039,6 +1154,15 @@ var BrowserUI = {
|
||||
return this._formattingEnabled;
|
||||
},
|
||||
|
||||
_mayTrimURLs: null,
|
||||
|
||||
get mayTrimURLs() {
|
||||
if (this._mayTrimURLs === null) {
|
||||
this._mayTrimURLs = Services.prefs.getBoolPref("browser.urlbar.trimURLs");
|
||||
}
|
||||
return this._mayTrimURLs;
|
||||
},
|
||||
|
||||
supportsCommand : function(cmd) {
|
||||
var isSupported = false;
|
||||
switch (cmd) {
|
||||
|
@ -261,6 +261,7 @@ pref("places.favicons.optimizeToDimension", 25);
|
||||
|
||||
// various and sundry awesomebar prefs (should remove/re-evaluate
|
||||
// these once bug 447900 is fixed)
|
||||
pref("browser.urlbar.trimURLs", true);
|
||||
pref("browser.urlbar.formatting.enabled", true);
|
||||
pref("browser.urlbar.clickSelectsAll", true);
|
||||
pref("browser.urlbar.doubleClickSelectsAll", true);
|
||||
|
@ -308,6 +308,12 @@ documenttab[selected] .documenttab-selection {
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
#urlbar-edit :invalid {
|
||||
/* Hide error glow around the address bar that shows by default
|
||||
* when URLs are made invalid by trmming. */
|
||||
box-shadow: none !important;
|
||||
}
|
||||
|
||||
/* Combined stop-reload button */
|
||||
#tool-reload {
|
||||
list-style-image: url("chrome://browser/skin/images/reload.png");
|
||||
|
Loading…
x
Reference in New Issue
Block a user