gecko-dev/browser/base/content/search.xml

496 lines
19 KiB
XML

<?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
# Joe Hewitt.
# Portions created by the Initial Developer are Copyright (C) 2003
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Pierre Chanial V 2.0 (p_ch@verizon.net)
# Gavin Sharp (gavin@gavinsharp.com)
#
# 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="SearchBindings"
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">
<binding id="searchbar-base">
<resources>
<stylesheet src="chrome://browser/content/searchbarBindings.css"/>
<stylesheet src="chrome://browser/skin/searchbar.css"/>
</resources>
</binding>
<binding id="searchbar" extends="chrome://browser/content/search.xml#searchbar-base">
<content>
<xul:stringbundle src="chrome://browser/locale/searchbar.properties"/>
<xul:textbox class="searchbar-textbox" type="autocomplete" flex="1"
autocompletepopup="PopupAutoComplete"
autocompletesearch="form-history"
autocompletesearchparam="searchbar-history"
completeselectedindex="true"
tabscrolling="true"
xbl:inherits="disableautocomplete,searchengine,src">
<xul:button class="searchbar-dropmarker" type="menu"
id="searchbar-dropmarker" popup="_child" xbl:inherits="src">
<xul:menupopup anonid="searchbar-popup" position="after_start"
datasources="rdf:internetsearch"
ref="NC:SearchEngineRoot"
oncommand="this.parentNode.parentNode.onEnginePopupCommand(event);"
onpopupshowing="this.parentNode.parentNode.onEnginePopupShowing(event);"
onpopuphidden="this.parentNode.parentNode.onEnginePopupHidden(event);">
<xul:template>
<xul:menuitem type="checkbox"
uri="rdf:*" value="rdf:*"
src="rdf:http://home.netscape.com/NC-rdf#Icon"
label="rdf:http://home.netscape.com/NC-rdf#Name"/>
</xul:template>
</xul:menupopup>
</xul:button>
</xul:textbox>
</content>
<implementation>
<field name="mStringBundle"> document.getAnonymousNodes(this)[0] </field>
<field name="mTextbox"> document.getAnonymousNodes(this)[1] </field>
<method name="focus">
<body><![CDATA[
this.mTextbox.focus();
]]></body>
</method>
<method name="select">
<body><![CDATA[
this.mTextbox.select();
]]></body>
</method>
</implementation>
</binding>
<binding id="searchbar-textbox" extends="chrome://global/content/bindings/autocomplete.xml#autocomplete">
<implementation>
<constructor><![CDATA[
if (this.parentNode.parentNode.parentNode.localName ==
"toolbarpaletteitem")
return;
setTimeout(function(a) { a.initialize(); }, 0, this);
]]></constructor>
<destructor><![CDATA[
// 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>
<property name="mContextMenu" readonly="true">
<getter>
var textBox = document.getAnonymousElementByAttribute(this,
"anonid", "textbox-input-box");
return document.getAnonymousElementByAttribute(textBox,
"anonid", "input-box-contextmenu");
</getter>
</property>
<method name="initialize">
<body><![CDATA[
this.rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"]
.getService(Components.interfaces.nsIRDFService);
this.internetSearchDS = this.rdfService.GetDataSource("rdf:internetsearch");
this.formHistSvc = Components
.classes["@mozilla.org/satchel/form-history;1"]
.getService(Components.interfaces.nsIFormHistory);
this.prefService =
Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch2);
if (this.prefService.getBoolPref("browser.urlbar.clickSelectsAll"))
this.setAttribute("clickSelectsAll", true);
this._initializeEngine();
var element;
element = document.createElementNS(XUL_NS, "menuseparator");
this.mContextMenu.appendChild(element);
element = document.createElementNS(XUL_NS, "menuitem");
element.setAttribute("label", this.mStringBundle
.getString("cmd_clearHistory"));
element.setAttribute("accesskey", this.mStringBundle
.getString("cmd_clearHistory_accesskey"));
element.setAttribute("cmd", "cmd_clearhistory");
this.mContextMenu.appendChild(element);
this.controllers.appendController(this.searchbarController);
]]></body>
</method>
<method name="_initializeEngine">
<body><![CDATA[
var selectedEngineName;
try {
selectedEngineName =
this.prefService
.getComplexValue("browser.search.selectedEngine",
this.nsIPrefLocalizedString).data;
} catch (ex) { }
// try to set the engine by name
this.currentEngineName = selectedEngineName;
// check to see whether it failed
var engine = this.currentEngine;
if (!engine)
this.currentEngine = this.getDefaultEngine();
]]></body>
</method>
<field name="nsIPrefLocalizedString">
Components.interfaces.nsIPrefLocalizedString;
</field>
<field name="mStringBundle"> this.parentNode.mStringBundle </field>
<field name="rdfService"/>
<field name="internetSearchDS"/>
<field name="formHistSvc"/>
<method name="openSearch">
<body>
<![CDATA[
if (!this.popupOpen) { // Don't open search popup if history popup is open
document.getAnonymousElementByAttribute(this.parentNode,
"id", "searchbar-dropmarker").click();
return false;
}
return true;
]]>
</body>
</method>
<property name="currentEngine"
onget="return this.parentNode.getAttribute('searchengine');">
<setter><![CDATA[
if (!val) {
if (this.parentNode)
this.parentNode.removeAttribute("searchengine");
return;
}
this.parentNode.setAttribute("searchengine", val);
const kNC_Icon = this.rdfService.GetResource("http://home.netscape.com/NC-rdf#Icon");
var rEngine = this.rdfService.GetResource(val);
this.parentNode.setAttribute("src", this.readRDFString(rEngine, kNC_Icon));
const kNC_Name = this.rdfService.GetResource("http://home.netscape.com/NC-rdf#Name");
var pls = Components.classes["@mozilla.org/pref-localizedstring;1"]
.createInstance(this.nsIPrefLocalizedString);
pls.data = this.readRDFString(rEngine, kNC_Name);
this.prefService.setComplexValue("browser.search.selectedEngine",
this.nsIPrefLocalizedString, pls);
var toolTipText = this.mStringBundle
.getFormattedString("searchtip", [pls]);
this.parentNode.setAttribute("tooltiptext", toolTipText);
]]></setter>
</property>
<property name="currentEngineName"
onget="return this.parentNode.getAttribute('searchenginename');"
onset="this.setEngineByName(val);"/>
<method name="setEngineByName">
<parameter name="aName"/>
<body><![CDATA[
// XXX this shouldn't be necessary, but it avoids errors
// because the searchbar isn't currently destroyed when
// removed from the toolbar
if (!this.parentNode) {
return false;
}
const kNC_Root = this.rdfService.GetResource("NC:SearchEngineRoot");
const kNC_Child = this.rdfService.GetResource("http://home.netscape.com/NC-rdf#child");
const kNC_Name = this.rdfService.GetResource("http://home.netscape.com/NC-rdf#Name");
var arcs = this.internetSearchDS.GetTargets(kNC_Root, kNC_Child, true);
while (arcs.hasMoreElements()) {
var rEngine = arcs.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
var name = this.readRDFString(rEngine, kNC_Name);
if (name == aName) {
this.currentEngine = rEngine.Value;
this.parentNode.setAttribute('searchenginename', name);
return true;
}
}
this.currentEngine = null;
this.parentNode.removeAttribute('searchenginename')
return false;
]]></body>
</method>
<method name="getDefaultEngine">
<body><![CDATA[
var defaultName = this.prefService
.getComplexValue("browser.search.defaultenginename",
this.nsIPrefLocalizedString).data;
const kNC_Root = this.rdfService.GetResource("NC:SearchEngineRoot");
const kNC_child = this.rdfService.GetResource("http://home.netscape.com/NC-rdf#child");
const kNC_Name = this.rdfService.GetResource("http://home.netscape.com/NC-rdf#Name");
var arcs = this.internetSearchDS.GetTargets(kNC_Root, kNC_child, true);
while (arcs.hasMoreElements()) {
var rEngine = arcs.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
var name = this.readRDFString(rEngine, kNC_Name);
if (name == defaultName)
return rEngine.Value;
}
return null;
]]></body>
</method>
<method name="readRDFString">
<parameter name="aRes"/>
<parameter name="aProp"/>
<body><![CDATA[
var n = this.internetSearchDS.GetTarget(aRes, aProp, true);
return n ? n.QueryInterface(Components.interfaces.nsIRDFLiteral).Value : null;
]]></body>
</method>
// overload |onTextEntered| in autocomplete.xml
<method name="onTextEntered">
<parameter name="aEvent"/>
<body><![CDATA[
// Save the current value in the form history
if (this.value && !this.hasAttribute("disableautocomplete"))
this.formHistSvc.addEntry(this.getAttribute(
"autocompletesearchparam"), this.value);
var ISEARCHSVC = Components.classes["@mozilla.org/rdf/datasource;1?name=internetsearch"]
.getService(Components.interfaces.nsIInternetSearchService);
//XXX Bug 269994: Add in dummy search text "ABC" if the field is empty to ensure a result
var searchURL = ISEARCHSVC.GetInternetSearchURL(this.currentEngine,
this.value? encodeURIComponent(this.value):"ABC",
0, 0, {value:0});
// if the search box is empty, let's load the host
if (!this.value) {
var uri = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService)
.newURI(searchURL, null, null);
try {
searchURL = uri.host;
} catch (ex) {}
}
var evt = aEvent || this.mEnterEvent;
var openInTab = this.prefService.getBoolPref("browser.search.openintab");
SearchLoadURL(searchURL, ((evt && evt.altKey) ^ openInTab));
]]></body>
</method>
<method name="onEnginePopupCommand">
<parameter name="aEvent"/>
<body><![CDATA[
var target = aEvent.target
if (target.getAttribute("anonid") == "addengine-menuitem") {
var regionBundle = document.getElementById("bundle_browser_region");
loadURI(regionBundle.getString("searchEnginesURL"), null, null);
} else {
this.currentEngine = target.id;
this.focus();
this.select();
}
]]></body>
</method>
<method name="onEnginePopupShowing">
<parameter name="aEvent"/>
<body><![CDATA[
var target = aEvent.target;
var element = document.getAnonymousElementByAttribute(this.parentNode,
"anonid", "addengine-menuitem");
if (element)
return;
element = document.createElementNS(XUL_NS, "menuseparator");
target.appendChild(element);
element = document.createElementNS(XUL_NS, "menuitem");
element.setAttribute("label", this.mStringBundle
.getString("cmd_addEngine"));
element.setAttribute("accesskey", this.mStringBundle
.getString("cmd_addEngine_accesskey"));
element.setAttribute("anonid", "addengine-menuitem");
target.appendChild(element);
]]></body>
</method>
<method name="onEnginePopupHidden">
<parameter name="aEvent"/>
<body><![CDATA[
var target = aEvent.target;
var element = document.getAnonymousElementByAttribute(this.parentNode,
"anonid", "addengine-menuitem");
if (element) {
target.removeChild(target.lastChild);
target.removeChild(target.lastChild);
}
]]></body>
</method>
<!-- nsIController -->
<field name="searchbarController" readonly="true"><![CDATA[
({
mOuter: this,
supportsCommand: function (aCommand)
{
return aCommand == "cmd_clearhistory";
},
isCommandEnabled: function (aCommand)
{
return this.mOuter.formHistSvc.nameExists(
this.mOuter.getAttribute("autocompletesearchparam"));
},
doCommand: function (aCommand)
{
// Clear the searchbar and its undo history
this.mOuter.value = "";
this.mOuter.editor.enableUndo(false);
this.mOuter.editor.enableUndo(true);
this.mOuter.formHistSvc.removeEntriesForName(
this.mOuter.getAttribute("autocompletesearchparam"));
}
})
]]></field>
<!-- DND Observer -->
<field name="searchbarDNDObserver" readonly="true"><![CDATA[
({
mOuter: this,
onDrop: function (aEvent, aXferData, aDragSession)
{
var data = transferUtils.retrieveURLFromData(aXferData.data,
aXferData.flavour.contentType);
if (data) {
this.mOuter.value = data;
this.mOuter.onTextEntered(aEvent);
}
},
getSupportedFlavours: function ()
{
var flavourSet = new FlavourSet();
flavourSet.appendFlavour("text/unicode");
flavourSet.appendFlavour("text/x-moz-url");
flavourSet.appendFlavour("application/x-moz-file", "nsIFile");
return flavourSet;
}
})
]]></field>
</implementation>
<handlers>
<handler event="keypress" keycode="vk_up" modifiers="accel" phase="capturing">
<![CDATA[
var currentEngine = this.currentEngine;
if (currentEngine) {
var searchEngineMenuitem = document.getAnonymousElementByAttribute(this.parentNode, "id", currentEngine);
var newEngine = searchEngineMenuitem.previousSibling;
if (newEngine && newEngine.localName == "menuitem")
this.currentEngine = newEngine.id;
}
event.preventDefault();
event.stopPropagation();
]]>
</handler>
<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
<handler event="keypress" keycode="vk_down" modifiers="accel" phase="capturing">
<![CDATA[
var currentEngine = this.currentEngine;
if (currentEngine) {
var searchEngineMenuitem = document.getAnonymousElementByAttribute(this.parentNode, "id", currentEngine);
var newEngine = searchEngineMenuitem.nextSibling;
if (newEngine && newEngine.localName == "menuitem")
this.currentEngine = newEngine.id;
}
event.preventDefault();
event.stopPropagation();
]]>
</handler>
<handler event="dragdrop" phase="capturing">
nsDragAndDrop.drop(event, this.searchbarDNDObserver);
</handler>
</handlers>
</binding>
<binding id="searchbar-dropmarker" extends="chrome://browser/content/search.xml#searchbar-base">
<content>
<xul:stack flex="1">
<xul:hbox align="center">
<xul:image class="searchbar-engine-image" xbl:inherits="src"/>
</xul:hbox>
<xul:image class="searchbar-dropmarker-image"/>
</xul:stack>
<children/>
</content>
</binding>
</bindings>