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

Side by Side Diff: chrome/browser/resources/shared/js/cr/ui/list.js

Issue 10824328: Reduce number of expensive calls to List.redraw() during load of settings page. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressed all comments. Created 8 years, 4 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
« no previous file with comments | « chrome/browser/resources/options2/content_settings_exceptions_area.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // require: array_data_model.js 5 // require: array_data_model.js
6 // require: list_selection_model.js 6 // require: list_selection_model.js
7 // require: list_selection_controller.js 7 // require: list_selection_controller.js
8 // require: list_item.js 8 // require: list_item.js
9 9
10 /** 10 /**
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 return { 941 return {
942 first: firstIndex, 942 first: firstIndex,
943 length: lastIndex - firstIndex + 1, 943 length: lastIndex - firstIndex + 1,
944 last: lastIndex + 1}; 944 last: lastIndex + 1};
945 } 945 }
946 }, 946 },
947 947
948 /** 948 /**
949 * Merges list items currently existing in the list with items in the range 949 * Merges list items currently existing in the list with items in the range
950 * [firstIndex, lastIndex). Removes or adds items if needed. 950 * [firstIndex, lastIndex). Removes or adds items if needed.
951 * Doesn't delete {@code this.pinnedItem_} if it presents (instead hides if 951 * Doesn't delete {@code this.pinnedItem_} if it is present (instead hides
952 * it's out of the range). Also adds the items to {@code newCachedItems}. 952 * it if it is out of the range). Adds items to {@code newCachedItems}.
953 * @param {number} firstIndex The index of first item, inclusively. 953 * @param {number} firstIndex The index of first item, inclusively.
954 * @param {number} lastIndex The index of last item, exclusively. 954 * @param {number} lastIndex The index of last item, exclusively.
955 * @param {Object.<string, ListItem>} cachedItems Old items cache. 955 * @param {Object.<string, ListItem>} cachedItems Old items cache.
956 * @param {Object.<string, ListItem>} newCachedItems New items cache. 956 * @param {Object.<string, ListItem>} newCachedItems New items cache.
957 */ 957 */
958 mergeItems: function(firstIndex, lastIndex, cachedItems, newCachedItems) { 958 mergeItems: function(firstIndex, lastIndex, cachedItems, newCachedItems) {
959 var self = this;
959 var dataModel = this.dataModel; 960 var dataModel = this.dataModel;
961 var currentIndex = firstIndex;
960 962
961 function insert(to) { 963 function insert() {
962 var dataItem = dataModel.item(currentIndex); 964 var dataItem = dataModel.item(currentIndex);
963 var newItem = cachedItems[currentIndex] || to.createItem(dataItem); 965 var newItem = cachedItems[currentIndex] || self.createItem(dataItem);
964 newItem.listIndex = currentIndex; 966 newItem.listIndex = currentIndex;
965 newCachedItems[currentIndex] = newItem; 967 newCachedItems[currentIndex] = newItem;
966 to.insertBefore(newItem, item); 968 self.insertBefore(newItem, item);
967 currentIndex++; 969 currentIndex++;
968 } 970 }
969 971
970 function remove(from) { 972 function remove() {
971 var next = item.nextSibling; 973 var next = item.nextSibling;
972 if (item != from.pinnedItem_) 974 if (item != self.pinnedItem_)
973 from.removeChild(item); 975 self.removeChild(item);
974 item = next; 976 item = next;
975 } 977 }
976 978
977 var currentIndex = firstIndex;
978 for (var item = this.beforeFiller_.nextSibling; 979 for (var item = this.beforeFiller_.nextSibling;
979 item != this.afterFiller_ && currentIndex < lastIndex;) { 980 item != this.afterFiller_ && currentIndex < lastIndex;) {
980 if (!this.isItem(item)) { 981 if (!this.isItem(item)) {
981 item = item.nextSibling; 982 item = item.nextSibling;
982 continue; 983 continue;
983 } 984 }
984 985
985 var index = item.listIndex; 986 var index = item.listIndex;
986 if (cachedItems[index] != item || index < currentIndex) { 987 if (cachedItems[index] != item || index < currentIndex) {
987 remove(this); 988 remove();
988 } else if (index == currentIndex) { 989 } else if (index == currentIndex) {
989 newCachedItems[currentIndex] = item; 990 newCachedItems[currentIndex] = item;
990 item = item.nextSibling; 991 item = item.nextSibling;
991 currentIndex++; 992 currentIndex++;
992 } else { // index > currentIndex 993 } else { // index > currentIndex
993 insert(this); 994 insert();
994 } 995 }
995 } 996 }
996 997
997 while (item != this.afterFiller_) { 998 while (item != this.afterFiller_) {
998 if (this.isItem(item)) 999 if (this.isItem(item))
999 remove(this); 1000 remove();
1000 else 1001 else
1001 item = item.nextSibling; 1002 item = item.nextSibling;
1002 } 1003 }
1003 1004
1004 if (this.pinnedItem_) { 1005 if (this.pinnedItem_) {
1005 var index = this.pinnedItem_.listIndex; 1006 var index = this.pinnedItem_.listIndex;
1006 this.pinnedItem_.hidden = index < firstIndex || index >= lastIndex; 1007 this.pinnedItem_.hidden = index < firstIndex || index >= lastIndex;
1007 newCachedItems[index] = this.pinnedItem_; 1008 newCachedItems[index] = this.pinnedItem_;
1008 if (index >= lastIndex) 1009 if (index >= lastIndex)
1009 item = this.pinnedItem_; // Insert new items before this one. 1010 item = this.pinnedItem_; // Insert new items before this one.
1010 } 1011 }
1011 1012
1012 while (currentIndex < lastIndex) 1013 while (currentIndex < lastIndex)
1013 insert(this); 1014 insert();
1014 }, 1015 },
1015 1016
1016 /** 1017 /**
1017 * Ensures that all the item sizes in the list have been already cached. 1018 * Ensures that all the item sizes in the list have been already cached.
1018 */ 1019 */
1019 ensureAllItemSizesInCache: function() { 1020 ensureAllItemSizesInCache: function() {
1020 var measuringIndexes = []; 1021 var measuringIndexes = [];
1021 var isElementAppended = []; 1022 var isElementAppended = [];
1022 for (var y = 0; y < this.dataModel.length; y++) { 1023 for (var y = 0; y < this.dataModel.length; y++) {
1023 if (!this.cachedItemHeights_[y]) { 1024 if (!this.cachedItemHeights_[y]) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 }, 1081 },
1081 1082
1082 /** 1083 /**
1083 * Redraws the viewport. 1084 * Redraws the viewport.
1084 */ 1085 */
1085 redraw: function() { 1086 redraw: function() {
1086 if (this.batchCount_ != 0) 1087 if (this.batchCount_ != 0)
1087 return; 1088 return;
1088 1089
1089 var dataModel = this.dataModel; 1090 var dataModel = this.dataModel;
1090 if (!dataModel) { 1091 if (!dataModel || !this.autoExpands_ && this.clientHeight == 0) {
1091 this.cachedItems_ = {}; 1092 this.cachedItems_ = {};
1092 this.firstIndex_ = 0; 1093 this.firstIndex_ = 0;
1093 this.lastIndex_ = 0; 1094 this.lastIndex_ = 0;
1094 this.remainingSpace_ = true; 1095 this.remainingSpace_ = true;
1095 this.mergeItems(0, 0, {}, {}); 1096 this.mergeItems(0, 0, {}, {});
1096 return; 1097 return;
1097 } 1098 }
1098 1099
1099 // Save the previous positions before any manipulation of elements. 1100 // Save the previous positions before any manipulation of elements.
1100 var scrollTop = this.scrollTop; 1101 var scrollTop = this.scrollTop;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 * because list items can contain controls that can be focused, and for some 1283 * because list items can contain controls that can be focused, and for some
1283 * purposes (e.g., styling), the list can still be conceptually focused at 1284 * purposes (e.g., styling), the list can still be conceptually focused at
1284 * that point even though it doesn't actually have the page focus. 1285 * that point even though it doesn't actually have the page focus.
1285 */ 1286 */
1286 cr.defineProperty(List, 'hasElementFocus', cr.PropertyKind.BOOL_ATTR); 1287 cr.defineProperty(List, 'hasElementFocus', cr.PropertyKind.BOOL_ATTR);
1287 1288
1288 return { 1289 return {
1289 List: List 1290 List: List
1290 }; 1291 };
1291 }); 1292 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/options2/content_settings_exceptions_area.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698