Bug 1905331 - Add findbar "not found" sound to PDF view, r=pdfjs-reviewers,robwu

Introduce another state `_lastNotFoundString` to trace search string
length. Avoid to break original `_findFailedString` logic. Also note
this `_updateControlState` can be called multiple times after single
input in search field thus not as simple as other findbars.

Differential Revision: https://phabricator.services.mozilla.com/D215196
This commit is contained in:
bootleq
2024-10-03 16:09:29 +00:00
parent 226d7db0f3
commit 4be22a08d6
2 changed files with 25 additions and 0 deletions

View File

@@ -525,11 +525,17 @@ class ChromeActions {
if (typeof data.rawQuery === "string") {
rawQuery = data.rawQuery;
}
// Same for the `entireWord` property.
let entireWord = false;
if (typeof data.entireWord === "boolean") {
entireWord = data.entireWord;
}
let actor = getActor(this.domWindow);
actor?.sendAsyncMessage("PDFJS:Parent:updateControlState", {
result,
findPrevious,
entireWord,
matchesCount,
rawQuery,
});

View File

@@ -15,6 +15,7 @@
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
import { PdfJsTelemetry } from "resource://pdf.js/PdfJsTelemetry.sys.mjs";
import { playNotFoundSound } from "resource://gre/modules/FinderSound.sys.mjs";
const lazy = {};
@@ -69,6 +70,7 @@ export class PdfjsParent extends JSWindowActorParent {
super();
this._boundToFindbar = null;
this._findFailedString = null;
this._lastNotFoundStringLength = 0;
this._updatedPreference();
}
@@ -414,6 +416,23 @@ export class PdfjsParent extends JSWindowActorParent {
lazy.SetClipboardSearchString(data.rawQuery);
}
let searchLengthened;
switch (data.result) {
case Ci.nsITypeAheadFind.FIND_NOTFOUND:
searchLengthened =
data.rawQuery.length > this._lastNotFoundStringLength;
this._lastNotFoundStringLength = data.rawQuery.length;
if (searchLengthened && !data.entireWord) {
playNotFoundSound();
}
break;
case Ci.nsITypeAheadFind.FIND_PENDING:
break;
default:
this._lastNotFoundStringLength = 0;
}
const matchesCount = this._requestMatchesCount(data.matchesCount);
fb.onMatchesCountResult(matchesCount);
});