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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 if (height && height.substr(-2) == 'px') | 59 if (height && height.substr(-2) == 'px') |
60 return parseInt(height.substr(0, height.length - 2), 10); | 60 return parseInt(height.substr(0, height.length - 2), 10); |
61 return item.getBoundingClientRect().height; | 61 return item.getBoundingClientRect().height; |
62 } | 62 } |
63 | 63 |
64 /** | 64 /** |
65 * Create tree nodes for the objects in the data array, and insert them all | 65 * Create tree nodes for the objects in the data array, and insert them all |
66 * into the given list using its @{code splice} method at the given index. | 66 * into the given list using its @{code splice} method at the given index. |
67 * @param {Array.<Object>} data The data objects for the nodes to add. | 67 * @param {Array.<Object>} data The data objects for the nodes to add. |
68 * @param {number} start The index at which to start inserting the nodes. | 68 * @param {number} start The index at which to start inserting the nodes. |
69 * @return {Array.<CookieTreeNode>} An array of CookieTreeNodes added. | 69 * @return {Array.<options.CookieTreeNode>} An array of CookieTreeNodes added. |
70 */ | 70 */ |
71 function spliceTreeNodes(data, start, list) { | 71 function spliceTreeNodes(data, start, list) { |
72 var nodes = data.map(function(x) { return new CookieTreeNode(x); }); | 72 var nodes = data.map(function(x) { return new CookieTreeNode(x); }); |
73 // Insert [start, 0] at the beginning of the array of nodes, making it | 73 // Insert [start, 0] at the beginning of the array of nodes, making it |
74 // into the arguments we want to pass to @{code list.splice} below. | 74 // into the arguments we want to pass to @{code list.splice} below. |
75 nodes.splice(0, 0, start, 0); | 75 nodes.splice(0, 0, start, 0); |
76 list.splice.apply(list, nodes); | 76 list.splice.apply(list, nodes); |
77 // Remove the [start, 0] prefix and return the array of nodes. | 77 // Remove the [start, 0] prefix and return the array of nodes. |
78 nodes.splice(0, 2); | 78 nodes.splice(0, 2); |
79 return nodes; | 79 return nodes; |
(...skipping 22 matching lines...) Expand all Loading... |
102 * Creates a new list item for sites data. Note that these are created and | 102 * Creates a new list item for sites data. Note that these are created and |
103 * destroyed lazily as they scroll into and out of view, so they must be | 103 * destroyed lazily as they scroll into and out of view, so they must be |
104 * stateless. We cache the expanded item in @{code CookiesList} though, so it | 104 * stateless. We cache the expanded item in @{code CookiesList} though, so it |
105 * can keep state. (Mostly just which item is selected.) | 105 * can keep state. (Mostly just which item is selected.) |
106 * @param {Object} origin Data used to create a cookie list item. | 106 * @param {Object} origin Data used to create a cookie list item. |
107 * @param {options.CookiesList} list The list that will contain this item. | 107 * @param {options.CookiesList} list The list that will contain this item. |
108 * @constructor | 108 * @constructor |
109 * @extends {options.DeletableItem} | 109 * @extends {options.DeletableItem} |
110 */ | 110 */ |
111 function CookieListItem(origin, list) { | 111 function CookieListItem(origin, list) { |
112 var listItem = new DeletableItem(null); | 112 var listItem = new DeletableItem(); |
113 listItem.__proto__ = CookieListItem.prototype; | 113 listItem.__proto__ = CookieListItem.prototype; |
114 | 114 |
115 listItem.origin = origin; | 115 listItem.origin = origin; |
116 listItem.list = list; | 116 listItem.list = list; |
117 listItem.decorate(); | 117 listItem.decorate(); |
118 | 118 |
119 // This hooks up updateOrigin() to the list item, makes the top-level | 119 // This hooks up updateOrigin() to the list item, makes the top-level |
120 // tree nodes (i.e., origins) register their IDs in parentLookup, and | 120 // tree nodes (i.e., origins) register their IDs in parentLookup, and |
121 // causes them to request their children if they have none. Note that we | 121 // causes them to request their children if they have none. Note that we |
122 // have special logic in the setter for the parent property to make sure | 122 // have special logic in the setter for the parent property to make sure |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 this.selectedIndex_ = -1; | 308 this.selectedIndex_ = -1; |
309 this.itemList_ = []; | 309 this.itemList_ = []; |
310 if (this.origin) | 310 if (this.origin) |
311 this.origin.createItems(this); | 311 this.origin.createItems(this); |
312 this.itemsChild.appendChild(this.infoChild); | 312 this.itemsChild.appendChild(this.infoChild); |
313 this.enableAnimation_(); | 313 this.enableAnimation_(); |
314 }, | 314 }, |
315 | 315 |
316 /** | 316 /** |
317 * Append a new cookie node "bubble" to this list item. | 317 * Append a new cookie node "bubble" to this list item. |
318 * @param {CookieTreeNode} node The cookie node to add a bubble for. | 318 * @param {options.CookieTreeNode} node The cookie node to add a bubble for. |
319 * @param {Element} div The DOM element for the bubble itself. | 319 * @param {Element} div The DOM element for the bubble itself. |
320 * @return {number} The index the bubble was added at. | 320 * @return {number} The index the bubble was added at. |
321 */ | 321 */ |
322 appendItem: function(node, div) { | 322 appendItem: function(node, div) { |
323 this.itemList_.push({node: node, div: div}); | 323 this.itemList_.push({node: node, div: div}); |
324 this.itemsChild.appendChild(div); | 324 this.itemsChild.appendChild(div); |
325 return this.itemList_.length - 1; | 325 return this.itemList_.length - 1; |
326 }, | 326 }, |
327 | 327 |
328 /** | 328 /** |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 apps.forEach(function(appInfo) { | 501 apps.forEach(function(appInfo) { |
502 info.appsProtectingThis[appInfo.id] = appInfo; | 502 info.appsProtectingThis[appInfo.id] = appInfo; |
503 }); | 503 }); |
504 } | 504 } |
505 } | 505 } |
506 }, | 506 }, |
507 | 507 |
508 /** | 508 /** |
509 * Create the cookie "bubbles" for this node, recursing into children | 509 * Create the cookie "bubbles" for this node, recursing into children |
510 * if there are any. Append the cookie bubbles to @{code item}. | 510 * if there are any. Append the cookie bubbles to @{code item}. |
511 * @param {CookieListItem} item The cookie list item to create items in. | 511 * @param {options.CookieListItem} item The cookie list item to create items |
| 512 * in. |
512 */ | 513 */ |
513 createItems: function(item) { | 514 createItems: function(item) { |
514 if (this.children.length > 0) { | 515 if (this.children.length > 0) { |
515 for (var i = 0; i < this.children.length; ++i) | 516 for (var i = 0; i < this.children.length; ++i) |
516 this.children[i].createItems(item); | 517 this.children[i].createItems(item); |
517 return; | 518 return; |
518 } | 519 } |
519 | 520 |
520 if (!this.data || this.data.hasChildren) | 521 if (!this.data || this.data.hasChildren) |
521 return; | 522 return; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 | 575 |
575 while (element.childNodes.length > 1) | 576 while (element.childNodes.length > 1) |
576 element.removeChild(element.firstChild); | 577 element.removeChild(element.firstChild); |
577 | 578 |
578 if (table) | 579 if (table) |
579 element.insertBefore(table, element.firstChild); | 580 element.insertBefore(table, element.firstChild); |
580 }, | 581 }, |
581 | 582 |
582 /** | 583 /** |
583 * The parent of this cookie tree node. | 584 * The parent of this cookie tree node. |
584 * @type {?CookieTreeNode|CookieListItem} | 585 * @type {?(options.CookieTreeNode|options.CookieListItem)} |
585 */ | 586 */ |
586 get parent() { | 587 get parent() { |
587 // See below for an explanation of this special case. | 588 // See below for an explanation of this special case. |
588 if (typeof this.parent_ == 'number') | 589 if (typeof this.parent_ == 'number') |
589 return this.list_.getListItemByIndex(this.parent_); | 590 return this.list_.getListItemByIndex(this.parent_); |
590 return this.parent_; | 591 return this.parent_; |
591 }, | 592 }, |
592 set parent(parent) { | 593 set parent(parent) { |
593 if (parent == this.parent) | 594 if (parent == this.parent) |
594 return; | 595 return; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 } | 790 } |
790 if (pe.newValue != -1) { | 791 if (pe.newValue != -1) { |
791 var listItem = this.getListItemByIndex(pe.newValue); | 792 var listItem = this.getListItemByIndex(pe.newValue); |
792 if (listItem && listItem.selected) | 793 if (listItem && listItem.selected) |
793 listItem.expanded = true; | 794 listItem.expanded = true; |
794 } | 795 } |
795 }, | 796 }, |
796 | 797 |
797 /** | 798 /** |
798 * The currently expanded item. Used by CookieListItem above. | 799 * The currently expanded item. Used by CookieListItem above. |
799 * @type {?CookieListItem} | 800 * @type {?options.CookieListItem} |
800 */ | 801 */ |
801 expandedItem: null, | 802 expandedItem: null, |
802 | 803 |
803 // from cr.ui.List | 804 // from cr.ui.List |
804 /** @override */ | 805 /** |
| 806 * @override |
| 807 * @param {Object} data |
| 808 */ |
805 createItem: function(data) { | 809 createItem: function(data) { |
806 // We use the cached expanded item in order to allow it to maintain some | 810 // We use the cached expanded item in order to allow it to maintain some |
807 // state (like its fixed height, and which bubble is selected). | 811 // state (like its fixed height, and which bubble is selected). |
808 if (this.expandedItem && this.expandedItem.origin == data) | 812 if (this.expandedItem && this.expandedItem.origin == data) |
809 return this.expandedItem; | 813 return this.expandedItem; |
810 return new CookieListItem(data, this); | 814 return new CookieListItem(data, this); |
811 }, | 815 }, |
812 | 816 |
813 // from options.DeletableItemList | 817 // from options.DeletableItemList |
814 /** @override */ | 818 /** @override */ |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 return; | 920 return; |
917 | 921 |
918 parent.startBatchUpdates(); | 922 parent.startBatchUpdates(); |
919 parent.clear(); | 923 parent.clear(); |
920 this.addByParent_(parent, 0, children); | 924 this.addByParent_(parent, 0, children); |
921 parent.endBatchUpdates(); | 925 parent.endBatchUpdates(); |
922 }, | 926 }, |
923 }; | 927 }; |
924 | 928 |
925 return { | 929 return { |
926 CookiesList: CookiesList | 930 CookiesList: CookiesList, |
| 931 CookieListItem: CookieListItem, |
| 932 CookieTreeNode: CookieTreeNode, |
927 }; | 933 }; |
928 }); | 934 }); |
OLD | NEW |