Bug 919340 - Always draw outline around links when using quickfind. r=mikedeboer

This commit is contained in:
Tom Schuster 2013-09-26 11:21:02 -04:00
parent cdbba9914a
commit 32023e2568
2 changed files with 46 additions and 27 deletions

View File

@ -44,7 +44,7 @@
}
this.findbar.onFindAgainCommand(aEvent.shiftKey);
} else if (this.findbar._findMode == this.findbar.FIND_LINKS) {
} else {
this.findbar._finishFAYT(aEvent);
}
]]></body>
@ -870,7 +870,8 @@
this._updateCaseSensitivity(val);
this.browser.finder.fastFind(val, this._findMode == this.FIND_LINKS);
this.browser.finder.fastFind(val, this._findMode == this.FIND_LINKS,
this._findMode != this.FIND_NORMAL);
}
if (this._findMode != this.FIND_NORMAL)
@ -923,7 +924,8 @@
<parameter name="aFindPrevious"/>
<body><![CDATA[
this.browser.finder.findAgain(aFindPrevious,
this._findMode == this.FIND_LINKS);
this._findMode == this.FIND_LINKS,
this._findMode != this.FIND_NORMAL);
]]></body>
</method>

View File

@ -18,7 +18,6 @@ function Finder(docShell) {
this._docShell = docShell;
this._listeners = [];
this._previousLink = null;
this._drewOutline = false;
this._searchString = null;
docShell.QueryInterface(Ci.nsIInterfaceRequestor)
@ -36,12 +35,12 @@ Finder.prototype = {
this._listeners = this._listeners.filter(l => l != aListener);
},
_notify: function (aResult, aFindBackwards, aLinksOnly) {
this._outlineLink(aLinksOnly);
_notify: function (aResult, aFindBackwards, aDrawOutline) {
this._outlineLink(aDrawOutline);
let foundLink = this._fastFind.foundLink;
let linkURL = null;
if (aLinksOnly && foundLink) {
if (foundLink) {
let docCharset = null;
let ownerDoc = foundLink.ownerDocument;
if (ownerDoc)
@ -68,14 +67,30 @@ Finder.prototype = {
this._fastFind.caseSensitive = aSensitive;
},
fastFind: function (aSearchString, aLinksOnly) {
/**
* Used for normal search operations, highlights the first match.
*
* @param aSearchString String to search for.
* @param aLinksOnly Only consider nodes that are links for the search.
* @param aDrawOutline Puts an outline around matched links.
*/
fastFind: function (aSearchString, aLinksOnly, aDrawOutline) {
let result = this._fastFind.find(aSearchString, aLinksOnly);
this._notify(result, false, aLinksOnly);
this._notify(result, false, aDrawOutline);
},
findAgain: function (aFindBackwards, aLinksOnly) {
/**
* Repeat the previous search. Should only be called after a previous
* call to Finder.fastFind.
*
* @param aFindBackwards Controls the search direction:
* true: before current match, false: after current match.
* @param aLinksOnly Only consider nodes that are links for the search.
* @param aDrawOutline Puts an outline around matched links.
*/
findAgain: function (aFindBackwards, aLinksOnly, aDrawOutline) {
let result = this._fastFind.findAgain(aFindBackwards, aLinksOnly);
this._notify(result, aFindBackwards, aLinksOnly);
this._notify(result, aFindBackwards, aDrawOutline);
},
highlight: function (aHighlight, aWord) {
@ -93,11 +108,7 @@ Finder.prototype = {
fastFind.collapseSelection();
fastFind.setSelectionModeAndRepaint(Ci.nsISelectionController.SELECTION_ON);
// We also drew our own outline, remove that as well.
if (this._previousLink && this._drewOutline) {
this._previousLink.style.outline = this._tmpOutline;
this._previousLink.style.outlineOffset = this._tmpOutlineOffset;
}
this._restoreOriginalOutline();
},
focusContent: function() {
@ -150,20 +161,17 @@ Finder.prototype = {
return this._docShell.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow);
},
_outlineLink: function (aLinksOnly) {
_outlineLink: function (aDrawOutline) {
let foundLink = this._fastFind.foundLink;
if (foundLink == this._previousLink)
// Optimization: We are drawing outlines and we matched
// the same link before, so don't duplicate work.
if (foundLink == this._previousLink && aDrawOutline)
return;
if (this._previousLink && this._drewOutline) {
// restore original outline
this._previousLink.style.outline = this._tmpOutline;
this._previousLink.style.outlineOffset = this._tmpOutlineOffset;
}
this._restoreOriginalOutline();
this._drewOutline = (foundLink && aLinksOnly);
if (this._drewOutline) {
if (foundLink && aDrawOutline) {
// Backup original outline
this._tmpOutline = foundLink.style.outline;
this._tmpOutlineOffset = foundLink.style.outlineOffset;
@ -175,9 +183,18 @@ Finder.prototype = {
// Don't set the outline-color, we should always use initial value.
foundLink.style.outline = "1px dotted";
foundLink.style.outlineOffset = "0";
}
this._previousLink = foundLink;
this._previousLink = foundLink;
}
},
_restoreOriginalOutline: function () {
// Removes the outline around the last found link.
if (this._previousLink) {
this._previousLink.style.outline = this._tmpOutline;
this._previousLink.style.outlineOffset = this._tmpOutlineOffset;
this._previousLink = null;
}
},
_highlight: function (aHighlight, aWord, aWindow) {