171581 - toolbar search/find in page for phoenix

This commit is contained in:
hewitt%netscape.com 2002-09-29 20:06:57 +00:00
Родитель fb638fd6f7
Коммит 6d6d593ffb
8 изменённых файлов: 271 добавлений и 7 удалений

Просмотреть файл

@ -18,3 +18,7 @@ window[chromehidden~="toolbar"] #navigator-throbber {
window[chromehidden~="toolbar"] #navigator-throbber[busy="true"] {
list-style-image: url("chrome://communicator/skin/brand/throbber16-anim.gif") !important;
}
#search-bar {
-moz-binding: url("chrome://browser/content/search.xml#searchbar");
}

Просмотреть файл

@ -81,7 +81,8 @@ var gPrintSettings = null;
var gChromeState = null; // chrome state before we went into print preview
var gOldCloseHandler = null; // close handler before we went into print preview
var gInPrintPreviewMode = false;
var gWebProgress = null;
var gWebProgress = null;
var gFormHistory = null;
/**
* We can avoid adding multiple load event listeners and save some time by adding
@ -1164,6 +1165,94 @@ function PageProxyDragGesture(aEvent)
return false;
}
function SearchBarPopupShowing(aEvent)
{
var popup = aEvent.target;
if (popup.firstChild.localName == "menuitem")
popup.removeChild(popup.firstChild);
var searchBar = document.getElementById("search-bar");
var searchMode = searchBar.getAttribute("searchmode");
var findItem = document.getElementById("miSearchModeFind");
findItem.setAttribute("checked", searchMode == "findinpage");
var searchBar = document.getElementById("search-bar");
if (!searchBar.enginesReady)
searchBar.updateEngines();
if (searchBar.currentSearchId) {
var menuitem = document.createElement("menuitem");
menuitem.setAttribute("label", searchBar.currentSearchName);
if (searchBar.currentSearchIcon) {
menuitem.setAttribute("class", "menuitem-iconic");
menuitem.setAttribute("image", searchBar.currentSearchIcon);
} else {
menuitem.setAttribute("type", "checkbox");
menuitem.setAttribute("checked", searchMode == "web");
}
popup.insertBefore(menuitem, popup.firstChild);
}
}
function SearchBarPopupCommand(aEvent)
{
var searchBar = document.getElementById("search-bar");
if (aEvent.target.id == "miSearchModeFind") {
searchBar.setAttribute("autocompletesearchparam", "__PhoenixFindInPage");
searchBar.setAttribute("searchmode", "findinpage");
} else {
searchBar.setAttribute("autocompletesearchparam", "q");
searchBar.setAttribute("searchmode", "web");
}
searchBar.detachController();
searchBar.focus();
}
function handleSearchBarCommand(aEvent)
{
var searchBar = document.getElementById("search-bar");
// Save the current value in the form history
if (!gFormHistory)
gFormHistory = Components.classes["@mozilla.org/satchel/form-history;1"]
.getService(Components.interfaces.nsIFormHistory);
gFormHistory.addEntry(searchBar.getAttribute("autocompletesearchparam"), searchBar.value);
if (searchBar.getAttribute("searchmode") == "web") {
gURLBar.value = searchBar.searchValue;
BrowserLoadURL(aEvent);
} else {
quickFindInPage(searchBar.value);
}
}
function quickFindInPage(aValue)
{
var focusedWindow = document.commandDispatcher.focusedWindow;
if (!focusedWindow || focusedWindow == window)
focusedWindow = window._content;
var findInst = getBrowser().webBrowserFind;
var findInFrames = findInst.QueryInterface(Components.interfaces.nsIWebBrowserFindInFrames);
findInFrames.rootSearchFrame = _content;
findInFrames.currentSearchFrame = focusedWindow;
var findService = Components.classes["@mozilla.org/find/find_service;1"]
.getService(Components.interfaces.nsIFindService);
findInst.searchString = aValue;
findInst.matchCase = findService.matchCase;
findInst.wrapFind = true;
findInst.entireWord = findService.entireWord;
findInst.findBackwards = false;
findInst.findNext();
}
function updateToolbarStates(toolbarMenuElt)
{
if (!gHaveUpdatedToolbarState) {

Просмотреть файл

@ -227,7 +227,14 @@ Contributor(s):
<popup id="backMenu" position="after_start" onpopupshowing="return BrowserBackMenu(event);" oncommand="gotoHistoryIndex(event);"/>
<popup id="forwardMenu" position="after_start" onpopupshowing="return BrowserForwardMenu(event);" oncommand="gotoHistoryIndex(event);"/>
<tooltip id="aHTMLTooltip" onpopupshowing="return FillInHTMLTooltip(document.tooltipNode);"/>
<popup id="SearchBarPopup" position="after_start"
oncommand="return SearchBarPopupCommand(event);"
onpopupshowing="return SearchBarPopupShowing(event);">
<menuseparator/>
<menuitem id="miSearchModeFind" type="checkbox" label="&findOnCmd.label;" accesskey="&findOnCmd.accesskey;"/>
</popup>
<popup type="autocomplete" id="PopupAutoComplete"/>
<popup id="toolbar-context-menu">
@ -755,7 +762,16 @@ Contributor(s):
<toolbaritem id="search-container" align="center"
title="&searchItem.title;" class="chromeclass-location">
<textbox id="search-bar" flex="1"/>
<textbox id="search-bar" type="autocomplete" flex="1"
autocompletepopup="PopupAutoComplete"
autocompletesearch="form-history"
autocompletesearchparam="q"
searchmode="web"
tabscrolling="true"
ontextentered="return handleSearchBarCommand(param);"
persist="searchmode,searchparam">
<image id="search-proxy-button" popup="SearchBarPopup"/>
</textbox>
</toolbaritem>
<toolbaritem id="go-container" align="center" class="chromeclass-location">

Просмотреть файл

@ -0,0 +1,146 @@
<?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" extends="chrome://global/content/widgets/autocomplete.xml#autocomplete">
<implementation>
<constructor><![CDATA[
var pbi = this.mPrefs.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
if (pbi)
pbi.addObserver("browser.search", this.mPrefObserver, false);
]]></constructor>
<destructor><![CDATA[
var pbi = this.mPrefs.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
if (pbi)
pbi.removeObserver("browser.search", 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.search") == 0)
this.updateEngines();
}
});
]]></field>
<field name="enginesReady">false</field>
<field name="currentSearchId">""</field>
<field name="currentSearchURL">""</field>
<field name="currentSearchName">""</field>
<field name="currentSearchIcon">""</field>
<property name="searchValue" readonly="true">
<getter>
<![CDATA[
if (!this.enginesReady)
this.updateEngines();
const ISEARCH_CONTRACTID = "@mozilla.org/rdf/datasource;1?name=internetsearch";
const nsIInternetSearchService = Components.interfaces.nsIInternetSearchService;
var searchService = Components.classes[ISEARCH_CONTRACTID].getService(nsIInternetSearchService);
if (this.currentSearchURL)
return this.currentSearchURL;
return searchService.GetInternetSearchURL(this.currentSearchId, escape(this.value), 0, 0, {value:0});
]]>
</getter>
</property>
<method name="updateEngines">
<body><![CDATA[
var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"]
.getService(Components.interfaces.nsIRDFService);
try {
var ds = rdf.GetDataSource("rdf:internetsearch");
} catch (ex) {
// sometimes bad profiles cause this error, which horks the hold urlbar
return;
}
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.nsISupportsString).data;
} catch(ex) {
this.ensureDefaultEnginePrefs(rdf, ds);
defaultEngine = this.mPrefs.getComplexValue("browser.search.defaultengine",
Components.interfaces.nsISupportsString).data;
}
if (defaultEngine) {
if (ds) {
var res = rdf.GetResource(defaultEngine);
try {
this.currentSearchURL = this.readRDFString(ds, res, kNC_searchBarUrl);
} catch(ex) { }
this.currentSearchId = res.Value;
this.currentSearchName = this.readRDFString(ds, res, kNC_Name);
this.currentSearchIcon = this.readRDFString(ds, res, kNC_Icon);
}
}
this.enginesReady = 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-string;1"]
.createInstance(Components.interfaces.nsISupportsString);
str.data = engineRes.Value;
this.mPrefs.setComplexValue("browser.search.defaultengine",
Components.interfaces.nsISupportsString,
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>
</implementation>
</binding>
</bindings>

Просмотреть файл

@ -12,6 +12,7 @@ browser.jar:
content/browser/viewSourceOverlay.xul (content/viewSourceOverlay.xul)
content/browser/openLocation.xul (content/openLocation.xul)
content/browser/openLocation.js (content/openLocation.js)
content/browser/search.xml (content/search.xml)
classic.jar:
skin/classic/browser/browser.css (skin/browser.css)
@ -46,6 +47,7 @@ classic.jar:
skin/classic/browser/lock-mixed.gif (skin/lock-mixed.gif)
skin/classic/browser/lock-secure.gif (skin/lock-secure.gif)
skin/classic/browser/loading.gif (skin/loading.gif)
skin/classic/browser/search-bar.png (skin/search-bar.png)
en-US.jar:
locale/en-US/browser/contents.rdf (locale/contents.rdf)

Просмотреть файл

@ -613,6 +613,13 @@ toolbar[iconsize="small"] #history-button[disabled="true"] {
-moz-image-region: rect(0px 64px 16px 48px);
}
/* ::::: search-bar ::::: */
#search-proxy-button {
margin: 2px;
list-style-image: url("chrome://browser/skin/search-bar.png");
}
/* ::::: autocomplete ::::: */
.autocomplete-treebody:-moz-tree-cell-text(treecolAutoCompleteComment) {

Двоичные данные
browser/base/skin/search-bar.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 457 B

Просмотреть файл

@ -111,8 +111,8 @@
onget="var t = parseInt(this.getAttribute('timeout')); return t ? t : 50;"/>
<property name="searchParam"
onget="return this.getAttribute('searchparam');"
onset="this.setAttribute('searchparam', val); return val;"/>
onget="return this.getAttribute('autocompletesearchparam');"
onset="this.setAttribute('autocompletesearchparam', val); return val;"/>
<property name="searchCount" readonly="true"
onget="this.initSearchNames(); return this.mSearchNames.length;"/>
@ -297,7 +297,7 @@
if (!this.disableKeyNavigation) {
switch (aEvent.keyCode) {
case KeyEvent.DOM_VK_TAB:
if (this.tabScrolling && this.mPopupOpen)
if (this.tabScrolling && this.popup.mPopupOpen)
cancel = this.mController.handleKeyNavigation(aEvent.shiftKey ? IController.KEY_UP : IController.KEY_DOWN);
break;
case KeyEvent.DOM_VK_UP:
@ -330,7 +330,7 @@
cancel = this.mController.handleEnter();
break;
}
if (cancel) {
aEvent.stopPropagation();
aEvent.preventDefault();