tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

accessibles.js (1903B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 "use strict";
      5 
      6 const {
      7  FETCH_CHILDREN,
      8  SELECT,
      9  HIGHLIGHT,
     10  UNHIGHLIGHT,
     11 } = require("resource://devtools/client/accessibility/constants.js");
     12 
     13 /**
     14 * Fetch child accessibles for a given accessible object.
     15 *
     16 * @param {object} accessible front
     17 */
     18 exports.fetchChildren =
     19  accessible =>
     20  ({ dispatch }) =>
     21    accessible
     22      .children()
     23      .then(response =>
     24        dispatch({ accessible, type: FETCH_CHILDREN, response })
     25      )
     26      .catch(error => dispatch({ accessible, type: FETCH_CHILDREN, error }));
     27 
     28 exports.select =
     29  accessible =>
     30  ({ dispatch }) => {
     31    const accessibleWalkerFront = accessible.getParent();
     32    if (!accessibleWalkerFront) {
     33      dispatch({
     34        accessible,
     35        type: SELECT,
     36        error: new Error("AccessibleWalker front is not available."),
     37      });
     38 
     39      return Promise.reject();
     40    }
     41 
     42    return accessibleWalkerFront
     43      .getAncestry(accessible)
     44      .then(response => dispatch({ accessible, type: SELECT, response }))
     45      .catch(error => dispatch({ accessible, type: SELECT, error }));
     46  };
     47 
     48 exports.highlight =
     49  accessible =>
     50  ({ dispatch }) => {
     51    const accessibleWalkerFront = accessible.getParent();
     52    if (!accessibleWalkerFront) {
     53      dispatch({
     54        accessible,
     55        type: SELECT,
     56        error: new Error("AccessibleWalker front is not available."),
     57      });
     58 
     59      return Promise.reject();
     60    }
     61 
     62    return accessibleWalkerFront
     63      .getAncestry(accessible)
     64      .then(response => dispatch({ accessible, type: HIGHLIGHT, response }))
     65      .catch(error => dispatch({ accessible, type: HIGHLIGHT, error }));
     66  };
     67 
     68 exports.unhighlight =
     69  () =>
     70  ({ dispatch }) =>
     71    dispatch({ type: UNHIGHLIGHT });