| 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 cr.define('cr.ui', function() { | 5 cr.define('cr.ui', function() { |
| 6 /** | 6 /** |
| 7 * Creates a selection controller that is to be used with lists. This is | 7 * Creates a selection controller that is to be used with lists. This is |
| 8 * implemented for vertical lists but changing the behavior for horizontal | 8 * implemented for vertical lists but changing the behavior for horizontal |
| 9 * lists or icon views is a matter of overriding {@code getIndexBefore}, | 9 * lists or icon views is a matter of overriding {@code getIndexBefore}, |
| 10 * {@code getIndexAfter}, {@code getIndexAbove} as well as | 10 * {@code getIndexAfter}, {@code getIndexAbove} as well as |
| 11 * {@code getIndexBelow}. | 11 * {@code getIndexBelow}. |
| 12 * | 12 * |
| 13 * @param {cr.ui.ListSelectionModel} selectionModel The selection model to | 13 * @param {cr.ui.ListSelectionModel} selectionModel The selection model to |
| 14 * interact with. | 14 * interact with. |
| 15 * | 15 * |
| 16 * @constructor | 16 * @constructor |
| 17 * @extends {cr.EventTarget} | 17 * @extends {cr.EventTarget} |
| 18 */ | 18 */ |
| 19 function ListSelectionController(selectionModel) { | 19 function ListSelectionController(selectionModel) { |
| 20 this.selectionModel_ = selectionModel; | 20 this.selectionModel_ = selectionModel; |
| 21 } | 21 } |
| 22 | 22 |
| 23 ListSelectionController.prototype = { | 23 ListSelectionController.prototype = { |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * The selection model we are interacting with. | 26 * The selection model we are interacting with. |
| 27 * @type {cr.ui.ListSelectionModel} | 27 * @type {cr.ui.ListSelectionModel} |
| 28 */ | 28 */ |
| 29 get selectionModel() { return this.selectionModel_; }, | 29 get selectionModel() { |
| 30 return this.selectionModel_; |
| 31 }, |
| 30 | 32 |
| 31 /** | 33 /** |
| 32 * Returns the index below (y axis) the given element. | 34 * Returns the index below (y axis) the given element. |
| 33 * @param {number} index The index to get the index below. | 35 * @param {number} index The index to get the index below. |
| 34 * @return {number} The index below or -1 if not found. | 36 * @return {number} The index below or -1 if not found. |
| 35 */ | 37 */ |
| 36 getIndexBelow: function(index) { | 38 getIndexBelow: function(index) { |
| 37 if (index == this.getLastIndex()) | 39 if (index == this.getLastIndex()) |
| 38 return -1; | 40 return -1; |
| 39 return index + 1; | 41 return index + 1; |
| 40 }, | 42 }, |
| 41 | 43 |
| 42 /** | 44 /** |
| 43 * Returns the index above (y axis) the given element. | 45 * Returns the index above (y axis) the given element. |
| 44 * @param {number} index The index to get the index above. | 46 * @param {number} index The index to get the index above. |
| 45 * @return {number} The index below or -1 if not found. | 47 * @return {number} The index below or -1 if not found. |
| 46 */ | 48 */ |
| 47 getIndexAbove: function(index) { return index - 1; }, | 49 getIndexAbove: function(index) { |
| 50 return index - 1; |
| 51 }, |
| 48 | 52 |
| 49 /** | 53 /** |
| 50 * Returns the index before (x axis) the given element. This returns -1 | 54 * Returns the index before (x axis) the given element. This returns -1 |
| 51 * by default but override this for icon view and horizontal selection | 55 * by default but override this for icon view and horizontal selection |
| 52 * models. | 56 * models. |
| 53 * | 57 * |
| 54 * @param {number} index The index to get the index before. | 58 * @param {number} index The index to get the index before. |
| 55 * @return {number} The index before or -1 if not found. | 59 * @return {number} The index before or -1 if not found. |
| 56 */ | 60 */ |
| 57 getIndexBefore: function(index) { return -1; }, | 61 getIndexBefore: function(index) { |
| 62 return -1; |
| 63 }, |
| 58 | 64 |
| 59 /** | 65 /** |
| 60 * Returns the index after (x axis) the given element. This returns -1 | 66 * Returns the index after (x axis) the given element. This returns -1 |
| 61 * by default but override this for icon view and horizontal selection | 67 * by default but override this for icon view and horizontal selection |
| 62 * models. | 68 * models. |
| 63 * | 69 * |
| 64 * @param {number} index The index to get the index after. | 70 * @param {number} index The index to get the index after. |
| 65 * @return {number} The index after or -1 if not found. | 71 * @return {number} The index after or -1 if not found. |
| 66 */ | 72 */ |
| 67 getIndexAfter: function(index) { return -1; }, | 73 getIndexAfter: function(index) { |
| 74 return -1; |
| 75 }, |
| 68 | 76 |
| 69 /** | 77 /** |
| 70 * Returns the next list index. This is the next logical and should not | 78 * Returns the next list index. This is the next logical and should not |
| 71 * depend on any kind of layout of the list. | 79 * depend on any kind of layout of the list. |
| 72 * @param {number} index The index to get the next index for. | 80 * @param {number} index The index to get the next index for. |
| 73 * @return {number} The next index or -1 if not found. | 81 * @return {number} The next index or -1 if not found. |
| 74 */ | 82 */ |
| 75 getNextIndex: function(index) { | 83 getNextIndex: function(index) { |
| 76 if (index == this.getLastIndex()) | 84 if (index == this.getLastIndex()) |
| 77 return -1; | 85 return -1; |
| 78 return index + 1; | 86 return index + 1; |
| 79 }, | 87 }, |
| 80 | 88 |
| 81 /** | 89 /** |
| 82 * Returns the prevous list index. This is the previous logical and should | 90 * Returns the prevous list index. This is the previous logical and should |
| 83 * not depend on any kind of layout of the list. | 91 * not depend on any kind of layout of the list. |
| 84 * @param {number} index The index to get the previous index for. | 92 * @param {number} index The index to get the previous index for. |
| 85 * @return {number} The previous index or -1 if not found. | 93 * @return {number} The previous index or -1 if not found. |
| 86 */ | 94 */ |
| 87 getPreviousIndex: function(index) { return index - 1; }, | 95 getPreviousIndex: function(index) { |
| 96 return index - 1; |
| 97 }, |
| 88 | 98 |
| 89 /** | 99 /** |
| 90 * @return {number} The first index. | 100 * @return {number} The first index. |
| 91 */ | 101 */ |
| 92 getFirstIndex: function() { return 0; }, | 102 getFirstIndex: function() { |
| 103 return 0; |
| 104 }, |
| 93 | 105 |
| 94 /** | 106 /** |
| 95 * @return {number} The last index. | 107 * @return {number} The last index. |
| 96 */ | 108 */ |
| 97 getLastIndex: function() { return this.selectionModel.length - 1; }, | 109 getLastIndex: function() { |
| 110 return this.selectionModel.length - 1; |
| 111 }, |
| 98 | 112 |
| 99 /** | 113 /** |
| 100 * Called by the view when the user does a mousedown or mouseup on the | 114 * Called by the view when the user does a mousedown or mouseup on the |
| 101 * list. | 115 * list. |
| 102 * @param {!Event} e The browser mouse event. | 116 * @param {!Event} e The browser mouse event. |
| 103 * @param {number} index The index that was under the mouse pointer, -1 if | 117 * @param {number} index The index that was under the mouse pointer, -1 if |
| 104 * none. | 118 * none. |
| 105 */ | 119 */ |
| 106 handlePointerDownUp: function(e, index) { | 120 handlePointerDownUp: function(e, index) { |
| 107 var sm = this.selectionModel; | 121 var sm = this.selectionModel; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 sm.endChange(); | 276 sm.endChange(); |
| 263 | 277 |
| 264 if (prevent) | 278 if (prevent) |
| 265 e.preventDefault(); | 279 e.preventDefault(); |
| 266 } | 280 } |
| 267 } | 281 } |
| 268 }; | 282 }; |
| 269 | 283 |
| 270 return {ListSelectionController: ListSelectionController}; | 284 return {ListSelectionController: ListSelectionController}; |
| 271 }); | 285 }); |
| OLD | NEW |