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

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

Issue 948243006: Unchecking the "Surprise Me" checkbox should go back previous wallpaper before "Surprise Me" was tu… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Please review from this patch. 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
« no previous file with comments | « no previous file | 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) 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 $('wallpaper-grid').classList.add('image-picker-offline'); 188 $('wallpaper-grid').classList.add('image-picker-offline');
189 }); 189 });
190 }; 190 };
191 191
192 /** 192 /**
193 * Toggle surprise me feature of wallpaper picker. It fires an storage 193 * Toggle surprise me feature of wallpaper picker. It fires an storage
194 * onChanged event. Event handler for that event is in event_page.js. 194 * onChanged event. Event handler for that event is in event_page.js.
195 * @private 195 * @private
196 */ 196 */
197 WallpaperManager.prototype.toggleSurpriseMe_ = function() { 197 WallpaperManager.prototype.toggleSurpriseMe_ = function() {
198 var self = this;
198 var checkbox = $('surprise-me').querySelector('#checkbox'); 199 var checkbox = $('surprise-me').querySelector('#checkbox');
199 var shouldEnable = !checkbox.classList.contains('checked'); 200 var shouldEnable = !checkbox.classList.contains('checked');
200 WallpaperUtil.saveToStorage(Constants.AccessSurpriseMeEnabledKey, 201 WallpaperUtil.saveToStorage(Constants.AccessSurpriseMeEnabledKey,
201 shouldEnable, true, function() { 202 shouldEnable, true, function() {
202 if (chrome.runtime.lastError == null) { 203 if (chrome.runtime.lastError == null) {
203 if (shouldEnable) { 204 if (shouldEnable) {
204 checkbox.classList.add('checked'); 205 checkbox.classList.add('checked');
205 } else { 206 } else {
207 // Unchecking the "Surprise me" checkbox falls back to the previous
208 // wallpaper before "Surprise me" was turned on.
209 self.setSelectedWallpaper_(self.wallpaperGrid_.activeItem_);
210 self.onWallpaperChanged_(self.wallpaperGrid_.activeItem_,
211 self.currentWallpaper_);
206 checkbox.classList.remove('checked'); 212 checkbox.classList.remove('checked');
207 } 213 }
208 $('categories-list').disabled = shouldEnable; 214 $('categories-list').disabled = shouldEnable;
209 $('wallpaper-grid').disabled = shouldEnable; 215 $('wallpaper-grid').disabled = shouldEnable;
210 } else { 216 } else {
211 // TODO(bshe): show error message to user. 217 // TODO(bshe): show error message to user.
212 console.error('Failed to save surprise me option to chrome storage.'); 218 console.error('Failed to save surprise me option to chrome storage.');
213 } 219 }
214 }); 220 });
215 }; 221 };
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 var categoriesList = this.categoriesList_; 981 var categoriesList = this.categoriesList_;
976 var selectedIndex = categoriesList.selectionModel.selectedIndex; 982 var selectedIndex = categoriesList.selectionModel.selectedIndex;
977 if (selectedIndex == -1) 983 if (selectedIndex == -1)
978 return; 984 return;
979 var selectedListItem = categoriesList.getListItemByIndex(selectedIndex); 985 var selectedListItem = categoriesList.getListItemByIndex(selectedIndex);
980 var bar = $('bar'); 986 var bar = $('bar');
981 bar.style.left = selectedListItem.offsetLeft + 'px'; 987 bar.style.left = selectedListItem.offsetLeft + 'px';
982 bar.style.width = selectedListItem.offsetWidth + 'px'; 988 bar.style.width = selectedListItem.offsetWidth + 'px';
983 989
984 var wallpapersDataModel = new cr.ui.ArrayDataModel([]); 990 var wallpapersDataModel = new cr.ui.ArrayDataModel([]);
985 var selectedItem; 991 var selectedItem = null;
986 if (selectedListItem.custom) { 992 if (selectedListItem.custom) {
987 this.document_.body.setAttribute('custom', ''); 993 this.document_.body.setAttribute('custom', '');
988 var errorHandler = this.onFileSystemError_.bind(this); 994 var errorHandler = this.onFileSystemError_.bind(this);
989 var toArray = function(list) { 995 var toArray = function(list) {
990 return Array.prototype.slice.call(list || [], 0); 996 return Array.prototype.slice.call(list || [], 0);
991 }; 997 };
992 998
993 var self = this; 999 var self = this;
994 var processResults = function(entries) { 1000 var processResults = function(entries) {
995 for (var i = 0; i < entries.length; i++) { 1001 for (var i = 0; i < entries.length; i++) {
(...skipping 25 matching lines...) Expand all
1021 selectedItem = wallpapersDataModel.item(i); 1027 selectedItem = wallpapersDataModel.item(i);
1022 } 1028 }
1023 var lastElement = { 1029 var lastElement = {
1024 baseURL: '', 1030 baseURL: '',
1025 layout: '', 1031 layout: '',
1026 source: Constants.WallpaperSourceEnum.AddNew, 1032 source: Constants.WallpaperSourceEnum.AddNew,
1027 availableOffline: true 1033 availableOffline: true
1028 }; 1034 };
1029 wallpapersDataModel.push(lastElement); 1035 wallpapersDataModel.push(lastElement);
1030 self.wallpaperGrid_.dataModel = wallpapersDataModel; 1036 self.wallpaperGrid_.dataModel = wallpapersDataModel;
1031 self.wallpaperGrid_.selectedItem = selectedItem; 1037 if (selectedItem) {
1032 self.wallpaperGrid_.activeItem = selectedItem; 1038 self.wallpaperGrid_.selectedItem = selectedItem;
1039 self.wallpaperGrid_.activeItem = selectedItem;
1040 }
1033 }; 1041 };
1034 1042
1035 var success = function(dirEntry) { 1043 var success = function(dirEntry) {
1036 var dirReader = dirEntry.createReader(); 1044 var dirReader = dirEntry.createReader();
1037 var entries = []; 1045 var entries = [];
1038 // All of a directory's entries are not guaranteed to return in a single 1046 // All of a directory's entries are not guaranteed to return in a single
1039 // call. 1047 // call.
1040 var readEntries = function() { 1048 var readEntries = function() {
1041 dirReader.readEntries(function(results) { 1049 dirReader.readEntries(function(results) {
1042 if (!results.length) { 1050 if (!results.length) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 } 1083 }
1076 wallpapersDataModel.push(wallpaperInfo); 1084 wallpapersDataModel.push(wallpaperInfo);
1077 var url = this.manifest_.wallpaper_list[key].base_url + 1085 var url = this.manifest_.wallpaper_list[key].base_url +
1078 Constants.HighResolutionSuffix; 1086 Constants.HighResolutionSuffix;
1079 if (url == this.currentWallpaper_) { 1087 if (url == this.currentWallpaper_) {
1080 selectedItem = wallpaperInfo; 1088 selectedItem = wallpaperInfo;
1081 } 1089 }
1082 } 1090 }
1083 } 1091 }
1084 this.wallpaperGrid_.dataModel = wallpapersDataModel; 1092 this.wallpaperGrid_.dataModel = wallpapersDataModel;
1085 this.wallpaperGrid_.selectedItem = selectedItem; 1093 if (selectedItem) {
1086 this.wallpaperGrid_.activeItem = selectedItem; 1094 this.wallpaperGrid_.selectedItem = selectedItem;
1095 this.wallpaperGrid_.activeItem = selectedItem;
1096 }
1087 } 1097 }
1088 }; 1098 };
1089 1099
1090 })(); 1100 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698