Bug 1279684 - make sure that toggling 'Highlight All' also hides the found occurrences from the mask. r?jaws
MozReview-Commit-ID: 2VgmzJNyrNN
--- a/toolkit/content/widgets/findbar.xml
+++ b/toolkit/content/widgets/findbar.xml
@@ -537,16 +537,18 @@
<parameter name="aHighlight"/>
<parameter name="aFromPrefObserver"/>
<body><![CDATA[
if (aHighlight === this._highlightAll) {
return;
}
this._highlightAll = aHighlight;
+ this.browser.finder.onHighlightAllChange(aHighlight);
+
if (!this._dispatchFindEvent("highlightallchange")) {
return;
}
this._setHighlightAll(aHighlight, aFromPrefObserver);
let word = this._findField.value;
// Bug 429723. Don't attempt to highlight ""
--- a/toolkit/modules/Finder.jsm
+++ b/toolkit/modules/Finder.jsm
@@ -302,16 +302,21 @@ Finder.prototype = {
this.highlighter.hide();
},
onModalHighlightChange(useModalHighlight) {
if (this._highlighter)
this._highlighter.onModalHighlightChange(useModalHighlight);
},
+ onHighlightAllChange(highlightAll) {
+ if (this._highlighter)
+ this._highlighter.onHighlightAllChange(highlightAll);
+ },
+
keyPress: function (aEvent) {
let controller = this._getSelectionController(this._getWindow());
switch (aEvent.keyCode) {
case Ci.nsIDOMKeyEvent.DOM_VK_RETURN:
if (this._fastFind.foundLink) {
let view = this._fastFind.foundLink.ownerDocument.defaultView;
this._fastFind.foundLink.dispatchEvent(new view.MouseEvent("click", {
--- a/toolkit/modules/FinderHighlighter.jsm
+++ b/toolkit/modules/FinderHighlighter.jsm
@@ -452,16 +452,29 @@ FinderHighlighter.prototype = {
if (this._modal && !useModalHighlight) {
this.hide();
this.clear();
}
this._modal = useModalHighlight;
},
/**
+ * When 'Highlight All' is toggled during a session, this callback is invoked
+ * and when it's turned off, the found occurrences will be removed from the mask.
+ *
+ * @param {Boolean} highlightAll
+ */
+ onHighlightAllChange(highlightAll) {
+ if (this._modal && !highlightAll) {
+ this.clear();
+ this._scheduleRepaintOfMask(this.finder._getWindow());
+ }
+ },
+
+ /**
* Utility; get the nsIDOMWindowUtils for a window.
*
* @param {nsIDOMWindow} window Optional, defaults to the finder window.
* @return {nsIDOMWindowUtils}
*/
_getDWU(window = null) {
return (window || this.finder._getWindow())
.QueryInterface(Ci.nsIInterfaceRequestor)
--- a/toolkit/modules/RemoteFinder.jsm
+++ b/toolkit/modules/RemoteFinder.jsm
@@ -185,16 +185,22 @@ RemoteFinder.prototype = {
},
onModalHighlightChange: function(aUseModalHighlight) {
this._browser.messageManager.sendAsyncMessage("Finder:ModalHighlightChange", {
useModalHighlight: aUseModalHighlight
});
},
+ onHighlightAllChange: function(aHighlightAll) {
+ this._browser.messageManager.sendAsyncMessage("Finder:HighlightAllChange", {
+ highlightAll: aHighlightAll
+ });
+ },
+
keyPress: function (aEvent) {
this._browser.messageManager.sendAsyncMessage("Finder:KeyPress",
{ keyCode: aEvent.keyCode,
ctrlKey: aEvent.ctrlKey,
metaKey: aEvent.metaKey,
altKey: aEvent.altKey,
shiftKey: aEvent.shiftKey });
},
@@ -223,16 +229,17 @@ RemoteFinderListener.prototype = {
"Finder:CaseSensitive",
"Finder:Destroy",
"Finder:EntireWord",
"Finder:FastFind",
"Finder:FindAgain",
"Finder:SetSearchStringToSelection",
"Finder:GetInitialSelection",
"Finder:Highlight",
+ "Finder:HighlightAllChange",
"Finder:EnableSelection",
"Finder:RemoveSelection",
"Finder:FocusContent",
"Finder:FindbarClose",
"Finder:KeyPress",
"Finder:MatchesCount",
"Finder:ModalHighlightChange"
],
@@ -290,16 +297,20 @@ RemoteFinderListener.prototype = {
case "Finder:FindAgain":
this._finder.findAgain(data.findBackwards, data.linksOnly, data.drawOutline);
break;
case "Finder:Highlight":
this._finder.highlight(data.highlight, data.word);
break;
+ case "Finder:HighlightAllChange":
+ this._finder.onHighlightAllChange(data.highlightAll);
+ break;
+
case "Finder:EnableSelection":
this._finder.enableSelection();
break;
case "Finder:RemoveSelection":
this._finder.removeSelection();
break;
--- a/toolkit/modules/tests/browser/browser_FinderHighlighter.js
+++ b/toolkit/modules/tests/browser/browser_FinderHighlighter.js
@@ -1,16 +1,17 @@
"use strict";
Cu.import("resource://testing-common/BrowserTestUtils.jsm", this);
Cu.import("resource://testing-common/ContentTask.jsm", this);
Cu.import("resource://gre/modules/Promise.jsm", this);
Cu.import("resource://gre/modules/Task.jsm", this);
Cu.import("resource://gre/modules/AppConstants.jsm");
+const kHighlightAllPref = "findbar.highlightAll";
const kPrefModalHighlight = "findbar.modalHighlight";
const kFixtureBaseURL = "https://example.com/browser/toolkit/modules/tests/browser/";
function promiseOpenFindbar(findbar) {
findbar.onFindCommand()
return gFindBar._startFindDeferred && gFindBar._startFindDeferred.promise;
}
@@ -124,18 +125,18 @@ function promiseTestHighlighterOutput(br
document.insertAnonymousContent = stub("insert");
document.removeAnonymousContent = stub("remove");
});
});
}
add_task(function* setup() {
yield SpecialPowers.pushPrefEnv({ set: [
- ["findbar.highlightAll", true],
- ["findbar.modalHighlight", true]
+ [kHighlightAllPref, true],
+ [kPrefModalHighlight, true]
]});
});
// Test the results of modal highlighting, which is on by default.
add_task(function* testModalResults() {
let tests = new Map([
["Roland", {
rectCount: 2,
@@ -265,8 +266,48 @@ add_task(function* testDarkPageDetection
Assert.ok(node.hasAttribute("brighttext"), "Dark HTML page should have 'brighttext' set");
});
yield promiseEnterStringIntoFindField(findbar, word);
yield promise;
findbar.close(true);
});
});
+
+add_task(function* testHighlightAllToggle() {
+ let url = kFixtureBaseURL + "file_FinderSample.html";
+ yield BrowserTestUtils.withNewTab(url, function* (browser) {
+ let findbar = gBrowser.getFindBar();
+
+ yield promiseOpenFindbar(findbar);
+
+ let word = "Roland";
+ let expectedResult = {
+ rectCount: 2,
+ insertCalls: [2, 4],
+ removeCalls: [1, 2]
+ };
+ let whenHighlightDone = promiseTestHighlighterOutput(browser, word, expectedResult);
+ yield promiseEnterStringIntoFindField(findbar, word);
+ yield whenHighlightDone;
+
+ // We now know we have multiple rectangles highlighted, so it's a good time
+ // to flip the pref.
+ expectedResult = {
+ rectCount: 0,
+ insertCalls: [1, 1],
+ removeCalls: [1, 1]
+ };
+ whenHighlightDone = promiseTestHighlighterOutput(browser, word, expectedResult);
+ yield SpecialPowers.pushPrefEnv({ "set": [[ kHighlightAllPref, false ]] });
+ yield whenHighlightDone;
+
+ // For posterity, let's switch back.
+ expectedResult = {
+ rectCount: 2,
+ insertCalls: [2, 4],
+ removeCalls: [1, 2]
+ };
+ whenHighlightDone = promiseTestHighlighterOutput(browser, word, expectedResult);
+ yield SpecialPowers.pushPrefEnv({ "set": [[ kHighlightAllPref, true ]] });
+ yield whenHighlightDone;
+ });
+});