| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 cr.define('options', function() { | |
| 6 const ListSelectionController = cr.ui.ListSelectionController; | |
| 7 | |
| 8 /** | |
| 9 * Creates a selection controller with a delegate that controls whether or | |
| 10 * not individual items are selectable. This is used for lists containing | |
| 11 * subgroups with headings that are in the list, since the headers themselves | |
| 12 * should not be selectable. | |
| 13 * | |
| 14 * @param {cr.ui.ListSelectionModel} selectionModel The selection model to | |
| 15 * interact with. | |
| 16 * @param {*} selectabilityDelegate A delegate responding to | |
| 17 * canSelectIndex(index). | |
| 18 * | |
| 19 * @constructor | |
| 20 * @extends {!cr.ui.ListSelectionController} | |
| 21 */ | |
| 22 function ListInlineHeaderSelectionController(selectionModel, | |
| 23 selectabilityDelegate) { | |
| 24 ListSelectionController.call(this, selectionModel); | |
| 25 this.selectabilityDelegate_ = selectabilityDelegate; | |
| 26 } | |
| 27 | |
| 28 ListInlineHeaderSelectionController.prototype = { | |
| 29 __proto__: ListSelectionController.prototype, | |
| 30 | |
| 31 /** @inheritDoc */ | |
| 32 getIndexBelow: function(index) { | |
| 33 var next = ListSelectionController.prototype.getIndexBelow.call(this, | |
| 34 index); | |
| 35 if (next == -1 || this.canSelect(next)) | |
| 36 return next; | |
| 37 return this.getIndexBelow(next); | |
| 38 }, | |
| 39 | |
| 40 /** @inheritDoc */ | |
| 41 getNextIndex: function(index) { | |
| 42 return this.getIndexBelow(index); | |
| 43 }, | |
| 44 | |
| 45 /** @inheritDoc */ | |
| 46 getIndexAbove: function(index) { | |
| 47 var previous = ListSelectionController.prototype.getIndexAbove.call( | |
| 48 this, index); | |
| 49 if (previous == -1 || this.canSelect(previous)) | |
| 50 return previous; | |
| 51 return this.getIndexAbove(previous); | |
| 52 }, | |
| 53 | |
| 54 /** @inheritDoc */ | |
| 55 getPreviousIndex: function(index) { | |
| 56 return this.getIndexAbove(index); | |
| 57 }, | |
| 58 | |
| 59 /** @inheritDoc */ | |
| 60 getFirstIndex: function(index) { | |
| 61 var first = ListSelectionController.prototype.getFirstIndex.call(this); | |
| 62 if (this.canSelect(first)) | |
| 63 return first; | |
| 64 return this.getNextIndex(first); | |
| 65 }, | |
| 66 | |
| 67 /** @inheritDoc */ | |
| 68 getLastIndex: function(index) { | |
| 69 var last = ListSelectionController.prototype.getLastIndex.call(this); | |
| 70 if (this.canSelect(last)) | |
| 71 return last; | |
| 72 return this.getPreviousIndex(last); | |
| 73 }, | |
| 74 | |
| 75 /** @inheritDoc */ | |
| 76 handleMouseDownUp: function(e, index) { | |
| 77 if (this.canSelect(index)) { | |
| 78 ListSelectionController.prototype.handleMouseDownUp.call( | |
| 79 this, e, index); | |
| 80 } | |
| 81 }, | |
| 82 | |
| 83 /** | |
| 84 * Returns true if the given index is selectable. | |
| 85 * @private | |
| 86 * @param {number} index The index to check. | |
| 87 */ | |
| 88 canSelect: function(index) { | |
| 89 return this.selectabilityDelegate_.canSelectIndex(index); | |
| 90 } | |
| 91 }; | |
| 92 | |
| 93 return { | |
| 94 ListInlineHeaderSelectionController: ListInlineHeaderSelectionController | |
| 95 }; | |
| 96 }); | |
| OLD | NEW |