зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1117274 - Implement desktops FindInPage matchString limit pref, r=wesj
This commit is contained in:
Родитель
966ef984e3
Коммит
58b9ea190d
|
@ -223,26 +223,33 @@ public class FindInPageBar extends LinearLayout implements TextWatcher, View.OnC
|
|||
@Override
|
||||
public void onResponse(NativeJSObject nativeJSObject) {
|
||||
final int total = nativeJSObject.optInt("total", 0);
|
||||
final int current = nativeJSObject.optInt("current", 0);
|
||||
updateResult(total, current);
|
||||
if (total == -1) {
|
||||
final int limit = nativeJSObject.optInt("limit", 0);
|
||||
updateResult(Integer.toString(limit) + "+");
|
||||
} else if (total > 0) {
|
||||
final int current = nativeJSObject.optInt("current", 0);
|
||||
updateResult(Integer.toString(current) + "/" + Integer.toString(total));
|
||||
} else {
|
||||
// We display no match-count information, when there were no
|
||||
// matches found, or if matching has been turned off by setting
|
||||
// pref accessibility.typeaheadfind.matchesCountLimit to 0.
|
||||
updateResult("");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(NativeJSObject error) {
|
||||
// Gecko didn't respond due to state change, javascript error, etc.
|
||||
updateResult(0, 0);
|
||||
Log.d(LOGTAG, "No response from Gecko on request to match string: [" +
|
||||
searchString + "]");
|
||||
updateResult("");
|
||||
}
|
||||
|
||||
private void updateResult(int total, int current) {
|
||||
final Boolean statusVisibility = (total > 0);
|
||||
final String statusText = current + "/" + total;
|
||||
|
||||
private void updateResult(final String statusText) {
|
||||
ThreadUtils.postToUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mStatusText.setVisibility(statusVisibility ? View.VISIBLE : View.GONE);
|
||||
mStatusText.setVisibility(statusText.isEmpty() ? View.GONE : View.VISIBLE);
|
||||
mStatusText.setText(statusText);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -8,7 +8,8 @@ var FindHelper = {
|
|||
_targetTab: null,
|
||||
_initialViewport: null,
|
||||
_viewportChanged: false,
|
||||
_matchesCountResult: null,
|
||||
_result: null,
|
||||
_limit: 0,
|
||||
|
||||
observe: function(aMessage, aTopic, aData) {
|
||||
switch(aTopic) {
|
||||
|
@ -31,6 +32,13 @@ var FindHelper = {
|
|||
},
|
||||
|
||||
_findOpened: function() {
|
||||
try {
|
||||
this._limit = Services.prefs.getIntPref("accessibility.typeaheadfind.matchesCountLimit");
|
||||
} catch (e) {
|
||||
// Pref not available, assume 0, no match counting.
|
||||
this._limit = 0;
|
||||
}
|
||||
|
||||
Messaging.addListener((data) => {
|
||||
this.doFind(data.searchString, data.matchCase);
|
||||
return this._getMatchesCountResult(data.searchString);
|
||||
|
@ -90,18 +98,22 @@ var FindHelper = {
|
|||
* Request, wait for, and return the current matchesCount results for a string.
|
||||
*/
|
||||
_getMatchesCountResult: function(findString) {
|
||||
// Sync call to Finder, results available immediately.
|
||||
this._matchesCountResult = null;
|
||||
this._finder.requestMatchesCount(findString);
|
||||
// Count matches up to any provided limit.
|
||||
if (this._limit <= 0) {
|
||||
return { total: 0, current: 0, limit: 0 };
|
||||
}
|
||||
|
||||
return this._matchesCountResult;
|
||||
// Sync call to Finder, results available immediately.
|
||||
this._finder.requestMatchesCount(findString, this._limit);
|
||||
return this._result;
|
||||
},
|
||||
|
||||
/**
|
||||
* Pass along the count results to FindInPageBar for display.
|
||||
*/
|
||||
onMatchesCountResult: function(result) {
|
||||
this._matchesCountResult = result;
|
||||
this._result = result;
|
||||
this._result.limit = this._limit;
|
||||
},
|
||||
|
||||
doFind: function(searchString, matchCase) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче