2007-03-22 10:30:00 -07:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
# -*- Mode: HTML -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
<!DOCTYPE bindings [
|
|
|
|
<!ENTITY % searchBarDTD SYSTEM "chrome://browser/locale/searchbar.dtd" >
|
|
|
|
%searchBarDTD;
|
2007-06-14 18:50:37 -07:00
|
|
|
<!ENTITY % browserDTD SYSTEM "chrome://browser/locale/browser.dtd">
|
|
|
|
%browserDTD;
|
2007-03-22 10:30:00 -07:00
|
|
|
]>
|
|
|
|
|
|
|
|
<bindings id="SearchBindings"
|
2012-02-23 04:55:04 -08:00
|
|
|
xmlns="http://www.mozilla.org/xbl"
|
|
|
|
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
|
|
|
xmlns:xbl="http://www.mozilla.org/xbl">
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-23 22:00:27 -08:00
|
|
|
<binding id="searchbar">
|
2007-03-22 10:30:00 -07:00
|
|
|
<resources>
|
|
|
|
<stylesheet src="chrome://browser/content/search/searchbarBindings.css"/>
|
|
|
|
<stylesheet src="chrome://browser/skin/searchbar.css"/>
|
|
|
|
</resources>
|
|
|
|
<content>
|
|
|
|
<xul:stringbundle src="chrome://browser/locale/search.properties"
|
|
|
|
anonid="searchbar-stringbundle"/>
|
|
|
|
|
2007-11-23 22:00:27 -08:00
|
|
|
<xul:textbox class="searchbar-textbox"
|
|
|
|
anonid="searchbar-textbox"
|
|
|
|
type="autocomplete"
|
|
|
|
flex="1"
|
|
|
|
autocompletepopup="PopupAutoComplete"
|
|
|
|
autocompletesearch="search-autocomplete"
|
|
|
|
autocompletesearchparam="searchbar-history"
|
|
|
|
timeout="250"
|
|
|
|
maxrows="10"
|
|
|
|
completeselectedindex="true"
|
|
|
|
showcommentcolumn="true"
|
|
|
|
tabscrolling="true"
|
|
|
|
xbl:inherits="disabled,disableautocomplete,searchengine,src,newlines">
|
2010-02-21 07:03:52 -08:00
|
|
|
<xul:box>
|
|
|
|
<xul:button class="searchbar-engine-button"
|
|
|
|
type="menu"
|
|
|
|
anonid="searchbar-engine-button">
|
|
|
|
<xul:image class="searchbar-engine-image" xbl:inherits="src"/>
|
|
|
|
<xul:image class="searchbar-dropmarker-image"/>
|
|
|
|
<xul:menupopup class="searchbar-popup"
|
|
|
|
anonid="searchbar-popup">
|
|
|
|
<xul:menuseparator/>
|
|
|
|
<xul:menuitem class="open-engine-manager"
|
|
|
|
anonid="open-engine-manager"
|
|
|
|
label="&cmd_engineManager.label;"
|
|
|
|
oncommand="openManager(event);"/>
|
|
|
|
</xul:menupopup>
|
|
|
|
</xul:button>
|
|
|
|
</xul:box>
|
2009-07-29 11:33:53 -07:00
|
|
|
<xul:hbox class="search-go-container">
|
2007-11-23 22:00:27 -08:00
|
|
|
<xul:image class="search-go-button"
|
|
|
|
anonid="search-go-button"
|
|
|
|
onclick="handleSearchCommand(event);"
|
2012-02-23 04:55:04 -08:00
|
|
|
tooltiptext="&searchEndCap.label;"/>
|
2007-03-22 10:30:00 -07:00
|
|
|
</xul:hbox>
|
2007-11-23 22:00:27 -08:00
|
|
|
</xul:textbox>
|
2007-03-22 10:30:00 -07:00
|
|
|
</content>
|
|
|
|
|
|
|
|
<implementation implements="nsIObserver">
|
|
|
|
<constructor><![CDATA[
|
|
|
|
if (this.parentNode.parentNode.localName == "toolbarpaletteitem")
|
|
|
|
return;
|
2012-04-19 07:08:09 -07:00
|
|
|
// Make sure we rebuild the popup in onpopupshowing
|
|
|
|
this._needToBuildPopup = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-04-19 07:08:09 -07:00
|
|
|
var os =
|
2007-03-22 10:30:00 -07:00
|
|
|
Components.classes["@mozilla.org/observer-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIObserverService);
|
2012-04-19 07:08:09 -07:00
|
|
|
os.addObserver(this, "browser-search-engine-modified", false);
|
2010-09-16 00:51:24 -07:00
|
|
|
|
2012-04-19 07:08:09 -07:00
|
|
|
this._addedObserver = true;
|
|
|
|
|
|
|
|
this.searchService.init((function search_init_cb(aStatus) {
|
|
|
|
if (Components.isSuccessCode(aStatus)) {
|
|
|
|
// Refresh the display (updating icon, etc)
|
|
|
|
this.updateDisplay();
|
|
|
|
} else {
|
|
|
|
Components.utils.reportError("Cannot initialize search service, bailing out: " + aStatus);
|
|
|
|
}
|
|
|
|
}).bind(this));
|
|
|
|
]]></constructor>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
<destructor><![CDATA[
|
2007-09-17 14:24:19 -07:00
|
|
|
if (this._addedObserver) {
|
|
|
|
var os = Components.classes["@mozilla.org/observer-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIObserverService);
|
|
|
|
os.removeObserver(this, "browser-search-engine-modified");
|
2012-05-31 05:45:28 -07:00
|
|
|
this._addedObserver = false;
|
2007-09-17 14:24:19 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-30 17:32:17 -07:00
|
|
|
// Make sure to break the cycle from _textbox to us. Otherwise we leak
|
2008-04-05 20:51:57 -07:00
|
|
|
// the world. But make sure it's actually pointing to us.
|
|
|
|
if (this._textbox.mController.input == this)
|
|
|
|
this._textbox.mController.input = null;
|
2007-03-22 10:30:00 -07:00
|
|
|
]]></destructor>
|
|
|
|
|
|
|
|
<field name="_stringBundle">document.getAnonymousElementByAttribute(this,
|
|
|
|
"anonid", "searchbar-stringbundle");</field>
|
|
|
|
<field name="_textbox">document.getAnonymousElementByAttribute(this,
|
|
|
|
"anonid", "searchbar-textbox");</field>
|
|
|
|
<field name="_popup">document.getAnonymousElementByAttribute(this,
|
|
|
|
"anonid", "searchbar-popup");</field>
|
|
|
|
<field name="_ss">null</field>
|
|
|
|
<field name="_engines">null</field>
|
2013-04-19 15:21:30 -07:00
|
|
|
<field name="FormHistory" readonly="true">
|
|
|
|
(Components.utils.import("resource://gre/modules/FormHistory.jsm", {})).FormHistory;
|
|
|
|
</field>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-10-13 18:26:26 -07:00
|
|
|
<property name="engines" readonly="true">
|
|
|
|
<getter><![CDATA[
|
|
|
|
if (!this._engines)
|
2009-11-06 13:56:26 -08:00
|
|
|
this._engines = this.searchService.getVisibleEngines();
|
2007-10-13 18:26:26 -07:00
|
|
|
return this._engines;
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
2007-11-28 00:46:26 -08:00
|
|
|
<field name="searchButton">document.getAnonymousElementByAttribute(this,
|
|
|
|
"anonid", "searchbar-engine-button");</field>
|
2007-10-08 13:17:14 -07:00
|
|
|
|
2013-04-09 17:12:27 -07:00
|
|
|
<property name="currentEngine">
|
|
|
|
<setter><![CDATA[
|
|
|
|
let ss = this.searchService;
|
|
|
|
ss.defaultEngine = ss.currentEngine = val;
|
|
|
|
return val;
|
|
|
|
]]></setter>
|
2007-03-22 10:30:00 -07:00
|
|
|
<getter><![CDATA[
|
|
|
|
var currentEngine = this.searchService.currentEngine;
|
|
|
|
// Return a dummy engine if there is no currentEngine
|
2012-02-23 04:55:04 -08:00
|
|
|
return currentEngine || {name: "", uri: null};
|
2007-03-22 10:30:00 -07:00
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
|
|
|
<!-- textbox is used by sanitize.js to clear the undo history when
|
|
|
|
clearing form information. -->
|
|
|
|
<property name="textbox" readonly="true"
|
|
|
|
onget="return this._textbox;"/>
|
|
|
|
|
|
|
|
<property name="searchService" readonly="true">
|
|
|
|
<getter><![CDATA[
|
|
|
|
if (!this._ss) {
|
|
|
|
const nsIBSS = Components.interfaces.nsIBrowserSearchService;
|
|
|
|
this._ss =
|
|
|
|
Components.classes["@mozilla.org/browser/search-service;1"]
|
|
|
|
.getService(nsIBSS);
|
|
|
|
}
|
|
|
|
return this._ss;
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
2008-02-06 11:00:09 -08:00
|
|
|
<property name="value" onget="return this._textbox.value;"
|
|
|
|
onset="return this._textbox.value = val;"/>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
<method name="focus">
|
|
|
|
<body><![CDATA[
|
|
|
|
this._textbox.focus();
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="select">
|
|
|
|
<body><![CDATA[
|
|
|
|
this._textbox.select();
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="observe">
|
|
|
|
<parameter name="aEngine"/>
|
|
|
|
<parameter name="aTopic"/>
|
|
|
|
<parameter name="aVerb"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
if (aTopic == "browser-search-engine-modified") {
|
|
|
|
switch (aVerb) {
|
|
|
|
case "engine-removed":
|
|
|
|
this.offerNewEngine(aEngine);
|
|
|
|
break;
|
|
|
|
case "engine-added":
|
|
|
|
this.hideNewEngine(aEngine);
|
|
|
|
break;
|
|
|
|
case "engine-current":
|
|
|
|
// The current engine was changed. Rebuilding the menu appears to
|
|
|
|
// confuse its idea of whether it should be open when it's just
|
|
|
|
// been clicked, so we force it to close now.
|
|
|
|
this._popup.hidePopup();
|
|
|
|
break;
|
|
|
|
case "engine-changed":
|
|
|
|
// An engine was removed (or hidden) or added, or an icon was
|
|
|
|
// changed. Do nothing special.
|
|
|
|
}
|
|
|
|
|
2007-10-13 18:26:26 -07:00
|
|
|
// Make sure the engine list is refetched next time it's needed
|
|
|
|
this._engines = null;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Rebuild the popup and update the display after any modification.
|
|
|
|
this.rebuildPopup();
|
|
|
|
this.updateDisplay();
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!-- There are two seaprate lists of search engines, whose uses intersect
|
|
|
|
in this file. The search service (nsIBrowserSearchService and
|
|
|
|
nsSearchService.js) maintains a list of Engine objects which is used to
|
|
|
|
populate the searchbox list of available engines and to perform queries.
|
|
|
|
That list is accessed here via this.SearchService, and it's that sort of
|
|
|
|
Engine that is passed to this binding's observer as aEngine.
|
|
|
|
|
|
|
|
In addition, browser.js fills two lists of autodetected search engines
|
|
|
|
(browser.engines and browser.hiddenEngines) as properties of
|
|
|
|
mCurrentBrowser. Those lists contain unnamed JS objects of the form
|
|
|
|
{ uri:, title:, icon: }, and that's what the searchbar uses to determine
|
|
|
|
whether to show any "Add <EngineName>" menu items in the drop-down.
|
|
|
|
|
|
|
|
The two types of engines are currently related by their identifying
|
|
|
|
titles (the Engine object's 'name'), although that may change; see bug
|
|
|
|
335102. -->
|
|
|
|
|
|
|
|
<!-- If the engine that was just removed from the searchbox list was
|
|
|
|
autodetected on this page, move it to each browser's active list so it
|
|
|
|
will be offered to be added again. -->
|
|
|
|
<method name="offerNewEngine">
|
|
|
|
<parameter name="aEngine"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
var allbrowsers = getBrowser().mPanelContainer.childNodes;
|
|
|
|
for (var tab = 0; tab < allbrowsers.length; tab++) {
|
|
|
|
var browser = getBrowser().getBrowserAtIndex(tab);
|
|
|
|
if (browser.hiddenEngines) {
|
|
|
|
// XXX This will need to be changed when engines are identified by
|
|
|
|
// URL rather than title; see bug 335102.
|
|
|
|
var removeTitle = aEngine.wrappedJSObject.name;
|
|
|
|
for (var i = 0; i < browser.hiddenEngines.length; i++) {
|
|
|
|
if (browser.hiddenEngines[i].title == removeTitle) {
|
|
|
|
if (!browser.engines)
|
|
|
|
browser.engines = [];
|
|
|
|
browser.engines.push(browser.hiddenEngines[i]);
|
|
|
|
browser.hiddenEngines.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!-- If the engine that was just added to the searchbox list was
|
|
|
|
autodetected on this page, move it to each browser's hidden list so it is
|
|
|
|
no longer offered to be added. -->
|
|
|
|
<method name="hideNewEngine">
|
|
|
|
<parameter name="aEngine"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
var allbrowsers = getBrowser().mPanelContainer.childNodes;
|
|
|
|
for (var tab = 0; tab < allbrowsers.length; tab++) {
|
|
|
|
var browser = getBrowser().getBrowserAtIndex(tab);
|
|
|
|
if (browser.engines) {
|
|
|
|
// XXX This will need to be changed when engines are identified by
|
|
|
|
// URL rather than title; see bug 335102.
|
|
|
|
var removeTitle = aEngine.wrappedJSObject.name;
|
|
|
|
for (var i = 0; i < browser.engines.length; i++) {
|
|
|
|
if (browser.engines[i].title == removeTitle) {
|
|
|
|
if (!browser.hiddenEngines)
|
|
|
|
browser.hiddenEngines = [];
|
|
|
|
browser.hiddenEngines.push(browser.engines[i]);
|
|
|
|
browser.engines.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2013-04-07 19:02:43 -07:00
|
|
|
<method name="setIcon">
|
|
|
|
<parameter name="element"/>
|
|
|
|
<parameter name="uri"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
if (uri) {
|
|
|
|
let size = Math.round(16 * window.devicePixelRatio);
|
|
|
|
if (!uri.contains("#"))
|
|
|
|
uri += "#-moz-resolution=" + size + "," + size;
|
|
|
|
}
|
|
|
|
element.setAttribute("src", uri);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
<method name="updateDisplay">
|
|
|
|
<body><![CDATA[
|
|
|
|
var uri = this.currentEngine.iconURI;
|
2013-04-07 19:02:43 -07:00
|
|
|
this.setIcon(this, uri ? uri.spec : "");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
var name = this.currentEngine.name;
|
|
|
|
var text = this._stringBundle.getFormattedString("searchtip", [name]);
|
2010-03-03 23:13:27 -08:00
|
|
|
this._textbox.placeholder = name;
|
2008-02-06 11:00:09 -08:00
|
|
|
this._textbox.label = text;
|
|
|
|
this._textbox.tooltipText = text;
|
2007-03-22 10:30:00 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!-- Rebuilds the dynamic portion of the popup menu (i.e., the menu items
|
|
|
|
for new search engines that can be added to the available list). This
|
|
|
|
is called each time the popup is shown.
|
|
|
|
-->
|
|
|
|
<method name="rebuildPopupDynamic">
|
|
|
|
<body><![CDATA[
|
2007-10-01 15:53:32 -07:00
|
|
|
// We might not have added the main popup items yet, do that first
|
|
|
|
// if needed.
|
|
|
|
if (this._needToBuildPopup)
|
|
|
|
this.rebuildPopup();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var popup = this._popup;
|
|
|
|
// Clear any addengine menuitems, including addengine-item entries and
|
|
|
|
// the addengine-separator. Work backward to avoid invalidating the
|
|
|
|
// indexes as items are removed.
|
|
|
|
var items = popup.childNodes;
|
|
|
|
for (var i = items.length - 1; i >= 0; i--) {
|
2012-02-23 09:56:48 -08:00
|
|
|
if (items[i].classList.contains("addengine-item") ||
|
|
|
|
items[i].classList.contains("addengine-separator"))
|
2007-03-22 10:30:00 -07:00
|
|
|
popup.removeChild(items[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
var addengines = getBrowser().mCurrentBrowser.engines;
|
|
|
|
if (addengines && addengines.length > 0) {
|
|
|
|
const kXULNS =
|
|
|
|
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
|
|
|
|
|
|
// Find the (first) separator in the remaining menu, or the first item
|
|
|
|
// if no separators are present.
|
|
|
|
var insertLocation = popup.firstChild;
|
|
|
|
while (insertLocation.nextSibling &&
|
|
|
|
insertLocation.localName != "menuseparator") {
|
|
|
|
insertLocation = insertLocation.nextSibling;
|
|
|
|
}
|
|
|
|
if (insertLocation.localName != "menuseparator")
|
|
|
|
insertLocation = popup.firstChild;
|
|
|
|
|
|
|
|
var separator = document.createElementNS(kXULNS, "menuseparator");
|
|
|
|
separator.setAttribute("class", "addengine-separator");
|
|
|
|
popup.insertBefore(separator, insertLocation);
|
|
|
|
|
|
|
|
// Insert the "add this engine" items.
|
|
|
|
for (var i = 0; i < addengines.length; i++) {
|
|
|
|
var menuitem = document.createElement("menuitem");
|
|
|
|
var engineInfo = addengines[i];
|
|
|
|
var labelStr =
|
|
|
|
this._stringBundle.getFormattedString("cmd_addFoundEngine",
|
|
|
|
[engineInfo.title]);
|
|
|
|
menuitem = document.createElementNS(kXULNS, "menuitem");
|
|
|
|
menuitem.setAttribute("class", "menuitem-iconic addengine-item");
|
|
|
|
menuitem.setAttribute("label", labelStr);
|
|
|
|
menuitem.setAttribute("tooltiptext", engineInfo.uri);
|
|
|
|
menuitem.setAttribute("uri", engineInfo.uri);
|
|
|
|
if (engineInfo.icon)
|
2013-04-07 19:02:43 -07:00
|
|
|
this.setIcon(menuitem, engineInfo.icon);
|
2007-03-22 10:30:00 -07:00
|
|
|
menuitem.setAttribute("title", engineInfo.title);
|
|
|
|
popup.insertBefore(menuitem, insertLocation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!-- Rebuilds the list of visible search engines in the menu. Does not remove
|
|
|
|
or update any dynamic entries (i.e., "Add this engine" items) nor the
|
|
|
|
Manage Engines item. This is called by the observer when the list of
|
|
|
|
visible engines, or the currently selected engine, has changed.
|
|
|
|
-->
|
|
|
|
<method name="rebuildPopup">
|
|
|
|
<body><![CDATA[
|
|
|
|
var popup = this._popup;
|
|
|
|
|
|
|
|
// Clear the popup, down to the first separator
|
|
|
|
while (popup.firstChild && popup.firstChild.localName != "menuseparator")
|
|
|
|
popup.removeChild(popup.firstChild);
|
|
|
|
|
|
|
|
const kXULNS =
|
|
|
|
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
|
|
|
2007-10-13 18:26:26 -07:00
|
|
|
var engines = this.engines;
|
|
|
|
for (var i = engines.length - 1; i >= 0; --i) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var menuitem = document.createElementNS(kXULNS, "menuitem");
|
2007-10-13 18:26:26 -07:00
|
|
|
var name = engines[i].name;
|
2007-03-22 10:30:00 -07:00
|
|
|
menuitem.setAttribute("label", name);
|
|
|
|
menuitem.setAttribute("id", name);
|
2010-03-24 02:17:40 -07:00
|
|
|
menuitem.setAttribute("class", "menuitem-iconic searchbar-engine-menuitem menuitem-with-favicon");
|
2007-03-22 10:30:00 -07:00
|
|
|
// Since this menu is rebuilt by the observer method whenever a new
|
|
|
|
// engine is selected, the "selected" attribute does not need to be
|
|
|
|
// explicitly cleared anywhere.
|
2007-10-13 18:26:26 -07:00
|
|
|
if (engines[i] == this.currentEngine)
|
2007-03-22 10:30:00 -07:00
|
|
|
menuitem.setAttribute("selected", "true");
|
|
|
|
var tooltip = this._stringBundle.getFormattedString("searchtip", [name]);
|
|
|
|
menuitem.setAttribute("tooltiptext", tooltip);
|
2007-10-13 18:26:26 -07:00
|
|
|
if (engines[i].iconURI)
|
2013-04-07 19:02:43 -07:00
|
|
|
this.setIcon(menuitem, engines[i].iconURI.spec);
|
2007-03-22 10:30:00 -07:00
|
|
|
popup.insertBefore(menuitem, popup.firstChild);
|
2007-10-13 18:26:26 -07:00
|
|
|
menuitem.engine = engines[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-10-01 15:53:32 -07:00
|
|
|
|
|
|
|
this._needToBuildPopup = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="openManager">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
var wm =
|
|
|
|
Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
|
|
|
.getService(Components.interfaces.nsIWindowMediator);
|
|
|
|
|
|
|
|
var window = wm.getMostRecentWindow("Browser:SearchManager");
|
|
|
|
if (window)
|
|
|
|
window.focus()
|
|
|
|
else {
|
|
|
|
setTimeout(function () {
|
|
|
|
openDialog("chrome://browser/content/search/engineManager.xul",
|
2010-02-12 02:43:18 -08:00
|
|
|
"_blank", "chrome,dialog,modal,centerscreen,resizable");
|
2007-03-22 10:30:00 -07:00
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="selectEngine">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<parameter name="isNextEngine"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
// Find the new index
|
2007-10-13 18:26:26 -07:00
|
|
|
var newIndex = this.engines.indexOf(this.currentEngine);
|
2012-02-23 04:55:04 -08:00
|
|
|
newIndex += isNextEngine ? 1 : -1;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-04-09 17:12:27 -07:00
|
|
|
if (newIndex >= 0 && newIndex < this.engines.length) {
|
2007-10-13 18:26:26 -07:00
|
|
|
this.currentEngine = this.engines[newIndex];
|
2013-04-09 17:12:27 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
aEvent.preventDefault();
|
|
|
|
aEvent.stopPropagation();
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="handleSearchCommand">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body><![CDATA[
|
2008-04-01 10:22:43 -07:00
|
|
|
var textBox = this._textbox;
|
|
|
|
var textValue = textBox.value;
|
|
|
|
|
2008-04-01 01:31:42 -07:00
|
|
|
var where = "current";
|
|
|
|
if (aEvent && aEvent.originalTarget.getAttribute("anonid") == "search-go-button") {
|
|
|
|
if (aEvent.button == 2)
|
|
|
|
return;
|
|
|
|
where = whereToOpenLink(aEvent, false, true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var newTabPref = textBox._prefBranch.getBoolPref("browser.search.openintab");
|
|
|
|
if ((aEvent && aEvent.altKey) ^ newTabPref)
|
|
|
|
where = "tab";
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
this.doSearch(textValue, where);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="doSearch">
|
|
|
|
<parameter name="aData"/>
|
|
|
|
<parameter name="aWhere"/>
|
|
|
|
<body><![CDATA[
|
2013-06-04 23:20:35 -07:00
|
|
|
var textBox = this._textbox;
|
|
|
|
|
|
|
|
// Save the current value in the form history
|
|
|
|
if (aData && !PrivateBrowsingUtils.isWindowPrivate(window)) {
|
|
|
|
this.FormHistory.update(
|
|
|
|
{ op : "bump",
|
|
|
|
fieldname : textBox.getAttribute("autocompletesearchparam"),
|
|
|
|
value : aData },
|
|
|
|
{ handleError : function(aError) {
|
|
|
|
Components.utils.reportError("Saving search to form history failed: " + aError.message);
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// null parameter below specifies HTML response for search
|
2010-06-16 09:54:29 -07:00
|
|
|
var submission = this.currentEngine.getSubmission(aData);
|
2013-02-13 14:33:24 -08:00
|
|
|
BrowserSearch.recordSearchInHealthReport(this.currentEngine.name, "searchbar");
|
2007-03-22 10:30:00 -07:00
|
|
|
openUILinkIn(submission.uri.spec, aWhere, null, submission.postData);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
</implementation>
|
|
|
|
|
|
|
|
<handlers>
|
|
|
|
<handler event="command"><![CDATA[
|
|
|
|
const target = event.originalTarget;
|
2013-06-18 06:39:02 -07:00
|
|
|
if (target.engine) {
|
|
|
|
this.currentEngine = target.engine;
|
|
|
|
} else if (target.classList.contains("addengine-item")) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var searchService =
|
|
|
|
Components.classes["@mozilla.org/browser/search-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIBrowserSearchService);
|
|
|
|
// We only detect OpenSearch files
|
|
|
|
var type = Components.interfaces.nsISearchEngine.DATA_XML;
|
2013-06-18 06:39:02 -07:00
|
|
|
// Select the installed engine if the installation succeeds
|
|
|
|
var installCallback = {
|
|
|
|
onSuccess: engine => this.currentEngine = engine
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
searchService.addEngine(target.getAttribute("uri"), type,
|
2013-06-18 06:39:02 -07:00
|
|
|
target.getAttribute("src"), false,
|
|
|
|
installCallback);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.focus();
|
|
|
|
this.select();
|
|
|
|
]]></handler>
|
|
|
|
|
|
|
|
<handler event="popupshowing" action="this.rebuildPopupDynamic();"/>
|
2007-11-30 22:46:40 -08:00
|
|
|
|
|
|
|
<handler event="DOMMouseScroll"
|
|
|
|
phase="capturing"
|
2011-04-19 15:12:50 -07:00
|
|
|
modifiers="accel"
|
|
|
|
action="this.selectEngine(event, (event.detail > 0));"/>
|
2012-04-25 05:54:42 -07:00
|
|
|
|
|
|
|
<handler event="focus">
|
|
|
|
<![CDATA[
|
|
|
|
// Speculatively connect to the current engine's search URI (and
|
|
|
|
// suggest URI, if different) to reduce request latency
|
|
|
|
|
|
|
|
const SUGGEST_TYPE = "application/x-suggestions+json";
|
|
|
|
var engine = this.currentEngine;
|
2013-03-21 07:11:40 -07:00
|
|
|
var connector =
|
2012-04-25 05:54:42 -07:00
|
|
|
Services.io.QueryInterface(Components.interfaces.nsISpeculativeConnect);
|
|
|
|
var searchURI = engine.getSubmission("dummy").uri;
|
2012-06-30 07:34:17 -07:00
|
|
|
let callbacks = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Components.interfaces.nsIWebNavigation)
|
|
|
|
.QueryInterface(Components.interfaces.nsILoadContext);
|
|
|
|
connector.speculativeConnect(searchURI, callbacks);
|
2012-04-25 05:54:42 -07:00
|
|
|
|
|
|
|
if (engine.supportsResponseType(SUGGEST_TYPE)) {
|
2013-03-21 07:11:40 -07:00
|
|
|
var suggestURI = engine.getSubmission("dummy", SUGGEST_TYPE).uri;
|
2012-04-25 05:54:42 -07:00
|
|
|
if (suggestURI.prePath != searchURI.prePath)
|
2012-06-30 07:34:17 -07:00
|
|
|
connector.speculativeConnect(suggestURI, callbacks);
|
2012-04-25 05:54:42 -07:00
|
|
|
}
|
|
|
|
]]></handler>
|
2007-03-22 10:30:00 -07:00
|
|
|
</handlers>
|
|
|
|
</binding>
|
|
|
|
|
|
|
|
<binding id="searchbar-textbox"
|
|
|
|
extends="chrome://global/content/bindings/autocomplete.xml#autocomplete">
|
2008-02-06 11:00:09 -08:00
|
|
|
<implementation implements="nsIObserver">
|
2007-03-22 10:30:00 -07:00
|
|
|
<constructor><![CDATA[
|
2013-06-04 12:43:27 -07:00
|
|
|
const kXULNS =
|
|
|
|
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
|
|
|
2007-11-23 22:00:27 -08:00
|
|
|
if (document.getBindingParent(this).parentNode.parentNode.localName ==
|
2007-03-22 10:30:00 -07:00
|
|
|
"toolbarpaletteitem")
|
|
|
|
return;
|
2013-05-22 12:37:37 -07:00
|
|
|
|
2013-06-04 12:43:27 -07:00
|
|
|
// Initialize fields
|
|
|
|
this._stringBundle = document.getBindingParent(this)._stringBundle;
|
|
|
|
this._prefBranch =
|
|
|
|
Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
this._suggestEnabled =
|
|
|
|
this._prefBranch.getBoolPref("browser.search.suggest.enabled");
|
|
|
|
|
|
|
|
if (this._prefBranch.getBoolPref("browser.urlbar.clickSelectsAll"))
|
|
|
|
this.setAttribute("clickSelectsAll", true);
|
|
|
|
|
|
|
|
// Add items to context menu and attach controller to handle them
|
|
|
|
var textBox = document.getAnonymousElementByAttribute(this,
|
|
|
|
"anonid", "textbox-input-box");
|
|
|
|
var cxmenu = document.getAnonymousElementByAttribute(textBox,
|
|
|
|
"anonid", "input-box-contextmenu");
|
|
|
|
var pasteAndSearch;
|
|
|
|
cxmenu.addEventListener("popupshowing", function() {
|
|
|
|
if (!pasteAndSearch)
|
|
|
|
return;
|
|
|
|
var controller = document.commandDispatcher.getControllerForCommand("cmd_paste");
|
|
|
|
var enabled = controller.isCommandEnabled("cmd_paste");
|
|
|
|
if (enabled)
|
|
|
|
pasteAndSearch.removeAttribute("disabled");
|
|
|
|
else
|
|
|
|
pasteAndSearch.setAttribute("disabled", "true");
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
var element, label, akey;
|
|
|
|
|
|
|
|
element = document.createElementNS(kXULNS, "menuseparator");
|
|
|
|
cxmenu.appendChild(element);
|
|
|
|
|
|
|
|
var insertLocation = cxmenu.firstChild;
|
|
|
|
while (insertLocation.nextSibling &&
|
|
|
|
insertLocation.getAttribute("cmd") != "cmd_paste")
|
|
|
|
insertLocation = insertLocation.nextSibling;
|
|
|
|
if (insertLocation) {
|
|
|
|
element = document.createElementNS(kXULNS, "menuitem");
|
|
|
|
label = this._stringBundle.getString("cmd_pasteAndSearch");
|
|
|
|
element.setAttribute("label", label);
|
|
|
|
element.setAttribute("anonid", "paste-and-search");
|
|
|
|
element.setAttribute("oncommand",
|
|
|
|
"BrowserSearch.searchBar.select(); goDoCommand('cmd_paste'); BrowserSearch.searchBar.handleSearchCommand();");
|
|
|
|
cxmenu.insertBefore(element, insertLocation.nextSibling);
|
|
|
|
pasteAndSearch = element;
|
|
|
|
}
|
|
|
|
|
|
|
|
element = document.createElementNS(kXULNS, "menuitem");
|
|
|
|
label = this._stringBundle.getString("cmd_clearHistory");
|
|
|
|
akey = this._stringBundle.getString("cmd_clearHistory_accesskey");
|
|
|
|
element.setAttribute("label", label);
|
|
|
|
element.setAttribute("accesskey", akey);
|
|
|
|
element.setAttribute("cmd", "cmd_clearhistory");
|
|
|
|
cxmenu.appendChild(element);
|
|
|
|
|
|
|
|
element = document.createElementNS(kXULNS, "menuitem");
|
|
|
|
label = this._stringBundle.getString("cmd_showSuggestions");
|
|
|
|
akey = this._stringBundle.getString("cmd_showSuggestions_accesskey");
|
|
|
|
element.setAttribute("anonid", "toggle-suggest-item");
|
|
|
|
element.setAttribute("label", label);
|
|
|
|
element.setAttribute("accesskey", akey);
|
|
|
|
element.setAttribute("cmd", "cmd_togglesuggest");
|
|
|
|
element.setAttribute("type", "checkbox");
|
|
|
|
element.setAttribute("checked", this._suggestEnabled);
|
|
|
|
element.setAttribute("autocheck", "false");
|
|
|
|
this._suggestMenuItem = element;
|
|
|
|
cxmenu.appendChild(element);
|
|
|
|
|
|
|
|
this.controllers.appendController(this.searchbarController);
|
|
|
|
|
|
|
|
// Add observer for suggest preference
|
|
|
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
prefs.addObserver("browser.search.suggest.enabled", this, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
]]></constructor>
|
|
|
|
|
|
|
|
<destructor><![CDATA[
|
2012-01-16 17:34:51 -08:00
|
|
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
prefs.removeObserver("browser.search.suggest.enabled", this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Because XBL and the customize toolbar code interacts poorly,
|
|
|
|
// there may not be anything to remove here
|
|
|
|
try {
|
|
|
|
this.controllers.removeController(this.searchbarController);
|
|
|
|
} catch (ex) { }
|
|
|
|
]]></destructor>
|
|
|
|
|
|
|
|
<field name="_stringBundle"/>
|
|
|
|
<field name="_prefBranch"/>
|
|
|
|
<field name="_suggestMenuItem"/>
|
|
|
|
<field name="_suggestEnabled"/>
|
|
|
|
|
2012-10-15 15:59:33 -07:00
|
|
|
<!--
|
|
|
|
This overrides the searchParam property in autocomplete.xml. We're
|
|
|
|
hijacking this property as a vehicle for delivering the privacy
|
2012-11-29 22:59:59 -08:00
|
|
|
information about the window into the guts of nsSearchSuggestions.
|
2012-10-15 15:59:33 -07:00
|
|
|
|
|
|
|
Note that the setter is the same as the parent. We were not sure whether
|
|
|
|
we can override just the getter. If that proves to be the case, the setter
|
|
|
|
can be removed.
|
|
|
|
-->
|
|
|
|
<property name="searchParam"
|
|
|
|
onget="return this.getAttribute('autocompletesearchparam') +
|
|
|
|
(PrivateBrowsingUtils.isWindowPrivate(window) ? '|private' : '');"
|
|
|
|
onset="this.setAttribute('autocompletesearchparam', val); return val;"/>
|
|
|
|
|
2011-02-03 16:52:46 -08:00
|
|
|
<!--
|
|
|
|
This method overrides the autocomplete binding's openPopup (essentially
|
|
|
|
duplicating the logic from the autocomplete popup binding's
|
|
|
|
openAutocompletePopup method), modifying it so that the popup is aligned with
|
|
|
|
the inner textbox, but sized to not extend beyond the search bar border.
|
|
|
|
-->
|
2007-11-23 22:00:27 -08:00
|
|
|
<method name="openPopup">
|
|
|
|
<body><![CDATA[
|
|
|
|
var popup = this.popup;
|
|
|
|
if (!popup.mPopupOpen) {
|
2007-12-04 14:54:34 -08:00
|
|
|
// Initially the panel used for the searchbar (PopupAutoComplete
|
|
|
|
// in browser.xul) is hidden to avoid impacting startup / new
|
|
|
|
// window performance. The base binding's openPopup would normally
|
|
|
|
// call the overriden openAutocompletePopup in urlbarBindings.xml's
|
2007-12-13 13:21:16 -08:00
|
|
|
// browser-autocomplete-result-popup binding to unhide the popup,
|
|
|
|
// but since we're overriding openPopup we need to unhide the panel
|
|
|
|
// ourselves.
|
2007-12-04 14:54:34 -08:00
|
|
|
popup.hidden = false;
|
|
|
|
|
2007-11-23 22:00:27 -08:00
|
|
|
popup.mInput = this;
|
|
|
|
popup.view = this.controller.QueryInterface(Components.interfaces.nsITreeView);
|
|
|
|
popup.invalidate();
|
2010-09-16 00:51:24 -07:00
|
|
|
|
2007-11-23 22:00:27 -08:00
|
|
|
popup.showCommentColumn = this.showCommentColumn;
|
|
|
|
popup.showImageColumn = this.showImageColumn;
|
|
|
|
|
|
|
|
document.popupNode = null;
|
|
|
|
|
2011-02-03 16:52:46 -08:00
|
|
|
const isRTL = getComputedStyle(this, "").direction == "rtl";
|
|
|
|
|
2007-11-23 22:00:27 -08:00
|
|
|
var outerRect = this.getBoundingClientRect();
|
|
|
|
var innerRect = this.inputField.getBoundingClientRect();
|
2011-02-03 16:52:46 -08:00
|
|
|
if (isRTL) {
|
|
|
|
var width = innerRect.right - outerRect.left;
|
|
|
|
} else {
|
|
|
|
var width = outerRect.right - innerRect.left;
|
|
|
|
}
|
2007-11-23 22:00:27 -08:00
|
|
|
popup.setAttribute("width", width > 100 ? width : 100);
|
|
|
|
|
2011-02-03 16:52:46 -08:00
|
|
|
var yOffset = outerRect.bottom - innerRect.bottom;
|
|
|
|
popup.openPopup(this.inputField, "after_start", 0, yOffset, false, false);
|
2007-11-23 22:00:27 -08:00
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
<method name="observe">
|
|
|
|
<parameter name="aSubject"/>
|
|
|
|
<parameter name="aTopic"/>
|
|
|
|
<parameter name="aData"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
if (aTopic == "nsPref:changed") {
|
|
|
|
this._suggestEnabled =
|
|
|
|
this._prefBranch.getBoolPref("browser.search.suggest.enabled");
|
|
|
|
this._suggestMenuItem.setAttribute("checked", this._suggestEnabled);
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="openSearch">
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
|
|
|
// Don't open search popup if history popup is open
|
|
|
|
if (!this.popupOpen) {
|
2007-12-03 14:35:08 -08:00
|
|
|
document.getBindingParent(this).searchButton.open = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
2012-02-23 04:55:04 -08:00
|
|
|
<!-- override |onTextEntered| in autocomplete.xml -->
|
2007-03-22 10:30:00 -07:00
|
|
|
<method name="onTextEntered">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
var evt = aEvent || this.mEnterEvent;
|
2007-11-23 22:00:27 -08:00
|
|
|
document.getBindingParent(this).handleSearchCommand(evt);
|
2007-03-22 10:30:00 -07:00
|
|
|
this.mEnterEvent = null;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!-- nsIController -->
|
|
|
|
<field name="searchbarController" readonly="true"><![CDATA[({
|
|
|
|
_self: this,
|
|
|
|
supportsCommand: function(aCommand) {
|
|
|
|
return aCommand == "cmd_clearhistory" ||
|
|
|
|
aCommand == "cmd_togglesuggest";
|
|
|
|
},
|
|
|
|
|
|
|
|
isCommandEnabled: function(aCommand) {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
doCommand: function (aCommand) {
|
|
|
|
switch (aCommand) {
|
|
|
|
case "cmd_clearhistory":
|
|
|
|
var param = this._self.getAttribute("autocompletesearchparam");
|
2013-04-19 15:21:30 -07:00
|
|
|
|
|
|
|
let searchBar = this._self.parentNode;
|
|
|
|
|
|
|
|
BrowserSearch.searchBar.FormHistory.update({ op : "remove", fieldname : param }, null);
|
2007-03-22 10:30:00 -07:00
|
|
|
this._self.value = "";
|
|
|
|
break;
|
|
|
|
case "cmd_togglesuggest":
|
|
|
|
// The pref observer will update _suggestEnabled and the menu
|
|
|
|
// checkmark.
|
|
|
|
this._self._prefBranch.setBoolPref("browser.search.suggest.enabled",
|
|
|
|
!this._self._suggestEnabled);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// do nothing with unrecognized command
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})]]></field>
|
|
|
|
</implementation>
|
|
|
|
|
|
|
|
<handlers>
|
|
|
|
<handler event="keypress" keycode="VK_UP" modifiers="accel"
|
|
|
|
phase="capturing"
|
2007-11-23 22:00:27 -08:00
|
|
|
action="document.getBindingParent(this).selectEngine(event, false);"/>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
<handler event="keypress" keycode="VK_DOWN" modifiers="accel"
|
|
|
|
phase="capturing"
|
2007-11-23 22:00:27 -08:00
|
|
|
action="document.getBindingParent(this).selectEngine(event, true);"/>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
<handler event="keypress" keycode="VK_DOWN" modifiers="alt"
|
|
|
|
phase="capturing"
|
|
|
|
action="return this.openSearch();"/>
|
|
|
|
|
|
|
|
<handler event="keypress" keycode="VK_UP" modifiers="alt"
|
|
|
|
phase="capturing"
|
|
|
|
action="return this.openSearch();"/>
|
|
|
|
|
|
|
|
#ifndef XP_MACOSX
|
|
|
|
<handler event="keypress" keycode="VK_F4"
|
|
|
|
phase="capturing"
|
|
|
|
action="return this.openSearch();"/>
|
|
|
|
#endif
|
|
|
|
|
2010-04-18 11:27:23 -07:00
|
|
|
<handler event="dragover">
|
|
|
|
<![CDATA[
|
|
|
|
var types = event.dataTransfer.types;
|
|
|
|
if (types.contains("text/plain") || types.contains("text/x-moz-text-internal"))
|
|
|
|
event.preventDefault();
|
|
|
|
]]>
|
|
|
|
</handler>
|
|
|
|
|
|
|
|
<handler event="drop">
|
|
|
|
<![CDATA[
|
|
|
|
var dataTransfer = event.dataTransfer;
|
|
|
|
var data = dataTransfer.getData("text/plain");
|
|
|
|
if (!data)
|
|
|
|
data = dataTransfer.getData("text/x-moz-text-internal");
|
|
|
|
if (data) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.value = data;
|
|
|
|
this.onTextEntered(event);
|
|
|
|
}
|
|
|
|
]]>
|
2007-03-22 10:30:00 -07:00
|
|
|
</handler>
|
|
|
|
|
|
|
|
</handlers>
|
|
|
|
</binding>
|
|
|
|
</bindings>
|