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 |
11 * similar elements placed in multiple columns. It's pretty similar to the list, | 11 * similar elements placed in multiple columns. It's pretty similar to the list, |
12 * except the multiple columns layout. | 12 * except the multiple columns layout. |
13 */ | 13 */ |
14 | 14 |
15 cr.define('cr.ui', function() { | 15 cr.define('cr.ui', function() { |
16 /** @const */ var ListSelectionController = cr.ui.ListSelectionController; | 16 /** @const */ var ListSelectionController = cr.ui.ListSelectionController; |
17 /** @const */ var List = cr.ui.List; | 17 /** @const */ var List = cr.ui.List; |
18 /** @const */ var ListItem = cr.ui.ListItem; | 18 /** @const */ var ListItem = cr.ui.ListItem; |
19 | 19 |
20 /** | 20 /** |
21 * Creates a new grid item element. | 21 * Creates a new grid item element. |
22 * @param {*} dataItem The data item. | 22 * @param {*} dataItem The data item. |
23 * @constructor | 23 * @constructor |
24 * @extends {cr.ui.ListItem} | 24 * @extends {cr.ui.ListItem} |
25 */ | 25 */ |
26 function GridItem(dataItem) { | 26 function GridItem(dataItem) { |
27 var el = cr.doc.createElement('span'); | 27 var el = cr.doc.createElement('li'); |
28 el.dataItem = dataItem; | 28 el.dataItem = dataItem; |
29 el.__proto__ = GridItem.prototype; | 29 el.__proto__ = GridItem.prototype; |
30 return el; | 30 return el; |
31 } | 31 } |
32 | 32 |
33 GridItem.prototype = { | 33 GridItem.prototype = { |
34 __proto__: ListItem.prototype, | 34 __proto__: ListItem.prototype, |
35 | 35 |
36 /** | 36 /** |
37 * Called when an element is decorated as a grid item. | 37 * Called when an element is decorated as a grid item. |
(...skipping 305 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 && |
| 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) |
361 return -1; | 376 return -1; |
362 } | |
363 index += this.grid_.columns; | 377 index += this.grid_.columns; |
364 return Math.min(index, last); | 378 return Math.min(index, last); |
365 }, | 379 }, |
366 | 380 |
367 /** | 381 /** |
368 * Returns the index above (y axis) the given element. | 382 * Returns the index above (y axis) the given element. |
369 * @param {number} index The index to get the index above. | 383 * @param {number} index The index to get the index above. |
370 * @return {number} The index below or -1 if not found. | 384 * @return {number} The index below or -1 if not found. |
371 * @override | 385 * @override |
372 */ | 386 */ |
373 getIndexAbove: function(index) { | 387 getIndexAbove: function(index) { |
374 if (index == 0) { | 388 if (this.isAccessibilityEnabled()) |
| 389 return this.getIndexBefore(index); |
| 390 if (index == 0) |
375 return -1; | 391 return -1; |
376 } | |
377 index -= this.grid_.columns; | 392 index -= this.grid_.columns; |
378 return Math.max(index, 0); | 393 return Math.max(index, 0); |
379 }, | 394 }, |
380 | 395 |
381 /** | 396 /** |
382 * Returns the index before (x axis) the given element. | 397 * Returns the index before (x axis) the given element. |
383 * @param {number} index The index to get the index before. | 398 * @param {number} index The index to get the index before. |
384 * @return {number} The index before or -1 if not found. | 399 * @return {number} The index before or -1 if not found. |
385 * @override | 400 * @override |
386 */ | 401 */ |
(...skipping 14 matching lines...) Expand all Loading... |
401 return index + 1; | 416 return index + 1; |
402 } | 417 } |
403 }; | 418 }; |
404 | 419 |
405 return { | 420 return { |
406 Grid: Grid, | 421 Grid: Grid, |
407 GridItem: GridItem, | 422 GridItem: GridItem, |
408 GridSelectionController: GridSelectionController | 423 GridSelectionController: GridSelectionController |
409 }; | 424 }; |
410 }); | 425 }); |
OLD | NEW |