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

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

Issue 10890038: Hook up custom wallpaper code path to new wallpaper picker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
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 /** 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.selectedCategory = null; 19 this.selectedCategory = null;
20 this.currentButter_ = null; 20 this.currentButter_ = null;
21 this.fetchManifest_(); 21 this.fetchManifest_();
22 this.initDom_(); 22 this.initDom_();
flackr 2012/08/29 18:43:45 Initialize "loadedFile_".
bshe 2012/08/30 19:22:40 Done.
23 } 23 }
24 24
25 // Anonymous 'namespace'. 25 // Anonymous 'namespace'.
26 // TODO(bshe): Get rid of anonymous namespace. 26 // TODO(bshe): Get rid of anonymous namespace.
27 (function() { 27 (function() {
28 28
29 /** 29 /**
30 * Base URL of the manifest file. 30 * Base URL of the manifest file.
31 */ 31 */
32 /** @const */ var ManifestBaseURL = 'http://commondatastorage.googleapis.' + 32 /** @const */ var ManifestBaseURL = 'http://commondatastorage.googleapis.' +
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 i18nTemplate.process(this.document_, loadTimeData); 107 i18nTemplate.process(this.document_, loadTimeData);
108 this.initCategoriesList_(); 108 this.initCategoriesList_();
109 this.initThumbnailsGrid_(); 109 this.initThumbnailsGrid_();
110 110
111 // Selects the first category in the list as default. 111 // Selects the first category in the list as default.
112 this.categoriesList_.selectionModel.selectedIndex = 0; 112 this.categoriesList_.selectionModel.selectedIndex = 0;
113 113
114 this.dialogDom_.querySelector('#file-selector').addEventListener( 114 this.dialogDom_.querySelector('#file-selector').addEventListener(
115 'change', this.onFileSelectorChanged_.bind(this)); 115 'change', this.onFileSelectorChanged_.bind(this));
116 116
117 this.dialogDom_.querySelector('#set-wallpaper-layout').addEventListener(
118 'change', this.onWallpaperLayoutChanged_.bind(this));
119
117 this.dialogDom_.ownerDocument.defaultView.addEventListener( 120 this.dialogDom_.ownerDocument.defaultView.addEventListener(
118 'resize', this.onResize_.bind(this)); 121 'resize', this.onResize_.bind(this));
119 122
120 this.onResize_(); 123 this.onResize_();
121 }; 124 };
122 125
123 /** 126 /**
124 * Constructs the thumbnails grid. 127 * Constructs the thumbnails grid.
125 */ 128 */
126 WallpaperManager.prototype.initThumbnailsGrid_ = function() { 129 WallpaperManager.prototype.initThumbnailsGrid_ = function() {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 }; 244 };
242 245
243 /** 246 /**
244 * Handles the custom wallpaper which user selected from file manager. Called 247 * Handles the custom wallpaper which user selected from file manager. Called
245 * when users select a file. 248 * when users select a file.
246 */ 249 */
247 WallpaperManager.prototype.onFileSelectorChanged_ = function() { 250 WallpaperManager.prototype.onFileSelectorChanged_ = function() {
248 var files = this.dialogDom_.querySelector('#file-selector').files; 251 var files = this.dialogDom_.querySelector('#file-selector').files;
249 if (files.length != 1) 252 if (files.length != 1)
250 console.error('More than one files are selected or no file selected'); 253 console.error('More than one files are selected or no file selected');
254 var reader = new FileReader();
255 reader.readAsArrayBuffer(files[0]);
256 var self = this;
flackr 2012/08/29 18:43:45 Add TODO to handle onerror.
bshe 2012/08/30 19:22:40 Done.
257 reader.onload = function(e) {
Ivan Korotkov 2012/08/30 14:07:36 Use addEventListener
bshe 2012/08/30 19:22:40 Looks like some other places use the same .onload/
258 self.loadedFile_ = e.target.result;
259 self.refreshWallpaper_();
260 };
251 this.generateThumbnail_(files[0]); 261 this.generateThumbnail_(files[0]);
252 }; 262 };
253 263
254 /** 264 /**
265 * Refreshes the custom wallpaper with the current selected layout.
266 */
267 WallpaperManager.prototype.refreshWallpaper_ = function() {
268 var setWallpaperLayout =
269 this.dialogDom_.querySelector('#set-wallpaper-layout');
Ivan Korotkov 2012/08/30 14:07:36 Could be just $('set-wallpaper-layout');
bshe 2012/08/30 19:22:40 I followed file manager js coding style. Not sure
dgozman 2012/08/31 09:20:08 Well, we just don't like it. It can be also confus
270 var layout =
271 setWallpaperLayout.options[setWallpaperLayout.selectedIndex].value;
272 if (this.loadedFile_) {
flackr 2012/08/29 18:43:45 I think you should guarantee that loadedFile_ is s
bshe 2012/08/30 19:22:40 Done.
273 chrome.wallpaperPrivate.setCustomWallpaper(this.loadedFile_,
274 layout);
275 }
276 };
277
278 /**
279 * Handles the layout setting change of custom wallpaper.
280 */
281 WallpaperManager.prototype.onWallpaperLayoutChanged_ = function() {
282 this.refreshWallpaper_();
flackr 2012/08/29 18:43:45 i.e. if (this.loadedFile_) this.refreshWal
bshe 2012/08/30 19:22:40 Done.
283 };
284
285 /**
255 * Generates a thumbnail of user selected image file. 286 * Generates a thumbnail of user selected image file.
256 * @param {Object} file The file user selected from file manager. 287 * @param {Object} file The file user selected from file manager.
257 */ 288 */
258 WallpaperManager.prototype.generateThumbnail_ = function(file) { 289 WallpaperManager.prototype.generateThumbnail_ = function(file) {
259 var img = this.dialogDom_.querySelector('#preview'); 290 var img = this.dialogDom_.querySelector('#preview');
260 img.file = file; 291 img.file = file;
261 var reader = new FileReader(); 292 var reader = new FileReader();
262 reader.onload = function(e) { 293 reader.onload = function(e) {
263 img.src = e.target.result; 294 img.src = e.target.result;
264 }; 295 };
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 authorWebsite: this.manifest_.wallpaper_list[key].author_website 337 authorWebsite: this.manifest_.wallpaper_list[key].author_website
307 }; 338 };
308 wallpapersDataModel.push(wallpaperInfo); 339 wallpapersDataModel.push(wallpaperInfo);
309 } 340 }
310 } 341 }
311 this.wallpaperGrid_.dataModel = wallpapersDataModel; 342 this.wallpaperGrid_.dataModel = wallpapersDataModel;
312 } 343 }
313 }; 344 };
314 345
315 })(); 346 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698