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; |
20 this.selectedItem_ = null; | 21 this.selectedItem_ = null; |
21 this.progressManager_ = new ProgressManager(); | 22 this.progressManager_ = new ProgressManager(); |
22 this.customWallpaperData_ = null; | 23 this.customWallpaperData_ = null; |
23 this.currentWallpaper_ = null; | 24 this.currentWallpaper_ = null; |
24 this.wallpaperRequest_ = null; | 25 this.wallpaperRequest_ = null; |
25 this.wallpaperDirs_ = WallpaperDirectories.getInstance(); | 26 this.wallpaperDirs_ = WallpaperDirectories.getInstance(); |
26 this.preManifestDomInit_(); | 27 this.preManifestDomInit_(); |
27 this.fetchManifest_(); | 28 this.fetchManifest_(); |
28 } | 29 } |
29 | 30 |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 }); | 448 }); |
448 } | 449 } |
449 }; | 450 }; |
450 | 451 |
451 /** | 452 /** |
452 * Constructs the thumbnails grid. | 453 * Constructs the thumbnails grid. |
453 */ | 454 */ |
454 WallpaperManager.prototype.initThumbnailsGrid_ = function() { | 455 WallpaperManager.prototype.initThumbnailsGrid_ = function() { |
455 this.wallpaperGrid_ = $('wallpaper-grid'); | 456 this.wallpaperGrid_ = $('wallpaper-grid'); |
456 wallpapers.WallpaperThumbnailsGrid.decorate(this.wallpaperGrid_); | 457 wallpapers.WallpaperThumbnailsGrid.decorate(this.wallpaperGrid_); |
| 458 this.wallpaperGrid_.autoExpands = true; |
457 | 459 |
458 this.wallpaperGrid_.addEventListener('change', this.onChange_.bind(this)); | 460 this.wallpaperGrid_.addEventListener('change', this.onChange_.bind(this)); |
459 this.wallpaperGrid_.addEventListener('dblclick', this.onClose_.bind(this)); | 461 this.wallpaperGrid_.addEventListener('dblclick', this.onClose_.bind(this)); |
460 }; | 462 }; |
461 | 463 |
462 /** | 464 /** |
463 * Handles change event dispatched by wallpaper grid. | 465 * Handles change event dispatched by wallpaper grid. |
464 */ | 466 */ |
465 WallpaperManager.prototype.onChange_ = function() { | 467 WallpaperManager.prototype.onChange_ = function() { |
466 // splice may dispatch a change event because the position of selected | 468 // splice may dispatch a change event because the position of selected |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 var wallpapersDataModel = new cr.ui.ArrayDataModel([]); | 996 var wallpapersDataModel = new cr.ui.ArrayDataModel([]); |
995 var selectedItem = null; | 997 var selectedItem = null; |
996 if (selectedListItem.custom) { | 998 if (selectedListItem.custom) { |
997 this.document_.body.setAttribute('custom', ''); | 999 this.document_.body.setAttribute('custom', ''); |
998 var errorHandler = this.onFileSystemError_.bind(this); | 1000 var errorHandler = this.onFileSystemError_.bind(this); |
999 var toArray = function(list) { | 1001 var toArray = function(list) { |
1000 return Array.prototype.slice.call(list || [], 0); | 1002 return Array.prototype.slice.call(list || [], 0); |
1001 }; | 1003 }; |
1002 | 1004 |
1003 var self = this; | 1005 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, | |
1011 baseURL: entry.name, | 1010 baseURL: entry.name, |
1012 // The layout will be replaced by the actual value saved in | 1011 // The layout will be replaced by the actual value saved in |
1013 // local storage when requested later. Layout is not important | 1012 // local storage when requested later. Layout is not important |
1014 // for constructing thumbnails grid, we use CENTER_CROPPED here | 1013 // for constructing thumbnails grid, we use CENTER_CROPPED here |
1015 // to speed up the process of constructing. So we do not need to | 1014 // to speed up the process of constructing. So we do not need to |
1016 // wait for fetching correct layout. | 1015 // wait for fetching correct layout. |
1017 layout: 'CENTER_CROPPED', | 1016 layout: 'CENTER_CROPPED', |
1018 source: Constants.WallpaperSourceEnum.Custom, | 1017 source: Constants.WallpaperSourceEnum.Custom, |
1019 availableOffline: true | 1018 availableOffline: true |
1020 }; | 1019 }; |
1021 wallpapersDataModel.push(wallpaperInfo); | 1020 wallpapersDataModel.push(wallpaperInfo); |
1022 } | 1021 } |
1023 if (loadTimeData.getBoolean('isOEMDefaultWallpaper')) { | 1022 if (loadTimeData.getBoolean('isOEMDefaultWallpaper')) { |
1024 var oemDefaultWallpaperElement = { | 1023 var oemDefaultWallpaperElement = { |
1025 wallpaperId: numOnlineWallpaper + entries.length, | |
1026 baseURL: 'OemDefaultWallpaper', | 1024 baseURL: 'OemDefaultWallpaper', |
1027 layout: 'CENTER_CROPPED', | 1025 layout: 'CENTER_CROPPED', |
1028 source: Constants.WallpaperSourceEnum.OEM, | 1026 source: Constants.WallpaperSourceEnum.OEM, |
1029 availableOffline: true | 1027 availableOffline: true |
1030 }; | 1028 }; |
1031 wallpapersDataModel.push(oemDefaultWallpaperElement); | 1029 wallpapersDataModel.push(oemDefaultWallpaperElement); |
1032 } | 1030 } |
1033 for (var i = 0; i < wallpapersDataModel.length; i++) { | 1031 for (var i = 0; i < wallpapersDataModel.length; i++) { |
1034 if (self.currentWallpaper_ == wallpapersDataModel.item(i).baseURL) | 1032 if (self.currentWallpaper_ == wallpapersDataModel.item(i).baseURL) |
1035 selectedItem = wallpapersDataModel.item(i); | 1033 selectedItem = wallpapersDataModel.item(i); |
(...skipping 26 matching lines...) Expand all Loading... |
1062 readEntries(); | 1060 readEntries(); |
1063 } | 1061 } |
1064 }, errorHandler); | 1062 }, errorHandler); |
1065 }; | 1063 }; |
1066 readEntries(); // Start reading dirs. | 1064 readEntries(); // Start reading dirs. |
1067 }; | 1065 }; |
1068 this.wallpaperDirs_.getDirectory(Constants.WallpaperDirNameEnum.ORIGINAL, | 1066 this.wallpaperDirs_.getDirectory(Constants.WallpaperDirNameEnum.ORIGINAL, |
1069 success, errorHandler); | 1067 success, errorHandler); |
1070 } else { | 1068 } else { |
1071 this.document_.body.removeAttribute('custom'); | 1069 this.document_.body.removeAttribute('custom'); |
1072 var numOnlineWallpaper = this.manifest_ ? | 1070 for (var key in this.manifest_.wallpaper_list) { |
1073 this.manifest_.wallpaper_list.length : 0; | |
1074 for (var i = 0; i < numOnlineWallpaper; i++) { | |
1075 if (selectedIndex == AllCategoryIndex || | 1071 if (selectedIndex == AllCategoryIndex || |
1076 this.manifest_.wallpaper_list[i].categories.indexOf( | 1072 this.manifest_.wallpaper_list[key].categories.indexOf( |
1077 selectedIndex - OnlineCategoriesOffset) != -1) { | 1073 selectedIndex - OnlineCategoriesOffset) != -1) { |
1078 var wallpaperInfo = { | 1074 var wallpaperInfo = { |
1079 wallpaperId: i, | 1075 baseURL: this.manifest_.wallpaper_list[key].base_url, |
1080 baseURL: this.manifest_.wallpaper_list[i].base_url, | 1076 layout: this.manifest_.wallpaper_list[key].default_layout, |
1081 layout: this.manifest_.wallpaper_list[i].default_layout, | |
1082 source: Constants.WallpaperSourceEnum.Online, | 1077 source: Constants.WallpaperSourceEnum.Online, |
1083 availableOffline: false, | 1078 availableOffline: false, |
1084 author: this.manifest_.wallpaper_list[i].author, | 1079 author: this.manifest_.wallpaper_list[key].author, |
1085 authorWebsite: this.manifest_.wallpaper_list[i].author_website, | 1080 authorWebsite: this.manifest_.wallpaper_list[key].author_website, |
1086 dynamicURL: this.manifest_.wallpaper_list[i].dynamic_url | 1081 dynamicURL: this.manifest_.wallpaper_list[key].dynamic_url |
1087 }; | 1082 }; |
1088 var startIndex = wallpaperInfo.baseURL.lastIndexOf('/') + 1; | 1083 var startIndex = wallpaperInfo.baseURL.lastIndexOf('/') + 1; |
1089 var fileName = wallpaperInfo.baseURL.substring(startIndex) + | 1084 var fileName = wallpaperInfo.baseURL.substring(startIndex) + |
1090 Constants.HighResolutionSuffix; | 1085 Constants.HighResolutionSuffix; |
1091 if (this.downloadedListMap_ && | 1086 if (this.downloadedListMap_ && |
1092 this.downloadedListMap_.hasOwnProperty(encodeURI(fileName))) { | 1087 this.downloadedListMap_.hasOwnProperty(encodeURI(fileName))) { |
1093 wallpaperInfo.availableOffline = true; | 1088 wallpaperInfo.availableOffline = true; |
1094 } | 1089 } |
1095 wallpapersDataModel.push(wallpaperInfo); | 1090 wallpapersDataModel.push(wallpaperInfo); |
1096 var url = this.manifest_.wallpaper_list[i].base_url + | 1091 var url = this.manifest_.wallpaper_list[key].base_url + |
1097 Constants.HighResolutionSuffix; | 1092 Constants.HighResolutionSuffix; |
1098 if (url == this.currentWallpaper_) { | 1093 if (url == this.currentWallpaper_) { |
1099 selectedItem = wallpaperInfo; | 1094 selectedItem = wallpaperInfo; |
1100 } | 1095 } |
1101 } | 1096 } |
1102 } | 1097 } |
1103 this.wallpaperGrid_.dataModel = wallpapersDataModel; | 1098 this.wallpaperGrid_.dataModel = wallpapersDataModel; |
1104 if (selectedItem) { | 1099 if (selectedItem) { |
1105 this.wallpaperGrid_.selectedItem = selectedItem; | 1100 this.wallpaperGrid_.selectedItem = selectedItem; |
1106 this.wallpaperGrid_.activeItem = selectedItem; | 1101 this.wallpaperGrid_.activeItem = selectedItem; |
1107 } | 1102 } |
1108 } | 1103 } |
1109 }; | 1104 }; |
1110 | 1105 |
1111 })(); | 1106 })(); |
OLD | NEW |