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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 171 |
172 App.prototype = { | 172 App.prototype = { |
173 __proto__: HTMLDivElement.prototype, | 173 __proto__: HTMLDivElement.prototype, |
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 if (!this.appData_.icon_big_exists && this.appData_.icon_small_exists) |
| 182 this.useSmallIcon_ = true; |
| 183 |
181 var appImg = this.ownerDocument.createElement('img'); | 184 var appImg = this.ownerDocument.createElement('img'); |
182 appImg.src = this.appData_.icon_big; | 185 appImg.src = this.useSmallIcon_ ? this.appData_.icon_small : |
183 // We use a mask of the same image so CSS rules can highlight just the | 186 this.appData_.icon_big; |
184 // image when it's touched. | |
185 appImg.style.WebkitMaskImage = url(this.appData_.icon_big); | |
186 // We put a click handler just on the app image - so clicking on the | 187 // We put a click handler just on the app image - so clicking on the |
187 // margins between apps doesn't do anything. | 188 // margins between apps doesn't do anything. |
188 appImg.addEventListener('click', this.onClick_.bind(this)); | 189 appImg.addEventListener('click', this.onClick_.bind(this)); |
189 this.appendChild(appImg); | 190 if (this.useSmallIcon_) { |
| 191 var imgDiv = this.ownerDocument.createElement('div'); |
| 192 imgDiv.setAttribute('class', 'app-icon-div'); |
| 193 imgDiv.appendChild(appImg); |
| 194 imgDiv.addEventListener('click', this.onClick_.bind(this)); |
| 195 this.imgDiv_ = imgDiv; |
| 196 this.appendChild(imgDiv); |
| 197 } else { |
| 198 this.appendChild(appImg); |
| 199 } |
190 this.appImg_ = appImg; | 200 this.appImg_ = appImg; |
191 | 201 |
192 var appSpan = this.ownerDocument.createElement('span'); | 202 var appSpan = this.ownerDocument.createElement('span'); |
193 appSpan.textContent = this.appData_.name; | 203 appSpan.textContent = this.appData_.name; |
194 this.appendChild(appSpan); | 204 this.appendChild(appSpan); |
195 | 205 |
196 this.addEventListener('contextmenu', cr.ui.contextMenuHandler); | 206 this.addEventListener('contextmenu', cr.ui.contextMenuHandler); |
197 this.addEventListener('keydown', cr.ui.contextMenuHandler); | 207 this.addEventListener('keydown', cr.ui.contextMenuHandler); |
198 this.addEventListener('keyup', cr.ui.contextMenuHandler); | 208 this.addEventListener('keyup', cr.ui.contextMenuHandler); |
199 }, | 209 }, |
200 | 210 |
201 /** | 211 /** |
202 * Set the size and position of the app tile. | 212 * Set the size and position of the app tile. |
203 * @param {number} size The total size of |this|. | 213 * @param {number} size The total size of |this|. |
204 * @param {number} x The x-position. | 214 * @param {number} x The x-position. |
205 * @param {number} y The y-position. | 215 * @param {number} y The y-position. |
206 * animate. | 216 * animate. |
207 */ | 217 */ |
208 setBounds: function(size, x, y) { | 218 setBounds: function(size, x, y) { |
209 this.appImg_.style.width = this.appImg_.style.height = | 219 if (this.useSmallIcon_) { |
210 (size * APP_IMG_SIZE_FRACTION) + 'px'; | 220 this.imgDiv_.style.width = (size * APP_IMG_SIZE_FRACTION) + 'px'; |
| 221 this.imgDiv_.style.height = (size * APP_IMG_SIZE_FRACTION - 4) + 'px'; |
| 222 this.appImg_.style.width = this.appImg_.style.height = '32px'; |
| 223 var margin = (size - (size * APP_IMG_SIZE_FRACTION)) / 2; |
| 224 this.imgDiv_.style['margin-left'] = margin + 'px'; |
| 225 this.imgDiv_.style['margin-right'] = margin + 'px'; |
| 226 this.imgDiv_.style['margin-bottom'] = '4px'; |
| 227 } |
| 228 else { |
| 229 this.appImg_.style.width = this.appImg_.style.height = |
| 230 (size * APP_IMG_SIZE_FRACTION) + 'px'; |
| 231 } |
| 232 |
211 this.style.width = this.style.height = size + 'px'; | 233 this.style.width = this.style.height = size + 'px'; |
212 | 234 |
213 this.style.left = x + 'px'; | 235 this.style.left = x + 'px'; |
214 this.style.right = x + 'px'; | 236 this.style.right = x + 'px'; |
215 this.style.top = y + 'px'; | 237 this.style.top = y + 'px'; |
216 }, | 238 }, |
217 | 239 |
218 /** | 240 /** |
219 * Invoked when an app is clicked | 241 * Invoked when an app is clicked |
220 * @param {Event} e The click event. | 242 * @param {Event} e The click event. |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 } | 389 } |
368 | 390 |
369 chrome.send('reorderApps', [draggedTile.firstChild.appId, appIds]); | 391 chrome.send('reorderApps', [draggedTile.firstChild.appId, appIds]); |
370 }, | 392 }, |
371 }; | 393 }; |
372 | 394 |
373 return { | 395 return { |
374 AppsPage: AppsPage, | 396 AppsPage: AppsPage, |
375 }; | 397 }; |
376 }); | 398 }); |
OLD | NEW |