home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2006 December
/
PCWorld_2006-12_cd.bin
/
komunikace
/
netscape
/
nsb-install-8-1-2.exe
/
chrome
/
browser.jar
/
content
/
browser
/
search.xml
< prev
next >
Wrap
Extensible Markup Language
|
2006-01-06
|
27KB
|
670 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:null"
ref="rdf:null"
oncommand="this.parentNode.setAttribute('src',event.target.getAttribute('src')); if (this.parentNode) this.parentNode.parentNode.onEnginePopupCommand(event);search.saveSelectionToPref(event.target);"
onpopupshowing="search.PopulateEnginePopup(event);if (this.parentNode) this.parentNode.parentNode.onEnginePopupShowing(event);"
onpopuphidden="if (this.parentNode) this.parentNode.parentNode.onEnginePopupHidden(event);">
</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 = window.top.document.getElementById('searchEngineBroadcaster');
if (!broadcaster) return; // JMC - This broadcaster is probably unneeded, since search sidebar is gone.
broadcaster.addEventListener('DOMAttrModified', this.onSearchEngineBroadcasterAttribChanged, 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="onSearchEngineBroadcasterAttribChanged">
<parameter name="evt"/>
<body><![CDATA[
// MERC (ccampbell) added this function to watch search engine broadcaster
if (evt.attrName == 'searchengine') {
var searchbar = document.getElementById('searchbar');
searchbar.currentEngine = evt.newValue;
//searchbar.mTextbox.select();
} else if (evt.attrName == 'searchStatus'){
if (evt.newValue == 'stopped'){
desktopSearch.StopCurrentSearch();
}
}
]]></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.FORMHISTSVC = Components
.classes["@mozilla.org/satchel/form-history;1"]
.getService(Components.interfaces.nsIFormHistory);
var engine = this.currentEngine;
//dump("\nBC: ###\nEngine == " + this.currentEngine + " \n");
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)) {
//dump("\nBC: ###\nGetting the default Engine\n");
this.currentEngine = this.getDefaultEngine();
} // if default engine not found... XXXblake what to do now?
}
var element;
element =document.createElement('menuseparator');
this.mContextMenu.appendChild(element);
element = document.createElement('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"/>
<property name="RDF" readonly="true">
<getter><![CDATA[
if (!this._RDF){
this._RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"]
.getService(Components.interfaces.nsIRDFService);
}
return this._RDF;
]]></getter>
</property>
<property name="ISEARCHDS" readonly="true">
<getter><![CDATA[
if (!this._ISEARCHDS) {
this._ISEARCHDS = this.RDF.GetDataSource("rdf:internetsearch");
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);
}
return this._ISEARCHDS;
]]></getter>
</property>
<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;
// Set the searchengine attribute on the broadcaster
var broadcaster = window.top.document.getElementById('searchEngineBroadcaster');
var src;
var pls = Components.classes["@mozilla.org/pref-localizedstring;1"]
.createInstance(Components.interfaces.nsIPrefLocalizedString);
var PREF = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch(null);
if (val=='DesktopSearch'){
src = "chrome://browser/skin/search/copernic.png";
pls.data = 'DesktopSearch';
} else {
const kNC_Icon = this.RDF.GetResource("http://home.netscape.com/NC-rdf#Icon");
const kNC_Name = this.RDF.GetResource("http://home.netscape.com/NC-rdf#Name");
var rEngine = this.RDF.GetResource(val);
src = this.readRDFString(rEngine, kNC_Icon);
pls.data = this.readRDFString(rEngine, kNC_Name);
}
PREF.setComplexValue("browser.search.selectedEngine",
Components.interfaces.nsIPrefLocalizedString,
pls);
broadcaster.setAttribute("src", src);
//alert(broadcaster.getAttribute("src"));
broadcaster.setAttribute("searchengine", val);
//alert(broadcaster.getAttribute("searchengine"));
//alert('searchengine=' + val);
// alert('src=' + src);
]]></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[
//dump('\n **************** getDefaultEngine ************************\n');
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){
//dump('\n **************** getDefaultEngine = ' + rEngine.Value + '************************\n');
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
var broadcaster = window.top.document.getElementById('searchEngineBroadcaster');
broadcaster.setAttribute("searchText", this.value);
var PREF = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch(null);
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) { }
// Do we have a desktop search
if (this.currentEngine=='DesktopSearch' ) {
try {
if (!desktopSearch.isDesktopSearchAvailable()) {
var sDesktopSearchDownloadURL = PREF.getCharPref('sidebar.desktopsearch.url');
SearchLoadURL(sDesktopSearchDownloadURL, null, true);
return;
}
}catch(e){
search.logError(e,'Desktop search error - unable to determine if Copernic is installed.');
}
try {
//Clear previous search filters
desktopSearch.ClearFilters();
// Start the desktop search.
desktopSearch.ExecuteSearch(this.value, this.displayDesktopSearchResults);
broadcaster.setAttribute("searchStatus", 'started');
}catch (e){
//MERC: NAJ: An undetermined search error has occured - dump it to log.
search.logError(e,'Desktop search error.');
return;
}
} else {
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="displayDesktopSearchResults">
<body><![CDATA[
var resultsDoc = desktopSearch.RetrieveResults();
var searchURL;
resultsCount = desktopSearch.GetSearchInfo(resultsDoc, 'count');
if (resultsCount> 0){
searchURL = desktopSearch.CreateResultsPage(resultsDoc);
} else {
var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
getService(Components.interfaces.nsIPromptService);
prompts.alert(window, "Desktop Search", "Desktop Search found no matching results.");
//prompts.alert(window, this.mStringBundle.getString("searchPromptTitle"), this.mStringBundle.getString("searchNoMatchingResultsMsg"));
}
var broadcaster = window.top.document.getElementById('searchEngineBroadcaster');
broadcaster.setAttribute("searchStatus", 'complete');
if (searchURL) {SearchLoadURL(searchURL, this.mEnterEvent, null, true )}
]]></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 {*/
//alert(target.id);
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);
]]></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();
}
// <input name=q> is the entries stored for search engine forms. Clear them.
var formHistSvc = Components.classes["@mozilla.org/satchel/form-history;1"]
.getService(Components.interfaces.nsIFormHistory);
formHistSvc.removeEntriesForName("q");
]]></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>