| OLD | NEW |
| 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 var itemToSelect; | 139 var itemToSelect; |
| 140 if (e.ctrlKey) | 140 if (e.ctrlKey) |
| 141 return; | 141 return; |
| 142 | 142 |
| 143 var item = this.selectedItem; | 143 var item = this.selectedItem; |
| 144 if (!item) | 144 if (!item) |
| 145 return; | 145 return; |
| 146 | 146 |
| 147 var rtl = getComputedStyle(item).direction == 'rtl'; | 147 var rtl = getComputedStyle(item).direction == 'rtl'; |
| 148 | 148 |
| 149 switch (e.keyIdentifier) { | 149 switch (e.key) { |
| 150 case 'Up': | 150 case 'ArrowUp': |
| 151 itemToSelect = item ? getPrevious(item) : | 151 itemToSelect = item ? getPrevious(item) : |
| 152 this.items[this.items.length - 1]; | 152 this.items[this.items.length - 1]; |
| 153 break; | 153 break; |
| 154 case 'Down': | 154 case 'ArrowDown': |
| 155 itemToSelect = item ? getNext(item) : | 155 itemToSelect = item ? getNext(item) : |
| 156 this.items[0]; | 156 this.items[0]; |
| 157 break; | 157 break; |
| 158 case 'Left': | 158 case 'ArrowLeft': |
| 159 case 'Right': | 159 case 'ArrowRight': |
| 160 // Don't let back/forward keyboard shortcuts be used. | 160 // Don't let back/forward keyboard shortcuts be used. |
| 161 if (!cr.isMac && e.altKey || cr.isMac && e.metaKey) | 161 if (!cr.isMac && e.altKey || cr.isMac && e.metaKey) |
| 162 break; | 162 break; |
| 163 | 163 |
| 164 if (e.keyIdentifier == 'Left' && !rtl || | 164 if (e.key == 'ArrowLeft' && !rtl || e.key == 'ArrowRight' && rtl) { |
| 165 e.keyIdentifier == 'Right' && rtl) { | |
| 166 if (item.expanded) | 165 if (item.expanded) |
| 167 item.expanded = false; | 166 item.expanded = false; |
| 168 else | 167 else |
| 169 itemToSelect = findTreeItem(item.parentNode); | 168 itemToSelect = findTreeItem(item.parentNode); |
| 170 } else { | 169 } else { |
| 171 if (!item.expanded) | 170 if (!item.expanded) |
| 172 item.expanded = true; | 171 item.expanded = true; |
| 173 else | 172 else |
| 174 itemToSelect = item.items[0]; | 173 itemToSelect = item.items[0]; |
| 175 } | 174 } |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 var text = this.label; | 551 var text = this.label; |
| 553 var input; | 552 var input; |
| 554 | 553 |
| 555 // Handles enter and escape which trigger reset and commit respectively. | 554 // Handles enter and escape which trigger reset and commit respectively. |
| 556 function handleKeydown(e) { | 555 function handleKeydown(e) { |
| 557 // Make sure that the tree does not handle the key. | 556 // Make sure that the tree does not handle the key. |
| 558 e.stopPropagation(); | 557 e.stopPropagation(); |
| 559 | 558 |
| 560 // Calling tree.focus blurs the input which will make the tree item | 559 // Calling tree.focus blurs the input which will make the tree item |
| 561 // non editable. | 560 // non editable. |
| 562 switch (e.keyIdentifier) { | 561 switch (e.key) { |
| 563 case 'U+001B': // Esc | 562 case 'Escape': |
| 564 input.value = text; | 563 input.value = text; |
| 565 // fall through | 564 // fall through |
| 566 case 'Enter': | 565 case 'Enter': |
| 567 self.tree.focus(); | 566 self.tree.focus(); |
| 568 } | 567 } |
| 569 } | 568 } |
| 570 | 569 |
| 571 function stopPropagation(e) { | 570 function stopPropagation(e) { |
| 572 e.stopPropagation(); | 571 e.stopPropagation(); |
| 573 } | 572 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 } | 688 } |
| 690 return item; | 689 return item; |
| 691 } | 690 } |
| 692 | 691 |
| 693 // Export | 692 // Export |
| 694 return { | 693 return { |
| 695 Tree: Tree, | 694 Tree: Tree, |
| 696 TreeItem: TreeItem | 695 TreeItem: TreeItem |
| 697 }; | 696 }; |
| 698 }); | 697 }); |
| OLD | NEW |