Chromium Code Reviews| 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: array_data_model.js | 5 // require: array_data_model.js |
| 6 // require: list_selection_model.js | 6 // require: list_selection_model.js |
| 7 // require: list_selection_controller.js | 7 // require: list_selection_controller.js |
| 8 // require: list_item.js | 8 // require: list_item.js |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 remainingSpace_: true, | 84 remainingSpace_: true, |
| 85 | 85 |
| 86 /** | 86 /** |
| 87 * Function used to create grid items. | 87 * Function used to create grid items. |
| 88 * @type {function(): !ListItem} | 88 * @type {function(): !ListItem} |
| 89 * @private | 89 * @private |
| 90 */ | 90 */ |
| 91 itemConstructor_: cr.ui.ListItem, | 91 itemConstructor_: cr.ui.ListItem, |
| 92 | 92 |
| 93 /** | 93 /** |
| 94 * The prefix to use when giving each item a unique id. | |
| 95 * @type {string} | |
| 96 * @private | |
| 97 */ | |
| 98 uniqueIdPrefix_: 'list', | |
| 99 | |
| 100 /** | |
| 101 * The next id suffix to use when giving each item an unique id. | |
| 102 * @type {number} | |
| 103 * @private | |
| 104 */ | |
| 105 nextUniqueIdSuffix_: 0, | |
|
Ivan Korotkov
2012/08/03 01:00:23
Don't put them into prototype: that makes them sha
dmazzoni
2012/08/03 22:59:01
Moved to decorate(), or did you have something els
Ivan Korotkov
2012/08/03 23:19:37
decorate is OK
| |
| 106 | |
| 107 /** | |
| 94 * Function used to create grid items. | 108 * Function used to create grid items. |
| 95 * @type {function(): !ListItem} | 109 * @type {function(): !ListItem} |
| 96 */ | 110 */ |
| 97 get itemConstructor() { | 111 get itemConstructor() { |
| 98 return this.itemConstructor_; | 112 return this.itemConstructor_; |
| 99 }, | 113 }, |
| 100 set itemConstructor(func) { | 114 set itemConstructor(func) { |
| 101 if (func != this.itemConstructor_) { | 115 if (func != this.itemConstructor_) { |
| 102 this.itemConstructor_ = func; | 116 this.itemConstructor_ = func; |
| 103 this.cachedItems_ = {}; | 117 this.cachedItems_ = {}; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 var length = this.dataModel ? this.dataModel.length : 0; | 326 var length = this.dataModel ? this.dataModel.length : 0; |
| 313 this.selectionModel = new ListSelectionModel(length); | 327 this.selectionModel = new ListSelectionModel(length); |
| 314 | 328 |
| 315 this.addEventListener('dblclick', this.handleDoubleClickOrTap_); | 329 this.addEventListener('dblclick', this.handleDoubleClickOrTap_); |
| 316 this.addEventListener('mousedown', this.handlePointerDownUp_); | 330 this.addEventListener('mousedown', this.handlePointerDownUp_); |
| 317 this.addEventListener('mouseup', this.handlePointerDownUp_); | 331 this.addEventListener('mouseup', this.handlePointerDownUp_); |
| 318 this.addEventListener('keydown', this.handleKeyDown); | 332 this.addEventListener('keydown', this.handleKeyDown); |
| 319 this.addEventListener('focus', this.handleElementFocus_, true); | 333 this.addEventListener('focus', this.handleElementFocus_, true); |
| 320 this.addEventListener('blur', this.handleElementBlur_, true); | 334 this.addEventListener('blur', this.handleElementBlur_, true); |
| 321 this.addEventListener('scroll', this.handleScroll.bind(this)); | 335 this.addEventListener('scroll', this.handleScroll.bind(this)); |
| 322 this.setAttribute('role', 'listbox'); | 336 this.setAttribute('role', 'list'); |
| 323 | 337 |
| 324 this.touchHandler_ = new cr.ui.TouchHandler(this); | 338 this.touchHandler_ = new cr.ui.TouchHandler(this); |
| 325 this.addEventListener(cr.ui.TouchHandler.EventType.TOUCH_START, | 339 this.addEventListener(cr.ui.TouchHandler.EventType.TOUCH_START, |
| 326 this.handlePointerDownUp_); | 340 this.handlePointerDownUp_); |
| 327 this.addEventListener(cr.ui.TouchHandler.EventType.TOUCH_END, | 341 this.addEventListener(cr.ui.TouchHandler.EventType.TOUCH_END, |
| 328 this.handlePointerDownUp_); | 342 this.handlePointerDownUp_); |
| 329 this.addEventListener(cr.ui.TouchHandler.EventType.TAP, | 343 this.addEventListener(cr.ui.TouchHandler.EventType.TAP, |
| 330 this.handleDoubleClickOrTap_); | 344 this.handleDoubleClickOrTap_); |
| 331 this.touchHandler_.enable(false, false); | 345 this.touchHandler_.enable(false, false); |
| 332 // Make list focusable | 346 // Make list focusable |
| 333 if (!this.hasAttribute('tabindex')) | 347 if (!this.hasAttribute('tabindex')) |
| 334 this.tabIndex = 0; | 348 this.tabIndex = 0; |
| 349 | |
| 350 // Try to get an unique id prefix from the id of this element or the | |
| 351 // nearest ancestor with an id. | |
| 352 var element = this; | |
| 353 while (element && !element.id) | |
| 354 element = element.parentElement; | |
| 355 if (element && element.id) | |
| 356 this.uniqueIdPrefix_ = element.id; | |
| 335 }, | 357 }, |
| 336 | 358 |
| 337 /** | 359 /** |
| 338 * @param {ListItem=} item The list item to measure. | 360 * @param {ListItem=} item The list item to measure. |
| 339 * @return {number} The height of the given item. If the fixed height on CSS | 361 * @return {number} The height of the given item. If the fixed height on CSS |
| 340 * is set by 'px', uses that value as height. Otherwise, measures the size. | 362 * is set by 'px', uses that value as height. Otherwise, measures the size. |
| 341 * @private | 363 * @private |
| 342 */ | 364 */ |
| 343 measureItemHeight_: function(item) { | 365 measureItemHeight_: function(item) { |
| 344 var height = item.style.height; | 366 var height = item.style.height; |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 575 | 597 |
| 576 /** | 598 /** |
| 577 * Callback from the selection model. We dispatch {@code change} events | 599 * Callback from the selection model. We dispatch {@code change} events |
| 578 * when the selection changes. | 600 * when the selection changes. |
| 579 * @param {!cr.Event} e Event with change info. | 601 * @param {!cr.Event} e Event with change info. |
| 580 * @private | 602 * @private |
| 581 */ | 603 */ |
| 582 handleOnChange_: function(ce) { | 604 handleOnChange_: function(ce) { |
| 583 ce.changes.forEach(function(change) { | 605 ce.changes.forEach(function(change) { |
| 584 var listItem = this.getListItemByIndex(change.index); | 606 var listItem = this.getListItemByIndex(change.index); |
| 585 if (listItem) | 607 if (listItem) { |
| 586 listItem.selected = change.selected; | 608 listItem.selected = change.selected; |
| 609 if (change.selected) | |
| 610 this.setAttribute('aria-activedescendant', listItem.id); | |
|
Ivan Korotkov
2012/08/03 01:00:23
Indentation.
dmazzoni
2012/08/03 22:59:01
Done.
| |
| 611 } | |
| 587 }, this); | 612 }, this); |
| 588 | 613 |
| 589 cr.dispatchSimpleEvent(this, 'change'); | 614 cr.dispatchSimpleEvent(this, 'change'); |
| 590 }, | 615 }, |
| 591 | 616 |
| 592 /** | 617 /** |
| 593 * Handles a change of the lead item from the selection model. | 618 * Handles a change of the lead item from the selection model. |
| 594 * @param {Event} pe The property change event. | 619 * @param {Event} pe The property change event. |
| 595 * @private | 620 * @private |
| 596 */ | 621 */ |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 809 }, | 834 }, |
| 810 | 835 |
| 811 /** | 836 /** |
| 812 * Creates a new list item. | 837 * Creates a new list item. |
| 813 * @param {*} value The value to use for the item. | 838 * @param {*} value The value to use for the item. |
| 814 * @return {!ListItem} The newly created list item. | 839 * @return {!ListItem} The newly created list item. |
| 815 */ | 840 */ |
| 816 createItem: function(value) { | 841 createItem: function(value) { |
| 817 var item = new this.itemConstructor_(value); | 842 var item = new this.itemConstructor_(value); |
| 818 item.label = value; | 843 item.label = value; |
| 844 item.id = this.uniqueIdPrefix_ + '-' + this.nextUniqueIdSuffix_++; | |
| 819 if (typeof item.decorate == 'function') | 845 if (typeof item.decorate == 'function') |
| 820 item.decorate(); | 846 item.decorate(); |
| 821 return item; | 847 return item; |
| 822 }, | 848 }, |
| 823 | 849 |
| 824 /** | 850 /** |
| 825 * Creates the selection controller to use internally. | 851 * Creates the selection controller to use internally. |
| 826 * @param {cr.ui.ListSelectionModel} sm The underlying selection model. | 852 * @param {cr.ui.ListSelectionModel} sm The underlying selection model. |
| 827 * @return {!cr.ui.ListSelectionController} The newly created selection | 853 * @return {!cr.ui.ListSelectionController} The newly created selection |
| 828 * controller. | 854 * controller. |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1265 * because list items can contain controls that can be focused, and for some | 1291 * because list items can contain controls that can be focused, and for some |
| 1266 * purposes (e.g., styling), the list can still be conceptually focused at | 1292 * purposes (e.g., styling), the list can still be conceptually focused at |
| 1267 * that point even though it doesn't actually have the page focus. | 1293 * that point even though it doesn't actually have the page focus. |
| 1268 */ | 1294 */ |
| 1269 cr.defineProperty(List, 'hasElementFocus', cr.PropertyKind.BOOL_ATTR); | 1295 cr.defineProperty(List, 'hasElementFocus', cr.PropertyKind.BOOL_ATTR); |
| 1270 | 1296 |
| 1271 return { | 1297 return { |
| 1272 List: List | 1298 List: List |
| 1273 }; | 1299 }; |
| 1274 }); | 1300 }); |
| OLD | NEW |