Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Side by Side Diff: chrome/browser/resources/access_chromevox/common/aria_util.js

Issue 6254007: Adding ChromeVox as a component extensions (enabled only for ChromeOS, for no... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:executable
+ *
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
5 /**
6 * @fileoverview A collection of JavaScript utilities used to simplify working
7 * with ARIA (http://www.w3.org/TR/wai-aria).
8 */
9
10
11 goog.provide('cvox.AriaUtil');
12
13
14 /**
15 * Create the namespace
16 * @constructor
17 */
18 cvox.AriaUtil = function() {
19 };
20
21 /**
22 * @type {string}
23 */
24 cvox.AriaUtil.MIN = 'Min ';
25
26 /**
27 * @type {string}
28 */
29 cvox.AriaUtil.MAX = 'Max ';
30
31 /**
32 * @type {Object.<string, string>}
33 */
34 cvox.AriaUtil.WIDGET_ROLE_TO_NAME = {
35 'alert' : 'Alert',
36 'alertdialog' : 'Alert dialog',
37 'button' : 'Button',
38 'checkbox' : 'Check box',
39 'combobox' : 'Combo box',
40 'dialog' : 'Dialog',
41 'gridcell' : 'Grid cell',
42 'link' : 'Link',
43 'log' : 'Log',
44 'marquee' : 'Marquee',
45 'menuitem' : 'Menu item',
46 'menuitemcheckbox' : 'Menu item check box',
47 'menuitemradio' : 'Menu item radio button',
48 'option' : 'Option',
49 'progressbar' : 'Progress bar',
50 'radio' : 'Radio button',
51 'radiogroup' : 'Radio button group',
52 'scrollbar' : 'Scroll bar',
53 'slider' : 'Slider',
54 'spinbutton' : 'Spin button',
55 'status' : 'Status',
56 'tab' : 'Tab',
57 'tabpanel' : 'Tab panel',
58 'textbox' : 'Text box',
59 'timer' : 'Timer',
60 'toolbar' : 'Tool bar',
61 'tooltip' : 'Tool tip',
62 'treeitem' : 'Tree item'
63 };
64
65 /**
66 * @type {Object.<string, string>}
67 */
68 cvox.AriaUtil.STRUCTURE_ROLE_TO_NAME = {
69 'article' : 'Article',
70 'columnheader' : 'Column header',
71 'definition' : 'Definition',
72 'directory' : 'Directory',
73 'document' : 'Document',
74 'group' : 'Group',
75 'heading' : 'Heading',
76 'img' : 'Image',
77 'list' : 'List',
78 'listitem' : 'List item',
79 'math' : 'Math',
80 'note' : 'Note',
81 'region' : 'Region',
82 'row' : 'Row',
83 'rowheader' : 'Row header',
84 'separator' : 'Separator'
85 };
86
87 /**
88 * @type {Array.<Object>}
89 */
90 cvox.AriaUtil.ATTRIBUTE_VALUE_TO_STATUS = [
91 { name: 'aria-autocomplete', values:
92 {'inline': 'Autocompletion inline', 'list': 'Autocompletion list',
93 'both': 'Autocompletion inline and list'} },
94 { name: 'aria-checked', values:
95 {'true': 'Checked', 'false': 'Not checked',
96 'mixed': 'Partially checked'} },
97 { name: 'aria-disabled', values: {'true': 'Disabled'} },
98 { name: 'aria-expanded', values:
99 {'true': 'Expanded', 'false': 'Collapsed'} },
100 { name: 'aria-haspopup', values: {'true': 'Has pop up'} },
101 { name: 'aria-invalid', values:
102 {'true': 'Invalid input', 'grammar': 'Grammatical mistake detected',
103 'spelling': 'Spelling mistake detected'} },
104 { name: 'aria-multiline', values: {'true': 'Multi line'} },
105 { name: 'aria-multiselectable', values: {'true': 'Multi select'} },
106 { name: 'aria-pressed', values:
107 {'true': 'Pressed', 'false': 'Not pressed',
108 'mixed': 'Partially pressed'} },
109 { name: 'aria-readonly', values: {'true': 'Read only'} },
110 { name: 'aria-required', values: {'true': 'Required'} },
111 { name: 'aria-selected', values:
112 {'true': 'Selected', 'false': 'Not selected'} }
113 ];
114
115 /**
116 * Checks if a node should be treated as a hidden node because of its ARIA
117 * markup.
118 *
119 * @param {Object} targetNode The node to check.
120 * @return {boolean} True if the targetNode should be treated as hidden.
121 */
122 cvox.AriaUtil.isHidden = function(targetNode) {
123 while (targetNode) {
124 if (targetNode.getAttribute) {
125 if (targetNode.getAttribute('role') == 'presentation') {
126 return true;
127 }
128 if (targetNode.getAttribute('aria-hidden') == 'true') {
129 return true;
130 }
131 }
132 targetNode = targetNode.parentNode;
133 }
134 return false;
135 };
136
137 /**
138 * Returns a string to be presented to the user that identifies what the
139 * targetNode's role is.
140 *
141 * @param {Object} targetNode The node to get the role name for.
142 * @return {string} The role name for the targetNode.
143 */
144 cvox.AriaUtil.getRoleName = function(targetNode) {
145 var roleName;
146 if (targetNode && targetNode.getAttribute) {
147 var role = targetNode.getAttribute('role');
148 roleName = cvox.AriaUtil.WIDGET_ROLE_TO_NAME[role];
149 if (!roleName) {
150 roleName = cvox.AriaUtil.STRUCTURE_ROLE_TO_NAME[role];
151 }
152 }
153 if (!roleName) {
154 roleName = '';
155 }
156 return roleName;
157 };
158
159 /**
160 * Returns a string that gives information about the state of the targetNode.
161 *
162 * @param {Object} targetNode The node to get the state information for.
163 * @return {string} The status information about the node.
164 */
165 cvox.AriaUtil.getState = function(targetNode) {
166 var state = '';
167 if (targetNode && targetNode.getAttribute) {
168 for (var i = 0, attr; attr = cvox.AriaUtil.ATTRIBUTE_VALUE_TO_STATUS[i];
169 i++) {
170 var value = targetNode.getAttribute(attr.name);
171 var status = attr.values[value];
172 if (status) {
173 state = state + ' ' + status;
174 }
175 }
176 // Add in the numeric/textual values
177 if (targetNode.getAttribute('aria-valuetext')) {
178 state = state + ' ' + targetNode.getAttribute('aria-valuetext');
179 } else if (targetNode.getAttribute('aria-valuenow')) {
180 state = state + ' ' + targetNode.getAttribute('aria-valuenow');
181 }
182 if (targetNode.getAttribute('aria-valuemin')) {
183 state = state + ' ' + cvox.AriaUtil.MIN +
184 targetNode.getAttribute('aria-valuemin');
185 }
186 if (targetNode.getAttribute('aria-valuemax')) {
187 state = state + ' ' + cvox.AriaUtil.MAX +
188 targetNode.getAttribute('aria-valuemax');
189 }
190 }
191 return state;
192 };
193
194 /**
195 * Given a node, returns true if it's an ARIA control widget.
196 *
197 * @param {Object} targetNode The node to be checked.
198 * @return {boolean} Whether the targetNode is an ARIA control widget.
199 */
200 cvox.AriaUtil.isControlWidget = function(targetNode) {
201 if (targetNode && targetNode.getAttribute) {
202 var role = targetNode.getAttribute('role');
203 switch (role) {
204 case 'button':
205 case 'checkbox':
206 case 'combobox':
207 case 'menuitemcheckbox':
208 case 'menuitemradio':
209 case 'radio':
210 case 'slider':
211 case 'spinbutton':
212 case 'textbox':
213 return true;
214 }
215 }
216 return false;
217 };
218
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698