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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // Use the fixed animation target height if set, in case the element is | 58 // Use the fixed animation target height if set, in case the element is |
59 // currently being animated and we'd get an intermediate height below. | 59 // currently being animated and we'd get an intermediate height below. |
60 if (height && height.substr(-2) == 'px') | 60 if (height && height.substr(-2) == 'px') |
61 return parseInt(height.substr(0, height.length - 2), 10); | 61 return parseInt(height.substr(0, height.length - 2), 10); |
62 return item.getBoundingClientRect().height; | 62 return item.getBoundingClientRect().height; |
63 } | 63 } |
64 | 64 |
65 /** | 65 /** |
66 * Create tree nodes for the objects in the data array, and insert them all | 66 * Create tree nodes for the objects in the data array, and insert them all |
67 * into the given list using its @{code splice} method at the given index. | 67 * into the given list using its @{code splice} method at the given index. |
68 * @param {Array.<Object>} data The data objects for the nodes to add. | 68 * @param {Array<Object>} data The data objects for the nodes to add. |
69 * @param {number} start The index at which to start inserting the nodes. | 69 * @param {number} start The index at which to start inserting the nodes. |
70 * @return {Array.<options.CookieTreeNode>} An array of CookieTreeNodes added. | 70 * @return {Array<options.CookieTreeNode>} An array of CookieTreeNodes added. |
71 */ | 71 */ |
72 function spliceTreeNodes(data, start, list) { | 72 function spliceTreeNodes(data, start, list) { |
73 var nodes = data.map(function(x) { return new CookieTreeNode(x); }); | 73 var nodes = data.map(function(x) { return new CookieTreeNode(x); }); |
74 // Insert [start, 0] at the beginning of the array of nodes, making it | 74 // Insert [start, 0] at the beginning of the array of nodes, making it |
75 // into the arguments we want to pass to @{code list.splice} below. | 75 // into the arguments we want to pass to @{code list.splice} below. |
76 nodes.splice(0, 0, start, 0); | 76 nodes.splice(0, 0, start, 0); |
77 list.splice.apply(list, nodes); | 77 list.splice.apply(list, nodes); |
78 // Remove the [start, 0] prefix and return the array of nodes. | 78 // Remove the [start, 0] prefix and return the array of nodes. |
79 nodes.splice(0, 2); | 79 nodes.splice(0, 2); |
80 return nodes; | 80 return nodes; |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 */ | 389 */ |
390 function CookieTreeNode(data) { | 390 function CookieTreeNode(data) { |
391 this.data = data; | 391 this.data = data; |
392 this.children = []; | 392 this.children = []; |
393 } | 393 } |
394 | 394 |
395 CookieTreeNode.prototype = { | 395 CookieTreeNode.prototype = { |
396 /** | 396 /** |
397 * Insert the given list of cookie tree nodes at the given index. | 397 * Insert the given list of cookie tree nodes at the given index. |
398 * Both CookiesList and CookieTreeNode implement this API. | 398 * Both CookiesList and CookieTreeNode implement this API. |
399 * @param {Array.<Object>} data The data objects for the nodes to add. | 399 * @param {Array<Object>} data The data objects for the nodes to add. |
400 * @param {number} start The index at which to start inserting the nodes. | 400 * @param {number} start The index at which to start inserting the nodes. |
401 */ | 401 */ |
402 insertAt: function(data, start) { | 402 insertAt: function(data, start) { |
403 var nodes = spliceTreeNodes(data, start, this.children); | 403 var nodes = spliceTreeNodes(data, start, this.children); |
404 for (var i = 0; i < nodes.length; i++) | 404 for (var i = 0; i < nodes.length; i++) |
405 nodes[i].parent = this; | 405 nodes[i].parent = this; |
406 this.updateOrigin(); | 406 this.updateOrigin(); |
407 }, | 407 }, |
408 | 408 |
409 /** | 409 /** |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 div.onclick = function() { | 547 div.onclick = function() { |
548 item.selectedIndex = (item.selectedIndex == index) ? -1 : index; | 548 item.selectedIndex = (item.selectedIndex == index) ? -1 : index; |
549 }; | 549 }; |
550 }, | 550 }, |
551 | 551 |
552 /** | 552 /** |
553 * Set the detail text to be displayed to that of this cookie tree node. | 553 * Set the detail text to be displayed to that of this cookie tree node. |
554 * Uses preallocated DOM elements for each cookie node type from @{code | 554 * Uses preallocated DOM elements for each cookie node type from @{code |
555 * infoNodes}, and inserts the appropriate elements to @{code element}. | 555 * infoNodes}, and inserts the appropriate elements to @{code element}. |
556 * @param {Element} element The DOM element to insert elements to. | 556 * @param {Element} element The DOM element to insert elements to. |
557 * @param {Object.<string, {table: Element, info: Object.<string, | 557 * @param {Object<string, {table: Element, info: Object<string, |
558 * Element>}>} infoNodes The map from cookie node types to maps from | 558 * Element>}>} infoNodes The map from cookie node types to maps from |
559 * cookie attribute names to DOM elements to display cookie attribute | 559 * cookie attribute names to DOM elements to display cookie attribute |
560 * values, created by @{code CookiesList.decorate}. | 560 * values, created by @{code CookiesList.decorate}. |
561 */ | 561 */ |
562 setDetailText: function(element, infoNodes) { | 562 setDetailText: function(element, infoNodes) { |
563 var table; | 563 var table; |
564 if (this.data && !this.data.hasChildren && cookieInfo[this.data.type]) { | 564 if (this.data && !this.data.hasChildren && cookieInfo[this.data.type]) { |
565 var info = cookieInfo[this.data.type]; | 565 var info = cookieInfo[this.data.type]; |
566 var nodes = infoNodes[this.data.type].info; | 566 var nodes = infoNodes[this.data.type].info; |
567 for (var i = 0; i < info.length; ++i) { | 567 for (var i = 0; i < info.length; ++i) { |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 if (item) { | 822 if (item) { |
823 var pathId = item.pathId; | 823 var pathId = item.pathId; |
824 if (pathId) | 824 if (pathId) |
825 chrome.send('removeCookie', [pathId]); | 825 chrome.send('removeCookie', [pathId]); |
826 } | 826 } |
827 }, | 827 }, |
828 | 828 |
829 /** | 829 /** |
830 * Insert the given list of cookie tree nodes at the given index. | 830 * Insert the given list of cookie tree nodes at the given index. |
831 * Both CookiesList and CookieTreeNode implement this API. | 831 * Both CookiesList and CookieTreeNode implement this API. |
832 * @param {Array.<Object>} data The data objects for the nodes to add. | 832 * @param {Array<Object>} data The data objects for the nodes to add. |
833 * @param {number} start The index at which to start inserting the nodes. | 833 * @param {number} start The index at which to start inserting the nodes. |
834 */ | 834 */ |
835 insertAt: function(data, start) { | 835 insertAt: function(data, start) { |
836 spliceTreeNodes(data, start, this.dataModel); | 836 spliceTreeNodes(data, start, this.dataModel); |
837 }, | 837 }, |
838 | 838 |
839 /** | 839 /** |
840 * Remove a cookie tree node from the given index. | 840 * Remove a cookie tree node from the given index. |
841 * Both CookiesList and CookieTreeNode implement this API. | 841 * Both CookiesList and CookieTreeNode implement this API. |
842 * @param {number} index The index of the tree node to remove. | 842 * @param {number} index The index of the tree node to remove. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 parent.endBatchUpdates(); | 926 parent.endBatchUpdates(); |
927 }, | 927 }, |
928 }; | 928 }; |
929 | 929 |
930 return { | 930 return { |
931 CookiesList: CookiesList, | 931 CookiesList: CookiesList, |
932 CookieListItem: CookieListItem, | 932 CookieListItem: CookieListItem, |
933 CookieTreeNode: CookieTreeNode, | 933 CookieTreeNode: CookieTreeNode, |
934 }; | 934 }; |
935 }); | 935 }); |
OLD | NEW |