Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: chrome/browser/resources/options/cookies_list.js

Issue 543493002: Compile chrome://settings, part 2: reduce from 950 to 400 errors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@F_settings
Patch Set: rebase? rebase! Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 * when the page is zoomed. See the similar calculation in @{code cr.ui.List}. 50 * when the page is zoomed. See the similar calculation in @{code cr.ui.List}.
51 * This version also accounts for the animation done in this file. 51 * This version also accounts for the animation done in this file.
52 * @param {Element} item The item to get the height of. 52 * @param {Element} item The item to get the height of.
53 * @return {number} The height of the item, calculated with zooming in mind. 53 * @return {number} The height of the item, calculated with zooming in mind.
54 */ 54 */
55 function getItemHeight(item) { 55 function getItemHeight(item) {
56 var height = item.style.height; 56 var height = item.style.height;
57 // Use the fixed animation target height if set, in case the element is 57 // Use the fixed animation target height if set, in case the element is
58 // currently being animated and we'd get an intermediate height below. 58 // currently being animated and we'd get an intermediate height below.
59 if (height && height.substr(-2) == 'px') 59 if (height && height.substr(-2) == 'px')
60 return parseInt(height.substr(0, height.length - 2)); 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.<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;
80 } 80 }
81 81
82 /** 82 /**
83 * Adds information about an app that protects this data item to the 83 * Adds information about an app that protects this data item to the
84 * @{code element}. 84 * |element|.
85 * @param {Element} element The DOM element the information should be 85 * @param {Element} element The DOM element the information should be
86 appended to. 86 appended to.
87 * @param {{id: string, name: string}} appInfo Information about an app. 87 * @param {{id: string, name: string}} appInfo Information about an app.
88 */ 88 */
89 function addAppInfo(element, appInfo) { 89 function addAppInfo(element, appInfo) {
90 var img = element.ownerDocument.createElement('img'); 90 var img = element.ownerDocument.createElement('img');
91 img.src = 'chrome://extension-icon/' + appInfo.id + '/16/1'; 91 img.src = 'chrome://extension-icon/' + appInfo.id + '/16/1';
92 element.title = loadTimeData.getString('label_protected_by_apps') + 92 element.title = loadTimeData.getString('label_protected_by_apps') +
93 ' ' + appInfo.name; 93 ' ' + appInfo.name;
94 img.className = 'protecting-app'; 94 img.className = 'protecting-app';
95 element.appendChild(img); 95 element.appendChild(img);
96 } 96 }
97 97
98 var parentLookup = {}; 98 var parentLookup = {};
99 var lookupRequests = {}; 99 var lookupRequests = {};
100 100
101 /** 101 /**
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 {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 {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(null);
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
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 if (!this.classList.contains('measure-items')) 222 if (!this.classList.contains('measure-items'))
223 this.disableAnimation_(); 223 this.disableAnimation_();
224 this.itemsChild.style.height = ''; 224 this.itemsChild.style.height = '';
225 // This will force relayout in order to calculate the new heights. 225 // This will force relayout in order to calculate the new heights.
226 var itemsHeight = getItemHeight(this.itemsChild); 226 var itemsHeight = getItemHeight(this.itemsChild);
227 var fixedHeight = getItemHeight(this) + itemsHeight - this.itemsHeight_; 227 var fixedHeight = getItemHeight(this) + itemsHeight - this.itemsHeight_;
228 this.itemsChild.style.height = this.itemsHeight_ + 'px'; 228 this.itemsChild.style.height = this.itemsHeight_ + 'px';
229 // Force relayout before enabling animation, so that if we have 229 // Force relayout before enabling animation, so that if we have
230 // changed things since the last layout, they will not be animated 230 // changed things since the last layout, they will not be animated
231 // during subsequent layouts. 231 // during subsequent layouts.
232 /** @suppress {suspiciousCode} */
232 this.itemsChild.offsetHeight; 233 this.itemsChild.offsetHeight;
233 this.classList.remove('measure-items'); 234 this.classList.remove('measure-items');
234 this.itemsChild.style.height = itemsHeight + 'px'; 235 this.itemsChild.style.height = itemsHeight + 'px';
235 this.style.height = fixedHeight + 'px'; 236 this.style.height = fixedHeight + 'px';
236 }, 237 },
237 238
238 /** 239 /**
239 * Updates the origin summary to reflect changes in its items. 240 * Updates the origin summary to reflect changes in its items.
240 * Both CookieListItem and CookieTreeNode implement this API. 241 * Both CookieListItem and CookieTreeNode implement this API.
241 * This implementation scans the descendants to update the text. 242 * This implementation scans the descendants to update the text.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 /** 335 /**
335 * Get the currently selected cookie node ("cookie bubble") index. 336 * Get the currently selected cookie node ("cookie bubble") index.
336 * @type {number} 337 * @type {number}
337 */ 338 */
338 get selectedIndex() { 339 get selectedIndex() {
339 return this.selectedIndex_; 340 return this.selectedIndex_;
340 }, 341 },
341 342
342 /** 343 /**
343 * Set the currently selected cookie node ("cookie bubble") index to 344 * Set the currently selected cookie node ("cookie bubble") index to
344 * @{code itemIndex}, unselecting any previously selected node first. 345 * |itemIndex|, unselecting any previously selected node first.
345 * @param {number} itemIndex The index to set as the selected index. 346 * @param {number} itemIndex The index to set as the selected index.
346 */ 347 */
347 set selectedIndex(itemIndex) { 348 set selectedIndex(itemIndex) {
348 // Get the list index up front before we change anything. 349 // Get the list index up front before we change anything.
349 var index = this.list.getIndexOfListItem(this); 350 var index = this.list.getIndexOfListItem(this);
350 // Unselect any previously selected item. 351 // Unselect any previously selected item.
351 if (this.selectedIndex_ >= 0) { 352 if (this.selectedIndex_ >= 0) {
352 var item = this.itemList_[this.selectedIndex_]; 353 var item = this.itemList_[this.selectedIndex_];
353 if (item && item.div) 354 if (item && item.div)
354 item.div.removeAttribute('selected'); 355 item.div.removeAttribute('selected');
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 if (parent && parent instanceof CookieTreeNode) 671 if (parent && parent instanceof CookieTreeNode)
671 return parent.pathId + ',' + this.data.id; 672 return parent.pathId + ',' + this.data.id;
672 return this.data.id; 673 return this.data.id;
673 }, 674 },
674 }; 675 };
675 676
676 /** 677 /**
677 * Creates a new cookies list. 678 * Creates a new cookies list.
678 * @param {Object=} opt_propertyBag Optional properties. 679 * @param {Object=} opt_propertyBag Optional properties.
679 * @constructor 680 * @constructor
680 * @extends {DeletableItemList} 681 * @extends {options.DeletableItemList}
681 */ 682 */
682 var CookiesList = cr.ui.define('list'); 683 var CookiesList = cr.ui.define('list');
683 684
684 CookiesList.prototype = { 685 CookiesList.prototype = {
685 __proto__: DeletableItemList.prototype, 686 __proto__: DeletableItemList.prototype,
686 687
687 /** @override */ 688 /** @override */
688 decorate: function() { 689 decorate: function() {
689 DeletableItemList.prototype.decorate.call(this); 690 DeletableItemList.prototype.decorate.call(this);
690 this.classList.add('cookie-list'); 691 this.classList.add('cookie-list');
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 parent.clear(); 919 parent.clear();
919 this.addByParent_(parent, 0, children); 920 this.addByParent_(parent, 0, children);
920 parent.endBatchUpdates(); 921 parent.endBatchUpdates();
921 }, 922 },
922 }; 923 };
923 924
924 return { 925 return {
925 CookiesList: CookiesList 926 CookiesList: CookiesList
926 }; 927 };
927 }); 928 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/controlled_setting.js ('k') | chrome/browser/resources/options/cookies_view.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698