OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * A class to manage grid of focusable elements in a 2D grid. For example, | 7 * A class to manage grid of focusable elements in a 2D grid. For example, |
8 * given this grid: | 8 * given this grid: |
9 * | 9 * |
10 * focusable [focused] focusable (row: 0, col: 1) | 10 * focusable [focused] focusable (row: 0, col: 1) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 this.ignoreFocusChange_ = false; | 132 this.ignoreFocusChange_ = false; |
133 return; | 133 return; |
134 } | 134 } |
135 | 135 |
136 var target = assertInstanceof(e.target, Node); | 136 var target = assertInstanceof(e.target, Node); |
137 if (this.getRowIndexForTarget(target) != -1) | 137 if (this.getRowIndexForTarget(target) != -1) |
138 this.lastFocused = target; | 138 this.lastFocused = target; |
139 }, | 139 }, |
140 | 140 |
141 /** | 141 /** |
142 * Add a FocusRow to this grid. This needs to be called AFTER adding columns | 142 * Add a FocusRow to this grid. Row is added at the end. |
Dan Beam
2015/05/12 01:28:42
Adds |row| to the end of this grid.
hcarmona
2015/05/12 02:00:47
Done.
| |
143 * to the row. This is so that TAB focus can be properly enabled in the | |
144 * columns. | |
145 * @param {cr.ui.FocusRow} row The row that needs to be added to this grid. | 143 * @param {cr.ui.FocusRow} row The row that needs to be added to this grid. |
146 */ | 144 */ |
147 addRow: function(row) { | 145 addRow: function(row) { |
148 row.delegate = row.delegate || this.delegate_; | 146 this.addRowBefore(row, null); |
149 this.rows.push(row); | |
150 }, | 147 }, |
151 | 148 |
152 /** | 149 /** |
150 * Add a FocusRow to this grid in order. Adds at the end if |nextRow| is | |
Dan Beam
2015/05/12 01:28:42
Add -> Adds
hcarmona
2015/05/12 02:00:47
Done.
| |
151 * not in the list of rows. | |
152 * @param {cr.ui.FocusRow} row The row that needs to be added to this grid. | |
Dan Beam
2015/05/12 01:28:42
!cr.ui.FocusRow for |row|
hcarmona
2015/05/12 02:00:47
Done.
| |
153 * @param {cr.ui.FocusRow} nextRow The row that should follow |row|. | |
154 */ | |
155 addRowBefore: function(row, nextRow) { | |
156 row.delegate = row.delegate || this.delegate_; | |
157 | |
158 var nextRowIndex = this.rows.indexOf(nextRow); | |
159 if (nextRowIndex == -1) { | |
Dan Beam
2015/05/12 01:28:42
no curlies
hcarmona
2015/05/12 02:00:47
Done.
| |
160 this.rows.push(row); | |
161 } else { | |
162 this.rows.splice(nextRowIndex, 0, row); | |
163 } | |
164 }, | |
165 | |
166 /** | |
167 * Removes a row from the focus row. No-op if row is not in the grid. | |
168 * @param {cr.ui.FocusRow} row The row that needs to be removed. | |
169 */ | |
170 removeRow: function(row) { | |
171 var nextRowIndex = this.rows.indexOf(row); | |
172 if (nextRowIndex > -1) { | |
Dan Beam
2015/05/12 01:28:42
no curlies
hcarmona
2015/05/12 02:00:47
Done.
| |
173 this.rows.splice(nextRowIndex, 1); | |
174 } | |
175 }, | |
176 | |
177 /** | |
153 * Makes sure that at least one row is active. Should be called once, after | 178 * Makes sure that at least one row is active. Should be called once, after |
154 * adding all rows to FocusGrid. | 179 * adding all rows to FocusGrid. |
155 */ | 180 */ |
156 ensureRowActive: function() { | 181 ensureRowActive: function() { |
157 if (this.rows.length == 0) | 182 if (this.rows.length == 0) |
158 return; | 183 return; |
159 | 184 |
160 for (var i = 0; i < this.rows.length; ++i) { | 185 for (var i = 0; i < this.rows.length; ++i) { |
161 if (this.rows[i].isActive()) | 186 if (this.rows[i].isActive()) |
162 return; | 187 return; |
163 } | 188 } |
164 | 189 |
165 this.rows[0].makeActive(true); | 190 this.rows[0].makeActive(true); |
166 }, | 191 }, |
167 }; | 192 }; |
168 | 193 |
169 return { | 194 return { |
170 FocusGrid: FocusGrid, | 195 FocusGrid: FocusGrid, |
171 }; | 196 }; |
172 }); | 197 }); |
OLD | NEW |