| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 /** | 6 /** |
| 7 * A class to manage grid of focusable elements in a 2D grid. For example, | 7 * A class to manage grid of focusable elements in a 2D grid. For example, |
| 8 * given this grid: | 8 * given this grid: |
| 9 * | 9 * |
| 10 * focusable [focused] focusable (row: 0, col: 1) | 10 * focusable [focused] focusable (row: 0, col: 1) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 this.rows.forEach(function(r) { r.makeActive(r == row); }); | 46 this.rows.forEach(function(r) { r.makeActive(r == row); }); |
| 47 }, | 47 }, |
| 48 | 48 |
| 49 /** @override */ | 49 /** @override */ |
| 50 onKeydown: function(row, e) { | 50 onKeydown: function(row, e) { |
| 51 var rowIndex = this.rows.indexOf(row); | 51 var rowIndex = this.rows.indexOf(row); |
| 52 assert(rowIndex >= 0); | 52 assert(rowIndex >= 0); |
| 53 | 53 |
| 54 var newRow = -1; | 54 var newRow = -1; |
| 55 | 55 |
| 56 if (e.keyIdentifier == 'Up') | 56 if (e.key == 'ArrowUp') |
| 57 newRow = rowIndex - 1; | 57 newRow = rowIndex - 1; |
| 58 else if (e.keyIdentifier == 'Down') | 58 else if (e.key == 'ArrowDown') |
| 59 newRow = rowIndex + 1; | 59 newRow = rowIndex + 1; |
| 60 else if (e.keyIdentifier == 'PageUp') | 60 else if (e.key == 'PageUp') |
| 61 newRow = 0; | 61 newRow = 0; |
| 62 else if (e.keyIdentifier == 'PageDown') | 62 else if (e.key == 'PageDown') |
| 63 newRow = this.rows.length - 1; | 63 newRow = this.rows.length - 1; |
| 64 | 64 |
| 65 var rowToFocus = this.rows[newRow]; | 65 var rowToFocus = this.rows[newRow]; |
| 66 if (rowToFocus) { | 66 if (rowToFocus) { |
| 67 this.ignoreFocusChange_ = true; | 67 this.ignoreFocusChange_ = true; |
| 68 rowToFocus.getEquivalentElement(this.lastFocused_).focus(); | 68 rowToFocus.getEquivalentElement(this.lastFocused_).focus(); |
| 69 e.preventDefault(); | 69 e.preventDefault(); |
| 70 return true; | 70 return true; |
| 71 } | 71 } |
| 72 | 72 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 } | 153 } |
| 154 | 154 |
| 155 this.rows[0].makeActive(true); | 155 this.rows[0].makeActive(true); |
| 156 }, | 156 }, |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 return { | 159 return { |
| 160 FocusGrid: FocusGrid, | 160 FocusGrid: FocusGrid, |
| 161 }; | 161 }; |
| 162 }); | 162 }); |
| OLD | NEW |