From fafd8819bcac381afdd6e6d60fc9e37ccf5a70cc Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 13 Sep 2018 11:32:12 +0200 Subject: [PATCH 1/3] Enable forwarding, in `FirefoxCom`, of the matchesCount to the browser findbar (bug 1062025) This depends on https://bugzilla.mozilla.org/show_bug.cgi?id=1062025 landing in `mozilla-central` first, since https://searchfox.org/mozilla-central/rev/37663bb87004167184de6f2afa6b05875eb0528e/browser/extensions/pdfjs/content/PdfStreamConverter.jsm#719,740 would otherwise throw for the unknown event name. --- web/firefoxcom.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/firefoxcom.js b/web/firefoxcom.js index 46c75db6a856b..4ac860f3f746e 100644 --- a/web/firefoxcom.js +++ b/web/firefoxcom.js @@ -212,7 +212,7 @@ PDFViewerApplication.externalServices = { }, updateFindMatchesCount(data) { - // FirefoxCom.request('updateFindMatchesCount', data); + FirefoxCom.request('updateFindMatchesCount', data); }, initPassiveLoading(callbacks) { From be7fdf148c54e1522f8e713f5db78397a0d4d74c Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 13 Sep 2018 11:40:12 +0200 Subject: [PATCH 2/3] Further ensure that `PDFFindController._requestMatchesCount` won't return broken data (PR 10052 follow-up) This prevents the findbar from intermittently displaying `0 of {number} matches`, which *could* theoretically happen for large and/or slow loading documents. --- web/pdf_find_controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index 815a3a93c7eab..fd3d9d17d03e4 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -510,7 +510,7 @@ class PDFFindController { // When searching starts, this method may be called before the `pageMatches` // have been counted (in `_calculateMatch`). Ensure that the UI won't show // temporarily broken state when the active find result doesn't make sense. - if (current > total) { + if (current < 1 || current > total) { current = total = 0; } return { current, total, }; From 06b9455263753747c3a23316639b2d3d49e641a9 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 14 Sep 2018 03:11:40 +0200 Subject: [PATCH 3/3] Hard-code the `MOZCENTRAL` build to use the `[other]` plural forms of the matcheCount strings, to prevent errors for PDF files embedded in iframe/object tags The built-in PDF Viewer (in Firefox) cannot use the browser findbar when PDF files are embedded in e.g. iframe/object tags, and the PDF.js findbar (i.e. `PDFFindBar`) will thus be used instead in those cases. This is slightly problematic, since the `MOZCENTRAL` version of the viewer uses a special, slimmed down, version of the `l10n.js` file that doesn't (currently) support plural forms. To prevent the matchesCounter from breaking completely in this edge-case, temporarily hard-code the plural form to use the default `[other]` version of the locale strings. --- web/pdf_find_bar.js | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/web/pdf_find_bar.js b/web/pdf_find_bar.js index a9f2e47d7a52c..5cd07710c123d 100644 --- a/web/pdf_find_bar.js +++ b/web/pdf_find_bar.js @@ -161,16 +161,33 @@ class PDFFindBar { if (total) { if (total > limit) { - matchesCountMsg = this.l10n.get('find_matches_count_limit', { - n: limit, - limit: limit.toLocaleString(), - }, 'More than {{limit}} match' + (limit !== 1 ? 'es' : '')); + if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('MOZCENTRAL')) { + // TODO: Remove this hard-coded `[other]` form once plural support has + // been implemented in the mozilla-central specific `l10n.js` file. + matchesCountMsg = this.l10n.get('find_matches_count_limit[other]', { + limit: limit.toLocaleString(), + }, 'More than {{limit}} matches'); + } else { + matchesCountMsg = this.l10n.get('find_matches_count_limit', { + n: limit, + limit: limit.toLocaleString(), + }, 'More than {{limit}} match' + (limit !== 1 ? 'es' : '')); + } } else { - matchesCountMsg = this.l10n.get('find_matches_count', { - n: total, - current: current.toLocaleString(), - total: total.toLocaleString(), - }, '{{current}} of {{total}} match' + (total !== 1 ? 'es' : '')); + if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('MOZCENTRAL')) { + // TODO: Remove this hard-coded `[other]` form once plural support has + // been implemented in the mozilla-central specific `l10n.js` file. + matchesCountMsg = this.l10n.get('find_matches_count[other]', { + current: current.toLocaleString(), + total: total.toLocaleString(), + }, '{{current}} of {{total}} matches'); + } else { + matchesCountMsg = this.l10n.get('find_matches_count', { + n: total, + current: current.toLocaleString(), + total: total.toLocaleString(), + }, '{{current}} of {{total}} match' + (total !== 1 ? 'es' : '')); + } } } Promise.resolve(matchesCountMsg).then((msg) => {