Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: chrome/browser/resources/ntp_search/apps_page.js

Issue 11438009: NTP5: Refactoring appData to use Tile's data implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing Dan's comments Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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('ntp', function() { 5 cr.define('ntp', function() {
6 'use strict'; 6 'use strict';
7 7
8 var Tile = ntp.Tile; 8 var Tile = ntp.Tile;
9 var TilePage = ntp.TilePage; 9 var TilePage = ntp.TilePage;
10 var APP_LAUNCH = ntp.APP_LAUNCH; 10 var APP_LAUNCH = ntp.APP_LAUNCH;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 113 }
114 }, 114 },
115 115
116 /** 116 /**
117 * Does all the necessary setup to show the menu for the given app. 117 * Does all the necessary setup to show the menu for the given app.
118 * @param {App} app The App object that will be showing a context menu. 118 * @param {App} app The App object that will be showing a context menu.
119 */ 119 */
120 setupForApp: function(app) { 120 setupForApp: function(app) {
121 this.app_ = app; 121 this.app_ = app;
122 122
123 this.launch_.textContent = app.appData.title; 123 this.launch_.textContent = app.data.title;
124 124
125 this.forAllLaunchTypes_(function(launchTypeButton, id) { 125 this.forAllLaunchTypes_(function(launchTypeButton, id) {
126 launchTypeButton.disabled = false; 126 launchTypeButton.disabled = false;
127 launchTypeButton.checked = app.appData.launch_type == id; 127 launchTypeButton.checked = app.data.launch_type == id;
128 }); 128 });
129 129
130 this.options_.disabled = !app.appData.optionsUrl || !app.appData.enabled; 130 this.options_.disabled = !app.data.optionsUrl || !app.data.enabled;
131 this.details_.disabled = !app.appData.detailsUrl; 131 this.details_.disabled = !app.data.detailsUrl;
132 this.uninstall_.disabled = !app.appData.mayDisable; 132 this.uninstall_.disabled = !app.data.mayDisable;
133 133
134 this.disableNotifications_.hidden = true; 134 this.disableNotifications_.hidden = true;
135 var notificationsDisabled = app.appData.notifications_disabled; 135 var notificationsDisabled = app.data.notifications_disabled;
136 if (typeof notificationsDisabled != 'undefined') { 136 if (typeof notificationsDisabled != 'undefined') {
137 this.disableNotifications_.hidden = false; 137 this.disableNotifications_.hidden = false;
138 this.disableNotifications_.checked = notificationsDisabled; 138 this.disableNotifications_.checked = notificationsDisabled;
139 } 139 }
140 }, 140 },
141 141
142 /** 142 /**
143 * Handlers for menu item activation. 143 * Handlers for menu item activation.
144 * @param {Event} e The activation event. 144 * @param {Event} e The activation event.
145 * @private 145 * @private
146 */ 146 */
147 onLaunch_: function(e) { 147 onLaunch_: function(e) {
148 chrome.send('launchApp', [this.app_.appId, APP_LAUNCH.NTP_APPS_MENU]); 148 chrome.send('launchApp', [this.app_.appId, APP_LAUNCH.NTP_APPS_MENU]);
149 }, 149 },
150 onLaunchTypeChanged_: function(e) { 150 onLaunchTypeChanged_: function(e) {
151 var pressed = e.currentTarget; 151 var pressed = e.currentTarget;
152 var app = this.app_; 152 var app = this.app_;
153 this.forAllLaunchTypes_(function(launchTypeButton, id) { 153 this.forAllLaunchTypes_(function(launchTypeButton, id) {
154 if (launchTypeButton == pressed) { 154 if (launchTypeButton == pressed) {
155 chrome.send('setLaunchType', [app.appId, id]); 155 chrome.send('setLaunchType', [app.appId, id]);
156 // Manually update the launch type. We will only get 156 // Manually update the launch type. We will only get
157 // appsPrefChangeCallback calls after changes to other NTP instances. 157 // appsPrefChangeCallback calls after changes to other NTP instances.
158 app.appData.launch_type = id; 158 app.data.launch_type = id;
159 } 159 }
160 }); 160 });
161 }, 161 },
162 onShowOptions_: function(e) { 162 onShowOptions_: function(e) {
163 window.location = this.app_.appData.optionsUrl; 163 window.location = this.app_.data.optionsUrl;
164 }, 164 },
165 onShowDetails_: function(e) { 165 onShowDetails_: function(e) {
166 var url = this.app_.appData.detailsUrl; 166 var url = this.app_.data.detailsUrl;
167 url = appendParam(url, 'utm_source', 'chrome-ntp-launcher'); 167 url = appendParam(url, 'utm_source', 'chrome-ntp-launcher');
168 window.location = url; 168 window.location = url;
169 }, 169 },
170 onDisableNotifications_: function(e) { 170 onDisableNotifications_: function(e) {
171 var app = this.app_; 171 var app = this.app_;
172 app.removeBubble(); 172 app.removeBubble();
173 // Toggle the current disable setting. 173 // Toggle the current disable setting.
174 var newSetting = !this.disableNotifications_.checked; 174 var newSetting = !this.disableNotifications_.checked;
175 app.appData.notifications_disabled = newSetting; 175 app.data.notifications_disabled = newSetting;
176 chrome.send('setNotificationsDisabled', [app.appData.id, newSetting]); 176 chrome.send('setNotificationsDisabled', [app.data.id, newSetting]);
177 }, 177 },
178 onUninstall_: function(e) { 178 onUninstall_: function(e) {
179 var tileCell = this.app_.tileCell; 179 chrome.send('uninstallApp', [this.app_.data.id]);
180 tileCell.tilePage.setTileRepositioningState(tileCell.index, true);
181 chrome.send('uninstallApp', [this.app_.appData.id]);
182 }, 180 },
183 onCreateShortcut_: function(e) { 181 onCreateShortcut_: function(e) {
184 chrome.send('createAppShortcut', [this.app_.appData.id]); 182 chrome.send('createAppShortcut', [this.app_.data.id]);
185 }, 183 },
186 }; 184 };
187 185
188 /** 186 /**
189 * Creates a new App object. 187 * Creates a new App object.
190 * @param {Object} appData The data object that describes the app.
191 * @constructor 188 * @constructor
192 * @extends {HTMLDivElement} 189 * @extends {HTMLDivElement}
193 */ 190 */
194 function App(appData) { 191 function App() {
195 var el = cr.doc.createElement('div'); 192 var el = cr.doc.createElement('div');
196 el.__proto__ = App.prototype; 193 el.__proto__ = App.prototype;
197 el.initialize(appData);
198 194
199 return el; 195 return el;
200 } 196 }
201 197
202 App.prototype = Tile.subclass({ 198 App.prototype = Tile.subclass({
203 __proto__: HTMLDivElement.prototype, 199 __proto__: HTMLDivElement.prototype,
Dan Beam 2012/12/07 05:05:31 nit: why isn't this simply Tile.prototype or Thumb
pedro (no code reviews) 2012/12/07 21:54:55 Thumbnail is a subclass of Tile. App is also a sub
204 200
205 /** 201 /**
206 * Initialize the app object. 202 * Initialize the app object.
207 * @param {Object} appData The data object that describes the app. 203 * @param {Object} data The data object that describes the app.
Dan Beam 2012/12/07 05:05:31 nit: can this be @private?
pedro (no code reviews) 2012/12/07 21:54:55 All other classes have a public initialize method.
Dan Beam 2012/12/07 22:31:07 but these public initialize methods are never used
pedro (no code reviews) 2012/12/10 19:44:43 Done.
208 */ 204 */
209 initialize: function(appData) { 205 initialize: function(data) {
210 this.className = 'app focusable'; 206 this.className = 'app focusable';
211 207
212 Tile.prototype.initialize.apply(this, arguments); 208 Tile.prototype.initialize.apply(this, arguments);
213 209
214 this.appData = appData; 210 assert(this.data_.id, 'Got an app without an ID');
215 assert(this.appData_.id, 'Got an app without an ID'); 211 this.id = this.data_.id;
216 this.id = this.appData_.id;
217 this.setAttribute('role', 'menuitem'); 212 this.setAttribute('role', 'menuitem');
218 213
219 if (!this.appData_.icon_big_exists && this.appData_.icon_small_exists) 214 if (!this.data_.icon_big_exists && this.data_.icon_small_exists)
220 this.useSmallIcon_ = true; 215 this.useSmallIcon_ = true;
221 216
222 this.appContents_ = this.useSmallIcon_ ? 217 this.appContents_ = this.useSmallIcon_ ?
223 $('app-small-icon-template').cloneNode(true) : 218 $('app-small-icon-template').cloneNode(true) :
224 $('app-large-icon-template').cloneNode(true); 219 $('app-large-icon-template').cloneNode(true);
225 this.appContents_.id = ''; 220 this.appContents_.id = '';
226 this.appendChild(this.appContents_); 221 this.appendChild(this.appContents_);
227 222
228 this.appImgContainer_ = this.querySelector('.app-img-container'); 223 this.appImgContainer_ = this.querySelector('.app-img-container');
229 this.appImg_ = this.appImgContainer_.querySelector('img'); 224 this.appImg_ = this.appImgContainer_.querySelector('img');
230 this.setIcon(); 225 this.setIcon();
231 226
232 if (this.useSmallIcon_) { 227 if (this.useSmallIcon_) {
233 this.imgDiv_ = this.querySelector('.app-icon-div'); 228 this.imgDiv_ = this.querySelector('.app-icon-div');
234 this.addLaunchClickTarget_(this.imgDiv_); 229 this.addLaunchClickTarget_(this.imgDiv_);
235 this.imgDiv_.title = this.appData_.title; 230 this.imgDiv_.title = this.data_.title;
236 chrome.send('getAppIconDominantColor', [this.id]); 231 chrome.send('getAppIconDominantColor', [this.id]);
237 } else { 232 } else {
238 this.addLaunchClickTarget_(this.appImgContainer_); 233 this.addLaunchClickTarget_(this.appImgContainer_);
239 this.appImgContainer_.title = this.appData_.title; 234 this.appImgContainer_.title = this.data_.title;
240 } 235 }
241 236
242 var appSpan = this.appContents_.querySelector('.title'); 237 var appSpan = this.appContents_.querySelector('.title');
243 appSpan.textContent = appSpan.title = this.appData_.title; 238 appSpan.textContent = appSpan.title = this.data_.title;
244 this.addLaunchClickTarget_(appSpan); 239 this.addLaunchClickTarget_(appSpan);
245 240
246 var notification = this.appData_.notification; 241 var notification = this.data_.notification;
247 var hasNotification = typeof notification != 'undefined' && 242 var hasNotification = typeof notification != 'undefined' &&
248 typeof notification['title'] != 'undefined' && 243 typeof notification['title'] != 'undefined' &&
249 typeof notification['body'] != 'undefined' && 244 typeof notification['body'] != 'undefined' &&
250 !this.appData_.notifications_disabled; 245 !this.data_.notifications_disabled;
251 if (hasNotification) 246 if (hasNotification)
252 this.setupNotification_(notification); 247 this.setupNotification_(notification);
253 248
254 this.addEventListener('keydown', cr.ui.contextMenuHandler); 249 this.addEventListener('keydown', cr.ui.contextMenuHandler);
255 this.addEventListener('keyup', cr.ui.contextMenuHandler); 250 this.addEventListener('keyup', cr.ui.contextMenuHandler);
256 251
257 // This hack is here so that appContents.contextMenu will be the same as 252 // This hack is here so that appContents.contextMenu will be the same as
258 // this.contextMenu. 253 // this.contextMenu.
259 var self = this; 254 var self = this;
260 this.appContents_.__defineGetter__('contextMenu', function() { 255 this.appContents_.__defineGetter__('contextMenu', function() {
261 return self.contextMenu; 256 return self.contextMenu;
262 }); 257 });
263 this.appContents_.addEventListener('contextmenu', 258 this.appContents_.addEventListener('contextmenu',
264 cr.ui.contextMenuHandler); 259 cr.ui.contextMenuHandler);
265 260
266 this.addEventListener('mousedown', this.onMousedown_, true); 261 this.addEventListener('mousedown', this.onMousedown_, true);
267 this.addEventListener('keydown', this.onKeydown_); 262 this.addEventListener('keydown', this.onKeydown_);
268 this.addEventListener('keyup', this.onKeyup_); 263 this.addEventListener('keyup', this.onKeyup_);
264
265 this.isInitialized_ = true;
269 }, 266 },
270 267
271 /** 268 /**
272 * Sets the color of the favicon dominant color bar. 269 * Sets the color of the favicon dominant color bar.
273 * @param {string} color The css-parsable value for the color. 270 * @param {string} color The css-parsable value for the color.
274 */ 271 */
275 set stripeColor(color) { 272 set stripeColor(color) {
276 this.querySelector('.color-stripe').style.backgroundColor = color; 273 this.querySelector('.color-stripe').style.backgroundColor = color;
277 }, 274 },
278 275
279 /** 276 /**
280 * Removes the app tile from the page. Should be called after the app has 277 * Removes the app tile from the page. Should be called after the app has
281 * been uninstalled. 278 * been uninstalled.
282 */ 279 */
283 remove: function(opt_animate) { 280 remove: function(opt_animate) {
284 // Unset the ID immediately, because the app is already gone. But leave 281 // Unset the ID immediately, because the app is already gone. But leave
285 // the tile on the page as it animates out. 282 // the tile on the page as it animates out.
286 this.id = ''; 283 this.id = '';
287 this.tileCell.doRemove(opt_animate); 284 this.tileCell.doRemove(opt_animate);
288 }, 285 },
289 286
290 /** 287 /**
291 * Set the URL of the icon from |appData_|. This won't actually show the 288 * Set the URL of the icon from |this.data_|. This won't actually show the
292 * icon until loadIcon() is called (for performance reasons; we don't want 289 * icon until loadIcon() is called (for performance reasons; we don't want
293 * to load icons until we have to). 290 * to load icons until we have to).
294 */ 291 */
295 setIcon: function() { 292 setIcon: function() {
296 var src = this.useSmallIcon_ ? this.appData_.icon_small : 293 var src = this.useSmallIcon_ ? this.data_.icon_small :
297 this.appData_.icon_big; 294 this.data_.icon_big;
298 if (!this.appData_.enabled || 295 if (!this.data_.enabled ||
299 (!this.appData_.offlineEnabled && !navigator.onLine)) { 296 (!this.data_.offlineEnabled && !navigator.onLine)) {
300 src += '?grayscale=true'; 297 src += '?grayscale=true';
301 } 298 }
302 299
303 this.appImgSrc_ = src; 300 this.appImgSrc_ = src;
304 this.classList.add('icon-loading'); 301 this.classList.add('icon-loading');
305 }, 302 },
306 303
307 /** 304 /**
308 * Shows the icon for the app. That is, it causes chrome to load the app 305 * Shows the icon for the app. That is, it causes chrome to load the app
309 * icon resource. 306 * icon resource.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 * @param {Object} notification The notification to show in the bubble. 349 * @param {Object} notification The notification to show in the bubble.
353 * @private 350 * @private
354 */ 351 */
355 setupNotification_: function(notification) { 352 setupNotification_: function(notification) {
356 if (notification) { 353 if (notification) {
357 var infoBubble; 354 var infoBubble;
358 if (!this.currentBubbleShowing_) { 355 if (!this.currentBubbleShowing_) {
359 // Create a new bubble. 356 // Create a new bubble.
360 infoBubble = new cr.ui.ExpandableBubble; 357 infoBubble = new cr.ui.ExpandableBubble;
361 infoBubble.anchorNode = this; 358 infoBubble.anchorNode = this;
362 infoBubble.appId = this.appData_.id; 359 infoBubble.appId = this.data_.id;
363 infoBubble.handleCloseEvent = function() { 360 infoBubble.handleCloseEvent = function() {
364 chrome.send('closeNotification', [this.appId]); 361 chrome.send('closeNotification', [this.appId]);
365 infoBubble.hide(); 362 infoBubble.hide();
366 }; 363 };
367 } else { 364 } else {
368 // Reuse the old bubble instead of popping up a new bubble over 365 // Reuse the old bubble instead of popping up a new bubble over
369 // the old one. 366 // the old one.
370 infoBubble = this.currentBubbleShowing_; 367 infoBubble = this.currentBubbleShowing_;
371 infoBubble.collapseBubble_(); 368 infoBubble.collapseBubble_();
372 } 369 }
(...skipping 15 matching lines...) Expand all
388 this.currentBubbleShowing_ = null; 385 this.currentBubbleShowing_ = null;
389 } 386 }
390 }, 387 },
391 388
392 /** 389 /**
393 * Invoked when an app is clicked. 390 * Invoked when an app is clicked.
394 * @param {Event} e The click event. 391 * @param {Event} e The click event.
395 * @private 392 * @private
396 */ 393 */
397 onClick_: function(e) { 394 onClick_: function(e) {
398 var url = !this.appData_.is_webstore ? '' : 395 var url = !this.data_.is_webstore ? '' :
399 appendParam(this.appData_.url, 396 appendParam(this.data_.url,
400 'utm_source', 397 'utm_source',
401 'chrome-ntp-icon'); 398 'chrome-ntp-icon');
402 399
403 chrome.send('launchApp', 400 chrome.send('launchApp',
404 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, url, 401 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, url,
405 e.button, e.altKey, e.ctrlKey, e.metaKey, e.shiftKey]); 402 e.button, e.altKey, e.ctrlKey, e.metaKey, e.shiftKey]);
406 403
407 // Don't allow the click to trigger a link or anything 404 // Don't allow the click to trigger a link or anything
408 e.preventDefault(); 405 e.preventDefault();
409 }, 406 },
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 } else { 474 } else {
478 this.appContents_.classList.remove('suppress-active'); 475 this.appContents_.classList.remove('suppress-active');
479 } 476 }
480 477
481 // This class is here so we don't show the focus state for apps that 478 // This class is here so we don't show the focus state for apps that
482 // gain keyboard focus via mouse clicking. 479 // gain keyboard focus via mouse clicking.
483 this.classList.add('click-focus'); 480 this.classList.add('click-focus');
484 }, 481 },
485 482
486 /** 483 /**
487 * Change the appData and update the appearance of the app. 484 * Change the data and update the appearance of the app.
488 * @param {Object} appData The new data object that describes the app. 485 * @param {Object} data The new data object that describes the app.
489 */ 486 */
490 replaceAppData: function(appData) { 487 replaceAppData: function(data) {
491 this.appData_ = appData; 488 assert(data);
489 this.data_ = data;
492 this.setIcon(); 490 this.setIcon();
493 this.loadIcon(); 491 this.loadIcon();
494 }, 492 },
495 493
496 /** 494 /**
497 * The data and preferences for this app. 495 * The data and preferences for this app.
498 * @type {Object} 496 * @type {Object}
499 */ 497 */
500 set appData(data) { 498 set data(data) {
501 this.appData_ = data; 499 Object.getOwnPropertyDescriptor(Tile.prototype, 'data').set.apply(this,
500 arguments);
501
502 if (!this.isInitialized_)
503 this.initialize(data);
502 }, 504 },
503 get appData() { 505 get data() {
504 return this.appData_; 506 return this.data_;
Dan Beam 2012/12/07 05:05:31 is this getter necessary?
pedro (no code reviews) 2012/12/07 21:54:55 Yes, it is. It's being used outside this class.
505 }, 507 },
506 508
507 get appId() { 509 get appId() {
508 return this.appData_.id; 510 return this.data_.id;
509 }, 511 },
510 512
511 /** 513 /**
512 * Returns a pointer to the context menu for this app. All apps share the 514 * Returns a pointer to the context menu for this app. All apps share the
513 * singleton AppContextMenu. This function is called by the 515 * singleton AppContextMenu. This function is called by the
514 * ContextMenuHandler in response to the 'contextmenu' event. 516 * ContextMenuHandler in response to the 'contextmenu' event.
515 * @type {cr.ui.Menu} 517 * @type {cr.ui.Menu}
516 */ 518 */
517 get contextMenu() { 519 get contextMenu() {
518 var menu = AppContextMenu.getInstance(); 520 var menu = AppContextMenu.getInstance();
519 menu.setupForApp(this); 521 menu.setupForApp(this);
520 return menu.menu; 522 return menu.menu;
521 }, 523 },
522 524
523 /** 525 /**
524 * Returns whether this element can be 'removed' from chrome (i.e. whether 526 * Returns whether this element can be 'removed' from chrome (i.e. whether
525 * the user can drag it onto the trash and expect something to happen). 527 * the user can drag it onto the trash and expect something to happen).
526 * @return {boolean} True if the app can be uninstalled. 528 * @return {boolean} True if the app can be uninstalled.
527 */ 529 */
528 canBeRemoved: function() { 530 canBeRemoved: function() {
529 return this.appData_.mayDisable; 531 return this.data_.mayDisable;
530 }, 532 },
531 533
532 /** 534 /**
533 * Uninstalls the app after it's been dropped on the trash. 535 * Uninstalls the app after it's been dropped on the trash.
534 */ 536 */
535 removeFromChrome: function() { 537 removeFromChrome: function() {
536 chrome.send('uninstallApp', [this.appData_.id, true]); 538 chrome.send('uninstallApp', [this.data_.id, true]);
537 this.tile.tilePage.removeTile(this.tile, true); 539 this.tile.tilePage.removeTile(this.tile, true);
538 if (this.currentBubbleShowing_) 540 if (this.currentBubbleShowing_)
539 this.currentBubbleShowing_.hide(); 541 this.currentBubbleShowing_.hide();
540 }, 542 },
541 543
542 /** 544 /**
543 * Called when a drag is starting on the tile. Updates dataTransfer with 545 * Called when a drag is starting on the tile. Updates dataTransfer with
544 * data for this tile. 546 * data for this tile.
545 */ 547 */
546 setDragData: function(dataTransfer) { 548 setDragData: function(dataTransfer) {
547 dataTransfer.setData('Text', this.appData_.title); 549 dataTransfer.setData('Text', this.data_.title);
548 dataTransfer.setData('URL', this.appData_.url); 550 dataTransfer.setData('URL', this.data_.url);
549 }, 551 },
550 }); 552 });
551 553
552 /** 554 /**
553 * Creates a new AppsPage object. 555 * Creates a new AppsPage object.
554 * @constructor 556 * @constructor
555 * @extends {TilePage} 557 * @extends {TilePage}
556 */ 558 */
557 function AppsPage() { 559 function AppsPage() {
558 var el = new TilePage(); 560 var el = new TilePage();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 // view. 598 // view.
597 this.addEventListener('carddeselected', this.onCardDeselected_); 599 this.addEventListener('carddeselected', this.onCardDeselected_);
598 this.addEventListener('cardSlider:card_change_ended', 600 this.addEventListener('cardSlider:card_change_ended',
599 this.onCardChangeEnded_); 601 this.onCardChangeEnded_);
600 602
601 this.addEventListener('tilePage:tile_added', this.onTileAdded_); 603 this.addEventListener('tilePage:tile_added', this.onTileAdded_);
602 }, 604 },
603 605
604 /** 606 /**
605 * Highlight a newly installed app as it's added to the NTP. 607 * Highlight a newly installed app as it's added to the NTP.
606 * @param {Object} appData The data object that describes the app. 608 * @param {Object} data The data object that describes the app.
607 */ 609 */
608 insertAndHighlightApp: function(appData) { 610 insertAndHighlightApp: function(data) {
609 ntp.getCardSlider().selectCardByValue(this); 611 ntp.getCardSlider().selectCardByValue(this);
610 this.insertApp(appData, true); 612 this.insertApp(data, true);
611 }, 613 },
612 614
613 /** 615 /**
614 * Inserts an App into the TilePage, preserving the alphabetical order. 616 * Inserts an App into the TilePage, preserving the alphabetical order.
615 * @param {Object} appData The data that describes the app. 617 * @param {Object} data The data that describes the app.
616 * @param {boolean} animate Whether to animate the insertion. 618 * @param {boolean} animate Whether to animate the insertion.
617 */ 619 */
618 insertApp: function(appData, animate) { 620 insertApp: function(data, animate) {
619 var index = this.tiles_.length; 621 var index = this.tiles_.length;
620 for (var i = 0; i < this.tiles_.length; i++) { 622 for (var i = 0; i < this.tiles_.length; i++) {
621 if (appData.title.toLocaleLowerCase() < 623 if (data.title.toLocaleLowerCase() <
622 this.tiles_[i].appData.title.toLocaleLowerCase()) { 624 this.tiles_[i].data.title.toLocaleLowerCase()) {
623 index = i; 625 index = i;
624 break; 626 break;
625 } 627 }
626 } 628 }
627 629
628 var app = new App(appData); 630 var app = new App();
Dan Beam 2012/12/07 05:05:31 I'm still confused as to why you wouldn't want to
pedro (no code reviews) 2012/12/07 21:54:55 This was part of the new design/refactoring. The c
Dan Beam 2012/12/07 22:31:07 do that ^
pedro (no code reviews) 2012/12/10 19:44:43 Added a TODO. Since this is not exactly related to
631 app.data = data;
629 this.addTileAt(app, index); 632 this.addTileAt(app, index);
630 this.renderGrid_(); 633 this.renderGrid_();
631 }, 634 },
632 635
633 /** 636 /**
634 * Handler for 'cardselected' event, fired when |this| is selected. The 637 * Handler for 'cardselected' event, fired when |this| is selected. The
635 * first time this is called, we load all the app icons. 638 * first time this is called, we load all the app icons.
636 * @private 639 * @private
637 */ 640 */
638 onCardSelected_: function(e) { 641 onCardSelected_: function(e) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 return false; 720 return false;
718 return Array.prototype.indexOf.call(e.dataTransfer.types, 721 return Array.prototype.indexOf.call(e.dataTransfer.types,
719 'text/uri-list') != -1; 722 'text/uri-list') != -1;
720 }, 723 },
721 724
722 /** @override */ 725 /** @override */
723 addDragData: function(dataTransfer, index) { 726 addDragData: function(dataTransfer, index) {
724 var sourceId = -1; 727 var sourceId = -1;
725 var currentlyDraggingTile = ntp.getCurrentlyDraggingTile(); 728 var currentlyDraggingTile = ntp.getCurrentlyDraggingTile();
726 if (currentlyDraggingTile) { 729 if (currentlyDraggingTile) {
727 var tileContents = currentlyDraggingTile.firstChild; 730 var tileContents = currentlyDraggingTile.tile;
Dan Beam 2012/12/07 05:05:31 nit: why isn't this getter named `tileContents` --
pedro (no code reviews) 2012/12/07 21:54:55 Because it is indeed a tile. The variable which is
728 if (tileContents.classList.contains('app')) { 731 if (tileContents.classList.contains('app')) {
729 var originalPage = currentlyDraggingTile.tilePage; 732 var originalPage = currentlyDraggingTile.tilePage;
730 var samePageDrag = originalPage == this; 733 var samePageDrag = originalPage == this;
731 sourceId = samePageDrag ? DRAG_SOURCE.SAME_APPS_PANE : 734 sourceId = samePageDrag ? DRAG_SOURCE.SAME_APPS_PANE :
732 DRAG_SOURCE.OTHER_APPS_PANE; 735 DRAG_SOURCE.OTHER_APPS_PANE;
733 this.tileGrid_.insertBefore(currentlyDraggingTile, 736 this.tileGrid_.insertBefore(currentlyDraggingTile,
734 this.tileElements_[index]); 737 this.tileElements_[index]);
735 this.tileMoved(currentlyDraggingTile); 738 this.tileMoved(currentlyDraggingTile);
736 if (!samePageDrag) { 739 if (!samePageDrag) {
737 originalPage.fireRemovedEvent(currentlyDraggingTile, index, true); 740 originalPage.fireRemovedEvent(currentlyDraggingTile, index, true);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 * and |title| members. 793 * and |title| members.
791 */ 794 */
792 generateAppForLink: function(data) { 795 generateAppForLink: function(data) {
793 assert(data.url != undefined); 796 assert(data.url != undefined);
794 assert(data.title != undefined); 797 assert(data.title != undefined);
795 chrome.send('generateAppForLink', [data.url, data.title, 0]); 798 chrome.send('generateAppForLink', [data.url, data.title, 0]);
796 }, 799 },
797 800
798 /** @override */ 801 /** @override */
799 tileMoved: function(draggedTile) { 802 tileMoved: function(draggedTile) {
800 if (!(draggedTile.firstChild instanceof App)) 803 if (!(draggedTile.tile instanceof App))
Dan Beam 2012/12/07 05:05:31 same here, tile.tile
pedro (no code reviews) 2012/12/07 21:54:55 Same here too. This method and others related to d
801 return; 804 return;
802 805
803 chrome.send('setPageIndex', [draggedTile.firstChild.appId, 0]); 806 chrome.send('setPageIndex', [draggedTile.tile.appId, 0]);
804 807
805 var appIds = []; 808 var appIds = [];
806 for (var i = 0; i < this.tiles_.length; i++) { 809 for (var i = 0; i < this.tiles_.length; i++) {
807 var tileContents = this.tiles_[i]; 810 var tileContents = this.tiles_[i];
808 if (tileContents instanceof App) 811 if (tileContents instanceof App)
809 appIds.push(tileContents.appId); 812 appIds.push(tileContents.appId);
810 } 813 }
811 814
812 chrome.send('reorderApps', [draggedTile.firstChild.appId, appIds]); 815 chrome.send('reorderApps', [draggedTile.tile.appId, appIds]);
813 }, 816 },
814 817
815 /** @override */ 818 /** @override */
816 setDropEffect: function(dataTransfer) { 819 setDropEffect: function(dataTransfer) {
817 var tile = ntp.getCurrentlyDraggingTile(); 820 var tile = ntp.getCurrentlyDraggingTile();
818 if (tile && tile.querySelector('.app')) 821 if (tile && tile.querySelector('.app'))
819 ntp.setCurrentDropEffect(dataTransfer, 'move'); 822 ntp.setCurrentDropEffect(dataTransfer, 'move');
820 else 823 else
821 ntp.setCurrentDropEffect(dataTransfer, 'copy'); 824 ntp.setCurrentDropEffect(dataTransfer, 'copy');
822 }, 825 },
823 }; 826 };
824 827
825 /** 828 /**
826 * Launches the specified app using the APP_LAUNCH_NTP_APP_RE_ENABLE 829 * Launches the specified app using the APP_LAUNCH_NTP_APP_RE_ENABLE
827 * histogram. This should only be invoked from the AppLauncherHandler. 830 * histogram. This should only be invoked from the AppLauncherHandler.
828 * @param {String} appID The ID of the app. 831 * @param {String} appID The ID of the app.
829 */ 832 */
830 function launchAppAfterEnable(appId) { 833 function launchAppAfterEnable(appId) {
831 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); 834 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]);
832 } 835 }
833 836
834 function appNotificationChanged(id, notification) { 837 function appNotificationChanged(id, notification) {
835 var app = $(id); 838 var app = $(id);
836 // The app might have been uninstalled, or notifications might be disabled. 839 // The app might have been uninstalled, or notifications might be disabled.
837 if (app && !app.appData.notifications_disabled) 840 if (app && !app.data.notifications_disabled)
838 app.setupNotification_(notification); 841 app.setupNotification_(notification);
839 } 842 }
840 843
841 return { 844 return {
842 appNotificationChanged: appNotificationChanged, 845 appNotificationChanged: appNotificationChanged,
843 AppsPage: AppsPage, 846 AppsPage: AppsPage,
844 launchAppAfterEnable: launchAppAfterEnable, 847 launchAppAfterEnable: launchAppAfterEnable,
845 }; 848 };
846 }); 849 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698