2007-06-05 04:51:15 +00:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
|
|
|
|
# -*- Mode: HTML -*-
|
|
|
|
# ***** BEGIN LICENSE BLOCK *****
|
|
|
|
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
# 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
# http://www.mozilla.org/MPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
# for the specific language governing rights and limitations under the
|
|
|
|
# License.
|
|
|
|
#
|
|
|
|
# The Original Code is mozilla.org browser.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is
|
2007-06-05 06:41:52 +00:00
|
|
|
# Simon Bünzli <zeniko@gmail.com>
|
2007-06-05 04:51:15 +00:00
|
|
|
# Portions created by the Initial Developer are Copyright (C) 2006
|
|
|
|
# the Initial Developer. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
2007-06-27 22:31:06 +00:00
|
|
|
# Dão Gottwald <dao@design-noir.de>
|
2007-06-05 04:51:15 +00:00
|
|
|
#
|
|
|
|
# Alternatively, the contents of this file may be used under the terms of
|
|
|
|
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
# in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
# of those above. If you wish to allow use of your version of this file only
|
|
|
|
# under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
# use your version of this file under the terms of the MPL, indicate your
|
|
|
|
# decision by deleting the provisions above and replace them with the notice
|
|
|
|
# and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
# the provisions above, a recipient may use your version of this file under
|
|
|
|
# the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
#
|
|
|
|
# ***** END LICENSE BLOCK *****
|
|
|
|
|
2007-10-26 02:53:01 +00:00
|
|
|
<bindings id="urlbarBindings" xmlns="http://www.mozilla.org/xbl">
|
2007-06-27 22:31:06 +00:00
|
|
|
|
|
|
|
<binding id="urlbar" extends="chrome://global/content/bindings/autocomplete.xml#autocomplete">
|
2007-08-04 08:35:28 +00:00
|
|
|
<implementation implements="nsIObserver, nsIDOMEventListener">
|
2007-06-27 22:31:06 +00:00
|
|
|
<constructor><![CDATA[
|
|
|
|
this._ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService);
|
|
|
|
this._prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefService)
|
|
|
|
.getBranch("browser.urlbar.")
|
|
|
|
.QueryInterface(Components.interfaces.nsIPrefBranch2);
|
|
|
|
|
|
|
|
this._prefs.addObserver("", this, false);
|
2007-07-03 17:40:40 +00:00
|
|
|
this.clickSelectsAll = this._prefs.getBoolPref("clickSelectsAll");
|
2007-08-04 08:35:28 +00:00
|
|
|
this.doubleClickSelectsAll = this._prefs.getBoolPref("doubleClickSelectsAll");
|
2007-07-03 17:40:40 +00:00
|
|
|
this.completeDefaultIndex = this._prefs.getBoolPref("autoFill");
|
2007-06-27 22:31:06 +00:00
|
|
|
|
2007-07-03 17:09:50 +00:00
|
|
|
this._urlTooltip = document.getElementById("urlTooltip");
|
|
|
|
|
2007-06-27 22:31:06 +00:00
|
|
|
this.inputField.controllers.insertControllerAt(0, this._copyCutController);
|
2007-08-04 08:35:28 +00:00
|
|
|
this.inputField.addEventListener("mousedown", this, false);
|
2007-10-26 02:53:01 +00:00
|
|
|
this.inputField.addEventListener("mousemove", this, false);
|
|
|
|
this.inputField.addEventListener("mouseout", this, false);
|
2007-06-27 22:31:06 +00:00
|
|
|
]]></constructor>
|
|
|
|
|
|
|
|
<destructor><![CDATA[
|
|
|
|
this._prefs.removeObserver("", this);
|
|
|
|
this._prefs = null;
|
|
|
|
this._ioService = null;
|
|
|
|
this.inputField.controllers.removeController(this._copyCutController);
|
2007-08-04 08:35:28 +00:00
|
|
|
this.inputField.removeEventListener("mousedown", this, false);
|
2007-10-26 02:53:01 +00:00
|
|
|
this.inputField.removeEventListener("mousemove", this, false);
|
|
|
|
this.inputField.removeEventListener("mouseout", this, false);
|
2007-06-27 22:31:06 +00:00
|
|
|
]]></destructor>
|
|
|
|
|
|
|
|
<property name="value"
|
|
|
|
onget="return this.inputField.value;">
|
|
|
|
<setter><![CDATA[
|
|
|
|
this.mIgnoreInput = true;
|
|
|
|
|
2007-10-26 02:53:01 +00:00
|
|
|
if (val != "") {
|
|
|
|
var uri;
|
2007-07-04 21:30:08 +00:00
|
|
|
try {
|
2007-10-26 02:53:01 +00:00
|
|
|
uri = this._ioService.newURI(val, null, null);
|
2007-07-04 21:30:08 +00:00
|
|
|
} catch(e) {}
|
2007-10-26 02:53:01 +00:00
|
|
|
if (uri) {
|
|
|
|
val = uri.spec;
|
2007-10-25 08:14:26 +00:00
|
|
|
try {
|
2007-10-26 02:53:01 +00:00
|
|
|
// try to decode as UTF-8
|
|
|
|
val = decodeURI(val);
|
|
|
|
} catch(e) {}
|
2007-06-27 22:31:06 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-26 02:53:01 +00:00
|
|
|
this.inputField.value = val;
|
2007-06-27 22:31:06 +00:00
|
|
|
|
2007-10-26 02:53:01 +00:00
|
|
|
this.mIgnoreInput = false;
|
|
|
|
var event = document.createEvent("Events");
|
|
|
|
event.initEvent("ValueChange", true, true);
|
|
|
|
this.inputField.dispatchEvent(event);
|
|
|
|
return val;
|
|
|
|
]]></setter>
|
|
|
|
</property>
|
2007-06-27 22:31:06 +00:00
|
|
|
|
|
|
|
<method name="_initURLTooltip">
|
|
|
|
<body><![CDATA[
|
2007-10-26 02:53:01 +00:00
|
|
|
if (this.focused)
|
|
|
|
return;
|
2007-06-27 22:31:06 +00:00
|
|
|
if (this._tooltipTimer)
|
|
|
|
clearTimeout(this._tooltipTimer);
|
2007-10-26 02:53:01 +00:00
|
|
|
this._tooltipTimer = setTimeout(function (self) {
|
2007-06-27 22:31:06 +00:00
|
|
|
self._tooltipTimer = 0;
|
2007-10-26 02:53:01 +00:00
|
|
|
var label = self._urlTooltip.firstChild;
|
|
|
|
label.value = self.value;
|
|
|
|
var bO = self.boxObject;
|
|
|
|
self._urlTooltip.maxWidth = bO.width;
|
|
|
|
self._urlTooltip.showPopup(self, bO.screenX, bO.screenY + bO.height, "tooltip");
|
|
|
|
}, 700, this);
|
2007-06-27 22:31:06 +00:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_hideURLTooltip">
|
|
|
|
<body><![CDATA[
|
|
|
|
if (this._tooltipTimer) {
|
|
|
|
clearTimeout(this._tooltipTimer);
|
|
|
|
this._tooltipTimer = 0;
|
|
|
|
}
|
|
|
|
this._urlTooltip.hidePopup();
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2007-11-28 22:36:24 +00:00
|
|
|
<method name="onDragOver">
|
|
|
|
<body>
|
|
|
|
return true;
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="onDrop">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<parameter name="aXferData"/>
|
|
|
|
<parameter name="aDragSession"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
var url = transferUtils.retrieveURLFromData(aXferData.data, aXferData.flavour.contentType);
|
|
|
|
|
|
|
|
// The URL bar automatically handles inputs with newline characters,
|
|
|
|
// so we can get away with treating text/x-moz-url flavours as text/unicode.
|
|
|
|
if (url) {
|
|
|
|
nsDragAndDrop.dragDropSecurityCheck(aEvent, aDragSession, url);
|
|
|
|
|
|
|
|
try {
|
|
|
|
gURLBar.value = url;
|
|
|
|
const nsIScriptSecMan = Components.interfaces.nsIScriptSecurityManager;
|
|
|
|
urlSecurityCheck(gURLBar.value,
|
|
|
|
gBrowser.contentPrincipal,
|
|
|
|
nsIScriptSecMan.DISALLOW_INHERIT_PRINCIPAL);
|
|
|
|
handleURLBarCommand();
|
|
|
|
} catch (ex) {}
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="getSupportedFlavours">
|
|
|
|
<body><![CDATA[
|
|
|
|
var flavourSet = new FlavourSet();
|
|
|
|
|
|
|
|
// Favor text/x-moz-url since text/unicode coming from Win32 1.8 branch
|
|
|
|
// drops contains URL\ntext. The previous comment here said that
|
|
|
|
// plain text drops often come with text/x-moz-url flavor, but I
|
|
|
|
// haven't seen that, so hopefully that behavior has changed.
|
|
|
|
flavourSet.appendFlavour("text/x-moz-url");
|
|
|
|
flavourSet.appendFlavour("text/unicode");
|
|
|
|
flavourSet.appendFlavour("application/x-moz-file", "nsIFile");
|
|
|
|
return flavourSet;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2007-06-27 22:31:06 +00:00
|
|
|
<field name="_copyCutController"><![CDATA[
|
|
|
|
({
|
|
|
|
urlbar: this,
|
|
|
|
doCommand: function(aCommand) {
|
2007-07-04 21:30:08 +00:00
|
|
|
var urlbar = this.urlbar;
|
|
|
|
var start = urlbar.selectionStart;
|
|
|
|
var end = urlbar.selectionEnd;
|
|
|
|
if (start == end)
|
|
|
|
return;
|
|
|
|
var val;
|
|
|
|
if (start == 0 && end == urlbar.textLength) {
|
|
|
|
// if the entire value is selected and it's a valid URI, encode it
|
|
|
|
val = urlbar.value;
|
|
|
|
try {
|
|
|
|
val = urlbar._ioService.newURI(val, null, null).spec;
|
|
|
|
} catch(e) {}
|
|
|
|
if (aCommand == "cmd_cut")
|
|
|
|
urlbar.value = "";
|
|
|
|
} else {
|
|
|
|
val = urlbar.value.substring(start, end);
|
|
|
|
if (aCommand == "cmd_cut") {
|
|
|
|
urlbar.value = urlbar.value.substring(0, start) + urlbar.value.substring(end);
|
|
|
|
urlbar.selectionStart = urlbar.selectionEnd = start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Components.classes["@mozilla.org/widget/clipboardhelper;1"]
|
|
|
|
.getService(Components.interfaces.nsIClipboardHelper)
|
|
|
|
.copyString(val);
|
2007-06-27 22:31:06 +00:00
|
|
|
},
|
|
|
|
supportsCommand: function(aCommand) {
|
|
|
|
switch (aCommand) {
|
|
|
|
case "cmd_copy":
|
|
|
|
case "cmd_cut":
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
isCommandEnabled: function(aCommand) {
|
|
|
|
return this.supportsCommand(aCommand) && this.urlbar.selectionStart < this.urlbar.selectionEnd;
|
|
|
|
},
|
|
|
|
onEvent: function(aEventName) {}
|
|
|
|
})
|
|
|
|
]]></field>
|
|
|
|
|
|
|
|
<method name="observe">
|
|
|
|
<parameter name="aSubject"/>
|
|
|
|
<parameter name="aTopic"/>
|
|
|
|
<parameter name="aData"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
if (aTopic == "nsPref:changed") {
|
|
|
|
switch(aData) {
|
|
|
|
case "clickSelectsAll":
|
2007-08-04 08:35:28 +00:00
|
|
|
case "doubleClickSelectsAll":
|
|
|
|
this[aData] = this._prefs.getBoolPref(aData);
|
2007-06-27 22:31:06 +00:00
|
|
|
break;
|
2007-07-03 17:40:40 +00:00
|
|
|
case "autoFill":
|
|
|
|
this.completeDefaultIndex = this._prefs.getBoolPref(aData);
|
|
|
|
break;
|
2007-06-27 22:31:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
2007-08-04 08:35:28 +00:00
|
|
|
|
|
|
|
<method name="handleEvent">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body><![CDATA[
|
2007-10-26 02:53:01 +00:00
|
|
|
switch (aEvent.type) {
|
|
|
|
case "mousedown":
|
|
|
|
if (this.doubleClickSelectsAll &&
|
|
|
|
aEvent.button == 0 && aEvent.detail == 2) {
|
|
|
|
this.editor.selectAll();
|
|
|
|
aEvent.preventDefault();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "mousemove":
|
|
|
|
this._initURLTooltip();
|
|
|
|
break;
|
|
|
|
case "mouseout":
|
|
|
|
this._hideURLTooltip();
|
|
|
|
break;
|
2007-08-04 08:35:28 +00:00
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
2007-06-27 22:31:06 +00:00
|
|
|
</implementation>
|
|
|
|
|
|
|
|
<handlers>
|
2007-10-26 02:53:01 +00:00
|
|
|
<handler event="focus" phase="capturing" action="this._hideURLTooltip();"/>
|
2007-11-28 22:36:24 +00:00
|
|
|
<handler event="dragover" phase="capturing" action="nsDragAndDrop.dragOver(event, this);"/>
|
|
|
|
<handler event="dragdrop" phase="capturing" action="nsDragAndDrop.drop(event, this);"/>
|
2007-06-27 22:31:06 +00:00
|
|
|
</handlers>
|
|
|
|
|
|
|
|
</binding>
|
|
|
|
|
2007-12-13 21:21:16 +00:00
|
|
|
<!-- Note: this binding is applied to the autocomplete popup used in the Search bar and in web page content -->
|
|
|
|
<binding id="browser-autocomplete-result-popup" extends="chrome://global/content/bindings/autocomplete.xml#autocomplete-result-popup">
|
2007-06-05 04:51:15 +00:00
|
|
|
<implementation>
|
2007-12-04 21:00:12 +00:00
|
|
|
<method name="openAutocompletePopup">
|
|
|
|
<parameter name="aInput"/>
|
|
|
|
<parameter name="aElement"/>
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
|
|
|
// initially the panel is hidden
|
|
|
|
// to avoid impacting startup / new window performance
|
|
|
|
aInput.popup.hidden = false;
|
|
|
|
|
|
|
|
// this method is defined on the base binding
|
|
|
|
this._openAutocompletePopup(aInput, aElement);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
2007-11-11 18:36:52 +00:00
|
|
|
|
2007-06-05 04:51:15 +00:00
|
|
|
<method name="onPopupClick">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body><![CDATA[
|
2007-12-13 21:21:16 +00:00
|
|
|
// Ignore all right-clicks
|
|
|
|
if (aEvent.button == 2)
|
|
|
|
return;
|
|
|
|
|
2007-06-05 04:51:15 +00:00
|
|
|
var controller = this.view.QueryInterface(Components.interfaces.nsIAutoCompleteController);
|
|
|
|
|
2007-12-13 21:21:16 +00:00
|
|
|
// Check for unmodified left-click, and use default behavior
|
2007-06-05 04:51:15 +00:00
|
|
|
if (aEvent.button == 0 && !aEvent.shiftKey && !aEvent.ctrlKey &&
|
|
|
|
!aEvent.altKey && !aEvent.metaKey) {
|
|
|
|
controller.handleEnter();
|
2007-12-13 21:21:16 +00:00
|
|
|
return;
|
2007-06-05 04:51:15 +00:00
|
|
|
}
|
2007-12-13 21:21:16 +00:00
|
|
|
|
|
|
|
// Check for middle-click or modified clicks on the search bar
|
|
|
|
var searchBar = BrowserSearch.searchBar;
|
|
|
|
if (searchBar && searchBar.textbox == this.mInput) {
|
|
|
|
// Handle search bar popup clicks
|
|
|
|
var search = controller.getValueAt(this.selectedIndex);
|
|
|
|
|
|
|
|
// close the autocomplete popup and revert the entered search term
|
|
|
|
this.closePopup();
|
|
|
|
controller.handleEscape();
|
|
|
|
|
|
|
|
// Fill in the search bar's value
|
|
|
|
searchBar.value = search;
|
|
|
|
|
|
|
|
// open the search results according to the clicking subtlety
|
|
|
|
var where = whereToOpenLink(aEvent, false, true);
|
|
|
|
searchBar.doSearch(search, where);
|
2007-06-05 04:51:15 +00:00
|
|
|
}
|
2007-12-04 21:00:12 +00:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
</implementation>
|
|
|
|
</binding>
|
2007-11-30 04:57:57 +00:00
|
|
|
|
2007-12-04 21:00:12 +00:00
|
|
|
<binding id="urlbar-rich-result-popup" extends="chrome://global/content/bindings/autocomplete.xml#autocomplete-rich-result-popup">
|
|
|
|
<implementation>
|
2007-11-30 04:57:57 +00:00
|
|
|
<field name="_maxResults">0</field>
|
|
|
|
|
2007-12-05 06:19:38 +00:00
|
|
|
<field name="_bundle" readonly="true">
|
|
|
|
Cc["@mozilla.org/intl/stringbundle;1"].
|
|
|
|
getService(Ci.nsIStringBundleService).
|
|
|
|
createBundle("chrome://browser/locale/places/places.properties");
|
|
|
|
</field>
|
|
|
|
|
2007-11-30 04:57:57 +00:00
|
|
|
<property name="maxResults" readonly="true">
|
|
|
|
<getter>
|
|
|
|
<![CDATA[
|
|
|
|
if (!this._maxResults) {
|
|
|
|
var prefService =
|
|
|
|
Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
this._maxResults = prefService.getIntPref("browser.urlbar.maxRichResults");
|
|
|
|
}
|
|
|
|
return this._maxResults;
|
|
|
|
]]>
|
|
|
|
</getter>
|
|
|
|
</property>
|
|
|
|
|
2007-12-04 21:00:12 +00:00
|
|
|
<method name="openAutocompletePopup">
|
|
|
|
<parameter name="aInput"/>
|
|
|
|
<parameter name="aElement"/>
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
|
|
|
// initially the panel is hidden
|
|
|
|
// to avoid impacting startup / new window performance
|
|
|
|
aInput.popup.hidden = false;
|
|
|
|
|
|
|
|
// this method is defined on the base binding
|
|
|
|
this._openAutocompletePopup(aInput, aElement);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2007-11-30 04:57:57 +00:00
|
|
|
<method name="onPopupClick">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
2007-12-13 21:21:16 +00:00
|
|
|
// Ignore right-clicks
|
|
|
|
if (aEvent.button == 2)
|
|
|
|
return;
|
|
|
|
|
2007-11-30 04:57:57 +00:00
|
|
|
var controller = this.view.QueryInterface(Components.interfaces.nsIAutoCompleteController);
|
|
|
|
|
2007-12-13 21:21:16 +00:00
|
|
|
// Check for unmodified left-click, and use default behavior
|
2007-11-30 04:57:57 +00:00
|
|
|
if (aEvent.button == 0 && !aEvent.shiftKey && !aEvent.ctrlKey &&
|
|
|
|
!aEvent.altKey && !aEvent.metaKey) {
|
|
|
|
controller.handleEnter();
|
2007-12-13 21:21:16 +00:00
|
|
|
return;
|
2007-11-30 04:57:57 +00:00
|
|
|
}
|
2007-12-13 21:21:16 +00:00
|
|
|
|
|
|
|
// Check for middle-click or modified clicks on the URL bar
|
|
|
|
if (gURLBar && this.mInput == gURLBar) {
|
|
|
|
var url = controller.getValueAt(this.selectedIndex);
|
|
|
|
|
|
|
|
// close the autocomplete popup and revert the entered address
|
|
|
|
this.closePopup();
|
|
|
|
controller.handleEscape();
|
|
|
|
|
|
|
|
// respect the usual clicking subtleties
|
|
|
|
openUILink(url, aEvent);
|
2007-11-30 04:57:57 +00:00
|
|
|
}
|
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
2007-12-05 06:19:38 +00:00
|
|
|
|
|
|
|
<method name="createResultLabel">
|
|
|
|
<parameter name="aTitle"/>
|
|
|
|
<parameter name="aUrl"/>
|
|
|
|
<parameter name="aType"/>
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
|
|
|
var label = aTitle + " " + aUrl;
|
|
|
|
// convert aType (ex: "ac-result-type-<aType>") to text to be spoke aloud
|
|
|
|
// by screen readers. convert "tag" and "bookmark" to the localized versions,
|
|
|
|
// but don't do anything for "favicon" (the default)
|
|
|
|
if (aType != "favicon") {
|
|
|
|
label += " " + this._bundle.GetStringFromName(aType + "ResultLabel");
|
|
|
|
}
|
|
|
|
return label;
|
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
2007-06-05 04:51:15 +00:00
|
|
|
</implementation>
|
|
|
|
</binding>
|
|
|
|
</bindings>
|