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 * Entry of NavigationListModel. This construtor should be called only from | 8 * Entry of NavigationListModel. This construtor should be called only from |
| 9 * the helper methods (NavigationModelItem.createWithPath/createWithEntry). | 9 * the helper methods (NavigationModelItem.createWithPath/createWithEntry). |
| 10 * | 10 * |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 function NavigationList() { | 439 function NavigationList() { |
| 440 } | 440 } |
| 441 | 441 |
| 442 /** | 442 /** |
| 443 * NavigationList inherits cr.ui.List. | 443 * NavigationList inherits cr.ui.List. |
| 444 */ | 444 */ |
| 445 NavigationList.prototype = { | 445 NavigationList.prototype = { |
| 446 __proto__: cr.ui.List.prototype, | 446 __proto__: cr.ui.List.prototype, |
| 447 | 447 |
| 448 set dataModel(dataModel) { | 448 set dataModel(dataModel) { |
| 449 if (!this.boundHandleListChanged_) | |
| 450 this.boundHandleListChanged_ = this.onListContentChanged_.bind(this); | |
| 451 | |
| 452 if (this.dataModel_) { | |
| 453 dataModel.removeEventListener('change', this.boundHandleListChanged_); | |
| 454 dataModel.removeEventListener('permuted', this.boundHandleListChanged_); | |
| 455 } | |
| 456 | |
| 457 dataModel.addEventListener('change', this.boundHandleListChanged_); | |
| 458 dataModel.addEventListener('permuted', this.boundHandleListChanged_); | |
| 459 | |
| 460 var parentSetter = cr.ui.List.prototype.__lookupSetter__('dataModel'); | 449 var parentSetter = cr.ui.List.prototype.__lookupSetter__('dataModel'); |
| 461 return parentSetter.call(this, dataModel); | 450 return parentSetter.call(this, dataModel); |
| 462 }, | 451 }, |
| 463 | 452 |
| 464 get dataModel() { | 453 get dataModel() { |
| 465 return this.dataModel_; | 454 return this.dataModel_; |
| 466 }, | 455 }, |
| 467 | 456 |
| 468 // TODO(yoshiki): Add a setter of 'directoryModel'. | 457 // TODO(yoshiki): Add a setter of 'directoryModel'. |
| 469 }; | 458 }; |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 685 /** | 674 /** |
| 686 * Invoked when the current directory is changed. | 675 * Invoked when the current directory is changed. |
| 687 * @param {Event} event The event. | 676 * @param {Event} event The event. |
| 688 * @private | 677 * @private |
| 689 */ | 678 */ |
| 690 NavigationList.prototype.onCurrentDirectoryChanged_ = function(event) { | 679 NavigationList.prototype.onCurrentDirectoryChanged_ = function(event) { |
| 691 this.selectBestMatchItem_(); | 680 this.selectBestMatchItem_(); |
| 692 }; | 681 }; |
| 693 | 682 |
| 694 /** | 683 /** |
| 695 * Invoked when the content in the data model is changed. | 684 * Redraw the list. |
| 696 * @param {Event} event The event. | 685 * @override |
| 686 */ | |
| 687 NavigationList.prototype.redraw = function() { | |
| 688 // Calls the parent class method. | |
| 689 cr.ui.List.prototype.redraw.call(this); | |
| 690 this.onListContentChanged_(); | |
|
hirono
2013/09/03 09:47:21
It seems that the redraw event is raised at the sc
yoshiki
2013/09/04 13:21:11
Thanks for good catching. I've found it can be fix
| |
| 691 }; | |
| 692 | |
| 693 /** | |
| 694 * Invoked when the elements in the list is updated. | |
| 697 * @private | 695 * @private |
| 698 */ | 696 */ |
| 699 NavigationList.prototype.onListContentChanged_ = function(event) { | 697 NavigationList.prototype.onListContentChanged_ = function() { |
| 700 this.selectBestMatchItem_(); | 698 this.selectBestMatchItem_(); |
| 701 }; | 699 }; |
| 702 | 700 |
| 703 /** | 701 /** |
| 704 * Synchronizes the volume list selection with the current directory, after | 702 * Synchronizes the volume list selection with the current directory, after |
| 705 * it is changed outside of the volume list. | 703 * it is changed outside of the volume list. |
| 706 * @private | 704 * @private |
| 707 */ | 705 */ |
| 708 NavigationList.prototype.selectBestMatchItem_ = function() { | 706 NavigationList.prototype.selectBestMatchItem_ = function() { |
| 707 if (!this.dataModel) | |
| 708 return; | |
| 709 | |
| 709 var entry = this.directoryModel_.getCurrentDirEntry(); | 710 var entry = this.directoryModel_.getCurrentDirEntry(); |
| 710 var path = entry && entry.fullPath; | 711 var path = entry && entry.fullPath; |
| 711 if (!path) | 712 if (!path) |
| 712 return; | 713 return; |
| 713 | 714 |
| 714 // (1) Select the nearest parent directory (including the shortcut folders). | 715 // (1) Select the nearest parent directory (including the shortcut folders). |
| 715 var bestMatchIndex = -1; | 716 var bestMatchIndex = -1; |
| 716 var bestMatchSubStringLen = 0; | 717 var bestMatchSubStringLen = 0; |
| 717 for (var i = 0; i < this.dataModel.length; i++) { | 718 for (var i = 0; i < this.dataModel.length; i++) { |
| 718 var itemPath = this.dataModel.item(i).path; | 719 var itemPath = this.dataModel.item(i).path; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 737 var itemPath = this.dataModel.item(i).path; | 738 var itemPath = this.dataModel.item(i).path; |
| 738 if (PathUtil.getRootPath(itemPath) == newRootPath) { | 739 if (PathUtil.getRootPath(itemPath) == newRootPath) { |
| 739 // Not to invoke the handler of this instance, sets the guard. | 740 // Not to invoke the handler of this instance, sets the guard. |
| 740 this.dontHandleSelectionEvent_ = true; | 741 this.dontHandleSelectionEvent_ = true; |
| 741 this.selectionModel.selectedIndex = i; | 742 this.selectionModel.selectedIndex = i; |
| 742 this.dontHandleSelectionEvent_ = false; | 743 this.dontHandleSelectionEvent_ = false; |
| 743 return; | 744 return; |
| 744 } | 745 } |
| 745 } | 746 } |
| 746 }; | 747 }; |
| OLD | NEW |