summaryrefslogtreecommitdiffstats
path: root/devtools/client/accessibility/actions/ui.js
blob: d4af5ba8fbb81b9e4ae4eef4481173f4c748ce55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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 });
    }
  };