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 cr.define('wallpapers', function() { | 5 cr.define('wallpapers', function() { |
6 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 6 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
7 /** @const */ var Grid = cr.ui.Grid; | 7 /** @const */ var Grid = cr.ui.Grid; |
8 /** @const */ var GridItem = cr.ui.GridItem; | 8 /** @const */ var GridItem = cr.ui.GridItem; |
9 /** @const */ var GridSelectionController = cr.ui.GridSelectionController; | 9 /** @const */ var GridSelectionController = cr.ui.GridSelectionController; |
10 /** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; | 10 /** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; |
11 /** @const */ var ThumbnailSuffix = '_thumbnail.png'; | 11 /** @const */ var ThumbnailSuffix = '_thumbnail.png'; |
12 | 12 |
13 /** | 13 /** |
14 * Creates a new wallpaper thumbnails grid item. | 14 * Creates a new wallpaper thumbnails grid item. |
15 * @param {{baseURL: string, dynamicURL: string, layout: string, | 15 * @param {{baseURL: string, layout: string, source: string, |
16 * author: string, authorWebsite: string, availableOffline: boolean}} | 16 * availableOffline: boolean, opt_dynamicURL: string, |
17 * wallpaperInfo Wallpaper baseURL, dynamicURL, layout, author and | 17 * opt_author: string, opt_authorWebsite: string}} |
18 * author website. | 18 * wallpaperInfo Wallpaper data item in WallpaperThumbnailsGrid's data |
19 * model. | |
19 * @constructor | 20 * @constructor |
20 * @extends {cr.ui.GridItem} | 21 * @extends {cr.ui.GridItem} |
21 */ | 22 */ |
22 function WallpaperThumbnailsGridItem(wallpaperInfo) { | 23 function WallpaperThumbnailsGridItem(wallpaperInfo) { |
23 var el = new GridItem(wallpaperInfo); | 24 var el = new GridItem(wallpaperInfo); |
24 el.__proto__ = WallpaperThumbnailsGridItem.prototype; | 25 el.__proto__ = WallpaperThumbnailsGridItem.prototype; |
25 return el; | 26 return el; |
26 } | 27 } |
27 | 28 |
28 WallpaperThumbnailsGridItem.prototype = { | 29 WallpaperThumbnailsGridItem.prototype = { |
29 __proto__: GridItem.prototype, | 30 __proto__: GridItem.prototype, |
30 | 31 |
31 /** @override */ | 32 /** @override */ |
32 decorate: function() { | 33 decorate: function() { |
33 GridItem.prototype.decorate.call(this); | 34 GridItem.prototype.decorate.call(this); |
34 // Removes garbage created by GridItem. | 35 // Removes garbage created by GridItem. |
35 this.innerText = ''; | 36 this.innerText = ''; |
36 var imageEl = cr.doc.createElement('img'); | 37 var imageEl = cr.doc.createElement('img'); |
37 imageEl.classList.add('thumbnail'); | 38 imageEl.classList.add('thumbnail'); |
38 cr.defineProperty(imageEl, 'offline', cr.PropertyKind.BOOL_ATTR); | 39 cr.defineProperty(imageEl, 'offline', cr.PropertyKind.BOOL_ATTR); |
39 imageEl.offline = this.dataItem.availableOffline; | 40 imageEl.offline = this.dataItem.availableOffline; |
40 this.appendChild(imageEl); | 41 this.appendChild(imageEl); |
41 | 42 |
bshe
2013/02/26 19:07:26
This element is the grid element responsible for o
| |
43 if (this.dataItem.source == 'ADDNEW') { | |
44 this.id = 'add-new'; | |
45 this.addEventListener('click', function(e) { | |
46 $('wallpaper-selection-container').hidden = false; | |
47 }); | |
48 return; | |
49 } | |
50 | |
42 var self = this; | 51 var self = this; |
43 chrome.wallpaperPrivate.getThumbnail(this.dataItem.baseURL, 'ONLINE', | 52 chrome.wallpaperPrivate.getThumbnail(this.dataItem.baseURL, |
53 this.dataItem.source, | |
44 function(data) { | 54 function(data) { |
45 if (data) { | 55 if (data) { |
46 var blob = new Blob([new Int8Array(data)], {'type' : 'image\/png'}); | 56 var blob = new Blob([new Int8Array(data)], {'type' : 'image\/png'}); |
47 imageEl.src = window.URL.createObjectURL(blob); | 57 imageEl.src = window.URL.createObjectURL(blob); |
48 imageEl.addEventListener('load', function(e) { | 58 imageEl.addEventListener('load', function(e) { |
49 window.URL.revokeObjectURL(this.src); | 59 window.URL.revokeObjectURL(this.src); |
50 }); | 60 }); |
51 } else { | 61 } else if (self.dataItem.source == 'ONLINE') { |
52 var xhr = new XMLHttpRequest(); | 62 var xhr = new XMLHttpRequest(); |
53 xhr.open('GET', self.dataItem.baseURL + ThumbnailSuffix, true); | 63 xhr.open('GET', self.dataItem.baseURL + ThumbnailSuffix, true); |
54 xhr.responseType = 'arraybuffer'; | 64 xhr.responseType = 'arraybuffer'; |
55 xhr.send(null); | 65 xhr.send(null); |
56 xhr.addEventListener('load', function(e) { | 66 xhr.addEventListener('load', function(e) { |
57 if (xhr.status === 200) { | 67 if (xhr.status === 200) { |
58 chrome.wallpaperPrivate.saveThumbnail(self.dataItem.baseURL, | 68 chrome.wallpaperPrivate.saveThumbnail(self.dataItem.baseURL, |
59 xhr.response); | 69 xhr.response); |
60 var blob = new Blob([new Int8Array(xhr.response)], | 70 var blob = new Blob([new Int8Array(xhr.response)], |
61 {'type' : 'image\/png'}); | 71 {'type' : 'image\/png'}); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 // The active thumbnail maybe deleted in the above redraw(). Sets it again | 246 // The active thumbnail maybe deleted in the above redraw(). Sets it again |
237 // to make sure checkmark shows correctly. | 247 // to make sure checkmark shows correctly. |
238 this.updateActiveThumb_(); | 248 this.updateActiveThumb_(); |
239 } | 249 } |
240 }; | 250 }; |
241 | 251 |
242 return { | 252 return { |
243 WallpaperThumbnailsGrid: WallpaperThumbnailsGrid | 253 WallpaperThumbnailsGrid: WallpaperThumbnailsGrid |
244 }; | 254 }; |
245 }); | 255 }); |
OLD | NEW |