2007-06-04 21:51:15 -07: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-04 23:41:52 -07:00
|
|
|
# Simon Bünzli <zeniko@gmail.com>
|
2007-06-04 21:51:15 -07:00
|
|
|
# Portions created by the Initial Developer are Copyright (C) 2006
|
|
|
|
# the Initial Developer. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
2010-09-14 22:41:16 -07:00
|
|
|
# Dão Gottwald <dao@design-noir.de>
|
|
|
|
# Drew Willcoxon <adw@mozilla.com>
|
2007-06-04 21:51:15 -07: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 *****
|
|
|
|
|
2010-12-16 09:53:24 -08:00
|
|
|
<!DOCTYPE bindings [
|
|
|
|
<!ENTITY % notificationDTD SYSTEM "chrome://global/locale/notification.dtd">
|
|
|
|
%notificationDTD;
|
|
|
|
]>
|
|
|
|
|
2010-04-09 10:45:25 -07:00
|
|
|
<bindings id="urlbarBindings" xmlns="http://www.mozilla.org/xbl"
|
2010-09-14 22:41:16 -07:00
|
|
|
xmlns:html="http://www.w3.org/1999/xhtml"
|
2010-04-09 10:45:25 -07:00
|
|
|
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
|
|
|
xmlns:xbl="http://www.mozilla.org/xbl">
|
2007-06-27 15:31:06 -07:00
|
|
|
|
|
|
|
<binding id="urlbar" extends="chrome://global/content/bindings/autocomplete.xml#autocomplete">
|
2010-09-14 22:41:16 -07:00
|
|
|
|
|
|
|
<content sizetopopup="pref">
|
2011-02-02 22:48:39 -08:00
|
|
|
<xul:hbox anonid="textbox-container"
|
|
|
|
class="autocomplete-textbox-container urlbar-textbox-container"
|
|
|
|
flex="1" xbl:inherits="focused">
|
2011-02-10 16:59:40 -08:00
|
|
|
<children includes="image|deck|stack|box">
|
|
|
|
<xul:image class="autocomplete-icon" allowevents="true"/>
|
|
|
|
</children>
|
2011-02-02 22:48:39 -08:00
|
|
|
<xul:hbox anonid="textbox-input-box"
|
|
|
|
class="textbox-input-box urlbar-input-box"
|
|
|
|
flex="1" xbl:inherits="tooltiptext=inputtooltiptext">
|
|
|
|
<children/>
|
|
|
|
<html:input anonid="input"
|
|
|
|
class="autocomplete-textbox urlbar-input textbox-input uri-element-right-align"
|
2011-04-22 18:36:24 -07:00
|
|
|
allowevents="true"
|
2011-02-02 22:48:39 -08:00
|
|
|
xbl:inherits="tooltiptext=inputtooltiptext,onfocus,onblur,value,type,maxlength,disabled,size,readonly,placeholder,tabindex,accesskey"/>
|
2010-10-11 20:47:59 -07:00
|
|
|
</xul:hbox>
|
2011-02-02 22:48:39 -08:00
|
|
|
<children includes="hbox"/>
|
2010-10-11 20:47:59 -07:00
|
|
|
</xul:hbox>
|
2011-02-02 22:48:39 -08:00
|
|
|
<xul:dropmarker anonid="historydropmarker"
|
|
|
|
class="autocomplete-history-dropmarker urlbar-history-dropmarker"
|
|
|
|
allowevents="true"
|
|
|
|
xbl:inherits="open,enablehistory,parentfocused=focused"/>
|
|
|
|
<xul:popupset anonid="popupset"
|
|
|
|
class="autocomplete-result-popupset"/>
|
2010-09-14 22:41:16 -07:00
|
|
|
<children includes="toolbarbutton"/>
|
|
|
|
</content>
|
|
|
|
|
2007-08-04 01:35:28 -07:00
|
|
|
<implementation implements="nsIObserver, nsIDOMEventListener">
|
2007-06-27 15:31:06 -07:00
|
|
|
<constructor><![CDATA[
|
|
|
|
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 10:40:40 -07:00
|
|
|
this.clickSelectsAll = this._prefs.getBoolPref("clickSelectsAll");
|
2007-08-04 01:35:28 -07:00
|
|
|
this.doubleClickSelectsAll = this._prefs.getBoolPref("doubleClickSelectsAll");
|
2007-07-03 10:40:40 -07:00
|
|
|
this.completeDefaultIndex = this._prefs.getBoolPref("autoFill");
|
2009-06-17 08:27:04 -07:00
|
|
|
this.timeout = this._prefs.getIntPref("delay");
|
2011-05-02 10:50:18 -07:00
|
|
|
this._formattingEnabled = this._prefs.getBoolPref("formatting.enabled");
|
2007-06-27 15:31:06 -07:00
|
|
|
|
2007-07-03 10:09:50 -07:00
|
|
|
this._urlTooltip = document.getElementById("urlTooltip");
|
|
|
|
|
2007-06-27 15:31:06 -07:00
|
|
|
this.inputField.controllers.insertControllerAt(0, this._copyCutController);
|
2007-08-04 01:35:28 -07:00
|
|
|
this.inputField.addEventListener("mousedown", this, false);
|
2007-10-25 19:53:01 -07:00
|
|
|
this.inputField.addEventListener("mousemove", this, false);
|
|
|
|
this.inputField.addEventListener("mouseout", this, false);
|
2010-03-26 14:59:02 -07:00
|
|
|
this.inputField.addEventListener("overflow", this, false);
|
|
|
|
this.inputField.addEventListener("underflow", this, false);
|
2010-09-16 00:51:24 -07:00
|
|
|
|
|
|
|
const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
|
|
var textBox = document.getAnonymousElementByAttribute(this,
|
|
|
|
"anonid", "textbox-input-box");
|
|
|
|
var cxmenu = document.getAnonymousElementByAttribute(textBox,
|
|
|
|
"anonid", "input-box-contextmenu");
|
2010-09-20 21:32:00 -07:00
|
|
|
var pasteAndGo;
|
|
|
|
cxmenu.addEventListener("popupshowing", function() {
|
|
|
|
if (!pasteAndGo)
|
|
|
|
return;
|
|
|
|
var controller = document.commandDispatcher.getControllerForCommand("cmd_paste");
|
2010-11-22 11:50:49 -08:00
|
|
|
var enabled = controller.isCommandEnabled("cmd_paste");
|
|
|
|
if (enabled)
|
|
|
|
pasteAndGo.removeAttribute("disabled");
|
|
|
|
else
|
|
|
|
pasteAndGo.setAttribute("disabled", "true");
|
2010-09-20 21:32:00 -07:00
|
|
|
}, false);
|
|
|
|
|
2010-09-16 00:51:24 -07:00
|
|
|
var insertLocation = cxmenu.firstChild;
|
|
|
|
while (insertLocation.nextSibling &&
|
|
|
|
insertLocation.getAttribute("cmd") != "cmd_paste")
|
|
|
|
insertLocation = insertLocation.nextSibling;
|
|
|
|
if (insertLocation) {
|
2010-09-20 21:32:00 -07:00
|
|
|
pasteAndGo = document.createElement("menuitem");
|
2010-09-16 00:51:24 -07:00
|
|
|
let label = Services.strings.createBundle("chrome://browser/locale/browser.properties").
|
|
|
|
GetStringFromName("pasteAndGo.label");
|
2010-09-20 21:32:00 -07:00
|
|
|
pasteAndGo.setAttribute("label", label);
|
|
|
|
pasteAndGo.setAttribute("anonid", "paste-and-go");
|
2010-10-26 15:35:44 -07:00
|
|
|
pasteAndGo.setAttribute("oncommand",
|
2010-11-05 12:56:03 -07:00
|
|
|
"gURLBar.select(); goDoCommand('cmd_paste'); gURLBar.handleCommand();");
|
2010-09-20 21:32:00 -07:00
|
|
|
cxmenu.insertBefore(pasteAndGo, insertLocation.nextSibling);
|
2010-09-16 00:51:24 -07:00
|
|
|
}
|
2007-06-27 15:31:06 -07:00
|
|
|
]]></constructor>
|
|
|
|
|
|
|
|
<destructor><![CDATA[
|
|
|
|
this._prefs.removeObserver("", this);
|
|
|
|
this._prefs = null;
|
|
|
|
this.inputField.controllers.removeController(this._copyCutController);
|
2007-08-04 01:35:28 -07:00
|
|
|
this.inputField.removeEventListener("mousedown", this, false);
|
2007-10-25 19:53:01 -07:00
|
|
|
this.inputField.removeEventListener("mousemove", this, false);
|
|
|
|
this.inputField.removeEventListener("mouseout", this, false);
|
2010-03-26 14:59:02 -07:00
|
|
|
this.inputField.removeEventListener("overflow", this, false);
|
|
|
|
this.inputField.removeEventListener("underflow", this, false);
|
2007-06-27 15:31:06 -07:00
|
|
|
]]></destructor>
|
|
|
|
|
2010-03-26 14:59:02 -07:00
|
|
|
<field name="_value"></field>
|
|
|
|
|
|
|
|
<!--
|
|
|
|
onBeforeValueGet is called by the base-binding's .value getter.
|
|
|
|
It can return an object with a "value" property, to override the
|
|
|
|
return value of the getter.
|
|
|
|
-->
|
|
|
|
<method name="onBeforeValueGet">
|
|
|
|
<body><![CDATA[
|
|
|
|
if (this.hasAttribute("actiontype"))
|
|
|
|
return {value: this._value};
|
|
|
|
return null;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!--
|
|
|
|
onBeforeValueSet is called by the base-binding's .value setter.
|
|
|
|
It should return the value that the setter should use.
|
|
|
|
-->
|
|
|
|
<method name="onBeforeValueSet">
|
|
|
|
<parameter name="aValue"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
this._value = aValue;
|
|
|
|
var returnValue = aValue;
|
|
|
|
var action = this._parseActionUrl(aValue);
|
|
|
|
if (action) {
|
|
|
|
returnValue = action.param;
|
|
|
|
this.setAttribute("actiontype", action.type);
|
|
|
|
} else {
|
|
|
|
this.removeAttribute("actiontype");
|
|
|
|
}
|
|
|
|
return returnValue;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2011-05-02 10:50:18 -07:00
|
|
|
<field name="_formattingEnabled">true</field>
|
|
|
|
<method name="formatValue">
|
|
|
|
<body><![CDATA[
|
|
|
|
if (!this._formattingEnabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let controller = this.editor.selectionController;
|
|
|
|
let selection = controller.getSelection(controller.SELECTION_URLSECONDARY);
|
|
|
|
selection.removeAllRanges();
|
|
|
|
|
|
|
|
let textNode = this.editor.rootElement.firstChild;
|
|
|
|
let value = textNode.textContent;
|
|
|
|
let matchedURL = value.match(/^((?:http|https|ftp):\/\/(?:[^\/]+@)?)([^\/:]+)/);
|
|
|
|
if (!matchedURL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let [, preDomain, domain] = matchedURL;
|
|
|
|
let baseDomain = domain;
|
|
|
|
try {
|
|
|
|
baseDomain = Services.eTLD.getBaseDomainFromHost(domain);
|
|
|
|
} catch (e) {}
|
|
|
|
let segments = function (s) s.replace(/[^.]*/g, "").length + 1;
|
|
|
|
let subSegments = segments(domain) - segments(baseDomain);
|
|
|
|
let subDomain = domain.match(new RegExp("(?:[^.]*\.){" + subSegments + "}"))[0];
|
|
|
|
|
|
|
|
let range = document.createRange();
|
|
|
|
range.setStart(textNode, 0);
|
|
|
|
range.setEnd(textNode, preDomain.length + subDomain.length);
|
|
|
|
selection.addRange(range);
|
|
|
|
|
|
|
|
let startRest = preDomain.length + domain.length;
|
|
|
|
if (startRest < value.length) {
|
|
|
|
range = document.createRange();
|
|
|
|
range.setStart(textNode, startRest);
|
|
|
|
range.setEnd(textNode, value.length);
|
|
|
|
selection.addRange(range);
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2008-09-25 04:33:51 -07:00
|
|
|
<method name="handleRevert">
|
|
|
|
<body><![CDATA[
|
|
|
|
var isScrolling = this.popupOpen;
|
|
|
|
|
|
|
|
gBrowser.userTypedValue = null;
|
|
|
|
|
|
|
|
// don't revert to last valid url unless page is NOT loading
|
|
|
|
// and user is NOT key-scrolling through autocomplete list
|
2008-10-25 06:15:53 -07:00
|
|
|
if (!XULBrowserWindow.isBusy && !isScrolling) {
|
2008-09-25 04:33:51 -07:00
|
|
|
URLBarSetURI();
|
|
|
|
|
|
|
|
// If the value isn't empty and the urlbar has focus, select the value.
|
|
|
|
if (this.value && this.hasAttribute("focused"))
|
|
|
|
this.select();
|
|
|
|
}
|
|
|
|
|
|
|
|
// tell widget to revert to last typed text only if the user
|
|
|
|
// was scrolling when they hit escape
|
|
|
|
return !isScrolling;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="handleCommand">
|
|
|
|
<parameter name="aTriggeringEvent"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
if (aTriggeringEvent instanceof MouseEvent && aTriggeringEvent.button == 2)
|
|
|
|
return; // Do nothing for right clicks
|
|
|
|
|
2010-07-15 22:05:47 -07:00
|
|
|
var url = this.value;
|
|
|
|
var postData = null;
|
2008-09-25 04:33:51 -07:00
|
|
|
|
2010-03-26 14:59:02 -07:00
|
|
|
var action = this._parseActionUrl(url);
|
|
|
|
if (action) {
|
2010-07-15 22:05:47 -07:00
|
|
|
url = action.param;
|
2010-12-10 18:32:14 -08:00
|
|
|
if (this.hasAttribute("actiontype")) {
|
2010-11-07 04:59:51 -08:00
|
|
|
if (action.type == "switchtab") {
|
|
|
|
this.handleRevert();
|
|
|
|
let prevTab = gBrowser.selectedTab;
|
|
|
|
if (switchToTabHavingURI(url) &&
|
|
|
|
isTabEmpty(prevTab))
|
|
|
|
gBrowser.removeTab(prevTab);
|
|
|
|
}
|
2010-07-15 22:05:47 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
[url, postData] = this._canonizeURL(aTriggeringEvent);
|
|
|
|
if (!url)
|
|
|
|
return;
|
2010-03-26 14:59:02 -07:00
|
|
|
}
|
|
|
|
|
2008-09-25 04:33:51 -07:00
|
|
|
this.value = url;
|
|
|
|
gBrowser.userTypedValue = url;
|
|
|
|
try {
|
|
|
|
addToUrlbarHistory(url);
|
2008-09-25 04:41:10 -07:00
|
|
|
} catch (ex) {
|
2008-09-25 04:33:51 -07:00
|
|
|
// Things may go wrong when adding url to session history,
|
|
|
|
// but don't let that interfere with the loading of the url.
|
|
|
|
Cu.reportError(ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aTriggeringEvent instanceof MouseEvent) {
|
|
|
|
// We have a mouse event (from the go button), so use the standard
|
|
|
|
// UI link behaviors
|
2010-11-05 03:56:49 -07:00
|
|
|
let where = whereToOpenLink(aTriggeringEvent, false, false);
|
|
|
|
if (where != "current") {
|
|
|
|
this.handleRevert();
|
|
|
|
content.focus();
|
|
|
|
}
|
|
|
|
openUILinkIn(url, where,
|
|
|
|
{ allowThirdPartyFixup: true, postData: postData });
|
2008-09-25 04:33:51 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-13 17:42:37 -08:00
|
|
|
if (aTriggeringEvent &&
|
|
|
|
aTriggeringEvent.altKey &&
|
|
|
|
!isTabEmpty(gBrowser.selectedTab)) {
|
2008-09-25 04:33:51 -07:00
|
|
|
this.handleRevert();
|
|
|
|
content.focus();
|
2009-09-17 06:03:15 -07:00
|
|
|
gBrowser.loadOneTab(url, {
|
|
|
|
postData: postData,
|
|
|
|
inBackground: false,
|
|
|
|
allowThirdPartyFixup: true});
|
2008-09-25 04:33:51 -07:00
|
|
|
aTriggeringEvent.preventDefault();
|
|
|
|
aTriggeringEvent.stopPropagation();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
loadURI(url, null, postData, true /* allow third party fixup */);
|
|
|
|
|
2009-08-10 09:27:10 -07:00
|
|
|
gBrowser.selectedBrowser.focus();
|
2008-09-25 04:33:51 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_canonizeURL">
|
|
|
|
<parameter name="aTriggeringEvent"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
var url = this.value;
|
|
|
|
if (!url)
|
|
|
|
return ["", null];
|
|
|
|
|
|
|
|
// Only add the suffix when the URL bar value isn't already "URL-like",
|
|
|
|
// and only if we get a keyboard event, to match user expectations.
|
|
|
|
if (!/^\s*(www|https?)\b|\/\s*$/i.test(url) &&
|
|
|
|
(aTriggeringEvent instanceof KeyEvent)) {
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
let accel = aTriggeringEvent.metaKey;
|
|
|
|
#else
|
|
|
|
let accel = aTriggeringEvent.ctrlKey;
|
|
|
|
#endif
|
|
|
|
let shift = aTriggeringEvent.shiftKey;
|
|
|
|
|
|
|
|
let suffix = "";
|
|
|
|
|
|
|
|
switch (true) {
|
|
|
|
case (accel && shift):
|
|
|
|
suffix = ".org/";
|
|
|
|
break;
|
|
|
|
case (shift):
|
|
|
|
suffix = ".net/";
|
|
|
|
break;
|
|
|
|
case (accel):
|
|
|
|
try {
|
|
|
|
suffix = gPrefService.getCharPref("browser.fixup.alternate.suffix");
|
|
|
|
if (suffix.charAt(suffix.length - 1) != "/")
|
|
|
|
suffix += "/";
|
|
|
|
} catch(e) {
|
|
|
|
suffix = ".com/";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (suffix) {
|
|
|
|
// trim leading/trailing spaces (bug 233205)
|
|
|
|
url = url.trim();
|
|
|
|
|
|
|
|
// Tack www. and suffix on. If user has appended directories, insert
|
|
|
|
// suffix before them (bug 279035). Be careful not to get two slashes.
|
|
|
|
// Also, don't add the suffix if it's in the original url (bug 233853).
|
2010-09-16 00:51:24 -07:00
|
|
|
|
2008-09-25 04:33:51 -07:00
|
|
|
let firstSlash = url.indexOf("/");
|
|
|
|
let existingSuffix = url.indexOf(suffix.substring(0, suffix.length - 1));
|
|
|
|
|
|
|
|
// * Logic for slash and existing suffix (example)
|
|
|
|
// No slash, no suffix: Add suffix (mozilla)
|
|
|
|
// No slash, yes suffix: Add slash (mozilla.com)
|
|
|
|
// Yes slash, no suffix: Insert suffix (mozilla/stuff)
|
|
|
|
// Yes slash, suffix before slash: Do nothing (mozilla.com/stuff)
|
|
|
|
// Yes slash, suffix after slash: Insert suffix (mozilla/?stuff=.com)
|
2010-09-16 00:51:24 -07:00
|
|
|
|
2008-09-25 04:33:51 -07:00
|
|
|
if (firstSlash >= 0) {
|
|
|
|
if (existingSuffix == -1 || existingSuffix > firstSlash)
|
|
|
|
url = url.substring(0, firstSlash) + suffix +
|
|
|
|
url.substring(firstSlash + 1);
|
|
|
|
} else
|
|
|
|
url = url + (existingSuffix == -1 ? suffix : "/");
|
|
|
|
|
|
|
|
url = "http://www." + url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var postData = {};
|
|
|
|
url = getShortcutOrURI(url, postData);
|
|
|
|
|
|
|
|
return [url, postData.value];
|
|
|
|
]]></body>
|
|
|
|
</method>
|
2010-03-26 14:59:02 -07:00
|
|
|
|
|
|
|
<field name="_contentIsCropped">false</field>
|
2008-09-25 04:33:51 -07:00
|
|
|
|
2007-06-27 15:31:06 -07:00
|
|
|
<method name="_initURLTooltip">
|
|
|
|
<body><![CDATA[
|
2010-03-26 14:59:02 -07:00
|
|
|
if (this.focused || !this._contentIsCropped)
|
2007-10-25 19:53:01 -07:00
|
|
|
return;
|
2007-06-27 15:31:06 -07:00
|
|
|
if (this._tooltipTimer)
|
|
|
|
clearTimeout(this._tooltipTimer);
|
2007-10-25 19:53:01 -07:00
|
|
|
this._tooltipTimer = setTimeout(function (self) {
|
2007-06-27 15:31:06 -07:00
|
|
|
self._tooltipTimer = 0;
|
2007-10-25 19:53:01 -07: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 15:31:06 -07: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 14:36:24 -08:00
|
|
|
<method name="onDragOver">
|
2009-06-20 17:04:07 -07:00
|
|
|
<parameter name="aEvent"/>
|
2007-11-28 14:36:24 -08:00
|
|
|
<body>
|
2009-06-20 17:04:07 -07:00
|
|
|
var types = aEvent.dataTransfer.types;
|
|
|
|
if (types.contains("application/x-moz-file") ||
|
|
|
|
types.contains("text/x-moz-url") ||
|
|
|
|
types.contains("text/uri-list") ||
|
|
|
|
types.contains("text/unicode"))
|
|
|
|
aEvent.preventDefault();
|
2007-11-28 14:36:24 -08:00
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="onDrop">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body><![CDATA[
|
2010-04-18 11:27:18 -07:00
|
|
|
let url = browserDragAndDrop.drop(aEvent, { })
|
2007-11-28 14:36:24 -08:00
|
|
|
|
|
|
|
// The URL bar automatically handles inputs with newline characters,
|
2009-06-20 17:04:07 -07:00
|
|
|
// so we can get away with treating text/x-moz-url flavours as text/plain.
|
2007-11-28 14:36:24 -08:00
|
|
|
if (url) {
|
2010-04-18 11:27:18 -07:00
|
|
|
aEvent.preventDefault();
|
2007-12-28 19:17:07 -08:00
|
|
|
this.value = url;
|
2008-02-07 01:01:05 -08:00
|
|
|
SetPageProxyState("invalid");
|
2011-05-11 06:15:34 -07:00
|
|
|
this.focus();
|
2007-11-28 14:36:24 -08:00
|
|
|
try {
|
2007-12-28 19:17:07 -08:00
|
|
|
urlSecurityCheck(this.value,
|
2007-11-28 14:36:24 -08:00
|
|
|
gBrowser.contentPrincipal,
|
2007-12-28 19:17:07 -08:00
|
|
|
Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
|
|
|
|
} catch (ex) {
|
|
|
|
return;
|
|
|
|
}
|
2008-09-25 04:33:51 -07:00
|
|
|
this.handleCommand();
|
2007-11-28 14:36:24 -08:00
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2008-10-08 07:42:39 -07:00
|
|
|
<method name="_getSelectedValueForClipboard">
|
|
|
|
<body><![CDATA[
|
2010-05-14 11:14:43 -07:00
|
|
|
// Grab the actual input field's value, not our value, which could include moz-action:
|
|
|
|
var inputVal = this.inputField.value;
|
|
|
|
var val = inputVal.substring(this.selectionStart, this.selectionEnd);
|
2008-10-08 07:42:39 -07:00
|
|
|
|
|
|
|
// If the entire value is selected and it's a valid non-javascript,
|
|
|
|
// non-data URI, encode it.
|
2010-05-14 11:14:43 -07:00
|
|
|
if (val == inputVal &&
|
2008-10-08 07:42:39 -07:00
|
|
|
this.getAttribute("pageproxystate") == "valid") {
|
|
|
|
let uri;
|
|
|
|
try {
|
2009-07-28 22:55:18 -07:00
|
|
|
uri = makeURI(val);
|
2008-10-08 07:42:39 -07:00
|
|
|
} catch (e) {}
|
2008-10-08 07:43:42 -07:00
|
|
|
|
|
|
|
if (uri && !uri.schemeIs("javascript") && !uri.schemeIs("data")) {
|
2008-10-08 07:42:39 -07:00
|
|
|
val = uri.spec;
|
2008-10-08 07:43:42 -07:00
|
|
|
|
|
|
|
// Parentheses are known to confuse third-party applications (bug 458565).
|
|
|
|
val = val.replace(/[()]/g, function (c) escape(c));
|
|
|
|
}
|
2008-10-08 07:42:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2007-06-27 15:31:06 -07:00
|
|
|
<field name="_copyCutController"><![CDATA[
|
|
|
|
({
|
|
|
|
urlbar: this,
|
|
|
|
doCommand: function(aCommand) {
|
2007-07-04 14:30:08 -07:00
|
|
|
var urlbar = this.urlbar;
|
2008-10-08 07:42:39 -07:00
|
|
|
var val = urlbar._getSelectedValueForClipboard();
|
|
|
|
if (!val)
|
2007-07-04 14:30:08 -07:00
|
|
|
return;
|
2008-01-28 23:50:13 -08:00
|
|
|
|
2008-10-08 07:42:39 -07:00
|
|
|
if (aCommand == "cmd_cut" && this.isCommandEnabled(aCommand)) {
|
|
|
|
let start = urlbar.selectionStart;
|
|
|
|
let end = urlbar.selectionEnd;
|
2010-05-14 11:14:43 -07:00
|
|
|
// This should reset any "moz-action:" prefix.
|
|
|
|
urlbar.value = urlbar.inputField.value.substring(0, start) +
|
|
|
|
urlbar.inputField.value.substring(end);
|
2008-10-08 07:42:39 -07:00
|
|
|
urlbar.selectionStart = urlbar.selectionEnd = start;
|
|
|
|
SetPageProxyState("invalid");
|
2007-07-04 14:30:08 -07:00
|
|
|
}
|
2008-10-08 07:42:39 -07:00
|
|
|
|
2008-01-12 02:19:31 -08:00
|
|
|
Cc["@mozilla.org/widget/clipboardhelper;1"]
|
|
|
|
.getService(Ci.nsIClipboardHelper)
|
|
|
|
.copyString(val);
|
2007-06-27 15:31:06 -07:00
|
|
|
},
|
|
|
|
supportsCommand: function(aCommand) {
|
|
|
|
switch (aCommand) {
|
|
|
|
case "cmd_copy":
|
|
|
|
case "cmd_cut":
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
isCommandEnabled: function(aCommand) {
|
2008-02-09 22:45:56 -08:00
|
|
|
return this.supportsCommand(aCommand) &&
|
|
|
|
(aCommand != "cmd_cut" || !this.urlbar.readOnly) &&
|
|
|
|
this.urlbar.selectionStart < this.urlbar.selectionEnd;
|
2007-06-27 15:31:06 -07:00
|
|
|
},
|
|
|
|
onEvent: function(aEventName) {}
|
|
|
|
})
|
|
|
|
]]></field>
|
|
|
|
|
|
|
|
<method name="observe">
|
|
|
|
<parameter name="aSubject"/>
|
|
|
|
<parameter name="aTopic"/>
|
|
|
|
<parameter name="aData"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
if (aTopic == "nsPref:changed") {
|
2010-02-06 02:40:06 -08:00
|
|
|
switch (aData) {
|
2007-06-27 15:31:06 -07:00
|
|
|
case "clickSelectsAll":
|
2007-08-04 01:35:28 -07:00
|
|
|
case "doubleClickSelectsAll":
|
|
|
|
this[aData] = this._prefs.getBoolPref(aData);
|
2007-06-27 15:31:06 -07:00
|
|
|
break;
|
2007-07-03 10:40:40 -07:00
|
|
|
case "autoFill":
|
|
|
|
this.completeDefaultIndex = this._prefs.getBoolPref(aData);
|
|
|
|
break;
|
2009-06-17 08:27:04 -07:00
|
|
|
case "delay":
|
|
|
|
this.timeout = this._prefs.getIntPref(aData);
|
|
|
|
break;
|
2011-05-02 10:50:18 -07:00
|
|
|
case "formatting.enabled":
|
|
|
|
this._formattingEnabled = this._prefs.getBoolPref(aData);
|
|
|
|
break;
|
2007-06-27 15:31:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
2007-08-04 01:35:28 -07:00
|
|
|
|
|
|
|
<method name="handleEvent">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body><![CDATA[
|
2007-10-25 19:53:01 -07: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;
|
2010-03-26 14:59:02 -07:00
|
|
|
case "overflow":
|
|
|
|
this._contentIsCropped = true;
|
|
|
|
break;
|
|
|
|
case "underflow":
|
|
|
|
this._contentIsCropped = false;
|
|
|
|
this._hideURLTooltip();
|
|
|
|
break;
|
2007-08-04 01:35:28 -07:00
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
2008-03-12 16:39:40 -07:00
|
|
|
|
|
|
|
<property name="textValue"
|
|
|
|
onget="return this.value;">
|
|
|
|
<setter>
|
|
|
|
<![CDATA[
|
|
|
|
try {
|
2009-07-28 22:55:18 -07:00
|
|
|
val = losslessDecodeURI(makeURI(val));
|
2008-03-28 01:45:18 -07:00
|
|
|
} catch (ex) { }
|
|
|
|
this.value = val;
|
2008-03-12 16:39:40 -07:00
|
|
|
|
|
|
|
// Completing a result should simulate the user typing the result, so
|
|
|
|
// fire an input event.
|
|
|
|
let evt = document.createEvent("UIEvents");
|
|
|
|
evt.initUIEvent("input", true, false, window, 0);
|
|
|
|
this.mIgnoreInput = true;
|
|
|
|
this.dispatchEvent(evt);
|
|
|
|
this.mIgnoreInput = false;
|
|
|
|
|
|
|
|
return this.value;
|
|
|
|
]]>
|
|
|
|
</setter>
|
|
|
|
</property>
|
2010-02-11 00:32:25 -08:00
|
|
|
|
2010-03-26 14:59:02 -07:00
|
|
|
<method name="_parseActionUrl">
|
|
|
|
<parameter name="aUrl"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
if (!/^moz-action:/.test(aUrl))
|
|
|
|
return null;
|
|
|
|
|
|
|
|
// url is in the format moz-action:ACTION,PARAM
|
|
|
|
let [, action, param] = aUrl.match(/^moz-action:([^,]+),(.*)$/);
|
|
|
|
return {type: action, param: param};
|
|
|
|
]]></body>
|
|
|
|
</method>
|
2010-09-14 22:41:16 -07:00
|
|
|
|
2010-12-10 18:32:14 -08:00
|
|
|
<field name="_numNoActionsKeys"><![CDATA[
|
|
|
|
0
|
|
|
|
]]></field>
|
|
|
|
|
|
|
|
<method name="_clearNoActions">
|
|
|
|
<parameter name="aURL"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
this._numNoActionsKeys = 0;
|
|
|
|
this.popup.removeAttribute("noactions");
|
|
|
|
let action = this._parseActionUrl(this._value);
|
|
|
|
if (action)
|
|
|
|
this.setAttribute("actiontype", action.type);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
2007-06-27 15:31:06 -07:00
|
|
|
</implementation>
|
|
|
|
|
|
|
|
<handlers>
|
2010-12-10 18:32:14 -08:00
|
|
|
<handler event="keydown"><![CDATA[
|
|
|
|
if ((event.keyCode === KeyEvent.DOM_VK_ALT ||
|
|
|
|
event.keyCode === KeyEvent.DOM_VK_SHIFT) &&
|
|
|
|
this.popup.selectedIndex >= 0) {
|
|
|
|
this._numNoActionsKeys++;
|
|
|
|
this.popup.setAttribute("noactions", "true");
|
|
|
|
this.removeAttribute("actiontype");
|
|
|
|
}
|
|
|
|
]]></handler>
|
|
|
|
|
|
|
|
<handler event="keyup"><![CDATA[
|
|
|
|
if ((event.keyCode === KeyEvent.DOM_VK_ALT ||
|
|
|
|
event.keyCode === KeyEvent.DOM_VK_SHIFT) &&
|
|
|
|
this._numNoActionsKeys > 0) {
|
|
|
|
this._numNoActionsKeys--;
|
|
|
|
if (this._numNoActionsKeys == 0)
|
|
|
|
this._clearNoActions();
|
|
|
|
}
|
|
|
|
]]></handler>
|
|
|
|
|
|
|
|
<handler event="blur"><![CDATA[
|
|
|
|
this._clearNoActions();
|
|
|
|
]]></handler>
|
|
|
|
|
2009-06-18 01:57:14 -07:00
|
|
|
<handler event="draggesture" phase="capturing"><![CDATA[
|
|
|
|
// TODO: This should use dragstart but editor code is still using
|
|
|
|
// the old drag & drop APIs, so we have to handle draggesture.
|
|
|
|
// This can be changed once editor code is updated to the new API.
|
|
|
|
// See bug 499008 for details.
|
|
|
|
|
|
|
|
// Drag only if the gesture starts from the input field.
|
|
|
|
if (event.originalTarget != this.inputField)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Drag only if the entire value is selected and it's a valid URI.
|
|
|
|
var isFullSelection = this.selectionStart == 0 &&
|
|
|
|
this.selectionEnd == this.textLength;
|
|
|
|
if (!isFullSelection ||
|
|
|
|
this.getAttribute("pageproxystate") != "valid")
|
|
|
|
return;
|
|
|
|
|
|
|
|
var urlString = content.location.href;
|
|
|
|
var title = content.document.title || urlString;
|
|
|
|
var htmlString = "<a href=\"" + urlString + "\">" + urlString + "</a>";
|
|
|
|
|
|
|
|
var dt = event.dataTransfer;
|
|
|
|
dt.setData("text/x-moz-url", urlString + "\n" + title);
|
|
|
|
dt.setData("text/unicode", urlString);
|
|
|
|
dt.setData("text/html", htmlString);
|
|
|
|
|
|
|
|
dt.effectAllowed = "copyLink";
|
|
|
|
event.stopPropagation();
|
|
|
|
]]></handler>
|
2010-09-14 22:41:16 -07:00
|
|
|
|
|
|
|
<handler event="focus" phase="capturing"><![CDATA[
|
|
|
|
this._hideURLTooltip();
|
|
|
|
]]></handler>
|
|
|
|
|
2009-06-20 17:04:07 -07:00
|
|
|
<handler event="dragover" phase="capturing" action="this.onDragOver(event, this);"/>
|
|
|
|
<handler event="drop" phase="capturing" action="this.onDrop(event, this);"/>
|
2008-10-08 07:42:39 -07:00
|
|
|
<handler event="select"><![CDATA[
|
|
|
|
if (!Cc["@mozilla.org/widget/clipboard;1"]
|
|
|
|
.getService(Ci.nsIClipboard)
|
|
|
|
.supportsSelectionClipboard())
|
|
|
|
return;
|
|
|
|
|
|
|
|
var val = this._getSelectedValueForClipboard();
|
|
|
|
if (!val)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Cc["@mozilla.org/widget/clipboardhelper;1"]
|
|
|
|
.getService(Ci.nsIClipboardHelper)
|
|
|
|
.copyStringToClipboard(val, Ci.nsIClipboard.kSelectionClipboard);
|
|
|
|
]]></handler>
|
2007-06-27 15:31:06 -07:00
|
|
|
</handlers>
|
|
|
|
|
|
|
|
</binding>
|
|
|
|
|
2007-12-13 13:21:16 -08: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-04 21:51:15 -07:00
|
|
|
<implementation>
|
2007-12-04 13:00:12 -08: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 10:36:52 -08:00
|
|
|
|
2007-06-04 21:51:15 -07:00
|
|
|
<method name="onPopupClick">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body><![CDATA[
|
2007-12-13 13:21:16 -08:00
|
|
|
// Ignore all right-clicks
|
|
|
|
if (aEvent.button == 2)
|
|
|
|
return;
|
|
|
|
|
2007-06-04 21:51:15 -07:00
|
|
|
var controller = this.view.QueryInterface(Components.interfaces.nsIAutoCompleteController);
|
|
|
|
|
2007-12-13 13:21:16 -08:00
|
|
|
// Check for unmodified left-click, and use default behavior
|
2007-06-04 21:51:15 -07:00
|
|
|
if (aEvent.button == 0 && !aEvent.shiftKey && !aEvent.ctrlKey &&
|
|
|
|
!aEvent.altKey && !aEvent.metaKey) {
|
2008-02-29 05:07:02 -08:00
|
|
|
controller.handleEnter(true);
|
2007-12-13 13:21:16 -08:00
|
|
|
return;
|
2007-06-04 21:51:15 -07:00
|
|
|
}
|
2007-12-13 13:21:16 -08: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);
|
2010-09-16 00:51:24 -07:00
|
|
|
|
2007-12-13 13:21:16 -08:00
|
|
|
// 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-04 21:51:15 -07:00
|
|
|
}
|
2007-12-04 13:00:12 -08:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
</implementation>
|
|
|
|
</binding>
|
2007-11-29 20:57:57 -08:00
|
|
|
|
2007-12-04 13:00:12 -08:00
|
|
|
<binding id="urlbar-rich-result-popup" extends="chrome://global/content/bindings/autocomplete.xml#autocomplete-rich-result-popup">
|
|
|
|
<implementation>
|
2007-11-29 20:57:57 -08:00
|
|
|
<field name="_maxResults">0</field>
|
|
|
|
|
2007-12-04 22:19:38 -08: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-29 20:57:57 -08: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 13:00:12 -08: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-29 20:57:57 -08:00
|
|
|
<method name="onPopupClick">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
2007-12-13 13:21:16 -08:00
|
|
|
// Ignore right-clicks
|
|
|
|
if (aEvent.button == 2)
|
|
|
|
return;
|
|
|
|
|
2007-11-29 20:57:57 -08:00
|
|
|
var controller = this.view.QueryInterface(Components.interfaces.nsIAutoCompleteController);
|
|
|
|
|
2007-12-13 13:21:16 -08:00
|
|
|
// Check for unmodified left-click, and use default behavior
|
2007-11-29 20:57:57 -08:00
|
|
|
if (aEvent.button == 0 && !aEvent.shiftKey && !aEvent.ctrlKey &&
|
|
|
|
!aEvent.altKey && !aEvent.metaKey) {
|
2008-02-29 05:07:02 -08:00
|
|
|
controller.handleEnter(true);
|
2007-12-13 13:21:16 -08:00
|
|
|
return;
|
2007-11-29 20:57:57 -08:00
|
|
|
}
|
2007-12-13 13:21:16 -08: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();
|
|
|
|
|
2010-03-26 14:59:02 -07:00
|
|
|
// Check if this is meant to be an action
|
|
|
|
let action = this.mInput._parseActionUrl(url);
|
|
|
|
if (action) {
|
|
|
|
if (action.type == "switchtab")
|
|
|
|
url = action.param;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-12-13 13:21:16 -08:00
|
|
|
// respect the usual clicking subtleties
|
|
|
|
openUILink(url, aEvent);
|
2007-11-29 20:57:57 -08:00
|
|
|
}
|
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
2007-12-04 22:19:38 -08: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-04 21:51:15 -07:00
|
|
|
</implementation>
|
|
|
|
</binding>
|
2010-08-30 09:55:17 -07:00
|
|
|
|
|
|
|
<binding id="geolocation-notification" extends="chrome://global/content/bindings/notification.xml#popup-notification">
|
2010-12-07 12:45:31 -08:00
|
|
|
<content align="start">
|
2010-08-30 09:55:17 -07:00
|
|
|
<xul:image class="popup-notification-icon"
|
|
|
|
xbl:inherits="popupid"/>
|
2010-12-07 12:45:31 -08:00
|
|
|
<xul:vbox flex="1">
|
2010-08-30 09:55:17 -07:00
|
|
|
<xul:description class="popup-notification-description"
|
2010-12-03 13:39:11 -08:00
|
|
|
xbl:inherits="xbl:text=label"/>
|
2010-08-30 09:55:17 -07:00
|
|
|
<xul:spacer flex="1"/>
|
2011-02-12 00:32:07 -08:00
|
|
|
<xul:hbox class="popup-notification-button-container"
|
|
|
|
pack="end" align="center">
|
2010-08-30 09:55:17 -07:00
|
|
|
<xul:label anonid="learnmore" class="text-link geolocation-text-link"/>
|
|
|
|
<xul:spacer flex="1"/>
|
|
|
|
<xul:button anonid="button"
|
2010-12-16 09:53:24 -08:00
|
|
|
type="menu-button"
|
2010-08-30 09:55:17 -07:00
|
|
|
class="popup-notification-menubutton"
|
2010-12-16 09:53:24 -08:00
|
|
|
xbl:inherits="oncommand=buttoncommand,label=buttonlabel,accesskey=buttonaccesskey">
|
2010-08-30 09:55:17 -07:00
|
|
|
<xul:menupopup anonid="menupopup"
|
|
|
|
xbl:inherits="oncommand=menucommand">
|
|
|
|
<children/>
|
2010-12-16 09:53:24 -08:00
|
|
|
<xul:menuitem class="menuitem-iconic popup-notification-closeitem"
|
|
|
|
label="&closeNotificationItem.label;"
|
|
|
|
xbl:inherits="oncommand=closeitemcommand"/>
|
2010-08-30 09:55:17 -07:00
|
|
|
</xul:menupopup>
|
|
|
|
</xul:button>
|
|
|
|
</xul:hbox>
|
|
|
|
</xul:vbox>
|
2011-01-13 16:07:44 -08:00
|
|
|
<xul:vbox pack="start">
|
|
|
|
<xul:toolbarbutton anonid="closebutton"
|
|
|
|
class="messageCloseButton popup-notification-closebutton"
|
|
|
|
xbl:inherits="oncommand=closebuttoncommand"
|
|
|
|
tooltiptext="&closeNotification.tooltip;"/>
|
|
|
|
</xul:vbox>
|
2010-08-30 09:55:17 -07:00
|
|
|
</content>
|
|
|
|
<implementation>
|
|
|
|
<constructor><![CDATA[
|
|
|
|
let link = document.getAnonymousElementByAttribute(this, "anonid", "learnmore");
|
|
|
|
link.value = gNavigatorBundle.getString("geolocation.learnMore");
|
|
|
|
|
|
|
|
let formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"].getService(Ci.nsIURLFormatter);
|
|
|
|
link.href = formatter.formatURLPref("browser.geolocation.warning.infoURL");
|
|
|
|
]]></constructor>
|
|
|
|
</implementation>
|
|
|
|
</binding>
|
2010-12-02 00:45:08 -08:00
|
|
|
|
2011-01-03 11:40:47 -08:00
|
|
|
<binding id="addon-progress-notification" extends="chrome://global/content/bindings/notification.xml#popup-notification">
|
|
|
|
<content align="start">
|
|
|
|
<xul:image class="popup-notification-icon"
|
|
|
|
xbl:inherits="popupid"/>
|
|
|
|
<xul:vbox flex="1">
|
|
|
|
<xul:description class="popup-notification-description addon-progress-description"
|
|
|
|
xbl:inherits="xbl:text=label"/>
|
|
|
|
<xul:spacer flex="1"/>
|
|
|
|
<xul:hbox align="center">
|
|
|
|
<xul:progressmeter anonid="progressmeter" flex="1" mode="undetermined" class="popup-progress-meter"/>
|
|
|
|
<xul:button anonid="cancel" class="popup-progress-cancel" oncommand="document.getBindingParent(this).cancel()"/>
|
|
|
|
</xul:hbox>
|
|
|
|
<xul:label anonid="progresstext" class="popup-progress-label"/>
|
2011-02-12 00:32:07 -08:00
|
|
|
<xul:hbox class="popup-notification-button-container"
|
|
|
|
pack="end" align="center">
|
2011-01-03 11:40:47 -08:00
|
|
|
<xul:button anonid="button"
|
|
|
|
class="popup-notification-menubutton"
|
|
|
|
type="menu-button"
|
|
|
|
xbl:inherits="oncommand=buttoncommand,label=buttonlabel,accesskey=buttonaccesskey">
|
|
|
|
<xul:menupopup anonid="menupopup"
|
|
|
|
xbl:inherits="oncommand=menucommand">
|
|
|
|
<children/>
|
|
|
|
<xul:menuitem class="menuitem-iconic popup-notification-closeitem"
|
|
|
|
label="&closeNotificationItem.label;"
|
|
|
|
xbl:inherits="oncommand=closeitemcommand"/>
|
|
|
|
</xul:menupopup>
|
|
|
|
</xul:button>
|
|
|
|
</xul:hbox>
|
|
|
|
</xul:vbox>
|
2011-01-13 16:07:44 -08:00
|
|
|
<xul:vbox pack="start">
|
|
|
|
<xul:toolbarbutton anonid="closebutton"
|
|
|
|
class="messageCloseButton popup-notification-closebutton"
|
|
|
|
xbl:inherits="oncommand=closebuttoncommand"
|
|
|
|
tooltiptext="&closeNotification.tooltip;"/>
|
|
|
|
</xul:vbox>
|
2011-01-03 11:40:47 -08:00
|
|
|
</content>
|
|
|
|
<implementation>
|
|
|
|
<constructor><![CDATA[
|
|
|
|
this.cancelbtn.setAttribute("tooltiptext", gNavigatorBundle.getString("addonDownloadCancelTooltip"));
|
|
|
|
|
|
|
|
this.notification.options.installs.forEach(function(aInstall) {
|
|
|
|
aInstall.addListener(this);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
// Calling updateProgress can sometimes cause this notification to be
|
|
|
|
// removed in the middle of refreshing the notification panel which
|
|
|
|
// makes the panel get refreshed again. Just initialise to the
|
2011-02-15 15:10:17 -08:00
|
|
|
// undetermined state and then schedule a proper check at the next
|
|
|
|
// opportunity
|
2011-01-03 11:40:47 -08:00
|
|
|
this.setProgress(0, -1);
|
2011-02-15 15:10:17 -08:00
|
|
|
setTimeout(this.updateProgress.bind(this), 0);
|
2011-01-03 11:40:47 -08:00
|
|
|
]]></constructor>
|
|
|
|
|
|
|
|
<destructor><![CDATA[
|
|
|
|
this.destroy();
|
|
|
|
]]></destructor>
|
|
|
|
|
|
|
|
<field name="progressmeter" readonly="true">
|
|
|
|
document.getAnonymousElementByAttribute(this, "anonid", "progressmeter");
|
|
|
|
</field>
|
|
|
|
<field name="progresstext" readonly="true">
|
|
|
|
document.getAnonymousElementByAttribute(this, "anonid", "progresstext");
|
|
|
|
</field>
|
|
|
|
<field name="cancelbtn" readonly="true">
|
|
|
|
document.getAnonymousElementByAttribute(this, "anonid", "cancel");
|
|
|
|
</field>
|
|
|
|
<field name="DownloadUtils" readonly="true">
|
|
|
|
let utils = {};
|
|
|
|
Components.utils.import("resource://gre/modules/DownloadUtils.jsm", utils);
|
|
|
|
utils.DownloadUtils;
|
|
|
|
</field>
|
|
|
|
|
|
|
|
<method name="destroy">
|
|
|
|
<body><![CDATA[
|
|
|
|
this.notification.options.installs.forEach(function(aInstall) {
|
|
|
|
aInstall.removeListener(this);
|
|
|
|
}, this);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="setProgress">
|
|
|
|
<parameter name="aProgress"/>
|
|
|
|
<parameter name="aMaxProgress"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
if (aMaxProgress == -1) {
|
|
|
|
this.progressmeter.mode = "undetermined";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.progressmeter.mode = "determined";
|
|
|
|
this.progressmeter.value = (aProgress * 100) / aMaxProgress;
|
|
|
|
}
|
|
|
|
|
|
|
|
let now = Date.now();
|
|
|
|
|
|
|
|
if (!this.notification.lastUpdate) {
|
|
|
|
this.notification.lastUpdate = now;
|
|
|
|
this.notification.lastProgress = aProgress;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let delta = now - this.notification.lastUpdate;
|
|
|
|
if ((delta < 400) && (aProgress < aMaxProgress))
|
|
|
|
return;
|
|
|
|
|
|
|
|
delta /= 1000;
|
|
|
|
|
|
|
|
// This code is taken from nsDownloadManager.cpp
|
|
|
|
let speed = (aProgress - this.notification.lastProgress) / delta;
|
|
|
|
if (this.notification.speed)
|
|
|
|
speed = speed * 0.9 + this.notification.speed * 0.1;
|
|
|
|
|
|
|
|
this.notification.lastUpdate = now;
|
|
|
|
this.notification.lastProgress = aProgress;
|
|
|
|
this.notification.speed = speed;
|
|
|
|
|
|
|
|
let status = null;
|
|
|
|
[status, this.notification.last] = this.DownloadUtils.getDownloadStatus(aProgress, aMaxProgress, speed, this.notification.last);
|
|
|
|
this.progresstext.value = status;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="cancel">
|
|
|
|
<body><![CDATA[
|
|
|
|
// Cache these as cancelling the installs will remove this
|
2011-01-07 09:16:35 -08:00
|
|
|
// notification which will drop these references
|
2011-01-03 11:40:47 -08:00
|
|
|
let browser = this.notification.browser;
|
|
|
|
let contentWindow = this.notification.options.contentWindow;
|
|
|
|
let sourceURI = this.notification.options.sourceURI;
|
|
|
|
|
|
|
|
let installs = this.notification.options.installs;
|
|
|
|
installs.forEach(function(aInstall) {
|
|
|
|
try {
|
|
|
|
aInstall.cancel();
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
// Cancel will throw if the download has already failed
|
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
let anchorID = "addons-notification-icon";
|
|
|
|
let notificationID = "addon-install-cancelled";
|
|
|
|
let messageString = gNavigatorBundle.getString("addonDownloadCancelled");
|
|
|
|
messageString = PluralForm.get(installs.length, messageString);
|
|
|
|
let buttonText = gNavigatorBundle.getString("addonDownloadRestart");
|
|
|
|
buttonText = PluralForm.get(installs.length, buttonText);
|
|
|
|
|
|
|
|
let action = {
|
|
|
|
label: buttonText,
|
|
|
|
accessKey: gNavigatorBundle.getString("addonDownloadRestart.accessKey"),
|
|
|
|
callback: function() {
|
|
|
|
let weblistener = Cc["@mozilla.org/addons/web-install-listener;1"].
|
|
|
|
getService(Ci.amIWebInstallListener);
|
|
|
|
if (weblistener.onWebInstallRequested(contentWindow, sourceURI,
|
|
|
|
installs, installs.length)) {
|
|
|
|
installs.forEach(function(aInstall) {
|
|
|
|
aInstall.install();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
PopupNotifications.show(browser, notificationID, messageString,
|
|
|
|
anchorID, action);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="updateProgress">
|
|
|
|
<body><![CDATA[
|
|
|
|
let downloadingCount = 0;
|
|
|
|
let progress = 0;
|
|
|
|
let maxProgress = 0;
|
|
|
|
|
|
|
|
this.notification.options.installs.forEach(function(aInstall) {
|
|
|
|
if (aInstall.maxProgress == -1)
|
|
|
|
maxProgress = -1;
|
|
|
|
progress += aInstall.progress;
|
|
|
|
if (maxProgress >= 0)
|
|
|
|
maxProgress += aInstall.maxProgress;
|
|
|
|
if (aInstall.state < AddonManager.STATE_DOWNLOADED)
|
|
|
|
downloadingCount++;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (downloadingCount == 0) {
|
|
|
|
this.destroy();
|
|
|
|
PopupNotifications.remove(this.notification);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.setProgress(progress, maxProgress);
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="onDownloadProgress">
|
|
|
|
<body><![CDATA[
|
|
|
|
this.updateProgress();
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="onDownloadFailed">
|
|
|
|
<body><![CDATA[
|
|
|
|
this.updateProgress();
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="onDownloadCancelled">
|
|
|
|
<body><![CDATA[
|
|
|
|
this.updateProgress();
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="onDownloadEnded">
|
|
|
|
<body><![CDATA[
|
|
|
|
this.updateProgress();
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
</implementation>
|
|
|
|
</binding>
|
2011-01-11 02:59:42 -08:00
|
|
|
|
|
|
|
<binding id="splitmenu">
|
|
|
|
<content>
|
2011-01-22 03:21:53 -08:00
|
|
|
<xul:hbox anonid="menuitem" flex="1"
|
|
|
|
class="splitmenu-menuitem"
|
|
|
|
xbl:inherits="iconic,label,disabled,onclick=oncommand,_moz-menuactive=active"/>
|
|
|
|
<xul:menu anonid="menu" class="splitmenu-menu"
|
2011-02-16 07:53:32 -08:00
|
|
|
xbl:inherits="disabled,_moz-menuactive=active"
|
2011-01-11 02:59:42 -08:00
|
|
|
oncommand="event.stopPropagation();">
|
|
|
|
<children includes="menupopup"/>
|
|
|
|
</xul:menu>
|
|
|
|
</content>
|
|
|
|
|
2011-03-02 10:47:03 -08:00
|
|
|
<implementation implements="nsIDOMEventListener">
|
|
|
|
<constructor><![CDATA[
|
|
|
|
this._parentMenupopup.addEventListener("DOMMenuItemActive", this, false);
|
|
|
|
this._parentMenupopup.addEventListener("popuphidden", this, false);
|
|
|
|
]]></constructor>
|
|
|
|
|
|
|
|
<destructor><![CDATA[
|
|
|
|
this._parentMenupopup.removeEventListener("DOMMenuItemActive", this, false);
|
|
|
|
this._parentMenupopup.removeEventListener("popuphidden", this, false);
|
|
|
|
]]></destructor>
|
|
|
|
|
2011-01-22 03:21:53 -08:00
|
|
|
<field name="menuitem" readonly="true">
|
|
|
|
document.getAnonymousElementByAttribute(this, "anonid", "menuitem");
|
|
|
|
</field>
|
|
|
|
<field name="menu" readonly="true">
|
|
|
|
document.getAnonymousElementByAttribute(this, "anonid", "menu");
|
2011-01-11 02:59:42 -08:00
|
|
|
</field>
|
2011-01-22 03:21:53 -08:00
|
|
|
|
|
|
|
<field name="_menuDelay">600</field>
|
|
|
|
|
|
|
|
<field name="_parentMenupopup"><![CDATA[
|
2011-03-02 10:47:03 -08:00
|
|
|
this._getParentMenupopup(this);
|
2011-01-22 03:21:53 -08:00
|
|
|
]]></field>
|
2011-03-02 10:47:03 -08:00
|
|
|
|
|
|
|
<method name="_getParentMenupopup">
|
|
|
|
<parameter name="aNode"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
let node = aNode.parentNode;
|
|
|
|
while (node) {
|
|
|
|
if (node.localName == "menupopup")
|
|
|
|
break;
|
|
|
|
node = node.parentNode;
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="handleEvent">
|
|
|
|
<parameter name="event"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
switch (event.type) {
|
|
|
|
case "DOMMenuItemActive":
|
|
|
|
if (this.getAttribute("active") == "true" &&
|
|
|
|
event.target != this &&
|
|
|
|
this._getParentMenupopup(event.target) == this._parentMenupopup)
|
|
|
|
this.removeAttribute("active");
|
|
|
|
break;
|
|
|
|
case "popuphidden":
|
|
|
|
if (event.target == this._parentMenupopup)
|
|
|
|
this.removeAttribute("active");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
2011-01-11 02:59:42 -08:00
|
|
|
</implementation>
|
2011-01-22 03:21:53 -08:00
|
|
|
|
|
|
|
<handlers>
|
|
|
|
<handler event="mouseover"><![CDATA[
|
2011-03-23 04:36:13 -07:00
|
|
|
if (this.getAttribute("active") != "true") {
|
2011-01-22 03:21:53 -08:00
|
|
|
this.setAttribute("active", "true");
|
|
|
|
|
2011-03-02 10:47:03 -08:00
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("DOMMenuItemActive", true, false);
|
|
|
|
this.dispatchEvent(event);
|
|
|
|
|
2011-03-23 04:36:13 -07:00
|
|
|
if (this.getAttribute("disabled") != "true") {
|
|
|
|
let self = this;
|
|
|
|
setTimeout(function () {
|
|
|
|
if (self.getAttribute("active") == "true")
|
|
|
|
self.menu.open = true;
|
|
|
|
}, this._menuDelay);
|
|
|
|
}
|
2011-01-22 03:21:53 -08:00
|
|
|
}
|
|
|
|
]]></handler>
|
|
|
|
|
2011-01-26 10:54:14 -08:00
|
|
|
<handler event="popupshowing"><![CDATA[
|
|
|
|
if (event.target == this.firstChild &&
|
|
|
|
this._parentMenupopup._currentPopup)
|
|
|
|
this._parentMenupopup._currentPopup.hidePopup();
|
|
|
|
]]></handler>
|
|
|
|
|
2011-01-22 03:21:53 -08:00
|
|
|
<handler event="click" phase="capturing"><![CDATA[
|
2011-03-03 02:34:55 -08:00
|
|
|
if (this.getAttribute("disabled") == "true") {
|
|
|
|
// Prevent the command from being carried out
|
|
|
|
event.stopPropagation();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-22 03:21:53 -08:00
|
|
|
let node = event.originalTarget;
|
|
|
|
while (true) {
|
|
|
|
if (node == this.menuitem)
|
|
|
|
break;
|
|
|
|
if (node == this)
|
|
|
|
return;
|
|
|
|
node = node.parentNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._parentMenupopup.hidePopup();
|
|
|
|
]]></handler>
|
|
|
|
</handlers>
|
2011-01-11 02:59:42 -08:00
|
|
|
</binding>
|
2010-09-07 13:37:04 -07:00
|
|
|
|
|
|
|
<binding id="menuitem-tooltip" extends="chrome://global/content/bindings/menu.xml#menuitem">
|
|
|
|
<implementation>
|
|
|
|
<constructor><![CDATA[
|
|
|
|
this.setAttribute("tooltiptext", this.getAttribute("acceltext"));
|
|
|
|
// TODO: Simplify this to this.setAttribute("acceltext", "") once bug
|
|
|
|
// 592424 is fixed
|
|
|
|
document.getAnonymousElementByAttribute(this, "anonid", "accel").firstChild.setAttribute("value", "");
|
|
|
|
]]></constructor>
|
|
|
|
</implementation>
|
|
|
|
</binding>
|
|
|
|
|
|
|
|
<binding id="menuitem-iconic-tooltip" extends="chrome://global/content/bindings/menu.xml#menuitem-iconic">
|
|
|
|
<implementation>
|
|
|
|
<constructor><![CDATA[
|
|
|
|
this.setAttribute("tooltiptext", this.getAttribute("acceltext"));
|
|
|
|
// TODO: Simplify this to this.setAttribute("acceltext", "") once bug
|
|
|
|
// 592424 is fixed
|
|
|
|
document.getAnonymousElementByAttribute(this, "anonid", "accel").firstChild.setAttribute("value", "");
|
|
|
|
]]></constructor>
|
|
|
|
</implementation>
|
|
|
|
</binding>
|
2011-01-22 03:21:53 -08:00
|
|
|
|
2007-06-04 21:51:15 -07:00
|
|
|
</bindings>
|