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 focus between given horizontally arranged elements. | 7 * A class to manage focus between given horizontally arranged elements. |
8 * | 8 * |
9 * Pressing left cycles backward and pressing right cycles forward in item | 9 * Pressing left cycles backward and pressing right cycles forward in item |
10 * order. Pressing Home goes to the beginning of the list and End goes to the | 10 * order. Pressing Home goes to the beginning of the list and End goes to the |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 assert(elementIndex >= 0); | 264 assert(elementIndex >= 0); |
265 | 265 |
266 if (this.delegate && this.delegate.onKeydown(this, e)) | 266 if (this.delegate && this.delegate.onKeydown(this, e)) |
267 return; | 267 return; |
268 | 268 |
269 if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) | 269 if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) |
270 return; | 270 return; |
271 | 271 |
272 var index = -1; | 272 var index = -1; |
273 | 273 |
274 if (e.keyIdentifier == 'Left') | 274 if (e.key == 'ArrowLeft') |
275 index = elementIndex + (isRTL() ? 1 : -1); | 275 index = elementIndex + (isRTL() ? 1 : -1); |
276 else if (e.keyIdentifier == 'Right') | 276 else if (e.key == 'ArrowRight') |
277 index = elementIndex + (isRTL() ? -1 : 1); | 277 index = elementIndex + (isRTL() ? -1 : 1); |
278 else if (e.keyIdentifier == 'Home') | 278 else if (e.key == 'Home') |
279 index = 0; | 279 index = 0; |
280 else if (e.keyIdentifier == 'End') | 280 else if (e.key == 'End') |
281 index = elements.length - 1; | 281 index = elements.length - 1; |
282 | 282 |
283 var elementToFocus = elements[index]; | 283 var elementToFocus = elements[index]; |
284 if (elementToFocus) { | 284 if (elementToFocus) { |
285 this.getEquivalentElement(elementToFocus).focus(); | 285 this.getEquivalentElement(elementToFocus).focus(); |
286 e.preventDefault(); | 286 e.preventDefault(); |
287 } | 287 } |
288 }, | 288 }, |
289 }; | 289 }; |
290 | 290 |
291 return { | 291 return { |
292 FocusRow: FocusRow, | 292 FocusRow: FocusRow, |
293 }; | 293 }; |
294 }); | 294 }); |
OLD | NEW |