From 32023e25688de95cdf4f616943bb63b9be95c3d6 Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Thu, 26 Sep 2013 11:21:02 -0400 Subject: [PATCH] Bug 919340 - Always draw outline around links when using quickfind. r=mikedeboer --- toolkit/content/widgets/findbar.xml | 8 ++-- toolkit/modules/Finder.jsm | 65 ++++++++++++++++++----------- 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/toolkit/content/widgets/findbar.xml b/toolkit/content/widgets/findbar.xml index 49ddc8b73e59..79ab577bcddb 100644 --- a/toolkit/content/widgets/findbar.xml +++ b/toolkit/content/widgets/findbar.xml @@ -44,7 +44,7 @@ } this.findbar.onFindAgainCommand(aEvent.shiftKey); - } else if (this.findbar._findMode == this.findbar.FIND_LINKS) { + } else { this.findbar._finishFAYT(aEvent); } ]]> @@ -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 @@ diff --git a/toolkit/modules/Finder.jsm b/toolkit/modules/Finder.jsm index 05b961b5c228..507f32a07a06 100644 --- a/toolkit/modules/Finder.jsm +++ b/toolkit/modules/Finder.jsm @@ -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) {