OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 // If focus is in an input field of some kind, only handle navigation keys | 185 // If focus is in an input field of some kind, only handle navigation keys |
186 // that aren't likely to conflict with input interaction (e.g., text | 186 // that aren't likely to conflict with input interaction (e.g., text |
187 // editing, or changing the value of a checkbox or select). | 187 // editing, or changing the value of a checkbox or select). |
188 if (tagName == 'INPUT') { | 188 if (tagName == 'INPUT') { |
189 var inputType = e.target.type; | 189 var inputType = e.target.type; |
190 // Just protect space (for toggling) for checkbox and radio. | 190 // Just protect space (for toggling) for checkbox and radio. |
191 if (inputType == 'checkbox' || inputType == 'radio') { | 191 if (inputType == 'checkbox' || inputType == 'radio') { |
192 if (e.keyCode == SPACE_KEY_CODE) | 192 if (e.keyCode == SPACE_KEY_CODE) |
193 return; | 193 return; |
194 // Protect all but the most basic navigation commands in anything else. | 194 // Protect all but the most basic navigation commands in anything else. |
195 } else if (e.keyIdentifier != 'Up' && e.keyIdentifier != 'Down') { | 195 } else if (e.key != 'ArrowUp' && e.key != 'ArrowDown') { |
196 return; | 196 return; |
197 } | 197 } |
198 } | 198 } |
199 // Similarly, don't interfere with select element handling. | 199 // Similarly, don't interfere with select element handling. |
200 if (tagName == 'SELECT') | 200 if (tagName == 'SELECT') |
201 return; | 201 return; |
202 | 202 |
203 var sm = this.selectionModel; | 203 var sm = this.selectionModel; |
204 var newIndex = -1; | 204 var newIndex = -1; |
205 var leadIndex = sm.leadIndex; | 205 var leadIndex = sm.leadIndex; |
(...skipping 11 matching lines...) Expand all Loading... |
217 if (e.keyCode == SPACE_KEY_CODE) { | 217 if (e.keyCode == SPACE_KEY_CODE) { |
218 if (leadIndex != -1) { | 218 if (leadIndex != -1) { |
219 var selected = sm.getIndexSelected(leadIndex); | 219 var selected = sm.getIndexSelected(leadIndex); |
220 if (e.ctrlKey || !selected) { | 220 if (e.ctrlKey || !selected) { |
221 sm.setIndexSelected(leadIndex, !selected || !sm.multiple); | 221 sm.setIndexSelected(leadIndex, !selected || !sm.multiple); |
222 return; | 222 return; |
223 } | 223 } |
224 } | 224 } |
225 } | 225 } |
226 | 226 |
227 switch (e.keyIdentifier) { | 227 switch (e.key) { |
228 case 'Home': | 228 case 'Home': |
229 newIndex = this.getFirstIndex(); | 229 newIndex = this.getFirstIndex(); |
230 break; | 230 break; |
231 case 'End': | 231 case 'End': |
232 newIndex = this.getLastIndex(); | 232 newIndex = this.getLastIndex(); |
233 break; | 233 break; |
234 case 'Up': | 234 case 'ArrowUp': |
235 newIndex = leadIndex == -1 ? | 235 newIndex = leadIndex == -1 ? |
236 this.getLastIndex() : this.getIndexAbove(leadIndex); | 236 this.getLastIndex() : this.getIndexAbove(leadIndex); |
237 break; | 237 break; |
238 case 'Down': | 238 case 'ArrowDown': |
239 newIndex = leadIndex == -1 ? | 239 newIndex = leadIndex == -1 ? |
240 this.getFirstIndex() : this.getIndexBelow(leadIndex); | 240 this.getFirstIndex() : this.getIndexBelow(leadIndex); |
241 break; | 241 break; |
242 case 'Left': | 242 case 'ArrrowLeft': |
243 newIndex = leadIndex == -1 ? | 243 newIndex = leadIndex == -1 ? |
244 this.getLastIndex() : this.getIndexBefore(leadIndex); | 244 this.getLastIndex() : this.getIndexBefore(leadIndex); |
245 break; | 245 break; |
246 case 'Right': | 246 case 'ArrowRight': |
247 newIndex = leadIndex == -1 ? | 247 newIndex = leadIndex == -1 ? |
248 this.getFirstIndex() : this.getIndexAfter(leadIndex); | 248 this.getFirstIndex() : this.getIndexAfter(leadIndex); |
249 break; | 249 break; |
250 default: | 250 default: |
251 prevent = false; | 251 prevent = false; |
252 } | 252 } |
253 | 253 |
254 if (newIndex != -1) { | 254 if (newIndex != -1) { |
255 sm.beginChange(); | 255 sm.beginChange(); |
256 | 256 |
(...skipping 23 matching lines...) Expand all Loading... |
280 if (prevent) | 280 if (prevent) |
281 e.preventDefault(); | 281 e.preventDefault(); |
282 } | 282 } |
283 } | 283 } |
284 }; | 284 }; |
285 | 285 |
286 return { | 286 return { |
287 ListSelectionController: ListSelectionController | 287 ListSelectionController: ListSelectionController |
288 }; | 288 }; |
289 }); | 289 }); |
OLD | NEW |