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 // require: list_selection_model.js | 5 // require: list_selection_model.js |
6 // require: list_selection_controller.js | 6 // require: list_selection_controller.js |
7 // require: list.js | 7 // require: list.js |
8 | 8 |
9 /** | 9 /** |
10 * @fileoverview This implements a grid control. Grid contains a bunch of | 10 * @fileoverview This implements a grid control. Grid contains a bunch of |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 */ | 343 */ |
344 function GridSelectionController(selectionModel, grid) { | 344 function GridSelectionController(selectionModel, grid) { |
345 this.selectionModel_ = selectionModel; | 345 this.selectionModel_ = selectionModel; |
346 this.grid_ = grid; | 346 this.grid_ = grid; |
347 } | 347 } |
348 | 348 |
349 GridSelectionController.prototype = { | 349 GridSelectionController.prototype = { |
350 __proto__: ListSelectionController.prototype, | 350 __proto__: ListSelectionController.prototype, |
351 | 351 |
352 /** | 352 /** |
353 * Check if accessibility is enabled: if ChromeVox is running | |
354 * (which provides spoken feedback for accessibility), make up/down | |
355 * behave the same as left/right. That's because the 2-dimensional | |
356 * structure of the grid isn't exposed, so it makes more sense to a | |
357 * user who is relying on spoken feedback to flatten it. | |
358 * @return {boolean} True if accessibility is enabled. | |
359 */ | |
360 isAccessibilityEnabled: function() { | |
361 return (window.cvox && cvox.Api && cvox.Api && | |
Evan Stade
2012/05/07 20:58:02
cvox.Api checked twice
| |
362 cvox.Api.isChromeVoxActive && cvox.Api.isChromeVoxActive()); | |
363 }, | |
364 | |
365 /** | |
353 * Returns the index below (y axis) the given element. | 366 * Returns the index below (y axis) the given element. |
354 * @param {number} index The index to get the index below. | 367 * @param {number} index The index to get the index below. |
355 * @return {number} The index below or -1 if not found. | 368 * @return {number} The index below or -1 if not found. |
356 * @override | 369 * @override |
357 */ | 370 */ |
358 getIndexBelow: function(index) { | 371 getIndexBelow: function(index) { |
372 if (this.isAccessibilityEnabled()) | |
373 return this.getIndexAfter(index); | |
359 var last = this.getLastIndex(); | 374 var last = this.getLastIndex(); |
360 if (index == last) { | 375 if (index == last) { |
Evan Stade
2012/05/07 20:58:02
no curlies
| |
361 return -1; | 376 return -1; |
362 } | 377 } |
363 index += this.grid_.columns; | 378 index += this.grid_.columns; |
364 return Math.min(index, last); | 379 return Math.min(index, last); |
365 }, | 380 }, |
366 | 381 |
367 /** | 382 /** |
368 * Returns the index above (y axis) the given element. | 383 * Returns the index above (y axis) the given element. |
369 * @param {number} index The index to get the index above. | 384 * @param {number} index The index to get the index above. |
370 * @return {number} The index below or -1 if not found. | 385 * @return {number} The index below or -1 if not found. |
371 * @override | 386 * @override |
372 */ | 387 */ |
373 getIndexAbove: function(index) { | 388 getIndexAbove: function(index) { |
389 if (this.isAccessibilityEnabled()) | |
390 return this.getIndexBefore(index); | |
374 if (index == 0) { | 391 if (index == 0) { |
Evan Stade
2012/05/07 20:58:02
no curlies
| |
375 return -1; | 392 return -1; |
376 } | 393 } |
377 index -= this.grid_.columns; | 394 index -= this.grid_.columns; |
378 return Math.max(index, 0); | 395 return Math.max(index, 0); |
379 }, | 396 }, |
380 | 397 |
381 /** | 398 /** |
382 * Returns the index before (x axis) the given element. | 399 * Returns the index before (x axis) the given element. |
383 * @param {number} index The index to get the index before. | 400 * @param {number} index The index to get the index before. |
384 * @return {number} The index before or -1 if not found. | 401 * @return {number} The index before or -1 if not found. |
(...skipping 16 matching lines...) Expand all Loading... | |
401 return index + 1; | 418 return index + 1; |
402 } | 419 } |
403 }; | 420 }; |
404 | 421 |
405 return { | 422 return { |
406 Grid: Grid, | 423 Grid: Grid, |
407 GridItem: GridItem, | 424 GridItem: GridItem, |
408 GridSelectionController: GridSelectionController | 425 GridSelectionController: GridSelectionController |
409 }; | 426 }; |
410 }); | 427 }); |
OLD | NEW |