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

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

Issue 12042095: Move wallpaper progress bar on top of thumbnails (completely remove butter bar) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 10 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) 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.storage_ = chrome.storage.local; 18 this.storage_ = chrome.storage.local;
19 this.document_ = dialogDom.ownerDocument; 19 this.document_ = dialogDom.ownerDocument;
20 this.selectedCategory = null; 20 this.selectedCategory = null;
21 this.butterBar_ = new ButterBar(this.dialogDom_); 21 this.progressManager_ = new ProgressManager();
22 this.customWallpaperData_ = null; 22 this.customWallpaperData_ = null;
23 this.currentWallpaper_ = null; 23 this.currentWallpaper_ = null;
24 this.wallpaperRequest_ = null; 24 this.wallpaperRequest_ = null;
25 this.checkmark_ = cr.doc.createElement('div');
26 this.checkmark_.classList.add('check');
25 this.fetchManifest_(); 27 this.fetchManifest_();
26 } 28 }
27 29
28 // Anonymous 'namespace'. 30 // Anonymous 'namespace'.
29 // TODO(bshe): Get rid of anonymous namespace. 31 // TODO(bshe): Get rid of anonymous namespace.
30 (function() { 32 (function() {
31 33
32 /** 34 /**
33 * Base URL of the manifest file. 35 * Base URL of the manifest file.
34 */ 36 */
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 this.storage_.set(items, function() {}); 151 this.storage_.set(items, function() {});
150 this.initDom_(); 152 this.initDom_();
151 }; 153 };
152 154
153 // Sets manifest to previously saved object if any and shows connection error. 155 // Sets manifest to previously saved object if any and shows connection error.
154 // Called after manifest failed to load. 156 // Called after manifest failed to load.
155 WallpaperManager.prototype.onLoadManifestFailed_ = function() { 157 WallpaperManager.prototype.onLoadManifestFailed_ = function() {
156 var self = this; 158 var self = this;
157 this.storage_.get(AccessManifestKey, function(items) { 159 this.storage_.get(AccessManifestKey, function(items) {
158 self.manifest_ = items[AccessManifestKey] ? items[AccessManifestKey] : {}; 160 self.manifest_ = items[AccessManifestKey] ? items[AccessManifestKey] : {};
159 self.butterBar_.showError_(str('connectionFailed'), 161 // TODO(bshe): Add error message back once we decide how to show error
160 {help_url: LEARN_MORE_URL}); 162 // message in the new UI. http://crbug.com/162563
161 self.initDom_(); 163 self.initDom_();
162 $('wallpaper-grid').classList.add('image-picker-offline'); 164 $('wallpaper-grid').classList.add('image-picker-offline');
163 }); 165 });
164 }; 166 };
165 167
166 /** 168 /**
167 * One-time initialization of various DOM nodes. 169 * One-time initialization of various DOM nodes.
168 */ 170 */
169 WallpaperManager.prototype.initDom_ = function() { 171 WallpaperManager.prototype.initDom_ = function() {
170 i18nTemplate.process(this.document_, loadTimeData); 172 i18nTemplate.process(this.document_, loadTimeData);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 }; 278 };
277 279
278 /** 280 /**
279 * Sets wallpaper to the corresponding wallpaper of selected thumbnail. 281 * Sets wallpaper to the corresponding wallpaper of selected thumbnail.
280 */ 282 */
281 WallpaperManager.prototype.onThumbnailClicked_ = function() { 283 WallpaperManager.prototype.onThumbnailClicked_ = function() {
282 var selectedItem = this.wallpaperGrid_.selectedItem; 284 var selectedItem = this.wallpaperGrid_.selectedItem;
283 if (selectedItem && selectedItem.dynamicURL && 285 if (selectedItem && selectedItem.dynamicURL &&
284 !this.wallpaperGrid_.inProgramSelection) { 286 !this.wallpaperGrid_.inProgramSelection) {
285 var wallpaperURL = selectedItem.baseURL + HighResolutionSuffix; 287 var wallpaperURL = selectedItem.baseURL + HighResolutionSuffix;
288 var selectedGridItem = this.wallpaperGrid_.getListItem(selectedItem);
286 var self = this; 289 var self = this;
287 290
288 chrome.wallpaperPrivate.setWallpaperIfExist(wallpaperURL, 291 chrome.wallpaperPrivate.setWallpaperIfExist(wallpaperURL,
289 selectedItem.layout, 292 selectedItem.layout,
290 function() { 293 function() {
291 if (chrome.runtime.lastError == undefined) { 294 if (chrome.runtime.lastError == undefined) {
292 self.currentWallpaper_ = wallpaperURL; 295 self.currentWallpaper_ = wallpaperURL;
293 self.setActiveThumb(selectedItem); 296 self.setActiveThumb(selectedGridItem);
294 return; 297 return;
295 } 298 }
296 299
297 // Falls back to request wallpaper from server. 300 // Falls back to request wallpaper from server.
298 if (self.wallpaperRequest_) 301 if (self.wallpaperRequest_)
299 self.wallpaperRequest_.abort(); 302 self.wallpaperRequest_.abort();
300 303
301 self.wallpaperRequest_ = new XMLHttpRequest(); 304 self.wallpaperRequest_ = new XMLHttpRequest();
302 self.wallpaperRequest_.open('GET', wallpaperURL, true); 305 self.wallpaperRequest_.open('GET', wallpaperURL, true);
303 self.wallpaperRequest_.responseType = 'arraybuffer'; 306 self.wallpaperRequest_.responseType = 'arraybuffer';
307 self.progressManager_.reset(self.wallpaperRequest_, selectedGridItem);
304 self.wallpaperRequest_.send(null); 308 self.wallpaperRequest_.send(null);
305 self.butterBar_.setRequest(self.wallpaperRequest_);
306 self.wallpaperRequest_.addEventListener('load', function(e) { 309 self.wallpaperRequest_.addEventListener('load', function(e) {
307 if (self.wallpaperRequest_.status === 200) { 310 if (self.wallpaperRequest_.status === 200) {
308 var image = self.wallpaperRequest_.response; 311 var image = self.wallpaperRequest_.response;
309 chrome.wallpaperPrivate.setWallpaper(image, 312 chrome.wallpaperPrivate.setWallpaper(
310 selectedItem.layout, 313 image,
311 wallpaperURL, 314 selectedItem.layout,
312 self.onFinished_.bind(self)); 315 wallpaperURL,
316 self.onFinished_.bind(self, selectedGridItem));
313 self.currentWallpaper_ = wallpaperURL; 317 self.currentWallpaper_ = wallpaperURL;
314 self.setActiveThumb(selectedItem);
315 } else { 318 } else {
316 self.butterBar_.showError_(str('downloadFailed'), 319 // TODO(bshe): Add error message back once we decide how to show
317 {help_url: LEARN_MORE_URL}); 320 // error message in the new UI. http://crbug.com/162563
318 } 321 }
319 self.wallpaperRequest_ = null; 322 self.wallpaperRequest_ = null;
320 }); 323 });
321 }); 324 });
322 } 325 }
323 this.setWallpaperAttribution_(selectedItem); 326 this.setWallpaperAttribution_(selectedItem);
324 }; 327 };
325 328
326 /** 329 /**
327 * Set attributions of wallpaper with given URL. If URL is not valid, clear 330 * Set attributions of wallpaper with given URL. If URL is not valid, clear
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 /** 421 /**
419 * Handles the custom wallpaper which user selected from file manager. Called 422 * Handles the custom wallpaper which user selected from file manager. Called
420 * when users select a file. 423 * when users select a file.
421 */ 424 */
422 WallpaperManager.prototype.onFileSelectorChanged_ = function() { 425 WallpaperManager.prototype.onFileSelectorChanged_ = function() {
423 var files = $('file-selector').files; 426 var files = $('file-selector').files;
424 if (files.length != 1) 427 if (files.length != 1)
425 console.error('More than one files are selected or no file selected'); 428 console.error('More than one files are selected or no file selected');
426 var file = files[0]; 429 var file = files[0];
427 if (!file.type.match('image/jpeg')) { 430 if (!file.type.match('image/jpeg')) {
428 this.butterBar_.showError_(str('invalidWallpaper'), 431 // TODO(bshe): Add error message back once we decide how to show error
429 {help_url: LEARN_MORE_URL}); 432 // message in the new UI. http://crbug.com/162563
430 return; 433 return;
431 } 434 }
432 var reader = new FileReader(); 435 var reader = new FileReader();
433 reader.readAsArrayBuffer(files[0]); 436 reader.readAsArrayBuffer(files[0]);
434 var self = this; 437 var self = this;
435 reader.addEventListener('error', function(e) { 438 reader.addEventListener('error', function(e) {
436 this.butterBar_.showError_(str('accessFileFailure'), 439 // TODO(bshe): Add error message back once we decide how to show error
437 {help_url: LEARN_MORE_URL}); 440 // message in the new UI. http://crbug.com/162563
438 }); 441 });
439 reader.addEventListener('load', function(e) { 442 reader.addEventListener('load', function(e) {
440 self.customWallpaperData_ = e.target.result; 443 self.customWallpaperData_ = e.target.result;
441 self.refreshWallpaper_(self.customWallpaperData_); 444 self.refreshWallpaper_(self.customWallpaperData_);
442 }); 445 });
443 this.generateThumbnail_(files[0]); 446 this.generateThumbnail_(files[0]);
444 }; 447 };
445 448
446 /** 449 /**
447 * Refreshes the custom wallpaper with the current selected layout. 450 * Refreshes the custom wallpaper with the current selected layout.
448 * @param {ArrayBuffer} customWallpaper The raw wallpaper file data. 451 * @param {ArrayBuffer} customWallpaper The raw wallpaper file data.
449 */ 452 */
450 WallpaperManager.prototype.refreshWallpaper_ = function(customWallpaper) { 453 WallpaperManager.prototype.refreshWallpaper_ = function(customWallpaper) {
451 var setWallpaperLayout = $('set-wallpaper-layout'); 454 var setWallpaperLayout = $('set-wallpaper-layout');
452 var layout = 455 var layout =
453 setWallpaperLayout.options[setWallpaperLayout.selectedIndex].value; 456 setWallpaperLayout.options[setWallpaperLayout.selectedIndex].value;
454 chrome.wallpaperPrivate.setCustomWallpaper(customWallpaper, 457 chrome.wallpaperPrivate.setCustomWallpaper(customWallpaper,
455 layout, 458 layout,
456 this.onFinished_.bind(this)); 459 this.onFinished_.bind(this));
457 this.currentWallpaper_ = 'CUSTOM'; 460 this.currentWallpaper_ = 'CUSTOM';
458 }; 461 };
459 462
460 /** 463 /**
461 * Sets wallpaper finished. Displays error message in butter bar if any. 464 * Sets wallpaper finished. Displays error message in butter bar if any.
465 * @param {WallpaperThumbnailsGridItem=} opt_selectedGridItem The wallpaper
466 * thumbnail grid item. It extends from cr.ui.ListItem.
462 */ 467 */
463 WallpaperManager.prototype.onFinished_ = function() { 468 WallpaperManager.prototype.onFinished_ = function(opt_selectedGridItem) {
469 if (opt_selectedGridItem)
470 this.progressManager_.hideProgressBar(opt_selectedGridItem);
471
464 if (chrome.runtime.lastError != undefined) { 472 if (chrome.runtime.lastError != undefined) {
465 this.butterBar_.showError_(chrome.runtime.lastError.message, 473 // TODO(bshe): Add error message back once we decide how to show error
466 {help_url: LEARN_MORE_URL}); 474 // message in the new UI. http://crbug.com/162563
467 } else { 475 } else if (opt_selectedGridItem) {
468 this.butterBar_.hide_(); 476 this.setActiveThumb(opt_selectedGridItem);
469 } 477 }
470 }; 478 };
471 479
472 /** 480 /**
473 * Handles the layout setting change of custom wallpaper. 481 * Handles the layout setting change of custom wallpaper.
474 */ 482 */
475 WallpaperManager.prototype.onWallpaperLayoutChanged_ = function() { 483 WallpaperManager.prototype.onWallpaperLayoutChanged_ = function() {
476 if (this.customWallpaperData_) 484 if (this.customWallpaperData_)
477 this.refreshWallpaper_(this.customWallpaperData_); 485 this.refreshWallpaper_(this.customWallpaperData_);
478 }; 486 };
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 wallpapersDataModel.push(wallpaperInfo); 549 wallpapersDataModel.push(wallpaperInfo);
542 var url = this.manifest_.wallpaper_list[key].base_url + 550 var url = this.manifest_.wallpaper_list[key].base_url +
543 HighResolutionSuffix; 551 HighResolutionSuffix;
544 if (url == this.currentWallpaper_) { 552 if (url == this.currentWallpaper_) {
545 selectedItem = wallpaperInfo; 553 selectedItem = wallpaperInfo;
546 } 554 }
547 } 555 }
548 } 556 }
549 this.wallpaperGrid_.dataModel = wallpapersDataModel; 557 this.wallpaperGrid_.dataModel = wallpapersDataModel;
550 this.wallpaperGrid_.selectedItem = selectedItem; 558 this.wallpaperGrid_.selectedItem = selectedItem;
551 this.setActiveThumb(selectedItem); 559 this.setActiveThumb(this.wallpaperGrid_.getListItem(selectedItem));
552 } 560 }
553 }; 561 };
554 562
555 /** 563 /**
556 * Shows a checkmark on the active thumbnail and clears previous active one if 564 * Shows a checkmark on the active thumbnail and clears previous active one if
557 * any. Note if wallpaper was not set successfully, checkmark should not show 565 * any. Note if wallpaper was not set successfully, checkmark should not show
558 * on that thumbnail. 566 * on that thumbnail.
559 * @param {{baseURL: string, dynamicURL: string, layout: string, 567 * @param {WallpaperThumbnailsGridItem} selectedGridItem The wallpaper
560 * author: string, authorWebsite: string, availableOffline: boolean}} 568 * thumbnail grid item. It extends from cr.ui.ListItem.
561 * activeItem the wallpaper item to active (show checkmark).
562 */ 569 */
563 WallpaperManager.prototype.setActiveThumb = function(activeItem) { 570 WallpaperManager.prototype.setActiveThumb = function(selectedGridItem) {
564 var activeThumb = $('wallpaper-grid').getListItem(activeItem); 571 if (!selectedGridItem)
565 if (!activeThumb)
566 return; 572 return;
567 // Clears previous checkmark. 573 // Clears previous checkmark.
568 var previousActiveThumb = $('wallpaper-grid').querySelector('[active]'); 574 if (this.checkmark_.parentNode)
569 if (previousActiveThumb) 575 this.checkmark_.parentNode.removeChild(this.checkmark_);
570 previousActiveThumb.active = false; 576 selectedGridItem.appendChild(this.checkmark_);
571 activeThumb.active = true;
572 }; 577 };
573 578
574 })(); 579 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698