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

Side by Side Diff: content/browser/resources/accessibility/accessibility.js

Issue 2552203005: Enable toggling of new accessibility modes in chrome://accessibility (Closed)
Patch Set: Rebase Created 4 years 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
« no previous file with comments | « content/browser/resources/accessibility/accessibility.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('accessibility', function() { 5 cr.define('accessibility', function() {
6 'use strict'; 6 'use strict';
7 7
8 // Keep in sync with view_message_enums.h
9 var AccessibilityModeFlag = {
10 Platform: 1 << 0,
11 FullTree: 1 << 1
12 }
13
14 var AccessibilityMode = {
15 Off: 0,
16 Complete:
17 AccessibilityModeFlag.Platform | AccessibilityModeFlag.FullTree,
18 EditableTextOnly: AccessibilityModeFlag.Platform,
19 TreeOnly: AccessibilityModeFlag.FullTree
20 }
21
22 function isAccessibilityComplete(mode) {
23 return ((mode & AccessibilityMode.Complete) == AccessibilityMode.Complete);
24 }
25
26 function requestData() { 8 function requestData() {
27 var xhr = new XMLHttpRequest(); 9 var xhr = new XMLHttpRequest();
28 xhr.open('GET', 'targets-data.json', false); 10 xhr.open('GET', 'targets-data.json', false);
29 xhr.send(null); 11 xhr.send(null);
30 if (xhr.status === 200) { 12 if (xhr.status === 200) {
31 console.log(xhr.responseText); 13 console.log(xhr.responseText);
32 return JSON.parse(xhr.responseText); 14 return JSON.parse(xhr.responseText);
33 } 15 }
34 return []; 16 return [];
35 } 17 }
(...skipping 15 matching lines...) Expand all
51 row.appendChild(document.createTextNode(' | ')); 33 row.appendChild(document.createTextNode(' | '));
52 row.appendChild(createShowAccessibilityTreeElement(data, row, false)); 34 row.appendChild(createShowAccessibilityTreeElement(data, row, false));
53 } 35 }
54 } 36 }
55 37
56 function requestAccessibilityTree(data, element) { 38 function requestAccessibilityTree(data, element) {
57 chrome.send('requestAccessibilityTree', 39 chrome.send('requestAccessibilityTree',
58 [String(data.processId), String(data.routeId)]); 40 [String(data.processId), String(data.routeId)]);
59 } 41 }
60 42
61 function toggleGlobalAccessibility() {
62 chrome.send('toggleGlobalAccessibility');
63 document.location.reload(); // FIXME see TODO above
64 }
65
66 function toggleInternalTree() {
67 chrome.send('toggleInternalTree');
68 document.location.reload(); // FIXME see TODO above
69 }
70
71 function initialize() { 43 function initialize() {
72 console.log('initialize'); 44 console.log('initialize');
73 var data = requestData(); 45 var data = requestData();
74 46
75 addGlobalAccessibilityModeToggle(data['global_a11y_mode']); 47 bindCheckbox('native', data['native']);
76 48 bindCheckbox('web', data['web']);
77 addInternalTreeToggle(data['global_internal_tree_mode']); 49 bindCheckbox('text', data['text']);
50 bindCheckbox('screenreader', data['screenreader']);
51 bindCheckbox('html', data['html']);
52 bindCheckbox('internal', data['internal']);
78 53
79 $('pages').textContent = ''; 54 $('pages').textContent = '';
80 55
81 var list = data['list']; 56 var list = data['list'];
82 for (var i = 0; i < list.length; i++) { 57 for (var i = 0; i < list.length; i++) {
83 addToPagesList(list[i]); 58 addToPagesList(list[i]);
84 } 59 }
85 } 60 }
86 61
87 function addGlobalAccessibilityModeToggle(global_a11y_mode) { 62 function bindCheckbox(name, value) {
88 var full_a11y_on = isAccessibilityComplete(global_a11y_mode); 63 if (value == 'on')
89 $('toggle_global').textContent = (full_a11y_on ? 'on' : 'off'); 64 $(name).checked = true;
90 $('toggle_global').setAttribute('aria-pressed', 65 if (value == 'disabled') {
91 (full_a11y_on ? 'true' : 'false')); 66 $(name).disabled = true;
92 $('toggle_global').addEventListener('click', 67 $(name).labels[0].classList.add('disabled');
93 toggleGlobalAccessibility); 68 }
94 } 69 $(name).addEventListener('change', function() {
95 70 chrome.send('setGlobalFlag', [name, $(name).checked]);
96 function addInternalTreeToggle(global_internal_tree_mode) { 71 document.location.reload(); // FIXME see TODO above
97 var on = global_internal_tree_mode; 72 });
98 $('toggle_internal').textContent = (on ? 'on' : 'off');
99 $('toggle_internal').setAttribute('aria-pressed',
100 (on ? 'true' : 'false'));
101 $('toggle_internal').addEventListener('click',
102 toggleInternalTree);
103 } 73 }
104 74
105 function addToPagesList(data) { 75 function addToPagesList(data) {
106 // TODO: iterate through data and pages rows instead 76 // TODO: iterate through data and pages rows instead
107 var id = data['processId'] + '.' + data['routeId']; 77 var id = data['processId'] + '.' + data['routeId'];
108 var row = document.createElement('div'); 78 var row = document.createElement('div');
109 row.className = 'row'; 79 row.className = 'row';
110 row.id = id; 80 row.id = id;
111 formatRow(row, data); 81 formatRow(row, data);
112 82
113 row.processId = data.processId; 83 row.processId = data.processId;
114 row.routeId = data.routeId; 84 row.routeId = data.routeId;
115 85
116 var list = $('pages'); 86 var list = $('pages');
117 list.appendChild(row); 87 list.appendChild(row);
118 } 88 }
119 89
120 function formatRow(row, data) { 90 function formatRow(row, data) {
121 if (!('url' in data)) { 91 if (!('url' in data)) {
122 if ('error' in data) { 92 if ('error' in data) {
123 row.appendChild(createErrorMessageElement(data, row)); 93 row.appendChild(createErrorMessageElement(data, row));
124 return; 94 return;
125 } 95 }
126 } 96 }
127 var properties = ['favicon_url', 'name', 'url']; 97 var properties = ['favicon_url', 'name', 'url'];
128 for (var j = 0; j < properties.length; j++) 98 for (var j = 0; j < properties.length; j++)
129 row.appendChild(formatValue(data, properties[j])); 99 row.appendChild(formatValue(data, properties[j]));
130 100
131 row.appendChild(createToggleAccessibilityElement(data)); 101 row.appendChild(createToggleAccessibilityElement(data));
132 if (isAccessibilityComplete(data['a11y_mode'])) { 102 if (data['a11y_mode']) {
133 row.appendChild(document.createTextNode(' | ')); 103 row.appendChild(document.createTextNode(' | '));
134 if ('tree' in data) { 104 if ('tree' in data) {
135 row.appendChild(createShowAccessibilityTreeElement(data, row, true)); 105 row.appendChild(createShowAccessibilityTreeElement(data, row, true));
136 row.appendChild(document.createTextNode(' | ')); 106 row.appendChild(document.createTextNode(' | '));
137 row.appendChild(createHideAccessibilityTreeElement(row.id)); 107 row.appendChild(createHideAccessibilityTreeElement(row.id));
138 row.appendChild(createAccessibilityTreeElement(data)); 108 row.appendChild(createAccessibilityTreeElement(data));
139 } 109 }
140 else { 110 else {
141 row.appendChild(createShowAccessibilityTreeElement(data, row, false)); 111 row.appendChild(createShowAccessibilityTreeElement(data, row, false));
142 if ('error' in data) 112 if ('error' in data)
(...skipping 19 matching lines...) Expand all
162 132
163 var span = document.createElement('span'); 133 var span = document.createElement('span');
164 span.textContent = ' ' + text + ' '; 134 span.textContent = ' ' + text + ' ';
165 span.className = property; 135 span.className = property;
166 return span; 136 return span;
167 } 137 }
168 138
169 function createToggleAccessibilityElement(data) { 139 function createToggleAccessibilityElement(data) {
170 var link = document.createElement('a', 'action-link'); 140 var link = document.createElement('a', 'action-link');
171 link.setAttribute('role', 'button'); 141 link.setAttribute('role', 'button');
172 var full_a11y_on = isAccessibilityComplete(data['a11y_mode']); 142 var full_a11y_on = data['a11y_mode'];
173 link.textContent = 'accessibility ' + (full_a11y_on ? 'on' : 'off'); 143 link.textContent = 'accessibility ' + (full_a11y_on ? 'on' : 'off');
174 link.setAttribute('aria-pressed', (full_a11y_on ? 'true' : 'false')); 144 link.setAttribute('aria-pressed', (full_a11y_on ? 'true' : 'false'));
175 link.addEventListener('click', 145 link.addEventListener('click',
176 toggleAccessibility.bind(this, data, link)); 146 toggleAccessibility.bind(this, data, link));
177 return link; 147 return link;
178 } 148 }
179 149
180 function createShowAccessibilityTreeElement(data, row, opt_refresh) { 150 function createShowAccessibilityTreeElement(data, row, opt_refresh) {
181 var link = document.createElement('a', 'action-link'); 151 var link = document.createElement('a', 'action-link');
182 link.setAttribute('role', 'button'); 152 link.setAttribute('role', 'button');
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 return treeElement; 211 return treeElement;
242 } 212 }
243 213
244 return { 214 return {
245 initialize: initialize, 215 initialize: initialize,
246 showTree: showTree 216 showTree: showTree
247 }; 217 };
248 }); 218 });
249 219
250 document.addEventListener('DOMContentLoaded', accessibility.initialize); 220 document.addEventListener('DOMContentLoaded', accessibility.initialize);
OLDNEW
« no previous file with comments | « content/browser/resources/accessibility/accessibility.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698