Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: chrome/browser/resources/shared/js/cr/ui/grid.js

Issue 10376003: Improve accessibility of user image selection screen. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, simplify change so it doesn't affect other uses of Grid/List Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 &&
Ivan Korotkov 2012/08/03 01:00:23 No need in braces.
362 cvox.Api.isChromeVoxActive && cvox.Api.isChromeVoxActive());
Ivan Korotkov 2012/08/03 01:00:23 No need in parens.
dmazzoni 2012/08/03 22:59:01 Removed parens. Braces are still needed, or am I m
Ivan Korotkov 2012/08/03 23:19:37 Uh, right, that was a stray comment.
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
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 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698