| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 155 |
| 156 /** | 156 /** |
| 157 * Creates a new App object. | 157 * Creates a new App object. |
| 158 * @param {Object} appData The data object that describes the app. | 158 * @param {Object} appData The data object that describes the app. |
| 159 * @constructor | 159 * @constructor |
| 160 * @extends {HTMLDivElement} | 160 * @extends {HTMLDivElement} |
| 161 */ | 161 */ |
| 162 function App(appData) { | 162 function App(appData) { |
| 163 var el = cr.doc.createElement('div'); | 163 var el = cr.doc.createElement('div'); |
| 164 el.__proto__ = App.prototype; | 164 el.__proto__ = App.prototype; |
| 165 el.appData = appData; | 165 el.initialize(appData); |
| 166 el.initialize(); | |
| 167 | 166 |
| 168 return el; | 167 return el; |
| 169 } | 168 } |
| 170 | 169 |
| 171 App.prototype = { | 170 App.prototype = { |
| 172 __proto__: HTMLDivElement.prototype, | 171 __proto__: HTMLDivElement.prototype, |
| 173 | 172 |
| 174 initialize: function() { | 173 /** |
| 174 * Initialize the app object. |
| 175 * @param {Object} appData The data object that describes the app. |
| 176 */ |
| 177 initialize: function(appData) { |
| 178 this.appData = appData; |
| 175 assert(this.appData_.id, 'Got an app without an ID'); | 179 assert(this.appData_.id, 'Got an app without an ID'); |
| 176 this.id = this.appData_.id; | 180 this.id = this.appData_.id; |
| 177 | 181 |
| 178 this.className = 'app'; | 182 this.className = 'app'; |
| 179 | 183 |
| 180 var appContents = this.ownerDocument.createElement('div'); | |
| 181 appContents.className = 'app-contents'; | |
| 182 | |
| 183 var appImgContainer = this.ownerDocument.createElement('div'); | |
| 184 appImgContainer.className = 'app-img-container'; | |
| 185 this.appImgContainer_ = appImgContainer; | |
| 186 | |
| 187 if (!this.appData_.icon_big_exists && this.appData_.icon_small_exists) | 184 if (!this.appData_.icon_big_exists && this.appData_.icon_small_exists) |
| 188 this.useSmallIcon_ = true; | 185 this.useSmallIcon_ = true; |
| 189 | 186 |
| 190 var appImg = this.ownerDocument.createElement('img'); | 187 this.appContents_ = this.useSmallIcon_ ? |
| 191 appImg.classList.add('invisible'); | 188 $('app-small-icon-template').cloneNode(true) : |
| 192 this.appImg_ = appImg; | 189 $('app-large-icon-template').cloneNode(true); |
| 190 this.appContents_.id = ''; |
| 191 this.appContents_.hidden = false; |
| 192 this.appendChild(this.appContents_); |
| 193 |
| 194 this.appImgContainer_ = this.querySelector('.app-img-container'); |
| 195 this.appImg_ = this.appImgContainer_.querySelector('img'); |
| 193 this.setIcon(); | 196 this.setIcon(); |
| 194 appImgContainer.appendChild(appImg); | |
| 195 | 197 |
| 196 if (this.useSmallIcon_) { | 198 if (this.useSmallIcon_) { |
| 197 var imgDiv = this.ownerDocument.createElement('div'); | 199 this.imgDiv_ = this.querySelector('.app-icon-div'); |
| 198 imgDiv.className = 'app-icon-div'; | 200 this.addLaunchClickTarget_(this.imgDiv_); |
| 199 imgDiv.appendChild(appImgContainer); | 201 this.imgDiv_.title = this.appData_.name; |
| 200 this.addLaunchClickTarget_(imgDiv); | |
| 201 imgDiv.title = this.appData_.name; | |
| 202 this.imgDiv_ = imgDiv; | |
| 203 appContents.appendChild(imgDiv); | |
| 204 this.appImgContainer_.style.position = 'absolute'; | |
| 205 this.appImgContainer_.style.bottom = '10px'; | |
| 206 this.appImgContainer_.style.left = '10px'; | |
| 207 var stripeDiv = this.ownerDocument.createElement('div'); | |
| 208 stripeDiv.className = 'color-stripe'; | |
| 209 imgDiv.appendChild(stripeDiv); | |
| 210 | |
| 211 chrome.send('getAppIconDominantColor', [this.id]); | 202 chrome.send('getAppIconDominantColor', [this.id]); |
| 212 } else { | 203 } else { |
| 213 this.addLaunchClickTarget_(appImgContainer); | 204 this.addLaunchClickTarget_(this.appImgContainer_); |
| 214 appImgContainer.title = this.appData_.name; | 205 this.appImgContainer_.title = this.appData_.name; |
| 215 appContents.appendChild(appImgContainer); | |
| 216 } | 206 } |
| 217 | 207 |
| 218 var appSpan = this.ownerDocument.createElement('span'); | 208 var appSpan = this.appContents_.querySelector('.title'); |
| 219 appSpan.textContent = appSpan.title = this.appData_.name; | 209 appSpan.textContent = appSpan.title = this.appData_.name; |
| 220 this.addLaunchClickTarget_(appSpan); | 210 this.addLaunchClickTarget_(appSpan); |
| 221 appContents.appendChild(appSpan); | |
| 222 this.appendChild(appContents); | |
| 223 | 211 |
| 224 var notification = this.appData_.notification; | 212 var notification = this.appData_.notification; |
| 225 var hasNotification = typeof notification != 'undefined' && | 213 var hasNotification = typeof notification != 'undefined' && |
| 226 typeof notification['title'] != 'undefined' && | 214 typeof notification['title'] != 'undefined' && |
| 227 typeof notification['body'] != 'undefined'; | 215 typeof notification['body'] != 'undefined'; |
| 228 if (hasNotification) | 216 if (hasNotification) |
| 229 this.setupNotification_(notification); | 217 this.setupNotification_(notification); |
| 230 | 218 |
| 231 this.appContents_ = appContents; | |
| 232 | |
| 233 this.addEventListener('keydown', cr.ui.contextMenuHandler); | 219 this.addEventListener('keydown', cr.ui.contextMenuHandler); |
| 234 this.addEventListener('keyup', cr.ui.contextMenuHandler); | 220 this.addEventListener('keyup', cr.ui.contextMenuHandler); |
| 235 | 221 |
| 236 // This hack is here so that appContents.contextMenu will be the same as | 222 // This hack is here so that appContents.contextMenu will be the same as |
| 237 // this.contextMenu. | 223 // this.contextMenu. |
| 238 var self = this; | 224 var self = this; |
| 239 appContents.__defineGetter__('contextMenu', function() { | 225 this.appContents_.__defineGetter__('contextMenu', function() { |
| 240 return self.contextMenu; | 226 return self.contextMenu; |
| 241 }); | 227 }); |
| 242 appContents.addEventListener('contextmenu', cr.ui.contextMenuHandler); | 228 this.appContents_.addEventListener('contextmenu', |
| 229 cr.ui.contextMenuHandler); |
| 243 | 230 |
| 244 this.isStore_ = this.appData_.is_webstore; | 231 this.isStore_ = this.appData_.is_webstore; |
| 245 if (this.isStore_) | 232 if (this.isStore_) |
| 246 this.createAppsPromoExtras_(); | 233 this.createAppsPromoExtras_(); |
| 247 | 234 |
| 248 this.addEventListener('mousedown', this.onMousedown_, true); | 235 this.addEventListener('mousedown', this.onMousedown_, true); |
| 249 }, | 236 }, |
| 250 | 237 |
| 251 /** | 238 /** |
| 252 * Sets the color of the favicon dominant color bar. | 239 * Sets the color of the favicon dominant color bar. |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 appNotificationChanged: appNotificationChanged, | 736 appNotificationChanged: appNotificationChanged, |
| 750 AppsPage: AppsPage, | 737 AppsPage: AppsPage, |
| 751 launchAppAfterEnable: launchAppAfterEnable, | 738 launchAppAfterEnable: launchAppAfterEnable, |
| 752 }; | 739 }; |
| 753 }); | 740 }); |
| 754 | 741 |
| 755 // TODO(estade): update the content handlers to use ntp namespace instead of | 742 // TODO(estade): update the content handlers to use ntp namespace instead of |
| 756 // making these global. | 743 // making these global. |
| 757 var appNotificationChanged = ntp4.appNotificationChanged; | 744 var appNotificationChanged = ntp4.appNotificationChanged; |
| 758 var launchAppAfterEnable = ntp4.launchAppAfterEnable; | 745 var launchAppAfterEnable = ntp4.launchAppAfterEnable; |
| OLD | NEW |