Polish search results.

b=106127; r=morse; sr=hewitt; a=asa
This commit is contained in:
sgehani%netscape.com 2002-03-21 23:29:56 +00:00
parent 2dfed2e029
commit 974387c8cb
14 changed files with 342 additions and 133 deletions

View File

@ -40,17 +40,22 @@
/* class for text with a 'link' appearance */
.text-link
{
color : #666699;
color : blue;
text-decoration : underline;
cursor : pointer;
}
.text-link:hover
{
color : #333366;
cursor : pointer;
}
.text-link:hover:active
{
color : #990000;
}
color : red;
}
.text-link[visited="true"]
{
color : purple;
}

View File

@ -10,19 +10,6 @@
list-style-image : url("resource:/res/rdf/document.gif") ! important ;
}
.searchresult-cell:hover
{
color : blue;
text-decoration : underline;
cursor : pointer;
}
.searchresult-cell:hover:active
{
color : red;
text-decoration : underline;
}
.searchresult-item[selected="true"] > .searchresult
{
background-color : transparent;

View File

@ -45,12 +45,19 @@
/* ::::: hypertext links ::::: */
.text-link {
cursor: pointer;
color: #424F63;
color: blue;
text-decoration: underline;
}
.text-link:hover {
color: #1455D6;
cursor: pointer;
}
.text-link:hover:active {
color: red;
}
.text-link[visited="true"] {
color: purple;
}

View File

@ -59,7 +59,3 @@ treeitem[selected="true"] > .searchresult {
background-color: transparent;
}
.searchresult-cell:hover {
color: blue;
text-decoration: underline;
}

View File

@ -121,9 +121,6 @@
oncommand="BookmarksUtils.addBookmark(gContextMenu.linkURL(),
gContextMenu.linkText(),
undefined, true);"/>
<menuitem id="context-searchselect" class="menuitem-iconic"
oncommand="OpenSearch('internet', false, gContextMenu.searchSelected(), true);"/>
<menuseparator id="context-sep-bookmark"/>
<!-- Save ==================================== -->
<menuitem id="context-savepage"
@ -182,6 +179,10 @@
label="&metadataCmd.label;"
accesskey="&metadataCmd.accesskey;"
oncommand="gContextMenu.showMetadata();"/>
<menuseparator id="context-sep-search"/>
<!-- Search ================================== -->
<menuitem id="context-searchselect" class="menuitem-iconic"
oncommand="OpenSearch('internet', false, gContextMenu.searchSelected(), true);"/>
</popup>
</popupset>
</overlay>

View File

@ -161,7 +161,8 @@ nsContextMenu.prototype = {
// Use "Bookmark This Link" if on a link.
this.showItem( "context-bookmarkpage", !this.onLink );
this.showItem( "context-bookmarklink", this.onLink );
this.showItem( "context-searchselect", this.isTextSelected() );
this.setItemAttr( "context-searchselect", "disabled",
!this.isTextSelected() );
},
initClipboardItems : function () {
// Select All is always OK, unless in directory listing.
@ -636,26 +637,31 @@ nsContextMenu.prototype = {
isTextSelected : function() {
var result = false;
var selection = this.searchSelected();
if (selection != "") {
if (!gDefaultEngine)
gDefaultEngine = new nsDefaultEngine();
var searchSelect = document.getElementById('context-searchselect');
if (!gDefaultEngine)
gDefaultEngine = new nsDefaultEngine();
var searchSelect = document.getElementById('context-searchselect');
// format "Search for <selection>" string to show in menu
var searchSelectText = selection.toString();
var bundle = srGetStrBundle("chrome://communicator/locale/contentAreaCommands.properties");
var bundle = srGetStrBundle("chrome://communicator/locale/contentAreaCommands.properties");
var searchSelectText;
if (selection != "") {
searchSelectText = selection.toString();
if (searchSelectText.length > 15)
searchSelectText = searchSelectText.substr(0,15) + "...";
searchSelectText = bundle.formatStringFromName("searchText",
[gDefaultEngine.name, searchSelectText], 2);
searchSelect.setAttribute("label", searchSelectText);
// add icon for default engine we're gonna use to search
// (eliminates last icon if we can't find current engine's icon)
searchSelect.setAttribute("src", gDefaultEngine.icon);
result = true;
} else {
searchSelectText = bundle.GetStringFromName("searchUnknown");
}
// format "Search for <selection>" string to show in menu
searchSelectText = bundle.formatStringFromName("searchText",
[gDefaultEngine.name, searchSelectText], 2);
searchSelect.setAttribute("label", searchSelectText);
// add icon for default engine we're gonna use to search
// (eliminates last icon if we can't find current engine's icon)
searchSelect.setAttribute("src", gDefaultEngine.icon);
return result;
},

View File

@ -3,6 +3,7 @@
saveImageAs=Save Image (%S)...
saveImageAsNoFilename=Save Image...
searchText=Search %S for "%S"
searchUnknown=<select term>
SavePageTitle=Save Web Page
SaveImageTitle=Save Picture

View File

@ -11,6 +11,8 @@
<input name="q" user>
<input name="sourceid" value="mozilla-search">
<inputnext name="start" factor="20">
<inputprev name="start" factor="20">
<interpret
browserResultType="result"

View File

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
@ -45,7 +45,7 @@
#include "nsISupports.idl"
#include "nsIRDFDataSource.idl"
interface nsIUnicodeDecoder;
interface nsIUnicodeDecoder;
[scriptable, uuid(1222e6f0-a5e3-11d2-8b7c-00805f8a7db6)]
interface nsILocalSearchService : nsISupports
@ -55,40 +55,44 @@ interface nsILocalSearchService : nsISupports
[scriptable, uuid(6bd1d803-1c67-11d3-9820-ed1b357eb3c4)]
interface nsIInternetSearchService : nsISupports
{
string GetInternetSearchURL(in string searchEngineURI, in wstring searchStr);
void RememberLastSearchText(in wstring escapedSearchStr);
boolean FindInternetSearchResults(in string url);
void Stop();
void ClearResults(in boolean flushLastSearchRef);
void ClearResultSearchSites();
nsIRDFDataSource GetCategoryDataSource();
void AddSearchEngine(in string engineURL, in string iconURL,
in wstring suggestedTitle, in wstring suggestedCategory);
// constants set in the whichButtons out param of GetInternetSearchURL()
const unsigned short kHaveNext = 1;
const unsigned short kHavePrev = 2;
string GetInternetSearchURL(in string searchEngineURI, in wstring searchStr, in short direction, in unsigned short pageNumber, out unsigned short whichButtons);
void RememberLastSearchText(in wstring escapedSearchStr);
boolean FindInternetSearchResults(in string url);
void Stop();
void ClearResults(in boolean flushLastSearchRef);
void ClearResultSearchSites();
nsIRDFDataSource GetCategoryDataSource();
void AddSearchEngine(in string engineURL, in string iconURL,
in wstring suggestedTitle, in wstring suggestedCategory);
};
[noscript, uuid(ac0c0781-ab71-11d3-a652-b09b68feee44)]
interface nsIInternetSearchContext : nsISupports
{
// context types: WEB_SEARCH_CONTEXT=1, ENGINE_DOWNLOAD_CONTEXT, ICON_DOWNLOAD_CONTEXT };
const unsigned long WEB_SEARCH_CONTEXT = 1;
const unsigned long ENGINE_DOWNLOAD_CONTEXT = 2;
const unsigned long ICON_DOWNLOAD_CONTEXT = 3;
const unsigned long ENGINE_UPDATE_CONTEXT = 4;
const unsigned long ICON_UPDATE_CONTEXT = 5;
// context types: WEB_SEARCH_CONTEXT=1, ENGINE_DOWNLOAD_CONTEXT, ICON_DOWNLOAD_CONTEXT };
const unsigned long WEB_SEARCH_CONTEXT = 1;
const unsigned long ENGINE_DOWNLOAD_CONTEXT = 2;
const unsigned long ICON_DOWNLOAD_CONTEXT = 3;
const unsigned long ENGINE_UPDATE_CONTEXT = 4;
const unsigned long ICON_UPDATE_CONTEXT = 5;
// attributes
readonly attribute unsigned long ContextType;
// attributes
readonly attribute unsigned long ContextType;
// methods
nsIUnicodeDecoder GetUnicodeDecoder();
nsIRDFResource GetParent();
nsIRDFResource GetEngine();
void GetHintConst([shared] out wstring buffer);
void AppendBytes(in string buffer, in long numBytes);
void AppendUnicodeBytes(in wstring buffer, in long numUniBytes);
long GetBufferLength();
void GetBufferConst([shared] out wstring buffer);
void Truncate();
// methods
nsIUnicodeDecoder GetUnicodeDecoder();
nsIRDFResource GetParent();
nsIRDFResource GetEngine();
void GetHintConst([shared] out wstring buffer);
void AppendBytes(in string buffer, in long numBytes);
void AppendUnicodeBytes(in wstring buffer, in long numUniBytes);
long GetBufferLength();
void GetBufferConst([shared] out wstring buffer);
void Truncate();
};
%{C++

View File

@ -32,4 +32,8 @@
<!ENTITY stop.button.label "Stop">
<!ENTITY customize.menuitem.label "Edit Categories ...">
<!ENTITY savesearch.button.label "Bookmark this Search">
<!ENTITY next.button.label "Next">
<!ENTITY previous.button.label "Previous">
<!ENTITY next.button.tooltip "Show next search results">
<!ENTITY previous.button.tooltip "Show previous search results">

View File

@ -345,7 +345,7 @@ function AskChangeDefaultEngine(aSelectedEngine)
var checkbox = {value:0};
change = promptSvc.confirmCheck(window, title, changeEngineMsg,
dontAskAgainMsg, checkbox);
dontAskAgainMsg, checkbox);
// store "don't ask again" pref from checkbox value (if changed)
debug("dontAskAgain: " + dontAskAgain);
@ -357,6 +357,18 @@ function AskChangeDefaultEngine(aSelectedEngine)
// if confirmed true, i.e., change default engine, then set pref
if (change)
nsPreferences.setUnicharPref(kDefaultEnginePref, aSelectedEngine.value);
disableNavButtons();
}
function disableNavButtons()
{
var nextButton = document.getElementById("next-results");
var prevButton = document.getElementById("prev-results");
if (nextButton && nextButton.getAttribute("disabled") != "true")
nextButton.setAttribute("disabled", "true");
if (prevButton && prevButton.getAttribute("disabled") != "true")
prevButton.setAttribute("disabled", "true");
}
function ensureSearchPref()
@ -829,6 +841,10 @@ function sidebarOpenURL(treeitem)
}
} catch (ex) {
}
// mark result as visited
treeitem.firstChild.firstChild.setAttribute("visited", "true");
loadURLInContent(id);
}
@ -863,9 +879,13 @@ function OpenSearch(aSearchStr, engineURIs)
// look up the correct search URL format for the given engine
try {
var searchURL = searchDS.GetInternetSearchURL(searchEngineURI, escapedSearchStr);
var whichButtons = new Object;
whichButtons.value = 0;
var searchURL = searchDS.GetInternetSearchURL(searchEngineURI, escapedSearchStr, 0, 0, whichButtons);
doNavButtonEnabling(whichButtons.value, searchDS, 0);
}
catch (ex) {
debug("Exception when calling GetInternetSearchURL: " + ex);
searchURL = "";
}
@ -889,7 +909,9 @@ function OpenSearch(aSearchStr, engineURIs)
loadURLInContent("chrome://communicator/content/search/internetresults.xul?" + escape(searchURL));
}
}
catch (ex) {}
catch (ex) {
debug("Exception: " + ex);
}
setTimeout("checkSearchProgress()", 1000);
}
@ -919,9 +941,6 @@ function switchTab(aPageIndex)
if (target)
haveSearchRef = true;
}
var saveQueryButton = document.getElementById("saveQueryButton");
saveQueryButton.disabled = !haveSearchRef;
}
function saveSearch()
@ -978,6 +997,78 @@ function saveSearch()
bmks.addBookmarkImmediately(lastSearchURI, searchTitle, bmks.BOOKMARK_SEARCH_TYPE, null);
}
var gPageNumber = 0;
/**
* showMoreResults
*
* Run a query to show the next/previous page of search results for the
* current search term.
*
* @param direction : -1 => previous
* 1 => next
*/
function showMoreResults(direction)
{
// XXX check if we are in basic search mode
// get search engine
var engine = document.getElementById("basicEngineMenu").selectedItem;
var engineURI = engine.id;
// get search term
var searchTerm = document.getElementById("sidebar-search-text").value;
searchTerm = escape(searchTerm);
// change page number
if (direction > 0)
++gPageNumber;
else
--gPageNumber;
// get qualified URL
var searchService = Components.classes[ISEARCH_CONTRACTID].
getService(nsIInternetSearchService);
var whichButtons = new Object;
whichButtons.value = 0;
var searchURL = searchService.GetInternetSearchURL(engineURI, searchTerm,
direction, gPageNumber, whichButtons);
doNavButtonEnabling(whichButtons.value, searchService, gPageNumber);
// load URL in navigator
loadURLInContent(searchURL);
}
function doNavButtonEnabling(whichButtons, searchService, pageNumber)
{
var nextButton = document.getElementById("next-results");
var nextDisabled = nextButton.getAttribute("disabled");
var prevButton = document.getElementById("prev-results");
var prevDisabled = prevButton.getAttribute("disabled");
if (whichButtons & searchService.kHaveNext)
{
if (nextDisabled)
nextButton.removeAttribute("disabled");
}
else
{
if (!nextDisabled)
nextButton.setAttribute("disabled", "true");
}
if ((pageNumber > 0) && (whichButtons & searchService.kHavePrev))
{
if (prevDisabled)
prevButton.removeAttribute("disabled");
}
else
{
if (!prevDisabled)
prevButton.setAttribute("disabled", "true");
}
}
function doCustomize()
{
//Switching from Edit Categories back to All Engines then launching customize window
@ -1041,6 +1132,34 @@ function getItemNode(aNode,nodeName)
return node ? node : null;
}
function getArcValueForID(aArc, aID)
{
var val = null;
try
{
var ds = document.getElementById("Tree").database;
if (ds)
{
var rdf = Components.classes[RDFSERVICE_CONTRACTID].
getService(nsIRDFService);
var src = rdf.GetResource(aID, true);
var prop = rdf.GetResource(
"http://home.netscape.com/NC-rdf#"+aArc, true);
val = ds.GetTarget(src, prop, true);
if (val)
val = val.QueryInterface(nsIRDFLiteral).Value;
}
}
catch (ex)
{
dump("Exception: no value for " + aArc + "!\t" + ex + "\n");
val = null;
}
return val;
}
//Fill in tooltip in teh search results panel
function FillInDescTooltip(tipElement)
{
@ -1052,48 +1171,61 @@ function FillInDescTooltip(tipElement)
var nodeTreeitem = getItemNode(tipElement, "treeitem");
//Get the Name of the tree cell for first item in the tooltip
var nodeLabel = nodeTreeCell.getAttribute("label");
var nodeLabel = nodeTreeCell.childNodes.item(1).getAttribute("value");
var nodeID = nodeTreeitem.id;
//Query RDF to get URL of tree item
if (nodeID)
try {
var ds = document.getElementById("Tree").database;
if (ds) {
var rdf = Components.classes[RDFSERVICE_CONTRACTID].getService(nsIRDFService);
var src = rdf.GetResource(nodeID, true);
var prop = rdf.GetResource("http://home.netscape.com/NC-rdf#URL", true);
var url = ds.GetTarget(src, prop, true);
if (url)
url = url.QueryInterface(nsIRDFLiteral).Value;
}
} catch (ex) {
}
var url = getArcValueForID("URL", nodeID);
//Fill in the the text nodes
//collapse them if there is not a node
if (nodeLabel || url) {
var tooltipTitle = document.getElementById("titleText");
var tooltipUrl = document.getElementById("urlText");
if (nodeLabel) {
if (tooltipTitle.getAttribute("hidden") == "true")
tooltipTitle.removeAttribute("hidden");
tooltipTitle.setAttribute("value",nodeLabel);
}
else {
tooltipTitle.setAttribute("hidden", "true");
}
if (url) {
if (tooltipUrl.getAttribute("hidden") == "true")
tooltipUrl.removeAttribute("hidden");
if (url.length > 100)
url = url.substr(0,100) + "...";
tooltipUrl.setAttribute("value",url);
}
else {
tooltipUrl.setAttribute("hidden", "true");
}
if (nodeLabel || url) {
var tooltipTitle = document.getElementById("titleText");
var tooltipUrl = document.getElementById("urlText");
if (nodeLabel) {
if (tooltipTitle.getAttribute("hidden") == "true")
tooltipTitle.removeAttribute("hidden");
tooltipTitle.setAttribute("value",nodeLabel);
}
else {
tooltipTitle.setAttribute("hidden", "true");
}
if (url) {
if (tooltipUrl.getAttribute("hidden") == "true")
tooltipUrl.removeAttribute("hidden");
if (url.length > 100)
url = url.substr(0,100) + "...";
tooltipUrl.setAttribute("value",url);
}
else {
tooltipUrl.setAttribute("hidden", "true");
}
retValue = true;
}
return retValue;
}
var nsResultDNDObserver =
{
onDragStart: function(aEvent, aXferData, aDragAction)
{
var node = getItemNode(aEvent.target, "treeitem");
var URL = getArcValueForID("URL", node.id);
var title = getArcValueForID("Name", node.id);
var htmlString = "<a href=\"" + URL + "\">" + title + "</a>";
var urlString = URL + "\n" + title;
aXferData.data = new TransferData();
aXferData.data.addDataForFlavour("text/x-moz-url", URL);
aXferData.data.addDataForFlavour("text/unicode", urlString);
aXferData.data.addDataForFlavour("text/html", htmlString);
}
};
function HandleResultDragGesture(aEvent)
{
nsDragAndDrop.startDrag(aEvent, nsResultDNDObserver);
return true;
}

View File

@ -34,6 +34,9 @@
<script type="application/x-javascript" src="chrome://global/content/nsUserSettings.js"/>
<script type="application/x-javascript" src="chrome://global/content/nsJSComponentManager.js"/>
<script type="application/x-javascript" src="chrome://global/content/nsDragAndDrop.js"/>
<script type="application/x-javascript" src="chrome://global/content/nsTransferable.js"/>
<script type="application/x-javascript" src="chrome://global/content/nsJSSupportsUtils.js"/>
<script type="application/x-javascript" src="chrome://global/content/strres.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/search/search-panel.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/search/shared.js"/>
@ -123,8 +126,8 @@
resource2="http://home.netscape.com/NC-rdf#Name"
sortDirection="ascending" sortActive="true"
flex="1" datasources="rdf:internetsearch"
onclick="if (event.button == 0 &amp;&amp; event.target.localName == 'treecell')
sidebarOpenURL(event.target.parentNode.parentNode);"
onclick="if (event.button == 0 &amp;&amp; event.target.localName == 'treecell') sidebarOpenURL(event.target.parentNode.parentNode);"
ondraggesture="if (event.target.localName == 'treecell') HandleResultDragGesture(event);"
style="-moz-user-focus:ignore !important;">
<template>
@ -148,10 +151,11 @@
searchtype="rdf:http://home.netscape.com/NC-rdf#SearchType"
type="rdf:http://www.w3.org/1999/02/22-rdf-syntax-ns#type">
<treerow class="searchresult">
<treecell class="treecell-iconic searchresult-cell"
src="rdf:http://home.netscape.com/NC-rdf#Icon"
label="rdf:http://home.netscape.com/NC-rdf#Name"
tooltip="descTooltip"/>
<treecell flex="0" class="text-link" tooltip="descTooltip">
<image class="tree-cell-icon"
src="rdf:http://home.netscape.com/NC-rdf#Icon"/>
<label value="rdf:http://home.netscape.com/NC-rdf#Name"/>
</treecell>
</treerow>
</treeitem>
</treechildren>
@ -177,10 +181,13 @@
</tree>
<hbox>
<spacer flex="1" />
<button id="saveQueryButton"
label="&savesearch.button.label;" oncommand="return saveSearch();"/>
<spacer flex="1" />
<button id="prev-results" label="&previous.button.label;"
tooltiptext="&previous.button.tooltip;"
oncommand="return showMoreResults(-1);" disabled="true"/>
<spacer flex="1"/>
<button id="next-results" label="&next.button.label;"
tooltiptext="&next.button.tooltip;"
oncommand="return showMoreResults(1);" disabled="true"/>
</hbox>
</vbox>

View File

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-file-style: "stroustrup" -*- */
/* -*- Mode: C++; tab-width: /; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
@ -2495,7 +2495,8 @@ InternetSearchDataSource::saveContents(nsIChannel* channel, nsIInternetSearchCon
NS_IMETHODIMP
InternetSearchDataSource::GetInternetSearchURL(const char *searchEngineURI,
const PRUnichar *searchStr, char **resultURL)
const PRUnichar *searchStr, PRInt16 direction, PRUint16 pageNumber,
PRUint16 *whichButtons, char **resultURL)
{
if (!resultURL) return(NS_ERROR_NULL_POINTER);
*resultURL = nsnull;
@ -2579,7 +2580,7 @@ InternetSearchDataSource::GetInternetSearchURL(const char *searchEngineURI,
return(rv);
if (NS_FAILED(rv = GetData(dataUni, "search", 0, "method", method)))
return(rv);
if (NS_FAILED(rv = GetInputs(dataUni, userVar, text, input)))
if (NS_FAILED(rv = GetInputs(dataUni, userVar, text, input, direction, pageNumber, whichButtons)))
return(rv);
if (input.Length() < 1) return(NS_ERROR_UNEXPECTED);
@ -2711,7 +2712,7 @@ InternetSearchDataSource::FindInternetSearchResults(const char *url, PRBool *sea
// look for query option which is the string the user is searching for
nsAutoString userVar, inputUnused;
if (NS_FAILED(rv = GetInputs(dataUni, userVar, nsAutoString(), inputUnused))) return(rv);
if (NS_FAILED(rv = GetInputs(dataUni, userVar, nsAutoString(), inputUnused, 0, 0, 0))) return(rv);
if (userVar.Length() < 1) return(NS_RDF_NO_VALUE);
nsAutoString queryStr;
@ -3690,7 +3691,7 @@ InternetSearchDataSource::DoSearch(nsIRDFResource *source, nsIRDFResource *engin
}
else if (methodStr.EqualsIgnoreCase("get"))
{
if (NS_FAILED(rv = GetInputs(dataUni, userVar, textTemp, input))) return(rv);
if (NS_FAILED(rv = GetInputs(dataUni, userVar, textTemp, input, 0, 0, 0))) return(rv);
if (input.Length() < 1) return(NS_ERROR_UNEXPECTED);
// HTTP Get method support
@ -4332,12 +4333,13 @@ InternetSearchDataSource::GetData(const PRUnichar *dataUni, const char *sectionT
nsresult
InternetSearchDataSource::GetInputs(const PRUnichar *dataUni, nsString &userVar,
const nsString &text, nsString &input)
const nsString &text, nsString &input, PRInt16 direction, PRUint16 pageNumber, PRUint16 *whichButtons)
{
nsString buffer(dataUni);
nsresult rv = NS_OK;
PRBool inSection = PR_FALSE;
PRBool inDirInput; // directional input: "inputnext" or "inputprev"
while(buffer.Length() > 0)
{
@ -4372,7 +4374,28 @@ InternetSearchDataSource::GetInputs(const PRUnichar *dataUni, nsString &userVar,
// look for inputs
if (line.Find("input", PR_TRUE) == 0)
{
line.Cut(0, 6);
line.Cut(0, 5);
// look for "inputnext" or "inputprev"
inDirInput = PR_FALSE;
if (line.Find("next", PR_TRUE) == 0)
{
inDirInput = PR_TRUE;
if (whichButtons)
*whichButtons |= kHaveNext;
}
if (line.Find("prev", PR_TRUE) == 0)
{
inDirInput = PR_TRUE;
if (whichButtons)
*whichButtons |= kHavePrev;
}
if (inDirInput)
line.Cut(0, 4);
line.Trim(" \t");
// first look for name attribute
@ -4417,7 +4440,11 @@ InternetSearchDataSource::GetInputs(const PRUnichar *dataUni, nsString &userVar,
// first look for value attribute
nsAutoString valueAttrib;
PRInt32 valueOffset = line.Find("value", PR_TRUE);
PRInt32 valueOffset;
if (!inDirInput)
valueOffset = line.Find("value", PR_TRUE);
else
valueOffset = line.Find("factor", PR_TRUE);
if (valueOffset >= 0)
{
PRInt32 equal = line.FindChar(PRUnichar('='), valueOffset);
@ -4464,14 +4491,43 @@ InternetSearchDataSource::GetInputs(const PRUnichar *dataUni, nsString &userVar,
input.Append(NS_LITERAL_STRING("&"));
}
input += nameAttrib;
input.Append(NS_LITERAL_STRING("="));
input.Append(NS_LITERAL_STRING("="));
if (!inDirInput)
input += valueAttrib;
else
input.AppendInt( computeIndex(valueAttrib, pageNumber, direction) );
}
}
}
return(rv);
}
PRInt32
InternetSearchDataSource::computeIndex(nsAutoString &factor,
PRUint16 page, PRInt16 direction)
{
// XXX get page
PRInt32 errorCode, index = 0;
PRInt32 factorInt = factor.ToInteger(&errorCode);
if (NS_SUCCEEDED(errorCode))
{
// if factor is garbled assume 10
if (factorInt <= 0)
factorInt = 10;
if (direction < 0)
{
// don't pass back a negative index!
if (0 <= (page - 1))
--page;
}
index = factorInt * page;
}
return index;
}
nsresult

View File

@ -155,7 +155,8 @@ friend int PR_CALLBACK searchModePrefCallback(const char *pref, void *aClosur
nsresult ReadFileContents(const nsFileSpec &baseFilename, nsString & sourceContents);
nsresult GetData(const PRUnichar *data, const char *sectionToFind, PRUint32 sectionNum, const char *attribToFind, nsString &value);
nsresult GetNumInterpretSections(const PRUnichar *data, PRUint32 &numInterpretSections);
nsresult GetInputs(const PRUnichar *data, nsString &userVar, const nsString &text, nsString &input);
nsresult GetInputs(const PRUnichar *data, nsString &userVar, const nsString &text, nsString &input, PRInt16 direction, PRUint16 pageNumber, PRUint16 *whichButtons);
PRInt32 computeIndex(nsAutoString &factor, PRUint16 page, PRInt16 direction);
nsresult GetURL(nsIRDFResource *source, nsIRDFLiteral** aResult);
nsresult validateEngineNow(nsIRDFResource *engine);
nsresult webSearchFinalize(nsIChannel *channel, nsIInternetSearchContext *context);