accessible/src/jsat/Constants.jsm

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/src/jsat/Constants.jsm	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     1.4 +const Ci = Components.interfaces;
     1.5 +const Cu = Components.utils;
     1.6 +
     1.7 +Cu.import('resource://gre/modules/XPCOMUtils.jsm');
     1.8 +
     1.9 +this.EXPORTED_SYMBOLS = ['Roles', 'Events', 'Relations',
    1.10 +                         'Filters', 'States', 'Prefilters'];
    1.11 +
    1.12 +function ConstantsMap (aObject, aPrefix, aMap = {}, aModifier = null) {
    1.13 +  let offset = aPrefix.length;
    1.14 +  for (var name in aObject) {
    1.15 +    if (name.indexOf(aPrefix) === 0) {
    1.16 +      aMap[name.slice(offset)] = aModifier ?
    1.17 +        aModifier(aObject[name]) : aObject[name];
    1.18 +    }
    1.19 +  }
    1.20 +
    1.21 +  return aMap;
    1.22 +}
    1.23 +
    1.24 +XPCOMUtils.defineLazyGetter(
    1.25 +  this, 'Roles',
    1.26 +  function() {
    1.27 +    return ConstantsMap(Ci.nsIAccessibleRole, 'ROLE_');
    1.28 +  });
    1.29 +
    1.30 +XPCOMUtils.defineLazyGetter(
    1.31 +  this, 'Events',
    1.32 +  function() {
    1.33 +    return ConstantsMap(Ci.nsIAccessibleEvent, 'EVENT_');
    1.34 +  });
    1.35 +
    1.36 +XPCOMUtils.defineLazyGetter(
    1.37 +  this, 'Relations',
    1.38 +  function() {
    1.39 +    return ConstantsMap(Ci.nsIAccessibleRelation, 'RELATION_');
    1.40 +  });
    1.41 +
    1.42 +XPCOMUtils.defineLazyGetter(
    1.43 +  this, 'Prefilters',
    1.44 +  function() {
    1.45 +    return ConstantsMap(Ci.nsIAccessibleTraversalRule, 'PREFILTER_');
    1.46 +  });
    1.47 +
    1.48 +XPCOMUtils.defineLazyGetter(
    1.49 +  this, 'Filters',
    1.50 +  function() {
    1.51 +    return ConstantsMap(Ci.nsIAccessibleTraversalRule, 'FILTER_');
    1.52 +  });
    1.53 +
    1.54 +XPCOMUtils.defineLazyGetter(
    1.55 +  this, 'States',
    1.56 +  function() {
    1.57 +    let statesMap = ConstantsMap(Ci.nsIAccessibleStates, 'STATE_', {},
    1.58 +                                 (val) => { return { base: val, extended: 0 }; });
    1.59 +    ConstantsMap(Ci.nsIAccessibleStates, 'EXT_STATE_', statesMap,
    1.60 +                 (val) => { return { base: 0, extended: val }; });
    1.61 +    return statesMap;
    1.62 +  });

mercurial