Constants.jsm 1.5 KB

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