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/. */
8 } = require("resource://devtools/client/accessibility/actions/accessibles.js");
11 * Data provider that is responsible for mapping of an accessibles cache to the
12 * data format that is supported by the TreeView component.
13 * @param {Map} accessibles accessibles object cache
14 * @param {Function} dispatch react dispatch function that triggers a redux
19 constructor(accessibles
, filtered
, dispatch
) {
20 this.accessibles
= accessibles
;
21 this.filtered
= filtered
;
22 this.dispatch
= dispatch
;
26 * Get accessible's cached children if available, if not fetch them from
28 * @param {Object} accessible accessible object whose children to get.
29 * @returns {Array} arraof of accessible children.
31 getChildren(accessible
) {
32 if (!accessible
|| !accessible
.actorID
|| accessible
.childCount
=== 0) {
36 const obj
= this.accessibles
.get(accessible
.actorID
);
37 if (!obj
|| !obj
.children
) {
38 return this.dispatch(fetchChildren(accessible
));
45 * Return a flag indicating if an accessible object has any children.
46 * @param {Object} accessible accessible object whose children to get.
47 * @returns {Boolean} idicator of whether accessible object has children.
49 hasChildren(accessible
) {
50 return accessible
.childCount
> 0;
54 * Get a value for an accessible object. Used to render the second (value)
55 * column of the accessible tree. Corresponds to an accesible object name, if
57 * @param {Object} accessible accessible object
58 * @returns {String} accessible object value.
60 getValue(accessible
) {
61 return accessible
.name
|| "";
65 * Get a label for an accessible object. Used to render the first column of
66 * the accessible tree. Corresponds to an accessible object role.
67 * @param {Object} accessible accessible object
68 * @returns {String} accessible object label.
70 getLabel(accessible
) {
71 return accessible
.role
;
75 * Get a unique key for an accessible object. Corresponds to an accessible
77 * @param {Object} accessible accessible object
78 * @returns {String} a key for an accessible object.
81 return accessible
.actorID
;
85 * Get a type of an accesible object. Corresponds to the type of an accessible
87 * @param {Object} accessible accessible object
88 * @returns {String} accessible object type
91 return accessible
.typeName
;
95 * Get the depth of the accesible object in the accessibility tree. When the
96 * tree is filtered it is flattened and the level is set to 0. Otherwise use
97 * internal TreeView level.
99 * @param {Object} accessible
101 * @param {Number} defaultLevel
102 * default level provided by the TreeView component.
104 * @returns {null|Number}
105 * depth level of the accessible object.
107 getLevel(accessible
, defaultLevel
) {
108 return this.filtered
? 0 : defaultLevel
;
112 exports
.Provider
= Provider
;