gecko/browser/base/content/urlbarBindings.xml

281 lines
10 KiB
XML
Raw Normal View History

<?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
# Simon Bünzli <zeniko@gmail.com>
# Portions created by the Initial Developer are Copyright (C) 2006
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Dão Gottwald <dao@design-noir.de>
#
# 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 *****
<bindings id="urlbarBindings" xmlns="http://www.mozilla.org/xbl">
<binding id="urlbar" extends="chrome://global/content/bindings/autocomplete.xml#autocomplete">
<implementation implements="nsIObserver, nsIDOMEventListener">
<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);
this.clickSelectsAll = this._prefs.getBoolPref("clickSelectsAll");
this.doubleClickSelectsAll = this._prefs.getBoolPref("doubleClickSelectsAll");
this.completeDefaultIndex = this._prefs.getBoolPref("autoFill");
this._urlTooltip = document.getElementById("urlTooltip");
this.inputField.controllers.insertControllerAt(0, this._copyCutController);
this.inputField.addEventListener("mousedown", this, false);
this.inputField.addEventListener("mousemove", this, false);
this.inputField.addEventListener("mouseout", this, false);
]]></constructor>
<destructor><![CDATA[
this._prefs.removeObserver("", this);
this._prefs = null;
this._ioService = null;
this.inputField.controllers.removeController(this._copyCutController);
this.inputField.removeEventListener("mousedown", this, false);
this.inputField.removeEventListener("mousemove", this, false);
this.inputField.removeEventListener("mouseout", this, false);
]]></destructor>
<property name="value"
onget="return this.inputField.value;">
<setter><![CDATA[
this.mIgnoreInput = true;
if (val != "") {
var uri;
try {
uri = this._ioService.newURI(val, null, null);
} catch(e) {}
if (uri) {
val = uri.spec;
try {
// try to decode as UTF-8
val = decodeURI(val);
} catch(e) {}
}
}
this.inputField.value = val;
this.mIgnoreInput = false;
var event = document.createEvent("Events");
event.initEvent("ValueChange", true, true);
this.inputField.dispatchEvent(event);
return val;
]]></setter>
</property>
<method name="_initURLTooltip">
<body><![CDATA[
if (this.focused)
return;
if (this._tooltipTimer)
clearTimeout(this._tooltipTimer);
this._tooltipTimer = setTimeout(function (self) {
self._tooltipTimer = 0;
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);
]]></body>
</method>
<method name="_hideURLTooltip">
<body><![CDATA[
if (this._tooltipTimer) {
clearTimeout(this._tooltipTimer);
this._tooltipTimer = 0;
}
this._urlTooltip.hidePopup();
]]></body>
</method>
<field name="_copyCutController"><![CDATA[
({
urlbar: this,
doCommand: function(aCommand) {
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);
},
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":
case "doubleClickSelectsAll":
this[aData] = this._prefs.getBoolPref(aData);
break;
case "autoFill":
this.completeDefaultIndex = this._prefs.getBoolPref(aData);
break;
}
}
]]></body>
</method>
<method name="handleEvent">
<parameter name="aEvent"/>
<body><![CDATA[
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;
}
]]></body>
</method>
</implementation>
<handlers>
<handler event="focus" phase="capturing" action="this._hideURLTooltip();"/>
</handlers>
</binding>
<binding id="urlbar-result-popup" extends="chrome://global/content/bindings/autocomplete.xml#autocomplete-result-popup">
<implementation>
<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>
<method name="onPopupClick">
<parameter name="aEvent"/>
<body><![CDATA[
var controller = this.view.QueryInterface(Components.interfaces.nsIAutoCompleteController);
// default action on unmodified left-click
if (aEvent.button == 0 && !aEvent.shiftKey && !aEvent.ctrlKey &&
!aEvent.altKey && !aEvent.metaKey) {
controller.handleEnter();
}
// completely ignore right-clicks
else if (aEvent.button != 2) {
if (gURLBar && this.mInput == gURLBar) {
// handle address bar click
var url = controller.getValueAt(this.tree.view.selection.currentIndex);
// close the autocomplete popup and revert the entered address
this.closePopup();
controller.handleEscape();
// respect the usual clicking subtleties
openUILink(url, aEvent);
}
else if (this.mInput._getParentSearchbar) {
// handle search bar click
var search = controller.getValueAt(this.tree.view.selection.currentIndex);
var textbox = this.mInput;
// close the autocomplete popup and copy the selected value to the search box
this.closePopup();
textbox.value = search;
// open the search results according to the clicking subtlety
var where = whereToOpenLink(aEvent, false, true);
textbox._getParentSearchbar().doSearch(search, where);
}
else {
// everybody else (i.e. browser content) gets unmodified behavior
controller.handleEnter();
}
}
]]></body>
</method>
</implementation>
</binding>
</bindings>