home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2005 December
/
PCWorld_2005-12_cd.bin
/
komunikace
/
netscape
/
nsb-install-8-0.exe
/
chrome
/
browser.jar
/
content
/
browser
/
search.xml
< prev
next >
Wrap
Extensible Markup Language
|
2005-09-26
|
23KB
|
593 lines
<?xml version="1.0"?>
<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">
<!--
type="autocomplete"
autocompletepopup="SearchBarHistoryPopup"
autocompletesearch="form-history"
autocompletesearchparam="searchbar-history"
disableautocomplete="true"
enablehistory="true"
-->
<content>
<xul:stringbundle src="chrome://browser/locale/searchbar.properties"/>
<xul:textbox class="searchbar-textbox" flex="1"
completeselectedindex="true"
tabscrolling="true"
onfocus="URLBarFocusHandler(event, this);"
onmousedown="URLBarMouseDownHandler(event, this);"
onclick="URLBarClickHandler(event, this);"
xbl:inherits="searchengine,src">
<xul:button class="searchbar-dropmarker" type="menu"
popup="_child" xbl:inherits="src">
<xul:menupopup anonid="searchbar-popup" position="after_start"
datasources="rdf:internetsearch"
ref="NC:SearchEngineRoot"
sortResource="http://home.netscape.com/NC-rdf#Name" sortDirection="ascending"
oncommand="if (this.parentNode) this.parentNode.parentNode.onEnginePopupCommand(event);"
onpopupshowing="if (this.parentNode) this.parentNode.parentNode.onEnginePopupShowing(event);"
onpopuphidden="if (this.parentNode) 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:menuseparator anonid="searchsize-menuseparator"/>
<xul:menu anonid="searchsize-menu" label="Select size">
<xul:menupopup label="Search Box Size" anonid="searchbar-size-popup" position="after_start"
oncommand="if (this.parentNode) this.parentNode.parentNode.parentNode.parentNode.onSearchBoxSize(event);">
<xul:menuitem anonid="searchbox-size-10em" type="radio" label="Short" name="searchbox-size" value="10em"/>
<xul:menuitem anonid="searchbox-size-15em" type="radio" label="Medium" name="searchbox-size" value="15em"/>
<xul:menuitem anonid="searchbox-size-19em" type="radio" label="Long" name="searchbox-size" value="19em"/>
</xul:menupopup>
</xul:menu> -->
</xul:menupopup>
</xul:button>
</xul:textbox>
<xul:dropmarker class="searchbar-history-dropmarker"
popup="SearchBarHistoryPopup">
<xul:image class="searchbar-history-dropmarker-image"/>
</xul:dropmarker>
</content>
<implementation>
<constructor><![CDATA[
var broadcaster = document.getElementById('searchEngineBroadcaster');
broadcaster.addEventListener('DOMAttrModified', this.onSearchEngineChange, false);
]]></constructor>
<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="clear">
<body><![CDATA[
this.mTextbox.value="";
]]></body>
</method>
<method name="select">
<body><![CDATA[
this.mTextbox.select();
]]></body>
</method>
<method name="onSearchEngineChange">
<parameter name="evt"/>
<body><![CDATA[
// MERC (ccampbell) added this function to watch search engine broadcaster
if (evt.attrName!='searchengine') return;
var searchbar = document.getElementById('searchbar');
searchbar.currentEngine = evt.newValue;
//searchbar.mTextbox.select();
]]></body>
</method>
</implementation>
</binding>
<binding id="searchbar-textbox" extends="chrome://global/content/bindings/autocomplete.xml#autocomplete">
<implementation>
<constructor><![CDATA[
if (this.parentNode && this.parentNode.parentNode.parentNode.localName ==
"toolbarpaletteitem")
return;
setTimeout(function(a) { a.initialize(); }, 0, this);
]]></constructor>
<destructor><![CDATA[
if (this.parentNode && this.parentNode.parentNode.parentNode.localName ==
"toolbarpaletteitem")
return;
this.controllers.removeController(this.searchbarController);
]]></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[
if (!this.parentNode || !this.mContextMenu) return;
this.RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"]
.getService(Components.interfaces.nsIRDFService);
this.ISEARCHDS = this.RDF.GetDataSource("rdf:internetsearch");
this.FORMHISTSVC = Components
.classes["@mozilla.org/satchel/form-history;1"]
.getService(Components.interfaces.nsIFormHistory);
var engine = this.currentEngine;
if (!engine)
this.currentEngine = this.getDefaultEngine();
else {
var rEngine = this.RDF.GetResource(engine);
var rChild = this.RDF.GetResource("http://home.netscape.com/NC-rdf#child");
if (!this.ISEARCHDS.hasArcIn(rEngine, rChild)) {
this.currentEngine = this.getDefaultEngine();
} // if default engine not found... XXXblake what to do now?
}
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>
<field name="mStringBundle">
if (this.parentNode)
this.parentNode.mStringBundle </field>
<field name="RDF"/>
<field name="ISEARCHDS"/>
<field name="FORMHISTSVC"/>
<field name="SEARCH_HISTORY_FILE">"search-history.txt"</field>
<field name="PR_RDONLY">1</field>
<property name="currentEngine"
onget="if (this.parentNode) return this.parentNode.getAttribute('searchengine'); else return null;">
<setter><![CDATA[
if (!val)
return;
var broadcaster = document.getElementById('searchEngineBroadcaster');
broadcaster.setAttribute("searchengine", val);
const kNC_Icon = this.RDF.GetResource("http://home.netscape.com/NC-rdf#Icon");
var rEngine = this.RDF.GetResource(val);
broadcaster.setAttribute("src", this.readRDFString(rEngine, kNC_Icon));
const kNC_Name = this.RDF.GetResource("http://home.netscape.com/NC-rdf#Name");
var pls = Components.classes["@mozilla.org/pref-localizedstring;1"]
.createInstance(Components.interfaces.nsIPrefLocalizedString);
pls.data = this.readRDFString(rEngine, kNC_Name);
var PREF = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch(null);
PREF.setComplexValue("browser.search.selectedEngine",
Components.interfaces.nsIPrefLocalizedString,
pls);
]]></setter>
</property>
<property name="perfmon">
<getter><![CDATA[
if (!this.parentNode) return null;
var rEngine = this.RDF.GetResource(this.currentEngine);
const kNC_Name = this.RDF.GetResource("http://home.netscape.com/NC-rdf#Name");
var pls = Components.classes["@mozilla.org/pref-localizedstring;1"]
.createInstance(Components.interfaces.nsIPrefLocalizedString);
var engineID = 'searchbar:'+this.readRDFString(rEngine, kNC_Name);
dump('search.xml: perfmon = '+engineID+'\n');
return engineID;
]]></getter>
</property>
<method name="getDefaultEngine">
<body><![CDATA[
var PREF = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch(null);
var defaultName = PREF.getComplexValue("browser.search.defaultenginename",
Components.interfaces.nsIPrefLocalizedString).data;
const kNC_Root = this.RDF.GetResource("NC:SearchEngineRoot");
const kNC_child = this.RDF.GetResource("http://home.netscape.com/NC-rdf#child");
const kNC_Name = this.RDF.GetResource("http://home.netscape.com/NC-rdf#Name");
var arcs = this.ISEARCHDS.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.ISEARCHDS.GetTarget(aRes, aProp, true);
return n ? n.QueryInterface(Components.interfaces.nsIRDFLiteral).Value : null;
]]></body>
</method>
<!-- // overload |onTextEntered| in autocomplete.xml -->
<method name="onTextEntered">
<body><![CDATA[
// CDC - Remember the text in the search history list
if (this.value) {
search.AddToHistory(this.value);
}
// CDC - Count search provider hits
try {
if (perfmon) {
this.setAttribute('perfmon', this.perfmon);
perfmon.trackData(this);
}
} catch (ex) { }
var ISEARCHSVC = Components.classes["@mozilla.org/rdf/datasource;1?name=internetsearch"]
.getService(Components.interfaces.nsIInternetSearchService);
var searchURL = ISEARCHSVC.GetInternetSearchURL(this.currentEngine,
this.value? encodeURIComponent(this.value):"",
0, 0, {value:0});
if (!this.value) {
var uri = Components.classes['@mozilla.org/network/standard-url;1']
.createInstance(Components.interfaces.nsIURI);
uri.spec = searchURL;
searchURL = uri.host;
if (!searchURL)
return;
}
// JMC - Why was this commented out?
SearchLoadURL(searchURL, this.mEnterEvent);
]]></body>
</method>
<method name="onSearchBoxSize">
<parameter name="aEvent"/>
<body><![CDATA[
if (!this.parentNode) return; // JMC - Sanity check fixes BLT bug 127010
var newSize;
newSize = aEvent.target.getAttribute("value");
this.parentNode.style.width = newSize;
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
prefService.setCharPref("browser.search.size",newSize);
/*
var menupopup = document.getAnonymousElementByAttribute(this, "anonid", "searchbar-size-popup");
var foundme = document.getAnonymousElementByAttribute(menupopup, "value", newSize);
if (foundme)
foundme.setAttribute("checked", "true");
*/
this.focus();
this.select();
]]></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[
dump("\n\nOnEnginePopupShowing... executed! \n\n");
if (!this.parentNode) return;
var target = aEvent.target;
var element = document.getAnonymousElementByAttribute(this.parentNode,
"anonid", "searchsize-menuseparator");
if (!element)
return;
var myParent = element.parentNode;
myParent.removeChild(element);
myParent.appendChild(element);
element = document.getAnonymousElementByAttribute(this.parentNode,
"anonid", "searchsize-menu");
myParent.removeChild(element);
myParent.appendChild(element);
/* don't need any of this pucky
search.ReadSearchHistory();
var target = aEvent.target;
var element = document.getAnonymousElementByAttribute(this.parentNode,
"anonid", "clearhistory-menuitem");
if (element)
return;
element = document.createElementNS(XUL_NS, "menuseparator");
target.appendChild(element);
// MERC: add 'clear search history' menu item
element = document.createElementNS(XUL_NS, "menuitem");
element.setAttribute("label", "Clear search history");
element.setAttribute("anonid", "clearhistory-menuitem");
target.appendChild(element);
*/
/* MERC: Disable adding of new search engines
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[
if (!this.parentNode) return;
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)
{
var entries = this.mOuter.ReadSearchHistory();
// MERC - JCH: If search history file is empty, array still ends up with size == 1.
return entries.length > 1;
// return this.mOuter.FORMHISTSVC.nameExists(
// this.mOuter.getAttribute("autocompletesearchparam"));
},
doCommand: function (aCommand)
{
this.mOuter.ClearSearchHistory();
//this.mOuter.FORMHISTSVC.removeEntriesForName(
// this.mOuter.getAttribute("autocompletesearchparam"));
//this.mOuter.value = "";
}
})
]]></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) {
// XXXBlake Workaround caret crash when you try to set the
// textbox's value on dropping
setTimeout(function(This, data, evt) { This.value = data; This.onTextEntered(evt); }, 0, this.mOuter, data, 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>
<!-- MERC - JCH: The following four methods address BLT# 150209 -->
<method name="GetSearchHistoryFile">
<body><![CDATA[
dump('GetSearchHistoryFile(): '+this.SEARCH_HISTORY_FILE);
// Get the user's profile directory
var profileDir = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsILocalFile);
if (profileDir)
{
// Create file descriptor
var file = profileDir.clone();
file.append(this.SEARCH_HISTORY_FILE);
// returns nsILocalFile
return file;
}
]]></body>
</method>
<method name="EnsureSearchHistoryFileExists">
<body><![CDATA[
dump('EnsureSearchHistoryFileExists()');
var file = this.GetSearchHistoryFile();
if (!file.exists()) {
dump(' creating file: '+this.SEARCH_HISTORY_FILE);
file.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0);
}
// returns nsILocalFile
return file;
]]></body>
</method>
<method name="ReadSearchHistory">
<body><![CDATA[
dump('ReadSearchHistory()');
var file = this.EnsureSearchHistoryFileExists();
// Init the file input stream
var fis = Components.classes["@mozilla.org/network/file-input-stream;1"]
.createInstance(Components.interfaces.nsIFileInputStream);
fis.init(file, this.PR_RDONLY, 0, 0);
// Init a scriptable input stream
var sis = Components.classes["@mozilla.org/scriptableinputstream;1"]
.createInstance(Components.interfaces.nsIScriptableInputStream);
sis.init(fis);
// Read the file
var fileContents = sis.read(sis.available());
// Close file
fis.close();
// Return the lines as an array
return fileContents.split('\n');
]]></body>
</method>
<method name="ClearSearchHistory">
<body><![CDATA[
dump('ClearSearchHistory()');
var file = this.GetSearchHistoryFile();
if (file.exists())
{
// Init the file input stream
var fis = Components.classes["@mozilla.org/network/file-input-stream;1"]
.createInstance(Components.interfaces.nsIFileInputStream);
fis.init(file, this.PR_RDONLY, 0,
Components.interfaces.nsIFileInputStream.DELETE_ON_CLOSE);
fis.close();
}
// MERC (rpaul) clear the searchbar text
var searchbar = document.getElementById('searchbar');
if (searchbar)
{
searchbar.clear();
}
]]></body>
</method>
</implementation>
<handlers>
<handler event="keypress" keycode="vk_up" modifiers="control" phase="capturing">
<![CDATA[
var currentEngine = this.currentEngine;
if (currentEngine) {
var searchEngineMenuitem = document.getAnonymousElementByAttribute(this.parentNode, "id", currentEngine);
var newEngine = searchEngineMenuitem.previousSibling;
if (newEngine)
this.currentEngine = newEngine.id;
}
event.preventDefault();
event.stopPropagation();
]]>
</handler>
<handler event="keypress" keycode="vk_down" modifiers="control" phase="capturing">
<![CDATA[
var currentEngine = this.currentEngine;
if (currentEngine) {
var searchEngineMenuitem = document.getAnonymousElementByAttribute(this.parentNode, "id", currentEngine);
var newEngine = searchEngineMenuitem.nextSibling;
if (newEngine)
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:hbox align="end">
<xul:spacer flex="1"/>
<xul:image class="searchbar-dropmarker-image"/>
</xul:hbox>
</xul:stack>
<children/>
</content>
</binding>
</bindings>