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 * |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 self.downloadedListMap_ = null; | 229 self.downloadedListMap_ = null; |
230 $('wallpaper-grid').classList.remove('image-picker-offline'); | 230 $('wallpaper-grid').classList.remove('image-picker-offline'); |
231 }); | 231 }); |
232 $('close').addEventListener('click', function() {window.close()}); | 232 $('close').addEventListener('click', function() {window.close()}); |
233 this.document_.defaultView.addEventListener( | 233 this.document_.defaultView.addEventListener( |
234 'resize', this.onResize_.bind(this)); | 234 'resize', this.onResize_.bind(this)); |
235 $('learn-more').href = LearnMoreURL; | 235 $('learn-more').href = LearnMoreURL; |
236 $('close-error').addEventListener('click', function() { | 236 $('close-error').addEventListener('click', function() { |
237 $('error-container').hidden = true; | 237 $('error-container').hidden = true; |
238 }); | 238 }); |
239 $('close-wallpaper-selection').addEventListener('click', function() { | |
240 $('wallpaper-selection-container').hidden = true; | |
241 $('set-wallpaper-layout').disabled = true; | |
242 }); | |
239 | 243 |
240 this.onResize_(); | 244 this.onResize_(); |
241 }; | 245 }; |
242 | 246 |
243 /** | 247 /** |
244 * Preset to the category which contains current wallpaper. | 248 * Preset to the category which contains current wallpaper. |
245 */ | 249 */ |
246 WallpaperManager.prototype.presetCategory_ = function() { | 250 WallpaperManager.prototype.presetCategory_ = function() { |
247 this.currentWallpaper_ = str('currentWallpaper'); | 251 this.currentWallpaper_ = str('currentWallpaper'); |
248 if (this.currentWallpaper_ && this.currentWallpaper_ == 'CUSTOM') { | 252 if (this.currentWallpaper_ && |
bshe
2013/02/26 19:07:26
the currentWallpaper is either a url contains High
flackr
2013/02/26 21:37:35
Great, I was going to comment on this. Can you add
bshe
2013/02/27 03:16:38
Done.
| |
253 this.currentWallpaper_.indexOf(HighResolutionSuffix) == -1) { | |
249 // Custom is the last one in the categories list. | 254 // Custom is the last one in the categories list. |
250 this.categoriesList_.selectionModel.selectedIndex = | 255 this.categoriesList_.selectionModel.selectedIndex = |
251 this.categoriesList_.dataModel.length - 1; | 256 this.categoriesList_.dataModel.length - 1; |
252 return; | 257 return; |
253 } | 258 } |
254 var self = this; | 259 var self = this; |
255 var presetCategoryInner_ = function() { | 260 var presetCategoryInner_ = function() { |
256 // Selects the first category in the categories list of current | 261 // Selects the first category in the categories list of current |
257 // wallpaper as the default selected category when showing wallpaper | 262 // wallpaper as the default selected category when showing wallpaper |
258 // picker UI. | 263 // picker UI. |
259 var presetCategory = AllCategoryIndex; | 264 var presetCategory = AllCategoryIndex; |
260 for (var key in self.manifest_.wallpaper_list) { | 265 if (self.currentWallpaper_) { |
261 var url = self.manifest_.wallpaper_list[key].base_url + | 266 for (var key in self.manifest_.wallpaper_list) { |
262 HighResolutionSuffix; | 267 var url = self.manifest_.wallpaper_list[key].base_url + |
263 if (url.indexOf(self.currentWallpaper_) != -1) | 268 HighResolutionSuffix; |
264 presetCategory = self.manifest_.wallpaper_list[key].categories[0] + | 269 if (url.indexOf(self.currentWallpaper_) != -1) |
flackr
2013/02/26 21:37:35
nit: I believe you need braces for a multi-line lo
bshe
2013/02/27 03:16:38
Done.
| |
265 OnlineCategoriesOffset; | 270 presetCategory = self.manifest_.wallpaper_list[key].categories[0] + |
271 OnlineCategoriesOffset; | |
flackr
2013/02/26 21:37:35
You should break when you've found the category.
bshe
2013/02/27 03:16:38
Done.
| |
272 } | |
266 } | 273 } |
267 self.categoriesList_.selectionModel.selectedIndex = presetCategory; | 274 self.categoriesList_.selectionModel.selectedIndex = presetCategory; |
268 }; | 275 }; |
269 if (navigator.onLine) { | 276 if (navigator.onLine) { |
270 presetCategoryInner_(); | 277 presetCategoryInner_(); |
271 } else { | 278 } else { |
272 // If device is offline, gets the available offline wallpaper list first. | 279 // If device is offline, gets the available offline wallpaper list first. |
273 // Wallpapers which are not in the list will display a grayscaled | 280 // Wallpapers which are not in the list will display a grayscaled |
274 // thumbnail. | 281 // thumbnail. |
275 chrome.wallpaperPrivate.getOfflineWallpaperList('ONLINE', | 282 chrome.wallpaperPrivate.getOfflineWallpaperList('ONLINE', |
276 function(lists) { | 283 function(lists) { |
277 if (!self.downloadedListMap_) | 284 if (!self.downloadedListMap_) |
278 self.downloadedListMap_ = {}; | 285 self.downloadedListMap_ = {}; |
279 for (var i = 0; i < lists.length; i++) | 286 for (var i = 0; i < lists.length; i++) |
280 self.downloadedListMap_[lists[i]] = true; | 287 self.downloadedListMap_[lists[i]] = true; |
281 presetCategoryInner_(); | 288 presetCategoryInner_(); |
282 }); | 289 }); |
283 } | 290 } |
284 }; | 291 }; |
285 | 292 |
286 /** | 293 /** |
287 * Constructs the thumbnails grid. | 294 * Constructs the thumbnails grid. |
288 */ | 295 */ |
289 WallpaperManager.prototype.initThumbnailsGrid_ = function() { | 296 WallpaperManager.prototype.initThumbnailsGrid_ = function() { |
290 this.wallpaperGrid_ = $('wallpaper-grid'); | 297 this.wallpaperGrid_ = $('wallpaper-grid'); |
291 wallpapers.WallpaperThumbnailsGrid.decorate(this.wallpaperGrid_); | 298 wallpapers.WallpaperThumbnailsGrid.decorate(this.wallpaperGrid_); |
292 | 299 |
293 this.wallpaperGrid_.addEventListener('change', | 300 this.wallpaperGrid_.addEventListener('change', |
294 this.onThumbnailClicked_.bind(this)); | 301 this.onThumbnailSelectionChanged_.bind(this)); |
295 this.wallpaperGrid_.addEventListener('dblclick', this.onClose_.bind(this)); | 302 this.wallpaperGrid_.addEventListener('dblclick', this.onClose_.bind(this)); |
296 }; | 303 }; |
297 | 304 |
298 /** | 305 /** |
299 * Closes window if no pending wallpaper request. | 306 * Closes window if no pending wallpaper request. |
300 */ | 307 */ |
301 WallpaperManager.prototype.onClose_ = function() { | 308 WallpaperManager.prototype.onClose_ = function() { |
302 if (this.wallpaperRequest_) { | 309 if (this.wallpaperRequest_) { |
303 this.wallpaperRequest_.addEventListener('loadend', function() { | 310 this.wallpaperRequest_.addEventListener('loadend', function() { |
304 // Close window on wallpaper loading finished. | 311 // Close window on wallpaper loading finished. |
305 window.close(); | 312 window.close(); |
306 }); | 313 }); |
307 } else { | 314 } else { |
308 window.close(); | 315 window.close(); |
309 } | 316 } |
310 }; | 317 }; |
311 | 318 |
312 /** | 319 /** |
313 * Sets wallpaper to the corresponding wallpaper of selected thumbnail. | 320 * Sets wallpaper to the corresponding wallpaper of selected thumbnail. |
321 * @param {{baseURL: string, layout: string, source: string, | |
322 * availableOffline: boolean, opt_dynamicURL: string, | |
323 * opt_author: string, opt_authorWebsite: string}} | |
324 * selectedItem the selected item in WallpaperThumbnailsGrid's data | |
325 * model. | |
326 */ | |
bshe
2013/02/26 19:07:26
Most of the code in this function is moved from on
| |
327 WallpaperManager.prototype.setSelectedWallpaper_ = function(selectedItem) { | |
328 var self = this; | |
329 var wallpaperURL = selectedItem.baseURL; | |
330 if (selectedItem.source == 'ONLINE') | |
flackr
2013/02/26 21:37:35
nit: constants for source values.
bshe
2013/02/27 03:16:38
Done.
| |
331 wallpaperURL += HighResolutionSuffix; | |
flackr
2013/02/26 21:37:35
TODO: Use non high resolution wallpaper when appro
bshe
2013/02/27 03:16:38
There are changes in the design on how to fetch wa
flackr
2013/02/27 14:39:52
In light of that, I'm surprised we have a high res
bshe
2013/03/01 17:43:56
Discussed offline. We should investigate removing
| |
332 var selectedGridItem = this.wallpaperGrid_.getListItem(selectedItem); | |
333 | |
334 chrome.wallpaperPrivate.setWallpaperIfExist(wallpaperURL, | |
335 selectedItem.layout, | |
336 selectedItem.source, | |
337 function() { | |
338 if (chrome.runtime.lastError == undefined) { | |
339 self.currentWallpaper_ = wallpaperURL; | |
340 self.wallpaperGrid_.activeItem = selectedItem; | |
341 return; | |
342 } | |
343 | |
344 if (selectedItem.source == 'CUSTOM') | |
345 return; | |
346 | |
347 // Falls back to request wallpaper from server. | |
348 if (self.wallpaperRequest_) | |
349 self.wallpaperRequest_.abort(); | |
350 | |
351 self.wallpaperRequest_ = new XMLHttpRequest(); | |
352 self.wallpaperRequest_.open('GET', wallpaperURL, true); | |
353 self.wallpaperRequest_.responseType = 'arraybuffer'; | |
354 self.progressManager_.reset(self.wallpaperRequest_, selectedGridItem); | |
355 self.wallpaperRequest_.send(null); | |
356 self.wallpaperRequest_.addEventListener('load', function(e) { | |
357 if (self.wallpaperRequest_.status === 200) { | |
358 var image = self.wallpaperRequest_.response; | |
359 chrome.wallpaperPrivate.setWallpaper( | |
360 image, | |
361 selectedItem.layout, | |
362 wallpaperURL, | |
363 self.onFinished_.bind(self, selectedGridItem, selectedItem)); | |
364 self.currentWallpaper_ = wallpaperURL; | |
365 } else { | |
366 self.progressManager_.hideProgressBar(selectedGridItem); | |
367 self.showError_(str('downloadFailed')); | |
368 } | |
369 self.wallpaperRequest_ = null; | |
370 }); | |
371 self.wallpaperRequest_.addEventListener('error', function() { | |
372 self.showError_(str('downloadFailed')); | |
373 }); | |
374 }); | |
375 }; | |
376 | |
377 /** | |
378 * Handles click on a different thumbnail in wallpaper grid. | |
314 */ | 379 */ |
315 WallpaperManager.prototype.onThumbnailClicked_ = function() { | 380 WallpaperManager.prototype.onThumbnailSelectionChanged_ = function() { |
316 var selectedItem = this.wallpaperGrid_.selectedItem; | 381 var selectedItem = this.wallpaperGrid_.selectedItem; |
317 if (selectedItem && selectedItem.dynamicURL && | 382 if (selectedItem && selectedItem.source == 'ADDNEW') |
383 return; | |
384 | |
385 if (selectedItem && selectedItem.baseURL && | |
318 !this.wallpaperGrid_.inProgramSelection) { | 386 !this.wallpaperGrid_.inProgramSelection) { |
flackr
2013/02/26 21:37:35
pardon my ignorance, but what does inProgramSelect
bshe
2013/02/27 03:16:38
Sorry for confusion. When the current thumbnail se
| |
319 var wallpaperURL = selectedItem.baseURL + HighResolutionSuffix; | 387 if (selectedItem.source == 'CUSTOM') { |
320 var selectedGridItem = this.wallpaperGrid_.getListItem(selectedItem); | 388 var items = {}; |
321 var self = this; | 389 var key = selectedItem.baseURL; |
322 | 390 var self = this; |
323 chrome.wallpaperPrivate.setWallpaperIfExist(wallpaperURL, | 391 this.storage_.get(key, function(items) { |
324 selectedItem.layout, | 392 selectedItem.layout = items[key] ? items[key] : 'CENTER_CROPPED'; |
325 'ONLINE', | 393 self.setSelectedWallpaper_(selectedItem); |
326 function() { | |
327 if (chrome.runtime.lastError == undefined) { | |
328 self.currentWallpaper_ = wallpaperURL; | |
329 self.wallpaperGrid_.activeItem = selectedItem; | |
330 return; | |
331 } | |
332 | |
333 // Falls back to request wallpaper from server. | |
334 if (self.wallpaperRequest_) | |
335 self.wallpaperRequest_.abort(); | |
336 | |
337 self.wallpaperRequest_ = new XMLHttpRequest(); | |
338 self.wallpaperRequest_.open('GET', wallpaperURL, true); | |
339 self.wallpaperRequest_.responseType = 'arraybuffer'; | |
340 self.progressManager_.reset(self.wallpaperRequest_, selectedGridItem); | |
341 self.wallpaperRequest_.send(null); | |
342 self.wallpaperRequest_.addEventListener('load', function(e) { | |
343 if (self.wallpaperRequest_.status === 200) { | |
344 var image = self.wallpaperRequest_.response; | |
345 chrome.wallpaperPrivate.setWallpaper( | |
346 image, | |
347 selectedItem.layout, | |
348 wallpaperURL, | |
349 self.onFinished_.bind(self, selectedGridItem, selectedItem)); | |
350 self.currentWallpaper_ = wallpaperURL; | |
351 } else { | |
352 self.progressManager_.hideProgressBar(selectedGridItem); | |
353 self.showError_(str('downloadFailed')); | |
354 } | |
355 self.wallpaperRequest_ = null; | |
356 }); | 394 }); |
357 self.wallpaperRequest_.addEventListener('error', function() { | 395 } else { |
358 self.showError_(str('downloadFailed')); | 396 this.setSelectedWallpaper_(selectedItem); |
359 }); | 397 } |
360 }); | |
361 } | 398 } |
362 this.setWallpaperAttribution_(selectedItem); | 399 this.setWallpaperAttribution_(selectedItem); |
363 }; | 400 }; |
364 | 401 |
365 /** | 402 /** |
366 * Set attributions of wallpaper with given URL. If URL is not valid, clear | 403 * Set attributions of wallpaper with given URL. If URL is not valid, clear |
367 * the attributions. | 404 * the attributions. |
368 * @param {{baseURL: string, dynamicURL: string, layout: string, | 405 * @param {{baseURL: string, dynamicURL: string, layout: string, |
369 * author: string, authorWebsite: string, availableOffline: boolean}} | 406 * author: string, authorWebsite: string, availableOffline: boolean}} |
370 * selectedItem selected wallpaper item in grid. | 407 * selectedItem selected wallpaper item in grid. |
371 * @private | 408 * @private |
372 */ | 409 */ |
373 WallpaperManager.prototype.setWallpaperAttribution_ = function(selectedItem) { | 410 WallpaperManager.prototype.setWallpaperAttribution_ = function(selectedItem) { |
374 if (selectedItem) { | 411 if (selectedItem) { |
375 $('author-name').textContent = selectedItem.author; | 412 $('author-name').textContent = selectedItem.author; |
376 $('author-website').textContent = $('author-website').href = | 413 $('author-website').textContent = $('author-website').href = |
377 selectedItem.authorWebsite; | 414 selectedItem.authorWebsite; |
378 chrome.wallpaperPrivate.getThumbnail(selectedItem.baseURL, | 415 chrome.wallpaperPrivate.getThumbnail(selectedItem.baseURL, |
416 selectedItem.source, | |
379 function(data) { | 417 function(data) { |
380 var img = $('attribute-image'); | 418 var img = $('attribute-image'); |
381 if (data) { | 419 if (data) { |
382 var blob = new Blob([new Int8Array(data)], {'type' : 'image\/png'}); | 420 var blob = new Blob([new Int8Array(data)], {'type' : 'image\/png'}); |
383 img.src = window.URL.createObjectURL(blob); | 421 img.src = window.URL.createObjectURL(blob); |
384 img.addEventListener('load', function(e) { | 422 img.addEventListener('load', function(e) { |
385 window.URL.revokeObjectURL(this.src); | 423 window.URL.revokeObjectURL(this.src); |
386 }); | 424 }); |
387 } else { | 425 } else { |
388 img.src = ''; | 426 img.src = ''; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
470 return; | 508 return; |
471 } | 509 } |
472 var reader = new FileReader(); | 510 var reader = new FileReader(); |
473 reader.readAsArrayBuffer(files[0]); | 511 reader.readAsArrayBuffer(files[0]); |
474 var self = this; | 512 var self = this; |
475 reader.addEventListener('error', function(e) { | 513 reader.addEventListener('error', function(e) { |
476 self.showError_(str('accessFileFailure')); | 514 self.showError_(str('accessFileFailure')); |
477 }); | 515 }); |
478 reader.addEventListener('load', function(e) { | 516 reader.addEventListener('load', function(e) { |
479 self.customWallpaperData_ = e.target.result; | 517 self.customWallpaperData_ = e.target.result; |
480 self.refreshWallpaper_(self.customWallpaperData_); | 518 var layout = self.getSelectedLayout_(); |
519 chrome.wallpaperPrivate.setCustomWallpaper(self.customWallpaperData_, | |
520 layout, self.onSetCustomWallpaperFinished_.bind(self)); | |
481 }); | 521 }); |
482 this.generateThumbnail_(files[0]); | |
483 }; | 522 }; |
484 | 523 |
485 /** | 524 /** |
486 * Refreshes the custom wallpaper with the current selected layout. | 525 * Retruns the current selected layout. |
487 * @param {ArrayBuffer} customWallpaper The raw wallpaper file data. | 526 * @return {string} The selected layout. |
488 */ | 527 */ |
489 WallpaperManager.prototype.refreshWallpaper_ = function(customWallpaper) { | 528 WallpaperManager.prototype.getSelectedLayout_ = function() { |
490 var setWallpaperLayout = $('set-wallpaper-layout'); | 529 var setWallpaperLayout = $('set-wallpaper-layout'); |
491 var layout = | 530 return setWallpaperLayout.options[setWallpaperLayout.selectedIndex].value; |
492 setWallpaperLayout.options[setWallpaperLayout.selectedIndex].value; | |
493 chrome.wallpaperPrivate.setCustomWallpaper(customWallpaper, | |
494 layout, | |
495 this.onFinished_.bind(this)); | |
496 this.currentWallpaper_ = 'CUSTOM'; | |
497 }; | 531 }; |
498 | 532 |
499 /** | 533 /** |
500 * Sets wallpaper finished. Displays error message in butter bar if any. | 534 * Add new thumbnail to custom wallpaper grid and set it as active thumbnail. |
535 * @param {string=} opt_fileName The file name used to save the new selected | |
flackr
2013/02/26 21:37:35
When is the filename optional / not passed?
bshe
2013/02/27 03:16:38
When custom wallpaper layout change finished, this
flackr
2013/02/27 14:39:52
Comment this please.
On 2013/02/27 03:16:38, bshe
bshe
2013/03/01 17:43:56
Done.
| |
536 * custom wallpaper. | |
537 */ | |
538 WallpaperManager.prototype.onSetCustomWallpaperFinished_ = | |
539 function(opt_fileName) { | |
540 if (chrome.runtime.lastError != undefined) { | |
541 this.showError_(chrome.runtime.lastError.message); | |
542 $('set-wallpaper-layout').disabled = true; | |
543 } else { | |
544 var layout = this.getSelectedLayout_(); | |
545 $('set-wallpaper-layout').disabled = false; | |
546 if (opt_fileName) { | |
547 var wallpaperInfo = { | |
548 baseURL: opt_fileName, | |
549 layout: layout, | |
550 source: 'CUSTOM', | |
551 availableOffline: true | |
552 }; | |
553 this.currentWallpaper_ = opt_fileName; | |
554 var items = {}; | |
555 items[this.currentWallpaper_] = layout; | |
556 this.storage_.set(items, function() {}); | |
557 this.wallpaperGrid_.dataModel.splice(0, 0, wallpaperInfo); | |
558 this.wallpaperGrid_.selectedItem = wallpaperInfo; | |
559 this.wallpaperGrid_.activeItem = wallpaperInfo; | |
560 } | |
561 } | |
562 }; | |
563 | |
564 /** | |
565 * Sets wallpaper finished. Displays error message if any. | |
501 * @param {WallpaperThumbnailsGridItem=} opt_selectedGridItem The wallpaper | 566 * @param {WallpaperThumbnailsGridItem=} opt_selectedGridItem The wallpaper |
502 * thumbnail grid item. It extends from cr.ui.ListItem. | 567 * thumbnail grid item. It extends from cr.ui.ListItem. |
503 * @param {{baseURL: string, dynamicURL: string, layout: string, | 568 * @param {{baseURL: string, layout: string, source: string, |
504 * author: string, authorWebsite: string, | 569 * availableOffline: boolean, opt_dynamicURL: string, |
505 * availableOffline: boolean}=} | 570 * opt_author: string, opt_authorWebsite: string}=} |
506 * opt_selectedItem the selected item in WallpaperThumbnailsGrid's data | 571 * opt_selectedItem the selected item in WallpaperThumbnailsGrid's data |
507 * model. | 572 * model. |
508 */ | 573 */ |
509 WallpaperManager.prototype.onFinished_ = function(opt_selectedGridItem, | 574 WallpaperManager.prototype.onFinished_ = function(opt_selectedGridItem, |
510 opt_selectedItem) { | 575 opt_selectedItem) { |
511 if (opt_selectedGridItem) | 576 if (opt_selectedGridItem) |
512 this.progressManager_.hideProgressBar(opt_selectedGridItem); | 577 this.progressManager_.hideProgressBar(opt_selectedGridItem); |
513 | 578 |
514 if (chrome.runtime.lastError != undefined) { | 579 if (chrome.runtime.lastError != undefined) { |
515 this.showError_(chrome.runtime.lastError.message); | 580 this.showError_(chrome.runtime.lastError.message); |
516 } else if (opt_selectedItem) { | 581 } else if (opt_selectedItem) { |
517 this.wallpaperGrid_.activeItem = opt_selectedItem; | 582 this.wallpaperGrid_.activeItem = opt_selectedItem; |
518 } | 583 } |
519 }; | 584 }; |
520 | 585 |
521 /** | 586 /** |
522 * Handles the layout setting change of custom wallpaper. | 587 * Handles the layout setting change of custom wallpaper. |
523 */ | 588 */ |
524 WallpaperManager.prototype.onWallpaperLayoutChanged_ = function() { | 589 WallpaperManager.prototype.onWallpaperLayoutChanged_ = function() { |
525 var setWallpaperLayout = $('set-wallpaper-layout'); | 590 var layout = this.getSelectedLayout_(); |
526 var layout = | 591 var items = {}; |
527 setWallpaperLayout.options[setWallpaperLayout.selectedIndex].value; | 592 items[this.currentWallpaper_] = layout; |
528 chrome.wallpaperPrivate.setCustomWallpaperLayout(layout, | 593 this.storage_.set(items, function() {}); |
529 this.onFinished_.bind(this)); | 594 chrome.wallpaperPrivate.setCustomWallpaperLayout(layout, |
595 this.onSetCustomWallpaperFinished_.bind(this)); | |
530 }; | 596 }; |
531 | 597 |
532 /** | 598 /** |
533 * Generates a thumbnail of user selected image file. | |
534 * @param {Object} file The file user selected from file manager. | |
535 */ | |
536 WallpaperManager.prototype.generateThumbnail_ = function(file) { | |
537 var img = $('preview'); | |
538 img.file = file; | |
539 var reader = new FileReader(); | |
540 reader.addEventListener('load', function(e) { | |
541 img.src = e.target.result; | |
542 }); | |
543 reader.readAsDataURL(file); | |
544 }; | |
545 | |
546 /** | |
547 * Toggle visibility of custom container and category container. | |
548 * @param {boolean} showCustom True if display custom container and hide | |
549 * category container. | |
550 */ | |
551 WallpaperManager.prototype.showCustomContainer_ = function(showCustom) { | |
552 $('category-container').hidden = showCustom; | |
553 $('custom-container').hidden = !showCustom; | |
554 }; | |
555 | |
556 /** | |
557 * Handles user clicking on a different category. | 599 * Handles user clicking on a different category. |
558 */ | 600 */ |
559 WallpaperManager.prototype.onCategoriesChange_ = function() { | 601 WallpaperManager.prototype.onCategoriesChange_ = function() { |
560 var categoriesList = this.categoriesList_; | 602 var categoriesList = this.categoriesList_; |
561 var selectedIndex = categoriesList.selectionModel.selectedIndex; | 603 var selectedIndex = categoriesList.selectionModel.selectedIndex; |
562 if (selectedIndex == -1) | 604 if (selectedIndex == -1) |
563 return; | 605 return; |
564 var selectedListItem = categoriesList.getListItemByIndex(selectedIndex); | 606 var selectedListItem = categoriesList.getListItemByIndex(selectedIndex); |
565 var bar = $('bar'); | 607 var bar = $('bar'); |
566 bar.style.left = selectedListItem.offsetLeft + 'px'; | 608 bar.style.left = selectedListItem.offsetLeft + 'px'; |
567 bar.style.width = selectedListItem.offsetWidth + 'px'; | 609 bar.style.width = selectedListItem.offsetWidth + 'px'; |
568 | 610 |
611 var wallpapersDataModel = new cr.ui.ArrayDataModel([]); | |
612 var selectedItem; | |
569 if (selectedListItem.custom) { | 613 if (selectedListItem.custom) { |
570 this.showCustomContainer_(true); | 614 $('online-wallpaper-attribute').hidden = true; |
615 var self = this; | |
616 chrome.wallpaperPrivate.getOfflineWallpaperList('CUSTOM', | |
617 function(lists) { | |
618 for (var i = 0; i < lists.length; i++) { | |
619 var wallpaperInfo = { | |
620 baseURL: lists[i], | |
621 layout: 'CENTER_CROPPED', | |
flackr
2013/02/26 21:37:35
So this is later replaced with the last used layou
bshe
2013/02/27 03:16:38
Right. It will be replaced by the value in local s
flackr
2013/02/27 14:39:52
Please add comment to this effect.
On 2013/02/27
bshe
2013/03/01 17:43:56
Done.
| |
622 source: 'CUSTOM', | |
623 availableOffline: true | |
624 }; | |
625 if (self.currentWallpaper_ == lists[i]) | |
626 selectedItem = wallpaperInfo; | |
627 wallpapersDataModel.push(wallpaperInfo); | |
628 } | |
629 var lastElement = { | |
630 baseURL: '', | |
631 layout: '', | |
632 source: 'ADDNEW', | |
633 availableOffline: true | |
634 }; | |
635 wallpapersDataModel.push(lastElement); | |
636 self.wallpaperGrid_.dataModel = wallpapersDataModel; | |
637 self.wallpaperGrid_.selectedItem = selectedItem; | |
638 self.wallpaperGrid_.activeItem = selectedItem; | |
639 }); | |
571 } else { | 640 } else { |
572 this.showCustomContainer_(false); | 641 $('online-wallpaper-attribute').hidden = false; |
573 var selectedItem; | |
574 var wallpapersDataModel = new cr.ui.ArrayDataModel([]); | |
575 for (var key in this.manifest_.wallpaper_list) { | 642 for (var key in this.manifest_.wallpaper_list) { |
576 if (selectedIndex == AllCategoryIndex || | 643 if (selectedIndex == AllCategoryIndex || |
577 this.manifest_.wallpaper_list[key].categories.indexOf( | 644 this.manifest_.wallpaper_list[key].categories.indexOf( |
578 selectedIndex - OnlineCategoriesOffset) != -1) { | 645 selectedIndex - OnlineCategoriesOffset) != -1) { |
579 var wallpaperInfo = { | 646 var wallpaperInfo = { |
580 baseURL: this.manifest_.wallpaper_list[key].base_url, | 647 baseURL: this.manifest_.wallpaper_list[key].base_url, |
581 dynamicURL: this.manifest_.wallpaper_list[key].dynamic_url, | |
582 layout: this.manifest_.wallpaper_list[key].default_layout, | 648 layout: this.manifest_.wallpaper_list[key].default_layout, |
649 source: 'ONLINE', | |
650 availableOffline: false, | |
583 author: this.manifest_.wallpaper_list[key].author, | 651 author: this.manifest_.wallpaper_list[key].author, |
584 authorWebsite: this.manifest_.wallpaper_list[key].author_website, | 652 authorWebsite: this.manifest_.wallpaper_list[key].author_website, |
585 availableOffline: false | 653 dynamicURL: this.manifest_.wallpaper_list[key].dynamic_url |
586 }; | 654 }; |
587 var startIndex = wallpaperInfo.baseURL.lastIndexOf('/') + 1; | 655 var startIndex = wallpaperInfo.baseURL.lastIndexOf('/') + 1; |
588 var fileName = wallpaperInfo.baseURL.substring(startIndex) + | 656 var fileName = wallpaperInfo.baseURL.substring(startIndex) + |
589 HighResolutionSuffix; | 657 HighResolutionSuffix; |
590 if (this.downloadedListMap_ && | 658 if (this.downloadedListMap_ && |
591 this.downloadedListMap_.hasOwnProperty(encodeURI(fileName))) { | 659 this.downloadedListMap_.hasOwnProperty(encodeURI(fileName))) { |
592 wallpaperInfo.availableOffline = true; | 660 wallpaperInfo.availableOffline = true; |
593 } | 661 } |
594 wallpapersDataModel.push(wallpaperInfo); | 662 wallpapersDataModel.push(wallpaperInfo); |
595 var url = this.manifest_.wallpaper_list[key].base_url + | 663 var url = this.manifest_.wallpaper_list[key].base_url + |
596 HighResolutionSuffix; | 664 HighResolutionSuffix; |
597 if (url == this.currentWallpaper_) { | 665 if (url == this.currentWallpaper_) { |
598 selectedItem = wallpaperInfo; | 666 selectedItem = wallpaperInfo; |
599 } | 667 } |
600 } | 668 } |
601 } | 669 } |
602 this.wallpaperGrid_.dataModel = wallpapersDataModel; | 670 this.wallpaperGrid_.dataModel = wallpapersDataModel; |
603 this.wallpaperGrid_.selectedItem = selectedItem; | 671 this.wallpaperGrid_.selectedItem = selectedItem; |
604 this.wallpaperGrid_.activeItem = selectedItem; | 672 this.wallpaperGrid_.activeItem = selectedItem; |
605 } | 673 } |
606 }; | 674 }; |
607 | 675 |
608 })(); | 676 })(); |
OLD | NEW |