tor-browser

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

accessibility.js (2852B)


      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 
      5 "use strict";
      6 
      7 loader.lazyRequireGetter(
      8  this,
      9  ["loadSheet", "removeSheet"],
     10  "resource://devtools/shared/layout/utils.js",
     11  true
     12 );
     13 
     14 // Highlighter style used for preventing transitions and applying transparency
     15 // when calculating colour contrast.
     16 const HIGHLIGHTER_STYLES_SHEET = `data:text/css;charset=utf-8,
     17 * {
     18  transition: initial !important;
     19 }
     20 
     21 :-moz-devtools-highlighted {
     22  color: transparent !important;
     23  text-shadow: none !important;
     24 }`;
     25 
     26 /**
     27 * Helper function that determines if nsIAccessible object is in defunct state.
     28 *
     29 * @param  {nsIAccessible}  accessible
     30 *         object to be tested.
     31 * @return {boolean}
     32 *         True if accessible object is defunct, false otherwise.
     33 */
     34 function isDefunct(accessible) {
     35  // If accessibility is disabled, safely assume that the accessible object is
     36  // now dead.
     37  if (!Services.appinfo.accessibilityEnabled) {
     38    return true;
     39  }
     40 
     41  let defunct = false;
     42 
     43  try {
     44    const extraState = {};
     45    accessible.getState({}, extraState);
     46    // extraState.value is a bitmask. We are applying bitwise AND to mask out
     47    // irrelevant states.
     48    defunct = !!(extraState.value & Ci.nsIAccessibleStates.EXT_STATE_DEFUNCT);
     49  } catch (e) {
     50    defunct = true;
     51  }
     52 
     53  return defunct;
     54 }
     55 
     56 /**
     57 * Load highlighter style sheet used for preventing transitions and
     58 * applying transparency when calculating colour contrast.
     59 *
     60 * @param  {Window} win
     61 *         Window where highlighting happens.
     62 */
     63 function loadSheetForBackgroundCalculation(win) {
     64  loadSheet(win, HIGHLIGHTER_STYLES_SHEET);
     65 }
     66 
     67 /**
     68 * Unload highlighter style sheet used for preventing transitions
     69 * and applying transparency when calculating colour contrast.
     70 *
     71 * @param  {Window} win
     72 *         Window where highlighting was happenning.
     73 */
     74 function removeSheetForBackgroundCalculation(win) {
     75  removeSheet(win, HIGHLIGHTER_STYLES_SHEET);
     76 }
     77 
     78 /**
     79 * Get role attribute for an accessible object if specified for its
     80 * corresponding DOMNode.
     81 *
     82 * @param   {nsIAccessible} accessible
     83 *          Accessible for which to determine its role attribute value.
     84 *
     85 * @returns {null | string}
     86 *          Role attribute value if specified.
     87 */
     88 function getAriaRoles(accessible) {
     89  try {
     90    return accessible.attributes.getStringProperty("xml-roles");
     91  } catch (e) {
     92    // No xml-roles. nsPersistentProperties throws if the attribute for a key
     93    // is not found.
     94  }
     95 
     96  return null;
     97 }
     98 
     99 exports.getAriaRoles = getAriaRoles;
    100 exports.isDefunct = isDefunct;
    101 exports.loadSheetForBackgroundCalculation = loadSheetForBackgroundCalculation;
    102 exports.removeSheetForBackgroundCalculation =
    103  removeSheetForBackgroundCalculation;