Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 this._comparator = null; | 41 this._comparator = null; |
| 42 | 42 |
| 43 this.contentElement = this._rootElement._childrenListNode; | 43 this.contentElement = this._rootElement._childrenListNode; |
| 44 this.contentElement.addEventListener('keydown', this._treeKeyDown.bind(this) , true); | 44 this.contentElement.addEventListener('keydown', this._treeKeyDown.bind(this) , true); |
| 45 | 45 |
| 46 this._focusable = true; | 46 this._focusable = true; |
| 47 this.setFocusable(this._focusable); | 47 this.setFocusable(this._focusable); |
| 48 if (this._focusable) | 48 if (this._focusable) |
| 49 this.contentElement.setAttribute('tabIndex', -1); | 49 this.contentElement.setAttribute('tabIndex', -1); |
| 50 this.element = this.contentElement; | 50 this.element = this.contentElement; |
| 51 UI.ARIAUtils.markAsTree(this.element); | |
| 51 | 52 |
| 52 // Adjust to allow computing margin-left for the selection element. | 53 // Adjust to allow computing margin-left for the selection element. |
| 53 // Check the padding-left for the li element for correct value. | 54 // Check the padding-left for the li element for correct value. |
| 54 this._paddingSize = 0; | 55 this._paddingSize = 0; |
| 55 } | 56 } |
| 56 | 57 |
| 57 _createRootElement() { | 58 _createRootElement() { |
| 58 this._rootElement = new UI.TreeElement(); | 59 this._rootElement = new UI.TreeElement(); |
| 59 this._rootElement.treeOutline = this; | 60 this._rootElement.treeOutline = this; |
| 60 this._rootElement.root = true; | 61 this._rootElement.root = true; |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 this._boundOnBlur = this._onBlur.bind(this); | 330 this._boundOnBlur = this._onBlur.bind(this); |
| 330 | 331 |
| 331 this._listItemNode = createElement('li'); | 332 this._listItemNode = createElement('li'); |
| 332 this._titleElement = this._listItemNode.createChild('span', 'tree-element-ti tle'); | 333 this._titleElement = this._listItemNode.createChild('span', 'tree-element-ti tle'); |
| 333 this._listItemNode.treeElement = this; | 334 this._listItemNode.treeElement = this; |
| 334 if (title) | 335 if (title) |
| 335 this.title = title; | 336 this.title = title; |
| 336 this._listItemNode.addEventListener('mousedown', this._handleMouseDown.bind( this), false); | 337 this._listItemNode.addEventListener('mousedown', this._handleMouseDown.bind( this), false); |
| 337 this._listItemNode.addEventListener('click', this._treeElementToggled.bind(t his), false); | 338 this._listItemNode.addEventListener('click', this._treeElementToggled.bind(t his), false); |
| 338 this._listItemNode.addEventListener('dblclick', this._handleDoubleClick.bind (this), false); | 339 this._listItemNode.addEventListener('dblclick', this._handleDoubleClick.bind (this), false); |
| 340 UI.ARIAUtils.markAsTreeitem(this._listItemNode); | |
|
hhillen
2017/02/05 21:41:11
Screen readers are currently announcing "aa" for t
einbinder
2017/02/07 21:12:58
We should be able to replace them with content: '\
hhillen
2017/02/09 02:18:41
Done
| |
| 339 | 341 |
| 340 this._childrenListNode = createElement('ol'); | 342 this._childrenListNode = createElement('ol'); |
| 341 this._childrenListNode.parentTreeElement = this; | 343 this._childrenListNode.parentTreeElement = this; |
| 342 this._childrenListNode.classList.add('children'); | 344 this._childrenListNode.classList.add('children'); |
| 345 UI.ARIAUtils.markAsGroup(this._childrenListNode); | |
| 343 | 346 |
| 344 this._hidden = false; | 347 this._hidden = false; |
| 345 this._selectable = true; | 348 this._selectable = true; |
| 346 this.expanded = false; | 349 this.expanded = false; |
| 347 this.selected = false; | 350 this.selected = false; |
| 348 this.setExpandable(expandable || false); | 351 this.setExpandable(expandable || false); |
| 349 this._collapsible = true; | 352 this._collapsible = true; |
| 350 } | 353 } |
| 351 | 354 |
| 352 /** | 355 /** |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 698 /** | 701 /** |
| 699 * @param {boolean} expandable | 702 * @param {boolean} expandable |
| 700 */ | 703 */ |
| 701 setExpandable(expandable) { | 704 setExpandable(expandable) { |
| 702 if (this._expandable === expandable) | 705 if (this._expandable === expandable) |
| 703 return; | 706 return; |
| 704 | 707 |
| 705 this._expandable = expandable; | 708 this._expandable = expandable; |
| 706 | 709 |
| 707 this._listItemNode.classList.toggle('parent', expandable); | 710 this._listItemNode.classList.toggle('parent', expandable); |
| 708 if (!expandable) | 711 if (!expandable) { |
| 709 this.collapse(); | 712 this.collapse(); |
| 713 this._listItemNode.removeAttribute('aria-expanded'); | |
|
hhillen
2017/02/05 21:41:11
@einbinder Would you prefer a dedicated method in
einbinder
2017/02/07 21:12:57
Yeah. It feels weird because expandable false is d
hhillen
2017/02/09 02:18:41
Done
| |
| 714 } else { | |
| 715 UI.ARIAUtils.setExpanded(this._listItemNode, false); | |
| 716 } | |
| 710 } | 717 } |
| 711 | 718 |
| 712 /** | 719 /** |
| 713 * @param {boolean} collapsible | 720 * @param {boolean} collapsible |
| 714 */ | 721 */ |
| 715 setCollapsible(collapsible) { | 722 setCollapsible(collapsible) { |
| 716 if (this._collapsible === collapsible) | 723 if (this._collapsible === collapsible) |
| 717 return; | 724 return; |
| 718 | 725 |
| 719 this._collapsible = collapsible; | 726 this._collapsible = collapsible; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 831 _detach() { | 838 _detach() { |
| 832 this._listItemNode.remove(); | 839 this._listItemNode.remove(); |
| 833 this._childrenListNode.remove(); | 840 this._childrenListNode.remove(); |
| 834 } | 841 } |
| 835 | 842 |
| 836 collapse() { | 843 collapse() { |
| 837 if (!this.expanded || !this._collapsible) | 844 if (!this.expanded || !this._collapsible) |
| 838 return; | 845 return; |
| 839 this._listItemNode.classList.remove('expanded'); | 846 this._listItemNode.classList.remove('expanded'); |
| 840 this._childrenListNode.classList.remove('expanded'); | 847 this._childrenListNode.classList.remove('expanded'); |
| 848 UI.ARIAUtils.setExpanded(this._listItemNode, false); | |
| 841 this.expanded = false; | 849 this.expanded = false; |
| 842 this.oncollapse(); | 850 this.oncollapse(); |
| 843 if (this.treeOutline) | 851 if (this.treeOutline) |
| 844 this.treeOutline.dispatchEventToListeners(UI.TreeOutline.Events.ElementCol lapsed, this); | 852 this.treeOutline.dispatchEventToListeners(UI.TreeOutline.Events.ElementCol lapsed, this); |
| 845 } | 853 } |
| 846 | 854 |
| 847 collapseRecursively() { | 855 collapseRecursively() { |
| 848 var item = this; | 856 var item = this; |
| 849 while (item) { | 857 while (item) { |
| 850 if (item.expanded) | 858 if (item.expanded) |
| 851 item.collapse(); | 859 item.collapse(); |
| 852 item = item.traverseNextTreeElement(false, this, true); | 860 item = item.traverseNextTreeElement(false, this, true); |
| 853 } | 861 } |
| 854 } | 862 } |
| 855 | 863 |
| 856 expand() { | 864 expand() { |
| 857 if (!this._expandable || (this.expanded && this._children)) | 865 if (!this._expandable || (this.expanded && this._children)) |
| 858 return; | 866 return; |
| 859 | 867 |
| 860 // Set this before onpopulate. Since onpopulate can add elements, this makes | 868 // Set this before onpopulate. Since onpopulate can add elements, this makes |
| 861 // sure the expanded flag is true before calling those functions. This preve nts the possibility | 869 // sure the expanded flag is true before calling those functions. This preve nts the possibility |
| 862 // of an infinite loop if onpopulate were to call expand. | 870 // of an infinite loop if onpopulate were to call expand. |
| 863 | 871 |
| 864 this.expanded = true; | 872 this.expanded = true; |
| 865 | 873 |
| 866 this._populateIfNeeded(); | 874 this._populateIfNeeded(); |
| 867 this._listItemNode.classList.add('expanded'); | 875 this._listItemNode.classList.add('expanded'); |
| 868 this._childrenListNode.classList.add('expanded'); | 876 this._childrenListNode.classList.add('expanded'); |
| 877 UI.ARIAUtils.setExpanded(this._listItemNode, true); | |
| 869 | 878 |
| 870 if (this.treeOutline) { | 879 if (this.treeOutline) { |
| 871 this.onexpand(); | 880 this.onexpand(); |
| 872 this.treeOutline.dispatchEventToListeners(UI.TreeOutline.Events.ElementExp anded, this); | 881 this.treeOutline.dispatchEventToListeners(UI.TreeOutline.Events.ElementExp anded, this); |
| 873 } | 882 } |
| 874 } | 883 } |
| 875 | 884 |
| 876 /** | 885 /** |
| 877 * @param {number=} maxDepth | 886 * @param {number=} maxDepth |
| 878 */ | 887 */ |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1206 var paddingLeftValue = window.getComputedStyle(this._listItemNode).paddingLe ft; | 1215 var paddingLeftValue = window.getComputedStyle(this._listItemNode).paddingLe ft; |
| 1207 console.assert(paddingLeftValue.endsWith('px')); | 1216 console.assert(paddingLeftValue.endsWith('px')); |
| 1208 var computedLeftPadding = parseFloat(paddingLeftValue); | 1217 var computedLeftPadding = parseFloat(paddingLeftValue); |
| 1209 var left = this._listItemNode.totalOffsetLeft() + computedLeftPadding; | 1218 var left = this._listItemNode.totalOffsetLeft() + computedLeftPadding; |
| 1210 return event.pageX >= left && event.pageX <= left + UI.TreeElement._ArrowTog gleWidth && this._expandable; | 1219 return event.pageX >= left && event.pageX <= left + UI.TreeElement._ArrowTog gleWidth && this._expandable; |
| 1211 } | 1220 } |
| 1212 }; | 1221 }; |
| 1213 | 1222 |
| 1214 /** @const */ | 1223 /** @const */ |
| 1215 UI.TreeElement._ArrowToggleWidth = 10; | 1224 UI.TreeElement._ArrowToggleWidth = 10; |
| OLD | NEW |