1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 * @fileoverview The cvox.NodeState typedef.
9 goog.provide('cvox.NodeState');
10 goog.provide('cvox.NodeStateUtil');
13 * Holds the state of a node. It is an Array or Arrays of strings and numbers.
14 * Each sub array is in the format:
15 * [state, opt_arg, opt_arg, ...]. These sub arrays map directly to a
16 * cvox.ChromeVox.getMsg() call. For example [list_position, 3, 5] maps to
17 * getMsg('list_position', [3, 5]);
19 * @typedef {!Array<!Array<string|number>>}
24 * Returns a localized, readable string with the NodeState.
26 * NOTE(deboer): Once AriaUtil and DomUtil are using NodeState exclusively, this
27 * function can be moved into DescriptionUtil, removing the cvox.ChromeVox
30 * @param {cvox.NodeState} state The node state.
31 * @return {string} The readable state string.
33 cvox.NodeStateUtil.expand = function(state) {
35 return state.map(function(s) {
37 throw new Error('cvox.NodeState must have at least one entry');
39 var args = s.slice(1).map(function(a) {
40 if (typeof a == 'number') {
41 return cvox.ChromeVox.msgs.getNumber(a);
45 return cvox.ChromeVox.msgs.getMsg(/** @type {string} */ (s[0]), args);
48 throw new Error('error: ' + e + ' state: ' + state);