OLD | NEW |
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 * |
11 * @constructor | 11 * @constructor |
12 * @param {HTMLElement} dialogDom The DOM node containing the prototypical | 12 * @param {HTMLElement} dialogDom The DOM node containing the prototypical |
13 * extension UI. | 13 * extension UI. |
14 */ | 14 */ |
15 | 15 |
16 function WallpaperManager(dialogDom) { | 16 function WallpaperManager(dialogDom) { |
17 this.dialogDom_ = dialogDom; | 17 this.dialogDom_ = dialogDom; |
18 this.document_ = dialogDom.ownerDocument; | 18 this.document_ = dialogDom.ownerDocument; |
19 this.enableOnlineWallpaper_ = loadTimeData.valueExists('manifestBaseURL'); | 19 this.enableOnlineWallpaper_ = loadTimeData.valueExists('manifestBaseURL'); |
20 this.selectedCategory = null; | |
21 this.selectedItem_ = null; | 20 this.selectedItem_ = null; |
22 this.progressManager_ = new ProgressManager(); | 21 this.progressManager_ = new ProgressManager(); |
23 this.customWallpaperData_ = null; | 22 this.customWallpaperData_ = null; |
24 this.currentWallpaper_ = null; | 23 this.currentWallpaper_ = null; |
25 this.wallpaperRequest_ = null; | 24 this.wallpaperRequest_ = null; |
26 this.wallpaperDirs_ = WallpaperDirectories.getInstance(); | 25 this.wallpaperDirs_ = WallpaperDirectories.getInstance(); |
27 this.preManifestDomInit_(); | 26 this.preManifestDomInit_(); |
28 this.fetchManifest_(); | 27 this.fetchManifest_(); |
29 } | 28 } |
30 | 29 |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 }); | 447 }); |
449 } | 448 } |
450 }; | 449 }; |
451 | 450 |
452 /** | 451 /** |
453 * Constructs the thumbnails grid. | 452 * Constructs the thumbnails grid. |
454 */ | 453 */ |
455 WallpaperManager.prototype.initThumbnailsGrid_ = function() { | 454 WallpaperManager.prototype.initThumbnailsGrid_ = function() { |
456 this.wallpaperGrid_ = $('wallpaper-grid'); | 455 this.wallpaperGrid_ = $('wallpaper-grid'); |
457 wallpapers.WallpaperThumbnailsGrid.decorate(this.wallpaperGrid_); | 456 wallpapers.WallpaperThumbnailsGrid.decorate(this.wallpaperGrid_); |
458 this.wallpaperGrid_.autoExpands = true; | |
459 | 457 |
460 this.wallpaperGrid_.addEventListener('change', this.onChange_.bind(this)); | 458 this.wallpaperGrid_.addEventListener('change', this.onChange_.bind(this)); |
461 this.wallpaperGrid_.addEventListener('dblclick', this.onClose_.bind(this)); | 459 this.wallpaperGrid_.addEventListener('dblclick', this.onClose_.bind(this)); |
462 }; | 460 }; |
463 | 461 |
464 /** | 462 /** |
465 * Handles change event dispatched by wallpaper grid. | 463 * Handles change event dispatched by wallpaper grid. |
466 */ | 464 */ |
467 WallpaperManager.prototype.onChange_ = function() { | 465 WallpaperManager.prototype.onChange_ = function() { |
468 // splice may dispatch a change event because the position of selected | 466 // splice may dispatch a change event because the position of selected |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 var wallpapersDataModel = new cr.ui.ArrayDataModel([]); | 994 var wallpapersDataModel = new cr.ui.ArrayDataModel([]); |
997 var selectedItem = null; | 995 var selectedItem = null; |
998 if (selectedListItem.custom) { | 996 if (selectedListItem.custom) { |
999 this.document_.body.setAttribute('custom', ''); | 997 this.document_.body.setAttribute('custom', ''); |
1000 var errorHandler = this.onFileSystemError_.bind(this); | 998 var errorHandler = this.onFileSystemError_.bind(this); |
1001 var toArray = function(list) { | 999 var toArray = function(list) { |
1002 return Array.prototype.slice.call(list || [], 0); | 1000 return Array.prototype.slice.call(list || [], 0); |
1003 }; | 1001 }; |
1004 | 1002 |
1005 var self = this; | 1003 var self = this; |
| 1004 var numOnlineWallpaper = this.manifest_ ? |
| 1005 this.manifest_.wallpaper_list.length : 0; |
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 Loading... |
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_ ? |
| 1073 this.manifest_.wallpaper_list.length : 0; |
| 1074 for (var i = 0; i < numOnlineWallpaper; i++) { |
1071 if (selectedIndex == AllCategoryIndex || | 1075 if (selectedIndex == AllCategoryIndex || |
1072 this.manifest_.wallpaper_list[key].categories.indexOf( | 1076 this.manifest_.wallpaper_list[i].categories.indexOf( |
1073 selectedIndex - OnlineCategoriesOffset) != -1) { | 1077 selectedIndex - OnlineCategoriesOffset) != -1) { |
1074 var wallpaperInfo = { | 1078 var wallpaperInfo = { |
1075 baseURL: this.manifest_.wallpaper_list[key].base_url, | 1079 wallpaperId: i, |
1076 layout: this.manifest_.wallpaper_list[key].default_layout, | 1080 baseURL: this.manifest_.wallpaper_list[i].base_url, |
| 1081 layout: this.manifest_.wallpaper_list[i].default_layout, |
1077 source: Constants.WallpaperSourceEnum.Online, | 1082 source: Constants.WallpaperSourceEnum.Online, |
1078 availableOffline: false, | 1083 availableOffline: false, |
1079 author: this.manifest_.wallpaper_list[key].author, | 1084 author: this.manifest_.wallpaper_list[i].author, |
1080 authorWebsite: this.manifest_.wallpaper_list[key].author_website, | 1085 authorWebsite: this.manifest_.wallpaper_list[i].author_website, |
1081 dynamicURL: this.manifest_.wallpaper_list[key].dynamic_url | 1086 dynamicURL: this.manifest_.wallpaper_list[i].dynamic_url |
1082 }; | 1087 }; |
1083 var startIndex = wallpaperInfo.baseURL.lastIndexOf('/') + 1; | 1088 var startIndex = wallpaperInfo.baseURL.lastIndexOf('/') + 1; |
1084 var fileName = wallpaperInfo.baseURL.substring(startIndex) + | 1089 var fileName = wallpaperInfo.baseURL.substring(startIndex) + |
1085 Constants.HighResolutionSuffix; | 1090 Constants.HighResolutionSuffix; |
1086 if (this.downloadedListMap_ && | 1091 if (this.downloadedListMap_ && |
1087 this.downloadedListMap_.hasOwnProperty(encodeURI(fileName))) { | 1092 this.downloadedListMap_.hasOwnProperty(encodeURI(fileName))) { |
1088 wallpaperInfo.availableOffline = true; | 1093 wallpaperInfo.availableOffline = true; |
1089 } | 1094 } |
1090 wallpapersDataModel.push(wallpaperInfo); | 1095 wallpapersDataModel.push(wallpaperInfo); |
1091 var url = this.manifest_.wallpaper_list[key].base_url + | 1096 var url = this.manifest_.wallpaper_list[i].base_url + |
1092 Constants.HighResolutionSuffix; | 1097 Constants.HighResolutionSuffix; |
1093 if (url == this.currentWallpaper_) { | 1098 if (url == this.currentWallpaper_) { |
1094 selectedItem = wallpaperInfo; | 1099 selectedItem = wallpaperInfo; |
1095 } | 1100 } |
1096 } | 1101 } |
1097 } | 1102 } |
1098 this.wallpaperGrid_.dataModel = wallpapersDataModel; | 1103 this.wallpaperGrid_.dataModel = wallpapersDataModel; |
1099 if (selectedItem) { | 1104 if (selectedItem) { |
1100 this.wallpaperGrid_.selectedItem = selectedItem; | 1105 this.wallpaperGrid_.selectedItem = selectedItem; |
1101 this.wallpaperGrid_.activeItem = selectedItem; | 1106 this.wallpaperGrid_.activeItem = selectedItem; |
1102 } | 1107 } |
1103 } | 1108 } |
1104 }; | 1109 }; |
1105 | 1110 |
1106 })(); | 1111 })(); |
OLD | NEW |