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

Side by Side Diff: chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js

Issue 1028513003: Decrease the lag when switching between different categories in the Cros wallpaper selector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only show items in the current viewport. Created 5 years, 9 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 /** 5 /**
6 * WallpaperManager constructor. 6 * WallpaperManager constructor.
7 * 7 *
8 * WallpaperManager objects encapsulate the functionality of the wallpaper 8 * WallpaperManager objects encapsulate the functionality of the wallpaper
9 * manager extension. 9 * manager extension.
10 * 10 *
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 }); 448 });
449 } 449 }
450 }; 450 };
451 451
452 /** 452 /**
453 * Constructs the thumbnails grid. 453 * Constructs the thumbnails grid.
454 */ 454 */
455 WallpaperManager.prototype.initThumbnailsGrid_ = function() { 455 WallpaperManager.prototype.initThumbnailsGrid_ = function() {
456 this.wallpaperGrid_ = $('wallpaper-grid'); 456 this.wallpaperGrid_ = $('wallpaper-grid');
457 wallpapers.WallpaperThumbnailsGrid.decorate(this.wallpaperGrid_); 457 wallpapers.WallpaperThumbnailsGrid.decorate(this.wallpaperGrid_);
458 this.wallpaperGrid_.autoExpands = true;
459 458
460 this.wallpaperGrid_.addEventListener('change', this.onChange_.bind(this)); 459 this.wallpaperGrid_.addEventListener('change', this.onChange_.bind(this));
461 this.wallpaperGrid_.addEventListener('dblclick', this.onClose_.bind(this)); 460 this.wallpaperGrid_.addEventListener('dblclick', this.onClose_.bind(this));
462 }; 461 };
463 462
464 /** 463 /**
465 * Handles change event dispatched by wallpaper grid. 464 * Handles change event dispatched by wallpaper grid.
466 */ 465 */
467 WallpaperManager.prototype.onChange_ = function() { 466 WallpaperManager.prototype.onChange_ = function() {
468 // splice may dispatch a change event because the position of selected 467 // splice may dispatch a change event because the position of selected
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 var wallpapersDataModel = new cr.ui.ArrayDataModel([]); 995 var wallpapersDataModel = new cr.ui.ArrayDataModel([]);
997 var selectedItem = null; 996 var selectedItem = null;
998 if (selectedListItem.custom) { 997 if (selectedListItem.custom) {
999 this.document_.body.setAttribute('custom', ''); 998 this.document_.body.setAttribute('custom', '');
1000 var errorHandler = this.onFileSystemError_.bind(this); 999 var errorHandler = this.onFileSystemError_.bind(this);
1001 var toArray = function(list) { 1000 var toArray = function(list) {
1002 return Array.prototype.slice.call(list || [], 0); 1001 return Array.prototype.slice.call(list || [], 0);
1003 }; 1002 };
1004 1003
1005 var self = this; 1004 var self = this;
1005 var numOnlineWallpaper = this.manifest_.wallpaper_list.length;
1006 var processResults = function(entries) { 1006 var processResults = function(entries) {
1007 for (var i = 0; i < entries.length; i++) { 1007 for (var i = 0; i < entries.length; i++) {
1008 var entry = entries[i]; 1008 var entry = entries[i];
1009 var wallpaperInfo = { 1009 var wallpaperInfo = {
1010 wallpaperId: numOnlineWallpaper + i,
1010 baseURL: entry.name, 1011 baseURL: entry.name,
1011 // The layout will be replaced by the actual value saved in 1012 // The layout will be replaced by the actual value saved in
1012 // local storage when requested later. Layout is not important 1013 // local storage when requested later. Layout is not important
1013 // for constructing thumbnails grid, we use CENTER_CROPPED here 1014 // for constructing thumbnails grid, we use CENTER_CROPPED here
1014 // to speed up the process of constructing. So we do not need to 1015 // to speed up the process of constructing. So we do not need to
1015 // wait for fetching correct layout. 1016 // wait for fetching correct layout.
1016 layout: 'CENTER_CROPPED', 1017 layout: 'CENTER_CROPPED',
1017 source: Constants.WallpaperSourceEnum.Custom, 1018 source: Constants.WallpaperSourceEnum.Custom,
1018 availableOffline: true 1019 availableOffline: true
1019 }; 1020 };
1020 wallpapersDataModel.push(wallpaperInfo); 1021 wallpapersDataModel.push(wallpaperInfo);
1021 } 1022 }
1022 if (loadTimeData.getBoolean('isOEMDefaultWallpaper')) { 1023 if (loadTimeData.getBoolean('isOEMDefaultWallpaper')) {
1023 var oemDefaultWallpaperElement = { 1024 var oemDefaultWallpaperElement = {
1025 wallpaperId: numOnlineWallpaper + entries.length,
1024 baseURL: 'OemDefaultWallpaper', 1026 baseURL: 'OemDefaultWallpaper',
1025 layout: 'CENTER_CROPPED', 1027 layout: 'CENTER_CROPPED',
1026 source: Constants.WallpaperSourceEnum.OEM, 1028 source: Constants.WallpaperSourceEnum.OEM,
1027 availableOffline: true 1029 availableOffline: true
1028 }; 1030 };
1029 wallpapersDataModel.push(oemDefaultWallpaperElement); 1031 wallpapersDataModel.push(oemDefaultWallpaperElement);
1030 } 1032 }
1031 for (var i = 0; i < wallpapersDataModel.length; i++) { 1033 for (var i = 0; i < wallpapersDataModel.length; i++) {
1032 if (self.currentWallpaper_ == wallpapersDataModel.item(i).baseURL) 1034 if (self.currentWallpaper_ == wallpapersDataModel.item(i).baseURL)
1033 selectedItem = wallpapersDataModel.item(i); 1035 selectedItem = wallpapersDataModel.item(i);
(...skipping 26 matching lines...) Expand all
1060 readEntries(); 1062 readEntries();
1061 } 1063 }
1062 }, errorHandler); 1064 }, errorHandler);
1063 }; 1065 };
1064 readEntries(); // Start reading dirs. 1066 readEntries(); // Start reading dirs.
1065 }; 1067 };
1066 this.wallpaperDirs_.getDirectory(Constants.WallpaperDirNameEnum.ORIGINAL, 1068 this.wallpaperDirs_.getDirectory(Constants.WallpaperDirNameEnum.ORIGINAL,
1067 success, errorHandler); 1069 success, errorHandler);
1068 } else { 1070 } else {
1069 this.document_.body.removeAttribute('custom'); 1071 this.document_.body.removeAttribute('custom');
1070 for (var key in this.manifest_.wallpaper_list) { 1072 var numOnlineWallpaper = this.manifest_.wallpaper_list.length;
1073 for (var key = 0; key < numOnlineWallpaper; key++) {
bshe 2015/03/23 21:40:31 nit: perhaps rename "key" to "i"?
xdai1 2015/03/23 22:06:12 Done.
1071 if (selectedIndex == AllCategoryIndex || 1074 if (selectedIndex == AllCategoryIndex ||
1072 this.manifest_.wallpaper_list[key].categories.indexOf( 1075 this.manifest_.wallpaper_list[key].categories.indexOf(
1073 selectedIndex - OnlineCategoriesOffset) != -1) { 1076 selectedIndex - OnlineCategoriesOffset) != -1) {
1074 var wallpaperInfo = { 1077 var wallpaperInfo = {
1078 wallpaperId: key,
1075 baseURL: this.manifest_.wallpaper_list[key].base_url, 1079 baseURL: this.manifest_.wallpaper_list[key].base_url,
1076 layout: this.manifest_.wallpaper_list[key].default_layout, 1080 layout: this.manifest_.wallpaper_list[key].default_layout,
1077 source: Constants.WallpaperSourceEnum.Online, 1081 source: Constants.WallpaperSourceEnum.Online,
1078 availableOffline: false, 1082 availableOffline: false,
1079 author: this.manifest_.wallpaper_list[key].author, 1083 author: this.manifest_.wallpaper_list[key].author,
1080 authorWebsite: this.manifest_.wallpaper_list[key].author_website, 1084 authorWebsite: this.manifest_.wallpaper_list[key].author_website,
1081 dynamicURL: this.manifest_.wallpaper_list[key].dynamic_url 1085 dynamicURL: this.manifest_.wallpaper_list[key].dynamic_url
1082 }; 1086 };
1083 var startIndex = wallpaperInfo.baseURL.lastIndexOf('/') + 1; 1087 var startIndex = wallpaperInfo.baseURL.lastIndexOf('/') + 1;
1084 var fileName = wallpaperInfo.baseURL.substring(startIndex) + 1088 var fileName = wallpaperInfo.baseURL.substring(startIndex) +
(...skipping 12 matching lines...) Expand all
1097 } 1101 }
1098 this.wallpaperGrid_.dataModel = wallpapersDataModel; 1102 this.wallpaperGrid_.dataModel = wallpapersDataModel;
1099 if (selectedItem) { 1103 if (selectedItem) {
1100 this.wallpaperGrid_.selectedItem = selectedItem; 1104 this.wallpaperGrid_.selectedItem = selectedItem;
1101 this.wallpaperGrid_.activeItem = selectedItem; 1105 this.wallpaperGrid_.activeItem = selectedItem;
1102 } 1106 }
1103 } 1107 }
1104 }; 1108 };
1105 1109
1106 })(); 1110 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698