diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /devtools/client/accessibility/actions | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
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.js | 59 | ||||
-rw-r--r-- | devtools/client/accessibility/actions/audit.js | 30 | ||||
-rw-r--r-- | devtools/client/accessibility/actions/details.js | 36 | ||||
-rw-r--r-- | devtools/client/accessibility/actions/moz.build | 5 | ||||
-rw-r--r-- | devtools/client/accessibility/actions/simulation.js | 12 | ||||
-rw-r--r-- | devtools/client/accessibility/actions/ui.js | 69 |
6 files changed, 211 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..f156477cad --- /dev/null +++ b/devtools/client/accessibility/actions/accessibles.js @@ -0,0 +1,59 @@ +/* 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("devtools/client/accessibility/constants"); + +/** + * 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..56b81f3f3b --- /dev/null +++ b/devtools/client/accessibility/actions/audit.js @@ -0,0 +1,30 @@ +/* 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("devtools/client/accessibility/constants"); + +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..d094ef06ef --- /dev/null +++ b/devtools/client/accessibility/actions/details.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 { UPDATE_DETAILS } = require("devtools/client/accessibility/constants"); + +/** + * 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..0a09219ef5 --- /dev/null +++ b/devtools/client/accessibility/actions/simulation.js @@ -0,0 +1,12 @@ +/* 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("devtools/client/accessibility/constants"); + +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..eefdd3a9f5 --- /dev/null +++ b/devtools/client/accessibility/actions/ui.js @@ -0,0 +1,69 @@ +/* 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 Services = require("Services"); + +const { + ENABLE, + RESET, + UPDATE_CAN_BE_DISABLED, + UPDATE_CAN_BE_ENABLED, + UPDATE_PREF, + PREF_KEYS, + UPDATE_DISPLAY_TABBING_ORDER, +} = require("devtools/client/accessibility/constants"); + +/** + * 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 }); + } +}; |