summaryrefslogtreecommitdiffstats
path: root/devtools/client/accessibility/utils
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/client/accessibility/utils
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/accessibility/utils')
-rw-r--r--devtools/client/accessibility/utils/audit.js45
-rw-r--r--devtools/client/accessibility/utils/l10n.js11
-rw-r--r--devtools/client/accessibility/utils/moz.build5
3 files changed, 61 insertions, 0 deletions
diff --git a/devtools/client/accessibility/utils/audit.js b/devtools/client/accessibility/utils/audit.js
new file mode 100644
index 0000000000..6234e711f1
--- /dev/null
+++ b/devtools/client/accessibility/utils/audit.js
@@ -0,0 +1,45 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+/**
+ * A helper class that contains the state of the audit progress performed by
+ * the accessibility panel. Its onProgressForWalker function wraps around the
+ * onProgress function (see actions/audit.js) that updates the panel state. It
+ * combines the audits across multiple frames that happen asynchronously. It
+ * only starts dispatching/calling onProgress after we get an initial progress
+ * audit-event from all frames (and thus know the combined total).
+ */
+class CombinedProgress {
+ constructor({ onProgress, totalFrames }) {
+ this.onProgress = onProgress;
+ this.totalFrames = totalFrames;
+ this.combinedProgress = new Map();
+ }
+
+ onProgressForWalker(walker, progress) {
+ this.combinedProgress.set(walker, progress);
+ // We did not get all initial progress events from all frames, do not
+ // relay them to the client until we can calculate combined total below.
+ if (this.combinedProgress.size < this.totalFrames) {
+ return;
+ }
+
+ let combinedTotal = 0;
+ let combinedCompleted = 0;
+
+ for (const { completed, total } of this.combinedProgress.values()) {
+ combinedTotal += total;
+ combinedCompleted += completed;
+ }
+ this.onProgress({
+ total: combinedTotal,
+ percentage: Math.round((combinedCompleted / combinedTotal) * 100),
+ });
+ }
+}
+
+exports.CombinedProgress = CombinedProgress;
+exports.isFiltered = filters => Object.values(filters).some(active => active);
diff --git a/devtools/client/accessibility/utils/l10n.js b/devtools/client/accessibility/utils/l10n.js
new file mode 100644
index 0000000000..0b1052c4fc
--- /dev/null
+++ b/devtools/client/accessibility/utils/l10n.js
@@ -0,0 +1,11 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { LocalizationHelper } = require("resource://devtools/shared/l10n.js");
+
+const A11Y_STRINGS_URI = "devtools/client/locales/accessibility.properties";
+
+exports.L10N = new LocalizationHelper(A11Y_STRINGS_URI);
diff --git a/devtools/client/accessibility/utils/moz.build b/devtools/client/accessibility/utils/moz.build
new file mode 100644
index 0000000000..8129eea8e5
--- /dev/null
+++ b/devtools/client/accessibility/utils/moz.build
@@ -0,0 +1,5 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+DevToolsModules("audit.js", "l10n.js")