Bug 1290914 - move the matches count and highlight-all request from the findbar binding to the JS module in the content process, so it's closer to the metal. r=jaws

MozReview-Commit-ID: INYobXmrVj5
This commit is contained in:
Mike de Boer 2016-09-08 22:38:55 +02:00
Родитель 3e295e6280
Коммит f52eb8430c
6 изменённых файлов: 61 добавлений и 56 удалений

Просмотреть файл

@ -1468,29 +1468,25 @@ BrowserElementChild.prototype = {
successRv: manifest
});
}),
_initFinder: function() {
if (!this._finder) {
try {
this._findLimit = Services.prefs.getIntPref("accessibility.typeaheadfind.matchesCountLimit");
} catch (e) {
// Pref not available, assume 0, no match counting.
this._findLimit = 0;
}
let {Finder} = Components.utils.import("resource://gre/modules/Finder.jsm", {});
this._finder = new Finder(docShell);
this._finder.addResultListener({
onMatchesCountResult: (data) => {
sendAsyncMsg('findchange', {
active: true,
searchString: this._finder.searchString,
searchLimit: this._findLimit,
activeMatchOrdinal: data.current,
numberOfMatches: data.total
});
}
});
}
let listener = {
onMatchesCountResult: (data) => {
sendAsyncMsg("findchange", {
active: true,
searchString: this._finder.searchString,
searchLimit: this._finder.matchesCountLimit,
activeMatchOrdinal: data.current,
numberOfMatches: data.total
});
this._finder.removeResultListener(listener);
}
};
this._finder.addResultListener(listener);
},
_recvFindAll: function(data) {
@ -1498,7 +1494,7 @@ BrowserElementChild.prototype = {
let searchString = data.json.searchString;
this._finder.caseSensitive = data.json.caseSensitive;
this._finder.fastFind(searchString, false, false);
this._finder.requestMatchesCount(searchString, this._findLimit, false);
this._finder.requestMatchesCount(searchString, this._finder.matchesCountLimit, false);
},
_recvFindNext: function(data) {
@ -1506,8 +1502,9 @@ BrowserElementChild.prototype = {
debug("findNext() called before findAll()");
return;
}
this._initFinder();
this._finder.findAgain(data.json.backward, false, false);
this._finder.requestMatchesCount(this._finder.searchString, this._findLimit, false);
this._finder.requestMatchesCount(this._finder.searchString, this._finder.matchesCountLimit, false);
},
_recvClearMatch: function(data) {
@ -1516,7 +1513,7 @@ BrowserElementChild.prototype = {
return;
}
this._finder.removeSelection();
sendAsyncMsg('findchange', {active: false});
sendAsyncMsg("findchange", {active: false});
},
_recvSetInputMethodActive: function(data) {

Просмотреть файл

@ -25,10 +25,13 @@
Cu.import("resource://testing-common/ContentTask.jsm");
ContentTask.setTestScope(window.opener.wrappedJSObject);
var gPrefsvc = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
const SAMPLE_URL = "http://www.mozilla.org/";
const SAMPLE_TEXT = "Some text in a text field.";
const SEARCH_TEXT = "Text Test";
const NOT_FOUND_TEXT = "This text is not on the page."
const ITERATOR_TIMEOUT = gPrefsvc.getIntPref("findbar.iteratorTimeout") + 20;
var gFindBar = null;
var gBrowser;
@ -250,6 +253,8 @@
}
};
gFindBar.browser.finder.addResultListener(listener);
// Make sure we resolve _at least_ after five times the find iterator timeout.
setTimeout(resolve, ITERATOR_TIMEOUT * 5);
});
}
@ -368,9 +373,7 @@
ok(!matchCaseCheckbox.hidden, "match case box is hidden in manual mode");
ok(matchCaseLabel.hidden, "match case label is visible in manual mode");
var prefsvc = Cc["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefBranch);
prefsvc.setIntPref("accessibility.typeaheadfind.casesensitive", 2);
gPrefsvc.setIntPref("accessibility.typeaheadfind.casesensitive", 2);
ok(matchCaseCheckbox.hidden,
"match case box is visible in automatic mode");
@ -388,7 +391,7 @@
gFindBar.onFindAgainCommand();
ok(matchCaseCheckbox.hidden && !matchCaseLabel.hidden,
"bug 365551: case sensitivity UI is broken after find-again");
prefsvc.setIntPref("accessibility.typeaheadfind.casesensitive", 0);
gPrefsvc.setIntPref("accessibility.typeaheadfind.casesensitive", 0);
gFindBar.close();
}
@ -519,6 +522,7 @@
if (matchCase.checked) {
promise = promiseFindResult();
matchCase.click();
yield new Promise(resolve => setTimeout(resolve, ITERATOR_TIMEOUT));
yield promise;
}
@ -553,15 +557,16 @@
gFindBar._findField.select();
gFindBar._findField.focus();
promise = promiseMatchesCountResult();
yield new Promise(resolve => setTimeout(resolve, ITERATOR_TIMEOUT));
yield enterStringIntoFindField(test.text, false);
yield promise;
yield promiseMatchesCountResult();
let matches = foundMatches.value.match(regex);
if (!test.total) {
ok(!matches, "No message should be shown when 0 matches are expected");
} else {
assertMatches(test, matches);
for (let i = 1; i < test.total; i++) {
yield new Promise(resolve => setTimeout(resolve, ITERATOR_TIMEOUT));
gFindBar.onFindAgainCommand();
yield promiseMatchesCountResult();
// test.current + 1, test.current + 2, ..., test.total, 1, ..., test.current
@ -583,16 +588,14 @@
yield enterStringIntoFindField(SEARCH_TEXT);
gFindBar.clear();
let prefsvc = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefBranch);
prefsvc.setIntPref("accessibility.typeaheadfind.casesensitive", 0);
gPrefsvc.setIntPref("accessibility.typeaheadfind.casesensitive", 0);
yield enterStringIntoFindField("t");
yield ContentTask.spawn(gBrowser, null, function* () {
Assert.equal(content.getSelection().toString(), "T", "First T should be selected.");
});
prefsvc.setIntPref("accessibility.typeaheadfind.casesensitive", 1);
gPrefsvc.setIntPref("accessibility.typeaheadfind.casesensitive", 1);
yield ContentTask.spawn(gBrowser, null, function* () {
Assert.equal(content.getSelection().toString(), "t", "First t should be selected.");
});
@ -602,16 +605,14 @@
// 1. Do a search that fails with case sensitivity but matches with no case sensitivity.
// 2. Uncheck case sensitivity button to match the string.
function* testFailedStringReset() {
let prefsvc = Cc["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefBranch);
prefsvc.setIntPref("accessibility.typeaheadfind.casesensitive", 1);
gPrefsvc.setIntPref("accessibility.typeaheadfind.casesensitive", 1);
yield enterStringIntoFindField(SEARCH_TEXT.toUpperCase(), false);
yield ContentTask.spawn(gBrowser, null, function* () {
Assert.equal(content.getSelection().toString(), "", "Not found.");
});
prefsvc.setIntPref("accessibility.typeaheadfind.casesensitive", 0);
gPrefsvc.setIntPref("accessibility.typeaheadfind.casesensitive", 0);
yield ContentTask.spawn(gBrowser, { SEARCH_TEXT }, function* (args) {
Assert.equal(content.getSelection().toString(), args.SEARCH_TEXT,
"Search text should be selected.");

Просмотреть файл

@ -344,6 +344,8 @@
case "findbar.entireword":
this._self._entireWord = prefsvc.getBoolPref(aPrefName);
this._self._updateEntireWord();
// Update the matches count.
this._updateMatchesCount(this.nsITypeAheadFind.FIND_FOUND);
break;
case "findbar.highlightAll":
this._self.toggleHighlight(prefsvc.getBoolPref(aPrefName), true);
@ -499,11 +501,11 @@
-->
<method name="_updateMatchesCount">
<body><![CDATA[
if (this._matchesCountLimit == 0 || !this._dispatchFindEvent("matchescount"))
if (!this._dispatchFindEvent("matchescount"))
return;
this.browser.finder.requestMatchesCount(this._findField.value,
this._matchesCountLimit, this._findMode == this.FIND_LINKS);
this._findMode == this.FIND_LINKS);
]]></body>
</method>
@ -628,7 +630,6 @@
this._updateCaseSensitivity();
this._findFailedString = null;
this._find();
this._maybeHighlightAll();
this._dispatchFindEvent("casesensitivitychange");
]]></body>
@ -653,9 +654,6 @@
statusLabel.hidden = !hideCheckbox;
this.browser.finder.entireWord = entireWord;
// Update the matches count
this._updateMatchesCount(this.nsITypeAheadFind.FIND_FOUND);
]]></body>
</method>
@ -1020,8 +1018,6 @@
}
this._enableFindButtons(val);
this._maybeHighlightAll();
this._updateCaseSensitivity(val);
this._updateEntireWord();
@ -1100,7 +1096,6 @@
this._findField.removeAttribute("status");
break;
}
this._updateMatchesCount(res);
]]></body>
</method>

Просмотреть файл

@ -26,6 +26,7 @@ XPCOMUtils.defineLazyServiceGetter(this, "ClipboardHelper",
"nsIClipboardHelper");
const kSelectionMaxLen = 150;
const kMatchesCountLimitPref = "accessibility.typeaheadfind.matchesCountLimit";
function Finder(docShell) {
this._fastFind = Cc["@mozilla.org/typeaheadfind;1"].createInstance(Ci.nsITypeAheadFind);
@ -113,7 +114,9 @@ Finder.prototype = {
})) {
this.iterator.stop();
}
this.highlighter.update(options);
this.requestMatchesCount(options.searchString, options.linksOnly);
this._outlineLink(options.drawOutline);
@ -167,6 +170,14 @@ Finder.prototype = {
return this._highlighter = new FinderHighlighter(this);
},
get matchesCountLimit() {
if (typeof this._matchesCountLimit == "number")
return this._matchesCountLimit;
this._matchesCountLimit = Services.prefs.getIntPref(kMatchesCountLimitPref) || 0;
return this._matchesCountLimit;
},
_lastFindResult: null,
/**
@ -321,6 +332,7 @@ Finder.prototype = {
onFindbarClose: function() {
this.enableSelection();
this.highlighter.highlight(false);
this.iterator.reset();
BrowserUtils.trackToolbarVisibility(this._docShell, "findbar", false);
},
@ -383,7 +395,7 @@ Finder.prototype = {
_notifyMatchesCount: function(result = this._currentMatchesCountResult) {
// The `_currentFound` property is only used for internal bookkeeping.
delete result._currentFound;
if (result.total == this._currentMatchLimit)
if (result.total == this.matchesCountLimit)
result.total = -1;
for (let l of this._listeners) {
@ -395,9 +407,9 @@ Finder.prototype = {
this._currentMatchesCountResult = null;
},
requestMatchesCount: function(aWord, aMatchLimit, aLinksOnly) {
requestMatchesCount: function(aWord, aLinksOnly) {
if (this._lastFindResult == Ci.nsITypeAheadFind.FIND_NOTFOUND ||
this.searchString == "" || !aWord) {
this.searchString == "" || !aWord || !this.matchesCountLimit) {
this._notifyMatchesCount({
total: 0,
current: 0
@ -407,7 +419,6 @@ Finder.prototype = {
let window = this._getWindow();
this._currentFoundRange = this._fastFind.getFoundRange();
this._currentMatchLimit = aMatchLimit;
let params = {
caseSensitive: this._fastFind.caseSensitive,
@ -420,7 +431,7 @@ Finder.prototype = {
this.iterator.start(Object.assign(params, {
finder: this,
limit: aMatchLimit,
limit: this.matchesCountLimit,
listener: this,
useCache: true,
})).then(() => {
@ -453,7 +464,7 @@ Finder.prototype = {
onIteratorReset() {},
onIteratorRestart({ word, linksOnly }) {
this.requestMatchesCount(word, this._currentMatchLimit, linksOnly);
this.requestMatchesCount(word, linksOnly);
},
onIteratorStart() {

Просмотреть файл

@ -30,7 +30,7 @@ const kFontPropsCamelCase = kFontPropsCSS.map(prop => {
let parts = prop.split("-");
return parts.shift() + parts.map(part => part.charAt(0).toUpperCase() + part.slice(1)).join("");
});
const kRGBRE = /^rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*/i
const kRGBRE = /^rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*/i;
// This uuid is used to prefix HTML element IDs and classNames in order to make
// them unique and hard to clash with IDs and classNames content authors come up
// with, since the stylesheet for modal highlighting is inserted as an agent-sheet
@ -484,6 +484,9 @@ FinderHighlighter.prototype = {
window.requestAnimationFrame(() => {
outlineNode.setAttributeForElement(kModalOutlineId, "grow", true);
});
if (this._highlightAll && data.searchString)
this.highlight(true, data.searchString, data.linksOnly);
},
/**
@ -963,8 +966,7 @@ FinderHighlighter.prototype = {
let maskNode = document.createElement("div");
// Make sure the dimmed mask node takes the full width and height that's available.
let {width, height} = this._getWindowDimensions(window);
dict.lastWindowDimensions = { width, height };
let {width, height} = dict.lastWindowDimensions = this._getWindowDimensions(window);
maskNode.setAttribute("id", kMaskId);
maskNode.setAttribute("class", kMaskId + (kDebug ? ` ${kModalIdPrefix}-findbar-debug` : ""));
maskNode.setAttribute("style", `width: ${width}px; height: ${height}px;`);

Просмотреть файл

@ -200,10 +200,9 @@ RemoteFinder.prototype = {
shiftKey: aEvent.shiftKey });
},
requestMatchesCount: function (aSearchString, aMatchLimit, aLinksOnly) {
requestMatchesCount: function (aSearchString, aLinksOnly) {
this._browser.messageManager.sendAsyncMessage("Finder:MatchesCount",
{ searchString: aSearchString,
matchLimit: aMatchLimit,
linksOnly: aLinksOnly });
}
}
@ -322,7 +321,7 @@ RemoteFinderListener.prototype = {
break;
case "Finder:MatchesCount":
this._finder.requestMatchesCount(data.searchString, data.matchLimit, data.linksOnly);
this._finder.requestMatchesCount(data.searchString, data.linksOnly);
break;
case "Finder:ModalHighlightChange":