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.use_small_icon_ = true; | |
Evan Stade
2011/07/27 16:31:45
useSmallIcon_
Greg Billock
2011/07/27 19:52:24
Done.
| |
183 | |
181 var appImg = this.ownerDocument.createElement('img'); | 184 var appImg = this.ownerDocument.createElement('img'); |
182 appImg.src = this.appData_.icon_big; | 185 if (this.use_small_icon_) |
Evan Stade
2011/07/27 16:31:45
ternary operator
Greg Billock
2011/07/27 19:52:24
Done.
| |
186 appImg.src = this.appData_.icon_small; | |
187 else | |
188 appImg.src = this.appData_.icon_big; | |
183 // We use a mask of the same image so CSS rules can highlight just the | 189 // We use a mask of the same image so CSS rules can highlight just the |
184 // image when it's touched. | 190 // image when it's touched. (Note: we elsewhere set mask-rect to 100%) |
185 appImg.style.WebkitMaskImage = url(this.appData_.icon_big); | 191 if (this.use_small_icon_) |
Evan Stade
2011/07/27 16:31:45
appImg.style.WebkitMaskImage = url(apImg.src)
Greg Billock
2011/07/27 19:52:24
I'm not sure this mask image is doing anything for
Evan Stade
2011/07/27 23:04:31
yea I guess
Greg Billock
2011/07/28 16:59:59
Done.
| |
192 appImg.style.WebkitMaskImage = url(this.appData_.icon_small); | |
193 else | |
194 appImg.style.WebkitMaskImage = url(this.appData_.icon_big); | |
186 // We put a click handler just on the app image - so clicking on the | 195 // We put a click handler just on the app image - so clicking on the |
187 // margins between apps doesn't do anything. | 196 // margins between apps doesn't do anything. |
188 appImg.addEventListener('click', this.onClick_.bind(this)); | 197 appImg.addEventListener('click', this.onClick_.bind(this)); |
189 this.appendChild(appImg); | 198 if (this.use_small_icon_) { |
199 var imgDiv = this.ownerDocument.createElement('div'); | |
200 imgDiv.style.display = '-webkit-box'; | |
Evan Stade
2011/07/27 16:31:45
all this style stuff should be in a css file, and
Greg Billock
2011/07/27 19:52:24
Done.
| |
201 imgDiv.style['-webkit-box-align'] = 'center'; | |
202 imgDiv.style['vertical-align'] = 'middle'; | |
Evan Stade
2011/07/27 16:31:45
notwithstanding my above comment, the way you'd do
Greg Billock
2011/07/27 19:52:24
ah HA! :-)
| |
203 imgDiv.style.border = '1px solid gray'; | |
204 imgDiv.style['border-radius'] = '4px'; | |
205 imgDiv.style.cursor = 'pointer'; | |
206 imgDiv.appendChild(appImg); | |
207 imgDiv.addEventListener('click', this.onClick_.bind(this)); | |
208 this.imgDiv_ = imgDiv; | |
209 this.appendChild(imgDiv); | |
210 } else { | |
211 this.appendChild(appImg); | |
212 } | |
190 this.appImg_ = appImg; | 213 this.appImg_ = appImg; |
191 | 214 |
192 var appSpan = this.ownerDocument.createElement('span'); | 215 var appSpan = this.ownerDocument.createElement('span'); |
193 appSpan.textContent = this.appData_.name; | 216 appSpan.textContent = this.appData_.name; |
194 this.appendChild(appSpan); | 217 this.appendChild(appSpan); |
195 | 218 |
196 this.addEventListener('contextmenu', cr.ui.contextMenuHandler); | 219 this.addEventListener('contextmenu', cr.ui.contextMenuHandler); |
197 this.addEventListener('keydown', cr.ui.contextMenuHandler); | 220 this.addEventListener('keydown', cr.ui.contextMenuHandler); |
198 this.addEventListener('keyup', cr.ui.contextMenuHandler); | 221 this.addEventListener('keyup', cr.ui.contextMenuHandler); |
199 }, | 222 }, |
200 | 223 |
201 /** | 224 /** |
202 * Set the size and position of the app tile. | 225 * Set the size and position of the app tile. |
203 * @param {number} size The total size of |this|. | 226 * @param {number} size The total size of |this|. |
204 * @param {number} x The x-position. | 227 * @param {number} x The x-position. |
205 * @param {number} y The y-position. | 228 * @param {number} y The y-position. |
206 * animate. | 229 * animate. |
207 */ | 230 */ |
208 setBounds: function(size, x, y) { | 231 setBounds: function(size, x, y) { |
209 this.appImg_.style.width = this.appImg_.style.height = | 232 if (this.use_small_icon_) { |
210 (size * APP_IMG_SIZE_FRACTION) + 'px'; | 233 this.imgDiv_.style.width = (size * APP_IMG_SIZE_FRACTION) + 'px'; |
234 this.imgDiv_.style.height = (size * APP_IMG_SIZE_FRACTION - 4) + 'px'; | |
235 this.appImg_.style.width = this.appImg_.style.height = '32px'; | |
236 var margin = (size - (size * APP_IMG_SIZE_FRACTION)) / 2; | |
237 this.imgDiv_.style['margin-left'] = margin + 'px'; | |
238 this.imgDiv_.style['margin-right'] = margin + 'px'; | |
239 this.imgDiv_.style['margin-bottom'] = '4px'; | |
240 } | |
241 else { | |
242 this.appImg_.style.width = this.appImg_.style.height = | |
243 (size * APP_IMG_SIZE_FRACTION) + 'px'; | |
244 } | |
245 | |
211 this.style.width = this.style.height = size + 'px'; | 246 this.style.width = this.style.height = size + 'px'; |
212 | 247 |
213 this.style.left = x + 'px'; | 248 this.style.left = x + 'px'; |
214 this.style.right = x + 'px'; | 249 this.style.right = x + 'px'; |
215 this.style.top = y + 'px'; | 250 this.style.top = y + 'px'; |
216 }, | 251 }, |
217 | 252 |
218 /** | 253 /** |
219 * Invoked when an app is clicked | 254 * Invoked when an app is clicked |
220 * @param {Event} e The click event. | 255 * @param {Event} e The click event. |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 } | 402 } |
368 | 403 |
369 chrome.send('reorderApps', [draggedTile.firstChild.appId, appIds]); | 404 chrome.send('reorderApps', [draggedTile.firstChild.appId, appIds]); |
370 }, | 405 }, |
371 }; | 406 }; |
372 | 407 |
373 return { | 408 return { |
374 AppsPage: AppsPage, | 409 AppsPage: AppsPage, |
375 }; | 410 }; |
376 }); | 411 }); |
OLD | NEW |