Chromium Code Reviews| 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A volume list model. This model combines the 2 lists. | 8 * A volume list model. This model combines the 2 lists. |
| 9 * @param {cr.ui.ArrayDataModel} volumesList The first list of the model. | 9 * @param {cr.ui.ArrayDataModel} volumesList The first list of the model. |
| 10 * @param {cr.ui.ArrayDataModel} pinnedList The second list of the model. | 10 * @param {cr.ui.ArrayDataModel} pinnedList The second list of the model. |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 this.directoryModel_ = directoryModel; | 179 this.directoryModel_ = directoryModel; |
| 180 this.volumeManager_ = VolumeManager.getInstance(); | 180 this.volumeManager_ = VolumeManager.getInstance(); |
| 181 this.selectionModel = new cr.ui.ListSingleSelectionModel(); | 181 this.selectionModel = new cr.ui.ListSingleSelectionModel(); |
| 182 | 182 |
| 183 this.directoryModel_.addEventListener('directory-changed', | 183 this.directoryModel_.addEventListener('directory-changed', |
| 184 this.onCurrentDirectoryChanged_.bind(this)); | 184 this.onCurrentDirectoryChanged_.bind(this)); |
| 185 this.selectionModel.addEventListener( | 185 this.selectionModel.addEventListener( |
| 186 'change', this.onSelectionChange_.bind(this)); | 186 'change', this.onSelectionChange_.bind(this)); |
| 187 this.selectionModel.addEventListener( | 187 this.selectionModel.addEventListener( |
| 188 'beforeChange', this.onBeforeSelectionChange_.bind(this)); | 188 'beforeChange', this.onBeforeSelectionChange_.bind(this)); |
| 189 this.currentVolume_ = null; | |
| 190 | |
| 191 | 189 |
| 192 this.scrollBar_ = new ScrollBar(); | 190 this.scrollBar_ = new ScrollBar(); |
| 193 this.scrollBar_.initialize(this.parentNode, this); | 191 this.scrollBar_.initialize(this.parentNode, this); |
| 194 | 192 |
| 195 // Overriding default role 'list' set by cr.ui.List.decorate() to 'listbox' | 193 // Overriding default role 'list' set by cr.ui.List.decorate() to 'listbox' |
| 196 // role for better accessibility on ChromeOS. | 194 // role for better accessibility on ChromeOS. |
| 197 this.setAttribute('role', 'listbox'); | 195 this.setAttribute('role', 'listbox'); |
| 198 | 196 |
| 199 var self = this; | 197 var self = this; |
| 200 this.itemConstructor = function(path) { | 198 this.itemConstructor = function(path) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 /** | 305 /** |
| 308 * Selects the n-th volume from the list. | 306 * Selects the n-th volume from the list. |
| 309 * @param {number} index Volume index. | 307 * @param {number} index Volume index. |
| 310 * @return {boolean} True for success, otherwise false. | 308 * @return {boolean} True for success, otherwise false. |
| 311 */ | 309 */ |
| 312 VolumeList.prototype.selectByIndex = function(index) { | 310 VolumeList.prototype.selectByIndex = function(index) { |
| 313 if (index < 0 || index > this.dataModel.length - 1) | 311 if (index < 0 || index > this.dataModel.length - 1) |
| 314 return false; | 312 return false; |
| 315 | 313 |
| 316 var newPath = this.dataModel.item(index); | 314 var newPath = this.dataModel.item(index); |
| 317 if (!newPath || this.currentVolume_ == newPath) | 315 if (!newPath || this.directoryModel.getCurrentDirEntry().fullPath == newPath) |
|
mtomasz
2013/08/05 12:17:57
directoryModel -> directoryModel_
mtomasz
2013/08/05 12:17:57
I think this will not work as it should. getCurren
yoshiki
2013/08/05 16:08:01
Done.
yoshiki
2013/08/05 16:08:01
It should work. Previous code was wrong.
Before i
mtomasz
2013/08/05 16:25:52
I see. My concern is that this check was used to a
| |
| 318 return false; | 316 return false; |
| 319 | 317 |
| 320 this.currentVolume_ = newPath; | 318 this.directoryModel_.changeDirectory(newPath); |
| 321 this.directoryModel_.changeDirectory(this.currentVolume_); | |
| 322 return true; | 319 return true; |
| 323 }; | 320 }; |
| 324 | 321 |
| 325 /** | 322 /** |
| 326 * Handler before root item change. | 323 * Handler before root item change. |
| 327 * @param {Event} event The event. | 324 * @param {Event} event The event. |
| 328 * @private | 325 * @private |
| 329 */ | 326 */ |
| 330 VolumeList.prototype.onBeforeSelectionChange_ = function(event) { | 327 VolumeList.prototype.onBeforeSelectionChange_ = function(event) { |
| 331 if (event.changes.length == 1 && !event.changes[0].selected) | 328 if (event.changes.length == 1 && !event.changes[0].selected) |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 348 | 345 |
| 349 /** | 346 /** |
| 350 * Invoked when the current directory is changed. | 347 * Invoked when the current directory is changed. |
| 351 * @param {Event} event The event. | 348 * @param {Event} event The event. |
| 352 * @private | 349 * @private |
| 353 */ | 350 */ |
| 354 VolumeList.prototype.onCurrentDirectoryChanged_ = function(event) { | 351 VolumeList.prototype.onCurrentDirectoryChanged_ = function(event) { |
| 355 var path = event.newDirEntry.fullPath || this.dataModel.getCurrentDirPath(); | 352 var path = event.newDirEntry.fullPath || this.dataModel.getCurrentDirPath(); |
| 356 var newRootPath = PathUtil.getRootPath(path); | 353 var newRootPath = PathUtil.getRootPath(path); |
| 357 | 354 |
| 358 // Sets |this.currentVolume_| in advance to prevent |onSelectionChange_()| | |
| 359 // from calling |DirectoryModel.ChangeDirectory()| again. | |
| 360 this.currentVolume_ = newRootPath; | |
| 361 | |
| 362 // Synchronizes the volume list selection with the current directory, after | 355 // Synchronizes the volume list selection with the current directory, after |
| 363 // it is changed outside of the volume list. | 356 // it is changed outside of the volume list. |
| 364 | 357 |
| 365 // (1) Select the nearest parent directory (including the pinned directories). | 358 // (1) Select the nearest parent directory (including the pinned directories). |
| 366 var bestMatchIndex = -1; | 359 var bestMatchIndex = -1; |
| 367 var bestMatchSubStringLen = 0; | 360 var bestMatchSubStringLen = 0; |
| 368 for (var i = 0; i < this.dataModel.length; i++) { | 361 for (var i = 0; i < this.dataModel.length; i++) { |
| 369 var itemPath = this.dataModel.item(i); | 362 var itemPath = this.dataModel.item(i); |
| 370 if (path.indexOf(itemPath) == 0) { | 363 if (path.indexOf(itemPath) == 0) { |
| 371 if (bestMatchSubStringLen < itemPath.length) { | 364 if (bestMatchSubStringLen < itemPath.length) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 387 var itemPath = this.dataModel.item(i); | 380 var itemPath = this.dataModel.item(i); |
| 388 if (PathUtil.getRootPath(itemPath) == newRootPath) { | 381 if (PathUtil.getRootPath(itemPath) == newRootPath) { |
| 389 // Not to invoke the handler of this instance, sets the guard. | 382 // Not to invoke the handler of this instance, sets the guard. |
| 390 this.dontHandleSelectionEvent_ = true; | 383 this.dontHandleSelectionEvent_ = true; |
| 391 this.selectionModel.selectedIndex = i; | 384 this.selectionModel.selectedIndex = i; |
| 392 this.dontHandleSelectionEvent_ = false; | 385 this.dontHandleSelectionEvent_ = false; |
| 393 return; | 386 return; |
| 394 } | 387 } |
| 395 } | 388 } |
| 396 }; | 389 }; |
| OLD | NEW |