зеркало из https://github.com/mozilla/gecko-dev.git
218 строки
8.5 KiB
XML
218 строки
8.5 KiB
XML
<?xml version="1.0"?>
|
|
|
|
# -*- Mode: HTML -*-
|
|
# ***** BEGIN LICENSE BLOCK *****
|
|
# 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)
|
|
#
|
|
# Alternatively, the contents of this file may be used under the
|
|
# terms of the GNU General Public License Version 2 or later (the
|
|
# "GPL"), in which case the provisions of the GPL are applicable
|
|
# instead of those above. If you wish to allow use of your
|
|
# version of this file only under the terms of the GPL and not to
|
|
# allow others to use your version of this file under the MPL,
|
|
# indicate your decision by deleting the provisions above and
|
|
# replace them with the notice and other provisions required by
|
|
# the GPL. If you do not delete the provisions above, a recipient
|
|
# may use your version of this file under either the MPL or the
|
|
# GPL.
|
|
#
|
|
# ***** 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" extends="chrome://global/content/bindings/autocomplete.xml#autocomplete">
|
|
<implementation>
|
|
<constructor><![CDATA[
|
|
setTimeout(function(a) { a.initialize(); }, 0, this);
|
|
]]></constructor>
|
|
|
|
<method name="initialize">
|
|
<body><![CDATA[
|
|
this.RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"]
|
|
.getService(Components.interfaces.nsIRDFService);
|
|
this.ISEARCHDS = this.RDF.GetDataSource("rdf:internetsearch");
|
|
|
|
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)) {
|
|
// XXXben this is a short term hack to prevent the search engine selector
|
|
// from forgetting the defaut.
|
|
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
|
|
file.initWithPath(unescape(engine.substr("engine://".length)));
|
|
if (!file.exists())
|
|
this.currentEngine = "__PhoenixFindInPage";
|
|
}
|
|
}
|
|
]]></body>
|
|
</method>
|
|
|
|
<field name="RDF"/>
|
|
<field name="ISEARCHDS"/>
|
|
|
|
<property name="currentEngine"
|
|
onget="return this.getAttribute('searchengine')">
|
|
<setter><![CDATA[
|
|
if (!val)
|
|
return;
|
|
|
|
this.setAttribute("searchengine", val);
|
|
|
|
if (val == "__PhoenixFindInPage") {
|
|
this.setAttribute("autocompletesearchparam", "__PhoenixFindInPage");
|
|
this.firstChild.removeAttribute("src");
|
|
return;
|
|
}
|
|
|
|
this.setAttribute("autocompletesearchparam", "q");
|
|
const kNC_Icon = this.RDF.GetResource("http://home.netscape.com/NC-rdf#Icon");
|
|
var rEngine = this.RDF.GetResource(val);
|
|
this.firstChild.setAttribute("src", this.readRDFString(rEngine, kNC_Icon));
|
|
|
|
]]></setter>
|
|
</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[
|
|
// Save the current value in the form history
|
|
if (gFormFillEnabled) {
|
|
if (!gFormHistory)
|
|
gFormHistory = Components.classes["@mozilla.org/satchel/form-history;1"]
|
|
.getService(Components.interfaces.nsIFormHistory);
|
|
gFormHistory.addEntry(this.getAttribute("autocompletesearchparam"), this.value);
|
|
}
|
|
if (this.currentEngine != "__PhoenixFindInPage") {
|
|
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 the search box is empty, let''s load the host
|
|
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;
|
|
}
|
|
gURLBar.value = searchURL; //pch: ugly!
|
|
BrowserLoadURL(this.mEnterEvent); // from autocomplete.xml
|
|
} else {
|
|
quickFindInPage(this.value);
|
|
}
|
|
]]></body>
|
|
</method>
|
|
|
|
</implementation>
|
|
|
|
<handlers>
|
|
|
|
<handler event="keypress" keycode="vk_up" modifiers="control" phase="capturing">
|
|
<![CDATA[
|
|
var currentEngine = this.currentEngine;
|
|
if (currentEngine && currentEngine != "__PhoenixFindInPage") {
|
|
var searchEngineMenuitem = document.getElementById(currentEngine);
|
|
var newEngine = searchEngineMenuitem.previousSibling;
|
|
if (!newEngine.id)
|
|
newEngine = {id: "__PhoenixFindInPage"}
|
|
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)
|
|
return;
|
|
var searchEngineMenuitem = document.getElementById(currentEngine);
|
|
var newEngine;
|
|
if (currentEngine == "__PhoenixFindInPage") {
|
|
newEngine = searchEngineMenuitem.nextSibling.nextSibling.nextSibling;
|
|
} else {
|
|
newEngine = searchEngineMenuitem.nextSibling;
|
|
}
|
|
if (newEngine)
|
|
this.currentEngine = newEngine.id;
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
]]>
|
|
</handler>
|
|
|
|
</handlers>
|
|
|
|
</binding>
|
|
|
|
<binding id="searchBarDropMarker">
|
|
<content>
|
|
<xul:stack flex="1">
|
|
<xul:hbox align="center">
|
|
<xul:image class="search-proxy-button-image" xbl:inherits="src"/>
|
|
</xul:hbox>
|
|
<xul:image class="search-proxy-button-dropmarker"/>
|
|
</xul:stack>
|
|
</content>
|
|
</binding>
|
|
|
|
</bindings>
|