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 52d857e002
commit 0b09fb0494
2 changed files with 46 additions and 27 deletions

View File

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

View File

@ -18,7 +18,6 @@ function Finder(docShell) {
this._docShell = docShell; this._docShell = docShell;
this._listeners = []; this._listeners = [];
this._previousLink = null; this._previousLink = null;
this._drewOutline = false;
this._searchString = null; this._searchString = null;
docShell.QueryInterface(Ci.nsIInterfaceRequestor) docShell.QueryInterface(Ci.nsIInterfaceRequestor)
@ -36,12 +35,12 @@ Finder.prototype = {
this._listeners = this._listeners.filter(l => l != aListener); this._listeners = this._listeners.filter(l => l != aListener);
}, },
_notify: function (aResult, aFindBackwards, aLinksOnly) { _notify: function (aResult, aFindBackwards, aDrawOutline) {
this._outlineLink(aLinksOnly); this._outlineLink(aDrawOutline);
let foundLink = this._fastFind.foundLink; let foundLink = this._fastFind.foundLink;
let linkURL = null; let linkURL = null;
if (aLinksOnly && foundLink) { if (foundLink) {
let docCharset = null; let docCharset = null;
let ownerDoc = foundLink.ownerDocument; let ownerDoc = foundLink.ownerDocument;
if (ownerDoc) if (ownerDoc)
@ -68,14 +67,30 @@ Finder.prototype = {
this._fastFind.caseSensitive = aSensitive; 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); 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); let result = this._fastFind.findAgain(aFindBackwards, aLinksOnly);
this._notify(result, aFindBackwards, aLinksOnly); this._notify(result, aFindBackwards, aDrawOutline);
}, },
highlight: function (aHighlight, aWord) { highlight: function (aHighlight, aWord) {
@ -93,11 +108,7 @@ Finder.prototype = {
fastFind.collapseSelection(); fastFind.collapseSelection();
fastFind.setSelectionModeAndRepaint(Ci.nsISelectionController.SELECTION_ON); fastFind.setSelectionModeAndRepaint(Ci.nsISelectionController.SELECTION_ON);
// We also drew our own outline, remove that as well. this._restoreOriginalOutline();
if (this._previousLink && this._drewOutline) {
this._previousLink.style.outline = this._tmpOutline;
this._previousLink.style.outlineOffset = this._tmpOutlineOffset;
}
}, },
focusContent: function() { focusContent: function() {
@ -150,20 +161,17 @@ Finder.prototype = {
return this._docShell.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow); return this._docShell.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow);
}, },
_outlineLink: function (aLinksOnly) { _outlineLink: function (aDrawOutline) {
let foundLink = this._fastFind.foundLink; 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; return;
if (this._previousLink && this._drewOutline) { this._restoreOriginalOutline();
// restore original outline
this._previousLink.style.outline = this._tmpOutline;
this._previousLink.style.outlineOffset = this._tmpOutlineOffset;
}
this._drewOutline = (foundLink && aLinksOnly); if (foundLink && aDrawOutline) {
if (this._drewOutline) {
// Backup original outline // Backup original outline
this._tmpOutline = foundLink.style.outline; this._tmpOutline = foundLink.style.outline;
this._tmpOutlineOffset = foundLink.style.outlineOffset; this._tmpOutlineOffset = foundLink.style.outlineOffset;
@ -175,9 +183,18 @@ Finder.prototype = {
// Don't set the outline-color, we should always use initial value. // Don't set the outline-color, we should always use initial value.
foundLink.style.outline = "1px dotted"; foundLink.style.outline = "1px dotted";
foundLink.style.outlineOffset = "0"; 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) { _highlight: function (aHighlight, aWord, aWindow) {