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 /** | 5 /** |
6 * @fileoverview This extends cr.ui.List for use in the table. | 6 * @fileoverview This extends cr.ui.List for use in the table. |
7 */ | 7 */ |
8 | 8 |
9 cr.define('cr.ui.table', function() { | 9 cr.define('cr.ui.table', function() { |
10 /** @const */ var List = cr.ui.List; | 10 /** @const */ var List = cr.ui.List; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 /** | 64 /** |
65 * Creates a new list item. | 65 * Creates a new list item. |
66 * @param {*} dataItem The value to use for the item. | 66 * @param {*} dataItem The value to use for the item. |
67 * @return {!ListItem} The newly created list item. | 67 * @return {!ListItem} The newly created list item. |
68 */ | 68 */ |
69 createItem: function(dataItem) { | 69 createItem: function(dataItem) { |
70 return this.table_.getRenderFunction().call(null, dataItem, this.table_); | 70 return this.table_.getRenderFunction().call(null, dataItem, this.table_); |
71 }, | 71 }, |
72 | 72 |
73 renderFunction_: function(dataItem, table) { | 73 renderFunction_: function(dataItem, table) { |
| 74 // `This` must not be accessed here, since it may be anything, especially |
| 75 // not a pointer to this object. |
| 76 |
74 var cm = table.columnModel; | 77 var cm = table.columnModel; |
75 var listItem = List.prototype.createItem.call(table.list, ''); | 78 var listItem = List.prototype.createItem.call(table.list, ''); |
76 | |
77 listItem.className = 'table-row'; | 79 listItem.className = 'table-row'; |
78 | 80 |
79 for (var i = 0; i < cm.size; i++) { | 81 for (var i = 0; i < cm.size; i++) { |
80 var cell = table.ownerDocument.createElement('div'); | 82 var cell = table.ownerDocument.createElement('div'); |
81 cell.style.width = cm.getWidth(i) + '%'; | 83 cell.style.width = cm.getWidth(i) + '%'; |
82 cell.className = 'table-row-cell'; | 84 cell.className = 'table-row-cell'; |
83 if (cm.isEndAlign(i)) | 85 if (cm.isEndAlign(i)) |
84 cell.style.textAlign = 'end'; | 86 cell.style.textAlign = 'end'; |
85 cell.appendChild( | 87 cell.appendChild( |
86 cm.getRenderFunction(i).call(null, dataItem, cm.getId(i), table)); | 88 cm.getRenderFunction(i).call(null, dataItem, cm.getId(i), table)); |
87 | 89 |
88 listItem.appendChild(cell); | 90 listItem.appendChild(cell); |
89 } | 91 } |
90 | 92 |
91 return listItem; | 93 return listItem; |
92 }, | 94 }, |
93 }; | 95 }; |
94 | 96 |
95 /** | 97 /** |
96 * The table associated with the list. | 98 * The table associated with the list. |
97 * @type {cr.ui.Table} | 99 * @type {cr.ui.Table} |
98 */ | 100 */ |
99 cr.defineProperty(TableList, 'table'); | 101 cr.defineProperty(TableList, 'table'); |
100 | 102 |
101 return { | 103 return { |
102 TableList: TableList | 104 TableList: TableList |
103 }; | 105 }; |
104 }); | 106 }); |
OLD | NEW |