summaryrefslogtreecommitdiffstats
path: root/devtools/client/accessibility/actions
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/actions
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/actions')
-rw-r--r--devtools/client/accessibility/actions/accessibles.js70
-rw-r--r--devtools/client/accessibility/actions/audit.js36
-rw-r--r--devtools/client/accessibility/actions/details.js40
-rw-r--r--devtools/client/accessibility/actions/moz.build5
-rw-r--r--devtools/client/accessibility/actions/simulation.js16
-rw-r--r--devtools/client/accessibility/actions/ui.js77
6 files changed, 244 insertions, 0 deletions
diff --git a/devtools/client/accessibility/actions/accessibles.js b/devtools/client/accessibility/actions/accessibles.js
new file mode 100644
index 0000000000..085157c445
--- /dev/null
+++ b/devtools/client/accessibility/actions/accessibles.js
@@ -0,0 +1,70 @@
+/* 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 {
+ FETCH_CHILDREN,
+ SELECT,
+ HIGHLIGHT,
+ UNHIGHLIGHT,
+} = require("resource://devtools/client/accessibility/constants.js");
+
+/**
+ * Fetch child accessibles for a given accessible object.
+ * @param {Object} accessible front
+ */
+exports.fetchChildren =
+ accessible =>
+ ({ dispatch }) =>
+ accessible
+ .children()
+ .then(response =>
+ dispatch({ accessible, type: FETCH_CHILDREN, response })
+ )
+ .catch(error => dispatch({ accessible, type: FETCH_CHILDREN, error }));
+
+exports.select =
+ accessible =>
+ ({ dispatch }) => {
+ const accessibleWalkerFront = accessible.getParent();
+ if (!accessibleWalkerFront) {
+ dispatch({
+ accessible,
+ type: SELECT,
+ error: new Error("AccessibleWalker front is not available."),
+ });
+
+ return Promise.reject();
+ }
+
+ return accessibleWalkerFront
+ .getAncestry(accessible)
+ .then(response => dispatch({ accessible, type: SELECT, response }))
+ .catch(error => dispatch({ accessible, type: SELECT, error }));
+ };
+
+exports.highlight =
+ accessible =>
+ ({ dispatch }) => {
+ const accessibleWalkerFront = accessible.getParent();
+ if (!accessibleWalkerFront) {
+ dispatch({
+ accessible,
+ type: SELECT,
+ error: new Error("AccessibleWalker front is not available."),
+ });
+
+ return Promise.reject();
+ }
+
+ return accessibleWalkerFront
+ .getAncestry(accessible)
+ .then(response => dispatch({ accessible, type: HIGHLIGHT, response }))
+ .catch(error => dispatch({ accessible, type: HIGHLIGHT, error }));
+ };
+
+exports.unhighlight =
+ () =>
+ ({ dispatch }) =>
+ dispatch({ type: UNHIGHLIGHT });
diff --git a/devtools/client/accessibility/actions/audit.js b/devtools/client/accessibility/actions/audit.js
new file mode 100644
index 0000000000..7d91299eea
--- /dev/null
+++ b/devtools/client/accessibility/actions/audit.js
@@ -0,0 +1,36 @@
+/* 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 {
+ AUDIT,
+ AUDIT_PROGRESS,
+ AUDITING,
+ FILTER_TOGGLE,
+ FILTERS,
+} = require("resource://devtools/client/accessibility/constants.js");
+
+exports.filterToggle =
+ filter =>
+ ({ dispatch }) =>
+ dispatch({ filter, type: FILTER_TOGGLE });
+
+exports.auditing =
+ filter =>
+ ({ dispatch }) => {
+ const auditing = filter === FILTERS.ALL ? Object.values(FILTERS) : [filter];
+ return dispatch({ auditing, type: AUDITING });
+ };
+
+exports.audit =
+ (auditFunc, filter) =>
+ ({ dispatch }) =>
+ auditFunc(filter, progress =>
+ dispatch({ type: AUDIT_PROGRESS, progress })
+ ).then(({ error, ancestries }) => {
+ return error
+ ? dispatch({ type: AUDIT, error: true })
+ : dispatch({ type: AUDIT, response: ancestries });
+ });
diff --git a/devtools/client/accessibility/actions/details.js b/devtools/client/accessibility/actions/details.js
new file mode 100644
index 0000000000..f25996589e
--- /dev/null
+++ b/devtools/client/accessibility/actions/details.js
@@ -0,0 +1,40 @@
+/* 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 {
+ UPDATE_DETAILS,
+} = require("resource://devtools/client/accessibility/constants.js");
+
+/**
+ * Update details with the given accessible object.
+ *
+ * @param {Object} accessible front
+ */
+exports.updateDetails =
+ accessible =>
+ async ({ dispatch }) => {
+ const { walker: domWalker } = await accessible.targetFront.getFront(
+ "inspector"
+ );
+ // By the time getFront resolves, the accessibleFront may have been destroyed.
+ // This typically happens during navigations.
+ if (accessible.isDestroyed()) {
+ return;
+ }
+ try {
+ const response = await Promise.all([
+ domWalker.getNodeFromActor(accessible.actorID, [
+ "rawAccessible",
+ "DOMNode",
+ ]),
+ accessible.getRelations(),
+ accessible.audit(),
+ accessible.hydrate(),
+ ]);
+ dispatch({ accessible, type: UPDATE_DETAILS, response });
+ } catch (error) {
+ dispatch({ accessible, type: UPDATE_DETAILS, error });
+ }
+ };
diff --git a/devtools/client/accessibility/actions/moz.build b/devtools/client/accessibility/actions/moz.build
new file mode 100644
index 0000000000..c4571d7998
--- /dev/null
+++ b/devtools/client/accessibility/actions/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("accessibles.js", "audit.js", "details.js", "simulation.js", "ui.js")
diff --git a/devtools/client/accessibility/actions/simulation.js b/devtools/client/accessibility/actions/simulation.js
new file mode 100644
index 0000000000..98d69d62f3
--- /dev/null
+++ b/devtools/client/accessibility/actions/simulation.js
@@ -0,0 +1,16 @@
+/* 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 {
+ SIMULATE,
+} = require("resource://devtools/client/accessibility/constants.js");
+
+exports.simulate =
+ (simulateFunc, simTypes = []) =>
+ ({ dispatch }) =>
+ simulateFunc(simTypes)
+ .then(success => dispatch({ error: !success, simTypes, type: SIMULATE }))
+ .catch(error => dispatch({ error, type: SIMULATE }));
diff --git a/devtools/client/accessibility/actions/ui.js b/devtools/client/accessibility/actions/ui.js
new file mode 100644
index 0000000000..d4af5ba8fb
--- /dev/null
+++ b/devtools/client/accessibility/actions/ui.js
@@ -0,0 +1,77 @@
+/* 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 {
+ ENABLE,
+ RESET,
+ UPDATE_CAN_BE_DISABLED,
+ UPDATE_CAN_BE_ENABLED,
+ UPDATE_PREF,
+ PREF_KEYS,
+ UPDATE_DISPLAY_TABBING_ORDER,
+} = require("resource://devtools/client/accessibility/constants.js");
+
+/**
+ * Reset accessibility panel UI.
+ */
+exports.reset =
+ (resetAccessiblity, supports) =>
+ async ({ dispatch }) => {
+ try {
+ const { enabled, canBeDisabled, canBeEnabled } =
+ await resetAccessiblity();
+ dispatch({ enabled, canBeDisabled, canBeEnabled, supports, type: RESET });
+ } catch (error) {
+ dispatch({ type: RESET, error });
+ }
+ };
+
+/**
+ * Update a "canBeDisabled" flag for accessibility service.
+ */
+exports.updateCanBeDisabled =
+ canBeDisabled =>
+ ({ dispatch }) =>
+ dispatch({ canBeDisabled, type: UPDATE_CAN_BE_DISABLED });
+
+/**
+ * Update a "canBeEnabled" flag for accessibility service.
+ */
+exports.updateCanBeEnabled =
+ canBeEnabled =>
+ ({ dispatch }) =>
+ dispatch({ canBeEnabled, type: UPDATE_CAN_BE_ENABLED });
+
+exports.updatePref =
+ (name, value) =>
+ ({ dispatch }) => {
+ dispatch({ type: UPDATE_PREF, name, value });
+ Services.prefs.setBoolPref(PREF_KEYS[name], value);
+ };
+
+/**
+ * Enable accessibility services in order to view accessible tree.
+ */
+exports.enable =
+ enableAccessibility =>
+ async ({ dispatch }) => {
+ try {
+ await enableAccessibility();
+ dispatch({ type: ENABLE });
+ } catch (error) {
+ dispatch({ error, type: ENABLE });
+ }
+ };
+
+exports.updateDisplayTabbingOrder =
+ tabbingOrderDisplayed =>
+ async ({ dispatch, options: { toggleDisplayTabbingOrder } }) => {
+ try {
+ await toggleDisplayTabbingOrder(tabbingOrderDisplayed);
+ dispatch({ tabbingOrderDisplayed, type: UPDATE_DISPLAY_TABBING_ORDER });
+ } catch (error) {
+ dispatch({ error, type: UPDATE_DISPLAY_TABBING_ORDER });
+ }
+ };