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

Side by Side Diff: ui/webui/resources/js/cr/ui/tree.js

Issue 2201033004: Improved accessibility of treeview control used in internal pages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « no previous file | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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('cr.ui', function() { 5 cr.define('cr.ui', function() {
6 // require cr.ui.define 6 // require cr.ui.define
7 // require cr.ui.limitInputWidth 7 // require cr.ui.limitInputWidth
8 8
9 /** 9 /**
10 * The number of pixels to indent per level. 10 * The number of pixels to indent per level.
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 * This is used as a blueprint for new tree item elements. 249 * This is used as a blueprint for new tree item elements.
250 * @type {!HTMLElement} 250 * @type {!HTMLElement}
251 */ 251 */
252 var treeItemProto = (function() { 252 var treeItemProto = (function() {
253 var treeItem = cr.doc.createElement('div'); 253 var treeItem = cr.doc.createElement('div');
254 treeItem.className = 'tree-item'; 254 treeItem.className = 'tree-item';
255 treeItem.innerHTML = '<div class=tree-row>' + 255 treeItem.innerHTML = '<div class=tree-row>' +
256 '<span class=expand-icon></span>' + 256 '<span class=expand-icon></span>' +
257 '<span class=tree-label></span>' + 257 '<span class=tree-label></span>' +
258 '</div>' + 258 '</div>' +
259 '<div class=tree-children></div>'; 259 '<div class=tree-children role=group></div>';
dpapad 2016/08/03 20:31:19 All those class= statements are missing quotes, sh
260 treeItem.setAttribute('role', 'treeitem'); 260 treeItem.setAttribute('role', 'treeitem');
261 return treeItem; 261 return treeItem;
262 })(); 262 })();
263 263
264 /** 264 /**
265 * Creates a new tree item. 265 * Creates a new tree item.
266 * @param {Object=} opt_propertyBag Optional properties. 266 * @param {Object=} opt_propertyBag Optional properties.
267 * @constructor 267 * @constructor
268 * @extends {HTMLElement} 268 * @extends {HTMLElement}
269 */ 269 */
270 var TreeItem = cr.ui.define(function() { 270 var TreeItem = cr.ui.define(function() {
271 var treeItem = treeItemProto.cloneNode(true); 271 var treeItem = treeItemProto.cloneNode(true);
272 treeItem.id = 'tree-item-autogen-id-' + treeItemAutoGeneratedIdCounter++; 272 treeItem.id = 'tree-item-autogen-id-' + treeItemAutoGeneratedIdCounter++;
273 return treeItem; 273 return treeItem;
274 }); 274 });
275 275
276 TreeItem.prototype = { 276 TreeItem.prototype = {
277 __proto__: HTMLElement.prototype, 277 __proto__: HTMLElement.prototype,
278 278
279 /** 279 /**
280 * Initializes the element. 280 * Initializes the element.
281 */ 281 */
282 decorate: function() { 282 decorate: function() {
283 283 var labelId = 'tree-item-label-autogen-id-' +
284 treeItemAutoGeneratedIdCounter;
285 this.labelElement.id = labelId;
286 this.setAttribute('aria-labelledby', labelId);
284 }, 287 },
285 288
286 /** 289 /**
287 * The tree items children. 290 * The tree items children.
288 */ 291 */
289 get items() { 292 get items() {
290 return this.lastElementChild.children; 293 return this.lastElementChild.children;
291 }, 294 },
292 295
293 /** 296 /**
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 }, 389 },
387 set expanded(b) { 390 set expanded(b) {
388 if (this.expanded == b) 391 if (this.expanded == b)
389 return; 392 return;
390 393
391 var treeChildren = this.lastElementChild; 394 var treeChildren = this.lastElementChild;
392 395
393 if (b) { 396 if (b) {
394 if (this.mayHaveChildren_) { 397 if (this.mayHaveChildren_) {
395 this.setAttribute('expanded', ''); 398 this.setAttribute('expanded', '');
399 this.setAttribute('aria-expanded', 'true');
396 treeChildren.setAttribute('expanded', ''); 400 treeChildren.setAttribute('expanded', '');
397 cr.dispatchSimpleEvent(this, 'expand', true); 401 cr.dispatchSimpleEvent(this, 'expand', true);
398 this.scrollIntoViewIfNeeded(false); 402 this.scrollIntoViewIfNeeded(false);
399 } 403 }
400 } else { 404 } else {
401 var tree = this.tree; 405 var tree = this.tree;
402 if (tree && !this.selected) { 406 if (tree && !this.selected) {
403 var oldSelected = tree.selectedItem; 407 var oldSelected = tree.selectedItem;
404 if (oldSelected && this.contains(oldSelected)) 408 if (oldSelected && this.contains(oldSelected))
405 this.selected = true; 409 this.selected = true;
406 } 410 }
407 this.removeAttribute('expanded'); 411 this.removeAttribute('expanded');
412 if (this.mayHaveChildren_) {
dpapad 2016/08/03 20:31:19 Nit: No need for curly braces.
413 this.setAttribute('aria-expanded', 'false');
414 } else {
415 this.removeAttribute('aria-expanded');
416 }
408 treeChildren.removeAttribute('expanded'); 417 treeChildren.removeAttribute('expanded');
409 cr.dispatchSimpleEvent(this, 'collapse', true); 418 cr.dispatchSimpleEvent(this, 'collapse', true);
410 } 419 }
411 }, 420 },
412 421
413 /** 422 /**
414 * Expands all parent items. 423 * Expands all parent items.
415 */ 424 */
416 reveal: function() { 425 reveal: function() {
417 var pi = this.parentItem; 426 var pi = this.parentItem;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 }, 522 },
514 523
515 /** 524 /**
516 * Whether the tree item has children. 525 * Whether the tree item has children.
517 * @type {boolean} 526 * @type {boolean}
518 */ 527 */
519 set hasChildren(b) { 528 set hasChildren(b) {
520 var rowItem = this.firstElementChild; 529 var rowItem = this.firstElementChild;
521 this.setAttribute('has-children', b); 530 this.setAttribute('has-children', b);
522 rowItem.setAttribute('has-children', b); 531 rowItem.setAttribute('has-children', b);
523 if (b) 532 if (b) {
524 this.mayHaveChildren_ = true; 533 this.mayHaveChildren_ = true;
534 this.setAttribute('aria-expanded', 'false');
535 }
525 }, 536 },
526 537
527 /** 538 /**
528 * Called when the user clicks on a tree item. This is forwarded from the 539 * Called when the user clicks on a tree item. This is forwarded from the
529 * cr.ui.Tree. 540 * cr.ui.Tree.
530 * @param {Event} e The click event. 541 * @param {Event} e The click event.
531 */ 542 */
532 handleClick: function(e) { 543 handleClick: function(e) {
533 if (e.target.className == 'expand-icon') 544 if (e.target.className == 'expand-icon')
534 this.expanded = !this.expanded; 545 this.expanded = !this.expanded;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 } 699 }
689 return item; 700 return item;
690 } 701 }
691 702
692 // Export 703 // Export
693 return { 704 return {
694 Tree: Tree, 705 Tree: Tree,
695 TreeItem: TreeItem 706 TreeItem: TreeItem
696 }; 707 };
697 }); 708 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698