OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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('ntp4', function() { | 5 cr.define('ntp4', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 var localStrings = new LocalStrings; | 8 var localStrings = new LocalStrings; |
9 | 9 |
10 var APP_LAUNCH = { | 10 var APP_LAUNCH = { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 174 |
175 initialize: function() { | 175 initialize: function() { |
176 assert(this.appData_.id, 'Got an app without an ID'); | 176 assert(this.appData_.id, 'Got an app without an ID'); |
177 this.id = this.appData_.id; | 177 this.id = this.appData_.id; |
178 | 178 |
179 this.className = 'app'; | 179 this.className = 'app'; |
180 | 180 |
181 var appContents = this.ownerDocument.createElement('div'); | 181 var appContents = this.ownerDocument.createElement('div'); |
182 appContents.className = 'app-contents'; | 182 appContents.className = 'app-contents'; |
183 | 183 |
| 184 if (!this.appData_.icon_big_exists && this.appData_.icon_small_exists) |
| 185 this.useSmallIcon_ = true; |
| 186 |
184 var appImg = this.ownerDocument.createElement('img'); | 187 var appImg = this.ownerDocument.createElement('img'); |
185 appImg.src = this.appData_.icon_big; | 188 appImg.src = this.useSmallIcon_ ? this.appData_.icon_small : |
186 // We use a mask of the same image so CSS rules can highlight just the | 189 this.appData_.icon_big; |
187 // image when it's touched. | 190 if (this.useSmallIcon_) { |
188 appImg.style.WebkitMaskImage = url(this.appData_.icon_big); | 191 var imgDiv = this.ownerDocument.createElement('div'); |
189 // We put a click handler just on the app image - so clicking on the | 192 imgDiv.className = 'app-icon-div'; |
190 // margins between apps doesn't do anything. | 193 imgDiv.appendChild(appImg); |
191 appImg.addEventListener('click', this.onClick_.bind(this)); | 194 imgDiv.addEventListener('click', this.onClick_.bind(this)); |
192 appContents.appendChild(appImg); | 195 this.imgDiv_ = imgDiv; |
| 196 appContents.appendChild(imgDiv); |
| 197 } else { |
| 198 appImg.addEventListener('click', this.onClick_.bind(this)); |
| 199 appContents.appendChild(appImg); |
| 200 } |
193 this.appImg_ = appImg; | 201 this.appImg_ = appImg; |
194 | 202 |
195 var appSpan = this.ownerDocument.createElement('span'); | 203 var appSpan = this.ownerDocument.createElement('span'); |
196 appSpan.textContent = this.appData_.name; | 204 appSpan.textContent = this.appData_.name; |
197 appSpan.addEventListener('click', this.onClick_.bind(this)); | 205 appSpan.addEventListener('click', this.onClick_.bind(this)); |
198 appContents.appendChild(appSpan); | 206 appContents.appendChild(appSpan); |
199 this.appendChild(appContents); | 207 this.appendChild(appContents); |
200 | 208 |
201 this.addEventListener('keydown', cr.ui.contextMenuHandler); | 209 this.addEventListener('keydown', cr.ui.contextMenuHandler); |
202 this.addEventListener('keyup', cr.ui.contextMenuHandler); | 210 this.addEventListener('keyup', cr.ui.contextMenuHandler); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 278 |
271 /** | 279 /** |
272 * Set the size and position of the app tile. | 280 * Set the size and position of the app tile. |
273 * @param {number} size The total size of |this|. | 281 * @param {number} size The total size of |this|. |
274 * @param {number} x The x-position. | 282 * @param {number} x The x-position. |
275 * @param {number} y The y-position. | 283 * @param {number} y The y-position. |
276 * animate. | 284 * animate. |
277 */ | 285 */ |
278 setBounds: function(size, x, y) { | 286 setBounds: function(size, x, y) { |
279 var imgSize = size * APP_IMG_SIZE_FRACTION; | 287 var imgSize = size * APP_IMG_SIZE_FRACTION; |
280 this.appImg_.style.width = this.appImg_.style.height = imgSize + 'px'; | 288 this.appImg_.style.width = this.appImg_.style.height = |
| 289 this.useSmallIcon_ ? '32px' : imgSize + 'px'; |
| 290 |
| 291 |
281 this.style.width = this.style.height = size + 'px'; | 292 this.style.width = this.style.height = size + 'px'; |
282 if (this.isStore_) | 293 if (this.isStore_) |
283 this.appsPromoExtras_.style.left = size + (imgSize - size) / 2 + 'px'; | 294 this.appsPromoExtras_.style.left = size + (imgSize - size) / 2 + 'px'; |
284 | 295 |
285 this.style.left = x + 'px'; | 296 this.style.left = x + 'px'; |
286 this.style.right = x + 'px'; | 297 this.style.right = x + 'px'; |
287 this.style.top = y + 'px'; | 298 this.style.top = y + 'px'; |
288 }, | 299 }, |
289 | 300 |
290 /** | 301 /** |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 var store = document.querySelector('.webstore'); | 457 var store = document.querySelector('.webstore'); |
447 if (store) | 458 if (store) |
448 store.setAppsPromoData(data); | 459 store.setAppsPromoData(data); |
449 }; | 460 }; |
450 | 461 |
451 return { | 462 return { |
452 APP_LAUNCH: APP_LAUNCH, | 463 APP_LAUNCH: APP_LAUNCH, |
453 AppsPage: AppsPage, | 464 AppsPage: AppsPage, |
454 }; | 465 }; |
455 }); | 466 }); |
OLD | NEW |