summaryrefslogtreecommitdiff
path: root/accessible/jsat/Constants.jsm
blob: 1526044316defd9e1cd6634359d17e7cfe745649 (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
const Ci = Components.interfaces;
const Cu = Components.utils;

Cu.import('resource://gre/modules/XPCOMUtils.jsm');

this.EXPORTED_SYMBOLS = ['Roles', 'Events', 'Relations',
                         'Filters', 'States', 'Prefilters'];

function ConstantsMap (aObject, aPrefix, aMap = {}, aModifier = null) {
  let offset = aPrefix.length;
  for (var name in aObject) {
    if (name.indexOf(aPrefix) === 0) {
      aMap[name.slice(offset)] = aModifier ?
        aModifier(aObject[name]) : aObject[name];
    }
  }

  return aMap;
}

XPCOMUtils.defineLazyGetter(
  this, 'Roles',
  function() {
    return ConstantsMap(Ci.nsIAccessibleRole, 'ROLE_');
  });

XPCOMUtils.defineLazyGetter(
  this, 'Events',
  function() {
    return ConstantsMap(Ci.nsIAccessibleEvent, 'EVENT_');
  });

XPCOMUtils.defineLazyGetter(
  this, 'Relations',
  function() {
    return ConstantsMap(Ci.nsIAccessibleRelation, 'RELATION_');
  });

XPCOMUtils.defineLazyGetter(
  this, 'Prefilters',
  function() {
    return ConstantsMap(Ci.nsIAccessibleTraversalRule, 'PREFILTER_');
  });

XPCOMUtils.defineLazyGetter(
  this, 'Filters',
  function() {
    return ConstantsMap(Ci.nsIAccessibleTraversalRule, 'FILTER_');
  });

XPCOMUtils.defineLazyGetter(
  this, 'States',
  function() {
    let statesMap = ConstantsMap(Ci.nsIAccessibleStates, 'STATE_', {},
                                 (val) => { return { base: val, extended: 0 }; });
    ConstantsMap(Ci.nsIAccessibleStates, 'EXT_STATE_', statesMap,
                 (val) => { return { base: 0, extended: val }; });
    return statesMap;
  });