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 cr.define('options', function() { | 5 cr.define('options', function() { |
6 /** @const */ var DeletableItemList = options.DeletableItemList; | 6 /** @const */ var DeletableItemList = options.DeletableItemList; |
7 /** @const */ var DeletableItem = options.DeletableItem; | 7 /** @const */ var DeletableItem = options.DeletableItem; |
8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
9 /** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; | 9 /** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; |
10 | 10 |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 */ | 619 */ |
620 var CookiesList = cr.ui.define('list'); | 620 var CookiesList = cr.ui.define('list'); |
621 | 621 |
622 CookiesList.prototype = { | 622 CookiesList.prototype = { |
623 __proto__: DeletableItemList.prototype, | 623 __proto__: DeletableItemList.prototype, |
624 | 624 |
625 /** @inheritDoc */ | 625 /** @inheritDoc */ |
626 decorate: function() { | 626 decorate: function() { |
627 DeletableItemList.prototype.decorate.call(this); | 627 DeletableItemList.prototype.decorate.call(this); |
628 this.classList.add('cookie-list'); | 628 this.classList.add('cookie-list'); |
629 this.data_ = []; | 629 this.dataModel = new ArrayDataModel([]); |
630 this.dataModel = new ArrayDataModel(this.data_); | |
631 this.addEventListener('keydown', this.handleKeyLeftRight_.bind(this)); | 630 this.addEventListener('keydown', this.handleKeyLeftRight_.bind(this)); |
632 var sm = new ListSingleSelectionModel(); | 631 var sm = new ListSingleSelectionModel(); |
633 sm.addEventListener('change', this.cookieSelectionChange_.bind(this)); | 632 sm.addEventListener('change', this.cookieSelectionChange_.bind(this)); |
634 sm.addEventListener('leadIndexChange', this.cookieLeadChange_.bind(this)); | 633 sm.addEventListener('leadIndexChange', this.cookieLeadChange_.bind(this)); |
635 this.selectionModel = sm; | 634 this.selectionModel = sm; |
636 this.infoNodes = {}; | 635 this.infoNodes = {}; |
637 this.fixedHeight = false; | 636 this.fixedHeight = false; |
638 var doc = this.ownerDocument; | 637 var doc = this.ownerDocument; |
639 // Create a table for each type of site data (e.g. cookies, databases, | 638 // Create a table for each type of site data (e.g. cookies, databases, |
640 // etc.) and save it so that we can reuse it for all origins. | 639 // etc.) and save it so that we can reuse it for all origins. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 // We use the cached expanded item in order to allow it to maintain some | 743 // We use the cached expanded item in order to allow it to maintain some |
745 // state (like its fixed height, and which bubble is selected). | 744 // state (like its fixed height, and which bubble is selected). |
746 if (this.expandedItem && this.expandedItem.origin == data) | 745 if (this.expandedItem && this.expandedItem.origin == data) |
747 return this.expandedItem; | 746 return this.expandedItem; |
748 return new CookieListItem(data, this); | 747 return new CookieListItem(data, this); |
749 }, | 748 }, |
750 | 749 |
751 // from options.DeletableItemList | 750 // from options.DeletableItemList |
752 /** @inheritDoc */ | 751 /** @inheritDoc */ |
753 deleteItemAtIndex: function(index) { | 752 deleteItemAtIndex: function(index) { |
754 var item = this.data_[index]; | 753 var item = this.dataModel.item(index); |
755 if (item) { | 754 if (item) { |
756 var pathId = item.pathId; | 755 var pathId = item.pathId; |
757 if (pathId) | 756 if (pathId) |
758 chrome.send('removeCookie', [pathId]); | 757 chrome.send('removeCookie', [pathId]); |
759 } | 758 } |
760 }, | 759 }, |
761 | 760 |
762 /** | 761 /** |
763 * Insert the given list of cookie tree nodes at the given index. | 762 * Insert the given list of cookie tree nodes at the given index. |
764 * Both CookiesList and CookieTreeNode implement this API. | 763 * Both CookiesList and CookieTreeNode implement this API. |
765 * @param {Array.<Object>} data The data objects for the nodes to add. | 764 * @param {Array.<Object>} data The data objects for the nodes to add. |
766 * @param {number} start The index at which to start inserting the nodes. | 765 * @param {number} start The index at which to start inserting the nodes. |
767 */ | 766 */ |
768 insertAt: function(data, start) { | 767 insertAt: function(data, start) { |
769 spliceTreeNodes(data, start, this.dataModel); | 768 spliceTreeNodes(data, start, this.dataModel); |
770 }, | 769 }, |
771 | 770 |
772 /** | 771 /** |
773 * Remove a cookie tree node from the given index. | 772 * Remove a cookie tree node from the given index. |
774 * Both CookiesList and CookieTreeNode implement this API. | 773 * Both CookiesList and CookieTreeNode implement this API. |
775 * @param {number} index The index of the tree node to remove. | 774 * @param {number} index The index of the tree node to remove. |
776 */ | 775 */ |
777 remove: function(index) { | 776 remove: function(index) { |
778 if (index < this.data_.length) | 777 if (index < this.dataModel.length) |
779 this.dataModel.splice(index, 1); | 778 this.dataModel.splice(index, 1); |
780 }, | 779 }, |
781 | 780 |
782 /** | 781 /** |
783 * Clears the list. | 782 * Clears the list. |
784 * Both CookiesList and CookieTreeNode implement this API. | 783 * Both CookiesList and CookieTreeNode implement this API. |
785 * It is used by CookiesList.loadChildren(). | 784 * It is used by CookiesList.loadChildren(). |
786 */ | 785 */ |
787 clear: function() { | 786 clear: function() { |
788 parentLookup = {}; | 787 parentLookup = {}; |
789 this.data_ = []; | 788 this.dataModel.splice(0, this.dataModel.length); |
790 this.dataModel = new ArrayDataModel(this.data_); | |
791 this.redraw(); | 789 this.redraw(); |
792 }, | 790 }, |
793 | 791 |
794 /** | 792 /** |
795 * Add tree nodes by given parent. | 793 * Add tree nodes by given parent. |
796 * @param {Object} parent The parent node. | 794 * @param {Object} parent The parent node. |
797 * @param {number} start The index at which to start inserting the nodes. | 795 * @param {number} start The index at which to start inserting the nodes. |
798 * @param {Array} nodesData Nodes data array. | 796 * @param {Array} nodesData Nodes data array. |
799 * @private | 797 * @private |
800 */ | 798 */ |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 parent.clear(); | 856 parent.clear(); |
859 this.addByParent_(parent, 0, children); | 857 this.addByParent_(parent, 0, children); |
860 parent.endBatchUpdates(); | 858 parent.endBatchUpdates(); |
861 }, | 859 }, |
862 }; | 860 }; |
863 | 861 |
864 return { | 862 return { |
865 CookiesList: CookiesList | 863 CookiesList: CookiesList |
866 }; | 864 }; |
867 }); | 865 }); |
OLD | NEW |