mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-05 08:35:26 +00:00
451 lines
16 KiB
XML
451 lines
16 KiB
XML
<?xml version="1.0"?>
|
|
|
|
<bindings id="urlbarBindings"
|
|
xmlns="http://www.mozilla.org/xbl"
|
|
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
|
|
|
<binding id="urlbar" extends="chrome://global/content/autocomplete.xml#autocomplete">
|
|
<implementation>
|
|
<constructor><![CDATA[
|
|
var pbi = this.mPrefs.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
|
|
if (pbi)
|
|
pbi.addObserver("browser.urlbar", this.mPrefObserver, false);
|
|
|
|
this.updatePref("browser.urlbar.showPopup");
|
|
this.updatePref("browser.urlbar.autoFill");
|
|
]]></constructor>
|
|
|
|
<destructor><![CDATA[
|
|
var pbi = this.mPrefs.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
|
|
if (pbi)
|
|
pbi.removeObserver("browser.urlbar", this.mPrefObserver);
|
|
]]></destructor>
|
|
|
|
<field name="mPrefs">
|
|
var svc = Components.classes["@mozilla.org/preferences-service;1"]
|
|
.getService(Components.interfaces.nsIPrefService);
|
|
svc.getBranch(null);
|
|
</field>
|
|
|
|
<field name="mPrefObserver"><![CDATA[
|
|
({
|
|
urlbar: this,
|
|
|
|
observe: function(aObserver, aBlah, aPref) {
|
|
if (!aPref.indexOf("browser.urlbar"))
|
|
this.urlbar.updatePref(aPref);
|
|
}
|
|
});
|
|
]]></field>
|
|
|
|
<method name="updatePref">
|
|
<parameter name="aPref"/>
|
|
<body><![CDATA[
|
|
if (!aPref.indexOf("browser.urlbar.showPopup")) {
|
|
this.showPopup = this.mPrefs.getBoolPref("browser.urlbar.showPopup");
|
|
} else if (!aPref.indexOf("browser.urlbar.autoFill")) {
|
|
this.autoFill = this.mPrefs.getBoolPref("browser.urlbar.autoFill");
|
|
}
|
|
]]></body>
|
|
</method>
|
|
|
|
</implementation>
|
|
</binding>
|
|
|
|
<binding id="autocomplete-result-popup" extends="chrome://global/content/autocomplete.xml#autocomplete-result-popup">
|
|
<content menugenerated="true" orient="vertical">
|
|
<xul:box class="autocomplete-result-box" flex="1">
|
|
<xul:outliner anonid="outliner" class="autocomplete-outliner" flex="1">
|
|
<xul:outlinerbody anonid="outlinerbody" class="autocomplete-outlinerbody" flex="1"/>
|
|
</xul:outliner>
|
|
</xul:box>
|
|
<xul:box role="search-box" class="autocomplete-search-box"/>
|
|
</content>
|
|
|
|
<implementation>
|
|
<constructor><![CDATA[
|
|
// listen for changes to default search engine
|
|
var pbi = this.mPrefs.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
|
|
if (pbi) {
|
|
pbi.addObserver("browser.search", this.mPrefObserver, false);
|
|
pbi.addObserver("browser.urlbar", this.mPrefObserver, false);
|
|
}
|
|
]]></constructor>
|
|
|
|
<destructor><![CDATA[
|
|
var pbi = this.mPrefs.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
|
|
if (pbi) {
|
|
pbi.removeObserver("browser.search", this.mPrefObserver);
|
|
pbi.removeObserver("browser.urlbar", this.mPrefObserver);
|
|
}
|
|
]]></destructor>
|
|
|
|
<property name="selectedIndex"
|
|
onget="return this.textbox.view.selectedIndex;">
|
|
<setter>
|
|
this.mSelectedIndex = val;
|
|
if (val == null)
|
|
this.mSearchBox.selectedIndex = null;
|
|
|
|
return val;
|
|
</setter>
|
|
</property>
|
|
|
|
<property name="showSearch" onget="return this.mShowSearch;">
|
|
<setter><![CDATA[
|
|
this.mShowSearch = val;
|
|
if (val) {
|
|
this.updateEngines();
|
|
this.mSearchBox.removeAttribute("hidden");
|
|
} else {
|
|
this.clearEngines();
|
|
this.mSearchBox.setAttribute("hidden", "true");
|
|
}
|
|
]]></setter>
|
|
</property>
|
|
|
|
<property name="mSelectedIndex">
|
|
<setter>
|
|
this.textbox.view.selectedIndex = val;
|
|
return val;
|
|
</setter>
|
|
</property>
|
|
|
|
<property name="defaultSearchEngine"
|
|
onget="return this.textbox.getAttribute('defaultSearchEngine') == 'true';"
|
|
onset="this.textbox.setAttribute('defaultSearchEngine', val); return val;"/>
|
|
|
|
<field name="mSearchBox">
|
|
document.getAnonymousElementByAttribute(this, "role", "search-box");
|
|
</field>
|
|
|
|
<field name="mPrefs">
|
|
var svc = Components.classes["@mozilla.org/preferences-service;1"]
|
|
.getService(Components.interfaces.nsIPrefService);
|
|
svc.getBranch(null);
|
|
</field>
|
|
|
|
<field name="mPrefObserver"><![CDATA[
|
|
({
|
|
resultsPopup: this,
|
|
|
|
observe: function(aObserver, aBlah, aPref) {
|
|
if (!aPref.indexOf("browser.search"))
|
|
this.resultsPopup.updateEngines();
|
|
else if (!aPref.indexOf("browser.urlbar"))
|
|
this.resultsPopup.updatePref(aPref);
|
|
}
|
|
});
|
|
]]></field>
|
|
|
|
<field name="mInputListener"><![CDATA[
|
|
(function(aEvent) {
|
|
// "this" is the textbox, not the popup
|
|
if (this.mSearchInputTO)
|
|
window.clearTimeout(this.mSearchInputTO);
|
|
this.mSearchInputTO = window.setTimeout(this.resultsPopup.mInputTimeout, this.timeout, this);
|
|
});
|
|
]]></field>
|
|
|
|
<field name="mInputTimeout"><![CDATA[
|
|
(function(me) {
|
|
me.resultsPopup.mSearchBox.searchValue = me.value;
|
|
me.mSearchInputTO = 0;
|
|
});
|
|
]]></field>
|
|
|
|
<field name="mEnginesReady">false</field>
|
|
|
|
<method name="getOverrideValue">
|
|
<body><![CDATA[
|
|
if (this.mSearchBox.selectedIndex != null)
|
|
return this.mSearchBox.getOverrideValue();
|
|
return null;
|
|
]]></body>
|
|
</method>
|
|
|
|
<method name="updatePref">
|
|
<parameter name="aPref"/>
|
|
<body><![CDATA[
|
|
if (!aPref.indexOf("browser.urlbar.showSearch"))
|
|
this.showSearch = this.mPrefs.getBoolPref("browser.urlbar.showSearch");
|
|
]]></body>
|
|
</method>
|
|
|
|
<method name="addEngine">
|
|
<parameter name="aEngineId"/>
|
|
<parameter name="aName"/>
|
|
<parameter name="aIcon"/>
|
|
<parameter name="aSearchBarUrl"/>
|
|
<body><![CDATA[
|
|
var box = document.createElement("box");
|
|
box.setAttribute("class", "autocomplete-search-engine");
|
|
box.setAttribute("searchEngine", aEngineId);
|
|
box.setAttribute("name", aName);
|
|
box.setAttribute("icon", aIcon);
|
|
box.setAttribute("searchBarUrl", aSearchBarUrl);
|
|
box.setAttribute("engineIndex", this.childNodes.length);
|
|
this.mSearchBox.appendChild(box);
|
|
]]></body>
|
|
</method>
|
|
|
|
<method name="clearEngines">
|
|
<body><![CDATA[
|
|
var kids = this.mSearchBox.childNodes;
|
|
for (var i = kids.length-1; i >= 0; --i)
|
|
this.mSearchBox.removeChild(kids[i]);
|
|
]]></body>
|
|
</method>
|
|
|
|
<method name="updateEngines">
|
|
<body><![CDATA[
|
|
var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"]
|
|
.getService(Components.interfaces.nsIRDFService);
|
|
var ds = rdf.GetDataSource("rdf:internetsearch");
|
|
|
|
const kNC_Name = rdf.GetResource("http://home.netscape.com/NC-rdf#Name");
|
|
const kNC_Icon = rdf.GetResource("http://home.netscape.com/NC-rdf#Icon");
|
|
const kNC_searchBarUrl = rdf.GetResource("http://home.netscape.com/NC-rdf#actionBar");
|
|
|
|
var defaultEngine = null;
|
|
try {
|
|
defaultEngine = this.mPrefs.getComplexValue("browser.search.defaultengine",
|
|
Components.interfaces.nsISupportsWString).data;
|
|
} catch(ex) {
|
|
this.ensureDefaultEnginePrefs(rdf, ds);
|
|
defaultEngine = this.mPrefs.getComplexValue("browser.search.defaultengine",
|
|
Components.interfaces.nsISupportsWString).data;
|
|
}
|
|
|
|
if (defaultEngine) {
|
|
this.clearEngines();
|
|
|
|
if (ds) {
|
|
var res = rdf.GetResource(defaultEngine);
|
|
try {
|
|
searchBarUrl = this.readRDFString(ds, res, kNC_searchBarUrl);
|
|
} catch(ex) {
|
|
searchBarUrl = null;
|
|
}
|
|
this.addEngine(res.Value,
|
|
this.readRDFString(ds, res, kNC_Name),
|
|
this.readRDFString(ds, res, kNC_Icon),
|
|
searchBarUrl);
|
|
}
|
|
}
|
|
|
|
this.mEnginesReady = true;
|
|
]]></body>
|
|
</method>
|
|
|
|
<method name="ensureDefaultEnginePrefs">
|
|
<parameter name="aRDF"/>
|
|
<parameter name="aDS"/>
|
|
<body><![CDATA[
|
|
var defaultName = this.mPrefs.getComplexValue("browser.search.defaultenginename",
|
|
Components.interfaces.nsIPrefLocalizedString).data;
|
|
const kNC_Root = aRDF.GetResource("NC:SearchEngineRoot");
|
|
const kNC_child = aRDF.GetResource("http://home.netscape.com/NC-rdf#child");
|
|
const kNC_Name = aRDF.GetResource("http://home.netscape.com/NC-rdf#Name");
|
|
|
|
var arcs = aDS.GetTargets(kNC_Root, kNC_child, true);
|
|
while (arcs.hasMoreElements()) {
|
|
var engineRes = arcs.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
|
|
var name = this.readRDFString(aDS, engineRes, kNC_Name);
|
|
if (name == defaultName) {
|
|
var str = Components.classes["@mozilla.org/supports-wstring;1"]
|
|
.createInstance(Components.interfaces.nsISupportsWString);
|
|
str.data = engineRes.Value;
|
|
this.mPrefs.setComplexValue("browser.search.defaultengine",
|
|
Components.interfaces.nsISupportsWString,
|
|
str);
|
|
}
|
|
}
|
|
]]></body>
|
|
</method>
|
|
|
|
<method name="readRDFString">
|
|
<parameter name="aDS"/>
|
|
<parameter name="aRes"/>
|
|
<parameter name="aProp"/>
|
|
<body><![CDATA[
|
|
var n = aDS.GetTarget(aRes, aProp, true);
|
|
return n ? n.QueryInterface(Components.interfaces.nsIRDFLiteral).Value : null;
|
|
]]></body>
|
|
</method>
|
|
|
|
<method name="selectBy">
|
|
<parameter name="aDir"/>
|
|
<parameter name="aAmount"/>
|
|
<body><![CDATA[
|
|
var bx = this.outliner.outlinerBoxObject;
|
|
var view = bx.view;
|
|
var sel;
|
|
if (this.selectedIndex == null && aDir < 0) {
|
|
sel = this.mSearchBox.selectBy(aDir, aAmount);
|
|
if (sel != null)
|
|
return null;
|
|
}
|
|
|
|
sel = this.getNextIndex(aDir, aAmount, this.selectedIndex, view.rowCount-1);
|
|
this.mSelectedIndex = sel;
|
|
|
|
if (sel == null && aDir > 0)
|
|
this.mSearchBox.selectBy(aDir, aAmount);
|
|
else if (this.mSearchBox.selectedIndex != null)
|
|
this.mSearchBox.selectedIndex = null;
|
|
|
|
return sel;
|
|
]]></body>
|
|
</method>
|
|
</implementation>
|
|
|
|
<handlers>
|
|
<handler event="popupshowing"><![CDATA[
|
|
if (!this.mEnginesReady && this.defaultSearchEngine)
|
|
this.updatePref("browser.urlbar.showSearch");
|
|
|
|
if (this.mShowSearch) {
|
|
this.textbox.addEventListener("input", this.mInputListener, false);
|
|
if ("searchValue" in this.mSearchBox)
|
|
this.mSearchBox.searchValue = this.textbox.currentSearchString;
|
|
else
|
|
this.mSearchBox.setAttribute("searchvalue", this.textbox.currentSearchString);
|
|
}
|
|
]]></handler>
|
|
|
|
<handler event="popuphiding"><![CDATA[
|
|
if (this.mShowSearch)
|
|
this.textbox.removeEventListener("input", this.mInputListener, false);
|
|
]]></handler>
|
|
</handlers>
|
|
</binding>
|
|
|
|
<binding id="autocomplete-search-box">
|
|
<content orient="vertical"/>
|
|
|
|
<implementation>
|
|
<constructor><![CDATA[
|
|
var text = this.getAttribute("searchvalue");
|
|
if (text)
|
|
this.searchValue = text;
|
|
|
|
this.mSelectedIndex = null;
|
|
]]></constructor>
|
|
|
|
<field name="parentMouseoverListener">
|
|
// ensure that if a result menuitem is moused-over, any
|
|
// search selection is cleared
|
|
(function(aEvent) {
|
|
if (aEvent.target.nodeName == "menuitem")
|
|
this.mSearchBox.selectedIndex = null;
|
|
})
|
|
</field>
|
|
|
|
<field name="parentDestroyListener">
|
|
// ensure that if the popup closes, any search selection is cleared
|
|
(function(aEvent) {
|
|
this.mSearchBox.selectedIndex = null;
|
|
})
|
|
</field>
|
|
|
|
<property name="activeChild"
|
|
onget="return this.childNodes[this.mSelectedIndex]"/>
|
|
|
|
<property name="selectedIndex">
|
|
<getter>return this.mSelectedIndex;</getter>
|
|
|
|
<setter><![CDATA[
|
|
if (this.mSelectedIndex != null)
|
|
this.activeChild.removeAttribute("menuactive");
|
|
|
|
this.mSelectedIndex = val;
|
|
|
|
if (val != null) {
|
|
this.parentNode.mSelectedIndex = null;
|
|
this.parentNode.addEventListener("mouseover", this.parentMouseoverListener, false);
|
|
this.parentNode.addEventListener("popuphiding", this.parentDestroyListener, false);
|
|
if (this.activeChild)
|
|
this.activeChild.setAttribute("menuactive", "true");
|
|
} else {
|
|
this.parentNode.removeEventListener("mouseover", this.parentMouseoverListener, false);
|
|
this.parentNode.removeEventListener("popuphiding", this.parentDestroyListener, false);
|
|
}
|
|
]]></setter>
|
|
|
|
</property>
|
|
|
|
<property name="searchValue">
|
|
<getter><![CDATA[
|
|
return this.mSearchValue;
|
|
]]></getter>
|
|
<setter><![CDATA[
|
|
this.mSearchValue = val;
|
|
var kids = this.childNodes;
|
|
for (var i = 0; i < kids.length; ++i) {
|
|
var name = kids[i].getAttribute("name");
|
|
kids[i].setAttribute("label", "Search " + name + " for \"" + val + "\"");
|
|
}
|
|
]]></setter>
|
|
</property>
|
|
|
|
<method name="selectBy">
|
|
<parameter name="aDir"/>
|
|
<parameter name="aAmount"/>
|
|
<body><![CDATA[
|
|
var sel = this.parentNode.getNextIndex(aDir, aAmount, this.selectedIndex, this.childNodes.length-1);
|
|
this.selectedIndex = sel;
|
|
return sel;
|
|
]]></body>
|
|
</method>
|
|
|
|
<method name="getOverrideValue">
|
|
<body><![CDATA[
|
|
var item = this.activeChild;
|
|
if (item) {
|
|
const ISEARCH_CONTRACTID = "@mozilla.org/rdf/datasource;1?name=internetsearch";
|
|
const nsIInternetSearchService = Components.interfaces.nsIInternetSearchService;
|
|
var searchService = Components.classes[ISEARCH_CONTRACTID].getService(nsIInternetSearchService);
|
|
var searchEng = item.getAttribute("searchEngine");
|
|
var searchEngUrl = item.getAttribute("searchBarUrl");
|
|
var escapedSearch = escape(this.mSearchValue)
|
|
if (searchEngUrl) {
|
|
searchEngUrl += escapedSearch;
|
|
return searchEngUrl;
|
|
} else {
|
|
return searchService.GetInternetSearchURL(item.getAttribute("searchEngine"),escapedSearch);
|
|
}
|
|
}
|
|
return null;
|
|
]]></body>
|
|
</method>
|
|
|
|
</implementation>
|
|
|
|
<handlers>
|
|
<handler event="mouseup">
|
|
this.parentNode.textbox.onResultClick();
|
|
</handler>
|
|
</handlers>
|
|
|
|
</binding>
|
|
|
|
<binding id="autocomplete-search-engine">
|
|
<content>
|
|
<xul:image class="autocomplete-search-engine-img" inherits="src=icon"/>
|
|
<xul:label class="autocomplete-search-engine-text" inherits="value=label" crop="right" flex="1"/>
|
|
</content>
|
|
|
|
<handlers>
|
|
<handler event="mouseover">
|
|
this.parentNode.selectedIndex = this.getAttribute("engineIndex");
|
|
</handler>
|
|
|
|
<handler event="mouseout">
|
|
this.parentNode.selectedIndex = null;
|
|
</handler>
|
|
</handlers>
|
|
</binding>
|
|
|
|
</bindings>
|