|
1 const Ci = Components.interfaces; |
|
2 const Cu = Components.utils; |
|
3 |
|
4 Cu.import('resource://gre/modules/XPCOMUtils.jsm'); |
|
5 |
|
6 this.EXPORTED_SYMBOLS = ['Roles', 'Events', 'Relations', |
|
7 'Filters', 'States', 'Prefilters']; |
|
8 |
|
9 function ConstantsMap (aObject, aPrefix, aMap = {}, aModifier = null) { |
|
10 let offset = aPrefix.length; |
|
11 for (var name in aObject) { |
|
12 if (name.indexOf(aPrefix) === 0) { |
|
13 aMap[name.slice(offset)] = aModifier ? |
|
14 aModifier(aObject[name]) : aObject[name]; |
|
15 } |
|
16 } |
|
17 |
|
18 return aMap; |
|
19 } |
|
20 |
|
21 XPCOMUtils.defineLazyGetter( |
|
22 this, 'Roles', |
|
23 function() { |
|
24 return ConstantsMap(Ci.nsIAccessibleRole, 'ROLE_'); |
|
25 }); |
|
26 |
|
27 XPCOMUtils.defineLazyGetter( |
|
28 this, 'Events', |
|
29 function() { |
|
30 return ConstantsMap(Ci.nsIAccessibleEvent, 'EVENT_'); |
|
31 }); |
|
32 |
|
33 XPCOMUtils.defineLazyGetter( |
|
34 this, 'Relations', |
|
35 function() { |
|
36 return ConstantsMap(Ci.nsIAccessibleRelation, 'RELATION_'); |
|
37 }); |
|
38 |
|
39 XPCOMUtils.defineLazyGetter( |
|
40 this, 'Prefilters', |
|
41 function() { |
|
42 return ConstantsMap(Ci.nsIAccessibleTraversalRule, 'PREFILTER_'); |
|
43 }); |
|
44 |
|
45 XPCOMUtils.defineLazyGetter( |
|
46 this, 'Filters', |
|
47 function() { |
|
48 return ConstantsMap(Ci.nsIAccessibleTraversalRule, 'FILTER_'); |
|
49 }); |
|
50 |
|
51 XPCOMUtils.defineLazyGetter( |
|
52 this, 'States', |
|
53 function() { |
|
54 let statesMap = ConstantsMap(Ci.nsIAccessibleStates, 'STATE_', {}, |
|
55 (val) => { return { base: val, extended: 0 }; }); |
|
56 ConstantsMap(Ci.nsIAccessibleStates, 'EXT_STATE_', statesMap, |
|
57 (val) => { return { base: 0, extended: val }; }); |
|
58 return statesMap; |
|
59 }); |