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 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 set parent(parent) { | 590 set parent(parent) { |
591 if (parent == this.parent) | 591 if (parent == this.parent) |
592 return; | 592 return; |
593 | 593 |
594 if (parent instanceof CookieListItem) { | 594 if (parent instanceof CookieListItem) { |
595 // If the parent is to be a CookieListItem, then we keep the reference | 595 // If the parent is to be a CookieListItem, then we keep the reference |
596 // to it by its containing list and list index, rather than directly. | 596 // to it by its containing list and list index, rather than directly. |
597 // This allows the list items to be garbage collected when they scroll | 597 // This allows the list items to be garbage collected when they scroll |
598 // out of view (except the expanded item, which we cache). This is | 598 // out of view (except the expanded item, which we cache). This is |
599 // transparent except in the setter and getter, where we handle it. | 599 // transparent except in the setter and getter, where we handle it. |
600 this.parent_ = parent.listIndex; | 600 if (this.parent_ == undefined || parent.listIndex != -1) { |
| 601 // Setting the parent is somewhat tricky because the CookieListItem |
| 602 // constructor has side-effects on the |origin| that it wraps. Every |
| 603 // time a CookieListItem is created for an |origin|, it registers |
| 604 // itself as the parent of the |origin|. |
| 605 // The List implementation may create a temporary CookieListItem item |
| 606 // that wraps the |origin| of the very first entry of the CokiesList, |
| 607 // when the List is redrawn the first time. This temporary |
| 608 // CookieListItem is fresh (has listIndex = -1) and is never inserted |
| 609 // into the List. Therefore it gets never updated. This destroys the |
| 610 // chain of parent pointers. |
| 611 // This is the stack trace: |
| 612 // CookieListItem |
| 613 // CookiesList.createItem |
| 614 // List.measureItem |
| 615 // List.getDefaultItemSize_ |
| 616 // List.getDefaultItemHeight_ |
| 617 // List.getIndexForListOffset_ |
| 618 // List.getItemsInViewPort |
| 619 // List.redraw |
| 620 // List.endBatchUpdates |
| 621 // CookiesList.loadChildren |
| 622 this.parent_ = parent.listIndex; |
| 623 } |
601 this.list_ = parent.list; | 624 this.list_ = parent.list; |
602 parent.addEventListener('listIndexChange', | 625 parent.addEventListener('listIndexChange', |
603 this.parentIndexChanged_.bind(this)); | 626 this.parentIndexChanged_.bind(this)); |
604 } else { | 627 } else { |
605 this.parent_ = parent; | 628 this.parent_ = parent; |
606 } | 629 } |
607 | 630 |
608 if (this.data && this.data.id) { | 631 if (this.data && this.data.id) { |
609 if (parent) | 632 if (parent) |
610 parentLookup[this.data.id] = this; | 633 parentLookup[this.data.id] = this; |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 parent.clear(); | 917 parent.clear(); |
895 this.addByParent_(parent, 0, children); | 918 this.addByParent_(parent, 0, children); |
896 parent.endBatchUpdates(); | 919 parent.endBatchUpdates(); |
897 }, | 920 }, |
898 }; | 921 }; |
899 | 922 |
900 return { | 923 return { |
901 CookiesList: CookiesList | 924 CookiesList: CookiesList |
902 }; | 925 }; |
903 }); | 926 }); |
OLD | NEW |