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 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
612 msg = 'Unknown Error'; | 612 msg = 'Unknown Error'; |
613 break; | 613 break; |
614 } | 614 } |
615 console.error('Error: ' + msg); | 615 console.error('Error: ' + msg); |
616 this.showError_(str('accessFileFailure')); | 616 this.showError_(str('accessFileFailure')); |
617 }; | 617 }; |
618 | 618 |
619 /** | 619 /** |
620 * Handles click on a different thumbnail in wallpaper grid. | 620 * Handles click on a different thumbnail in wallpaper grid. |
621 */ | 621 */ |
622 WallpaperManager.prototype.onThumbnailSelectionChanged_ = function() { | 622 WallpaperManager.prototype.onThumbnailSelectionChanged_ = function() { |
flackr
2013/04/16 01:28:41
This method and description seem to be inaccuratel
bshe
2013/04/16 16:19:26
Done.
| |
623 var selectedItem = this.wallpaperGrid_.selectedItem; | 623 var selectedItem = this.wallpaperGrid_.selectedItem; |
624 if (selectedItem && selectedItem.source == 'ADDNEW') | 624 this.setWallpaperAttribution_(selectedItem); |
625 | |
626 // splice may dispatch a change event because the position of selected | |
627 // element changing. But the actual selected element didn't change after | |
628 // splice. Check if the new selected element equals to the previous selected | |
629 // element before continuing. Otherwise, wallpaper may reset to previous one | |
630 // as described in http://crbug.com/229036. | |
631 if (!selectedItem || selectedItem.source == 'ADDNEW' || | |
632 selectedItem == this.wallpaperGrid_.previousSelectedItem) { | |
625 return; | 633 return; |
634 } | |
626 | 635 |
627 if (selectedItem && selectedItem.baseURL && | 636 this.wallpaperGrid_.previousSelectedItem = selectedItem; |
flackr
2013/04/16 01:28:41
previousSelectedItem doesn't belong in wallpaperGr
bshe
2013/04/16 16:19:26
I can't use currentWallpaper or activeItem to repl
| |
628 !this.wallpaperGrid_.inProgramSelection) { | 637 if (selectedItem.baseURL && !this.wallpaperGrid_.inProgramSelection) { |
629 if (selectedItem.source == wallpapers.WallpaperSourceEnum.Custom) { | 638 if (selectedItem.source == wallpapers.WallpaperSourceEnum.Custom) { |
630 var items = {}; | 639 var items = {}; |
631 var key = selectedItem.baseURL; | 640 var key = selectedItem.baseURL; |
632 var self = this; | 641 var self = this; |
633 this.storage_.get(key, function(items) { | 642 this.storage_.get(key, function(items) { |
634 selectedItem.layout = items[key] ? items[key] : 'CENTER_CROPPED'; | 643 selectedItem.layout = items[key] ? items[key] : 'CENTER_CROPPED'; |
635 self.setSelectedWallpaper_(selectedItem); | 644 self.setSelectedWallpaper_(selectedItem); |
636 }); | 645 }); |
637 } else { | 646 } else { |
638 this.setSelectedWallpaper_(selectedItem); | 647 this.setSelectedWallpaper_(selectedItem); |
639 } | 648 } |
640 } | 649 } |
641 this.setWallpaperAttribution_(selectedItem); | |
642 }; | 650 }; |
643 | 651 |
644 /** | 652 /** |
645 * Set attributions of wallpaper with given URL. If URL is not valid, clear | 653 * Set attributions of wallpaper with given URL. If URL is not valid, clear |
646 * the attributions. | 654 * the attributions. |
647 * @param {{baseURL: string, dynamicURL: string, layout: string, | 655 * @param {{baseURL: string, dynamicURL: string, layout: string, |
648 * author: string, authorWebsite: string, availableOffline: boolean}} | 656 * author: string, authorWebsite: string, availableOffline: boolean}} |
649 * selectedItem selected wallpaper item in grid. | 657 * selectedItem selected wallpaper item in grid. |
650 * @private | 658 * @private |
651 */ | 659 */ |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
762 $('set-wallpaper-layout').disabled = false; | 770 $('set-wallpaper-layout').disabled = false; |
763 var wallpaperInfo = { | 771 var wallpaperInfo = { |
764 baseURL: fileName, | 772 baseURL: fileName, |
765 layout: layout, | 773 layout: layout, |
766 source: wallpapers.WallpaperSourceEnum.Custom, | 774 source: wallpapers.WallpaperSourceEnum.Custom, |
767 availableOffline: true | 775 availableOffline: true |
768 }; | 776 }; |
769 self.currentWallpaper_ = fileName; | 777 self.currentWallpaper_ = fileName; |
770 var items = {}; | 778 var items = {}; |
771 items[self.currentWallpaper_] = layout; | 779 items[self.currentWallpaper_] = layout; |
772 self.storage_.set(items, function() {}); | |
773 self.wallpaperGrid_.dataModel.splice(0, 0, wallpaperInfo); | 780 self.wallpaperGrid_.dataModel.splice(0, 0, wallpaperInfo); |
774 self.wallpaperGrid_.selectedItem = wallpaperInfo; | 781 self.wallpaperGrid_.selectedItem = wallpaperInfo; |
775 self.wallpaperGrid_.activeItem = wallpaperInfo; | 782 self.wallpaperGrid_.activeItem = wallpaperInfo; |
776 }; | 783 }; |
777 | 784 |
778 fileWriter.onerror = errorHandler; | 785 fileWriter.onerror = errorHandler; |
779 | 786 |
780 var blob = new Blob([new Int8Array(thumbnail)], | 787 var blob = new Blob([new Int8Array(thumbnail)], |
781 {'type' : 'image\/jpeg'}); | 788 {'type' : 'image\/jpeg'}); |
782 fileWriter.write(blob); | 789 fileWriter.write(blob); |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1017 } | 1024 } |
1018 } | 1025 } |
1019 } | 1026 } |
1020 this.wallpaperGrid_.dataModel = wallpapersDataModel; | 1027 this.wallpaperGrid_.dataModel = wallpapersDataModel; |
1021 this.wallpaperGrid_.selectedItem = selectedItem; | 1028 this.wallpaperGrid_.selectedItem = selectedItem; |
1022 this.wallpaperGrid_.activeItem = selectedItem; | 1029 this.wallpaperGrid_.activeItem = selectedItem; |
1023 } | 1030 } |
1024 }; | 1031 }; |
1025 | 1032 |
1026 })(); | 1033 })(); |
OLD | NEW |