Bug 348298: Clean up Find Bar code, patch 1.

r=masayuki
This commit is contained in:
pkasting%google.com 2006-08-18 20:26:23 +00:00
parent 8f6e411ffd
commit 0a0053c799
8 changed files with 30 additions and 87 deletions

View File

@ -144,8 +144,8 @@
<command id="View:PageInfo" oncommand="BrowserPageInfo();"/>
<command id="View:FullScreen" oncommand="BrowserFullScreen();"/>
<command id="cmd_find" oncommand="gFindBar.onFindCmd();" observes="isImage"/>
<command id="cmd_findAgain" oncommand="gFindBar.onFindAgainCmd();" observes="isImage"/>
<command id="cmd_findPrevious" oncommand="gFindBar.onFindPreviousCmd();" observes="isImage"/>
<command id="cmd_findAgain" oncommand="gFindBar.onFindAgainCmd(false);" observes="isImage"/>
<command id="cmd_findPrevious" oncommand="gFindBar.onFindAgainCmd(true);" observes="isImage"/>
#ifdef MOZ_PLACES
<command id="Browser:AddBookmarkAs"
oncommand="PlacesCommandHook.bookmarkCurrentPage();"/>

View File

@ -1500,10 +1500,7 @@ function MsgFind()
}
function MsgFindAgain(reverse)
{
if (reverse)
gFindBar.onFindPreviousCmd();
else
gFindBar.onFindAgainCmd();
gFindBar.onFindAgainCmd(reverse);
}
function MsgFilters(emailAddress, folder)

View File

@ -103,8 +103,8 @@
<command id="cmd_textZoomReduce" oncommand="ZoomManager.prototype.getInstance().reduce();"/>
<command id="cmd_textZoomEnlarge" oncommand="ZoomManager.prototype.getInstance().enlarge();"/>
<command id="cmd_find" oncommand="gFindBar.onFindCmd();"/>
<command id="cmd_findAgain" oncommand="gFindBar.onFindAgainCmd();"/>
<command id="cmd_findPrevious" oncommand="gFindBar.onFindPreviousCmd();"/>
<command id="cmd_findAgain" oncommand="gFindBar.onFindAgainCmd(false);"/>
<command id="cmd_findPrevious" oncommand="gFindBar.onFindAgainCmd(true);"/>
<command id="cmd_copy" oncommand="goDoCommand('cmd_copy')" disabled="true"/>
<command id="cmd_selectAll" oncommand="goDoCommand('cmd_selectAll')"/>
</commandset>

View File

@ -203,9 +203,9 @@ var gFindBar = {
// We have to update the status because we might still have the status
// of another tab
if (this.highlightDoc('yellow', 'black', word))
this.updateStatus(Components.interfaces.nsITypeAheadFind.FIND_FOUND, false);
this.updateStatus(Components.interfaces.nsITypeAheadFind.FIND_FOUND);
else
this.updateStatus(Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND, false);
this.updateStatus(Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND);
} else {
this.highlightDoc(null, null, null);
this.mLastHighlightString = null;
@ -444,7 +444,7 @@ var gFindBar = {
var findField = document.getElementById("find-field");
this.setCaseSensitivity(findField.value);
this.updateStatus(Components.interfaces.nsITypeAheadFind.FIND_FOUND, false);
this.updateStatus(Components.interfaces.nsITypeAheadFind.FIND_FOUND);
return true;
}
@ -730,7 +730,7 @@ var gFindBar = {
if (autostartFAYT)
this.fireKeypressEvent(findField.inputField, evt);
else
this.updateStatus(Components.interfaces.nsITypeAheadFind.FIND_FOUND, false);
this.updateStatus(Components.interfaces.nsITypeAheadFind.FIND_FOUND);
evt.preventDefault();
}
},
@ -752,10 +752,7 @@ var gFindBar = {
return;
}
if (evt.shiftKey)
this.findPrevious();
else
this.findNext();
this.findAgain(evt.shiftKey);
}
else {
if (this.mFoundLink) {
@ -863,7 +860,7 @@ var gFindBar = {
var fastFind = getBrowser().fastFind;
var res = fastFind.find(val, this.mFindMode == FIND_LINKS, this.mHasFocus);
this.updateFoundLink(res);
this.updateStatus(res, true);
this.updateStatus(res, false);
if (this.mFindMode != FIND_NORMAL)
this.setFindCloseTimeout();
@ -905,7 +902,7 @@ var gFindBar = {
this.focusFindBar();
},
onFindAgainCmd: function ()
onFindAgainCmd: function (aFindPrevious)
{
var findString = getBrowser().findString;
if (!findString) {
@ -913,7 +910,7 @@ var gFindBar = {
return;
}
var res = this.findNext();
var res = this.findAgain(aFindPrevious);
if (res == Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND) {
try {
var opened = this.openFindBar(this.mUsingMinimalUI);
@ -926,33 +923,7 @@ var gFindBar = {
if (this.mFindMode != FIND_NORMAL)
this.setFindCloseTimeout();
this.updateStatus(res, true);
}
}
},
onFindPreviousCmd: function ()
{
var findString = getBrowser().findString;
if (!findString) {
this.onFindCmd();
return;
}
var res = this.findPrevious();
if (res == Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND) {
try {
var opened = this.openFindBar(this.mUsingMinimalUI);
}
catch (e) {
}
if (opened) {
this.focusFindBar();
this.selectFindBar();
if (this.mFindMode != FIND_NORMAL)
this.setFindCloseTimeout();
this.updateStatus(res, false);
this.updateStatus(res, aFindPrevious);
}
}
},
@ -974,12 +945,12 @@ var gFindBar = {
return !findBar.hidden;
},
findNext: function ()
findAgain: function (aFindPrevious)
{
var fastFind = getBrowser().fastFind;
var res = fastFind.findNext(this.mHasFocus);
var res = fastFind.findAgain(aFindPrevious, this.mHasFocus);
this.updateFoundLink(res);
this.updateStatus(res, true);
this.updateStatus(res, aFindPrevious);
if (this.mFindMode != FIND_NORMAL && this.isFindBarVisible())
this.setFindCloseTimeout();
@ -987,20 +958,7 @@ var gFindBar = {
return res;
},
findPrevious: function ()
{
var fastFind = getBrowser().fastFind;
var res = fastFind.findPrevious(this.mHasFocus);
this.updateFoundLink(res);
this.updateStatus(res, false);
if (this.mFindMode != FIND_NORMAL && this.isFindBarVisible())
this.setFindCloseTimeout();
return res;
},
updateStatus: function (res, findNext)
updateStatus: function (res, aFindPrevious)
{
var findBar = document.getElementById("FindToolbar");
var field = document.getElementById("find-field");
@ -1010,7 +968,7 @@ var gFindBar = {
case Components.interfaces.nsITypeAheadFind.FIND_WRAPPED:
statusIcon.setAttribute("status", "wrapped");
statusText.value =
findNext ? this.mWrappedToTopStr : this.mWrappedToBottomStr;
aFindPrevious ? this.mWrappedToBottomStr : this.mWrappedToTopStr;
break;
case Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND:
statusIcon.setAttribute("status", "notfound");

View File

@ -51,7 +51,7 @@ interface nsIDocShell;
/****************************** nsTypeAheadFind ******************************/
[scriptable, uuid(c67aa119-fe47-4d1a-9a9b-485728f9adbe)]
[scriptable, uuid(e6a9966a-5fc8-41a4-9d9d-9c15e9664c45)]
interface nsITypeAheadFind : nsISupports
{
/****************************** Initializer ******************************/
@ -69,11 +69,8 @@ interface nsITypeAheadFind : nsISupports
* has focus. */
unsigned short find(in AString aSearchString, in boolean aLinksOnly, in boolean aHasFocus);
/* Find next match in the page. */
unsigned short findNext(in boolean aHasFocus);
/* Find previous match in the page. */
unsigned short findPrevious(in boolean aHasFocus);
/* Find another match in the page. */
unsigned short findAgain(in boolean findBackwards, in boolean aHasFocus);
/**************************** Helper functions ***************************/

View File

@ -869,23 +869,14 @@ nsTypeAheadFind::RangeStartsInsideLink(nsIDOMRange *aRange,
}
NS_IMETHODIMP
nsTypeAheadFind::FindPrevious(PRBool aHasFocus, PRUint16* aResult)
nsTypeAheadFind::FindAgain(PRBool aFindBackwards, PRBool aHasFocus,
PRUint16* aResult)
/* Find another match in the page. */
{
*aResult = FIND_NOTFOUND;
if (!mTypeAheadBuffer.IsEmpty())
FindItNow(nsnull, mLinksOnly, PR_FALSE, PR_TRUE, aHasFocus, aResult);
return NS_OK;
}
NS_IMETHODIMP
nsTypeAheadFind::FindNext(PRBool aHasFocus, PRUint16* aResult)
{
*aResult = FIND_NOTFOUND;
if (!mTypeAheadBuffer.IsEmpty())
FindItNow(nsnull, mLinksOnly, PR_FALSE, PR_FALSE, aHasFocus, aResult);
FindItNow(nsnull, mLinksOnly, PR_FALSE, aFindBackwards, aHasFocus, aResult);
return NS_OK;
}

View File

@ -89,8 +89,8 @@
<command id="cmd_close" oncommand="window.close();"/>
<commandset id="editMenuCommands"/>
<command id="cmd_find" oncommand="gFindBar.onFindCmd();"/>
<command id="cmd_findAgain" oncommand="gFindBar.onFindAgainCmd();"/>
<command id="cmd_findPrevious" oncommand="gFindBar.onFindPreviousCmd();"/>
<command id="cmd_findAgain" oncommand="gFindBar.onFindAgainCmd(false);"/>
<command id="cmd_findPrevious" oncommand="gFindBar.onFindAgainCmd(true);"/>
<command id="cmd_goToLine" oncommand="ViewSourceGoToLine();" disabled="true"/>
<command id="cmd_highlightSyntax" oncommand="highlightSyntax();"/>
<command id="cmd_wrapLongLines" oncommand="wrapLongLines()"/>

View File

@ -88,8 +88,8 @@
<command id="cmd_close" oncommand="window.close();"/>
<commandset id="editMenuCommands"/>
<command id="cmd_find" oncommand="gFindBar.onFindCmd();"/>
<command id="cmd_findAgain" oncommand="gFindBar.onFindAgainCmd();"/>
<command id="cmd_findPrevious" oncommand="gFindBar.onFindPreviousCmd();"/>
<command id="cmd_findAgain" oncommand="gFindBar.onFindAgainCmd(false);"/>
<command id="cmd_findPrevious" oncommand="gFindBar.onFindAgainCmd(true);"/>
<command id="cmd_reload" oncommand="ViewSourceReload();"/>
<command id="cmd_goToLine" oncommand="ViewSourceGoToLine();" disabled="true"/>
<command id="cmd_highlightSyntax" oncommand="highlightSyntax();"/>